@klinking/colander 0.0.0 → 2.0.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.
- package/dist/formats/date.cjs +51 -48
- package/dist/formats/date.d.cts +10 -37
- package/dist/formats/date.d.mts +10 -37
- package/dist/formats/date.mjs +6 -2
- package/dist/formats/object.cjs +51 -48
- package/dist/formats/object.d.cts +10 -37
- package/dist/formats/object.d.mts +10 -37
- package/dist/formats/object.mjs +6 -2
- package/dist/formats/plain-date-time.cjs +51 -48
- package/dist/formats/plain-date-time.d.cts +10 -37
- package/dist/formats/plain-date-time.d.mts +10 -37
- package/dist/formats/plain-date-time.mjs +6 -2
- package/dist/formats/plain-date.cjs +51 -48
- package/dist/formats/plain-date.d.cts +10 -37
- package/dist/formats/plain-date.d.mts +10 -37
- package/dist/formats/plain-date.mjs +6 -2
- package/dist/formats/plain-month-day.cjs +51 -48
- package/dist/formats/plain-month-day.d.cts +10 -37
- package/dist/formats/plain-month-day.d.mts +10 -37
- package/dist/formats/plain-month-day.mjs +6 -2
- package/dist/formats/plain-year-month.cjs +51 -48
- package/dist/formats/plain-year-month.d.cts +10 -37
- package/dist/formats/plain-year-month.d.mts +10 -37
- package/dist/formats/plain-year-month.mjs +6 -2
- package/dist/formats/zoned-date-time.cjs +51 -48
- package/dist/formats/zoned-date-time.d.cts +10 -37
- package/dist/formats/zoned-date-time.d.mts +10 -37
- package/dist/formats/zoned-date-time.mjs +6 -2
- package/dist/index.cjs +47 -48
- package/dist/index.d.cts +11 -2
- package/dist/index.d.mts +11 -2
- package/dist/index.mjs +2 -2
- package/dist/{temporal-polyfill-DTx0VIX5.mjs → weeks-navigation-B-Nch3LS.mjs} +357 -562
- package/dist/{temporal-polyfill-DU8VfleL.cjs → weeks-navigation-FxcECgCR.cjs} +357 -568
- package/dist/{weeks-view-context-BN6qR-83.d.mts → weeks-view-context-BZeWx9N8.d.cts} +275 -258
- package/dist/{weeks-view-context-aHGgYkpt.d.cts → weeks-view-context-MVe1b-BS.d.mts} +275 -258
- package/package.json +20 -20
- package/src/calendar-context.ts +12 -5
- package/src/calendar-provider.test.tsx +18 -4
- package/src/calendar-provider.tsx +130 -35
- package/src/calendar-types.ts +21 -4
- package/src/compute-weeks-in-window.test.ts +9 -7
- package/src/context.ts +1 -1
- package/src/day-cell.test.tsx +109 -0
- package/src/day-cell.tsx +132 -49
- package/src/drag-handle.tsx +23 -24
- package/src/formats/date.ts +120 -56
- package/src/formats/formats.test.ts +8 -4
- package/src/formats/object.ts +120 -56
- package/src/formats/plain-date-time.ts +120 -56
- package/src/formats/plain-date.ts +120 -56
- package/src/formats/plain-month-day.ts +120 -56
- package/src/formats/plain-year-month.ts +120 -56
- package/src/formats/zoned-date-time.ts +120 -56
- package/src/grid-header.tsx +24 -18
- package/src/grid.event-perf.test.tsx +30 -13
- package/src/grid.perf.test.tsx +97 -33
- package/src/grid.tsx +75 -43
- package/src/index.ts +16 -4
- package/src/keyboard.test.ts +110 -42
- package/src/keyboard.ts +18 -7
- package/src/month-separator.test.tsx +3 -1
- package/src/month-separator.tsx +30 -9
- package/src/month-view-context.ts +8 -3
- package/src/month-view-types.ts +14 -10
- package/src/month-view.test.tsx +687 -68
- package/src/month-view.tsx +176 -71
- package/src/navigation.tsx +77 -47
- package/src/overflow.test.ts +15 -13
- package/src/overflow.ts +10 -2
- package/src/range-preview.tsx +37 -12
- package/src/resolve-first-week.test.ts +14 -10
- package/src/resolve-first-week.ts +6 -2
- package/src/root-selection.ts +185 -101
- package/src/selected-range.tsx +47 -22
- package/src/test-temporal.ts +0 -2
- package/src/types.ts +126 -103
- package/src/utils.bench.ts +30 -6
- package/src/utils.test.ts +203 -55
- package/src/utils.ts +156 -54
- package/src/view-context.ts +4 -1
- package/src/week-number.tsx +5 -8
- package/src/weeks-grid.tsx +45 -19
- package/src/weeks-keyboard.test.ts +6 -7
- package/src/weeks-keyboard.ts +8 -3
- package/src/weeks-navigation.tsx +21 -9
- package/src/weeks-view-context.ts +8 -3
- package/src/weeks-view-state.ts +100 -33
- package/src/weeks-view-types.ts +14 -8
- package/src/weeks-view.test.tsx +127 -19
- package/src/weeks-view.tsx +30 -12
- package/src/temporal-polyfill.test.ts +0 -317
- package/src/temporal-polyfill.ts +0 -566
|
@@ -22,25 +22,21 @@ function useCalendarState() {
|
|
|
22
22
|
//#endregion
|
|
23
23
|
//#region src/utils.ts
|
|
24
24
|
/**
|
|
25
|
-
* Returns the default calendar system for a given locale (e.g. `"gregory"` for `"en-US"`).
|
|
26
|
-
*
|
|
27
|
-
* @param locale - A BCP 47 locale string. Falls back to the runtime default when empty.
|
|
28
|
-
*/
|
|
29
|
-
function calendarForLocale(locale) {
|
|
30
|
-
return new Intl.DateTimeFormat(locale || void 0).resolvedOptions().calendar;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
25
|
* Resolves a {@link TemporalNamespace} instance.
|
|
34
26
|
*
|
|
35
|
-
* Returns `provided` when given, otherwise
|
|
36
|
-
*
|
|
27
|
+
* Returns `provided` when given, otherwise native `globalThis.Temporal`. This
|
|
28
|
+
* library does not bundle a `Temporal` implementation — if neither is
|
|
29
|
+
* available, it throws. Provide one via the `temporal` prop, e.g. the
|
|
30
|
+
* `Temporal` export from `temporal-polyfill`
|
|
31
|
+
* (https://github.com/fullcalendar/temporal-polyfill) or `@js-temporal/polyfill`
|
|
32
|
+
* (https://github.com/js-temporal/temporal-polyfill).
|
|
37
33
|
*
|
|
38
34
|
* @param provided - An explicit Temporal polyfill or namespace.
|
|
39
35
|
*/
|
|
40
36
|
function resolveTemporal(provided) {
|
|
41
37
|
if (provided) return provided;
|
|
42
38
|
if (typeof globalThis !== "undefined" && globalThis.Temporal) return globalThis.Temporal;
|
|
43
|
-
throw new Error("DatePicker: Temporal is not available. Pass a Temporal
|
|
39
|
+
throw new Error("DatePicker: Temporal is not available. Pass a Temporal implementation via the `temporal` prop — e.g. `temporal-polyfill` or `@js-temporal/polyfill` — or run where the native Temporal API exists.");
|
|
44
40
|
}
|
|
45
41
|
/**
|
|
46
42
|
* Returns the IANA time zone identifier of the host environment (e.g. `"America/New_York"`).
|
|
@@ -261,6 +257,40 @@ function computeAdjacentMonth(current, direction, T) {
|
|
|
261
257
|
};
|
|
262
258
|
}
|
|
263
259
|
/**
|
|
260
|
+
* Computes the new first-visible month after the **minimum** shift needed to
|
|
261
|
+
* bring `focused` into a window of `numberOfMonths` months that currently
|
|
262
|
+
* starts at `start`.
|
|
263
|
+
*
|
|
264
|
+
* - Already visible → returns `start` unchanged (by value).
|
|
265
|
+
* - Before the window → `focused` becomes the first (leftmost) pane.
|
|
266
|
+
* - After the window → `focused` becomes the last (rightmost) pane.
|
|
267
|
+
*
|
|
268
|
+
* This keeps keyboard focus-crossing symmetric with single-month stepping: a
|
|
269
|
+
* Gregorian-style window only ever scrolls as far as it must, never jumping
|
|
270
|
+
* the focused month to the leftmost slot. Pure month arithmetic — calendar
|
|
271
|
+
* agnostic, since `{year, month}` indices are computed by the caller.
|
|
272
|
+
*
|
|
273
|
+
* @param start - The current first-visible month.
|
|
274
|
+
* @param focused - The month that must become visible.
|
|
275
|
+
* @param numberOfMonths - Number of month panes displayed (>= 1).
|
|
276
|
+
*/
|
|
277
|
+
function shiftWindowToMonth(start, focused, numberOfMonths) {
|
|
278
|
+
const startIndex = start.year * 12 + (start.month - 1);
|
|
279
|
+
const focusedIndex = focused.year * 12 + (focused.month - 1);
|
|
280
|
+
if (focusedIndex < startIndex) return {
|
|
281
|
+
year: focused.year,
|
|
282
|
+
month: focused.month
|
|
283
|
+
};
|
|
284
|
+
if (focusedIndex > startIndex + numberOfMonths - 1) {
|
|
285
|
+
const newStartIndex = focusedIndex - (numberOfMonths - 1);
|
|
286
|
+
return {
|
|
287
|
+
year: Math.floor(newStartIndex / 12),
|
|
288
|
+
month: newStartIndex % 12 + 1
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
return start;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
264
294
|
* Determines the focused date after navigating to a new month.
|
|
265
295
|
*
|
|
266
296
|
* If `currentFocused` is already within `targetMonth`, it is preserved.
|
|
@@ -280,7 +310,8 @@ function focusedDateForMonth(currentFocused, targetMonth, firstDay) {
|
|
|
280
310
|
* Priority when `gridHasFocus` is `true` (keyboard navigation):
|
|
281
311
|
* 1. `focusedDate` if it exists in the grid.
|
|
282
312
|
* 2. `selectedDate` if it exists in the grid.
|
|
283
|
-
* 3. First enabled day of `currentMonth`,
|
|
313
|
+
* 3. First enabled day of `currentMonth`, then first grid day, then
|
|
314
|
+
* `focusedDate` itself (empty grid) as last resorts.
|
|
284
315
|
*
|
|
285
316
|
* When `gridHasFocus` is `false` (tab-in), `selectedDate` takes priority
|
|
286
317
|
* over `focusedDate`.
|
|
@@ -299,7 +330,7 @@ function resolveFocusTarget(focusedDate, selectedDate, weeks, currentMonth, isDa
|
|
|
299
330
|
if (gridHasFocus && inGrid(focusedDate)) return focusedDate;
|
|
300
331
|
if (selectedDate && inGrid(selectedDate)) return selectedDate;
|
|
301
332
|
if (!gridHasFocus && inGrid(focusedDate)) return focusedDate;
|
|
302
|
-
return allDays.find((d) => d.year === currentMonth.year && d.month === currentMonth.month && !isDateDisabled(d)) ?? allDays[0];
|
|
333
|
+
return allDays.find((d) => d.year === currentMonth.year && d.month === currentMonth.month && !isDateDisabled(d)) ?? allDays[0] ?? focusedDate;
|
|
303
334
|
}
|
|
304
335
|
/**
|
|
305
336
|
* Determines whether a day cell should imperatively receive DOM focus.
|
|
@@ -333,6 +364,13 @@ function isInRange(date, rangeStart, rangeEnd, T) {
|
|
|
333
364
|
if (totalDays === 0) return 0;
|
|
334
365
|
return date.since(effectiveStart).days / totalDays;
|
|
335
366
|
}
|
|
367
|
+
const INACTIVE_RANGE_INFO = {
|
|
368
|
+
active: false,
|
|
369
|
+
startIndex: -1,
|
|
370
|
+
endIndex: -1,
|
|
371
|
+
extendsBefore: false,
|
|
372
|
+
extendsAfter: false
|
|
373
|
+
};
|
|
336
374
|
/**
|
|
337
375
|
* Computes how a date range intersects with a single calendar week row.
|
|
338
376
|
*
|
|
@@ -347,31 +385,24 @@ function isInRange(date, rangeStart, rangeEnd, T) {
|
|
|
347
385
|
* `extendsBefore` / `extendsAfter` (whether the range continues beyond the week).
|
|
348
386
|
*/
|
|
349
387
|
function computeWeekRangeInfo(weekDays, rangeStart, rangeEnd, T) {
|
|
350
|
-
|
|
351
|
-
active: false,
|
|
352
|
-
startIndex: 0,
|
|
353
|
-
endIndex: 0,
|
|
354
|
-
extendsBefore: false,
|
|
355
|
-
extendsAfter: false
|
|
356
|
-
};
|
|
357
|
-
if (weekDays.length === 0) return inactive;
|
|
358
|
-
if (!rangeStart && !rangeEnd) return inactive;
|
|
359
|
-
const effectiveStart = rangeStart ?? rangeEnd;
|
|
360
|
-
const effectiveEnd = rangeEnd ?? rangeStart;
|
|
388
|
+
if (!rangeStart && !rangeEnd) return INACTIVE_RANGE_INFO;
|
|
361
389
|
const weekStart = weekDays[0];
|
|
362
390
|
const weekEnd = weekDays[weekDays.length - 1];
|
|
363
|
-
if (
|
|
391
|
+
if (!weekStart || !weekEnd) return INACTIVE_RANGE_INFO;
|
|
392
|
+
const effectiveStart = rangeStart ?? rangeEnd;
|
|
393
|
+
const effectiveEnd = rangeEnd ?? rangeStart;
|
|
394
|
+
if (T.PlainDate.compare(effectiveEnd, weekStart) < 0 || T.PlainDate.compare(effectiveStart, weekEnd) > 0) return INACTIVE_RANGE_INFO;
|
|
364
395
|
const extendsBefore = T.PlainDate.compare(effectiveStart, weekStart) < 0;
|
|
365
396
|
const extendsAfter = T.PlainDate.compare(effectiveEnd, weekEnd) > 0;
|
|
366
397
|
let startIndex = 0;
|
|
367
398
|
if (!extendsBefore) {
|
|
368
399
|
startIndex = weekDays.findIndex((d) => T.PlainDate.compare(d, effectiveStart) === 0);
|
|
369
|
-
if (startIndex === -1) return
|
|
400
|
+
if (startIndex === -1) return INACTIVE_RANGE_INFO;
|
|
370
401
|
}
|
|
371
402
|
let endIndex = weekDays.length - 1;
|
|
372
403
|
if (!extendsAfter) {
|
|
373
404
|
endIndex = weekDays.findIndex((d) => T.PlainDate.compare(d, effectiveEnd) === 0);
|
|
374
|
-
if (endIndex === -1) return
|
|
405
|
+
if (endIndex === -1) return INACTIVE_RANGE_INFO;
|
|
375
406
|
}
|
|
376
407
|
return {
|
|
377
408
|
active: true,
|
|
@@ -387,7 +418,9 @@ function computeWeekRangeInfo(weekDays, rangeStart, rangeEnd, T) {
|
|
|
387
418
|
* @param locale - BCP 47 locale string (e.g. `"en-US"`).
|
|
388
419
|
* @param T - Temporal namespace.
|
|
389
420
|
* @param weekStartDay - 0=Sunday (default), 1=Monday, etc.
|
|
390
|
-
* @returns An array of
|
|
421
|
+
* @returns An array of objects with `long`, `short`, and `narrow` name variants,
|
|
422
|
+
* one per day in the calendar's week (typically 7, but may differ for
|
|
423
|
+
* non-Gregorian calendars).
|
|
391
424
|
*/
|
|
392
425
|
function getWeekdayNames(locale, T, weekStartDay = 0) {
|
|
393
426
|
const refStart = getReferenceWeekStart(T, weekStartDay);
|
|
@@ -529,8 +562,8 @@ function computeSelectionUpdate(opts) {
|
|
|
529
562
|
if (isComplete) {
|
|
530
563
|
const start = committedDates[0];
|
|
531
564
|
const end = committedDates[1];
|
|
532
|
-
const isOnStart = T.PlainDate.compare(date, start) === 0;
|
|
533
|
-
const isOnEnd = T.PlainDate.compare(date, end) === 0;
|
|
565
|
+
const isOnStart = start != null && T.PlainDate.compare(date, start) === 0;
|
|
566
|
+
const isOnEnd = end != null && T.PlainDate.compare(date, end) === 0;
|
|
534
567
|
if (isOnStart || isOnEnd) return {
|
|
535
568
|
newDates: [],
|
|
536
569
|
fireCallback: (onValueChange) => {
|
|
@@ -579,19 +612,31 @@ function computeSelectionUpdate(opts) {
|
|
|
579
612
|
}
|
|
580
613
|
const beforeStart = T.PlainDate.compare(date, committedStart) < 0;
|
|
581
614
|
const afterEnd = T.PlainDate.compare(date, committedEnd) > 0;
|
|
582
|
-
let
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
615
|
+
let newStart;
|
|
616
|
+
let newEnd;
|
|
617
|
+
if (beforeStart) {
|
|
618
|
+
newStart = date;
|
|
619
|
+
newEnd = committedEnd;
|
|
620
|
+
} else if (afterEnd) {
|
|
621
|
+
newStart = committedStart;
|
|
622
|
+
newEnd = date;
|
|
623
|
+
} else {
|
|
586
624
|
const action = resolveInsideAction(rangeMode, date, committedStart, committedEnd);
|
|
587
|
-
if (action === "start")
|
|
588
|
-
|
|
589
|
-
|
|
625
|
+
if (action === "start") {
|
|
626
|
+
newStart = date;
|
|
627
|
+
newEnd = committedEnd;
|
|
628
|
+
} else if (action === "end") {
|
|
629
|
+
newStart = committedStart;
|
|
630
|
+
newEnd = date;
|
|
631
|
+
} else {
|
|
632
|
+
newStart = date;
|
|
633
|
+
newEnd = date;
|
|
634
|
+
}
|
|
590
635
|
}
|
|
591
636
|
return {
|
|
592
|
-
newDates,
|
|
637
|
+
newDates: [newStart, newEnd],
|
|
593
638
|
fireCallback: (onValueChange, plainToFormatValue) => {
|
|
594
|
-
onValueChange?.(mkRange(plainToFormatValue(
|
|
639
|
+
onValueChange?.(mkRange(plainToFormatValue(newStart), plainToFormatValue(newEnd)), {
|
|
595
640
|
date,
|
|
596
641
|
previous: prevRange
|
|
597
642
|
});
|
|
@@ -600,11 +645,10 @@ function computeSelectionUpdate(opts) {
|
|
|
600
645
|
}
|
|
601
646
|
if (isRange) {
|
|
602
647
|
const prevRange = currentRangeFormatted();
|
|
603
|
-
const newDates = [date, date];
|
|
604
648
|
return {
|
|
605
|
-
newDates,
|
|
649
|
+
newDates: [date, date],
|
|
606
650
|
fireCallback: (onValueChange, plainToFormatValue) => {
|
|
607
|
-
onValueChange?.(mkRange(plainToFormatValue(
|
|
651
|
+
onValueChange?.(mkRange(plainToFormatValue(date), plainToFormatValue(date)), {
|
|
608
652
|
date,
|
|
609
653
|
previous: prevRange
|
|
610
654
|
});
|
|
@@ -1128,9 +1172,9 @@ function CalendarProvider(props) {
|
|
|
1128
1172
|
selectionMode,
|
|
1129
1173
|
disabled,
|
|
1130
1174
|
readOnly,
|
|
1131
|
-
isDateDisabled,
|
|
1132
|
-
minValue,
|
|
1133
|
-
maxValue,
|
|
1175
|
+
...isDateDisabled !== void 0 && { isDateDisabled },
|
|
1176
|
+
...minValue !== void 0 && { minValue },
|
|
1177
|
+
...maxValue !== void 0 && { maxValue },
|
|
1134
1178
|
timeZone,
|
|
1135
1179
|
locale,
|
|
1136
1180
|
temporal: T,
|
|
@@ -1157,6 +1201,23 @@ function CalendarProvider(props) {
|
|
|
1157
1201
|
resolvedFormat,
|
|
1158
1202
|
setHoveredDate
|
|
1159
1203
|
]);
|
|
1204
|
+
const baseRootState = useMemo(() => ({
|
|
1205
|
+
hasSelection: nonNullDates.length > 0,
|
|
1206
|
+
selected: nonNullDates[0],
|
|
1207
|
+
selectedDates: nonNullDates,
|
|
1208
|
+
rangeStart,
|
|
1209
|
+
rangeEnd,
|
|
1210
|
+
timeZone,
|
|
1211
|
+
locale,
|
|
1212
|
+
readOnly
|
|
1213
|
+
}), [
|
|
1214
|
+
nonNullDates,
|
|
1215
|
+
rangeStart,
|
|
1216
|
+
rangeEnd,
|
|
1217
|
+
timeZone,
|
|
1218
|
+
locale,
|
|
1219
|
+
readOnly
|
|
1220
|
+
]);
|
|
1160
1221
|
const stateCtx = useMemo(() => ({
|
|
1161
1222
|
selected,
|
|
1162
1223
|
selectedDates: nonNullDates,
|
|
@@ -1164,7 +1225,8 @@ function CalendarProvider(props) {
|
|
|
1164
1225
|
rangeEnd,
|
|
1165
1226
|
hoveredDate,
|
|
1166
1227
|
previewStart,
|
|
1167
|
-
previewEnd
|
|
1228
|
+
previewEnd,
|
|
1229
|
+
baseRootState
|
|
1168
1230
|
}), [
|
|
1169
1231
|
selected,
|
|
1170
1232
|
nonNullDates,
|
|
@@ -1172,7 +1234,8 @@ function CalendarProvider(props) {
|
|
|
1172
1234
|
rangeEnd,
|
|
1173
1235
|
hoveredDate,
|
|
1174
1236
|
previewStart,
|
|
1175
|
-
previewEnd
|
|
1237
|
+
previewEnd,
|
|
1238
|
+
baseRootState
|
|
1176
1239
|
]);
|
|
1177
1240
|
return /* @__PURE__ */ jsx(CalendarStableContext.Provider, {
|
|
1178
1241
|
value: stableCtx,
|
|
@@ -1221,7 +1284,7 @@ function MonthViewRoot(props) {
|
|
|
1221
1284
|
const calStable = useCalendarStable();
|
|
1222
1285
|
const calState = useCalendarState();
|
|
1223
1286
|
const T = calStable.temporal;
|
|
1224
|
-
const { timeZone,
|
|
1287
|
+
const { timeZone, weekStartDay, isDateDisabled } = calStable;
|
|
1225
1288
|
const isMonthControlled = monthProp !== void 0;
|
|
1226
1289
|
const [internalMonth, setInternalMonth] = useState(() => {
|
|
1227
1290
|
if (monthProp) return {
|
|
@@ -1271,34 +1334,87 @@ function MonthViewRoot(props) {
|
|
|
1271
1334
|
};
|
|
1272
1335
|
});
|
|
1273
1336
|
}, []);
|
|
1337
|
+
const onMonthChangeRef = useRef(onMonthChange);
|
|
1338
|
+
onMonthChangeRef.current = onMonthChange;
|
|
1339
|
+
const notifyMonth = useCallback((year, month) => {
|
|
1340
|
+
onMonthChangeRef.current?.(T.PlainYearMonth.from({
|
|
1341
|
+
year,
|
|
1342
|
+
month
|
|
1343
|
+
}));
|
|
1344
|
+
}, [T]);
|
|
1345
|
+
const isMonthVisible = useCallback((targetYear, targetMonth) => {
|
|
1346
|
+
for (let i = 0; i < numberOfMonths; i++) {
|
|
1347
|
+
const totalMonths = currentMonth.year * 12 + (currentMonth.month - 1) + i;
|
|
1348
|
+
const y = Math.floor(totalMonths / 12);
|
|
1349
|
+
const m = totalMonths % 12 + 1;
|
|
1350
|
+
if (targetYear === y && targetMonth === m) return true;
|
|
1351
|
+
}
|
|
1352
|
+
return false;
|
|
1353
|
+
}, [
|
|
1354
|
+
currentMonth.year,
|
|
1355
|
+
currentMonth.month,
|
|
1356
|
+
numberOfMonths
|
|
1357
|
+
]);
|
|
1274
1358
|
const navigateToMonth = useCallback((targetYear, targetMonth) => {
|
|
1275
1359
|
if (isMonthControlled) return;
|
|
1276
1360
|
setInternalMonth((prev) => {
|
|
1277
|
-
|
|
1278
|
-
const totalMonths = prev.year * 12 + (prev.month - 1) + i;
|
|
1279
|
-
const y = Math.floor(totalMonths / 12);
|
|
1280
|
-
const m = totalMonths % 12 + 1;
|
|
1281
|
-
if (targetYear === y && targetMonth === m) return prev;
|
|
1282
|
-
}
|
|
1283
|
-
return {
|
|
1361
|
+
const next = shiftWindowToMonth(prev, {
|
|
1284
1362
|
year: targetYear,
|
|
1285
1363
|
month: targetMonth
|
|
1286
|
-
};
|
|
1364
|
+
}, numberOfMonths);
|
|
1365
|
+
if (next.year === prev.year && next.month === prev.month) return prev;
|
|
1366
|
+
return next;
|
|
1287
1367
|
});
|
|
1288
1368
|
}, [isMonthControlled, numberOfMonths]);
|
|
1369
|
+
const skipFocusSyncForRef = useRef(null);
|
|
1370
|
+
const prevFocusedRef = useRef(focusedDate);
|
|
1289
1371
|
useEffect(() => {
|
|
1372
|
+
skipFocusSyncForRef.current = null;
|
|
1373
|
+
}, [monthProp?.year, monthProp?.month]);
|
|
1374
|
+
useEffect(() => {
|
|
1375
|
+
const prevFocused = prevFocusedRef.current;
|
|
1376
|
+
prevFocusedRef.current = focusedDate;
|
|
1377
|
+
if (isMonthControlled) {
|
|
1378
|
+
if (skipFocusSyncForRef.current === focusedDate) {
|
|
1379
|
+
skipFocusSyncForRef.current = null;
|
|
1380
|
+
return;
|
|
1381
|
+
}
|
|
1382
|
+
if (prevFocused === focusedDate) return;
|
|
1383
|
+
if (isMonthVisible(focusedDate.year, focusedDate.month)) return;
|
|
1384
|
+
const next = shiftWindowToMonth({
|
|
1385
|
+
year: currentMonth.year,
|
|
1386
|
+
month: currentMonth.month
|
|
1387
|
+
}, {
|
|
1388
|
+
year: focusedDate.year,
|
|
1389
|
+
month: focusedDate.month
|
|
1390
|
+
}, numberOfMonths);
|
|
1391
|
+
notifyMonth(next.year, next.month);
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1290
1394
|
navigateToMonth(focusedDate.year, focusedDate.month);
|
|
1291
|
-
}, [
|
|
1395
|
+
}, [
|
|
1396
|
+
focusedDate,
|
|
1397
|
+
navigateToMonth,
|
|
1398
|
+
isMonthControlled,
|
|
1399
|
+
isMonthVisible,
|
|
1400
|
+
notifyMonth,
|
|
1401
|
+
currentMonth.year,
|
|
1402
|
+
currentMonth.month,
|
|
1403
|
+
numberOfMonths
|
|
1404
|
+
]);
|
|
1292
1405
|
const goNextMonth = useCallback(() => {
|
|
1293
1406
|
if (isMonthControlled) {
|
|
1294
1407
|
const { year, month, firstDay } = computeAdjacentMonth({
|
|
1295
1408
|
year: monthProp.year,
|
|
1296
1409
|
month: monthProp.month
|
|
1297
1410
|
}, "next", T);
|
|
1298
|
-
|
|
1411
|
+
const nextFocus = focusedDateForMonth(focusedDate, {
|
|
1299
1412
|
year,
|
|
1300
1413
|
month
|
|
1301
|
-
}, firstDay)
|
|
1414
|
+
}, firstDay);
|
|
1415
|
+
skipFocusSyncForRef.current = nextFocus;
|
|
1416
|
+
notifyMonth(year, month);
|
|
1417
|
+
setFocusedDate(nextFocus);
|
|
1302
1418
|
return;
|
|
1303
1419
|
}
|
|
1304
1420
|
setInternalMonth((m) => {
|
|
@@ -1315,7 +1431,9 @@ function MonthViewRoot(props) {
|
|
|
1315
1431
|
}, [
|
|
1316
1432
|
T,
|
|
1317
1433
|
isMonthControlled,
|
|
1318
|
-
monthProp
|
|
1434
|
+
monthProp,
|
|
1435
|
+
notifyMonth,
|
|
1436
|
+
focusedDate
|
|
1319
1437
|
]);
|
|
1320
1438
|
const goPrevMonth = useCallback(() => {
|
|
1321
1439
|
if (isMonthControlled) {
|
|
@@ -1323,10 +1441,13 @@ function MonthViewRoot(props) {
|
|
|
1323
1441
|
year: monthProp.year,
|
|
1324
1442
|
month: monthProp.month
|
|
1325
1443
|
}, "prev", T);
|
|
1326
|
-
|
|
1444
|
+
const nextFocus = focusedDateForMonth(focusedDate, {
|
|
1327
1445
|
year,
|
|
1328
1446
|
month
|
|
1329
|
-
}, firstDay)
|
|
1447
|
+
}, firstDay);
|
|
1448
|
+
skipFocusSyncForRef.current = nextFocus;
|
|
1449
|
+
notifyMonth(year, month);
|
|
1450
|
+
setFocusedDate(nextFocus);
|
|
1330
1451
|
return;
|
|
1331
1452
|
}
|
|
1332
1453
|
setInternalMonth((m) => {
|
|
@@ -1343,7 +1464,9 @@ function MonthViewRoot(props) {
|
|
|
1343
1464
|
}, [
|
|
1344
1465
|
T,
|
|
1345
1466
|
isMonthControlled,
|
|
1346
|
-
monthProp
|
|
1467
|
+
monthProp,
|
|
1468
|
+
notifyMonth,
|
|
1469
|
+
focusedDate
|
|
1347
1470
|
]);
|
|
1348
1471
|
const allMonths = useMemo(() => {
|
|
1349
1472
|
const opts = {
|
|
@@ -1370,7 +1493,9 @@ function MonthViewRoot(props) {
|
|
|
1370
1493
|
fixedWeeks,
|
|
1371
1494
|
numberOfMonths
|
|
1372
1495
|
]);
|
|
1373
|
-
const
|
|
1496
|
+
const firstMonth = allMonths[0];
|
|
1497
|
+
if (firstMonth === void 0) throw new Error("MonthView: numberOfMonths must be at least 1.");
|
|
1498
|
+
const weeks = firstMonth.weeks;
|
|
1374
1499
|
const selectedZdt = useMemo(() => selectedToZdt(calState.selected, timeZone, T), [
|
|
1375
1500
|
calState.selected,
|
|
1376
1501
|
timeZone,
|
|
@@ -1402,48 +1527,27 @@ function MonthViewRoot(props) {
|
|
|
1402
1527
|
T,
|
|
1403
1528
|
gridHasFocus
|
|
1404
1529
|
]);
|
|
1405
|
-
const localeCalendar = useMemo(() => calendarForLocale(locale), [locale]);
|
|
1406
1530
|
const viewingYearMonth = useMemo(() => T.PlainYearMonth.from({
|
|
1407
1531
|
year: currentMonth.year,
|
|
1408
|
-
month: currentMonth.month
|
|
1409
|
-
|
|
1410
|
-
}), [
|
|
1411
|
-
currentMonth,
|
|
1412
|
-
T,
|
|
1413
|
-
localeCalendar
|
|
1414
|
-
]);
|
|
1415
|
-
const onMonthChangeRef = useRef(onMonthChange);
|
|
1416
|
-
onMonthChangeRef.current = onMonthChange;
|
|
1532
|
+
month: currentMonth.month
|
|
1533
|
+
}), [currentMonth, T]);
|
|
1417
1534
|
const mountedRef = useRef(false);
|
|
1418
1535
|
useEffect(() => {
|
|
1419
1536
|
if (!mountedRef.current) {
|
|
1420
1537
|
mountedRef.current = true;
|
|
1421
1538
|
return;
|
|
1422
1539
|
}
|
|
1540
|
+
if (isMonthControlled) return;
|
|
1423
1541
|
onMonthChangeRef.current?.(viewingYearMonth);
|
|
1424
|
-
}, [viewingYearMonth]);
|
|
1425
|
-
const { selected, selectedDates, rangeStart, rangeEnd } = calState;
|
|
1542
|
+
}, [viewingYearMonth, isMonthControlled]);
|
|
1426
1543
|
const rootState = useMemo(() => ({
|
|
1427
|
-
|
|
1428
|
-
selected: selected?.value,
|
|
1429
|
-
selectedDates,
|
|
1430
|
-
rangeStart,
|
|
1431
|
-
rangeEnd,
|
|
1544
|
+
...calState.baseRootState,
|
|
1432
1545
|
focused: focusedDate,
|
|
1433
|
-
viewing: viewingYearMonth
|
|
1434
|
-
timeZone,
|
|
1435
|
-
locale,
|
|
1436
|
-
readOnly: calStable.readOnly
|
|
1546
|
+
viewing: viewingYearMonth
|
|
1437
1547
|
}), [
|
|
1438
|
-
|
|
1439
|
-
selected,
|
|
1440
|
-
rangeStart,
|
|
1441
|
-
rangeEnd,
|
|
1548
|
+
calState.baseRootState,
|
|
1442
1549
|
focusedDate,
|
|
1443
|
-
viewingYearMonth
|
|
1444
|
-
timeZone,
|
|
1445
|
-
locale,
|
|
1446
|
-
calStable.readOnly
|
|
1550
|
+
viewingYearMonth
|
|
1447
1551
|
]);
|
|
1448
1552
|
const stableCtx = useMemo(() => ({
|
|
1449
1553
|
numberOfMonths,
|
|
@@ -1538,13 +1642,17 @@ function useGridHeaderCellState(index) {
|
|
|
1538
1642
|
T,
|
|
1539
1643
|
weekStartDay
|
|
1540
1644
|
]);
|
|
1541
|
-
const state = useMemo(() =>
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1645
|
+
const state = useMemo(() => {
|
|
1646
|
+
const names = weekdayNames[index];
|
|
1647
|
+
if (names === void 0) throw new Error(`GridHeaderCell: index must be between 0 and ${weekdayNames.length - 1}, got ${index}.`);
|
|
1648
|
+
return {
|
|
1649
|
+
root: rootState,
|
|
1650
|
+
dayOfWeek: index,
|
|
1651
|
+
long: names.long,
|
|
1652
|
+
short: names.short,
|
|
1653
|
+
narrow: names.narrow
|
|
1654
|
+
};
|
|
1655
|
+
}, [
|
|
1548
1656
|
rootState,
|
|
1549
1657
|
index,
|
|
1550
1658
|
weekdayNames
|
|
@@ -1894,8 +2002,7 @@ function WeeksGrid(props) {
|
|
|
1894
2002
|
const monthBoundaries = useMemo(() => {
|
|
1895
2003
|
const boundaries = [];
|
|
1896
2004
|
const seenMonths = /* @__PURE__ */ new Set();
|
|
1897
|
-
for (
|
|
1898
|
-
const days = weekDaysArrays[i];
|
|
2005
|
+
for (const [i, days] of weekDaysArrays.entries()) {
|
|
1899
2006
|
const isFirstWeek = i === 0;
|
|
1900
2007
|
const monthsInWeek = [];
|
|
1901
2008
|
for (const day of days) {
|
|
@@ -1919,12 +2026,21 @@ function WeeksGrid(props) {
|
|
|
1919
2026
|
const windowEnd = weekDaysArrays[weekDaysArrays.length - 1]?.[6];
|
|
1920
2027
|
const firstDayVisible = windowStart && windowEnd ? T.PlainDate.compare(firstOfMonth, windowStart) >= 0 && T.PlainDate.compare(firstOfMonth, windowEnd) <= 0 : false;
|
|
1921
2028
|
let weeksVisibleBefore = 0;
|
|
1922
|
-
for (let j = i - 1; j >= 0; j--)
|
|
1923
|
-
|
|
2029
|
+
for (let j = i - 1; j >= 0; j--) {
|
|
2030
|
+
const prevDays = weekDaysArrays[j];
|
|
2031
|
+
if (prevDays === void 0) break;
|
|
2032
|
+
if (!prevDays.some((d) => d.month === newMonth && d.year === newYear)) weeksVisibleBefore++;
|
|
2033
|
+
else break;
|
|
2034
|
+
}
|
|
1924
2035
|
let weeksVisibleAfter = 0;
|
|
1925
|
-
for (let j = i; j <
|
|
1926
|
-
|
|
1927
|
-
|
|
2036
|
+
for (let j = i; j < weekDaysArrays.length; j++) {
|
|
2037
|
+
const wDays = weekDaysArrays[j];
|
|
2038
|
+
if (wDays === void 0) break;
|
|
2039
|
+
if (wDays.some((d) => d.month === newMonth && d.year === newYear)) weeksVisibleAfter++;
|
|
2040
|
+
else break;
|
|
2041
|
+
}
|
|
2042
|
+
const lastBoundary = boundaries[boundaries.length - 1];
|
|
2043
|
+
const isNewYear = lastBoundary !== void 0 ? lastBoundary.data.year !== newYear : newMonth === 1;
|
|
1928
2044
|
boundaries.push({
|
|
1929
2045
|
index: i,
|
|
1930
2046
|
data: {
|
|
@@ -1943,9 +2059,9 @@ function WeeksGrid(props) {
|
|
|
1943
2059
|
});
|
|
1944
2060
|
}
|
|
1945
2061
|
}
|
|
1946
|
-
for (
|
|
1947
|
-
const
|
|
1948
|
-
const nextIndex =
|
|
2062
|
+
for (const [b, current] of boundaries.entries()) {
|
|
2063
|
+
const next = boundaries[b + 1];
|
|
2064
|
+
const nextIndex = next !== void 0 ? next.index : weeks.length;
|
|
1949
2065
|
current.data.fullWeeksVisibleAfter = nextIndex - current.index;
|
|
1950
2066
|
current.data.gridRowStart = current.index + 2;
|
|
1951
2067
|
}
|
|
@@ -1968,9 +2084,9 @@ function WeeksGrid(props) {
|
|
|
1968
2084
|
return map;
|
|
1969
2085
|
}, [monthBoundaries]);
|
|
1970
2086
|
const rows = [];
|
|
1971
|
-
for (
|
|
1972
|
-
const week = weeks[i];
|
|
2087
|
+
for (const [i, week] of weeks.entries()) {
|
|
1973
2088
|
const days = weekDaysArrays[i];
|
|
2089
|
+
if (days === void 0) continue;
|
|
1974
2090
|
const separators = boundariesAtIndex.get(i);
|
|
1975
2091
|
if (separators && separatorTemplate.length > 0) for (const separatorData of separators) rows.push(/* @__PURE__ */ jsx(MonthSeparatorDataContext.Provider, {
|
|
1976
2092
|
value: separatorData,
|
|
@@ -2258,11 +2374,37 @@ function DayCellInstanceFn(props) {
|
|
|
2258
2374
|
children: cell
|
|
2259
2375
|
});
|
|
2260
2376
|
}
|
|
2377
|
+
/**
|
|
2378
|
+
* Shallow-compares the arbitrary pass-through props (className, style, event
|
|
2379
|
+
* handlers, data-*, …) that day-cell components spread onto their element.
|
|
2380
|
+
* The explicitly-handled keys (compared separately) are skipped, as is
|
|
2381
|
+
* `children` — a fresh React element every render, never usefully comparable.
|
|
2382
|
+
*/
|
|
2383
|
+
function passThroughPropsEqual(prev, next, handledKeys) {
|
|
2384
|
+
const prevKeys = Object.keys(prev).filter((k) => !handledKeys.has(k));
|
|
2385
|
+
const nextKeys = Object.keys(next).filter((k) => !handledKeys.has(k));
|
|
2386
|
+
if (prevKeys.length !== nextKeys.length) return false;
|
|
2387
|
+
for (const key of prevKeys) if (prev[key] !== next[key]) return false;
|
|
2388
|
+
return true;
|
|
2389
|
+
}
|
|
2390
|
+
const DAY_CELL_HANDLED_KEYS = new Set([
|
|
2391
|
+
"render",
|
|
2392
|
+
"date",
|
|
2393
|
+
"columnIndex",
|
|
2394
|
+
"children",
|
|
2395
|
+
"_derivedState"
|
|
2396
|
+
]);
|
|
2397
|
+
const DAY_BUTTON_HANDLED_KEYS = new Set([
|
|
2398
|
+
"render",
|
|
2399
|
+
"date",
|
|
2400
|
+
"children",
|
|
2401
|
+
"_derivedState"
|
|
2402
|
+
]);
|
|
2261
2403
|
function dayCellInstancePropsAreEqual(prev, next) {
|
|
2262
2404
|
if (prev.date !== next.date || prev.render !== next.render || prev.columnIndex !== next.columnIndex) return false;
|
|
2263
2405
|
const a = prev._derivedState;
|
|
2264
2406
|
const b = next._derivedState;
|
|
2265
|
-
return a.selected === b.selected && a.today === b.today && a.disabled === b.disabled && a.outsideMonth === b.outsideMonth && a.hidden === b.hidden && a.focused === b.focused && a.rangeStart === b.rangeStart && a.rangeEnd === b.rangeEnd && a.inRange === b.inRange && a.rangeIndex === b.rangeIndex && a.rangeLength === b.rangeLength && a.rangeHasStart === b.rangeHasStart && a.rangeHasEnd === b.rangeHasEnd && a.rangePreviewStart === b.rangePreviewStart && a.rangePreviewEnd === b.rangePreviewEnd && a.rangePreviewBoundary === b.rangePreviewBoundary && a.rangePreviewInRange === b.rangePreviewInRange && a.rangePreviewIndex === b.rangePreviewIndex && a.rangePreviewLength === b.rangePreviewLength && a.rangePreviewHasStart === b.rangePreviewHasStart && a.rangePreviewHasEnd === b.rangePreviewHasEnd && a.isTabTarget === b.isTabTarget;
|
|
2407
|
+
return a.selected === b.selected && a.today === b.today && a.disabled === b.disabled && a.outsideMonth === b.outsideMonth && a.hidden === b.hidden && a.focused === b.focused && a.rangeStart === b.rangeStart && a.rangeEnd === b.rangeEnd && a.inRange === b.inRange && a.rangeIndex === b.rangeIndex && a.rangeLength === b.rangeLength && a.rangeHasStart === b.rangeHasStart && a.rangeHasEnd === b.rangeHasEnd && a.rangePreviewStart === b.rangePreviewStart && a.rangePreviewEnd === b.rangePreviewEnd && a.rangePreviewBoundary === b.rangePreviewBoundary && a.rangePreviewInRange === b.rangePreviewInRange && a.rangePreviewIndex === b.rangePreviewIndex && a.rangePreviewLength === b.rangePreviewLength && a.rangePreviewHasStart === b.rangePreviewHasStart && a.rangePreviewHasEnd === b.rangePreviewHasEnd && a.isTabTarget === b.isTabTarget && passThroughPropsEqual(prev, next, DAY_CELL_HANDLED_KEYS);
|
|
2266
2408
|
}
|
|
2267
2409
|
const DayCellInstance = memo(DayCellInstanceFn, dayCellInstancePropsAreEqual);
|
|
2268
2410
|
/**
|
|
@@ -2360,6 +2502,7 @@ function DayButtonInnerFn(props, ref) {
|
|
|
2360
2502
|
}
|
|
2361
2503
|
function dayButtonInnerPropsAreEqual(prev, next) {
|
|
2362
2504
|
if (prev.date !== next.date || prev.render !== next.render) return false;
|
|
2505
|
+
if (!passThroughPropsEqual(prev, next, DAY_BUTTON_HANDLED_KEYS)) return false;
|
|
2363
2506
|
const a = prev._derivedState;
|
|
2364
2507
|
const b = next._derivedState;
|
|
2365
2508
|
if (!a || !b) return a === b;
|
|
@@ -2432,7 +2575,7 @@ function useGridKeyboard() {
|
|
|
2432
2575
|
maxValue,
|
|
2433
2576
|
disabled,
|
|
2434
2577
|
readOnly,
|
|
2435
|
-
isDateDisabled,
|
|
2578
|
+
...isDateDisabled !== void 0 && { isDateDisabled },
|
|
2436
2579
|
T,
|
|
2437
2580
|
weekStartDay
|
|
2438
2581
|
});
|
|
@@ -2472,7 +2615,7 @@ function useWeeksGridKeyboard() {
|
|
|
2472
2615
|
maxValue,
|
|
2473
2616
|
disabled,
|
|
2474
2617
|
readOnly,
|
|
2475
|
-
isDateDisabled,
|
|
2618
|
+
...isDateDisabled !== void 0 && { isDateDisabled },
|
|
2476
2619
|
scrollBy: weeksStable.scrollBy,
|
|
2477
2620
|
T,
|
|
2478
2621
|
weekStartDay
|
|
@@ -2726,8 +2869,12 @@ function WeeksViewGridFn(props, ref) {
|
|
|
2726
2869
|
allMonths: [],
|
|
2727
2870
|
currentDateTime,
|
|
2728
2871
|
gridLabelIds,
|
|
2729
|
-
rootState:
|
|
2730
|
-
}), [
|
|
2872
|
+
rootState: weeksState.rootState
|
|
2873
|
+
}), [
|
|
2874
|
+
currentDateTime,
|
|
2875
|
+
gridLabelIds,
|
|
2876
|
+
weeksState.rootState
|
|
2877
|
+
]);
|
|
2731
2878
|
return /* @__PURE__ */ jsx(MonthViewStableContext.Provider, {
|
|
2732
2879
|
value: monthViewStableShim,
|
|
2733
2880
|
children: /* @__PURE__ */ jsx(MonthViewStateContext.Provider, {
|
|
@@ -2813,15 +2960,19 @@ function WeekTemplate(props) {
|
|
|
2813
2960
|
month: gridMonthCtx.month
|
|
2814
2961
|
} : void 0, [gridMonthCtx]);
|
|
2815
2962
|
const Instance = WeekInstance;
|
|
2816
|
-
return /* @__PURE__ */ jsx(Fragment, { children: weeks.map((weekDays, i) =>
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2963
|
+
return /* @__PURE__ */ jsx(Fragment, { children: weeks.map((weekDays, i) => {
|
|
2964
|
+
const firstDay = weekDays[0];
|
|
2965
|
+
if (firstDay === void 0) return null;
|
|
2966
|
+
return /* @__PURE__ */ jsx(WeekDataContext.Provider, {
|
|
2967
|
+
value: {
|
|
2968
|
+
days: weekDays,
|
|
2969
|
+
weekIndex: i,
|
|
2970
|
+
...gridMonth !== void 0 && { gridMonth },
|
|
2971
|
+
...outerWeekData?.gridRowIndex !== void 0 && { gridRowIndex: outerWeekData.gridRowIndex }
|
|
2972
|
+
},
|
|
2973
|
+
children: /* @__PURE__ */ jsx(Instance, { ...props })
|
|
2974
|
+
}, firstDay.toString());
|
|
2975
|
+
}) });
|
|
2825
2976
|
}
|
|
2826
2977
|
//#endregion
|
|
2827
2978
|
//#region src/navigation.tsx
|
|
@@ -2929,7 +3080,7 @@ const TimeString = forwardRef(TimeStringFn);
|
|
|
2929
3080
|
function MonthYearStringFn(props, ref) {
|
|
2930
3081
|
const { render, locales, options, monthIndex: monthIndexProp, ...otherProps } = props;
|
|
2931
3082
|
const monthIndex = monthIndexProp ?? 0;
|
|
2932
|
-
const { locale } = useCalendarStable();
|
|
3083
|
+
const { locale, temporal: T } = useCalendarStable();
|
|
2933
3084
|
const monthViewStable = useMonthViewStable();
|
|
2934
3085
|
const { currentMonth: currentDateTime, allMonths, rootState } = useMonthViewState();
|
|
2935
3086
|
const { setGridLabelId } = monthViewStable;
|
|
@@ -2945,12 +3096,15 @@ function MonthYearStringFn(props, ref) {
|
|
|
2945
3096
|
const monthData = allMonths[monthIndex];
|
|
2946
3097
|
const displayYear = monthData?.year ?? currentDateTime.year;
|
|
2947
3098
|
const displayMonth = monthData?.month ?? currentDateTime.month;
|
|
2948
|
-
const displayDate = new Date(displayYear, displayMonth - 1, 1);
|
|
2949
3099
|
const defaultOptions = options ?? {
|
|
2950
3100
|
month: "long",
|
|
2951
3101
|
year: "numeric"
|
|
2952
3102
|
};
|
|
2953
|
-
const formatted =
|
|
3103
|
+
const formatted = T.PlainDate.from({
|
|
3104
|
+
year: displayYear,
|
|
3105
|
+
month: displayMonth,
|
|
3106
|
+
day: 1
|
|
3107
|
+
}).toLocaleString(locales ?? locale, defaultOptions);
|
|
2954
3108
|
const state = useMemo(() => ({
|
|
2955
3109
|
root: rootState,
|
|
2956
3110
|
month: displayMonth,
|
|
@@ -2987,7 +3141,7 @@ function MonthYearStringFn(props, ref) {
|
|
|
2987
3141
|
*/
|
|
2988
3142
|
const MonthYearString = forwardRef(MonthYearStringFn);
|
|
2989
3143
|
function useNavButton(direction) {
|
|
2990
|
-
const { disabled: globalDisabled, minValue, maxValue,
|
|
3144
|
+
const { disabled: globalDisabled, minValue, maxValue, temporal: T } = useCalendarStable();
|
|
2991
3145
|
const monthViewStable = useMonthViewStable();
|
|
2992
3146
|
const monthViewState = useMonthViewState();
|
|
2993
3147
|
const { goNextMonth: goToNextMonth, goPrevMonth: goToPrevMonth, numberOfMonths } = monthViewStable;
|
|
@@ -3008,16 +3162,13 @@ function useNavButton(direction) {
|
|
|
3008
3162
|
boundValue,
|
|
3009
3163
|
direction
|
|
3010
3164
|
]);
|
|
3011
|
-
const localeCalendar = useMemo(() => calendarForLocale(locale), [locale]);
|
|
3012
3165
|
const target = useMemo(() => T.PlainYearMonth.from({
|
|
3013
3166
|
year: destYear,
|
|
3014
|
-
month: destMonth
|
|
3015
|
-
calendar: localeCalendar
|
|
3167
|
+
month: destMonth
|
|
3016
3168
|
}), [
|
|
3017
3169
|
destYear,
|
|
3018
3170
|
destMonth,
|
|
3019
|
-
T
|
|
3020
|
-
localeCalendar
|
|
3171
|
+
T
|
|
3021
3172
|
]);
|
|
3022
3173
|
return {
|
|
3023
3174
|
state: useMemo(() => ({
|
|
@@ -3099,11 +3250,15 @@ function computeClippedRangeInfo(days, rangeStart, rangeEnd, T, outsideDays, gri
|
|
|
3099
3250
|
const raw = computeWeekRangeInfo(days, rangeStart, rangeEnd, T);
|
|
3100
3251
|
if ((outsideDays === "disabled" || outsideDays === "hidden") && raw.active && gridMonth) {
|
|
3101
3252
|
let { startIndex, endIndex, extendsBefore, extendsAfter } = raw;
|
|
3102
|
-
|
|
3253
|
+
const inMonth = (i) => {
|
|
3254
|
+
const day = days[i];
|
|
3255
|
+
return day !== void 0 && day.year === gridMonth.year && day.month === gridMonth.month;
|
|
3256
|
+
};
|
|
3257
|
+
while (startIndex <= endIndex && !inMonth(startIndex)) {
|
|
3103
3258
|
startIndex++;
|
|
3104
3259
|
extendsBefore = true;
|
|
3105
3260
|
}
|
|
3106
|
-
while (endIndex >= startIndex && (
|
|
3261
|
+
while (endIndex >= startIndex && !inMonth(endIndex)) {
|
|
3107
3262
|
endIndex--;
|
|
3108
3263
|
extendsAfter = true;
|
|
3109
3264
|
}
|
|
@@ -3158,8 +3313,8 @@ function RangeSelectedInnerFn(props, ref) {
|
|
|
3158
3313
|
outsideDays,
|
|
3159
3314
|
gridMonth
|
|
3160
3315
|
]);
|
|
3161
|
-
const startDate = info.active ? days[info.startIndex]
|
|
3162
|
-
const endDate = info.active ? days[info.endIndex]
|
|
3316
|
+
const startDate = info.active ? days[info.startIndex]?.toString() ?? "" : "";
|
|
3317
|
+
const endDate = info.active ? days[info.endIndex]?.toString() ?? "" : "";
|
|
3163
3318
|
const weekIndex = weekData?.weekIndex ?? 0;
|
|
3164
3319
|
const state = useMemo(() => ({
|
|
3165
3320
|
root: rootState,
|
|
@@ -3233,8 +3388,8 @@ function RangePreviewInnerFn(props, ref) {
|
|
|
3233
3388
|
outsideDays,
|
|
3234
3389
|
gridMonth
|
|
3235
3390
|
]);
|
|
3236
|
-
const startDate = info.active ? days[info.startIndex]
|
|
3237
|
-
const endDate = info.active ? days[info.endIndex]
|
|
3391
|
+
const startDate = info.active ? days[info.startIndex]?.toString() ?? "" : "";
|
|
3392
|
+
const endDate = info.active ? days[info.endIndex]?.toString() ?? "" : "";
|
|
3238
3393
|
const weekIndex = weekData?.weekIndex ?? 0;
|
|
3239
3394
|
const state = useMemo(() => ({
|
|
3240
3395
|
root: rootState,
|
|
@@ -3290,7 +3445,7 @@ function useDragHandle(edge, { dragging: draggingProp }) {
|
|
|
3290
3445
|
const date = cellData?.date;
|
|
3291
3446
|
const outsideDisabled = cellData?.outsideDisabled ?? false;
|
|
3292
3447
|
const isActive = readOnly || disabled || outsideDisabled ? false : edge === "start" ? !!(date && rangeStart && T.PlainDate.compare(date, rangeStart) === 0) : !!(date && rangeEnd && T.PlainDate.compare(date, rangeEnd) === 0);
|
|
3293
|
-
const isDragging =
|
|
3448
|
+
const isDragging = !!draggingProp && isActive;
|
|
3294
3449
|
const handleRef = useRef(null);
|
|
3295
3450
|
return {
|
|
3296
3451
|
state: useMemo(() => ({
|
|
@@ -3371,8 +3526,8 @@ function WeekNumberCellFn(props, ref) {
|
|
|
3371
3526
|
const { temporal: T } = useCalendarStable();
|
|
3372
3527
|
const days = weekData?.days ?? [];
|
|
3373
3528
|
const weekNumber = useMemo(() => {
|
|
3374
|
-
if (days.length === 0) return 0;
|
|
3375
3529
|
let thursday = days[0];
|
|
3530
|
+
if (thursday === void 0) return 0;
|
|
3376
3531
|
for (const d of days) if (d.dayOfWeek === 4) {
|
|
3377
3532
|
thursday = d;
|
|
3378
3533
|
break;
|
|
@@ -3676,8 +3831,8 @@ function useWeeksViewRootState(props) {
|
|
|
3676
3831
|
targetFirstWeek: resolvedFirstWeek,
|
|
3677
3832
|
weekCount,
|
|
3678
3833
|
behavior: overflowBehavior,
|
|
3679
|
-
min: minValue,
|
|
3680
|
-
max: maxValue,
|
|
3834
|
+
...minValue !== void 0 && { min: minValue },
|
|
3835
|
+
...maxValue !== void 0 && { max: maxValue },
|
|
3681
3836
|
weekStartDay,
|
|
3682
3837
|
T
|
|
3683
3838
|
}), [
|
|
@@ -3715,7 +3870,9 @@ function useWeeksViewRootState(props) {
|
|
|
3715
3870
|
]);
|
|
3716
3871
|
const windowInfo = useMemo(() => {
|
|
3717
3872
|
const weeks = adjustedWeeks;
|
|
3718
|
-
|
|
3873
|
+
const firstWeek = weeks[0];
|
|
3874
|
+
const lastWeek = weeks[weeks.length - 1];
|
|
3875
|
+
if (firstWeek === void 0 || lastWeek === void 0) {
|
|
3719
3876
|
const today = T.Now.plainDateISO();
|
|
3720
3877
|
return {
|
|
3721
3878
|
windowStart: today,
|
|
@@ -3727,8 +3884,8 @@ function useWeeksViewRootState(props) {
|
|
|
3727
3884
|
visibleMonths: []
|
|
3728
3885
|
};
|
|
3729
3886
|
}
|
|
3730
|
-
const windowStart =
|
|
3731
|
-
const windowEnd =
|
|
3887
|
+
const windowStart = firstWeek.startDate;
|
|
3888
|
+
const windowEnd = lastWeek.endDate;
|
|
3732
3889
|
const wc = weeks.length;
|
|
3733
3890
|
const dayCount = wc * 7;
|
|
3734
3891
|
let enabledDayCount = 0;
|
|
@@ -3870,8 +4027,8 @@ function useWeeksViewRootState(props) {
|
|
|
3870
4027
|
targetFirstWeek: resolvedFirstWeek.add({ weeks: shift }),
|
|
3871
4028
|
weekCount,
|
|
3872
4029
|
behavior: overflowBehavior,
|
|
3873
|
-
min: minValue,
|
|
3874
|
-
max: maxValue,
|
|
4030
|
+
...minValue !== void 0 && { min: minValue },
|
|
4031
|
+
...maxValue !== void 0 && { max: maxValue },
|
|
3875
4032
|
weekStartDay,
|
|
3876
4033
|
T
|
|
3877
4034
|
}).firstWeek);
|
|
@@ -3891,8 +4048,8 @@ function useWeeksViewRootState(props) {
|
|
|
3891
4048
|
targetFirstWeek: resolvedFirstWeek.subtract({ weeks: shift }),
|
|
3892
4049
|
weekCount,
|
|
3893
4050
|
behavior: overflowBehavior,
|
|
3894
|
-
min: minValue,
|
|
3895
|
-
max: maxValue,
|
|
4051
|
+
...minValue !== void 0 && { min: minValue },
|
|
4052
|
+
...maxValue !== void 0 && { max: maxValue },
|
|
3896
4053
|
weekStartDay,
|
|
3897
4054
|
T
|
|
3898
4055
|
}).firstWeek);
|
|
@@ -3911,8 +4068,8 @@ function useWeeksViewRootState(props) {
|
|
|
3911
4068
|
targetFirstWeek: resolveFirstWeek(resolvedFirstWeek, weekCount, resolveSpec(target), options),
|
|
3912
4069
|
weekCount,
|
|
3913
4070
|
behavior: overflowBehavior,
|
|
3914
|
-
min: minValue,
|
|
3915
|
-
max: maxValue,
|
|
4071
|
+
...minValue !== void 0 && { min: minValue },
|
|
4072
|
+
...maxValue !== void 0 && { max: maxValue },
|
|
3916
4073
|
weekStartDay,
|
|
3917
4074
|
T
|
|
3918
4075
|
}).firstWeek);
|
|
@@ -3937,37 +4094,53 @@ function useWeeksViewRootState(props) {
|
|
|
3937
4094
|
onWindowChangeRef.current?.(windowInfo);
|
|
3938
4095
|
}
|
|
3939
4096
|
}, [windowInfo, T]);
|
|
4097
|
+
const stableCtx = useMemo(() => ({
|
|
4098
|
+
weekCount,
|
|
4099
|
+
scrollBy,
|
|
4100
|
+
overflowBehavior,
|
|
4101
|
+
goNext,
|
|
4102
|
+
goPrev,
|
|
4103
|
+
scrollToWeek,
|
|
4104
|
+
gridFocusedRef,
|
|
4105
|
+
setGridLabelId
|
|
4106
|
+
}), [
|
|
4107
|
+
weekCount,
|
|
4108
|
+
scrollBy,
|
|
4109
|
+
overflowBehavior,
|
|
4110
|
+
goNext,
|
|
4111
|
+
goPrev,
|
|
4112
|
+
scrollToWeek,
|
|
4113
|
+
setGridLabelId
|
|
4114
|
+
]);
|
|
4115
|
+
const rootState = useMemo(() => ({
|
|
4116
|
+
...calState.baseRootState,
|
|
4117
|
+
focused: focusedDate,
|
|
4118
|
+
viewing: T.PlainYearMonth.from({
|
|
4119
|
+
year: currentDateTime.year,
|
|
4120
|
+
month: currentDateTime.month
|
|
4121
|
+
})
|
|
4122
|
+
}), [
|
|
4123
|
+
calState.baseRootState,
|
|
4124
|
+
focusedDate,
|
|
4125
|
+
currentDateTime,
|
|
4126
|
+
T
|
|
4127
|
+
]);
|
|
3940
4128
|
return {
|
|
3941
|
-
stableCtx
|
|
3942
|
-
weekCount,
|
|
3943
|
-
scrollBy,
|
|
3944
|
-
overflowBehavior,
|
|
3945
|
-
goNext,
|
|
3946
|
-
goPrev,
|
|
3947
|
-
scrollToWeek,
|
|
3948
|
-
gridFocusedRef,
|
|
3949
|
-
setGridLabelId
|
|
3950
|
-
}), [
|
|
3951
|
-
weekCount,
|
|
3952
|
-
scrollBy,
|
|
3953
|
-
overflowBehavior,
|
|
3954
|
-
goNext,
|
|
3955
|
-
goPrev,
|
|
3956
|
-
scrollToWeek,
|
|
3957
|
-
setGridLabelId
|
|
3958
|
-
]),
|
|
4129
|
+
stableCtx,
|
|
3959
4130
|
stateCtx: useMemo(() => ({
|
|
3960
4131
|
focusedDate,
|
|
3961
4132
|
windowInfo,
|
|
3962
4133
|
gridLabelIds,
|
|
3963
4134
|
weeks: adjustedWeeks,
|
|
3964
|
-
currentDateTime
|
|
4135
|
+
currentDateTime,
|
|
4136
|
+
rootState
|
|
3965
4137
|
}), [
|
|
3966
4138
|
focusedDate,
|
|
3967
4139
|
windowInfo,
|
|
3968
4140
|
gridLabelIds,
|
|
3969
4141
|
adjustedWeeks,
|
|
3970
|
-
currentDateTime
|
|
4142
|
+
currentDateTime,
|
|
4143
|
+
rootState
|
|
3971
4144
|
]),
|
|
3972
4145
|
viewCtx: useMemo(() => ({
|
|
3973
4146
|
viewType: "weeks",
|
|
@@ -4010,8 +4183,12 @@ function WeeksViewRootFn(props, ref) {
|
|
|
4010
4183
|
allMonths: [],
|
|
4011
4184
|
currentDateTime: stateCtx.currentDateTime,
|
|
4012
4185
|
gridLabelIds: stateCtx.gridLabelIds,
|
|
4013
|
-
rootState:
|
|
4014
|
-
}), [
|
|
4186
|
+
rootState: stateCtx.rootState
|
|
4187
|
+
}), [
|
|
4188
|
+
stateCtx.currentDateTime,
|
|
4189
|
+
stateCtx.gridLabelIds,
|
|
4190
|
+
stateCtx.rootState
|
|
4191
|
+
]);
|
|
4015
4192
|
return /* @__PURE__ */ jsx(MonthViewStableContext.Provider, {
|
|
4016
4193
|
value: monthViewStableShim,
|
|
4017
4194
|
children: /* @__PURE__ */ jsx(MonthViewStateContext.Provider, {
|
|
@@ -4072,10 +4249,10 @@ function useWeeksNavButton(direction, shiftByProp) {
|
|
|
4072
4249
|
currentFirstWeek,
|
|
4073
4250
|
weekCount,
|
|
4074
4251
|
direction: direction === "next" ? 1 : -1,
|
|
4075
|
-
shiftBy: shiftByProp,
|
|
4252
|
+
...shiftByProp !== void 0 && { shiftBy: shiftByProp },
|
|
4076
4253
|
behavior: overflowBehavior,
|
|
4077
|
-
min: minValue,
|
|
4078
|
-
max: maxValue,
|
|
4254
|
+
...minValue !== void 0 && { min: minValue },
|
|
4255
|
+
...maxValue !== void 0 && { max: maxValue },
|
|
4079
4256
|
weekStartDay,
|
|
4080
4257
|
T
|
|
4081
4258
|
});
|
|
@@ -4171,386 +4348,4 @@ function WeekCountFn(props, ref) {
|
|
|
4171
4348
|
*/
|
|
4172
4349
|
const WeekCount = forwardRef(WeekCountFn);
|
|
4173
4350
|
//#endregion
|
|
4174
|
-
|
|
4175
|
-
function daysInMonth(year, month) {
|
|
4176
|
-
return new Date(year, month, 0).getDate();
|
|
4177
|
-
}
|
|
4178
|
-
function toUTC(y, m, d) {
|
|
4179
|
-
return Date.UTC(y, m - 1, d);
|
|
4180
|
-
}
|
|
4181
|
-
function isoWeekday(utcDate) {
|
|
4182
|
-
const dow = utcDate.getUTCDay();
|
|
4183
|
-
return dow === 0 ? 7 : dow;
|
|
4184
|
-
}
|
|
4185
|
-
function pad2(n) {
|
|
4186
|
-
return n < 10 ? `0${n}` : `${n}`;
|
|
4187
|
-
}
|
|
4188
|
-
function clamp(val, min, max) {
|
|
4189
|
-
return val < min ? min : val > max ? max : val;
|
|
4190
|
-
}
|
|
4191
|
-
function parseDateISO(str) {
|
|
4192
|
-
const [datePart] = str.split("T");
|
|
4193
|
-
const [y, m, d] = datePart.split("-").map(Number);
|
|
4194
|
-
return {
|
|
4195
|
-
year: y,
|
|
4196
|
-
month: m,
|
|
4197
|
-
day: d
|
|
4198
|
-
};
|
|
4199
|
-
}
|
|
4200
|
-
function parseDateTimeISO(str) {
|
|
4201
|
-
const [datePart, timePart] = str.split("T");
|
|
4202
|
-
const [y, m, d] = datePart.split("-").map(Number);
|
|
4203
|
-
if (!timePart) return {
|
|
4204
|
-
year: y,
|
|
4205
|
-
month: m,
|
|
4206
|
-
day: d,
|
|
4207
|
-
hour: 0,
|
|
4208
|
-
minute: 0,
|
|
4209
|
-
second: 0
|
|
4210
|
-
};
|
|
4211
|
-
const [h, min, s] = timePart.split(":").map(Number);
|
|
4212
|
-
return {
|
|
4213
|
-
year: y,
|
|
4214
|
-
month: m,
|
|
4215
|
-
day: d,
|
|
4216
|
-
hour: h || 0,
|
|
4217
|
-
minute: min || 0,
|
|
4218
|
-
second: s || 0
|
|
4219
|
-
};
|
|
4220
|
-
}
|
|
4221
|
-
const dtfCache = /* @__PURE__ */ new Map();
|
|
4222
|
-
function getDTF(tz) {
|
|
4223
|
-
let dtf = dtfCache.get(tz);
|
|
4224
|
-
if (!dtf) {
|
|
4225
|
-
dtf = new Intl.DateTimeFormat("en-US", {
|
|
4226
|
-
timeZone: tz,
|
|
4227
|
-
year: "numeric",
|
|
4228
|
-
month: "numeric",
|
|
4229
|
-
day: "numeric",
|
|
4230
|
-
hour: "numeric",
|
|
4231
|
-
minute: "numeric",
|
|
4232
|
-
second: "numeric",
|
|
4233
|
-
hour12: false
|
|
4234
|
-
});
|
|
4235
|
-
dtfCache.set(tz, dtf);
|
|
4236
|
-
}
|
|
4237
|
-
return dtf;
|
|
4238
|
-
}
|
|
4239
|
-
function extractTzParts(epochMs, tz) {
|
|
4240
|
-
const parts = getDTF(tz).formatToParts(new Date(epochMs));
|
|
4241
|
-
const vals = {};
|
|
4242
|
-
for (const p of parts) if (p.type !== "literal") vals[p.type] = Number(p.value);
|
|
4243
|
-
return {
|
|
4244
|
-
year: vals.year,
|
|
4245
|
-
month: vals.month,
|
|
4246
|
-
day: vals.day,
|
|
4247
|
-
hour: vals.hour === 24 ? 0 : vals.hour,
|
|
4248
|
-
minute: vals.minute,
|
|
4249
|
-
second: vals.second
|
|
4250
|
-
};
|
|
4251
|
-
}
|
|
4252
|
-
function wallToEpoch(y, m, d, h, min, s, tz) {
|
|
4253
|
-
const utcGuess = Date.UTC(y, m - 1, d, h, min, s);
|
|
4254
|
-
const inTz = extractTzParts(utcGuess, tz);
|
|
4255
|
-
return utcGuess - (Date.UTC(inTz.year, inTz.month - 1, inTz.day, inTz.hour, inTz.minute, inTz.second) - utcGuess);
|
|
4256
|
-
}
|
|
4257
|
-
var MiniPlainDate = class MiniPlainDate {
|
|
4258
|
-
year;
|
|
4259
|
-
month;
|
|
4260
|
-
day;
|
|
4261
|
-
constructor(year, month, day) {
|
|
4262
|
-
this.year = year;
|
|
4263
|
-
this.month = month;
|
|
4264
|
-
this.day = day;
|
|
4265
|
-
}
|
|
4266
|
-
get dayOfWeek() {
|
|
4267
|
-
return isoWeekday(new Date(toUTC(this.year, this.month, this.day)));
|
|
4268
|
-
}
|
|
4269
|
-
get daysInWeek() {
|
|
4270
|
-
return 7;
|
|
4271
|
-
}
|
|
4272
|
-
get daysInMonth() {
|
|
4273
|
-
return daysInMonth(this.year, this.month);
|
|
4274
|
-
}
|
|
4275
|
-
get monthCode() {
|
|
4276
|
-
return `M${pad2(this.month)}`;
|
|
4277
|
-
}
|
|
4278
|
-
add(dur) {
|
|
4279
|
-
let y = this.year + (dur.years || 0);
|
|
4280
|
-
let m = this.month + (dur.months || 0);
|
|
4281
|
-
while (m > 12) {
|
|
4282
|
-
m -= 12;
|
|
4283
|
-
y += 1;
|
|
4284
|
-
}
|
|
4285
|
-
while (m < 1) {
|
|
4286
|
-
m += 12;
|
|
4287
|
-
y -= 1;
|
|
4288
|
-
}
|
|
4289
|
-
const d = Math.min(this.day, daysInMonth(y, m));
|
|
4290
|
-
const totalDays = (dur.days || 0) + (dur.weeks || 0) * 7;
|
|
4291
|
-
if (totalDays === 0) return new MiniPlainDate(y, m, d);
|
|
4292
|
-
const epoch = toUTC(y, m, d) + totalDays * 864e5;
|
|
4293
|
-
const ud = new Date(epoch);
|
|
4294
|
-
return new MiniPlainDate(ud.getUTCFullYear(), ud.getUTCMonth() + 1, ud.getUTCDate());
|
|
4295
|
-
}
|
|
4296
|
-
subtract(dur) {
|
|
4297
|
-
return this.add({
|
|
4298
|
-
days: dur.days ? -dur.days : void 0,
|
|
4299
|
-
weeks: dur.weeks ? -dur.weeks : void 0,
|
|
4300
|
-
months: dur.months ? -dur.months : void 0,
|
|
4301
|
-
years: dur.years ? -dur.years : void 0
|
|
4302
|
-
});
|
|
4303
|
-
}
|
|
4304
|
-
since(other, _opts) {
|
|
4305
|
-
const thisUTC = toUTC(this.year, this.month, this.day);
|
|
4306
|
-
const otherUTC = toUTC(other.year, other.month, other.day);
|
|
4307
|
-
return { days: Math.round((thisUTC - otherUTC) / 864e5) };
|
|
4308
|
-
}
|
|
4309
|
-
until(other, _opts) {
|
|
4310
|
-
const thisUTC = toUTC(this.year, this.month, this.day);
|
|
4311
|
-
const otherUTC = toUTC(other.year, other.month, other.day);
|
|
4312
|
-
return { days: Math.round((otherUTC - thisUTC) / 864e5) };
|
|
4313
|
-
}
|
|
4314
|
-
equals(other) {
|
|
4315
|
-
return this.year === other.year && this.month === other.month && this.day === other.day;
|
|
4316
|
-
}
|
|
4317
|
-
toString() {
|
|
4318
|
-
return `${String(this.year).padStart(4, "0")}-${pad2(this.month)}-${pad2(this.day)}`;
|
|
4319
|
-
}
|
|
4320
|
-
toZonedDateTime(tz) {
|
|
4321
|
-
const tzId = typeof tz === "string" ? tz : tz.timeZone;
|
|
4322
|
-
return this.toPlainDateTime().toZonedDateTime(tzId);
|
|
4323
|
-
}
|
|
4324
|
-
toPlainDateTime(timeLike) {
|
|
4325
|
-
return new MiniPlainDateTime(this.year, this.month, this.day, timeLike?.hour ?? 0, timeLike?.minute ?? 0, timeLike?.second ?? 0);
|
|
4326
|
-
}
|
|
4327
|
-
toPlainMonthDay() {
|
|
4328
|
-
return new MiniPlainMonthDay(this.month, this.day);
|
|
4329
|
-
}
|
|
4330
|
-
toPlainYearMonth() {
|
|
4331
|
-
return new MiniPlainYearMonth(this.year, this.month);
|
|
4332
|
-
}
|
|
4333
|
-
toLocaleString(locale, options) {
|
|
4334
|
-
return new Date(toUTC(this.year, this.month, this.day)).toLocaleDateString(locale, {
|
|
4335
|
-
timeZone: "UTC",
|
|
4336
|
-
...options
|
|
4337
|
-
});
|
|
4338
|
-
}
|
|
4339
|
-
};
|
|
4340
|
-
var MiniPlainDateTime = class {
|
|
4341
|
-
year;
|
|
4342
|
-
month;
|
|
4343
|
-
day;
|
|
4344
|
-
hour;
|
|
4345
|
-
minute;
|
|
4346
|
-
second;
|
|
4347
|
-
constructor(year, month, day, hour = 0, minute = 0, second = 0) {
|
|
4348
|
-
this.year = year;
|
|
4349
|
-
this.month = month;
|
|
4350
|
-
this.day = day;
|
|
4351
|
-
this.hour = hour;
|
|
4352
|
-
this.minute = minute;
|
|
4353
|
-
this.second = second;
|
|
4354
|
-
}
|
|
4355
|
-
get dayOfWeek() {
|
|
4356
|
-
return isoWeekday(new Date(toUTC(this.year, this.month, this.day)));
|
|
4357
|
-
}
|
|
4358
|
-
get daysInMonth() {
|
|
4359
|
-
return daysInMonth(this.year, this.month);
|
|
4360
|
-
}
|
|
4361
|
-
toZonedDateTime(tz) {
|
|
4362
|
-
const tzId = typeof tz === "string" ? tz : tz.timeZone;
|
|
4363
|
-
return new MiniZonedDateTime(wallToEpoch(this.year, this.month, this.day, this.hour, this.minute, this.second, tzId), tzId);
|
|
4364
|
-
}
|
|
4365
|
-
toPlainDate() {
|
|
4366
|
-
return new MiniPlainDate(this.year, this.month, this.day);
|
|
4367
|
-
}
|
|
4368
|
-
toString() {
|
|
4369
|
-
return `${String(this.year).padStart(4, "0")}-${pad2(this.month)}-${pad2(this.day)}T${pad2(this.hour)}:${pad2(this.minute)}:${pad2(this.second)}`;
|
|
4370
|
-
}
|
|
4371
|
-
};
|
|
4372
|
-
var MiniPlainMonthDay = class {
|
|
4373
|
-
monthCode;
|
|
4374
|
-
month;
|
|
4375
|
-
day;
|
|
4376
|
-
constructor(month, day) {
|
|
4377
|
-
this.month = month;
|
|
4378
|
-
this.day = day;
|
|
4379
|
-
this.monthCode = `M${pad2(month)}`;
|
|
4380
|
-
}
|
|
4381
|
-
toPlainDate(fields) {
|
|
4382
|
-
return new MiniPlainDate(fields.year, this.month, this.day);
|
|
4383
|
-
}
|
|
4384
|
-
equals(other) {
|
|
4385
|
-
return this.month === other.month && this.day === other.day;
|
|
4386
|
-
}
|
|
4387
|
-
toString() {
|
|
4388
|
-
return `${pad2(this.month)}-${pad2(this.day)}`;
|
|
4389
|
-
}
|
|
4390
|
-
};
|
|
4391
|
-
var MiniPlainYearMonth = class MiniPlainYearMonth {
|
|
4392
|
-
year;
|
|
4393
|
-
month;
|
|
4394
|
-
constructor(year, month) {
|
|
4395
|
-
this.year = year;
|
|
4396
|
-
this.month = month;
|
|
4397
|
-
}
|
|
4398
|
-
get monthCode() {
|
|
4399
|
-
return `M${pad2(this.month)}`;
|
|
4400
|
-
}
|
|
4401
|
-
get daysInMonth() {
|
|
4402
|
-
return daysInMonth(this.year, this.month);
|
|
4403
|
-
}
|
|
4404
|
-
toPlainDate(fields) {
|
|
4405
|
-
return new MiniPlainDate(this.year, this.month, fields.day);
|
|
4406
|
-
}
|
|
4407
|
-
add(dur) {
|
|
4408
|
-
let y = this.year + (dur.years || 0);
|
|
4409
|
-
let m = this.month + (dur.months || 0);
|
|
4410
|
-
while (m > 12) {
|
|
4411
|
-
m -= 12;
|
|
4412
|
-
y += 1;
|
|
4413
|
-
}
|
|
4414
|
-
while (m < 1) {
|
|
4415
|
-
m += 12;
|
|
4416
|
-
y -= 1;
|
|
4417
|
-
}
|
|
4418
|
-
return new MiniPlainYearMonth(y, m);
|
|
4419
|
-
}
|
|
4420
|
-
subtract(dur) {
|
|
4421
|
-
return this.add({
|
|
4422
|
-
months: dur.months ? -dur.months : void 0,
|
|
4423
|
-
years: dur.years ? -dur.years : void 0
|
|
4424
|
-
});
|
|
4425
|
-
}
|
|
4426
|
-
equals(other) {
|
|
4427
|
-
return this.year === other.year && this.month === other.month;
|
|
4428
|
-
}
|
|
4429
|
-
toString() {
|
|
4430
|
-
return `${String(this.year).padStart(4, "0")}-${pad2(this.month)}`;
|
|
4431
|
-
}
|
|
4432
|
-
};
|
|
4433
|
-
var MiniZonedDateTime = class {
|
|
4434
|
-
epochMilliseconds;
|
|
4435
|
-
timeZoneId;
|
|
4436
|
-
_parts;
|
|
4437
|
-
constructor(epochMs, timeZoneId) {
|
|
4438
|
-
this.epochMilliseconds = epochMs;
|
|
4439
|
-
this.timeZoneId = timeZoneId;
|
|
4440
|
-
}
|
|
4441
|
-
get parts() {
|
|
4442
|
-
if (!this._parts) this._parts = extractTzParts(this.epochMilliseconds, this.timeZoneId);
|
|
4443
|
-
return this._parts;
|
|
4444
|
-
}
|
|
4445
|
-
get year() {
|
|
4446
|
-
return this.parts.year;
|
|
4447
|
-
}
|
|
4448
|
-
get month() {
|
|
4449
|
-
return this.parts.month;
|
|
4450
|
-
}
|
|
4451
|
-
get day() {
|
|
4452
|
-
return this.parts.day;
|
|
4453
|
-
}
|
|
4454
|
-
get hour() {
|
|
4455
|
-
return this.parts.hour;
|
|
4456
|
-
}
|
|
4457
|
-
get minute() {
|
|
4458
|
-
return this.parts.minute;
|
|
4459
|
-
}
|
|
4460
|
-
get second() {
|
|
4461
|
-
return this.parts.second;
|
|
4462
|
-
}
|
|
4463
|
-
get dayOfWeek() {
|
|
4464
|
-
return isoWeekday(new Date(toUTC(this.year, this.month, this.day)));
|
|
4465
|
-
}
|
|
4466
|
-
toPlainDate() {
|
|
4467
|
-
return new MiniPlainDate(this.year, this.month, this.day);
|
|
4468
|
-
}
|
|
4469
|
-
toPlainDateTime() {
|
|
4470
|
-
return new MiniPlainDateTime(this.year, this.month, this.day, this.hour, this.minute, this.second);
|
|
4471
|
-
}
|
|
4472
|
-
toPlainTime() {
|
|
4473
|
-
return {
|
|
4474
|
-
hour: this.hour,
|
|
4475
|
-
minute: this.minute,
|
|
4476
|
-
second: this.second
|
|
4477
|
-
};
|
|
4478
|
-
}
|
|
4479
|
-
toPlainYearMonth() {
|
|
4480
|
-
return new MiniPlainYearMonth(this.year, this.month);
|
|
4481
|
-
}
|
|
4482
|
-
toString() {
|
|
4483
|
-
return `${String(this.year).padStart(4, "0")}-${pad2(this.month)}-${pad2(this.day)}T${pad2(this.hour)}:${pad2(this.minute)}:${pad2(this.second)}[${this.timeZoneId}]`;
|
|
4484
|
-
}
|
|
4485
|
-
};
|
|
4486
|
-
const PlainDate = {
|
|
4487
|
-
from(item, options) {
|
|
4488
|
-
if (typeof item === "string") {
|
|
4489
|
-
const { year, month, day } = parseDateISO(item);
|
|
4490
|
-
if (options?.overflow === "constrain") return new MiniPlainDate(year, month, clamp(day, 1, daysInMonth(year, month)));
|
|
4491
|
-
return new MiniPlainDate(year, month, day);
|
|
4492
|
-
}
|
|
4493
|
-
const year = item.year;
|
|
4494
|
-
const month = item.month;
|
|
4495
|
-
let day = item.day;
|
|
4496
|
-
if (options?.overflow === "constrain") day = clamp(day, 1, daysInMonth(year, month));
|
|
4497
|
-
return new MiniPlainDate(year, month, day);
|
|
4498
|
-
},
|
|
4499
|
-
compare(a, b) {
|
|
4500
|
-
if (a.year !== b.year) return Math.sign(a.year - b.year);
|
|
4501
|
-
if (a.month !== b.month) return Math.sign(a.month - b.month);
|
|
4502
|
-
if (a.day !== b.day) return Math.sign(a.day - b.day);
|
|
4503
|
-
return 0;
|
|
4504
|
-
}
|
|
4505
|
-
};
|
|
4506
|
-
const PlainDateTime = { from(item, _options) {
|
|
4507
|
-
if (typeof item === "string") {
|
|
4508
|
-
const { year, month, day, hour, minute, second } = parseDateTimeISO(item);
|
|
4509
|
-
return new MiniPlainDateTime(year, month, day, hour, minute, second);
|
|
4510
|
-
}
|
|
4511
|
-
return new MiniPlainDateTime(item.year, item.month, item.day, item.hour ?? 0, item.minute ?? 0, item.second ?? 0);
|
|
4512
|
-
} };
|
|
4513
|
-
const PlainMonthDay = { from(item) {
|
|
4514
|
-
if (typeof item === "string") {
|
|
4515
|
-
const parts = item.split("-").map(Number);
|
|
4516
|
-
if (parts.length >= 3) return new MiniPlainMonthDay(parts[1], parts[2]);
|
|
4517
|
-
return new MiniPlainMonthDay(parts[0], parts[1]);
|
|
4518
|
-
}
|
|
4519
|
-
return new MiniPlainMonthDay(item.month ?? (item.monthCode ? Number.parseInt(item.monthCode.slice(1), 10) : 1), item.day);
|
|
4520
|
-
} };
|
|
4521
|
-
const PlainYearMonth = {
|
|
4522
|
-
from(item) {
|
|
4523
|
-
if (typeof item === "string") {
|
|
4524
|
-
const [y, m] = item.split("-").map(Number);
|
|
4525
|
-
return new MiniPlainYearMonth(y, m);
|
|
4526
|
-
}
|
|
4527
|
-
return new MiniPlainYearMonth(item.year, item.month);
|
|
4528
|
-
},
|
|
4529
|
-
compare(a, b) {
|
|
4530
|
-
if (a.year !== b.year) return Math.sign(a.year - b.year);
|
|
4531
|
-
if (a.month !== b.month) return Math.sign(a.month - b.month);
|
|
4532
|
-
return 0;
|
|
4533
|
-
}
|
|
4534
|
-
};
|
|
4535
|
-
const Now = {
|
|
4536
|
-
timeZoneId() {
|
|
4537
|
-
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
4538
|
-
},
|
|
4539
|
-
zonedDateTimeISO(tz) {
|
|
4540
|
-
return new MiniZonedDateTime(Date.now(), tz ?? Now.timeZoneId());
|
|
4541
|
-
},
|
|
4542
|
-
plainDateISO() {
|
|
4543
|
-
const tz = Now.timeZoneId();
|
|
4544
|
-
const parts = extractTzParts(Date.now(), tz);
|
|
4545
|
-
return new MiniPlainDate(parts.year, parts.month, parts.day);
|
|
4546
|
-
}
|
|
4547
|
-
};
|
|
4548
|
-
const Temporal = {
|
|
4549
|
-
Now,
|
|
4550
|
-
PlainDate,
|
|
4551
|
-
PlainDateTime,
|
|
4552
|
-
PlainMonthDay,
|
|
4553
|
-
PlainYearMonth
|
|
4554
|
-
};
|
|
4555
|
-
//#endregion
|
|
4556
|
-
export { MonthSeparatorMonth as A, MonthViewRoot as B, WeekTemplate as C, useWeeksViewState as D, useWeeksViewStable as E, GridHeaderCell as F, computePreviewRange as G, useMonthViewStable as H, DayCellDataContext as I, useCalendarStable as K, GridContext as L, MonthSeparatorWeekCount as M, MonthSeparatorYear as N, MonthSeparator as O, GridHeader as P, WeekDataContext as R, GridBody as S, DayCellTemplate as T, useMonthViewState as U, useViewContext as V, CalendarProvider as W, MonthYearString as _, WeeksView as a, TimeString as b, resolveFirstWeekSpec as c, WeekNumberHeader as d, RangeEndDragHandle as f, DateString as g, RangeSelected as h, WeekCount as i, MonthSeparatorRow as j, MonthSeparatorCell as k, computeWeeksInWindow as l, RangePreview as m, NextWeeksButton as n, WeeksViewRoot as o, RangeStartDragHandle as p, useCalendarState as q, PrevWeeksButton as r, resolveFirstWeek as s, Temporal as t, WeekNumberCell as u, NextMonthButton as v, DayButton as w, Grid as x, PrevMonthButton as y, MonthView as z };
|
|
4351
|
+
export { MonthSeparatorRow as A, useViewContext as B, DayButton as C, MonthSeparator as D, useWeeksViewState as E, DayCellDataContext as F, useCalendarStable as G, useMonthViewState as H, GridContext as I, useCalendarState as K, WeekDataContext as L, MonthSeparatorYear as M, GridHeader as N, MonthSeparatorCell as O, GridHeaderCell as P, MonthView as R, WeekTemplate as S, useWeeksViewStable as T, CalendarProvider as U, useMonthViewStable as V, computePreviewRange as W, NextMonthButton as _, WeeksViewRoot as a, Grid as b, computeWeeksInWindow as c, RangeEndDragHandle as d, RangeStartDragHandle as f, MonthYearString as g, DateString as h, WeeksView as i, MonthSeparatorWeekCount as j, MonthSeparatorMonth as k, WeekNumberCell as l, RangeSelected as m, PrevWeeksButton as n, resolveFirstWeek as o, RangePreview as p, WeekCount as r, resolveFirstWeekSpec as s, NextWeeksButton as t, WeekNumberHeader as u, PrevMonthButton as v, DayCellTemplate as w, GridBody as x, TimeString as y, MonthViewRoot as z };
|