convex-cms 0.0.2 → 0.0.3
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/admin-dist/nitro.json +15 -0
- package/admin-dist/public/assets/CmsEmptyState-CRswfTzk.js +5 -0
- package/admin-dist/public/assets/CmsPageHeader-CirpXndm.js +1 -0
- package/admin-dist/public/assets/CmsStatusBadge-CbEUpQu-.js +1 -0
- package/admin-dist/public/assets/CmsToolbar-BI2nZOXp.js +1 -0
- package/admin-dist/public/assets/ContentEntryEditor-CBeCyK_m.js +4 -0
- package/admin-dist/public/assets/ErrorState-BIVaWmom.js +1 -0
- package/admin-dist/public/assets/TaxonomyFilter-ChaY6Y_x.js +1 -0
- package/admin-dist/public/assets/_contentTypeId-DQ8k_Rvw.js +1 -0
- package/admin-dist/public/assets/_entryId-CKU_glsK.js +1 -0
- package/admin-dist/public/assets/alert-BXjTqrwQ.js +1 -0
- package/admin-dist/public/assets/badge-hvUOzpVZ.js +1 -0
- package/admin-dist/public/assets/circle-check-big-CF_pR17r.js +1 -0
- package/admin-dist/public/assets/command-DU82cJlt.js +1 -0
- package/admin-dist/public/assets/content-_LXl3pp7.js +1 -0
- package/admin-dist/public/assets/content-types-KjxaXGxY.js +2 -0
- package/admin-dist/public/assets/globals-CS6BZ0zp.css +1 -0
- package/admin-dist/public/assets/index-DNGIZHL-.js +1 -0
- package/admin-dist/public/assets/label-KNtpL71g.js +1 -0
- package/admin-dist/public/assets/link-2-Bw2aI4V4.js +1 -0
- package/admin-dist/public/assets/list-sYepHjt_.js +1 -0
- package/admin-dist/public/assets/main-CKj5yfEi.js +97 -0
- package/admin-dist/public/assets/media-Bkrkffm7.js +1 -0
- package/admin-dist/public/assets/new._contentTypeId-C3LstjNs.js +1 -0
- package/admin-dist/public/assets/plus-DUn8v_Xf.js +1 -0
- package/admin-dist/public/assets/rotate-ccw-DJEoHcRI.js +1 -0
- package/admin-dist/public/assets/scroll-area-DfIlT0in.js +1 -0
- package/admin-dist/public/assets/search-MuAUDJKR.js +1 -0
- package/admin-dist/public/assets/select-BD29IXCI.js +1 -0
- package/admin-dist/public/assets/settings-DmMyn_6A.js +1 -0
- package/admin-dist/public/assets/switch-h3Rrnl5i.js +1 -0
- package/admin-dist/public/assets/tabs-imc8h-Dp.js +1 -0
- package/admin-dist/public/assets/taxonomies-dAsrT65H.js +1 -0
- package/admin-dist/public/assets/textarea-BTy7nwzR.js +1 -0
- package/admin-dist/public/assets/trash-SAWKZZHv.js +1 -0
- package/admin-dist/public/assets/triangle-alert-E52Vfeuh.js +1 -0
- package/admin-dist/public/assets/useBreadcrumbLabel-BECBMCzM.js +1 -0
- package/admin-dist/public/assets/usePermissions-Basjs9BT.js +1 -0
- package/admin-dist/public/favicon.ico +0 -0
- package/admin-dist/server/_chunks/_libs/@date-fns/tz.mjs +217 -0
- package/admin-dist/server/_chunks/_libs/@floating-ui/core.mjs +719 -0
- package/admin-dist/server/_chunks/_libs/@floating-ui/dom.mjs +622 -0
- package/admin-dist/server/_chunks/_libs/@floating-ui/react-dom.mjs +292 -0
- package/admin-dist/server/_chunks/_libs/@floating-ui/utils.mjs +320 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/number.mjs +6 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/primitive.mjs +11 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-arrow.mjs +23 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-avatar.mjs +119 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-checkbox.mjs +270 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-collection.mjs +69 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-compose-refs.mjs +39 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-context.mjs +137 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-dialog.mjs +325 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-direction.mjs +9 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-dismissable-layer.mjs +210 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-dropdown-menu.mjs +253 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-focus-guards.mjs +29 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-focus-scope.mjs +206 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-id.mjs +14 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-label.mjs +23 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-menu.mjs +812 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-popover.mjs +300 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-popper.mjs +286 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-portal.mjs +16 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-presence.mjs +128 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-primitive.mjs +141 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-roving-focus.mjs +224 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-scroll-area.mjs +721 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-select.mjs +1163 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-separator.mjs +28 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-slot.mjs +601 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-switch.mjs +152 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-tabs.mjs +189 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-callback-ref.mjs +11 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-controllable-state.mjs +69 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-effect-event.mjs +1 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-escape-keydown.mjs +17 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-is-hydrated.mjs +15 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-layout-effect.mjs +6 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-previous.mjs +14 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-use-size.mjs +39 -0
- package/admin-dist/server/_chunks/_libs/@radix-ui/react-visually-hidden.mjs +33 -0
- package/admin-dist/server/_chunks/_libs/@tanstack/history.mjs +409 -0
- package/admin-dist/server/_chunks/_libs/@tanstack/react-router.mjs +1711 -0
- package/admin-dist/server/_chunks/_libs/@tanstack/react-store.mjs +56 -0
- package/admin-dist/server/_chunks/_libs/@tanstack/router-core.mjs +4829 -0
- package/admin-dist/server/_chunks/_libs/@tanstack/store.mjs +134 -0
- package/admin-dist/server/_chunks/_libs/react-dom.mjs +10781 -0
- package/admin-dist/server/_chunks/_libs/react.mjs +513 -0
- package/admin-dist/server/_libs/aria-hidden.mjs +122 -0
- package/admin-dist/server/_libs/class-variance-authority.mjs +44 -0
- package/admin-dist/server/_libs/clsx.mjs +16 -0
- package/admin-dist/server/_libs/cmdk.mjs +315 -0
- package/admin-dist/server/_libs/convex.mjs +4841 -0
- package/admin-dist/server/_libs/cookie-es.mjs +58 -0
- package/admin-dist/server/_libs/croner.mjs +1 -0
- package/admin-dist/server/_libs/crossws.mjs +1 -0
- package/admin-dist/server/_libs/date-fns.mjs +1716 -0
- package/admin-dist/server/_libs/detect-node-es.mjs +1 -0
- package/admin-dist/server/_libs/get-nonce.mjs +9 -0
- package/admin-dist/server/_libs/h3-v2.mjs +277 -0
- package/admin-dist/server/_libs/h3.mjs +401 -0
- package/admin-dist/server/_libs/hookable.mjs +1 -0
- package/admin-dist/server/_libs/isbot.mjs +20 -0
- package/admin-dist/server/_libs/lucide-react.mjs +850 -0
- package/admin-dist/server/_libs/ohash.mjs +1 -0
- package/admin-dist/server/_libs/react-day-picker.mjs +2201 -0
- package/admin-dist/server/_libs/react-remove-scroll-bar.mjs +82 -0
- package/admin-dist/server/_libs/react-remove-scroll.mjs +328 -0
- package/admin-dist/server/_libs/react-style-singleton.mjs +69 -0
- package/admin-dist/server/_libs/rou3.mjs +8 -0
- package/admin-dist/server/_libs/seroval-plugins.mjs +58 -0
- package/admin-dist/server/_libs/seroval.mjs +1765 -0
- package/admin-dist/server/_libs/srvx.mjs +719 -0
- package/admin-dist/server/_libs/tailwind-merge.mjs +3010 -0
- package/admin-dist/server/_libs/tiny-invariant.mjs +12 -0
- package/admin-dist/server/_libs/tiny-warning.mjs +5 -0
- package/admin-dist/server/_libs/tslib.mjs +39 -0
- package/admin-dist/server/_libs/ufo.mjs +54 -0
- package/admin-dist/server/_libs/unctx.mjs +1 -0
- package/admin-dist/server/_libs/unstorage.mjs +1 -0
- package/admin-dist/server/_libs/use-callback-ref.mjs +66 -0
- package/admin-dist/server/_libs/use-sidecar.mjs +106 -0
- package/admin-dist/server/_libs/use-sync-external-store.mjs +139 -0
- package/admin-dist/server/_libs/zod.mjs +4223 -0
- package/admin-dist/server/_ssr/CmsEmptyState-DU7-7-mV.mjs +290 -0
- package/admin-dist/server/_ssr/CmsPageHeader-CseW0AHm.mjs +24 -0
- package/admin-dist/server/_ssr/CmsStatusBadge-B_pi4KCp.mjs +127 -0
- package/admin-dist/server/_ssr/CmsToolbar-X75ex6ek.mjs +49 -0
- package/admin-dist/server/_ssr/ContentEntryEditor-CepusRsA.mjs +3720 -0
- package/admin-dist/server/_ssr/ErrorState-cI-bKLez.mjs +89 -0
- package/admin-dist/server/_ssr/TaxonomyFilter-Bwrq0-cz.mjs +188 -0
- package/admin-dist/server/_ssr/_contentTypeId-BqYKEcLr.mjs +379 -0
- package/admin-dist/server/_ssr/_entryId-CRfnqeDf.mjs +161 -0
- package/admin-dist/server/_ssr/_tanstack-start-manifest_v-BwDlABVk.mjs +4 -0
- package/admin-dist/server/_ssr/alert-CVt45UUP.mjs +92 -0
- package/admin-dist/server/_ssr/badge-6BsP37vG.mjs +125 -0
- package/admin-dist/server/_ssr/command-fy8epIKf.mjs +128 -0
- package/admin-dist/server/_ssr/config.server-D7JHDcDv.mjs +117 -0
- package/admin-dist/server/_ssr/content-B5RhL7uW.mjs +532 -0
- package/admin-dist/server/_ssr/content-types-BIOqCQYN.mjs +1166 -0
- package/admin-dist/server/_ssr/index-DHSHDPt1.mjs +193 -0
- package/admin-dist/server/_ssr/index.mjs +1275 -0
- package/admin-dist/server/_ssr/label-C8Dko1j7.mjs +22 -0
- package/admin-dist/server/_ssr/media-CSx3XttC.mjs +1832 -0
- package/admin-dist/server/_ssr/new._contentTypeId-DzanEZQM.mjs +144 -0
- package/admin-dist/server/_ssr/router-DDWcF-kt.mjs +1556 -0
- package/admin-dist/server/_ssr/scroll-area-bjPYwhXN.mjs +59 -0
- package/admin-dist/server/_ssr/select-BUhDDf4T.mjs +142 -0
- package/admin-dist/server/_ssr/settings-DAsxnw2q.mjs +348 -0
- package/admin-dist/server/_ssr/start-HYkvq4Ni.mjs +4 -0
- package/admin-dist/server/_ssr/switch-BgyRtQ1Z.mjs +31 -0
- package/admin-dist/server/_ssr/tabs-DzMdRB1A.mjs +628 -0
- package/admin-dist/server/_ssr/taxonomies-C8j8g5Q5.mjs +915 -0
- package/admin-dist/server/_ssr/textarea-9jNeYJSc.mjs +18 -0
- package/admin-dist/server/_ssr/trash-DYMxwhZB.mjs +291 -0
- package/admin-dist/server/_ssr/useBreadcrumbLabel-FNSAr2Ha.mjs +16 -0
- package/admin-dist/server/_ssr/usePermissions-BJGGahrJ.mjs +68 -0
- package/admin-dist/server/favicon.ico +0 -0
- package/admin-dist/server/index.mjs +627 -0
- package/dist/cli/index.js +0 -0
- package/dist/client/admin-config.d.ts +0 -1
- package/dist/client/admin-config.d.ts.map +1 -1
- package/dist/client/admin-config.js +0 -1
- package/dist/client/admin-config.js.map +1 -1
- package/dist/client/adminApi.d.ts.map +1 -1
- package/dist/client/agentTools.d.ts +1237 -135
- package/dist/client/agentTools.d.ts.map +1 -1
- package/dist/client/agentTools.js +33 -9
- package/dist/client/agentTools.js.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/component.d.ts +9 -0
- package/dist/component/_generated/component.d.ts.map +1 -1
- package/dist/component/mediaAssets.d.ts +35 -0
- package/dist/component/mediaAssets.d.ts.map +1 -1
- package/dist/component/mediaAssets.js +81 -0
- package/dist/component/mediaAssets.js.map +1 -1
- package/dist/test.d.ts.map +1 -1
- package/dist/test.js +2 -1
- package/dist/test.js.map +1 -1
- package/package.json +9 -5
- package/dist/component/auditLog.d.ts +0 -410
- package/dist/component/auditLog.d.ts.map +0 -1
- package/dist/component/auditLog.js +0 -607
- package/dist/component/auditLog.js.map +0 -1
- package/dist/component/types.d.ts +0 -4
- package/dist/component/types.d.ts.map +0 -1
- package/dist/component/types.js +0 -2
- package/dist/component/types.js.map +0 -1
- package/src/cli/commands/admin.ts +0 -104
- package/src/cli/index.ts +0 -21
- package/src/cli/utils/detectConvexUrl.ts +0 -54
- package/src/cli/utils/openBrowser.ts +0 -16
- package/src/client/admin-config.ts +0 -138
- package/src/client/adminApi.ts +0 -942
- package/src/client/agentTools.ts +0 -1311
- package/src/client/argTypes.ts +0 -316
- package/src/client/field-types.ts +0 -187
- package/src/client/index.ts +0 -1301
- package/src/client/queryBuilder.ts +0 -1100
- package/src/client/schema/codegen.ts +0 -500
- package/src/client/schema/defineContentType.ts +0 -501
- package/src/client/schema/index.ts +0 -169
- package/src/client/schema/schemaDrift.ts +0 -574
- package/src/client/schema/typedClient.ts +0 -688
- package/src/client/schema/types.ts +0 -666
- package/src/client/types.ts +0 -723
- package/src/client/workflows.ts +0 -141
- package/src/client/wrapper.ts +0 -4304
- package/src/component/_generated/api.ts +0 -140
- package/src/component/_generated/component.ts +0 -5029
- package/src/component/_generated/dataModel.ts +0 -60
- package/src/component/_generated/server.ts +0 -156
- package/src/component/authorization.ts +0 -647
- package/src/component/authorizationHooks.ts +0 -668
- package/src/component/bulkOperations.ts +0 -687
- package/src/component/contentEntries.ts +0 -1976
- package/src/component/contentEntryMutations.ts +0 -1223
- package/src/component/contentEntryValidation.ts +0 -707
- package/src/component/contentLock.ts +0 -550
- package/src/component/contentTypeMigration.ts +0 -1064
- package/src/component/contentTypeMutations.ts +0 -969
- package/src/component/contentTypes.ts +0 -346
- package/src/component/convex.config.ts +0 -44
- package/src/component/documentTypes.ts +0 -240
- package/src/component/eventEmitter.ts +0 -485
- package/src/component/exportImport.ts +0 -1169
- package/src/component/index.ts +0 -491
- package/src/component/lib/deepReferenceResolver.ts +0 -999
- package/src/component/lib/errors.ts +0 -816
- package/src/component/lib/index.ts +0 -145
- package/src/component/lib/mediaReferenceResolver.ts +0 -495
- package/src/component/lib/metadataExtractor.ts +0 -792
- package/src/component/lib/mutationAuth.ts +0 -199
- package/src/component/lib/queries.ts +0 -79
- package/src/component/lib/ragContentChunker.ts +0 -1371
- package/src/component/lib/referenceResolver.ts +0 -430
- package/src/component/lib/slugGenerator.ts +0 -262
- package/src/component/lib/slugUniqueness.ts +0 -333
- package/src/component/lib/softDelete.ts +0 -44
- package/src/component/localeFallbackChain.ts +0 -673
- package/src/component/localeFields.ts +0 -896
- package/src/component/mediaAssetMutations.ts +0 -725
- package/src/component/mediaAssets.ts +0 -932
- package/src/component/mediaFolderMutations.ts +0 -1046
- package/src/component/mediaUploadMutations.ts +0 -224
- package/src/component/mediaVariantMutations.ts +0 -900
- package/src/component/mediaVariants.ts +0 -793
- package/src/component/ragContentIndexer.ts +0 -1067
- package/src/component/rateLimitHooks.ts +0 -572
- package/src/component/roles.ts +0 -1360
- package/src/component/scheduledPublish.ts +0 -358
- package/src/component/schema.ts +0 -617
- package/src/component/taxonomies.ts +0 -949
- package/src/component/taxonomyMutations.ts +0 -1210
- package/src/component/trash.ts +0 -724
- package/src/component/userContext.ts +0 -898
- package/src/component/validation.ts +0 -1388
- package/src/component/validators.ts +0 -949
- package/src/component/versionMutations.ts +0 -392
- package/src/component/webhookTrigger.ts +0 -1922
- package/src/react/index.ts +0 -898
- package/src/test.ts +0 -1580
|
@@ -0,0 +1,2201 @@
|
|
|
1
|
+
import { a as React, r as reactExports } from "../_chunks/_libs/react.mjs";
|
|
2
|
+
import { e as enUS$1, f as format, a as addDays, b as addMonths, c as addWeeks, d as addYears, g as differenceInCalendarDays, h as differenceInCalendarMonths, i as eachMonthOfInterval, j as eachYearOfInterval, k as endOfISOWeek, l as endOfMonth, m as endOfWeek, n as endOfYear, o as getISOWeek, p as getMonth, q as getYear, r as getWeek, s as isAfter, t as isBefore, u as isDate, v as isSameDay, w as isSameMonth, x as isSameYear, y as max, z as min, A as setMonth, B as setYear, C as startOfDay, D as startOfISOWeek, E as startOfMonth, F as startOfWeek, G as startOfYear } from "./date-fns.mjs";
|
|
3
|
+
import { T as TZDate } from "../_chunks/_libs/@date-fns/tz.mjs";
|
|
4
|
+
const FIVE_WEEKS = 5;
|
|
5
|
+
const FOUR_WEEKS = 4;
|
|
6
|
+
function getBroadcastWeeksInMonth(month, dateLib) {
|
|
7
|
+
const firstDayOfMonth = dateLib.startOfMonth(month);
|
|
8
|
+
const firstDayOfWeek = firstDayOfMonth.getDay() > 0 ? firstDayOfMonth.getDay() : 7;
|
|
9
|
+
const broadcastStartDate = dateLib.addDays(month, -firstDayOfWeek + 1);
|
|
10
|
+
const lastDateOfLastWeek = dateLib.addDays(broadcastStartDate, FIVE_WEEKS * 7 - 1);
|
|
11
|
+
const numberOfWeeks = dateLib.getMonth(month) === dateLib.getMonth(lastDateOfLastWeek) ? FIVE_WEEKS : FOUR_WEEKS;
|
|
12
|
+
return numberOfWeeks;
|
|
13
|
+
}
|
|
14
|
+
function startOfBroadcastWeek(date, dateLib) {
|
|
15
|
+
const firstOfMonth = dateLib.startOfMonth(date);
|
|
16
|
+
const dayOfWeek = firstOfMonth.getDay();
|
|
17
|
+
if (dayOfWeek === 1) {
|
|
18
|
+
return firstOfMonth;
|
|
19
|
+
} else if (dayOfWeek === 0) {
|
|
20
|
+
return dateLib.addDays(firstOfMonth, -1 * 6);
|
|
21
|
+
} else {
|
|
22
|
+
return dateLib.addDays(firstOfMonth, -1 * (dayOfWeek - 1));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function endOfBroadcastWeek(date, dateLib) {
|
|
26
|
+
const startDate = startOfBroadcastWeek(date, dateLib);
|
|
27
|
+
const numberOfWeeks = getBroadcastWeeksInMonth(date, dateLib);
|
|
28
|
+
const endDate = dateLib.addDays(startDate, numberOfWeeks * 7 - 1);
|
|
29
|
+
return endDate;
|
|
30
|
+
}
|
|
31
|
+
const enUS = {
|
|
32
|
+
...enUS$1,
|
|
33
|
+
labels: {
|
|
34
|
+
labelDayButton: (date, modifiers, options, dateLib) => {
|
|
35
|
+
let formatDate;
|
|
36
|
+
if (dateLib && typeof dateLib.format === "function") {
|
|
37
|
+
formatDate = dateLib.format.bind(dateLib);
|
|
38
|
+
} else {
|
|
39
|
+
formatDate = (d, pattern) => format(d, pattern, { locale: enUS$1, ...options });
|
|
40
|
+
}
|
|
41
|
+
let label = formatDate(date, "PPPP");
|
|
42
|
+
if (modifiers.today)
|
|
43
|
+
label = `Today, ${label}`;
|
|
44
|
+
if (modifiers.selected)
|
|
45
|
+
label = `${label}, selected`;
|
|
46
|
+
return label;
|
|
47
|
+
},
|
|
48
|
+
labelMonthDropdown: "Choose the Month",
|
|
49
|
+
labelNext: "Go to the Next Month",
|
|
50
|
+
labelPrevious: "Go to the Previous Month",
|
|
51
|
+
labelWeekNumber: (weekNumber) => `Week ${weekNumber}`,
|
|
52
|
+
labelYearDropdown: "Choose the Year",
|
|
53
|
+
labelGrid: (date, options, dateLib) => {
|
|
54
|
+
let formatDate;
|
|
55
|
+
if (dateLib && typeof dateLib.format === "function") {
|
|
56
|
+
formatDate = dateLib.format.bind(dateLib);
|
|
57
|
+
} else {
|
|
58
|
+
formatDate = (d, pattern) => format(d, pattern, { locale: enUS$1, ...options });
|
|
59
|
+
}
|
|
60
|
+
return formatDate(date, "LLLL yyyy");
|
|
61
|
+
},
|
|
62
|
+
labelGridcell: (date, modifiers, options, dateLib) => {
|
|
63
|
+
let formatDate;
|
|
64
|
+
if (dateLib && typeof dateLib.format === "function") {
|
|
65
|
+
formatDate = dateLib.format.bind(dateLib);
|
|
66
|
+
} else {
|
|
67
|
+
formatDate = (d, pattern) => format(d, pattern, { locale: enUS$1, ...options });
|
|
68
|
+
}
|
|
69
|
+
let label = formatDate(date, "PPPP");
|
|
70
|
+
if (modifiers?.today) {
|
|
71
|
+
label = `Today, ${label}`;
|
|
72
|
+
}
|
|
73
|
+
return label;
|
|
74
|
+
},
|
|
75
|
+
labelNav: "Navigation bar",
|
|
76
|
+
labelWeekNumberHeader: "Week Number",
|
|
77
|
+
labelWeekday: (date, options, dateLib) => {
|
|
78
|
+
let formatDate;
|
|
79
|
+
if (dateLib && typeof dateLib.format === "function") {
|
|
80
|
+
formatDate = dateLib.format.bind(dateLib);
|
|
81
|
+
} else {
|
|
82
|
+
formatDate = (d, pattern) => format(d, pattern, { locale: enUS$1, ...options });
|
|
83
|
+
}
|
|
84
|
+
return formatDate(date, "cccc");
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
class DateLib {
|
|
89
|
+
/**
|
|
90
|
+
* Creates an instance of `DateLib`.
|
|
91
|
+
*
|
|
92
|
+
* @param options Configuration options for the date library.
|
|
93
|
+
* @param overrides Custom overrides for the date library functions.
|
|
94
|
+
*/
|
|
95
|
+
constructor(options, overrides) {
|
|
96
|
+
this.Date = Date;
|
|
97
|
+
this.today = () => {
|
|
98
|
+
if (this.overrides?.today) {
|
|
99
|
+
return this.overrides.today();
|
|
100
|
+
}
|
|
101
|
+
if (this.options.timeZone) {
|
|
102
|
+
return TZDate.tz(this.options.timeZone);
|
|
103
|
+
}
|
|
104
|
+
return new this.Date();
|
|
105
|
+
};
|
|
106
|
+
this.newDate = (year, monthIndex, date) => {
|
|
107
|
+
if (this.overrides?.newDate) {
|
|
108
|
+
return this.overrides.newDate(year, monthIndex, date);
|
|
109
|
+
}
|
|
110
|
+
if (this.options.timeZone) {
|
|
111
|
+
return new TZDate(year, monthIndex, date, this.options.timeZone);
|
|
112
|
+
}
|
|
113
|
+
return new Date(year, monthIndex, date);
|
|
114
|
+
};
|
|
115
|
+
this.addDays = (date, amount) => {
|
|
116
|
+
return this.overrides?.addDays ? this.overrides.addDays(date, amount) : addDays(date, amount);
|
|
117
|
+
};
|
|
118
|
+
this.addMonths = (date, amount) => {
|
|
119
|
+
return this.overrides?.addMonths ? this.overrides.addMonths(date, amount) : addMonths(date, amount);
|
|
120
|
+
};
|
|
121
|
+
this.addWeeks = (date, amount) => {
|
|
122
|
+
return this.overrides?.addWeeks ? this.overrides.addWeeks(date, amount) : addWeeks(date, amount);
|
|
123
|
+
};
|
|
124
|
+
this.addYears = (date, amount) => {
|
|
125
|
+
return this.overrides?.addYears ? this.overrides.addYears(date, amount) : addYears(date, amount);
|
|
126
|
+
};
|
|
127
|
+
this.differenceInCalendarDays = (dateLeft, dateRight) => {
|
|
128
|
+
return this.overrides?.differenceInCalendarDays ? this.overrides.differenceInCalendarDays(dateLeft, dateRight) : differenceInCalendarDays(dateLeft, dateRight);
|
|
129
|
+
};
|
|
130
|
+
this.differenceInCalendarMonths = (dateLeft, dateRight) => {
|
|
131
|
+
return this.overrides?.differenceInCalendarMonths ? this.overrides.differenceInCalendarMonths(dateLeft, dateRight) : differenceInCalendarMonths(dateLeft, dateRight);
|
|
132
|
+
};
|
|
133
|
+
this.eachMonthOfInterval = (interval) => {
|
|
134
|
+
return this.overrides?.eachMonthOfInterval ? this.overrides.eachMonthOfInterval(interval) : eachMonthOfInterval(interval);
|
|
135
|
+
};
|
|
136
|
+
this.eachYearOfInterval = (interval) => {
|
|
137
|
+
const years = this.overrides?.eachYearOfInterval ? this.overrides.eachYearOfInterval(interval) : eachYearOfInterval(interval);
|
|
138
|
+
const uniqueYears = new Set(years.map((d) => this.getYear(d)));
|
|
139
|
+
if (uniqueYears.size === years.length) {
|
|
140
|
+
return years;
|
|
141
|
+
}
|
|
142
|
+
const yearsArray = [];
|
|
143
|
+
uniqueYears.forEach((y) => {
|
|
144
|
+
yearsArray.push(new Date(y, 0, 1));
|
|
145
|
+
});
|
|
146
|
+
return yearsArray;
|
|
147
|
+
};
|
|
148
|
+
this.endOfBroadcastWeek = (date) => {
|
|
149
|
+
return this.overrides?.endOfBroadcastWeek ? this.overrides.endOfBroadcastWeek(date) : endOfBroadcastWeek(date, this);
|
|
150
|
+
};
|
|
151
|
+
this.endOfISOWeek = (date) => {
|
|
152
|
+
return this.overrides?.endOfISOWeek ? this.overrides.endOfISOWeek(date) : endOfISOWeek(date);
|
|
153
|
+
};
|
|
154
|
+
this.endOfMonth = (date) => {
|
|
155
|
+
return this.overrides?.endOfMonth ? this.overrides.endOfMonth(date) : endOfMonth(date);
|
|
156
|
+
};
|
|
157
|
+
this.endOfWeek = (date, options2) => {
|
|
158
|
+
return this.overrides?.endOfWeek ? this.overrides.endOfWeek(date, options2) : endOfWeek(date, this.options);
|
|
159
|
+
};
|
|
160
|
+
this.endOfYear = (date) => {
|
|
161
|
+
return this.overrides?.endOfYear ? this.overrides.endOfYear(date) : endOfYear(date);
|
|
162
|
+
};
|
|
163
|
+
this.format = (date, formatStr, _options) => {
|
|
164
|
+
const formatted = this.overrides?.format ? this.overrides.format(date, formatStr, this.options) : format(date, formatStr, this.options);
|
|
165
|
+
if (this.options.numerals && this.options.numerals !== "latn") {
|
|
166
|
+
return this.replaceDigits(formatted);
|
|
167
|
+
}
|
|
168
|
+
return formatted;
|
|
169
|
+
};
|
|
170
|
+
this.getISOWeek = (date) => {
|
|
171
|
+
return this.overrides?.getISOWeek ? this.overrides.getISOWeek(date) : getISOWeek(date);
|
|
172
|
+
};
|
|
173
|
+
this.getMonth = (date, _options) => {
|
|
174
|
+
return this.overrides?.getMonth ? this.overrides.getMonth(date, this.options) : getMonth(date, this.options);
|
|
175
|
+
};
|
|
176
|
+
this.getYear = (date, _options) => {
|
|
177
|
+
return this.overrides?.getYear ? this.overrides.getYear(date, this.options) : getYear(date, this.options);
|
|
178
|
+
};
|
|
179
|
+
this.getWeek = (date, _options) => {
|
|
180
|
+
return this.overrides?.getWeek ? this.overrides.getWeek(date, this.options) : getWeek(date, this.options);
|
|
181
|
+
};
|
|
182
|
+
this.isAfter = (date, dateToCompare) => {
|
|
183
|
+
return this.overrides?.isAfter ? this.overrides.isAfter(date, dateToCompare) : isAfter(date, dateToCompare);
|
|
184
|
+
};
|
|
185
|
+
this.isBefore = (date, dateToCompare) => {
|
|
186
|
+
return this.overrides?.isBefore ? this.overrides.isBefore(date, dateToCompare) : isBefore(date, dateToCompare);
|
|
187
|
+
};
|
|
188
|
+
this.isDate = (value) => {
|
|
189
|
+
return this.overrides?.isDate ? this.overrides.isDate(value) : isDate(value);
|
|
190
|
+
};
|
|
191
|
+
this.isSameDay = (dateLeft, dateRight) => {
|
|
192
|
+
return this.overrides?.isSameDay ? this.overrides.isSameDay(dateLeft, dateRight) : isSameDay(dateLeft, dateRight);
|
|
193
|
+
};
|
|
194
|
+
this.isSameMonth = (dateLeft, dateRight) => {
|
|
195
|
+
return this.overrides?.isSameMonth ? this.overrides.isSameMonth(dateLeft, dateRight) : isSameMonth(dateLeft, dateRight);
|
|
196
|
+
};
|
|
197
|
+
this.isSameYear = (dateLeft, dateRight) => {
|
|
198
|
+
return this.overrides?.isSameYear ? this.overrides.isSameYear(dateLeft, dateRight) : isSameYear(dateLeft, dateRight);
|
|
199
|
+
};
|
|
200
|
+
this.max = (dates) => {
|
|
201
|
+
return this.overrides?.max ? this.overrides.max(dates) : max(dates);
|
|
202
|
+
};
|
|
203
|
+
this.min = (dates) => {
|
|
204
|
+
return this.overrides?.min ? this.overrides.min(dates) : min(dates);
|
|
205
|
+
};
|
|
206
|
+
this.setMonth = (date, month) => {
|
|
207
|
+
return this.overrides?.setMonth ? this.overrides.setMonth(date, month) : setMonth(date, month);
|
|
208
|
+
};
|
|
209
|
+
this.setYear = (date, year) => {
|
|
210
|
+
return this.overrides?.setYear ? this.overrides.setYear(date, year) : setYear(date, year);
|
|
211
|
+
};
|
|
212
|
+
this.startOfBroadcastWeek = (date, _dateLib) => {
|
|
213
|
+
return this.overrides?.startOfBroadcastWeek ? this.overrides.startOfBroadcastWeek(date, this) : startOfBroadcastWeek(date, this);
|
|
214
|
+
};
|
|
215
|
+
this.startOfDay = (date) => {
|
|
216
|
+
return this.overrides?.startOfDay ? this.overrides.startOfDay(date) : startOfDay(date);
|
|
217
|
+
};
|
|
218
|
+
this.startOfISOWeek = (date) => {
|
|
219
|
+
return this.overrides?.startOfISOWeek ? this.overrides.startOfISOWeek(date) : startOfISOWeek(date);
|
|
220
|
+
};
|
|
221
|
+
this.startOfMonth = (date) => {
|
|
222
|
+
return this.overrides?.startOfMonth ? this.overrides.startOfMonth(date) : startOfMonth(date);
|
|
223
|
+
};
|
|
224
|
+
this.startOfWeek = (date, _options) => {
|
|
225
|
+
return this.overrides?.startOfWeek ? this.overrides.startOfWeek(date, this.options) : startOfWeek(date, this.options);
|
|
226
|
+
};
|
|
227
|
+
this.startOfYear = (date) => {
|
|
228
|
+
return this.overrides?.startOfYear ? this.overrides.startOfYear(date) : startOfYear(date);
|
|
229
|
+
};
|
|
230
|
+
this.options = { locale: enUS, ...options };
|
|
231
|
+
this.overrides = overrides;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Generates a mapping of Arabic digits (0-9) to the target numbering system
|
|
235
|
+
* digits.
|
|
236
|
+
*
|
|
237
|
+
* @since 9.5.0
|
|
238
|
+
* @returns A record mapping Arabic digits to the target numerals.
|
|
239
|
+
*/
|
|
240
|
+
getDigitMap() {
|
|
241
|
+
const { numerals = "latn" } = this.options;
|
|
242
|
+
const formatter = new Intl.NumberFormat("en-US", {
|
|
243
|
+
numberingSystem: numerals
|
|
244
|
+
});
|
|
245
|
+
const digitMap = {};
|
|
246
|
+
for (let i = 0; i < 10; i++) {
|
|
247
|
+
digitMap[i.toString()] = formatter.format(i);
|
|
248
|
+
}
|
|
249
|
+
return digitMap;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Replaces Arabic digits in a string with the target numbering system digits.
|
|
253
|
+
*
|
|
254
|
+
* @since 9.5.0
|
|
255
|
+
* @param input The string containing Arabic digits.
|
|
256
|
+
* @returns The string with digits replaced.
|
|
257
|
+
*/
|
|
258
|
+
replaceDigits(input) {
|
|
259
|
+
const digitMap = this.getDigitMap();
|
|
260
|
+
return input.replace(/\d/g, (digit) => digitMap[digit] || digit);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Formats a number using the configured numbering system.
|
|
264
|
+
*
|
|
265
|
+
* @since 9.5.0
|
|
266
|
+
* @param value The number to format.
|
|
267
|
+
* @returns The formatted number as a string.
|
|
268
|
+
*/
|
|
269
|
+
formatNumber(value) {
|
|
270
|
+
return this.replaceDigits(value.toString());
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Returns the preferred ordering for month and year labels for the current
|
|
274
|
+
* locale.
|
|
275
|
+
*/
|
|
276
|
+
getMonthYearOrder() {
|
|
277
|
+
const code = this.options.locale?.code;
|
|
278
|
+
if (!code) {
|
|
279
|
+
return "month-first";
|
|
280
|
+
}
|
|
281
|
+
return DateLib.yearFirstLocales.has(code) ? "year-first" : "month-first";
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Formats the month/year pair respecting locale conventions.
|
|
285
|
+
*
|
|
286
|
+
* @since 9.11.0
|
|
287
|
+
*/
|
|
288
|
+
formatMonthYear(date) {
|
|
289
|
+
const { locale, timeZone, numerals } = this.options;
|
|
290
|
+
const localeCode = locale?.code;
|
|
291
|
+
if (localeCode && DateLib.yearFirstLocales.has(localeCode)) {
|
|
292
|
+
try {
|
|
293
|
+
const intl = new Intl.DateTimeFormat(localeCode, {
|
|
294
|
+
month: "long",
|
|
295
|
+
year: "numeric",
|
|
296
|
+
timeZone,
|
|
297
|
+
numberingSystem: numerals
|
|
298
|
+
});
|
|
299
|
+
const formatted = intl.format(date);
|
|
300
|
+
return formatted;
|
|
301
|
+
} catch {
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const pattern = this.getMonthYearOrder() === "year-first" ? "y LLLL" : "LLLL y";
|
|
305
|
+
return this.format(date, pattern);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
DateLib.yearFirstLocales = /* @__PURE__ */ new Set([
|
|
309
|
+
"eu",
|
|
310
|
+
"hu",
|
|
311
|
+
"ja",
|
|
312
|
+
"ja-Hira",
|
|
313
|
+
"ja-JP",
|
|
314
|
+
"ko",
|
|
315
|
+
"ko-KR",
|
|
316
|
+
"lt",
|
|
317
|
+
"lt-LT",
|
|
318
|
+
"lv",
|
|
319
|
+
"lv-LV",
|
|
320
|
+
"mn",
|
|
321
|
+
"mn-MN",
|
|
322
|
+
"zh",
|
|
323
|
+
"zh-CN",
|
|
324
|
+
"zh-HK",
|
|
325
|
+
"zh-TW"
|
|
326
|
+
]);
|
|
327
|
+
const defaultDateLib = new DateLib();
|
|
328
|
+
class CalendarDay {
|
|
329
|
+
constructor(date, displayMonth, dateLib = defaultDateLib) {
|
|
330
|
+
this.date = date;
|
|
331
|
+
this.displayMonth = displayMonth;
|
|
332
|
+
this.outside = Boolean(displayMonth && !dateLib.isSameMonth(date, displayMonth));
|
|
333
|
+
this.dateLib = dateLib;
|
|
334
|
+
this.isoDate = dateLib.format(date, "yyyy-MM-dd");
|
|
335
|
+
this.displayMonthId = dateLib.format(displayMonth, "yyyy-MM");
|
|
336
|
+
this.dateMonthId = dateLib.format(date, "yyyy-MM");
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Checks if this day is equal to another `CalendarDay`, considering both the
|
|
340
|
+
* date and the displayed month.
|
|
341
|
+
*
|
|
342
|
+
* @param day The `CalendarDay` to compare with.
|
|
343
|
+
* @returns `true` if the days are equal, otherwise `false`.
|
|
344
|
+
*/
|
|
345
|
+
isEqualTo(day) {
|
|
346
|
+
return this.dateLib.isSameDay(day.date, this.date) && this.dateLib.isSameMonth(day.displayMonth, this.displayMonth);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
class CalendarMonth {
|
|
350
|
+
constructor(month, weeks) {
|
|
351
|
+
this.date = month;
|
|
352
|
+
this.weeks = weeks;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
class CalendarWeek {
|
|
356
|
+
constructor(weekNumber, days) {
|
|
357
|
+
this.days = days;
|
|
358
|
+
this.weekNumber = weekNumber;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function Button(props) {
|
|
362
|
+
return React.createElement("button", { ...props });
|
|
363
|
+
}
|
|
364
|
+
function CaptionLabel(props) {
|
|
365
|
+
return React.createElement("span", { ...props });
|
|
366
|
+
}
|
|
367
|
+
function Chevron(props) {
|
|
368
|
+
const { size = 24, orientation = "left", className } = props;
|
|
369
|
+
return (
|
|
370
|
+
// biome-ignore lint/a11y/noSvgWithoutTitle: handled by the parent component
|
|
371
|
+
React.createElement(
|
|
372
|
+
"svg",
|
|
373
|
+
{ className, width: size, height: size, viewBox: "0 0 24 24" },
|
|
374
|
+
orientation === "up" && React.createElement("polygon", { points: "6.77 17 12.5 11.43 18.24 17 20 15.28 12.5 8 5 15.28" }),
|
|
375
|
+
orientation === "down" && React.createElement("polygon", { points: "6.77 8 12.5 13.57 18.24 8 20 9.72 12.5 17 5 9.72" }),
|
|
376
|
+
orientation === "left" && React.createElement("polygon", { points: "16 18.112 9.81111111 12 16 5.87733333 14.0888889 4 6 12 14.0888889 20" }),
|
|
377
|
+
orientation === "right" && React.createElement("polygon", { points: "8 18.112 14.18888889 12 8 5.87733333 9.91111111 4 18 12 9.91111111 20" })
|
|
378
|
+
)
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
function Day(props) {
|
|
382
|
+
const { day, modifiers, ...tdProps } = props;
|
|
383
|
+
return React.createElement("td", { ...tdProps });
|
|
384
|
+
}
|
|
385
|
+
function DayButton(props) {
|
|
386
|
+
const { day, modifiers, ...buttonProps } = props;
|
|
387
|
+
const ref = React.useRef(null);
|
|
388
|
+
React.useEffect(() => {
|
|
389
|
+
if (modifiers.focused)
|
|
390
|
+
ref.current?.focus();
|
|
391
|
+
}, [modifiers.focused]);
|
|
392
|
+
return React.createElement("button", { ref, ...buttonProps });
|
|
393
|
+
}
|
|
394
|
+
var UI;
|
|
395
|
+
(function(UI2) {
|
|
396
|
+
UI2["Root"] = "root";
|
|
397
|
+
UI2["Chevron"] = "chevron";
|
|
398
|
+
UI2["Day"] = "day";
|
|
399
|
+
UI2["DayButton"] = "day_button";
|
|
400
|
+
UI2["CaptionLabel"] = "caption_label";
|
|
401
|
+
UI2["Dropdowns"] = "dropdowns";
|
|
402
|
+
UI2["Dropdown"] = "dropdown";
|
|
403
|
+
UI2["DropdownRoot"] = "dropdown_root";
|
|
404
|
+
UI2["Footer"] = "footer";
|
|
405
|
+
UI2["MonthGrid"] = "month_grid";
|
|
406
|
+
UI2["MonthCaption"] = "month_caption";
|
|
407
|
+
UI2["MonthsDropdown"] = "months_dropdown";
|
|
408
|
+
UI2["Month"] = "month";
|
|
409
|
+
UI2["Months"] = "months";
|
|
410
|
+
UI2["Nav"] = "nav";
|
|
411
|
+
UI2["NextMonthButton"] = "button_next";
|
|
412
|
+
UI2["PreviousMonthButton"] = "button_previous";
|
|
413
|
+
UI2["Week"] = "week";
|
|
414
|
+
UI2["Weeks"] = "weeks";
|
|
415
|
+
UI2["Weekday"] = "weekday";
|
|
416
|
+
UI2["Weekdays"] = "weekdays";
|
|
417
|
+
UI2["WeekNumber"] = "week_number";
|
|
418
|
+
UI2["WeekNumberHeader"] = "week_number_header";
|
|
419
|
+
UI2["YearsDropdown"] = "years_dropdown";
|
|
420
|
+
})(UI || (UI = {}));
|
|
421
|
+
var DayFlag;
|
|
422
|
+
(function(DayFlag2) {
|
|
423
|
+
DayFlag2["disabled"] = "disabled";
|
|
424
|
+
DayFlag2["hidden"] = "hidden";
|
|
425
|
+
DayFlag2["outside"] = "outside";
|
|
426
|
+
DayFlag2["focused"] = "focused";
|
|
427
|
+
DayFlag2["today"] = "today";
|
|
428
|
+
})(DayFlag || (DayFlag = {}));
|
|
429
|
+
var SelectionState;
|
|
430
|
+
(function(SelectionState2) {
|
|
431
|
+
SelectionState2["range_end"] = "range_end";
|
|
432
|
+
SelectionState2["range_middle"] = "range_middle";
|
|
433
|
+
SelectionState2["range_start"] = "range_start";
|
|
434
|
+
SelectionState2["selected"] = "selected";
|
|
435
|
+
})(SelectionState || (SelectionState = {}));
|
|
436
|
+
var Animation;
|
|
437
|
+
(function(Animation2) {
|
|
438
|
+
Animation2["weeks_before_enter"] = "weeks_before_enter";
|
|
439
|
+
Animation2["weeks_before_exit"] = "weeks_before_exit";
|
|
440
|
+
Animation2["weeks_after_enter"] = "weeks_after_enter";
|
|
441
|
+
Animation2["weeks_after_exit"] = "weeks_after_exit";
|
|
442
|
+
Animation2["caption_after_enter"] = "caption_after_enter";
|
|
443
|
+
Animation2["caption_after_exit"] = "caption_after_exit";
|
|
444
|
+
Animation2["caption_before_enter"] = "caption_before_enter";
|
|
445
|
+
Animation2["caption_before_exit"] = "caption_before_exit";
|
|
446
|
+
})(Animation || (Animation = {}));
|
|
447
|
+
function Dropdown(props) {
|
|
448
|
+
const { options, className, components: components2, classNames, ...selectProps } = props;
|
|
449
|
+
const cssClassSelect = [classNames[UI.Dropdown], className].join(" ");
|
|
450
|
+
const selectedOption = options?.find(({ value }) => value === selectProps.value);
|
|
451
|
+
return React.createElement(
|
|
452
|
+
"span",
|
|
453
|
+
{ "data-disabled": selectProps.disabled, className: classNames[UI.DropdownRoot] },
|
|
454
|
+
React.createElement(components2.Select, { className: cssClassSelect, ...selectProps }, options?.map(({ value, label, disabled }) => React.createElement(components2.Option, { key: value, value, disabled }, label))),
|
|
455
|
+
React.createElement(
|
|
456
|
+
"span",
|
|
457
|
+
{ className: classNames[UI.CaptionLabel], "aria-hidden": true },
|
|
458
|
+
selectedOption?.label,
|
|
459
|
+
React.createElement(components2.Chevron, { orientation: "down", size: 18, className: classNames[UI.Chevron] })
|
|
460
|
+
)
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
function DropdownNav(props) {
|
|
464
|
+
return React.createElement("div", { ...props });
|
|
465
|
+
}
|
|
466
|
+
function Footer(props) {
|
|
467
|
+
return React.createElement("div", { ...props });
|
|
468
|
+
}
|
|
469
|
+
function Month(props) {
|
|
470
|
+
const { calendarMonth, displayIndex, ...divProps } = props;
|
|
471
|
+
return React.createElement("div", { ...divProps }, props.children);
|
|
472
|
+
}
|
|
473
|
+
function MonthCaption(props) {
|
|
474
|
+
const { calendarMonth, displayIndex, ...divProps } = props;
|
|
475
|
+
return React.createElement("div", { ...divProps });
|
|
476
|
+
}
|
|
477
|
+
function MonthGrid(props) {
|
|
478
|
+
return React.createElement("table", { ...props });
|
|
479
|
+
}
|
|
480
|
+
function Months(props) {
|
|
481
|
+
return React.createElement("div", { ...props });
|
|
482
|
+
}
|
|
483
|
+
const dayPickerContext = reactExports.createContext(void 0);
|
|
484
|
+
function useDayPicker() {
|
|
485
|
+
const context = reactExports.useContext(dayPickerContext);
|
|
486
|
+
if (context === void 0) {
|
|
487
|
+
throw new Error("useDayPicker() must be used within a custom component.");
|
|
488
|
+
}
|
|
489
|
+
return context;
|
|
490
|
+
}
|
|
491
|
+
function MonthsDropdown(props) {
|
|
492
|
+
const { components: components2 } = useDayPicker();
|
|
493
|
+
return React.createElement(components2.Dropdown, { ...props });
|
|
494
|
+
}
|
|
495
|
+
function Nav(props) {
|
|
496
|
+
const { onPreviousClick, onNextClick, previousMonth, nextMonth, ...navProps } = props;
|
|
497
|
+
const { components: components2, classNames, labels: { labelPrevious: labelPrevious2, labelNext: labelNext2 } } = useDayPicker();
|
|
498
|
+
const handleNextClick = reactExports.useCallback((e) => {
|
|
499
|
+
if (nextMonth) {
|
|
500
|
+
onNextClick?.(e);
|
|
501
|
+
}
|
|
502
|
+
}, [nextMonth, onNextClick]);
|
|
503
|
+
const handlePreviousClick = reactExports.useCallback((e) => {
|
|
504
|
+
if (previousMonth) {
|
|
505
|
+
onPreviousClick?.(e);
|
|
506
|
+
}
|
|
507
|
+
}, [previousMonth, onPreviousClick]);
|
|
508
|
+
return React.createElement(
|
|
509
|
+
"nav",
|
|
510
|
+
{ ...navProps },
|
|
511
|
+
React.createElement(
|
|
512
|
+
components2.PreviousMonthButton,
|
|
513
|
+
{ type: "button", className: classNames[UI.PreviousMonthButton], tabIndex: previousMonth ? void 0 : -1, "aria-disabled": previousMonth ? void 0 : true, "aria-label": labelPrevious2(previousMonth), onClick: handlePreviousClick },
|
|
514
|
+
React.createElement(components2.Chevron, { disabled: previousMonth ? void 0 : true, className: classNames[UI.Chevron], orientation: "left" })
|
|
515
|
+
),
|
|
516
|
+
React.createElement(
|
|
517
|
+
components2.NextMonthButton,
|
|
518
|
+
{ type: "button", className: classNames[UI.NextMonthButton], tabIndex: nextMonth ? void 0 : -1, "aria-disabled": nextMonth ? void 0 : true, "aria-label": labelNext2(nextMonth), onClick: handleNextClick },
|
|
519
|
+
React.createElement(components2.Chevron, { disabled: nextMonth ? void 0 : true, orientation: "right", className: classNames[UI.Chevron] })
|
|
520
|
+
)
|
|
521
|
+
);
|
|
522
|
+
}
|
|
523
|
+
function NextMonthButton(props) {
|
|
524
|
+
const { components: components2 } = useDayPicker();
|
|
525
|
+
return React.createElement(components2.Button, { ...props });
|
|
526
|
+
}
|
|
527
|
+
function Option(props) {
|
|
528
|
+
return React.createElement("option", { ...props });
|
|
529
|
+
}
|
|
530
|
+
function PreviousMonthButton(props) {
|
|
531
|
+
const { components: components2 } = useDayPicker();
|
|
532
|
+
return React.createElement(components2.Button, { ...props });
|
|
533
|
+
}
|
|
534
|
+
function Root(props) {
|
|
535
|
+
const { rootRef, ...rest } = props;
|
|
536
|
+
return React.createElement("div", { ...rest, ref: rootRef });
|
|
537
|
+
}
|
|
538
|
+
function Select(props) {
|
|
539
|
+
return React.createElement("select", { ...props });
|
|
540
|
+
}
|
|
541
|
+
function Week(props) {
|
|
542
|
+
const { week, ...trProps } = props;
|
|
543
|
+
return React.createElement("tr", { ...trProps });
|
|
544
|
+
}
|
|
545
|
+
function Weekday(props) {
|
|
546
|
+
return React.createElement("th", { ...props });
|
|
547
|
+
}
|
|
548
|
+
function Weekdays(props) {
|
|
549
|
+
return React.createElement(
|
|
550
|
+
"thead",
|
|
551
|
+
{ "aria-hidden": true },
|
|
552
|
+
React.createElement("tr", { ...props })
|
|
553
|
+
);
|
|
554
|
+
}
|
|
555
|
+
function WeekNumber(props) {
|
|
556
|
+
const { week, ...thProps } = props;
|
|
557
|
+
return React.createElement("th", { ...thProps });
|
|
558
|
+
}
|
|
559
|
+
function WeekNumberHeader(props) {
|
|
560
|
+
return React.createElement("th", { ...props });
|
|
561
|
+
}
|
|
562
|
+
function Weeks(props) {
|
|
563
|
+
return React.createElement("tbody", { ...props });
|
|
564
|
+
}
|
|
565
|
+
function YearsDropdown(props) {
|
|
566
|
+
const { components: components2 } = useDayPicker();
|
|
567
|
+
return React.createElement(components2.Dropdown, { ...props });
|
|
568
|
+
}
|
|
569
|
+
const components = /* @__PURE__ */ Object.freeze({
|
|
570
|
+
__proto__: null,
|
|
571
|
+
Button,
|
|
572
|
+
CaptionLabel,
|
|
573
|
+
Chevron,
|
|
574
|
+
Day,
|
|
575
|
+
DayButton,
|
|
576
|
+
Dropdown,
|
|
577
|
+
DropdownNav,
|
|
578
|
+
Footer,
|
|
579
|
+
Month,
|
|
580
|
+
MonthCaption,
|
|
581
|
+
MonthGrid,
|
|
582
|
+
Months,
|
|
583
|
+
MonthsDropdown,
|
|
584
|
+
Nav,
|
|
585
|
+
NextMonthButton,
|
|
586
|
+
Option,
|
|
587
|
+
PreviousMonthButton,
|
|
588
|
+
Root,
|
|
589
|
+
Select,
|
|
590
|
+
Week,
|
|
591
|
+
WeekNumber,
|
|
592
|
+
WeekNumberHeader,
|
|
593
|
+
Weekday,
|
|
594
|
+
Weekdays,
|
|
595
|
+
Weeks,
|
|
596
|
+
YearsDropdown
|
|
597
|
+
});
|
|
598
|
+
function rangeIncludesDate(range, date, excludeEnds = false, dateLib = defaultDateLib) {
|
|
599
|
+
let { from, to } = range;
|
|
600
|
+
const { differenceInCalendarDays: differenceInCalendarDays2, isSameDay: isSameDay2 } = dateLib;
|
|
601
|
+
if (from && to) {
|
|
602
|
+
const isRangeInverted = differenceInCalendarDays2(to, from) < 0;
|
|
603
|
+
if (isRangeInverted) {
|
|
604
|
+
[from, to] = [to, from];
|
|
605
|
+
}
|
|
606
|
+
const isInRange = differenceInCalendarDays2(date, from) >= (excludeEnds ? 1 : 0) && differenceInCalendarDays2(to, date) >= (excludeEnds ? 1 : 0);
|
|
607
|
+
return isInRange;
|
|
608
|
+
}
|
|
609
|
+
if (!excludeEnds && to) {
|
|
610
|
+
return isSameDay2(to, date);
|
|
611
|
+
}
|
|
612
|
+
if (!excludeEnds && from) {
|
|
613
|
+
return isSameDay2(from, date);
|
|
614
|
+
}
|
|
615
|
+
return false;
|
|
616
|
+
}
|
|
617
|
+
function isDateInterval(matcher) {
|
|
618
|
+
return Boolean(matcher && typeof matcher === "object" && "before" in matcher && "after" in matcher);
|
|
619
|
+
}
|
|
620
|
+
function isDateRange(value) {
|
|
621
|
+
return Boolean(value && typeof value === "object" && "from" in value);
|
|
622
|
+
}
|
|
623
|
+
function isDateAfterType(value) {
|
|
624
|
+
return Boolean(value && typeof value === "object" && "after" in value);
|
|
625
|
+
}
|
|
626
|
+
function isDateBeforeType(value) {
|
|
627
|
+
return Boolean(value && typeof value === "object" && "before" in value);
|
|
628
|
+
}
|
|
629
|
+
function isDayOfWeekType(value) {
|
|
630
|
+
return Boolean(value && typeof value === "object" && "dayOfWeek" in value);
|
|
631
|
+
}
|
|
632
|
+
function isDatesArray(value, dateLib) {
|
|
633
|
+
return Array.isArray(value) && value.every(dateLib.isDate);
|
|
634
|
+
}
|
|
635
|
+
function dateMatchModifiers(date, matchers, dateLib = defaultDateLib) {
|
|
636
|
+
const matchersArr = !Array.isArray(matchers) ? [matchers] : matchers;
|
|
637
|
+
const { isSameDay: isSameDay2, differenceInCalendarDays: differenceInCalendarDays2, isAfter: isAfter2 } = dateLib;
|
|
638
|
+
return matchersArr.some((matcher) => {
|
|
639
|
+
if (typeof matcher === "boolean") {
|
|
640
|
+
return matcher;
|
|
641
|
+
}
|
|
642
|
+
if (dateLib.isDate(matcher)) {
|
|
643
|
+
return isSameDay2(date, matcher);
|
|
644
|
+
}
|
|
645
|
+
if (isDatesArray(matcher, dateLib)) {
|
|
646
|
+
return matcher.some((matcherDate) => isSameDay2(date, matcherDate));
|
|
647
|
+
}
|
|
648
|
+
if (isDateRange(matcher)) {
|
|
649
|
+
return rangeIncludesDate(matcher, date, false, dateLib);
|
|
650
|
+
}
|
|
651
|
+
if (isDayOfWeekType(matcher)) {
|
|
652
|
+
if (!Array.isArray(matcher.dayOfWeek)) {
|
|
653
|
+
return matcher.dayOfWeek === date.getDay();
|
|
654
|
+
}
|
|
655
|
+
return matcher.dayOfWeek.includes(date.getDay());
|
|
656
|
+
}
|
|
657
|
+
if (isDateInterval(matcher)) {
|
|
658
|
+
const diffBefore = differenceInCalendarDays2(matcher.before, date);
|
|
659
|
+
const diffAfter = differenceInCalendarDays2(matcher.after, date);
|
|
660
|
+
const isDayBefore = diffBefore > 0;
|
|
661
|
+
const isDayAfter = diffAfter < 0;
|
|
662
|
+
const isClosedInterval = isAfter2(matcher.before, matcher.after);
|
|
663
|
+
if (isClosedInterval) {
|
|
664
|
+
return isDayAfter && isDayBefore;
|
|
665
|
+
} else {
|
|
666
|
+
return isDayBefore || isDayAfter;
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
if (isDateAfterType(matcher)) {
|
|
670
|
+
return differenceInCalendarDays2(date, matcher.after) > 0;
|
|
671
|
+
}
|
|
672
|
+
if (isDateBeforeType(matcher)) {
|
|
673
|
+
return differenceInCalendarDays2(matcher.before, date) > 0;
|
|
674
|
+
}
|
|
675
|
+
if (typeof matcher === "function") {
|
|
676
|
+
return matcher(date);
|
|
677
|
+
}
|
|
678
|
+
return false;
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
function createGetModifiers(days, props, navStart, navEnd, dateLib) {
|
|
682
|
+
const { disabled, hidden, modifiers, showOutsideDays, broadcastCalendar, today = dateLib.today() } = props;
|
|
683
|
+
const { isSameDay: isSameDay2, isSameMonth: isSameMonth2, startOfMonth: startOfMonth2, isBefore: isBefore2, endOfMonth: endOfMonth2, isAfter: isAfter2 } = dateLib;
|
|
684
|
+
const computedNavStart = navStart && startOfMonth2(navStart);
|
|
685
|
+
const computedNavEnd = navEnd && endOfMonth2(navEnd);
|
|
686
|
+
const internalModifiersMap = {
|
|
687
|
+
[DayFlag.focused]: [],
|
|
688
|
+
[DayFlag.outside]: [],
|
|
689
|
+
[DayFlag.disabled]: [],
|
|
690
|
+
[DayFlag.hidden]: [],
|
|
691
|
+
[DayFlag.today]: []
|
|
692
|
+
};
|
|
693
|
+
const customModifiersMap = {};
|
|
694
|
+
for (const day of days) {
|
|
695
|
+
const { date, displayMonth } = day;
|
|
696
|
+
const isOutside = Boolean(displayMonth && !isSameMonth2(date, displayMonth));
|
|
697
|
+
const isBeforeNavStart = Boolean(computedNavStart && isBefore2(date, computedNavStart));
|
|
698
|
+
const isAfterNavEnd = Boolean(computedNavEnd && isAfter2(date, computedNavEnd));
|
|
699
|
+
const isDisabled = Boolean(disabled && dateMatchModifiers(date, disabled, dateLib));
|
|
700
|
+
const isHidden = Boolean(hidden && dateMatchModifiers(date, hidden, dateLib)) || isBeforeNavStart || isAfterNavEnd || // Broadcast calendar will show outside days as default
|
|
701
|
+
!broadcastCalendar && !showOutsideDays && isOutside || broadcastCalendar && showOutsideDays === false && isOutside;
|
|
702
|
+
const isToday = isSameDay2(date, today);
|
|
703
|
+
if (isOutside)
|
|
704
|
+
internalModifiersMap.outside.push(day);
|
|
705
|
+
if (isDisabled)
|
|
706
|
+
internalModifiersMap.disabled.push(day);
|
|
707
|
+
if (isHidden)
|
|
708
|
+
internalModifiersMap.hidden.push(day);
|
|
709
|
+
if (isToday)
|
|
710
|
+
internalModifiersMap.today.push(day);
|
|
711
|
+
if (modifiers) {
|
|
712
|
+
Object.keys(modifiers).forEach((name) => {
|
|
713
|
+
const modifierValue = modifiers?.[name];
|
|
714
|
+
const isMatch = modifierValue ? dateMatchModifiers(date, modifierValue, dateLib) : false;
|
|
715
|
+
if (!isMatch)
|
|
716
|
+
return;
|
|
717
|
+
if (customModifiersMap[name]) {
|
|
718
|
+
customModifiersMap[name].push(day);
|
|
719
|
+
} else {
|
|
720
|
+
customModifiersMap[name] = [day];
|
|
721
|
+
}
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
return (day) => {
|
|
726
|
+
const dayFlags = {
|
|
727
|
+
[DayFlag.focused]: false,
|
|
728
|
+
[DayFlag.disabled]: false,
|
|
729
|
+
[DayFlag.hidden]: false,
|
|
730
|
+
[DayFlag.outside]: false,
|
|
731
|
+
[DayFlag.today]: false
|
|
732
|
+
};
|
|
733
|
+
const customModifiers = {};
|
|
734
|
+
for (const name in internalModifiersMap) {
|
|
735
|
+
const days2 = internalModifiersMap[name];
|
|
736
|
+
dayFlags[name] = days2.some((d) => d === day);
|
|
737
|
+
}
|
|
738
|
+
for (const name in customModifiersMap) {
|
|
739
|
+
customModifiers[name] = customModifiersMap[name].some((d) => d === day);
|
|
740
|
+
}
|
|
741
|
+
return {
|
|
742
|
+
...dayFlags,
|
|
743
|
+
// custom modifiers should override all the previous ones
|
|
744
|
+
...customModifiers
|
|
745
|
+
};
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
function getClassNamesForModifiers(modifiers, classNames, modifiersClassNames = {}) {
|
|
749
|
+
const modifierClassNames = Object.entries(modifiers).filter(([, active]) => active === true).reduce((previousValue, [key]) => {
|
|
750
|
+
if (modifiersClassNames[key]) {
|
|
751
|
+
previousValue.push(modifiersClassNames[key]);
|
|
752
|
+
} else if (classNames[DayFlag[key]]) {
|
|
753
|
+
previousValue.push(classNames[DayFlag[key]]);
|
|
754
|
+
} else if (classNames[SelectionState[key]]) {
|
|
755
|
+
previousValue.push(classNames[SelectionState[key]]);
|
|
756
|
+
}
|
|
757
|
+
return previousValue;
|
|
758
|
+
}, [classNames[UI.Day]]);
|
|
759
|
+
return modifierClassNames;
|
|
760
|
+
}
|
|
761
|
+
function getComponents(customComponents) {
|
|
762
|
+
return {
|
|
763
|
+
...components,
|
|
764
|
+
...customComponents
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
function getDataAttributes(props) {
|
|
768
|
+
const dataAttributes = {
|
|
769
|
+
"data-mode": props.mode ?? void 0,
|
|
770
|
+
"data-required": "required" in props ? props.required : void 0,
|
|
771
|
+
"data-multiple-months": props.numberOfMonths && props.numberOfMonths > 1 || void 0,
|
|
772
|
+
"data-week-numbers": props.showWeekNumber || void 0,
|
|
773
|
+
"data-broadcast-calendar": props.broadcastCalendar || void 0,
|
|
774
|
+
"data-nav-layout": props.navLayout || void 0
|
|
775
|
+
};
|
|
776
|
+
Object.entries(props).forEach(([key, val]) => {
|
|
777
|
+
if (key.startsWith("data-")) {
|
|
778
|
+
dataAttributes[key] = val;
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
return dataAttributes;
|
|
782
|
+
}
|
|
783
|
+
function getDefaultClassNames() {
|
|
784
|
+
const classNames = {};
|
|
785
|
+
for (const key in UI) {
|
|
786
|
+
classNames[UI[key]] = `rdp-${UI[key]}`;
|
|
787
|
+
}
|
|
788
|
+
for (const key in DayFlag) {
|
|
789
|
+
classNames[DayFlag[key]] = `rdp-${DayFlag[key]}`;
|
|
790
|
+
}
|
|
791
|
+
for (const key in SelectionState) {
|
|
792
|
+
classNames[SelectionState[key]] = `rdp-${SelectionState[key]}`;
|
|
793
|
+
}
|
|
794
|
+
for (const key in Animation) {
|
|
795
|
+
classNames[Animation[key]] = `rdp-${Animation[key]}`;
|
|
796
|
+
}
|
|
797
|
+
return classNames;
|
|
798
|
+
}
|
|
799
|
+
function formatCaption(month, options, dateLib) {
|
|
800
|
+
const lib = dateLib ?? new DateLib(options);
|
|
801
|
+
return lib.formatMonthYear(month);
|
|
802
|
+
}
|
|
803
|
+
const formatMonthCaption = formatCaption;
|
|
804
|
+
function formatDay(date, options, dateLib) {
|
|
805
|
+
return (dateLib ?? new DateLib(options)).format(date, "d");
|
|
806
|
+
}
|
|
807
|
+
function formatMonthDropdown(month, dateLib = defaultDateLib) {
|
|
808
|
+
return dateLib.format(month, "LLLL");
|
|
809
|
+
}
|
|
810
|
+
function formatWeekdayName(weekday, options, dateLib) {
|
|
811
|
+
return (dateLib ?? new DateLib(options)).format(weekday, "cccccc");
|
|
812
|
+
}
|
|
813
|
+
function formatWeekNumber(weekNumber, dateLib = defaultDateLib) {
|
|
814
|
+
if (weekNumber < 10) {
|
|
815
|
+
return dateLib.formatNumber(`0${weekNumber.toLocaleString()}`);
|
|
816
|
+
}
|
|
817
|
+
return dateLib.formatNumber(`${weekNumber.toLocaleString()}`);
|
|
818
|
+
}
|
|
819
|
+
function formatWeekNumberHeader() {
|
|
820
|
+
return ``;
|
|
821
|
+
}
|
|
822
|
+
function formatYearDropdown(year, dateLib = defaultDateLib) {
|
|
823
|
+
return dateLib.format(year, "yyyy");
|
|
824
|
+
}
|
|
825
|
+
const formatYearCaption = formatYearDropdown;
|
|
826
|
+
const defaultFormatters = /* @__PURE__ */ Object.freeze({
|
|
827
|
+
__proto__: null,
|
|
828
|
+
formatCaption,
|
|
829
|
+
formatDay,
|
|
830
|
+
formatMonthCaption,
|
|
831
|
+
formatMonthDropdown,
|
|
832
|
+
formatWeekNumber,
|
|
833
|
+
formatWeekNumberHeader,
|
|
834
|
+
formatWeekdayName,
|
|
835
|
+
formatYearCaption,
|
|
836
|
+
formatYearDropdown
|
|
837
|
+
});
|
|
838
|
+
function getFormatters(customFormatters) {
|
|
839
|
+
if (customFormatters?.formatMonthCaption && !customFormatters.formatCaption) {
|
|
840
|
+
customFormatters.formatCaption = customFormatters.formatMonthCaption;
|
|
841
|
+
}
|
|
842
|
+
if (customFormatters?.formatYearCaption && !customFormatters.formatYearDropdown) {
|
|
843
|
+
customFormatters.formatYearDropdown = customFormatters.formatYearCaption;
|
|
844
|
+
}
|
|
845
|
+
return {
|
|
846
|
+
...defaultFormatters,
|
|
847
|
+
...customFormatters
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
function labelDayButton(date, modifiers, options, dateLib) {
|
|
851
|
+
let label = (dateLib ?? new DateLib(options)).format(date, "PPPP");
|
|
852
|
+
if (modifiers.today)
|
|
853
|
+
label = `Today, ${label}`;
|
|
854
|
+
if (modifiers.selected)
|
|
855
|
+
label = `${label}, selected`;
|
|
856
|
+
return label;
|
|
857
|
+
}
|
|
858
|
+
const labelDay = labelDayButton;
|
|
859
|
+
function labelGrid(date, options, dateLib) {
|
|
860
|
+
const lib = dateLib ?? new DateLib(options);
|
|
861
|
+
return lib.formatMonthYear(date);
|
|
862
|
+
}
|
|
863
|
+
const labelCaption = labelGrid;
|
|
864
|
+
function labelGridcell(date, modifiers, options, dateLib) {
|
|
865
|
+
let label = (dateLib ?? new DateLib(options)).format(date, "PPPP");
|
|
866
|
+
if (modifiers?.today) {
|
|
867
|
+
label = `Today, ${label}`;
|
|
868
|
+
}
|
|
869
|
+
return label;
|
|
870
|
+
}
|
|
871
|
+
function labelMonthDropdown(_options) {
|
|
872
|
+
return "Choose the Month";
|
|
873
|
+
}
|
|
874
|
+
function labelNav() {
|
|
875
|
+
return "";
|
|
876
|
+
}
|
|
877
|
+
const defaultLabel = "Go to the Next Month";
|
|
878
|
+
function labelNext(_month, _options) {
|
|
879
|
+
return defaultLabel;
|
|
880
|
+
}
|
|
881
|
+
function labelPrevious(_month) {
|
|
882
|
+
return "Go to the Previous Month";
|
|
883
|
+
}
|
|
884
|
+
function labelWeekday(date, options, dateLib) {
|
|
885
|
+
return (dateLib ?? new DateLib(options)).format(date, "cccc");
|
|
886
|
+
}
|
|
887
|
+
function labelWeekNumber(weekNumber, _options) {
|
|
888
|
+
return `Week ${weekNumber}`;
|
|
889
|
+
}
|
|
890
|
+
function labelWeekNumberHeader(_options) {
|
|
891
|
+
return "Week Number";
|
|
892
|
+
}
|
|
893
|
+
function labelYearDropdown(_options) {
|
|
894
|
+
return "Choose the Year";
|
|
895
|
+
}
|
|
896
|
+
const defaultLabels = /* @__PURE__ */ Object.freeze({
|
|
897
|
+
__proto__: null,
|
|
898
|
+
labelCaption,
|
|
899
|
+
labelDay,
|
|
900
|
+
labelDayButton,
|
|
901
|
+
labelGrid,
|
|
902
|
+
labelGridcell,
|
|
903
|
+
labelMonthDropdown,
|
|
904
|
+
labelNav,
|
|
905
|
+
labelNext,
|
|
906
|
+
labelPrevious,
|
|
907
|
+
labelWeekNumber,
|
|
908
|
+
labelWeekNumberHeader,
|
|
909
|
+
labelWeekday,
|
|
910
|
+
labelYearDropdown
|
|
911
|
+
});
|
|
912
|
+
const resolveLabel = (defaultLabel2, customLabel, localeLabel) => {
|
|
913
|
+
if (customLabel)
|
|
914
|
+
return customLabel;
|
|
915
|
+
if (localeLabel) {
|
|
916
|
+
return typeof localeLabel === "function" ? localeLabel : (..._args) => localeLabel;
|
|
917
|
+
}
|
|
918
|
+
return defaultLabel2;
|
|
919
|
+
};
|
|
920
|
+
function getLabels(customLabels, options) {
|
|
921
|
+
const localeLabels = options.locale?.labels ?? {};
|
|
922
|
+
return {
|
|
923
|
+
...defaultLabels,
|
|
924
|
+
...customLabels ?? {},
|
|
925
|
+
labelDayButton: resolveLabel(labelDayButton, customLabels?.labelDayButton, localeLabels.labelDayButton),
|
|
926
|
+
labelMonthDropdown: resolveLabel(labelMonthDropdown, customLabels?.labelMonthDropdown, localeLabels.labelMonthDropdown),
|
|
927
|
+
labelNext: resolveLabel(labelNext, customLabels?.labelNext, localeLabels.labelNext),
|
|
928
|
+
labelPrevious: resolveLabel(labelPrevious, customLabels?.labelPrevious, localeLabels.labelPrevious),
|
|
929
|
+
labelWeekNumber: resolveLabel(labelWeekNumber, customLabels?.labelWeekNumber, localeLabels.labelWeekNumber),
|
|
930
|
+
labelYearDropdown: resolveLabel(labelYearDropdown, customLabels?.labelYearDropdown, localeLabels.labelYearDropdown),
|
|
931
|
+
labelGrid: resolveLabel(labelGrid, customLabels?.labelGrid, localeLabels.labelGrid),
|
|
932
|
+
labelGridcell: resolveLabel(labelGridcell, customLabels?.labelGridcell, localeLabels.labelGridcell),
|
|
933
|
+
labelNav: resolveLabel(labelNav, customLabels?.labelNav, localeLabels.labelNav),
|
|
934
|
+
labelWeekNumberHeader: resolveLabel(labelWeekNumberHeader, customLabels?.labelWeekNumberHeader, localeLabels.labelWeekNumberHeader),
|
|
935
|
+
labelWeekday: resolveLabel(labelWeekday, customLabels?.labelWeekday, localeLabels.labelWeekday)
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
function getMonthOptions(displayMonth, navStart, navEnd, formatters, dateLib) {
|
|
939
|
+
const { startOfMonth: startOfMonth2, startOfYear: startOfYear2, endOfYear: endOfYear2, eachMonthOfInterval: eachMonthOfInterval2, getMonth: getMonth2 } = dateLib;
|
|
940
|
+
const months = eachMonthOfInterval2({
|
|
941
|
+
start: startOfYear2(displayMonth),
|
|
942
|
+
end: endOfYear2(displayMonth)
|
|
943
|
+
});
|
|
944
|
+
const options = months.map((month) => {
|
|
945
|
+
const label = formatters.formatMonthDropdown(month, dateLib);
|
|
946
|
+
const value = getMonth2(month);
|
|
947
|
+
const disabled = navStart && month < startOfMonth2(navStart) || navEnd && month > startOfMonth2(navEnd) || false;
|
|
948
|
+
return { value, label, disabled };
|
|
949
|
+
});
|
|
950
|
+
return options;
|
|
951
|
+
}
|
|
952
|
+
function getStyleForModifiers(dayModifiers, styles = {}, modifiersStyles = {}) {
|
|
953
|
+
let style = { ...styles?.[UI.Day] };
|
|
954
|
+
Object.entries(dayModifiers).filter(([, active]) => active === true).forEach(([modifier]) => {
|
|
955
|
+
style = {
|
|
956
|
+
...style,
|
|
957
|
+
...modifiersStyles?.[modifier]
|
|
958
|
+
};
|
|
959
|
+
});
|
|
960
|
+
return style;
|
|
961
|
+
}
|
|
962
|
+
function getWeekdays(dateLib, ISOWeek, broadcastCalendar, today) {
|
|
963
|
+
const referenceToday = today ?? dateLib.today();
|
|
964
|
+
const start = broadcastCalendar ? dateLib.startOfBroadcastWeek(referenceToday, dateLib) : ISOWeek ? dateLib.startOfISOWeek(referenceToday) : dateLib.startOfWeek(referenceToday);
|
|
965
|
+
const days = [];
|
|
966
|
+
for (let i = 0; i < 7; i++) {
|
|
967
|
+
const day = dateLib.addDays(start, i);
|
|
968
|
+
days.push(day);
|
|
969
|
+
}
|
|
970
|
+
return days;
|
|
971
|
+
}
|
|
972
|
+
function getYearOptions(navStart, navEnd, formatters, dateLib, reverse = false) {
|
|
973
|
+
if (!navStart)
|
|
974
|
+
return void 0;
|
|
975
|
+
if (!navEnd)
|
|
976
|
+
return void 0;
|
|
977
|
+
const { startOfYear: startOfYear2, endOfYear: endOfYear2, eachYearOfInterval: eachYearOfInterval2, getYear: getYear2 } = dateLib;
|
|
978
|
+
const firstNavYear = startOfYear2(navStart);
|
|
979
|
+
const lastNavYear = endOfYear2(navEnd);
|
|
980
|
+
const years = eachYearOfInterval2({ start: firstNavYear, end: lastNavYear });
|
|
981
|
+
if (reverse)
|
|
982
|
+
years.reverse();
|
|
983
|
+
return years.map((year) => {
|
|
984
|
+
const label = formatters.formatYearDropdown(year, dateLib);
|
|
985
|
+
return {
|
|
986
|
+
value: getYear2(year),
|
|
987
|
+
label,
|
|
988
|
+
disabled: false
|
|
989
|
+
};
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
function createNoonOverrides(timeZone, options = {}) {
|
|
993
|
+
const { weekStartsOn, locale } = options;
|
|
994
|
+
const fallbackWeekStartsOn = weekStartsOn ?? locale?.options?.weekStartsOn ?? 0;
|
|
995
|
+
const toNoonTZDate = (date) => {
|
|
996
|
+
const normalizedDate = typeof date === "number" || typeof date === "string" ? new Date(date) : date;
|
|
997
|
+
return new TZDate(normalizedDate.getFullYear(), normalizedDate.getMonth(), normalizedDate.getDate(), 12, 0, 0, timeZone);
|
|
998
|
+
};
|
|
999
|
+
const toCalendarDate = (date) => {
|
|
1000
|
+
const zoned = toNoonTZDate(date);
|
|
1001
|
+
return new Date(zoned.getFullYear(), zoned.getMonth(), zoned.getDate(), 0, 0, 0, 0);
|
|
1002
|
+
};
|
|
1003
|
+
return {
|
|
1004
|
+
today: () => {
|
|
1005
|
+
return toNoonTZDate(TZDate.tz(timeZone));
|
|
1006
|
+
},
|
|
1007
|
+
newDate: (year, monthIndex, date) => {
|
|
1008
|
+
return new TZDate(year, monthIndex, date, 12, 0, 0, timeZone);
|
|
1009
|
+
},
|
|
1010
|
+
startOfDay: (date) => {
|
|
1011
|
+
return toNoonTZDate(date);
|
|
1012
|
+
},
|
|
1013
|
+
startOfWeek: (date, options2) => {
|
|
1014
|
+
const base = toNoonTZDate(date);
|
|
1015
|
+
const weekStartsOnValue = options2?.weekStartsOn ?? fallbackWeekStartsOn;
|
|
1016
|
+
const diff = (base.getDay() - weekStartsOnValue + 7) % 7;
|
|
1017
|
+
base.setDate(base.getDate() - diff);
|
|
1018
|
+
return base;
|
|
1019
|
+
},
|
|
1020
|
+
startOfISOWeek: (date) => {
|
|
1021
|
+
const base = toNoonTZDate(date);
|
|
1022
|
+
const diff = (base.getDay() - 1 + 7) % 7;
|
|
1023
|
+
base.setDate(base.getDate() - diff);
|
|
1024
|
+
return base;
|
|
1025
|
+
},
|
|
1026
|
+
startOfMonth: (date) => {
|
|
1027
|
+
const base = toNoonTZDate(date);
|
|
1028
|
+
base.setDate(1);
|
|
1029
|
+
return base;
|
|
1030
|
+
},
|
|
1031
|
+
startOfYear: (date) => {
|
|
1032
|
+
const base = toNoonTZDate(date);
|
|
1033
|
+
base.setMonth(0, 1);
|
|
1034
|
+
return base;
|
|
1035
|
+
},
|
|
1036
|
+
endOfWeek: (date, options2) => {
|
|
1037
|
+
const base = toNoonTZDate(date);
|
|
1038
|
+
const weekStartsOnValue = options2?.weekStartsOn ?? fallbackWeekStartsOn;
|
|
1039
|
+
const endDow = (weekStartsOnValue + 6) % 7;
|
|
1040
|
+
const diff = (endDow - base.getDay() + 7) % 7;
|
|
1041
|
+
base.setDate(base.getDate() + diff);
|
|
1042
|
+
return base;
|
|
1043
|
+
},
|
|
1044
|
+
endOfISOWeek: (date) => {
|
|
1045
|
+
const base = toNoonTZDate(date);
|
|
1046
|
+
const diff = (7 - base.getDay()) % 7;
|
|
1047
|
+
base.setDate(base.getDate() + diff);
|
|
1048
|
+
return base;
|
|
1049
|
+
},
|
|
1050
|
+
endOfMonth: (date) => {
|
|
1051
|
+
const base = toNoonTZDate(date);
|
|
1052
|
+
base.setMonth(base.getMonth() + 1, 0);
|
|
1053
|
+
return base;
|
|
1054
|
+
},
|
|
1055
|
+
endOfYear: (date) => {
|
|
1056
|
+
const base = toNoonTZDate(date);
|
|
1057
|
+
base.setMonth(11, 31);
|
|
1058
|
+
return base;
|
|
1059
|
+
},
|
|
1060
|
+
eachMonthOfInterval: (interval) => {
|
|
1061
|
+
const start = toNoonTZDate(interval.start);
|
|
1062
|
+
const end = toNoonTZDate(interval.end);
|
|
1063
|
+
const result = [];
|
|
1064
|
+
const cursor = new TZDate(start.getFullYear(), start.getMonth(), 1, 12, 0, 0, timeZone);
|
|
1065
|
+
const endKey = end.getFullYear() * 12 + end.getMonth();
|
|
1066
|
+
while (cursor.getFullYear() * 12 + cursor.getMonth() <= endKey) {
|
|
1067
|
+
result.push(new TZDate(cursor, timeZone));
|
|
1068
|
+
cursor.setMonth(cursor.getMonth() + 1, 1);
|
|
1069
|
+
}
|
|
1070
|
+
return result;
|
|
1071
|
+
},
|
|
1072
|
+
// Normalize to noon once before arithmetic (avoid DST/midnight edge cases),
|
|
1073
|
+
// mutate the same TZDate, and return it.
|
|
1074
|
+
addDays: (date, amount) => {
|
|
1075
|
+
const base = toNoonTZDate(date);
|
|
1076
|
+
base.setDate(base.getDate() + amount);
|
|
1077
|
+
return base;
|
|
1078
|
+
},
|
|
1079
|
+
addWeeks: (date, amount) => {
|
|
1080
|
+
const base = toNoonTZDate(date);
|
|
1081
|
+
base.setDate(base.getDate() + amount * 7);
|
|
1082
|
+
return base;
|
|
1083
|
+
},
|
|
1084
|
+
addMonths: (date, amount) => {
|
|
1085
|
+
const base = toNoonTZDate(date);
|
|
1086
|
+
base.setMonth(base.getMonth() + amount);
|
|
1087
|
+
return base;
|
|
1088
|
+
},
|
|
1089
|
+
addYears: (date, amount) => {
|
|
1090
|
+
const base = toNoonTZDate(date);
|
|
1091
|
+
base.setFullYear(base.getFullYear() + amount);
|
|
1092
|
+
return base;
|
|
1093
|
+
},
|
|
1094
|
+
eachYearOfInterval: (interval) => {
|
|
1095
|
+
const start = toNoonTZDate(interval.start);
|
|
1096
|
+
const end = toNoonTZDate(interval.end);
|
|
1097
|
+
const years = [];
|
|
1098
|
+
const cursor = new TZDate(start.getFullYear(), 0, 1, 12, 0, 0, timeZone);
|
|
1099
|
+
while (cursor.getFullYear() <= end.getFullYear()) {
|
|
1100
|
+
years.push(new TZDate(cursor, timeZone));
|
|
1101
|
+
cursor.setFullYear(cursor.getFullYear() + 1, 0, 1);
|
|
1102
|
+
}
|
|
1103
|
+
return years;
|
|
1104
|
+
},
|
|
1105
|
+
getWeek: (date, options2) => {
|
|
1106
|
+
const base = toCalendarDate(date);
|
|
1107
|
+
return getWeek(base, {
|
|
1108
|
+
weekStartsOn: options2?.weekStartsOn ?? fallbackWeekStartsOn,
|
|
1109
|
+
firstWeekContainsDate: options2?.firstWeekContainsDate ?? locale?.options?.firstWeekContainsDate ?? 1
|
|
1110
|
+
});
|
|
1111
|
+
},
|
|
1112
|
+
getISOWeek: (date) => {
|
|
1113
|
+
const base = toCalendarDate(date);
|
|
1114
|
+
return getISOWeek(base);
|
|
1115
|
+
},
|
|
1116
|
+
differenceInCalendarDays: (dateLeft, dateRight) => {
|
|
1117
|
+
const left = toCalendarDate(dateLeft);
|
|
1118
|
+
const right = toCalendarDate(dateRight);
|
|
1119
|
+
return differenceInCalendarDays(left, right);
|
|
1120
|
+
},
|
|
1121
|
+
differenceInCalendarMonths: (dateLeft, dateRight) => {
|
|
1122
|
+
const left = toCalendarDate(dateLeft);
|
|
1123
|
+
const right = toCalendarDate(dateRight);
|
|
1124
|
+
return differenceInCalendarMonths(left, right);
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
const asHtmlElement = (element) => {
|
|
1129
|
+
if (element instanceof HTMLElement)
|
|
1130
|
+
return element;
|
|
1131
|
+
return null;
|
|
1132
|
+
};
|
|
1133
|
+
const queryMonthEls = (element) => [
|
|
1134
|
+
...element.querySelectorAll("[data-animated-month]") ?? []
|
|
1135
|
+
];
|
|
1136
|
+
const queryMonthEl = (element) => asHtmlElement(element.querySelector("[data-animated-month]"));
|
|
1137
|
+
const queryCaptionEl = (element) => asHtmlElement(element.querySelector("[data-animated-caption]"));
|
|
1138
|
+
const queryWeeksEl = (element) => asHtmlElement(element.querySelector("[data-animated-weeks]"));
|
|
1139
|
+
const queryNavEl = (element) => asHtmlElement(element.querySelector("[data-animated-nav]"));
|
|
1140
|
+
const queryWeekdaysEl = (element) => asHtmlElement(element.querySelector("[data-animated-weekdays]"));
|
|
1141
|
+
function useAnimation(rootElRef, enabled, { classNames, months, focused, dateLib }) {
|
|
1142
|
+
const previousRootElSnapshotRef = reactExports.useRef(null);
|
|
1143
|
+
const previousMonthsRef = reactExports.useRef(months);
|
|
1144
|
+
const animatingRef = reactExports.useRef(false);
|
|
1145
|
+
reactExports.useLayoutEffect(() => {
|
|
1146
|
+
const previousMonths = previousMonthsRef.current;
|
|
1147
|
+
previousMonthsRef.current = months;
|
|
1148
|
+
if (!enabled || !rootElRef.current || // safety check because the ref can be set to anything by consumers
|
|
1149
|
+
!(rootElRef.current instanceof HTMLElement) || // validation required for the animation to work as expected
|
|
1150
|
+
months.length === 0 || previousMonths.length === 0 || months.length !== previousMonths.length) {
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
const isSameMonth2 = dateLib.isSameMonth(months[0].date, previousMonths[0].date);
|
|
1154
|
+
const isAfterPreviousMonth = dateLib.isAfter(months[0].date, previousMonths[0].date);
|
|
1155
|
+
const captionAnimationClass = isAfterPreviousMonth ? classNames[Animation.caption_after_enter] : classNames[Animation.caption_before_enter];
|
|
1156
|
+
const weeksAnimationClass = isAfterPreviousMonth ? classNames[Animation.weeks_after_enter] : classNames[Animation.weeks_before_enter];
|
|
1157
|
+
const previousRootElSnapshot = previousRootElSnapshotRef.current;
|
|
1158
|
+
const rootElSnapshot = rootElRef.current.cloneNode(true);
|
|
1159
|
+
if (rootElSnapshot instanceof HTMLElement) {
|
|
1160
|
+
const currentMonthElsSnapshot = queryMonthEls(rootElSnapshot);
|
|
1161
|
+
currentMonthElsSnapshot.forEach((currentMonthElSnapshot) => {
|
|
1162
|
+
if (!(currentMonthElSnapshot instanceof HTMLElement))
|
|
1163
|
+
return;
|
|
1164
|
+
const previousMonthElSnapshot = queryMonthEl(currentMonthElSnapshot);
|
|
1165
|
+
if (previousMonthElSnapshot && currentMonthElSnapshot.contains(previousMonthElSnapshot)) {
|
|
1166
|
+
currentMonthElSnapshot.removeChild(previousMonthElSnapshot);
|
|
1167
|
+
}
|
|
1168
|
+
const captionEl = queryCaptionEl(currentMonthElSnapshot);
|
|
1169
|
+
if (captionEl) {
|
|
1170
|
+
captionEl.classList.remove(captionAnimationClass);
|
|
1171
|
+
}
|
|
1172
|
+
const weeksEl = queryWeeksEl(currentMonthElSnapshot);
|
|
1173
|
+
if (weeksEl) {
|
|
1174
|
+
weeksEl.classList.remove(weeksAnimationClass);
|
|
1175
|
+
}
|
|
1176
|
+
});
|
|
1177
|
+
previousRootElSnapshotRef.current = rootElSnapshot;
|
|
1178
|
+
} else {
|
|
1179
|
+
previousRootElSnapshotRef.current = null;
|
|
1180
|
+
}
|
|
1181
|
+
if (animatingRef.current || isSameMonth2 || // skip animation if a day is focused because it can cause issues to the animation and is better for a11y
|
|
1182
|
+
focused) {
|
|
1183
|
+
return;
|
|
1184
|
+
}
|
|
1185
|
+
const previousMonthEls = previousRootElSnapshot instanceof HTMLElement ? queryMonthEls(previousRootElSnapshot) : [];
|
|
1186
|
+
const currentMonthEls = queryMonthEls(rootElRef.current);
|
|
1187
|
+
if (currentMonthEls?.every((el) => el instanceof HTMLElement) && previousMonthEls && previousMonthEls.every((el) => el instanceof HTMLElement)) {
|
|
1188
|
+
animatingRef.current = true;
|
|
1189
|
+
rootElRef.current.style.isolation = "isolate";
|
|
1190
|
+
const navEl = queryNavEl(rootElRef.current);
|
|
1191
|
+
if (navEl) {
|
|
1192
|
+
navEl.style.zIndex = "1";
|
|
1193
|
+
}
|
|
1194
|
+
currentMonthEls.forEach((currentMonthEl, index) => {
|
|
1195
|
+
const previousMonthEl = previousMonthEls[index];
|
|
1196
|
+
if (!previousMonthEl) {
|
|
1197
|
+
return;
|
|
1198
|
+
}
|
|
1199
|
+
currentMonthEl.style.position = "relative";
|
|
1200
|
+
currentMonthEl.style.overflow = "hidden";
|
|
1201
|
+
const captionEl = queryCaptionEl(currentMonthEl);
|
|
1202
|
+
if (captionEl) {
|
|
1203
|
+
captionEl.classList.add(captionAnimationClass);
|
|
1204
|
+
}
|
|
1205
|
+
const weeksEl = queryWeeksEl(currentMonthEl);
|
|
1206
|
+
if (weeksEl) {
|
|
1207
|
+
weeksEl.classList.add(weeksAnimationClass);
|
|
1208
|
+
}
|
|
1209
|
+
const cleanUp = () => {
|
|
1210
|
+
animatingRef.current = false;
|
|
1211
|
+
if (rootElRef.current) {
|
|
1212
|
+
rootElRef.current.style.isolation = "";
|
|
1213
|
+
}
|
|
1214
|
+
if (navEl) {
|
|
1215
|
+
navEl.style.zIndex = "";
|
|
1216
|
+
}
|
|
1217
|
+
if (captionEl) {
|
|
1218
|
+
captionEl.classList.remove(captionAnimationClass);
|
|
1219
|
+
}
|
|
1220
|
+
if (weeksEl) {
|
|
1221
|
+
weeksEl.classList.remove(weeksAnimationClass);
|
|
1222
|
+
}
|
|
1223
|
+
currentMonthEl.style.position = "";
|
|
1224
|
+
currentMonthEl.style.overflow = "";
|
|
1225
|
+
if (currentMonthEl.contains(previousMonthEl)) {
|
|
1226
|
+
currentMonthEl.removeChild(previousMonthEl);
|
|
1227
|
+
}
|
|
1228
|
+
};
|
|
1229
|
+
previousMonthEl.style.pointerEvents = "none";
|
|
1230
|
+
previousMonthEl.style.position = "absolute";
|
|
1231
|
+
previousMonthEl.style.overflow = "hidden";
|
|
1232
|
+
previousMonthEl.setAttribute("aria-hidden", "true");
|
|
1233
|
+
const previousWeekdaysEl = queryWeekdaysEl(previousMonthEl);
|
|
1234
|
+
if (previousWeekdaysEl) {
|
|
1235
|
+
previousWeekdaysEl.style.opacity = "0";
|
|
1236
|
+
}
|
|
1237
|
+
const previousCaptionEl = queryCaptionEl(previousMonthEl);
|
|
1238
|
+
if (previousCaptionEl) {
|
|
1239
|
+
previousCaptionEl.classList.add(isAfterPreviousMonth ? classNames[Animation.caption_before_exit] : classNames[Animation.caption_after_exit]);
|
|
1240
|
+
previousCaptionEl.addEventListener("animationend", cleanUp);
|
|
1241
|
+
}
|
|
1242
|
+
const previousWeeksEl = queryWeeksEl(previousMonthEl);
|
|
1243
|
+
if (previousWeeksEl) {
|
|
1244
|
+
previousWeeksEl.classList.add(isAfterPreviousMonth ? classNames[Animation.weeks_before_exit] : classNames[Animation.weeks_after_exit]);
|
|
1245
|
+
}
|
|
1246
|
+
currentMonthEl.insertBefore(previousMonthEl, currentMonthEl.firstChild);
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
function getDates(displayMonths, maxDate, props, dateLib) {
|
|
1252
|
+
const firstMonth = displayMonths[0];
|
|
1253
|
+
const lastMonth = displayMonths[displayMonths.length - 1];
|
|
1254
|
+
const { ISOWeek, fixedWeeks, broadcastCalendar } = props ?? {};
|
|
1255
|
+
const { addDays: addDays2, differenceInCalendarDays: differenceInCalendarDays2, differenceInCalendarMonths: differenceInCalendarMonths2, endOfBroadcastWeek: endOfBroadcastWeek2, endOfISOWeek: endOfISOWeek2, endOfMonth: endOfMonth2, endOfWeek: endOfWeek2, isAfter: isAfter2, startOfBroadcastWeek: startOfBroadcastWeek2, startOfISOWeek: startOfISOWeek2, startOfWeek: startOfWeek2 } = dateLib;
|
|
1256
|
+
const startWeekFirstDate = broadcastCalendar ? startOfBroadcastWeek2(firstMonth, dateLib) : ISOWeek ? startOfISOWeek2(firstMonth) : startOfWeek2(firstMonth);
|
|
1257
|
+
const displayMonthsWeekEnd = broadcastCalendar ? endOfBroadcastWeek2(lastMonth) : ISOWeek ? endOfISOWeek2(endOfMonth2(lastMonth)) : endOfWeek2(endOfMonth2(lastMonth));
|
|
1258
|
+
const constraintWeekEnd = maxDate && (broadcastCalendar ? endOfBroadcastWeek2(maxDate) : ISOWeek ? endOfISOWeek2(maxDate) : endOfWeek2(maxDate));
|
|
1259
|
+
const gridEndDate = constraintWeekEnd && isAfter2(displayMonthsWeekEnd, constraintWeekEnd) ? constraintWeekEnd : displayMonthsWeekEnd;
|
|
1260
|
+
const nOfDays = differenceInCalendarDays2(gridEndDate, startWeekFirstDate);
|
|
1261
|
+
const nOfMonths = differenceInCalendarMonths2(lastMonth, firstMonth) + 1;
|
|
1262
|
+
const dates = [];
|
|
1263
|
+
for (let i = 0; i <= nOfDays; i++) {
|
|
1264
|
+
const date = addDays2(startWeekFirstDate, i);
|
|
1265
|
+
dates.push(date);
|
|
1266
|
+
}
|
|
1267
|
+
const nrOfDaysWithFixedWeeks = broadcastCalendar ? 35 : 42;
|
|
1268
|
+
const extraDates = nrOfDaysWithFixedWeeks * nOfMonths;
|
|
1269
|
+
if (fixedWeeks && dates.length < extraDates) {
|
|
1270
|
+
const daysToAdd = extraDates - dates.length;
|
|
1271
|
+
for (let i = 0; i < daysToAdd; i++) {
|
|
1272
|
+
const date = addDays2(dates[dates.length - 1], 1);
|
|
1273
|
+
dates.push(date);
|
|
1274
|
+
}
|
|
1275
|
+
}
|
|
1276
|
+
return dates;
|
|
1277
|
+
}
|
|
1278
|
+
function getDays(calendarMonths) {
|
|
1279
|
+
const initialDays = [];
|
|
1280
|
+
return calendarMonths.reduce((days, month) => {
|
|
1281
|
+
const weekDays = month.weeks.reduce((weekDays2, week) => {
|
|
1282
|
+
return weekDays2.concat(week.days.slice());
|
|
1283
|
+
}, initialDays.slice());
|
|
1284
|
+
return days.concat(weekDays.slice());
|
|
1285
|
+
}, initialDays.slice());
|
|
1286
|
+
}
|
|
1287
|
+
function getDisplayMonths(firstDisplayedMonth, calendarEndMonth, props, dateLib) {
|
|
1288
|
+
const { numberOfMonths = 1 } = props;
|
|
1289
|
+
const months = [];
|
|
1290
|
+
for (let i = 0; i < numberOfMonths; i++) {
|
|
1291
|
+
const month = dateLib.addMonths(firstDisplayedMonth, i);
|
|
1292
|
+
if (calendarEndMonth && month > calendarEndMonth) {
|
|
1293
|
+
break;
|
|
1294
|
+
}
|
|
1295
|
+
months.push(month);
|
|
1296
|
+
}
|
|
1297
|
+
return months;
|
|
1298
|
+
}
|
|
1299
|
+
function getInitialMonth(props, navStart, navEnd, dateLib) {
|
|
1300
|
+
const { month, defaultMonth, today = dateLib.today(), numberOfMonths = 1 } = props;
|
|
1301
|
+
let initialMonth = month || defaultMonth || today;
|
|
1302
|
+
const { differenceInCalendarMonths: differenceInCalendarMonths2, addMonths: addMonths2, startOfMonth: startOfMonth2 } = dateLib;
|
|
1303
|
+
if (navEnd && differenceInCalendarMonths2(navEnd, initialMonth) < numberOfMonths - 1) {
|
|
1304
|
+
const offset = -1 * (numberOfMonths - 1);
|
|
1305
|
+
initialMonth = addMonths2(navEnd, offset);
|
|
1306
|
+
}
|
|
1307
|
+
if (navStart && differenceInCalendarMonths2(initialMonth, navStart) < 0) {
|
|
1308
|
+
initialMonth = navStart;
|
|
1309
|
+
}
|
|
1310
|
+
return startOfMonth2(initialMonth);
|
|
1311
|
+
}
|
|
1312
|
+
function getMonths(displayMonths, dates, props, dateLib) {
|
|
1313
|
+
const { addDays: addDays2, endOfBroadcastWeek: endOfBroadcastWeek2, endOfISOWeek: endOfISOWeek2, endOfMonth: endOfMonth2, endOfWeek: endOfWeek2, getISOWeek: getISOWeek2, getWeek: getWeek2, startOfBroadcastWeek: startOfBroadcastWeek2, startOfISOWeek: startOfISOWeek2, startOfWeek: startOfWeek2 } = dateLib;
|
|
1314
|
+
const dayPickerMonths = displayMonths.reduce((months, month) => {
|
|
1315
|
+
const firstDateOfFirstWeek = props.broadcastCalendar ? startOfBroadcastWeek2(month, dateLib) : props.ISOWeek ? startOfISOWeek2(month) : startOfWeek2(month);
|
|
1316
|
+
const lastDateOfLastWeek = props.broadcastCalendar ? endOfBroadcastWeek2(month) : props.ISOWeek ? endOfISOWeek2(endOfMonth2(month)) : endOfWeek2(endOfMonth2(month));
|
|
1317
|
+
const monthDates = dates.filter((date) => {
|
|
1318
|
+
return date >= firstDateOfFirstWeek && date <= lastDateOfLastWeek;
|
|
1319
|
+
});
|
|
1320
|
+
const nrOfDaysWithFixedWeeks = props.broadcastCalendar ? 35 : 42;
|
|
1321
|
+
if (props.fixedWeeks && monthDates.length < nrOfDaysWithFixedWeeks) {
|
|
1322
|
+
const extraDates = dates.filter((date) => {
|
|
1323
|
+
const daysToAdd = nrOfDaysWithFixedWeeks - monthDates.length;
|
|
1324
|
+
return date > lastDateOfLastWeek && date <= addDays2(lastDateOfLastWeek, daysToAdd);
|
|
1325
|
+
});
|
|
1326
|
+
monthDates.push(...extraDates);
|
|
1327
|
+
}
|
|
1328
|
+
const weeks = monthDates.reduce((weeks2, date) => {
|
|
1329
|
+
const weekNumber = props.ISOWeek ? getISOWeek2(date) : getWeek2(date);
|
|
1330
|
+
const week = weeks2.find((week2) => week2.weekNumber === weekNumber);
|
|
1331
|
+
const day = new CalendarDay(date, month, dateLib);
|
|
1332
|
+
if (!week) {
|
|
1333
|
+
weeks2.push(new CalendarWeek(weekNumber, [day]));
|
|
1334
|
+
} else {
|
|
1335
|
+
week.days.push(day);
|
|
1336
|
+
}
|
|
1337
|
+
return weeks2;
|
|
1338
|
+
}, []);
|
|
1339
|
+
const dayPickerMonth = new CalendarMonth(month, weeks);
|
|
1340
|
+
months.push(dayPickerMonth);
|
|
1341
|
+
return months;
|
|
1342
|
+
}, []);
|
|
1343
|
+
if (!props.reverseMonths) {
|
|
1344
|
+
return dayPickerMonths;
|
|
1345
|
+
} else {
|
|
1346
|
+
return dayPickerMonths.reverse();
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
function getNavMonths(props, dateLib) {
|
|
1350
|
+
let { startMonth, endMonth } = props;
|
|
1351
|
+
const { startOfYear: startOfYear2, startOfDay: startOfDay2, startOfMonth: startOfMonth2, endOfMonth: endOfMonth2, addYears: addYears2, endOfYear: endOfYear2, newDate, today } = dateLib;
|
|
1352
|
+
const { fromYear, toYear, fromMonth, toMonth } = props;
|
|
1353
|
+
if (!startMonth && fromMonth) {
|
|
1354
|
+
startMonth = fromMonth;
|
|
1355
|
+
}
|
|
1356
|
+
if (!startMonth && fromYear) {
|
|
1357
|
+
startMonth = dateLib.newDate(fromYear, 0, 1);
|
|
1358
|
+
}
|
|
1359
|
+
if (!endMonth && toMonth) {
|
|
1360
|
+
endMonth = toMonth;
|
|
1361
|
+
}
|
|
1362
|
+
if (!endMonth && toYear) {
|
|
1363
|
+
endMonth = newDate(toYear, 11, 31);
|
|
1364
|
+
}
|
|
1365
|
+
const hasYearDropdown = props.captionLayout === "dropdown" || props.captionLayout === "dropdown-years";
|
|
1366
|
+
if (startMonth) {
|
|
1367
|
+
startMonth = startOfMonth2(startMonth);
|
|
1368
|
+
} else if (fromYear) {
|
|
1369
|
+
startMonth = newDate(fromYear, 0, 1);
|
|
1370
|
+
} else if (!startMonth && hasYearDropdown) {
|
|
1371
|
+
startMonth = startOfYear2(addYears2(props.today ?? today(), -100));
|
|
1372
|
+
}
|
|
1373
|
+
if (endMonth) {
|
|
1374
|
+
endMonth = endOfMonth2(endMonth);
|
|
1375
|
+
} else if (toYear) {
|
|
1376
|
+
endMonth = newDate(toYear, 11, 31);
|
|
1377
|
+
} else if (!endMonth && hasYearDropdown) {
|
|
1378
|
+
endMonth = endOfYear2(props.today ?? today());
|
|
1379
|
+
}
|
|
1380
|
+
return [
|
|
1381
|
+
startMonth ? startOfDay2(startMonth) : startMonth,
|
|
1382
|
+
endMonth ? startOfDay2(endMonth) : endMonth
|
|
1383
|
+
];
|
|
1384
|
+
}
|
|
1385
|
+
function getNextMonth(firstDisplayedMonth, calendarEndMonth, options, dateLib) {
|
|
1386
|
+
if (options.disableNavigation) {
|
|
1387
|
+
return void 0;
|
|
1388
|
+
}
|
|
1389
|
+
const { pagedNavigation, numberOfMonths = 1 } = options;
|
|
1390
|
+
const { startOfMonth: startOfMonth2, addMonths: addMonths2, differenceInCalendarMonths: differenceInCalendarMonths2 } = dateLib;
|
|
1391
|
+
const offset = pagedNavigation ? numberOfMonths : 1;
|
|
1392
|
+
const month = startOfMonth2(firstDisplayedMonth);
|
|
1393
|
+
if (!calendarEndMonth) {
|
|
1394
|
+
return addMonths2(month, offset);
|
|
1395
|
+
}
|
|
1396
|
+
const monthsDiff = differenceInCalendarMonths2(calendarEndMonth, firstDisplayedMonth);
|
|
1397
|
+
if (monthsDiff < numberOfMonths) {
|
|
1398
|
+
return void 0;
|
|
1399
|
+
}
|
|
1400
|
+
return addMonths2(month, offset);
|
|
1401
|
+
}
|
|
1402
|
+
function getPreviousMonth(firstDisplayedMonth, calendarStartMonth, options, dateLib) {
|
|
1403
|
+
if (options.disableNavigation) {
|
|
1404
|
+
return void 0;
|
|
1405
|
+
}
|
|
1406
|
+
const { pagedNavigation, numberOfMonths } = options;
|
|
1407
|
+
const { startOfMonth: startOfMonth2, addMonths: addMonths2, differenceInCalendarMonths: differenceInCalendarMonths2 } = dateLib;
|
|
1408
|
+
const offset = pagedNavigation ? numberOfMonths ?? 1 : 1;
|
|
1409
|
+
const month = startOfMonth2(firstDisplayedMonth);
|
|
1410
|
+
if (!calendarStartMonth) {
|
|
1411
|
+
return addMonths2(month, -offset);
|
|
1412
|
+
}
|
|
1413
|
+
const monthsDiff = differenceInCalendarMonths2(month, calendarStartMonth);
|
|
1414
|
+
if (monthsDiff <= 0) {
|
|
1415
|
+
return void 0;
|
|
1416
|
+
}
|
|
1417
|
+
return addMonths2(month, -offset);
|
|
1418
|
+
}
|
|
1419
|
+
function getWeeks(months) {
|
|
1420
|
+
const initialWeeks = [];
|
|
1421
|
+
return months.reduce((weeks, month) => {
|
|
1422
|
+
return weeks.concat(month.weeks.slice());
|
|
1423
|
+
}, initialWeeks.slice());
|
|
1424
|
+
}
|
|
1425
|
+
function useControlledValue(defaultValue, controlledValue) {
|
|
1426
|
+
const [uncontrolledValue, setValue] = reactExports.useState(defaultValue);
|
|
1427
|
+
const value = controlledValue === void 0 ? uncontrolledValue : controlledValue;
|
|
1428
|
+
return [value, setValue];
|
|
1429
|
+
}
|
|
1430
|
+
function useCalendar(props, dateLib) {
|
|
1431
|
+
const [navStart, navEnd] = getNavMonths(props, dateLib);
|
|
1432
|
+
const { startOfMonth: startOfMonth2, endOfMonth: endOfMonth2 } = dateLib;
|
|
1433
|
+
const initialMonth = getInitialMonth(props, navStart, navEnd, dateLib);
|
|
1434
|
+
const [firstMonth, setFirstMonth] = useControlledValue(
|
|
1435
|
+
initialMonth,
|
|
1436
|
+
// initialMonth is always computed from props.month if provided
|
|
1437
|
+
props.month ? initialMonth : void 0
|
|
1438
|
+
);
|
|
1439
|
+
reactExports.useEffect(() => {
|
|
1440
|
+
const newInitialMonth = getInitialMonth(props, navStart, navEnd, dateLib);
|
|
1441
|
+
setFirstMonth(newInitialMonth);
|
|
1442
|
+
}, [props.timeZone]);
|
|
1443
|
+
const { months, weeks, days, previousMonth, nextMonth } = reactExports.useMemo(() => {
|
|
1444
|
+
const displayMonths = getDisplayMonths(firstMonth, navEnd, { numberOfMonths: props.numberOfMonths }, dateLib);
|
|
1445
|
+
const dates = getDates(displayMonths, props.endMonth ? endOfMonth2(props.endMonth) : void 0, {
|
|
1446
|
+
ISOWeek: props.ISOWeek,
|
|
1447
|
+
fixedWeeks: props.fixedWeeks,
|
|
1448
|
+
broadcastCalendar: props.broadcastCalendar
|
|
1449
|
+
}, dateLib);
|
|
1450
|
+
const months2 = getMonths(displayMonths, dates, {
|
|
1451
|
+
broadcastCalendar: props.broadcastCalendar,
|
|
1452
|
+
fixedWeeks: props.fixedWeeks,
|
|
1453
|
+
ISOWeek: props.ISOWeek,
|
|
1454
|
+
reverseMonths: props.reverseMonths
|
|
1455
|
+
}, dateLib);
|
|
1456
|
+
const weeks2 = getWeeks(months2);
|
|
1457
|
+
const days2 = getDays(months2);
|
|
1458
|
+
const previousMonth2 = getPreviousMonth(firstMonth, navStart, props, dateLib);
|
|
1459
|
+
const nextMonth2 = getNextMonth(firstMonth, navEnd, props, dateLib);
|
|
1460
|
+
return {
|
|
1461
|
+
months: months2,
|
|
1462
|
+
weeks: weeks2,
|
|
1463
|
+
days: days2,
|
|
1464
|
+
previousMonth: previousMonth2,
|
|
1465
|
+
nextMonth: nextMonth2
|
|
1466
|
+
};
|
|
1467
|
+
}, [
|
|
1468
|
+
dateLib,
|
|
1469
|
+
firstMonth.getTime(),
|
|
1470
|
+
navEnd?.getTime(),
|
|
1471
|
+
navStart?.getTime(),
|
|
1472
|
+
props.disableNavigation,
|
|
1473
|
+
props.broadcastCalendar,
|
|
1474
|
+
props.endMonth?.getTime(),
|
|
1475
|
+
props.fixedWeeks,
|
|
1476
|
+
props.ISOWeek,
|
|
1477
|
+
props.numberOfMonths,
|
|
1478
|
+
props.pagedNavigation,
|
|
1479
|
+
props.reverseMonths
|
|
1480
|
+
]);
|
|
1481
|
+
const { disableNavigation, onMonthChange } = props;
|
|
1482
|
+
const isDayInCalendar = (day) => weeks.some((week) => week.days.some((d) => d.isEqualTo(day)));
|
|
1483
|
+
const goToMonth = (date) => {
|
|
1484
|
+
if (disableNavigation) {
|
|
1485
|
+
return;
|
|
1486
|
+
}
|
|
1487
|
+
let newMonth = startOfMonth2(date);
|
|
1488
|
+
if (navStart && newMonth < startOfMonth2(navStart)) {
|
|
1489
|
+
newMonth = startOfMonth2(navStart);
|
|
1490
|
+
}
|
|
1491
|
+
if (navEnd && newMonth > startOfMonth2(navEnd)) {
|
|
1492
|
+
newMonth = startOfMonth2(navEnd);
|
|
1493
|
+
}
|
|
1494
|
+
setFirstMonth(newMonth);
|
|
1495
|
+
onMonthChange?.(newMonth);
|
|
1496
|
+
};
|
|
1497
|
+
const goToDay = (day) => {
|
|
1498
|
+
if (isDayInCalendar(day)) {
|
|
1499
|
+
return;
|
|
1500
|
+
}
|
|
1501
|
+
goToMonth(day.date);
|
|
1502
|
+
};
|
|
1503
|
+
const calendar = {
|
|
1504
|
+
months,
|
|
1505
|
+
weeks,
|
|
1506
|
+
days,
|
|
1507
|
+
navStart,
|
|
1508
|
+
navEnd,
|
|
1509
|
+
previousMonth,
|
|
1510
|
+
nextMonth,
|
|
1511
|
+
goToMonth,
|
|
1512
|
+
goToDay
|
|
1513
|
+
};
|
|
1514
|
+
return calendar;
|
|
1515
|
+
}
|
|
1516
|
+
var FocusTargetPriority;
|
|
1517
|
+
(function(FocusTargetPriority2) {
|
|
1518
|
+
FocusTargetPriority2[FocusTargetPriority2["Today"] = 0] = "Today";
|
|
1519
|
+
FocusTargetPriority2[FocusTargetPriority2["Selected"] = 1] = "Selected";
|
|
1520
|
+
FocusTargetPriority2[FocusTargetPriority2["LastFocused"] = 2] = "LastFocused";
|
|
1521
|
+
FocusTargetPriority2[FocusTargetPriority2["FocusedModifier"] = 3] = "FocusedModifier";
|
|
1522
|
+
})(FocusTargetPriority || (FocusTargetPriority = {}));
|
|
1523
|
+
function isFocusableDay(modifiers) {
|
|
1524
|
+
return !modifiers[DayFlag.disabled] && !modifiers[DayFlag.hidden] && !modifiers[DayFlag.outside];
|
|
1525
|
+
}
|
|
1526
|
+
function calculateFocusTarget(days, getModifiers, isSelected, lastFocused) {
|
|
1527
|
+
let focusTarget;
|
|
1528
|
+
let foundFocusTargetPriority = -1;
|
|
1529
|
+
for (const day of days) {
|
|
1530
|
+
const modifiers = getModifiers(day);
|
|
1531
|
+
if (isFocusableDay(modifiers)) {
|
|
1532
|
+
if (modifiers[DayFlag.focused] && foundFocusTargetPriority < FocusTargetPriority.FocusedModifier) {
|
|
1533
|
+
focusTarget = day;
|
|
1534
|
+
foundFocusTargetPriority = FocusTargetPriority.FocusedModifier;
|
|
1535
|
+
} else if (lastFocused?.isEqualTo(day) && foundFocusTargetPriority < FocusTargetPriority.LastFocused) {
|
|
1536
|
+
focusTarget = day;
|
|
1537
|
+
foundFocusTargetPriority = FocusTargetPriority.LastFocused;
|
|
1538
|
+
} else if (isSelected(day.date) && foundFocusTargetPriority < FocusTargetPriority.Selected) {
|
|
1539
|
+
focusTarget = day;
|
|
1540
|
+
foundFocusTargetPriority = FocusTargetPriority.Selected;
|
|
1541
|
+
} else if (modifiers[DayFlag.today] && foundFocusTargetPriority < FocusTargetPriority.Today) {
|
|
1542
|
+
focusTarget = day;
|
|
1543
|
+
foundFocusTargetPriority = FocusTargetPriority.Today;
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
if (!focusTarget) {
|
|
1548
|
+
focusTarget = days.find((day) => isFocusableDay(getModifiers(day)));
|
|
1549
|
+
}
|
|
1550
|
+
return focusTarget;
|
|
1551
|
+
}
|
|
1552
|
+
function getFocusableDate(moveBy, moveDir, refDate, navStart, navEnd, props, dateLib) {
|
|
1553
|
+
const { ISOWeek, broadcastCalendar } = props;
|
|
1554
|
+
const { addDays: addDays2, addMonths: addMonths2, addWeeks: addWeeks2, addYears: addYears2, endOfBroadcastWeek: endOfBroadcastWeek2, endOfISOWeek: endOfISOWeek2, endOfWeek: endOfWeek2, max: max2, min: min2, startOfBroadcastWeek: startOfBroadcastWeek2, startOfISOWeek: startOfISOWeek2, startOfWeek: startOfWeek2 } = dateLib;
|
|
1555
|
+
const moveFns = {
|
|
1556
|
+
day: addDays2,
|
|
1557
|
+
week: addWeeks2,
|
|
1558
|
+
month: addMonths2,
|
|
1559
|
+
year: addYears2,
|
|
1560
|
+
startOfWeek: (date) => broadcastCalendar ? startOfBroadcastWeek2(date, dateLib) : ISOWeek ? startOfISOWeek2(date) : startOfWeek2(date),
|
|
1561
|
+
endOfWeek: (date) => broadcastCalendar ? endOfBroadcastWeek2(date) : ISOWeek ? endOfISOWeek2(date) : endOfWeek2(date)
|
|
1562
|
+
};
|
|
1563
|
+
let focusableDate = moveFns[moveBy](refDate, moveDir === "after" ? 1 : -1);
|
|
1564
|
+
if (moveDir === "before" && navStart) {
|
|
1565
|
+
focusableDate = max2([navStart, focusableDate]);
|
|
1566
|
+
} else if (moveDir === "after" && navEnd) {
|
|
1567
|
+
focusableDate = min2([navEnd, focusableDate]);
|
|
1568
|
+
}
|
|
1569
|
+
return focusableDate;
|
|
1570
|
+
}
|
|
1571
|
+
function getNextFocus(moveBy, moveDir, refDay, calendarStartMonth, calendarEndMonth, props, dateLib, attempt = 0) {
|
|
1572
|
+
if (attempt > 365) {
|
|
1573
|
+
return void 0;
|
|
1574
|
+
}
|
|
1575
|
+
const focusableDate = getFocusableDate(moveBy, moveDir, refDay.date, calendarStartMonth, calendarEndMonth, props, dateLib);
|
|
1576
|
+
const isDisabled = Boolean(props.disabled && dateMatchModifiers(focusableDate, props.disabled, dateLib));
|
|
1577
|
+
const isHidden = Boolean(props.hidden && dateMatchModifiers(focusableDate, props.hidden, dateLib));
|
|
1578
|
+
const targetMonth = focusableDate;
|
|
1579
|
+
const focusDay = new CalendarDay(focusableDate, targetMonth, dateLib);
|
|
1580
|
+
if (!isDisabled && !isHidden) {
|
|
1581
|
+
return focusDay;
|
|
1582
|
+
}
|
|
1583
|
+
return getNextFocus(moveBy, moveDir, focusDay, calendarStartMonth, calendarEndMonth, props, dateLib, attempt + 1);
|
|
1584
|
+
}
|
|
1585
|
+
function useFocus(props, calendar, getModifiers, isSelected, dateLib) {
|
|
1586
|
+
const { autoFocus } = props;
|
|
1587
|
+
const [lastFocused, setLastFocused] = reactExports.useState();
|
|
1588
|
+
const focusTarget = calculateFocusTarget(calendar.days, getModifiers, isSelected || (() => false), lastFocused);
|
|
1589
|
+
const [focusedDay, setFocused] = reactExports.useState(autoFocus ? focusTarget : void 0);
|
|
1590
|
+
const blur = () => {
|
|
1591
|
+
setLastFocused(focusedDay);
|
|
1592
|
+
setFocused(void 0);
|
|
1593
|
+
};
|
|
1594
|
+
const moveFocus = (moveBy, moveDir) => {
|
|
1595
|
+
if (!focusedDay)
|
|
1596
|
+
return;
|
|
1597
|
+
const nextFocus = getNextFocus(moveBy, moveDir, focusedDay, calendar.navStart, calendar.navEnd, props, dateLib);
|
|
1598
|
+
if (!nextFocus)
|
|
1599
|
+
return;
|
|
1600
|
+
if (props.disableNavigation) {
|
|
1601
|
+
const isNextInCalendar = calendar.days.some((day) => day.isEqualTo(nextFocus));
|
|
1602
|
+
if (!isNextInCalendar) {
|
|
1603
|
+
return;
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
calendar.goToDay(nextFocus);
|
|
1607
|
+
setFocused(nextFocus);
|
|
1608
|
+
};
|
|
1609
|
+
const isFocusTarget = (day) => {
|
|
1610
|
+
return Boolean(focusTarget?.isEqualTo(day));
|
|
1611
|
+
};
|
|
1612
|
+
const useFocus2 = {
|
|
1613
|
+
isFocusTarget,
|
|
1614
|
+
setFocused,
|
|
1615
|
+
focused: focusedDay,
|
|
1616
|
+
blur,
|
|
1617
|
+
moveFocus
|
|
1618
|
+
};
|
|
1619
|
+
return useFocus2;
|
|
1620
|
+
}
|
|
1621
|
+
function useMulti(props, dateLib) {
|
|
1622
|
+
const { selected: initiallySelected, required, onSelect } = props;
|
|
1623
|
+
const [internallySelected, setSelected] = useControlledValue(initiallySelected, onSelect ? initiallySelected : void 0);
|
|
1624
|
+
const selected = !onSelect ? internallySelected : initiallySelected;
|
|
1625
|
+
const { isSameDay: isSameDay2 } = dateLib;
|
|
1626
|
+
const isSelected = (date) => {
|
|
1627
|
+
return selected?.some((d) => isSameDay2(d, date)) ?? false;
|
|
1628
|
+
};
|
|
1629
|
+
const { min: min2, max: max2 } = props;
|
|
1630
|
+
const select = (triggerDate, modifiers, e) => {
|
|
1631
|
+
let newDates = [...selected ?? []];
|
|
1632
|
+
if (isSelected(triggerDate)) {
|
|
1633
|
+
if (selected?.length === min2) {
|
|
1634
|
+
return;
|
|
1635
|
+
}
|
|
1636
|
+
if (required && selected?.length === 1) {
|
|
1637
|
+
return;
|
|
1638
|
+
}
|
|
1639
|
+
newDates = selected?.filter((d) => !isSameDay2(d, triggerDate));
|
|
1640
|
+
} else {
|
|
1641
|
+
if (selected?.length === max2) {
|
|
1642
|
+
newDates = [triggerDate];
|
|
1643
|
+
} else {
|
|
1644
|
+
newDates = [...newDates, triggerDate];
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
if (!onSelect) {
|
|
1648
|
+
setSelected(newDates);
|
|
1649
|
+
}
|
|
1650
|
+
onSelect?.(newDates, triggerDate, modifiers, e);
|
|
1651
|
+
return newDates;
|
|
1652
|
+
};
|
|
1653
|
+
return {
|
|
1654
|
+
selected,
|
|
1655
|
+
select,
|
|
1656
|
+
isSelected
|
|
1657
|
+
};
|
|
1658
|
+
}
|
|
1659
|
+
function addToRange(date, initialRange, min2 = 0, max2 = 0, required = false, dateLib = defaultDateLib) {
|
|
1660
|
+
const { from, to } = initialRange || {};
|
|
1661
|
+
const { isSameDay: isSameDay2, isAfter: isAfter2, isBefore: isBefore2 } = dateLib;
|
|
1662
|
+
let range;
|
|
1663
|
+
if (!from && !to) {
|
|
1664
|
+
range = { from: date, to: min2 > 0 ? void 0 : date };
|
|
1665
|
+
} else if (from && !to) {
|
|
1666
|
+
if (isSameDay2(from, date)) {
|
|
1667
|
+
if (min2 === 0) {
|
|
1668
|
+
range = { from, to: date };
|
|
1669
|
+
} else if (required) {
|
|
1670
|
+
range = { from, to: void 0 };
|
|
1671
|
+
} else {
|
|
1672
|
+
range = void 0;
|
|
1673
|
+
}
|
|
1674
|
+
} else if (isBefore2(date, from)) {
|
|
1675
|
+
range = { from: date, to: from };
|
|
1676
|
+
} else {
|
|
1677
|
+
range = { from, to: date };
|
|
1678
|
+
}
|
|
1679
|
+
} else if (from && to) {
|
|
1680
|
+
if (isSameDay2(from, date) && isSameDay2(to, date)) {
|
|
1681
|
+
if (required) {
|
|
1682
|
+
range = { from, to };
|
|
1683
|
+
} else {
|
|
1684
|
+
range = void 0;
|
|
1685
|
+
}
|
|
1686
|
+
} else if (isSameDay2(from, date)) {
|
|
1687
|
+
range = { from, to: min2 > 0 ? void 0 : date };
|
|
1688
|
+
} else if (isSameDay2(to, date)) {
|
|
1689
|
+
range = { from: date, to: min2 > 0 ? void 0 : date };
|
|
1690
|
+
} else if (isBefore2(date, from)) {
|
|
1691
|
+
range = { from: date, to };
|
|
1692
|
+
} else if (isAfter2(date, from)) {
|
|
1693
|
+
range = { from, to: date };
|
|
1694
|
+
} else if (isAfter2(date, to)) {
|
|
1695
|
+
range = { from, to: date };
|
|
1696
|
+
} else {
|
|
1697
|
+
throw new Error("Invalid range");
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
if (range?.from && range?.to) {
|
|
1701
|
+
const diff = dateLib.differenceInCalendarDays(range.to, range.from);
|
|
1702
|
+
if (max2 > 0 && diff > max2) {
|
|
1703
|
+
range = { from: date, to: void 0 };
|
|
1704
|
+
} else if (min2 > 1 && diff < min2) {
|
|
1705
|
+
range = { from: date, to: void 0 };
|
|
1706
|
+
}
|
|
1707
|
+
}
|
|
1708
|
+
return range;
|
|
1709
|
+
}
|
|
1710
|
+
function rangeContainsDayOfWeek(range, dayOfWeek, dateLib = defaultDateLib) {
|
|
1711
|
+
const dayOfWeekArr = !Array.isArray(dayOfWeek) ? [dayOfWeek] : dayOfWeek;
|
|
1712
|
+
let date = range.from;
|
|
1713
|
+
const totalDays = dateLib.differenceInCalendarDays(range.to, range.from);
|
|
1714
|
+
const totalDaysLimit = Math.min(totalDays, 6);
|
|
1715
|
+
for (let i = 0; i <= totalDaysLimit; i++) {
|
|
1716
|
+
if (dayOfWeekArr.includes(date.getDay())) {
|
|
1717
|
+
return true;
|
|
1718
|
+
}
|
|
1719
|
+
date = dateLib.addDays(date, 1);
|
|
1720
|
+
}
|
|
1721
|
+
return false;
|
|
1722
|
+
}
|
|
1723
|
+
function rangeOverlaps(rangeLeft, rangeRight, dateLib = defaultDateLib) {
|
|
1724
|
+
return rangeIncludesDate(rangeLeft, rangeRight.from, false, dateLib) || rangeIncludesDate(rangeLeft, rangeRight.to, false, dateLib) || rangeIncludesDate(rangeRight, rangeLeft.from, false, dateLib) || rangeIncludesDate(rangeRight, rangeLeft.to, false, dateLib);
|
|
1725
|
+
}
|
|
1726
|
+
function rangeContainsModifiers(range, modifiers, dateLib = defaultDateLib) {
|
|
1727
|
+
const matchers = Array.isArray(modifiers) ? modifiers : [modifiers];
|
|
1728
|
+
const nonFunctionMatchers = matchers.filter((matcher) => typeof matcher !== "function");
|
|
1729
|
+
const nonFunctionMatchersResult = nonFunctionMatchers.some((matcher) => {
|
|
1730
|
+
if (typeof matcher === "boolean")
|
|
1731
|
+
return matcher;
|
|
1732
|
+
if (dateLib.isDate(matcher)) {
|
|
1733
|
+
return rangeIncludesDate(range, matcher, false, dateLib);
|
|
1734
|
+
}
|
|
1735
|
+
if (isDatesArray(matcher, dateLib)) {
|
|
1736
|
+
return matcher.some((date) => rangeIncludesDate(range, date, false, dateLib));
|
|
1737
|
+
}
|
|
1738
|
+
if (isDateRange(matcher)) {
|
|
1739
|
+
if (matcher.from && matcher.to) {
|
|
1740
|
+
return rangeOverlaps(range, { from: matcher.from, to: matcher.to }, dateLib);
|
|
1741
|
+
}
|
|
1742
|
+
return false;
|
|
1743
|
+
}
|
|
1744
|
+
if (isDayOfWeekType(matcher)) {
|
|
1745
|
+
return rangeContainsDayOfWeek(range, matcher.dayOfWeek, dateLib);
|
|
1746
|
+
}
|
|
1747
|
+
if (isDateInterval(matcher)) {
|
|
1748
|
+
const isClosedInterval = dateLib.isAfter(matcher.before, matcher.after);
|
|
1749
|
+
if (isClosedInterval) {
|
|
1750
|
+
return rangeOverlaps(range, {
|
|
1751
|
+
from: dateLib.addDays(matcher.after, 1),
|
|
1752
|
+
to: dateLib.addDays(matcher.before, -1)
|
|
1753
|
+
}, dateLib);
|
|
1754
|
+
}
|
|
1755
|
+
return dateMatchModifiers(range.from, matcher, dateLib) || dateMatchModifiers(range.to, matcher, dateLib);
|
|
1756
|
+
}
|
|
1757
|
+
if (isDateAfterType(matcher) || isDateBeforeType(matcher)) {
|
|
1758
|
+
return dateMatchModifiers(range.from, matcher, dateLib) || dateMatchModifiers(range.to, matcher, dateLib);
|
|
1759
|
+
}
|
|
1760
|
+
return false;
|
|
1761
|
+
});
|
|
1762
|
+
if (nonFunctionMatchersResult) {
|
|
1763
|
+
return true;
|
|
1764
|
+
}
|
|
1765
|
+
const functionMatchers = matchers.filter((matcher) => typeof matcher === "function");
|
|
1766
|
+
if (functionMatchers.length) {
|
|
1767
|
+
let date = range.from;
|
|
1768
|
+
const totalDays = dateLib.differenceInCalendarDays(range.to, range.from);
|
|
1769
|
+
for (let i = 0; i <= totalDays; i++) {
|
|
1770
|
+
if (functionMatchers.some((matcher) => matcher(date))) {
|
|
1771
|
+
return true;
|
|
1772
|
+
}
|
|
1773
|
+
date = dateLib.addDays(date, 1);
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
return false;
|
|
1777
|
+
}
|
|
1778
|
+
function useRange(props, dateLib) {
|
|
1779
|
+
const { disabled, excludeDisabled, selected: initiallySelected, required, onSelect } = props;
|
|
1780
|
+
const [internallySelected, setSelected] = useControlledValue(initiallySelected, onSelect ? initiallySelected : void 0);
|
|
1781
|
+
const selected = !onSelect ? internallySelected : initiallySelected;
|
|
1782
|
+
const isSelected = (date) => selected && rangeIncludesDate(selected, date, false, dateLib);
|
|
1783
|
+
const select = (triggerDate, modifiers, e) => {
|
|
1784
|
+
const { min: min2, max: max2 } = props;
|
|
1785
|
+
const newRange = triggerDate ? addToRange(triggerDate, selected, min2, max2, required, dateLib) : void 0;
|
|
1786
|
+
if (excludeDisabled && disabled && newRange?.from && newRange.to) {
|
|
1787
|
+
if (rangeContainsModifiers({ from: newRange.from, to: newRange.to }, disabled, dateLib)) {
|
|
1788
|
+
newRange.from = triggerDate;
|
|
1789
|
+
newRange.to = void 0;
|
|
1790
|
+
}
|
|
1791
|
+
}
|
|
1792
|
+
if (!onSelect) {
|
|
1793
|
+
setSelected(newRange);
|
|
1794
|
+
}
|
|
1795
|
+
onSelect?.(newRange, triggerDate, modifiers, e);
|
|
1796
|
+
return newRange;
|
|
1797
|
+
};
|
|
1798
|
+
return {
|
|
1799
|
+
selected,
|
|
1800
|
+
select,
|
|
1801
|
+
isSelected
|
|
1802
|
+
};
|
|
1803
|
+
}
|
|
1804
|
+
function useSingle(props, dateLib) {
|
|
1805
|
+
const { selected: initiallySelected, required, onSelect } = props;
|
|
1806
|
+
const [internallySelected, setSelected] = useControlledValue(initiallySelected, onSelect ? initiallySelected : void 0);
|
|
1807
|
+
const selected = !onSelect ? internallySelected : initiallySelected;
|
|
1808
|
+
const { isSameDay: isSameDay2 } = dateLib;
|
|
1809
|
+
const isSelected = (compareDate) => {
|
|
1810
|
+
return selected ? isSameDay2(selected, compareDate) : false;
|
|
1811
|
+
};
|
|
1812
|
+
const select = (triggerDate, modifiers, e) => {
|
|
1813
|
+
let newDate = triggerDate;
|
|
1814
|
+
if (!required && selected && selected && isSameDay2(triggerDate, selected)) {
|
|
1815
|
+
newDate = void 0;
|
|
1816
|
+
}
|
|
1817
|
+
if (!onSelect) {
|
|
1818
|
+
setSelected(newDate);
|
|
1819
|
+
}
|
|
1820
|
+
if (required) {
|
|
1821
|
+
onSelect?.(newDate, triggerDate, modifiers, e);
|
|
1822
|
+
} else {
|
|
1823
|
+
onSelect?.(newDate, triggerDate, modifiers, e);
|
|
1824
|
+
}
|
|
1825
|
+
return newDate;
|
|
1826
|
+
};
|
|
1827
|
+
return {
|
|
1828
|
+
selected,
|
|
1829
|
+
select,
|
|
1830
|
+
isSelected
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
function useSelection(props, dateLib) {
|
|
1834
|
+
const single = useSingle(props, dateLib);
|
|
1835
|
+
const multi = useMulti(props, dateLib);
|
|
1836
|
+
const range = useRange(props, dateLib);
|
|
1837
|
+
switch (props.mode) {
|
|
1838
|
+
case "single":
|
|
1839
|
+
return single;
|
|
1840
|
+
case "multiple":
|
|
1841
|
+
return multi;
|
|
1842
|
+
case "range":
|
|
1843
|
+
return range;
|
|
1844
|
+
default:
|
|
1845
|
+
return void 0;
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
function toTimeZone(date, timeZone) {
|
|
1849
|
+
if (date instanceof TZDate && date.timeZone === timeZone) {
|
|
1850
|
+
return date;
|
|
1851
|
+
}
|
|
1852
|
+
return new TZDate(date, timeZone);
|
|
1853
|
+
}
|
|
1854
|
+
function toZoneNoon(date, timeZone, noonSafe) {
|
|
1855
|
+
return toTimeZone(date, timeZone);
|
|
1856
|
+
}
|
|
1857
|
+
function convertMatcher(matcher, timeZone, noonSafe) {
|
|
1858
|
+
if (typeof matcher === "boolean" || typeof matcher === "function") {
|
|
1859
|
+
return matcher;
|
|
1860
|
+
}
|
|
1861
|
+
if (matcher instanceof Date) {
|
|
1862
|
+
return toZoneNoon(matcher, timeZone);
|
|
1863
|
+
}
|
|
1864
|
+
if (Array.isArray(matcher)) {
|
|
1865
|
+
return matcher.map((value) => value instanceof Date ? toZoneNoon(value, timeZone) : value);
|
|
1866
|
+
}
|
|
1867
|
+
if (isDateRange(matcher)) {
|
|
1868
|
+
return {
|
|
1869
|
+
...matcher,
|
|
1870
|
+
from: matcher.from ? toTimeZone(matcher.from, timeZone) : matcher.from,
|
|
1871
|
+
to: matcher.to ? toTimeZone(matcher.to, timeZone) : matcher.to
|
|
1872
|
+
};
|
|
1873
|
+
}
|
|
1874
|
+
if (isDateInterval(matcher)) {
|
|
1875
|
+
return {
|
|
1876
|
+
before: toZoneNoon(matcher.before, timeZone),
|
|
1877
|
+
after: toZoneNoon(matcher.after, timeZone)
|
|
1878
|
+
};
|
|
1879
|
+
}
|
|
1880
|
+
if (isDateAfterType(matcher)) {
|
|
1881
|
+
return {
|
|
1882
|
+
after: toZoneNoon(matcher.after, timeZone)
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1885
|
+
if (isDateBeforeType(matcher)) {
|
|
1886
|
+
return {
|
|
1887
|
+
before: toZoneNoon(matcher.before, timeZone)
|
|
1888
|
+
};
|
|
1889
|
+
}
|
|
1890
|
+
return matcher;
|
|
1891
|
+
}
|
|
1892
|
+
function convertMatchersToTimeZone(matchers, timeZone, noonSafe) {
|
|
1893
|
+
if (!matchers) {
|
|
1894
|
+
return matchers;
|
|
1895
|
+
}
|
|
1896
|
+
if (Array.isArray(matchers)) {
|
|
1897
|
+
return matchers.map((matcher) => convertMatcher(matcher, timeZone));
|
|
1898
|
+
}
|
|
1899
|
+
return convertMatcher(matchers, timeZone);
|
|
1900
|
+
}
|
|
1901
|
+
function DayPicker(initialProps) {
|
|
1902
|
+
let props = initialProps;
|
|
1903
|
+
const timeZone = props.timeZone;
|
|
1904
|
+
if (timeZone) {
|
|
1905
|
+
props = {
|
|
1906
|
+
...initialProps,
|
|
1907
|
+
timeZone
|
|
1908
|
+
};
|
|
1909
|
+
if (props.today) {
|
|
1910
|
+
props.today = toTimeZone(props.today, timeZone);
|
|
1911
|
+
}
|
|
1912
|
+
if (props.month) {
|
|
1913
|
+
props.month = toTimeZone(props.month, timeZone);
|
|
1914
|
+
}
|
|
1915
|
+
if (props.defaultMonth) {
|
|
1916
|
+
props.defaultMonth = toTimeZone(props.defaultMonth, timeZone);
|
|
1917
|
+
}
|
|
1918
|
+
if (props.startMonth) {
|
|
1919
|
+
props.startMonth = toTimeZone(props.startMonth, timeZone);
|
|
1920
|
+
}
|
|
1921
|
+
if (props.endMonth) {
|
|
1922
|
+
props.endMonth = toTimeZone(props.endMonth, timeZone);
|
|
1923
|
+
}
|
|
1924
|
+
if (props.mode === "single" && props.selected) {
|
|
1925
|
+
props.selected = toTimeZone(props.selected, timeZone);
|
|
1926
|
+
} else if (props.mode === "multiple" && props.selected) {
|
|
1927
|
+
props.selected = props.selected?.map((date) => toTimeZone(date, timeZone));
|
|
1928
|
+
} else if (props.mode === "range" && props.selected) {
|
|
1929
|
+
props.selected = {
|
|
1930
|
+
from: props.selected.from ? toTimeZone(props.selected.from, timeZone) : props.selected.from,
|
|
1931
|
+
to: props.selected.to ? toTimeZone(props.selected.to, timeZone) : props.selected.to
|
|
1932
|
+
};
|
|
1933
|
+
}
|
|
1934
|
+
if (props.disabled !== void 0) {
|
|
1935
|
+
props.disabled = convertMatchersToTimeZone(props.disabled, timeZone);
|
|
1936
|
+
}
|
|
1937
|
+
if (props.hidden !== void 0) {
|
|
1938
|
+
props.hidden = convertMatchersToTimeZone(props.hidden, timeZone);
|
|
1939
|
+
}
|
|
1940
|
+
if (props.modifiers) {
|
|
1941
|
+
const nextModifiers = {};
|
|
1942
|
+
Object.keys(props.modifiers).forEach((key) => {
|
|
1943
|
+
nextModifiers[key] = convertMatchersToTimeZone(props.modifiers?.[key], timeZone);
|
|
1944
|
+
});
|
|
1945
|
+
props.modifiers = nextModifiers;
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
const { components: components2, formatters, labels, dateLib, locale, classNames } = reactExports.useMemo(() => {
|
|
1949
|
+
const locale2 = { ...enUS, ...props.locale };
|
|
1950
|
+
const weekStartsOn = props.broadcastCalendar ? 1 : props.weekStartsOn;
|
|
1951
|
+
const noonOverrides = props.noonSafe && props.timeZone ? createNoonOverrides(props.timeZone, {
|
|
1952
|
+
weekStartsOn,
|
|
1953
|
+
locale: locale2
|
|
1954
|
+
}) : void 0;
|
|
1955
|
+
const overrides = props.dateLib && noonOverrides ? { ...noonOverrides, ...props.dateLib } : props.dateLib ?? noonOverrides;
|
|
1956
|
+
const dateLib2 = new DateLib({
|
|
1957
|
+
locale: locale2,
|
|
1958
|
+
weekStartsOn,
|
|
1959
|
+
firstWeekContainsDate: props.firstWeekContainsDate,
|
|
1960
|
+
useAdditionalWeekYearTokens: props.useAdditionalWeekYearTokens,
|
|
1961
|
+
useAdditionalDayOfYearTokens: props.useAdditionalDayOfYearTokens,
|
|
1962
|
+
timeZone: props.timeZone,
|
|
1963
|
+
numerals: props.numerals
|
|
1964
|
+
}, overrides);
|
|
1965
|
+
return {
|
|
1966
|
+
dateLib: dateLib2,
|
|
1967
|
+
components: getComponents(props.components),
|
|
1968
|
+
formatters: getFormatters(props.formatters),
|
|
1969
|
+
labels: getLabels(props.labels, dateLib2.options),
|
|
1970
|
+
locale: locale2,
|
|
1971
|
+
classNames: { ...getDefaultClassNames(), ...props.classNames }
|
|
1972
|
+
};
|
|
1973
|
+
}, [
|
|
1974
|
+
props.locale,
|
|
1975
|
+
props.broadcastCalendar,
|
|
1976
|
+
props.weekStartsOn,
|
|
1977
|
+
props.firstWeekContainsDate,
|
|
1978
|
+
props.useAdditionalWeekYearTokens,
|
|
1979
|
+
props.useAdditionalDayOfYearTokens,
|
|
1980
|
+
props.timeZone,
|
|
1981
|
+
props.numerals,
|
|
1982
|
+
props.dateLib,
|
|
1983
|
+
props.noonSafe,
|
|
1984
|
+
props.components,
|
|
1985
|
+
props.formatters,
|
|
1986
|
+
props.labels,
|
|
1987
|
+
props.classNames
|
|
1988
|
+
]);
|
|
1989
|
+
if (!props.today) {
|
|
1990
|
+
props = { ...props, today: dateLib.today() };
|
|
1991
|
+
}
|
|
1992
|
+
const { captionLayout, mode, navLayout, numberOfMonths = 1, onDayBlur, onDayClick, onDayFocus, onDayKeyDown, onDayMouseEnter, onDayMouseLeave, onNextClick, onPrevClick, showWeekNumber, styles } = props;
|
|
1993
|
+
const { formatCaption: formatCaption2, formatDay: formatDay2, formatMonthDropdown: formatMonthDropdown2, formatWeekNumber: formatWeekNumber2, formatWeekNumberHeader: formatWeekNumberHeader2, formatWeekdayName: formatWeekdayName2, formatYearDropdown: formatYearDropdown2 } = formatters;
|
|
1994
|
+
const calendar = useCalendar(props, dateLib);
|
|
1995
|
+
const { days, months, navStart, navEnd, previousMonth, nextMonth, goToMonth } = calendar;
|
|
1996
|
+
const getModifiers = createGetModifiers(days, props, navStart, navEnd, dateLib);
|
|
1997
|
+
const { isSelected, select, selected: selectedValue } = useSelection(props, dateLib) ?? {};
|
|
1998
|
+
const { blur, focused, isFocusTarget, moveFocus, setFocused } = useFocus(props, calendar, getModifiers, isSelected ?? (() => false), dateLib);
|
|
1999
|
+
const { labelDayButton: labelDayButton2, labelGridcell: labelGridcell2, labelGrid: labelGrid2, labelMonthDropdown: labelMonthDropdown2, labelNav: labelNav2, labelPrevious: labelPrevious2, labelNext: labelNext2, labelWeekday: labelWeekday2, labelWeekNumber: labelWeekNumber2, labelWeekNumberHeader: labelWeekNumberHeader2, labelYearDropdown: labelYearDropdown2 } = labels;
|
|
2000
|
+
const weekdays = reactExports.useMemo(() => getWeekdays(dateLib, props.ISOWeek, props.broadcastCalendar, props.today), [dateLib, props.ISOWeek, props.broadcastCalendar, props.today]);
|
|
2001
|
+
const isInteractive = mode !== void 0 || onDayClick !== void 0;
|
|
2002
|
+
const handlePreviousClick = reactExports.useCallback(() => {
|
|
2003
|
+
if (!previousMonth)
|
|
2004
|
+
return;
|
|
2005
|
+
goToMonth(previousMonth);
|
|
2006
|
+
onPrevClick?.(previousMonth);
|
|
2007
|
+
}, [previousMonth, goToMonth, onPrevClick]);
|
|
2008
|
+
const handleNextClick = reactExports.useCallback(() => {
|
|
2009
|
+
if (!nextMonth)
|
|
2010
|
+
return;
|
|
2011
|
+
goToMonth(nextMonth);
|
|
2012
|
+
onNextClick?.(nextMonth);
|
|
2013
|
+
}, [goToMonth, nextMonth, onNextClick]);
|
|
2014
|
+
const handleDayClick = reactExports.useCallback((day, m) => (e) => {
|
|
2015
|
+
e.preventDefault();
|
|
2016
|
+
e.stopPropagation();
|
|
2017
|
+
setFocused(day);
|
|
2018
|
+
if (m.disabled) {
|
|
2019
|
+
return;
|
|
2020
|
+
}
|
|
2021
|
+
select?.(day.date, m, e);
|
|
2022
|
+
onDayClick?.(day.date, m, e);
|
|
2023
|
+
}, [select, onDayClick, setFocused]);
|
|
2024
|
+
const handleDayFocus = reactExports.useCallback((day, m) => (e) => {
|
|
2025
|
+
setFocused(day);
|
|
2026
|
+
onDayFocus?.(day.date, m, e);
|
|
2027
|
+
}, [onDayFocus, setFocused]);
|
|
2028
|
+
const handleDayBlur = reactExports.useCallback((day, m) => (e) => {
|
|
2029
|
+
blur();
|
|
2030
|
+
onDayBlur?.(day.date, m, e);
|
|
2031
|
+
}, [blur, onDayBlur]);
|
|
2032
|
+
const handleDayKeyDown = reactExports.useCallback((day, modifiers) => (e) => {
|
|
2033
|
+
const keyMap = {
|
|
2034
|
+
ArrowLeft: [
|
|
2035
|
+
e.shiftKey ? "month" : "day",
|
|
2036
|
+
props.dir === "rtl" ? "after" : "before"
|
|
2037
|
+
],
|
|
2038
|
+
ArrowRight: [
|
|
2039
|
+
e.shiftKey ? "month" : "day",
|
|
2040
|
+
props.dir === "rtl" ? "before" : "after"
|
|
2041
|
+
],
|
|
2042
|
+
ArrowDown: [e.shiftKey ? "year" : "week", "after"],
|
|
2043
|
+
ArrowUp: [e.shiftKey ? "year" : "week", "before"],
|
|
2044
|
+
PageUp: [e.shiftKey ? "year" : "month", "before"],
|
|
2045
|
+
PageDown: [e.shiftKey ? "year" : "month", "after"],
|
|
2046
|
+
Home: ["startOfWeek", "before"],
|
|
2047
|
+
End: ["endOfWeek", "after"]
|
|
2048
|
+
};
|
|
2049
|
+
if (keyMap[e.key]) {
|
|
2050
|
+
e.preventDefault();
|
|
2051
|
+
e.stopPropagation();
|
|
2052
|
+
const [moveBy, moveDir] = keyMap[e.key];
|
|
2053
|
+
moveFocus(moveBy, moveDir);
|
|
2054
|
+
}
|
|
2055
|
+
onDayKeyDown?.(day.date, modifiers, e);
|
|
2056
|
+
}, [moveFocus, onDayKeyDown, props.dir]);
|
|
2057
|
+
const handleDayMouseEnter = reactExports.useCallback((day, modifiers) => (e) => {
|
|
2058
|
+
onDayMouseEnter?.(day.date, modifiers, e);
|
|
2059
|
+
}, [onDayMouseEnter]);
|
|
2060
|
+
const handleDayMouseLeave = reactExports.useCallback((day, modifiers) => (e) => {
|
|
2061
|
+
onDayMouseLeave?.(day.date, modifiers, e);
|
|
2062
|
+
}, [onDayMouseLeave]);
|
|
2063
|
+
const handleMonthChange = reactExports.useCallback((date) => (e) => {
|
|
2064
|
+
const selectedMonth = Number(e.target.value);
|
|
2065
|
+
const month = dateLib.setMonth(dateLib.startOfMonth(date), selectedMonth);
|
|
2066
|
+
goToMonth(month);
|
|
2067
|
+
}, [dateLib, goToMonth]);
|
|
2068
|
+
const handleYearChange = reactExports.useCallback((date) => (e) => {
|
|
2069
|
+
const selectedYear = Number(e.target.value);
|
|
2070
|
+
const month = dateLib.setYear(dateLib.startOfMonth(date), selectedYear);
|
|
2071
|
+
goToMonth(month);
|
|
2072
|
+
}, [dateLib, goToMonth]);
|
|
2073
|
+
const { className, style } = reactExports.useMemo(() => ({
|
|
2074
|
+
className: [classNames[UI.Root], props.className].filter(Boolean).join(" "),
|
|
2075
|
+
style: { ...styles?.[UI.Root], ...props.style }
|
|
2076
|
+
}), [classNames, props.className, props.style, styles]);
|
|
2077
|
+
const dataAttributes = getDataAttributes(props);
|
|
2078
|
+
const rootElRef = reactExports.useRef(null);
|
|
2079
|
+
useAnimation(rootElRef, Boolean(props.animate), {
|
|
2080
|
+
classNames,
|
|
2081
|
+
months,
|
|
2082
|
+
focused,
|
|
2083
|
+
dateLib
|
|
2084
|
+
});
|
|
2085
|
+
const contextValue = {
|
|
2086
|
+
dayPickerProps: props,
|
|
2087
|
+
selected: selectedValue,
|
|
2088
|
+
select,
|
|
2089
|
+
isSelected,
|
|
2090
|
+
months,
|
|
2091
|
+
nextMonth,
|
|
2092
|
+
previousMonth,
|
|
2093
|
+
goToMonth,
|
|
2094
|
+
getModifiers,
|
|
2095
|
+
components: components2,
|
|
2096
|
+
classNames,
|
|
2097
|
+
styles,
|
|
2098
|
+
labels,
|
|
2099
|
+
formatters
|
|
2100
|
+
};
|
|
2101
|
+
return React.createElement(
|
|
2102
|
+
dayPickerContext.Provider,
|
|
2103
|
+
{ value: contextValue },
|
|
2104
|
+
React.createElement(
|
|
2105
|
+
components2.Root,
|
|
2106
|
+
{ rootRef: props.animate ? rootElRef : void 0, className, style, dir: props.dir, id: props.id, lang: props.lang, nonce: props.nonce, title: props.title, role: props.role, "aria-label": props["aria-label"], "aria-labelledby": props["aria-labelledby"], ...dataAttributes },
|
|
2107
|
+
React.createElement(
|
|
2108
|
+
components2.Months,
|
|
2109
|
+
{ className: classNames[UI.Months], style: styles?.[UI.Months] },
|
|
2110
|
+
!props.hideNavigation && !navLayout && React.createElement(components2.Nav, { "data-animated-nav": props.animate ? "true" : void 0, className: classNames[UI.Nav], style: styles?.[UI.Nav], "aria-label": labelNav2(), onPreviousClick: handlePreviousClick, onNextClick: handleNextClick, previousMonth, nextMonth }),
|
|
2111
|
+
months.map((calendarMonth, displayIndex) => {
|
|
2112
|
+
return React.createElement(
|
|
2113
|
+
components2.Month,
|
|
2114
|
+
{
|
|
2115
|
+
"data-animated-month": props.animate ? "true" : void 0,
|
|
2116
|
+
className: classNames[UI.Month],
|
|
2117
|
+
style: styles?.[UI.Month],
|
|
2118
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: breaks animation
|
|
2119
|
+
key: displayIndex,
|
|
2120
|
+
displayIndex,
|
|
2121
|
+
calendarMonth
|
|
2122
|
+
},
|
|
2123
|
+
navLayout === "around" && !props.hideNavigation && displayIndex === 0 && React.createElement(
|
|
2124
|
+
components2.PreviousMonthButton,
|
|
2125
|
+
{ type: "button", className: classNames[UI.PreviousMonthButton], tabIndex: previousMonth ? void 0 : -1, "aria-disabled": previousMonth ? void 0 : true, "aria-label": labelPrevious2(previousMonth), onClick: handlePreviousClick, "data-animated-button": props.animate ? "true" : void 0 },
|
|
2126
|
+
React.createElement(components2.Chevron, { disabled: previousMonth ? void 0 : true, className: classNames[UI.Chevron], orientation: props.dir === "rtl" ? "right" : "left" })
|
|
2127
|
+
),
|
|
2128
|
+
React.createElement(components2.MonthCaption, { "data-animated-caption": props.animate ? "true" : void 0, className: classNames[UI.MonthCaption], style: styles?.[UI.MonthCaption], calendarMonth, displayIndex }, captionLayout?.startsWith("dropdown") ? React.createElement(
|
|
2129
|
+
components2.DropdownNav,
|
|
2130
|
+
{ className: classNames[UI.Dropdowns], style: styles?.[UI.Dropdowns] },
|
|
2131
|
+
(() => {
|
|
2132
|
+
const monthControl = captionLayout === "dropdown" || captionLayout === "dropdown-months" ? React.createElement(components2.MonthsDropdown, { key: "month", className: classNames[UI.MonthsDropdown], "aria-label": labelMonthDropdown2(), classNames, components: components2, disabled: Boolean(props.disableNavigation), onChange: handleMonthChange(calendarMonth.date), options: getMonthOptions(calendarMonth.date, navStart, navEnd, formatters, dateLib), style: styles?.[UI.Dropdown], value: dateLib.getMonth(calendarMonth.date) }) : React.createElement("span", { key: "month" }, formatMonthDropdown2(calendarMonth.date, dateLib));
|
|
2133
|
+
const yearControl = captionLayout === "dropdown" || captionLayout === "dropdown-years" ? React.createElement(components2.YearsDropdown, { key: "year", className: classNames[UI.YearsDropdown], "aria-label": labelYearDropdown2(dateLib.options), classNames, components: components2, disabled: Boolean(props.disableNavigation), onChange: handleYearChange(calendarMonth.date), options: getYearOptions(navStart, navEnd, formatters, dateLib, Boolean(props.reverseYears)), style: styles?.[UI.Dropdown], value: dateLib.getYear(calendarMonth.date) }) : React.createElement("span", { key: "year" }, formatYearDropdown2(calendarMonth.date, dateLib));
|
|
2134
|
+
const controls = dateLib.getMonthYearOrder() === "year-first" ? [yearControl, monthControl] : [monthControl, yearControl];
|
|
2135
|
+
return controls;
|
|
2136
|
+
})(),
|
|
2137
|
+
React.createElement("span", { role: "status", "aria-live": "polite", style: {
|
|
2138
|
+
border: 0,
|
|
2139
|
+
clip: "rect(0 0 0 0)",
|
|
2140
|
+
height: "1px",
|
|
2141
|
+
margin: "-1px",
|
|
2142
|
+
overflow: "hidden",
|
|
2143
|
+
padding: 0,
|
|
2144
|
+
position: "absolute",
|
|
2145
|
+
width: "1px",
|
|
2146
|
+
whiteSpace: "nowrap",
|
|
2147
|
+
wordWrap: "normal"
|
|
2148
|
+
} }, formatCaption2(calendarMonth.date, dateLib.options, dateLib))
|
|
2149
|
+
) : React.createElement(components2.CaptionLabel, { className: classNames[UI.CaptionLabel], role: "status", "aria-live": "polite" }, formatCaption2(calendarMonth.date, dateLib.options, dateLib))),
|
|
2150
|
+
navLayout === "around" && !props.hideNavigation && displayIndex === numberOfMonths - 1 && React.createElement(
|
|
2151
|
+
components2.NextMonthButton,
|
|
2152
|
+
{ type: "button", className: classNames[UI.NextMonthButton], tabIndex: nextMonth ? void 0 : -1, "aria-disabled": nextMonth ? void 0 : true, "aria-label": labelNext2(nextMonth), onClick: handleNextClick, "data-animated-button": props.animate ? "true" : void 0 },
|
|
2153
|
+
React.createElement(components2.Chevron, { disabled: nextMonth ? void 0 : true, className: classNames[UI.Chevron], orientation: props.dir === "rtl" ? "left" : "right" })
|
|
2154
|
+
),
|
|
2155
|
+
displayIndex === numberOfMonths - 1 && navLayout === "after" && !props.hideNavigation && React.createElement(components2.Nav, { "data-animated-nav": props.animate ? "true" : void 0, className: classNames[UI.Nav], style: styles?.[UI.Nav], "aria-label": labelNav2(), onPreviousClick: handlePreviousClick, onNextClick: handleNextClick, previousMonth, nextMonth }),
|
|
2156
|
+
React.createElement(
|
|
2157
|
+
components2.MonthGrid,
|
|
2158
|
+
{ role: "grid", "aria-multiselectable": mode === "multiple" || mode === "range", "aria-label": labelGrid2(calendarMonth.date, dateLib.options, dateLib) || void 0, className: classNames[UI.MonthGrid], style: styles?.[UI.MonthGrid] },
|
|
2159
|
+
!props.hideWeekdays && React.createElement(
|
|
2160
|
+
components2.Weekdays,
|
|
2161
|
+
{ "data-animated-weekdays": props.animate ? "true" : void 0, className: classNames[UI.Weekdays], style: styles?.[UI.Weekdays] },
|
|
2162
|
+
showWeekNumber && React.createElement(components2.WeekNumberHeader, { "aria-label": labelWeekNumberHeader2(dateLib.options), className: classNames[UI.WeekNumberHeader], style: styles?.[UI.WeekNumberHeader], scope: "col" }, formatWeekNumberHeader2()),
|
|
2163
|
+
weekdays.map((weekday) => React.createElement(components2.Weekday, { "aria-label": labelWeekday2(weekday, dateLib.options, dateLib), className: classNames[UI.Weekday], key: String(weekday), style: styles?.[UI.Weekday], scope: "col" }, formatWeekdayName2(weekday, dateLib.options, dateLib)))
|
|
2164
|
+
),
|
|
2165
|
+
React.createElement(components2.Weeks, { "data-animated-weeks": props.animate ? "true" : void 0, className: classNames[UI.Weeks], style: styles?.[UI.Weeks] }, calendarMonth.weeks.map((week) => {
|
|
2166
|
+
return React.createElement(
|
|
2167
|
+
components2.Week,
|
|
2168
|
+
{ className: classNames[UI.Week], key: week.weekNumber, style: styles?.[UI.Week], week },
|
|
2169
|
+
showWeekNumber && React.createElement(components2.WeekNumber, { week, style: styles?.[UI.WeekNumber], "aria-label": labelWeekNumber2(week.weekNumber, {
|
|
2170
|
+
locale
|
|
2171
|
+
}), className: classNames[UI.WeekNumber], scope: "row", role: "rowheader" }, formatWeekNumber2(week.weekNumber, dateLib)),
|
|
2172
|
+
week.days.map((day) => {
|
|
2173
|
+
const { date } = day;
|
|
2174
|
+
const modifiers = getModifiers(day);
|
|
2175
|
+
modifiers[DayFlag.focused] = !modifiers.hidden && Boolean(focused?.isEqualTo(day));
|
|
2176
|
+
modifiers[SelectionState.selected] = isSelected?.(date) || modifiers.selected;
|
|
2177
|
+
if (isDateRange(selectedValue)) {
|
|
2178
|
+
const { from, to } = selectedValue;
|
|
2179
|
+
modifiers[SelectionState.range_start] = Boolean(from && to && dateLib.isSameDay(date, from));
|
|
2180
|
+
modifiers[SelectionState.range_end] = Boolean(from && to && dateLib.isSameDay(date, to));
|
|
2181
|
+
modifiers[SelectionState.range_middle] = rangeIncludesDate(selectedValue, date, true, dateLib);
|
|
2182
|
+
}
|
|
2183
|
+
const style2 = getStyleForModifiers(modifiers, styles, props.modifiersStyles);
|
|
2184
|
+
const className2 = getClassNamesForModifiers(modifiers, classNames, props.modifiersClassNames);
|
|
2185
|
+
const ariaLabel = !isInteractive && !modifiers.hidden ? labelGridcell2(date, modifiers, dateLib.options, dateLib) : void 0;
|
|
2186
|
+
return React.createElement(components2.Day, { key: `${day.isoDate}_${day.displayMonthId}`, day, modifiers, className: className2.join(" "), style: style2, role: "gridcell", "aria-selected": modifiers.selected || void 0, "aria-label": ariaLabel, "data-day": day.isoDate, "data-month": day.outside ? day.dateMonthId : void 0, "data-selected": modifiers.selected || void 0, "data-disabled": modifiers.disabled || void 0, "data-hidden": modifiers.hidden || void 0, "data-outside": day.outside || void 0, "data-focused": modifiers.focused || void 0, "data-today": modifiers.today || void 0 }, !modifiers.hidden && isInteractive ? React.createElement(components2.DayButton, { className: classNames[UI.DayButton], style: styles?.[UI.DayButton], type: "button", day, modifiers, disabled: !modifiers.focused && modifiers.disabled || void 0, "aria-disabled": modifiers.focused && modifiers.disabled || void 0, tabIndex: isFocusTarget(day) ? 0 : -1, "aria-label": labelDayButton2(date, modifiers, dateLib.options, dateLib), onClick: handleDayClick(day, modifiers), onBlur: handleDayBlur(day, modifiers), onFocus: handleDayFocus(day, modifiers), onKeyDown: handleDayKeyDown(day, modifiers), onMouseEnter: handleDayMouseEnter(day, modifiers), onMouseLeave: handleDayMouseLeave(day, modifiers) }, formatDay2(date, dateLib.options, dateLib)) : !modifiers.hidden && formatDay2(day.date, dateLib.options, dateLib));
|
|
2187
|
+
})
|
|
2188
|
+
);
|
|
2189
|
+
}))
|
|
2190
|
+
)
|
|
2191
|
+
);
|
|
2192
|
+
})
|
|
2193
|
+
),
|
|
2194
|
+
props.footer && React.createElement(components2.Footer, { className: classNames[UI.Footer], style: styles?.[UI.Footer], role: "status", "aria-live": "polite" }, props.footer)
|
|
2195
|
+
)
|
|
2196
|
+
);
|
|
2197
|
+
}
|
|
2198
|
+
export {
|
|
2199
|
+
DayPicker as D,
|
|
2200
|
+
getDefaultClassNames as g
|
|
2201
|
+
};
|