universal-datetime-picker 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs ADDED
@@ -0,0 +1,2030 @@
1
+ import { useId, useRef, useEffect, useSyncExternalStore, useCallback, useMemo, useState, useLayoutEffect } from 'react';
2
+ import { createPortal } from 'react-dom';
3
+ import dayjs from 'dayjs';
4
+ export { default as dayjs } from 'dayjs';
5
+ import customParseFormat from 'dayjs/plugin/customParseFormat';
6
+ import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
7
+ import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
8
+ import localeData from 'dayjs/plugin/localeData';
9
+ import weekday from 'dayjs/plugin/weekday';
10
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
11
+
12
+ dayjs.extend(customParseFormat);
13
+ dayjs.extend(isSameOrAfter);
14
+ dayjs.extend(isSameOrBefore);
15
+ dayjs.extend(localeData);
16
+ dayjs.extend(weekday);
17
+ var DEFAULT_FORMAT = "YYYY-MM-DD HH:mm:ss";
18
+ var DATE_FORMAT = "YYYY-MM-DD";
19
+ var TIME_FORMAT = "HH:mm:ss";
20
+ function resolveFormat(options) {
21
+ if (options.format) {
22
+ return options.format;
23
+ }
24
+ const mode = options.mode ?? "datetime";
25
+ const showSeconds = options.showSeconds !== false;
26
+ const use12Hours = Boolean(options.use12Hours);
27
+ const timePart = use12Hours ? showSeconds ? "hh:mm:ss A" : "hh:mm A" : showSeconds ? "HH:mm:ss" : "HH:mm";
28
+ if (mode === "date") {
29
+ return DATE_FORMAT;
30
+ }
31
+ if (mode === "time") {
32
+ return timePart;
33
+ }
34
+ return `${DATE_FORMAT} ${timePart}`;
35
+ }
36
+ function buildTimeValue(value, format) {
37
+ const hour24 = value.hour();
38
+ const { hour, isAm } = to12Hour(hour24);
39
+ return {
40
+ hour,
41
+ hour24,
42
+ minute: value.minute(),
43
+ second: value.second(),
44
+ ampm: isAm ? "AM" : "PM",
45
+ formatted: value.format(format)
46
+ };
47
+ }
48
+ var asStringDeprecationWarned = false;
49
+ function warnAsStringDeprecation() {
50
+ if (asStringDeprecationWarned) {
51
+ return;
52
+ }
53
+ if (typeof process !== "undefined" && process.env.NODE_ENV === "production") {
54
+ return;
55
+ }
56
+ asStringDeprecationWarned = true;
57
+ console.warn(
58
+ "[universal-datetime-picker] Omitting `asString` currently returns a formatted string. Set `asString={true}` to keep strings, or `asString={false}` to receive a Date / TimeValue. A future major release will default to Date / TimeValue."
59
+ );
60
+ }
61
+ function parseValue(value, format = DEFAULT_FORMAT) {
62
+ if (value === void 0 || value === null || value === "") {
63
+ return null;
64
+ }
65
+ if (dayjs.isDayjs(value)) {
66
+ return value.isValid() ? value : null;
67
+ }
68
+ if (value instanceof Date) {
69
+ const parsed2 = dayjs(value);
70
+ return parsed2.isValid() ? parsed2 : null;
71
+ }
72
+ if (typeof value === "string") {
73
+ const parsed2 = dayjs(value, format, true);
74
+ if (parsed2.isValid()) {
75
+ return parsed2;
76
+ }
77
+ const fallback = dayjs(value);
78
+ return fallback.isValid() ? fallback : null;
79
+ }
80
+ const parsed = dayjs(value);
81
+ return parsed.isValid() ? parsed : null;
82
+ }
83
+ function formatValue(value, format = DEFAULT_FORMAT) {
84
+ if (!value || !value.isValid()) {
85
+ return null;
86
+ }
87
+ return value.format(format);
88
+ }
89
+ function pad2(n) {
90
+ return String(n).padStart(2, "0");
91
+ }
92
+ var HOURS_24 = Array.from({ length: 24 }, (_, i) => pad2(i));
93
+ var HOURS_12 = Array.from(
94
+ { length: 12 },
95
+ (_, i) => pad2(i === 0 ? 12 : i)
96
+ );
97
+ var MINUTES = Array.from({ length: 60 }, (_, i) => pad2(i));
98
+ function to12Hour(hour24) {
99
+ const isAm = hour24 < 12;
100
+ const hour = hour24 % 12 === 0 ? 12 : hour24 % 12;
101
+ return { hour, isAm };
102
+ }
103
+ function to24Hour(hour12, isAm) {
104
+ if (hour12 === 12) {
105
+ return isAm ? 0 : 12;
106
+ }
107
+ return isAm ? hour12 : hour12 + 12;
108
+ }
109
+ function formatLocalized(date, template, locale) {
110
+ return date.locale(locale).format(template);
111
+ }
112
+ function getWeekdayLabels(locale, weekStartsOn) {
113
+ const labels = dayjs().locale(locale).localeData().weekdaysMin();
114
+ return [...labels.slice(weekStartsOn), ...labels.slice(0, weekStartsOn)];
115
+ }
116
+ function startOfWeek(date, weekStartsOn) {
117
+ const day = date.day();
118
+ const diff = (day - weekStartsOn + 7) % 7;
119
+ return date.subtract(diff, "day").startOf("day");
120
+ }
121
+ function endOfWeek(date, weekStartsOn) {
122
+ return startOfWeek(date, weekStartsOn).add(6, "day").endOf("day");
123
+ }
124
+ function cx(...parts) {
125
+ return parts.filter(Boolean).join(" ");
126
+ }
127
+ function yearWindowStart(year) {
128
+ return Math.floor(year / 12) * 12;
129
+ }
130
+ function CalendarHeader(props) {
131
+ const {
132
+ viewMonth,
133
+ setViewMonth,
134
+ panel,
135
+ onPanelChange,
136
+ locale,
137
+ labels,
138
+ titleId
139
+ } = props;
140
+ const year = viewMonth.year();
141
+ const windowStart = yearWindowStart(year);
142
+ const windowEnd = windowStart + 11;
143
+ const now = dayjs();
144
+ const onPrev = () => {
145
+ if (panel === "day") {
146
+ setViewMonth((m) => m.subtract(1, "month"));
147
+ return;
148
+ }
149
+ if (panel === "month") {
150
+ setViewMonth((m) => m.subtract(1, "year"));
151
+ return;
152
+ }
153
+ setViewMonth((m) => m.subtract(12, "year"));
154
+ };
155
+ const onNext = () => {
156
+ if (panel === "day") {
157
+ setViewMonth((m) => m.add(1, "month"));
158
+ return;
159
+ }
160
+ if (panel === "month") {
161
+ setViewMonth((m) => m.add(1, "year"));
162
+ return;
163
+ }
164
+ setViewMonth((m) => m.add(12, "year"));
165
+ };
166
+ const prevLabel = panel === "day" ? labels.previousMonth : labels.previousYear;
167
+ const nextLabel = panel === "day" ? labels.nextMonth : labels.nextYear;
168
+ let titleContent;
169
+ if (panel === "day") {
170
+ titleContent = /* @__PURE__ */ jsx(
171
+ "button",
172
+ {
173
+ type: "button",
174
+ className: "ctp-current-month",
175
+ id: titleId,
176
+ "aria-label": `${formatLocalized(viewMonth, "MMMM YYYY", locale)}. ${labels.chooseMonth}`,
177
+ onClick: () => onPanelChange("month"),
178
+ children: formatLocalized(viewMonth, "MMMM YYYY", locale)
179
+ }
180
+ );
181
+ } else if (panel === "month") {
182
+ titleContent = /* @__PURE__ */ jsx(
183
+ "button",
184
+ {
185
+ type: "button",
186
+ className: "ctp-current-month",
187
+ id: titleId,
188
+ "aria-label": `${year}. ${labels.chooseYear}`,
189
+ onClick: () => onPanelChange("year"),
190
+ children: String(year)
191
+ }
192
+ );
193
+ } else {
194
+ titleContent = /* @__PURE__ */ jsxs("span", { className: "ctp-current-month", id: titleId, children: [
195
+ windowStart,
196
+ " \u2013 ",
197
+ windowEnd
198
+ ] });
199
+ }
200
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
201
+ /* @__PURE__ */ jsxs("div", { className: "ctp-month-year", children: [
202
+ /* @__PURE__ */ jsx(
203
+ "button",
204
+ {
205
+ type: "button",
206
+ className: "ctp-prev-month",
207
+ "aria-label": prevLabel,
208
+ onClick: onPrev,
209
+ children: "\u2039"
210
+ }
211
+ ),
212
+ titleContent,
213
+ /* @__PURE__ */ jsx(
214
+ "button",
215
+ {
216
+ type: "button",
217
+ className: "ctp-next-month",
218
+ "aria-label": nextLabel,
219
+ onClick: onNext,
220
+ children: "\u203A"
221
+ }
222
+ )
223
+ ] }),
224
+ panel === "month" && /* @__PURE__ */ jsx(
225
+ "div",
226
+ {
227
+ className: "ctp-month-grid",
228
+ role: "grid",
229
+ "aria-label": labels.chooseMonth,
230
+ children: Array.from({ length: 12 }, (_, monthIndex) => {
231
+ const monthDate = viewMonth.month(monthIndex);
232
+ const isCurrent = viewMonth.year() === now.year() && monthIndex === now.month();
233
+ return /* @__PURE__ */ jsx(
234
+ "button",
235
+ {
236
+ type: "button",
237
+ role: "gridcell",
238
+ "aria-current": isCurrent ? "date" : void 0,
239
+ "aria-label": formatLocalized(monthDate, "MMMM YYYY", locale),
240
+ className: cx(
241
+ "ctp-box",
242
+ "ctp-box-month",
243
+ isCurrent && "ctp-current"
244
+ ),
245
+ onClick: () => {
246
+ setViewMonth((m) => m.month(monthIndex));
247
+ onPanelChange("day");
248
+ },
249
+ children: formatLocalized(monthDate, "MMM", locale)
250
+ },
251
+ monthIndex
252
+ );
253
+ })
254
+ }
255
+ ),
256
+ panel === "year" && /* @__PURE__ */ jsx(
257
+ "div",
258
+ {
259
+ className: "ctp-year-grid",
260
+ role: "grid",
261
+ "aria-label": labels.chooseYear,
262
+ children: Array.from({ length: 12 }, (_, offset) => {
263
+ const y = windowStart + offset;
264
+ const isCurrent = now.year() === y;
265
+ return /* @__PURE__ */ jsx(
266
+ "button",
267
+ {
268
+ type: "button",
269
+ role: "gridcell",
270
+ "aria-current": isCurrent ? "date" : void 0,
271
+ "aria-label": String(y),
272
+ className: cx(
273
+ "ctp-box",
274
+ "ctp-box-year",
275
+ isCurrent && "ctp-current"
276
+ ),
277
+ onClick: () => {
278
+ setViewMonth((m) => m.year(y));
279
+ onPanelChange("month");
280
+ },
281
+ children: y
282
+ },
283
+ y
284
+ );
285
+ })
286
+ }
287
+ )
288
+ ] });
289
+ }
290
+
291
+ // src/core/logic/calendar.ts
292
+ function isDisabledDay(date, options) {
293
+ const today = dayjs().startOf("day");
294
+ const day = date.startOf("day");
295
+ if (options.disablePastDates && day.isBefore(today, "day")) {
296
+ return true;
297
+ }
298
+ if (options.disableFutureDates && day.isAfter(today, "day")) {
299
+ return true;
300
+ }
301
+ const min = parseValue(options.minDate ?? null);
302
+ const max = parseValue(options.maxDate ?? null);
303
+ if (min && day.isBefore(min.startOf("day"), "day")) {
304
+ return true;
305
+ }
306
+ if (max && day.isAfter(max.startOf("day"), "day")) {
307
+ return true;
308
+ }
309
+ return false;
310
+ }
311
+ function buildCalendarMonth(options) {
312
+ const weekStartsOn = options.weekStartsOn ?? 0;
313
+ const monthStart = options.viewMonth.startOf("month");
314
+ const monthEnd = options.viewMonth.endOf("month");
315
+ const gridStart = startOfWeek(monthStart, weekStartsOn);
316
+ const gridEnd = endOfWeek(monthEnd, weekStartsOn);
317
+ const weeks = [];
318
+ let cursor = gridStart.clone();
319
+ while (cursor.isBefore(gridEnd) || cursor.isSame(gridEnd, "day")) {
320
+ const week = [];
321
+ for (let i = 0; i < 7; i += 1) {
322
+ const date = cursor.clone();
323
+ const isCurrentMonth = date.isSame(options.viewMonth, "month");
324
+ const isSelected = Boolean(
325
+ options.selected && date.isSame(options.selected, "day")
326
+ );
327
+ const isRangeStart = Boolean(
328
+ options.rangeStart && date.isSame(options.rangeStart, "day")
329
+ );
330
+ const isRangeEnd = Boolean(
331
+ options.rangeEnd && date.isSame(options.rangeEnd, "day")
332
+ );
333
+ const effectiveEnd = options.rangeEnd ?? options.hoverEnd ?? null;
334
+ let isInRange = false;
335
+ if (options.rangeStart && effectiveEnd) {
336
+ const rangeLow = options.rangeStart.isBefore(effectiveEnd, "day") ? options.rangeStart : effectiveEnd;
337
+ const rangeHigh = options.rangeStart.isBefore(effectiveEnd, "day") ? effectiveEnd : options.rangeStart;
338
+ isInRange = date.isAfter(rangeLow, "day") && date.isBefore(rangeHigh, "day") || date.isSame(rangeLow, "day") || date.isSame(rangeHigh, "day");
339
+ }
340
+ week.push({
341
+ date,
342
+ isCurrentMonth,
343
+ isCurrentDate: date.isSame(dayjs(), "day"),
344
+ isFuture: date.isAfter(dayjs(), "day"),
345
+ isPast: date.isBefore(dayjs(), "day"),
346
+ isWeekend: date.day() === 0 || date.day() === 6,
347
+ isDisabled: isDisabledDay(date, options),
348
+ isSelected,
349
+ isInRange,
350
+ isRangeStart,
351
+ isRangeEnd
352
+ });
353
+ cursor = cursor.add(1, "day");
354
+ }
355
+ weeks.push(week);
356
+ }
357
+ return weeks;
358
+ }
359
+
360
+ // src/core/types.ts
361
+ var DEFAULT_LABELS = {
362
+ date: "Date",
363
+ time: "Time",
364
+ clear: "Clear",
365
+ close: "Close",
366
+ ok: "OK",
367
+ start: "Start",
368
+ end: "End",
369
+ chooseDate: "Choose date",
370
+ chooseDateRange: "Choose date range",
371
+ chooseMonth: "Choose month",
372
+ chooseYear: "Choose year",
373
+ previousMonth: "Previous month",
374
+ nextMonth: "Next month",
375
+ previousYear: "Previous year",
376
+ nextYear: "Next year",
377
+ selectEnd: "Select end date"
378
+ };
379
+
380
+ // src/core/controller.ts
381
+ function padDisplay(n) {
382
+ return String(n).padStart(2, "0");
383
+ }
384
+ var PickerController = class {
385
+ constructor(options = {}) {
386
+ this.listeners = /* @__PURE__ */ new Set();
387
+ this.calPanel = "day";
388
+ this.showHours = false;
389
+ this.showMinutes = false;
390
+ this.showSecondsOpen = false;
391
+ this.showAmPm = false;
392
+ this.subscribe = (listener) => {
393
+ this.listeners.add(listener);
394
+ return () => {
395
+ this.listeners.delete(listener);
396
+ };
397
+ };
398
+ this.getSnapshot = () => this.snapshot;
399
+ /** Stable for useSyncExternalStore — returns same reference until mutate. */
400
+ this.getServerSnapshot = () => this.snapshot;
401
+ this.options = { ...options };
402
+ const mode = options.mode ?? "datetime";
403
+ const showSeconds = options.showSeconds !== false;
404
+ const use12Hours = Boolean(options.use12Hours);
405
+ const format = resolveFormat({
406
+ mode,
407
+ format: options.format,
408
+ use12Hours,
409
+ showSeconds
410
+ });
411
+ const initial = parseValue(options.value ?? options.defaultValue ?? dayjs(), format) ?? dayjs();
412
+ this.draft = initial;
413
+ this.viewMonth = initial.startOf("month");
414
+ this.focusedDay = initial;
415
+ this.tab = mode === "time" ? "time" : "date";
416
+ this.open = options.open ?? (options.inline ? true : options.defaultOpen ?? true);
417
+ this.snapshot = this.buildSnapshot();
418
+ }
419
+ setOptions(partial) {
420
+ const prev = this.options;
421
+ this.options = { ...this.options, ...partial };
422
+ if (partial.mode !== void 0 && partial.mode !== prev.mode) {
423
+ this.tab = partial.mode === "time" ? "time" : "date";
424
+ }
425
+ if (partial.open !== void 0) {
426
+ this.open = partial.open;
427
+ }
428
+ if ("value" in partial) {
429
+ if (partial.value === null) {
430
+ const fallback = dayjs();
431
+ this.draft = fallback;
432
+ this.viewMonth = fallback.startOf("month");
433
+ this.focusedDay = fallback;
434
+ } else if (partial.value !== void 0) {
435
+ const format = this.getResolvedFormat();
436
+ const parsed = parseValue(partial.value, format);
437
+ if (parsed) {
438
+ this.draft = parsed;
439
+ this.viewMonth = parsed.startOf("month");
440
+ this.focusedDay = parsed;
441
+ }
442
+ }
443
+ }
444
+ this.emit();
445
+ }
446
+ getResolvedFormat() {
447
+ return resolveFormat({
448
+ mode: this.options.mode ?? "datetime",
449
+ format: this.options.format,
450
+ use12Hours: Boolean(this.options.use12Hours),
451
+ showSeconds: this.options.showSeconds !== false
452
+ });
453
+ }
454
+ getLabels() {
455
+ return { ...DEFAULT_LABELS, ...this.options.labels };
456
+ }
457
+ emit() {
458
+ this.snapshot = this.buildSnapshot();
459
+ this.listeners.forEach((l) => l());
460
+ }
461
+ buildSnapshot() {
462
+ const mode = this.options.mode ?? "datetime";
463
+ const layout = this.options.layout ?? "combined";
464
+ const showSeconds = this.options.showSeconds !== false;
465
+ const use12Hours = Boolean(this.options.use12Hours);
466
+ const inline = Boolean(this.options.inline);
467
+ const popover = Boolean(this.options.popover);
468
+ const weekStartsOn = this.options.weekStartsOn ?? 0;
469
+ const locale = this.options.locale ?? "en";
470
+ const resolvedFormat = this.getResolvedFormat();
471
+ const labels = this.getLabels();
472
+ const weeks = buildCalendarMonth({
473
+ viewMonth: this.viewMonth,
474
+ selected: this.draft,
475
+ minDate: this.options.minDate,
476
+ maxDate: this.options.maxDate,
477
+ disablePastDates: this.options.disablePastDates,
478
+ disableFutureDates: this.options.disableFutureDates,
479
+ weekStartsOn
480
+ });
481
+ const showDate = mode !== "time";
482
+ const showTime = mode !== "date";
483
+ const useTabs = mode === "datetime" && layout === "tabs";
484
+ const showDatePanel = showDate && (!useTabs || this.tab === "date");
485
+ const showTimePanel = showTime && (!useTabs || this.tab === "time");
486
+ const hour24 = this.draft.hour();
487
+ const { hour: hour12, isAm } = to12Hour(hour24);
488
+ return {
489
+ draft: this.draft,
490
+ viewMonth: this.viewMonth,
491
+ calPanel: this.calPanel,
492
+ tab: this.tab,
493
+ showHours: this.showHours,
494
+ showMinutes: this.showMinutes,
495
+ showSecondsOpen: this.showSecondsOpen,
496
+ showAmPm: this.showAmPm,
497
+ focusedDay: this.focusedDay,
498
+ open: this.open,
499
+ mode,
500
+ layout,
501
+ showSeconds,
502
+ use12Hours,
503
+ inline,
504
+ popover,
505
+ weekStartsOn,
506
+ locale,
507
+ labels,
508
+ resolvedFormat,
509
+ asString: this.options.asString,
510
+ className: this.options.className,
511
+ theme: this.options.theme,
512
+ weeks,
513
+ weekdayLabels: getWeekdayLabels(locale, weekStartsOn),
514
+ showDate,
515
+ showTime,
516
+ useTabs,
517
+ showDatePanel,
518
+ showTimePanel,
519
+ showModeTabs: useTabs,
520
+ hour24,
521
+ hour12,
522
+ isAm,
523
+ hourOptions: use12Hours ? HOURS_12 : HOURS_24,
524
+ displayHour: use12Hours ? padDisplay(hour12) : padDisplay(hour24),
525
+ displayMinute: padDisplay(this.draft.minute()),
526
+ displaySecond: padDisplay(this.draft.second()),
527
+ minuteOptions: MINUTES
528
+ };
529
+ }
530
+ setOpen(open) {
531
+ if (this.options.inline) {
532
+ return;
533
+ }
534
+ this.open = open;
535
+ this.options.onOpenChange?.(open);
536
+ this.emit();
537
+ }
538
+ close() {
539
+ if (!this.options.inline) {
540
+ this.setOpen(false);
541
+ }
542
+ }
543
+ setTab(tab) {
544
+ this.tab = tab;
545
+ this.emit();
546
+ }
547
+ setCalPanel(panel) {
548
+ this.calPanel = panel;
549
+ this.emit();
550
+ }
551
+ setViewMonth(next) {
552
+ this.viewMonth = typeof next === "function" ? next(this.viewMonth) : next;
553
+ this.emit();
554
+ }
555
+ selectDay(day) {
556
+ this.draft = this.draft.year(day.year()).month(day.month()).date(day.date());
557
+ this.focusedDay = day;
558
+ this.emit();
559
+ }
560
+ setHour(hourValue) {
561
+ this.draft = this.draft.hour(hourValue);
562
+ this.emit();
563
+ }
564
+ setMinute(minute) {
565
+ this.draft = this.draft.minute(minute);
566
+ this.emit();
567
+ }
568
+ setSecond(second) {
569
+ this.draft = this.draft.second(second);
570
+ this.emit();
571
+ }
572
+ setAmPm(isAm) {
573
+ const { hour } = to12Hour(this.draft.hour());
574
+ this.draft = this.draft.hour(to24Hour(hour, isAm));
575
+ this.emit();
576
+ }
577
+ toggleHours() {
578
+ this.showHours = !this.showHours;
579
+ this.showMinutes = false;
580
+ this.showSecondsOpen = false;
581
+ this.showAmPm = false;
582
+ this.emit();
583
+ }
584
+ toggleMinutes() {
585
+ this.showMinutes = !this.showMinutes;
586
+ this.showHours = false;
587
+ this.showSecondsOpen = false;
588
+ this.showAmPm = false;
589
+ this.emit();
590
+ }
591
+ toggleSeconds() {
592
+ this.showSecondsOpen = !this.showSecondsOpen;
593
+ this.showHours = false;
594
+ this.showMinutes = false;
595
+ this.showAmPm = false;
596
+ this.emit();
597
+ }
598
+ toggleAmPm() {
599
+ this.showAmPm = !this.showAmPm;
600
+ this.showHours = false;
601
+ this.showMinutes = false;
602
+ this.showSecondsOpen = false;
603
+ this.emit();
604
+ }
605
+ closeTimeColumns() {
606
+ this.showHours = false;
607
+ this.showMinutes = false;
608
+ this.showSecondsOpen = false;
609
+ this.showAmPm = false;
610
+ this.emit();
611
+ }
612
+ selectHourOption(opt) {
613
+ const snap = this.snapshot;
614
+ if (snap.use12Hours) {
615
+ this.draft = this.draft.hour(to24Hour(Number(opt), snap.isAm));
616
+ } else {
617
+ this.draft = this.draft.hour(Number(opt));
618
+ }
619
+ this.showHours = false;
620
+ this.emit();
621
+ }
622
+ selectMinuteOption(opt) {
623
+ this.draft = this.draft.minute(Number(opt));
624
+ this.showMinutes = false;
625
+ this.emit();
626
+ }
627
+ selectSecondOption(opt) {
628
+ this.draft = this.draft.second(Number(opt));
629
+ this.showSecondsOpen = false;
630
+ this.emit();
631
+ }
632
+ selectAmPmOption(opt) {
633
+ const { hour } = to12Hour(this.draft.hour());
634
+ this.draft = this.draft.hour(to24Hour(hour, opt === "AM"));
635
+ this.showAmPm = false;
636
+ this.emit();
637
+ }
638
+ handleGridKeyDown(key) {
639
+ const snap = this.snapshot;
640
+ let next = this.focusedDay;
641
+ switch (key) {
642
+ case "ArrowLeft":
643
+ next = this.focusedDay.subtract(1, "day");
644
+ break;
645
+ case "ArrowRight":
646
+ next = this.focusedDay.add(1, "day");
647
+ break;
648
+ case "ArrowUp":
649
+ next = this.focusedDay.subtract(7, "day");
650
+ break;
651
+ case "ArrowDown":
652
+ next = this.focusedDay.add(7, "day");
653
+ break;
654
+ case "Home":
655
+ next = startOfWeek(this.focusedDay, snap.weekStartsOn);
656
+ break;
657
+ case "End":
658
+ next = endOfWeek(this.focusedDay, snap.weekStartsOn);
659
+ break;
660
+ case "PageUp":
661
+ next = this.focusedDay.subtract(1, "month");
662
+ this.viewMonth = next.startOf("month");
663
+ break;
664
+ case "PageDown":
665
+ next = this.focusedDay.add(1, "month");
666
+ this.viewMonth = next.startOf("month");
667
+ break;
668
+ case "Enter":
669
+ case " ": {
670
+ const cell = snap.weeks.flat().find((d) => d.date.isSame(this.focusedDay, "day"));
671
+ if (cell && !cell.isDisabled && cell.isCurrentMonth) {
672
+ this.selectDay(cell.date);
673
+ }
674
+ return true;
675
+ }
676
+ default:
677
+ return false;
678
+ }
679
+ this.focusedDay = next;
680
+ if (!next.isSame(this.viewMonth, "month")) {
681
+ this.viewMonth = next.startOf("month");
682
+ }
683
+ this.emit();
684
+ return true;
685
+ }
686
+ confirm() {
687
+ const snap = this.snapshot;
688
+ let payload;
689
+ if (snap.asString === false) {
690
+ if (snap.mode === "time") {
691
+ payload = buildTimeValue(this.draft, snap.resolvedFormat);
692
+ } else if (snap.mode === "date") {
693
+ payload = this.draft.startOf("day").toDate();
694
+ } else {
695
+ payload = this.draft.toDate();
696
+ }
697
+ } else {
698
+ if (snap.asString === void 0) {
699
+ warnAsStringDeprecation();
700
+ }
701
+ payload = formatValue(this.draft, snap.resolvedFormat);
702
+ }
703
+ this.options.onChange?.(payload);
704
+ this.close();
705
+ return payload;
706
+ }
707
+ clear() {
708
+ this.options.onChange?.(null);
709
+ this.close();
710
+ }
711
+ /** Year window helpers for month/year panels */
712
+ yearWindowStart(year) {
713
+ return Math.floor(year / 12) * 12;
714
+ }
715
+ navigatePrev() {
716
+ if (this.calPanel === "day") {
717
+ this.viewMonth = this.viewMonth.subtract(1, "month");
718
+ } else if (this.calPanel === "month") {
719
+ this.viewMonth = this.viewMonth.subtract(1, "year");
720
+ } else {
721
+ this.viewMonth = this.viewMonth.subtract(12, "year");
722
+ }
723
+ this.emit();
724
+ }
725
+ navigateNext() {
726
+ if (this.calPanel === "day") {
727
+ this.viewMonth = this.viewMonth.add(1, "month");
728
+ } else if (this.calPanel === "month") {
729
+ this.viewMonth = this.viewMonth.add(1, "year");
730
+ } else {
731
+ this.viewMonth = this.viewMonth.add(12, "year");
732
+ }
733
+ this.emit();
734
+ }
735
+ selectMonth(monthIndex) {
736
+ this.viewMonth = this.viewMonth.month(monthIndex);
737
+ this.calPanel = "day";
738
+ this.emit();
739
+ }
740
+ selectYear(year) {
741
+ this.viewMonth = this.viewMonth.year(year);
742
+ this.calPanel = "month";
743
+ this.emit();
744
+ }
745
+ };
746
+
747
+ // src/vanilla/a11y.ts
748
+ var FOCUSABLE = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
749
+ var POPOVER_GAP = 8;
750
+ var POPOVER_PADDING = 8;
751
+ var DEFAULT_PICKER_WIDTH = 300;
752
+ var DEFAULT_PICKER_HEIGHT = 360;
753
+ function attachFocusTrap(container, active) {
754
+ const previouslyFocused = document.activeElement;
755
+ const focusables = () => Array.from(container.querySelectorAll(FOCUSABLE)).filter(
756
+ (el) => !el.hasAttribute("disabled") && el.offsetParent !== null
757
+ );
758
+ const first = focusables()[0];
759
+ first?.focus({ preventScroll: true });
760
+ const onKeyDown = (event) => {
761
+ if (event.key !== "Tab") {
762
+ return;
763
+ }
764
+ const items = focusables();
765
+ if (items.length === 0) {
766
+ return;
767
+ }
768
+ const firstItem = items[0];
769
+ const lastItem = items[items.length - 1];
770
+ if (event.shiftKey && document.activeElement === firstItem) {
771
+ event.preventDefault();
772
+ lastItem.focus({ preventScroll: true });
773
+ } else if (!event.shiftKey && document.activeElement === lastItem) {
774
+ event.preventDefault();
775
+ firstItem.focus({ preventScroll: true });
776
+ }
777
+ };
778
+ container.addEventListener("keydown", onKeyDown);
779
+ return () => {
780
+ container.removeEventListener("keydown", onKeyDown);
781
+ previouslyFocused?.focus?.({ preventScroll: true });
782
+ };
783
+ }
784
+ function attachEscape(handler, active) {
785
+ const onKeyDown = (event) => {
786
+ if (event.key === "Escape") {
787
+ event.preventDefault();
788
+ handler();
789
+ }
790
+ };
791
+ document.addEventListener("keydown", onKeyDown);
792
+ return () => document.removeEventListener("keydown", onKeyDown);
793
+ }
794
+ function attachClickOutside(handler, active, floating, anchorEl) {
795
+ const onPointerDown = (event) => {
796
+ const target = event.target;
797
+ if (!(target instanceof Node)) {
798
+ return;
799
+ }
800
+ if (floating?.contains(target)) {
801
+ return;
802
+ }
803
+ if (anchorEl?.contains(target)) {
804
+ return;
805
+ }
806
+ handler();
807
+ };
808
+ document.addEventListener("pointerdown", onPointerDown, true);
809
+ return () => {
810
+ document.removeEventListener("pointerdown", onPointerDown, true);
811
+ };
812
+ }
813
+ function computePopoverPosition(anchorEl, pickerWidth, pickerHeight) {
814
+ const rect = anchorEl.getBoundingClientRect();
815
+ let top = rect.bottom + POPOVER_GAP;
816
+ let left = rect.left;
817
+ if (left + pickerWidth > window.innerWidth - POPOVER_PADDING) {
818
+ left = Math.max(
819
+ POPOVER_PADDING,
820
+ window.innerWidth - pickerWidth - POPOVER_PADDING
821
+ );
822
+ }
823
+ if (left < POPOVER_PADDING) {
824
+ left = POPOVER_PADDING;
825
+ }
826
+ if (top + pickerHeight > window.innerHeight - POPOVER_PADDING) {
827
+ const above = rect.top - pickerHeight - POPOVER_GAP;
828
+ if (above >= POPOVER_PADDING) {
829
+ top = above;
830
+ } else {
831
+ top = Math.max(
832
+ POPOVER_PADDING,
833
+ window.innerHeight - pickerHeight - POPOVER_PADDING
834
+ );
835
+ }
836
+ }
837
+ return { top, left };
838
+ }
839
+ function resolveThemeAttr(theme, anchorEl) {
840
+ if (theme === "light" || theme === "dark") {
841
+ return theme;
842
+ }
843
+ let node = anchorEl ?? null;
844
+ while (node) {
845
+ const attr = node.getAttribute("data-ctp-theme");
846
+ if (attr === "dark" || attr === "light") {
847
+ return attr;
848
+ }
849
+ node = node.parentElement;
850
+ }
851
+ if (typeof document !== "undefined") {
852
+ const root = document.documentElement.getAttribute("data-ctp-theme");
853
+ if (root === "dark" || root === "light") {
854
+ return root;
855
+ }
856
+ }
857
+ return void 0;
858
+ }
859
+ function useControllableState(options) {
860
+ const { value, defaultValue, onChange } = options;
861
+ const [uncontrolled, setUncontrolled] = useState(defaultValue);
862
+ const isControlled = value !== void 0;
863
+ const state = isControlled ? value : uncontrolled;
864
+ const setState = useCallback(
865
+ (next) => {
866
+ const resolved = typeof next === "function" ? next(state) : next;
867
+ if (!isControlled) {
868
+ setUncontrolled(resolved);
869
+ }
870
+ onChange?.(resolved);
871
+ },
872
+ [isControlled, onChange, state]
873
+ );
874
+ return [state, setState];
875
+ }
876
+ function cx2(...parts) {
877
+ return parts.filter(Boolean).join(" ");
878
+ }
879
+ var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
880
+ function usePopoverPosition(anchorEl, open, enabled, floatingRef) {
881
+ const [position, setPosition] = useState(null);
882
+ const update = useCallback(() => {
883
+ if (!enabled || !open || !anchorEl) {
884
+ setPosition(null);
885
+ return;
886
+ }
887
+ const floating = floatingRef.current;
888
+ const width = floating?.offsetWidth || DEFAULT_PICKER_WIDTH;
889
+ const height = floating?.offsetHeight || DEFAULT_PICKER_HEIGHT;
890
+ setPosition(computePopoverPosition(anchorEl, width, height));
891
+ }, [anchorEl, enabled, open, floatingRef]);
892
+ useIsomorphicLayoutEffect(() => {
893
+ update();
894
+ }, [update]);
895
+ useEffect(() => {
896
+ if (!open || !enabled) {
897
+ return;
898
+ }
899
+ window.addEventListener("resize", update);
900
+ window.addEventListener("scroll", update, true);
901
+ const floating = floatingRef.current;
902
+ let observer;
903
+ if (floating && typeof ResizeObserver !== "undefined") {
904
+ observer = new ResizeObserver(() => update());
905
+ observer.observe(floating);
906
+ }
907
+ return () => {
908
+ window.removeEventListener("resize", update);
909
+ window.removeEventListener("scroll", update, true);
910
+ observer?.disconnect();
911
+ };
912
+ }, [open, enabled, update, floatingRef]);
913
+ if (!open || !enabled) {
914
+ return null;
915
+ }
916
+ return position;
917
+ }
918
+ function DateTime(props) {
919
+ const {
920
+ value,
921
+ defaultValue,
922
+ onChange,
923
+ asString,
924
+ showSeconds = true,
925
+ format,
926
+ mode = "datetime",
927
+ layout = "combined",
928
+ minDate,
929
+ maxDate,
930
+ disablePastDates = false,
931
+ disableFutureDates = false,
932
+ weekStartsOn = 0,
933
+ use12Hours = false,
934
+ inline = false,
935
+ className,
936
+ style,
937
+ locale = "en",
938
+ labels: labelsProp,
939
+ theme,
940
+ open: openProp,
941
+ defaultOpen = true,
942
+ onOpenChange,
943
+ anchorEl,
944
+ popover = false
945
+ } = props;
946
+ const titleId = useId();
947
+ const dialogRef = useRef(null);
948
+ const [open, setOpen] = useControllableState({
949
+ value: openProp,
950
+ defaultValue: inline ? true : defaultOpen,
951
+ onChange: onOpenChange
952
+ });
953
+ const controllerRef = useRef(null);
954
+ if (!controllerRef.current) {
955
+ controllerRef.current = new PickerController({
956
+ value,
957
+ defaultValue,
958
+ onChange,
959
+ asString,
960
+ showSeconds,
961
+ format,
962
+ mode,
963
+ layout,
964
+ minDate,
965
+ maxDate,
966
+ disablePastDates,
967
+ disableFutureDates,
968
+ weekStartsOn,
969
+ use12Hours,
970
+ inline,
971
+ className,
972
+ locale,
973
+ labels: labelsProp,
974
+ theme,
975
+ open,
976
+ popover,
977
+ anchorEl
978
+ });
979
+ }
980
+ const controller = controllerRef.current;
981
+ useEffect(() => {
982
+ controller.setOptions({
983
+ value,
984
+ onChange,
985
+ asString,
986
+ showSeconds,
987
+ format,
988
+ mode,
989
+ layout,
990
+ minDate,
991
+ maxDate,
992
+ disablePastDates,
993
+ disableFutureDates,
994
+ weekStartsOn,
995
+ use12Hours,
996
+ inline,
997
+ className,
998
+ locale,
999
+ labels: labelsProp,
1000
+ theme,
1001
+ open,
1002
+ popover,
1003
+ anchorEl,
1004
+ onOpenChange: setOpen
1005
+ });
1006
+ }, [
1007
+ controller,
1008
+ value,
1009
+ onChange,
1010
+ asString,
1011
+ showSeconds,
1012
+ format,
1013
+ mode,
1014
+ layout,
1015
+ minDate,
1016
+ maxDate,
1017
+ disablePastDates,
1018
+ disableFutureDates,
1019
+ weekStartsOn,
1020
+ use12Hours,
1021
+ inline,
1022
+ className,
1023
+ locale,
1024
+ labelsProp,
1025
+ theme,
1026
+ open,
1027
+ popover,
1028
+ anchorEl,
1029
+ setOpen
1030
+ ]);
1031
+ const snap = useSyncExternalStore(
1032
+ controller.subscribe,
1033
+ controller.getSnapshot,
1034
+ controller.getServerSnapshot
1035
+ );
1036
+ const close = useCallback(() => {
1037
+ if (!inline) {
1038
+ setOpen(false);
1039
+ }
1040
+ }, [inline, setOpen]);
1041
+ useEffect(() => {
1042
+ if (!(open && !inline)) {
1043
+ return;
1044
+ }
1045
+ const el = dialogRef.current;
1046
+ if (!el) {
1047
+ return;
1048
+ }
1049
+ return attachEscape(close);
1050
+ }, [open, inline, close]);
1051
+ useEffect(() => {
1052
+ if (!(open && !inline)) {
1053
+ return;
1054
+ }
1055
+ const el = dialogRef.current;
1056
+ if (!el) {
1057
+ return;
1058
+ }
1059
+ return attachFocusTrap(el);
1060
+ }, [open, inline]);
1061
+ useEffect(() => {
1062
+ if (!(open && !inline && popover)) {
1063
+ return;
1064
+ }
1065
+ return attachClickOutside(close, true, dialogRef.current, anchorEl);
1066
+ }, [open, inline, popover, close, anchorEl]);
1067
+ const position = usePopoverPosition(
1068
+ anchorEl,
1069
+ open && !inline,
1070
+ popover,
1071
+ dialogRef
1072
+ );
1073
+ const onGridKeyDown = (event) => {
1074
+ if (controller.handleGridKeyDown(event.key)) {
1075
+ event.preventDefault();
1076
+ }
1077
+ };
1078
+ const onBackdropClick = (event) => {
1079
+ if (event.target === event.currentTarget) {
1080
+ close();
1081
+ }
1082
+ };
1083
+ if (!open && !inline) {
1084
+ return null;
1085
+ }
1086
+ const themeAttr = resolveThemeAttr(theme, anchorEl);
1087
+ const pickerStyle = popover && !inline ? {
1088
+ ...style,
1089
+ position: "fixed",
1090
+ top: position?.top ?? 80,
1091
+ left: position?.left ?? 16
1092
+ } : style;
1093
+ const datePanel = /* @__PURE__ */ jsxs("div", { className: "ctp-body ctp-body-calendar-date", children: [
1094
+ /* @__PURE__ */ jsx(
1095
+ CalendarHeader,
1096
+ {
1097
+ viewMonth: snap.viewMonth,
1098
+ setViewMonth: (next) => controller.setViewMonth(next),
1099
+ panel: snap.calPanel,
1100
+ onPanelChange: (p) => controller.setCalPanel(p),
1101
+ locale: snap.locale,
1102
+ labels: snap.labels,
1103
+ titleId: snap.showDatePanel ? titleId : void 0
1104
+ }
1105
+ ),
1106
+ snap.calPanel === "day" && /* @__PURE__ */ jsxs(
1107
+ "div",
1108
+ {
1109
+ className: "ctp-main-calendar",
1110
+ role: "grid",
1111
+ "aria-label": snap.labels.chooseDate,
1112
+ tabIndex: 0,
1113
+ onKeyDown: onGridKeyDown,
1114
+ children: [
1115
+ snap.weekdayLabels.map((label) => /* @__PURE__ */ jsx(
1116
+ "div",
1117
+ {
1118
+ className: "ctp-box ctp-box-days",
1119
+ role: "columnheader",
1120
+ children: label
1121
+ },
1122
+ label
1123
+ )),
1124
+ snap.weeks.map(
1125
+ (week) => week.map((dayData) => {
1126
+ const selected = dayData.isSelected;
1127
+ const focused = dayData.date.isSame(snap.focusedDay, "day");
1128
+ const disabled = !dayData.isCurrentMonth || dayData.isDisabled;
1129
+ return /* @__PURE__ */ jsx(
1130
+ "button",
1131
+ {
1132
+ type: "button",
1133
+ role: "gridcell",
1134
+ tabIndex: focused ? 0 : -1,
1135
+ "aria-selected": selected,
1136
+ "aria-disabled": disabled,
1137
+ disabled,
1138
+ "aria-label": formatLocalized(
1139
+ dayData.date,
1140
+ "dddd, MMMM D, YYYY",
1141
+ snap.locale
1142
+ ),
1143
+ className: cx2(
1144
+ "ctp-box",
1145
+ "ctp-box-date",
1146
+ !dayData.isCurrentMonth && "not-current-month",
1147
+ selected && "selected",
1148
+ dayData.isDisabled && "disabled-date",
1149
+ dayData.isWeekend && "weekend-day",
1150
+ dayData.isCurrentDate && "ctp-today",
1151
+ dayData.isInRange && "ctp-in-range",
1152
+ dayData.isRangeStart && "ctp-range-start",
1153
+ dayData.isRangeEnd && "ctp-range-end"
1154
+ ),
1155
+ onClick: () => {
1156
+ if (!disabled) {
1157
+ controller.selectDay(dayData.date);
1158
+ }
1159
+ },
1160
+ children: dayData.date.format("D")
1161
+ },
1162
+ dayData.date.format("YYYY-MM-DD")
1163
+ );
1164
+ })
1165
+ )
1166
+ ]
1167
+ }
1168
+ )
1169
+ ] });
1170
+ const timePanel = /* @__PURE__ */ jsxs("div", { className: "ctp-body ctp-body-calendar-time", children: [
1171
+ snap.showDatePanel && /* @__PURE__ */ jsx("div", { className: "ctp-section-label", children: snap.labels.time }),
1172
+ !snap.showDatePanel && /* @__PURE__ */ jsx("span", { className: "ctp-visually-hidden", id: titleId, children: snap.labels.time }),
1173
+ /* @__PURE__ */ jsxs("div", { className: "ctp-main-time", children: [
1174
+ /* @__PURE__ */ jsxs("div", { className: "ctp-main-time-header", children: [
1175
+ /* @__PURE__ */ jsx("div", { className: "ctp-box", children: "Hr" }),
1176
+ /* @__PURE__ */ jsx("div", { className: "ctp-box", children: "Min" }),
1177
+ snap.showSeconds && /* @__PURE__ */ jsx("div", { className: "ctp-box", children: "Sec" }),
1178
+ snap.use12Hours && /* @__PURE__ */ jsx("div", { className: "ctp-box", children: "AM/PM" })
1179
+ ] }),
1180
+ /* @__PURE__ */ jsxs("div", { className: "ctp-main-time-body", children: [
1181
+ /* @__PURE__ */ jsx(
1182
+ TimeColumn,
1183
+ {
1184
+ label: "hours",
1185
+ open: snap.showHours,
1186
+ onToggle: () => controller.toggleHours(),
1187
+ display: snap.displayHour,
1188
+ options: snap.hourOptions,
1189
+ onSelect: (opt) => controller.selectHourOption(opt)
1190
+ }
1191
+ ),
1192
+ /* @__PURE__ */ jsx(
1193
+ TimeColumn,
1194
+ {
1195
+ label: "minutes",
1196
+ open: snap.showMinutes,
1197
+ onToggle: () => controller.toggleMinutes(),
1198
+ display: snap.displayMinute,
1199
+ options: snap.minuteOptions,
1200
+ onSelect: (opt) => controller.selectMinuteOption(opt)
1201
+ }
1202
+ ),
1203
+ snap.showSeconds && /* @__PURE__ */ jsx(
1204
+ TimeColumn,
1205
+ {
1206
+ label: "seconds",
1207
+ open: snap.showSecondsOpen,
1208
+ onToggle: () => controller.toggleSeconds(),
1209
+ display: snap.displaySecond,
1210
+ options: snap.minuteOptions,
1211
+ onSelect: (opt) => controller.selectSecondOption(opt)
1212
+ }
1213
+ ),
1214
+ snap.use12Hours && /* @__PURE__ */ jsx(
1215
+ TimeColumn,
1216
+ {
1217
+ label: "am-pm",
1218
+ open: snap.showAmPm,
1219
+ onToggle: () => controller.toggleAmPm(),
1220
+ display: snap.isAm ? "AM" : "PM",
1221
+ options: ["AM", "PM"],
1222
+ onSelect: (opt) => controller.selectAmPmOption(opt)
1223
+ }
1224
+ )
1225
+ ] })
1226
+ ] })
1227
+ ] });
1228
+ const picker = /* @__PURE__ */ jsxs(
1229
+ "div",
1230
+ {
1231
+ ref: dialogRef,
1232
+ className: cx2(
1233
+ "ctp-calendar-time-picker",
1234
+ popover && !inline && "ctp-popover",
1235
+ snap.use12Hours && "ctp-use-12h",
1236
+ snap.mode === "time" && "ctp-mode-time",
1237
+ !snap.showSeconds && "ctp-no-seconds",
1238
+ snap.showDatePanel && snap.showTimePanel && "ctp-layout-combined",
1239
+ className
1240
+ ),
1241
+ style: pickerStyle,
1242
+ "data-ctp-theme": themeAttr,
1243
+ role: inline ? void 0 : "dialog",
1244
+ "aria-modal": inline ? void 0 : true,
1245
+ "aria-labelledby": titleId,
1246
+ children: [
1247
+ snap.showModeTabs && /* @__PURE__ */ jsx("div", { className: "ctp-header", children: /* @__PURE__ */ jsxs(
1248
+ "div",
1249
+ {
1250
+ className: "ctp-button-container",
1251
+ role: "tablist",
1252
+ "aria-label": "Picker mode",
1253
+ children: [
1254
+ /* @__PURE__ */ jsx(
1255
+ "button",
1256
+ {
1257
+ type: "button",
1258
+ role: "tab",
1259
+ "aria-selected": snap.tab === "date",
1260
+ className: cx2("ctp-date", snap.tab === "date" && "ctp-active"),
1261
+ onClick: () => controller.setTab("date"),
1262
+ children: snap.labels.date
1263
+ }
1264
+ ),
1265
+ /* @__PURE__ */ jsx(
1266
+ "button",
1267
+ {
1268
+ type: "button",
1269
+ role: "tab",
1270
+ "aria-selected": snap.tab === "time",
1271
+ className: cx2("ctp-time", snap.tab === "time" && "ctp-active"),
1272
+ onClick: () => controller.setTab("time"),
1273
+ children: snap.labels.time
1274
+ }
1275
+ )
1276
+ ]
1277
+ }
1278
+ ) }),
1279
+ snap.showDatePanel && datePanel,
1280
+ snap.showTimePanel && timePanel,
1281
+ /* @__PURE__ */ jsxs("div", { className: "ctp-footer", children: [
1282
+ /* @__PURE__ */ jsx(
1283
+ "button",
1284
+ {
1285
+ type: "button",
1286
+ className: "close-button",
1287
+ onClick: () => {
1288
+ onChange?.(null);
1289
+ close();
1290
+ },
1291
+ children: snap.labels.clear
1292
+ }
1293
+ ),
1294
+ !inline && /* @__PURE__ */ jsx("button", { type: "button", className: "ctp-cancel", onClick: close, children: snap.labels.close }),
1295
+ /* @__PURE__ */ jsx(
1296
+ "button",
1297
+ {
1298
+ type: "button",
1299
+ onClick: () => {
1300
+ controller.confirm();
1301
+ close();
1302
+ },
1303
+ children: snap.labels.ok
1304
+ }
1305
+ )
1306
+ ] })
1307
+ ]
1308
+ }
1309
+ );
1310
+ if (inline) {
1311
+ return picker;
1312
+ }
1313
+ if (popover) {
1314
+ return createPortal(picker, document.body);
1315
+ }
1316
+ return createPortal(
1317
+ /* @__PURE__ */ jsx(
1318
+ "div",
1319
+ {
1320
+ className: "ctp-calendar-time-picker-absolute-container",
1321
+ "data-ctp-theme": themeAttr,
1322
+ onClick: onBackdropClick,
1323
+ children: picker
1324
+ }
1325
+ ),
1326
+ document.body
1327
+ );
1328
+ }
1329
+ function TimeColumn(props) {
1330
+ const listId = useId();
1331
+ const listRef = useRef(null);
1332
+ useIsomorphicLayoutEffect(() => {
1333
+ if (props.open && listRef.current) {
1334
+ listRef.current.scrollTop = 0;
1335
+ }
1336
+ }, [props.open]);
1337
+ return /* @__PURE__ */ jsxs(
1338
+ "div",
1339
+ {
1340
+ className: cx2("ctp-box", "ctp-box-time", !props.open && "not-opened"),
1341
+ children: [
1342
+ /* @__PURE__ */ jsx(
1343
+ "button",
1344
+ {
1345
+ type: "button",
1346
+ className: `ctp-${props.label === "am-pm" ? "am-pm" : props.label.slice(0, -1)} ctp-initial-time`,
1347
+ "aria-haspopup": "listbox",
1348
+ "aria-expanded": props.open,
1349
+ "aria-controls": listId,
1350
+ "aria-label": `Select ${props.label}`,
1351
+ onClick: props.onToggle,
1352
+ children: props.display
1353
+ }
1354
+ ),
1355
+ /* @__PURE__ */ jsx(
1356
+ "div",
1357
+ {
1358
+ ref: listRef,
1359
+ id: listId,
1360
+ role: "listbox",
1361
+ "aria-label": props.label,
1362
+ className: cx2(
1363
+ `ctp-overflow-${props.label}`,
1364
+ !props.open && "not-visible"
1365
+ ),
1366
+ children: props.options.map((opt) => /* @__PURE__ */ jsx(
1367
+ "button",
1368
+ {
1369
+ type: "button",
1370
+ role: "option",
1371
+ "aria-selected": opt === props.display,
1372
+ className: `ctp-${props.label === "am-pm" ? "am-pm" : props.label.slice(0, -1)}`,
1373
+ onClick: () => props.onSelect(opt),
1374
+ children: opt
1375
+ },
1376
+ opt
1377
+ ))
1378
+ }
1379
+ )
1380
+ ]
1381
+ }
1382
+ );
1383
+ }
1384
+ function cx3(...parts) {
1385
+ return parts.filter(Boolean).join(" ");
1386
+ }
1387
+ function isTimeValue(value) {
1388
+ return typeof value === "object" && value !== null && !(value instanceof Date) && "formatted" in value && "hour24" in value;
1389
+ }
1390
+ function toDisplayString(value, format) {
1391
+ if (value === null) {
1392
+ return null;
1393
+ }
1394
+ if (typeof value === "string") {
1395
+ return value;
1396
+ }
1397
+ if (isTimeValue(value)) {
1398
+ return value.formatted;
1399
+ }
1400
+ return formatValue(dayjs(value), format);
1401
+ }
1402
+ function DateTimeInput(props) {
1403
+ const {
1404
+ value,
1405
+ defaultValue = null,
1406
+ onChange,
1407
+ asString,
1408
+ showSeconds = true,
1409
+ format,
1410
+ mode = "datetime",
1411
+ use12Hours = false,
1412
+ open: openProp,
1413
+ defaultOpen = false,
1414
+ onOpenChange,
1415
+ placeholder = "Select date and time",
1416
+ id,
1417
+ name,
1418
+ disabled = false,
1419
+ readOnly = true,
1420
+ className,
1421
+ inputClassName,
1422
+ style,
1423
+ "aria-labelledby": ariaLabelledBy,
1424
+ "aria-label": ariaLabel,
1425
+ ...pickerProps
1426
+ } = props;
1427
+ const resolvedFormat = useMemo(
1428
+ () => resolveFormat({ mode, format, use12Hours, showSeconds }),
1429
+ [mode, format, use12Hours, showSeconds]
1430
+ );
1431
+ const [anchorEl, setAnchorEl] = useState(null);
1432
+ const controlledFormatted = value !== void 0 ? formatValue(parseValue(value, resolvedFormat), resolvedFormat) : void 0;
1433
+ const defaultFormatted = useMemo(
1434
+ () => formatValue(parseValue(defaultValue, resolvedFormat), resolvedFormat),
1435
+ // only seed once from defaultValue
1436
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1437
+ []
1438
+ );
1439
+ const [internalValue, setInternalValue] = useControllableState({
1440
+ value: controlledFormatted,
1441
+ defaultValue: defaultFormatted,
1442
+ onChange: void 0
1443
+ });
1444
+ const [open, setOpen] = useControllableState({
1445
+ value: openProp,
1446
+ defaultValue: defaultOpen,
1447
+ onChange: onOpenChange
1448
+ });
1449
+ const display = internalValue ?? "";
1450
+ const setInputRef = useCallback((node) => {
1451
+ setAnchorEl(node);
1452
+ }, []);
1453
+ return /* @__PURE__ */ jsxs("div", { className: cx3("ctp-input-root", className), style, children: [
1454
+ /* @__PURE__ */ jsx(
1455
+ "input",
1456
+ {
1457
+ ref: setInputRef,
1458
+ id,
1459
+ name,
1460
+ className: cx3("ctp-input", inputClassName),
1461
+ value: display,
1462
+ readOnly,
1463
+ disabled,
1464
+ placeholder,
1465
+ "aria-haspopup": "dialog",
1466
+ "aria-expanded": open,
1467
+ "aria-labelledby": ariaLabelledBy,
1468
+ "aria-label": ariaLabel ?? placeholder,
1469
+ onClick: () => {
1470
+ if (!disabled) {
1471
+ setOpen(true);
1472
+ }
1473
+ },
1474
+ onKeyDown: (event) => {
1475
+ if (disabled) {
1476
+ return;
1477
+ }
1478
+ if (event.key === "Enter" || event.key === " ") {
1479
+ event.preventDefault();
1480
+ setOpen(true);
1481
+ }
1482
+ }
1483
+ }
1484
+ ),
1485
+ /* @__PURE__ */ jsx(
1486
+ DateTime,
1487
+ {
1488
+ ...pickerProps,
1489
+ format,
1490
+ mode,
1491
+ use12Hours,
1492
+ asString,
1493
+ showSeconds,
1494
+ value: internalValue,
1495
+ open,
1496
+ onOpenChange: setOpen,
1497
+ popover: true,
1498
+ anchorEl,
1499
+ onChange: (next) => {
1500
+ setInternalValue(toDisplayString(next, resolvedFormat));
1501
+ onChange?.(next);
1502
+ }
1503
+ }
1504
+ )
1505
+ ] });
1506
+ }
1507
+
1508
+ // src/core/rangeController.ts
1509
+ var RangeController = class {
1510
+ constructor(options = {}) {
1511
+ this.listeners = /* @__PURE__ */ new Set();
1512
+ this.hoverEnd = null;
1513
+ this.calPanel = "day";
1514
+ this.subscribe = (listener) => {
1515
+ this.listeners.add(listener);
1516
+ return () => {
1517
+ this.listeners.delete(listener);
1518
+ };
1519
+ };
1520
+ this.getSnapshot = () => this.snapshot;
1521
+ this.getServerSnapshot = () => this.snapshot;
1522
+ this.options = { ...options };
1523
+ const format = options.format ?? DATE_FORMAT;
1524
+ const parsed = this.parseRange(options.value ?? options.defaultValue, format);
1525
+ this.start = parsed.start;
1526
+ this.end = parsed.end;
1527
+ this.viewMonth = (parsed.start ?? dayjs()).startOf("month");
1528
+ this.focusedDay = parsed.start ?? dayjs();
1529
+ this.open = options.open ?? (options.inline ? true : options.defaultOpen ?? true);
1530
+ this.snapshot = this.buildSnapshot();
1531
+ }
1532
+ parseRange(range, format) {
1533
+ return {
1534
+ start: parseValue(range?.start ?? null, format),
1535
+ end: parseValue(range?.end ?? null, format)
1536
+ };
1537
+ }
1538
+ setOptions(partial) {
1539
+ this.options = { ...this.options, ...partial };
1540
+ if (partial.open !== void 0) {
1541
+ this.open = partial.open;
1542
+ }
1543
+ if ("value" in partial) {
1544
+ if (partial.value === null) {
1545
+ this.start = null;
1546
+ this.end = null;
1547
+ this.hoverEnd = null;
1548
+ } else if (partial.value !== void 0) {
1549
+ const format = this.options.format ?? DATE_FORMAT;
1550
+ const parsed = this.parseRange(partial.value, format);
1551
+ this.start = parsed.start;
1552
+ this.end = parsed.end;
1553
+ if (parsed.start) {
1554
+ this.viewMonth = parsed.start.startOf("month");
1555
+ this.focusedDay = parsed.start;
1556
+ }
1557
+ }
1558
+ }
1559
+ this.emit();
1560
+ }
1561
+ getLabels() {
1562
+ return { ...DEFAULT_LABELS, ...this.options.labels };
1563
+ }
1564
+ emit() {
1565
+ this.snapshot = this.buildSnapshot();
1566
+ this.listeners.forEach((l) => l());
1567
+ }
1568
+ buildSnapshot() {
1569
+ const format = this.options.format ?? DATE_FORMAT;
1570
+ const weekStartsOn = this.options.weekStartsOn ?? 0;
1571
+ const locale = this.options.locale ?? "en";
1572
+ const weeks = buildCalendarMonth({
1573
+ viewMonth: this.viewMonth,
1574
+ rangeStart: this.start,
1575
+ rangeEnd: this.end,
1576
+ hoverEnd: this.start && !this.end ? this.hoverEnd : null,
1577
+ minDate: this.options.minDate,
1578
+ maxDate: this.options.maxDate,
1579
+ disablePastDates: this.options.disablePastDates,
1580
+ disableFutureDates: this.options.disableFutureDates,
1581
+ weekStartsOn
1582
+ });
1583
+ return {
1584
+ start: this.start,
1585
+ end: this.end,
1586
+ hoverEnd: this.hoverEnd,
1587
+ viewMonth: this.viewMonth,
1588
+ focusedDay: this.focusedDay,
1589
+ calPanel: this.calPanel,
1590
+ open: this.open,
1591
+ inline: Boolean(this.options.inline),
1592
+ format,
1593
+ asString: this.options.asString,
1594
+ weekStartsOn,
1595
+ locale,
1596
+ labels: this.getLabels(),
1597
+ className: this.options.className,
1598
+ weeks,
1599
+ weekdayLabels: getWeekdayLabels(locale, weekStartsOn)
1600
+ };
1601
+ }
1602
+ setOpen(open) {
1603
+ if (this.options.inline) {
1604
+ return;
1605
+ }
1606
+ this.open = open;
1607
+ this.options.onOpenChange?.(open);
1608
+ this.emit();
1609
+ }
1610
+ close() {
1611
+ if (!this.options.inline) {
1612
+ this.setOpen(false);
1613
+ }
1614
+ }
1615
+ setCalPanel(panel) {
1616
+ this.calPanel = panel;
1617
+ this.emit();
1618
+ }
1619
+ setViewMonth(next) {
1620
+ this.viewMonth = typeof next === "function" ? next(this.viewMonth) : next;
1621
+ this.emit();
1622
+ }
1623
+ navigatePrev() {
1624
+ if (this.calPanel === "day") {
1625
+ this.viewMonth = this.viewMonth.subtract(1, "month");
1626
+ } else if (this.calPanel === "month") {
1627
+ this.viewMonth = this.viewMonth.subtract(1, "year");
1628
+ } else {
1629
+ this.viewMonth = this.viewMonth.subtract(12, "year");
1630
+ }
1631
+ this.emit();
1632
+ }
1633
+ navigateNext() {
1634
+ if (this.calPanel === "day") {
1635
+ this.viewMonth = this.viewMonth.add(1, "month");
1636
+ } else if (this.calPanel === "month") {
1637
+ this.viewMonth = this.viewMonth.add(1, "year");
1638
+ } else {
1639
+ this.viewMonth = this.viewMonth.add(12, "year");
1640
+ }
1641
+ this.emit();
1642
+ }
1643
+ selectMonth(monthIndex) {
1644
+ this.viewMonth = this.viewMonth.month(monthIndex);
1645
+ this.calPanel = "day";
1646
+ this.emit();
1647
+ }
1648
+ selectYear(year) {
1649
+ this.viewMonth = this.viewMonth.year(year);
1650
+ this.calPanel = "month";
1651
+ this.emit();
1652
+ }
1653
+ emitRange(nextStart, nextEnd) {
1654
+ if (this.options.asString === false) {
1655
+ this.options.onChange?.({
1656
+ start: nextStart ? nextStart.toDate() : null,
1657
+ end: nextEnd ? nextEnd.toDate() : null
1658
+ });
1659
+ } else {
1660
+ if (this.options.asString === void 0) {
1661
+ warnAsStringDeprecation();
1662
+ }
1663
+ const format = this.options.format ?? DATE_FORMAT;
1664
+ this.options.onChange?.({
1665
+ start: formatValue(nextStart, format),
1666
+ end: formatValue(nextEnd, format)
1667
+ });
1668
+ }
1669
+ }
1670
+ pickDay(day) {
1671
+ if (!this.start || this.start && this.end) {
1672
+ this.start = day;
1673
+ this.end = null;
1674
+ this.hoverEnd = null;
1675
+ this.focusedDay = day;
1676
+ } else if (day.isBefore(this.start, "day")) {
1677
+ this.start = day;
1678
+ this.end = null;
1679
+ this.hoverEnd = null;
1680
+ this.focusedDay = day;
1681
+ } else {
1682
+ this.end = day;
1683
+ this.hoverEnd = null;
1684
+ this.focusedDay = day;
1685
+ }
1686
+ this.emit();
1687
+ }
1688
+ setHoverEnd(day) {
1689
+ if (this.start && !this.end) {
1690
+ this.hoverEnd = day;
1691
+ this.emit();
1692
+ }
1693
+ }
1694
+ handleGridKeyDown(key) {
1695
+ const snap = this.snapshot;
1696
+ let next = this.focusedDay;
1697
+ switch (key) {
1698
+ case "ArrowLeft":
1699
+ next = this.focusedDay.subtract(1, "day");
1700
+ break;
1701
+ case "ArrowRight":
1702
+ next = this.focusedDay.add(1, "day");
1703
+ break;
1704
+ case "ArrowUp":
1705
+ next = this.focusedDay.subtract(7, "day");
1706
+ break;
1707
+ case "ArrowDown":
1708
+ next = this.focusedDay.add(7, "day");
1709
+ break;
1710
+ case "Home":
1711
+ next = startOfWeek(this.focusedDay, snap.weekStartsOn);
1712
+ break;
1713
+ case "End":
1714
+ next = endOfWeek(this.focusedDay, snap.weekStartsOn);
1715
+ break;
1716
+ case "PageUp":
1717
+ next = this.focusedDay.subtract(1, "month");
1718
+ this.viewMonth = next.startOf("month");
1719
+ break;
1720
+ case "PageDown":
1721
+ next = this.focusedDay.add(1, "month");
1722
+ this.viewMonth = next.startOf("month");
1723
+ break;
1724
+ case "Enter":
1725
+ case " ": {
1726
+ const cell = snap.weeks.flat().find((d) => d.date.isSame(this.focusedDay, "day"));
1727
+ if (cell && !cell.isDisabled && cell.isCurrentMonth) {
1728
+ this.pickDay(cell.date);
1729
+ }
1730
+ return true;
1731
+ }
1732
+ default:
1733
+ return false;
1734
+ }
1735
+ this.focusedDay = next;
1736
+ if (!next.isSame(this.viewMonth, "month")) {
1737
+ this.viewMonth = next.startOf("month");
1738
+ }
1739
+ this.emit();
1740
+ return true;
1741
+ }
1742
+ confirm() {
1743
+ if (!this.start || !this.end) {
1744
+ return null;
1745
+ }
1746
+ this.emitRange(this.start, this.end);
1747
+ this.close();
1748
+ return {
1749
+ start: this.start.toDate(),
1750
+ end: this.end.toDate()
1751
+ };
1752
+ }
1753
+ clear() {
1754
+ this.start = null;
1755
+ this.end = null;
1756
+ this.hoverEnd = null;
1757
+ this.emitRange(null, null);
1758
+ this.emit();
1759
+ this.close();
1760
+ }
1761
+ };
1762
+ function cx4(...parts) {
1763
+ return parts.filter(Boolean).join(" ");
1764
+ }
1765
+ function DateTimeRange(props) {
1766
+ const {
1767
+ value,
1768
+ defaultValue = null,
1769
+ onChange,
1770
+ asString,
1771
+ format,
1772
+ minDate,
1773
+ maxDate,
1774
+ disablePastDates = false,
1775
+ disableFutureDates = false,
1776
+ weekStartsOn = 0,
1777
+ locale = "en",
1778
+ labels: labelsProp,
1779
+ inline = false,
1780
+ className,
1781
+ style,
1782
+ open: openProp,
1783
+ defaultOpen = true,
1784
+ onOpenChange
1785
+ } = props;
1786
+ const titleId = useId();
1787
+ const dialogRef = useRef(null);
1788
+ const [open, setOpen] = useControllableState({
1789
+ value: openProp,
1790
+ defaultValue: inline ? true : defaultOpen,
1791
+ onChange: onOpenChange
1792
+ });
1793
+ const controllerRef = useRef(null);
1794
+ if (!controllerRef.current) {
1795
+ controllerRef.current = new RangeController({
1796
+ value,
1797
+ defaultValue,
1798
+ onChange,
1799
+ asString,
1800
+ format,
1801
+ minDate,
1802
+ maxDate,
1803
+ disablePastDates,
1804
+ disableFutureDates,
1805
+ weekStartsOn,
1806
+ locale,
1807
+ labels: labelsProp,
1808
+ inline,
1809
+ className,
1810
+ open,
1811
+ onOpenChange: setOpen
1812
+ });
1813
+ }
1814
+ const controller = controllerRef.current;
1815
+ useEffect(() => {
1816
+ controller.setOptions({
1817
+ value,
1818
+ onChange,
1819
+ asString,
1820
+ format,
1821
+ minDate,
1822
+ maxDate,
1823
+ disablePastDates,
1824
+ disableFutureDates,
1825
+ weekStartsOn,
1826
+ locale,
1827
+ labels: labelsProp,
1828
+ inline,
1829
+ className,
1830
+ open,
1831
+ onOpenChange: setOpen
1832
+ });
1833
+ }, [
1834
+ controller,
1835
+ value,
1836
+ onChange,
1837
+ asString,
1838
+ format,
1839
+ minDate,
1840
+ maxDate,
1841
+ disablePastDates,
1842
+ disableFutureDates,
1843
+ weekStartsOn,
1844
+ locale,
1845
+ labelsProp,
1846
+ inline,
1847
+ className,
1848
+ open,
1849
+ setOpen
1850
+ ]);
1851
+ const snap = useSyncExternalStore(
1852
+ controller.subscribe,
1853
+ controller.getSnapshot,
1854
+ controller.getServerSnapshot
1855
+ );
1856
+ const close = useCallback(() => {
1857
+ if (!inline) {
1858
+ setOpen(false);
1859
+ }
1860
+ }, [inline, setOpen]);
1861
+ useEffect(() => {
1862
+ if (!(open && !inline)) {
1863
+ return;
1864
+ }
1865
+ return attachEscape(close);
1866
+ }, [open, inline, close]);
1867
+ useEffect(() => {
1868
+ if (!(open && !inline) || !dialogRef.current) {
1869
+ return;
1870
+ }
1871
+ return attachFocusTrap(dialogRef.current);
1872
+ }, [open, inline]);
1873
+ const onGridKeyDown = (event) => {
1874
+ if (controller.handleGridKeyDown(event.key)) {
1875
+ event.preventDefault();
1876
+ }
1877
+ };
1878
+ if (!open && !inline) {
1879
+ return null;
1880
+ }
1881
+ const statusText = snap.start && !snap.end ? snap.labels.selectEnd : `${snap.start ? formatLocalized(snap.start, "MMM D, YYYY", snap.locale) : snap.labels.start} \u2014 ${snap.end ? formatLocalized(snap.end, "MMM D, YYYY", snap.locale) : snap.labels.end}`;
1882
+ const picker = /* @__PURE__ */ jsxs(
1883
+ "div",
1884
+ {
1885
+ ref: dialogRef,
1886
+ className: cx4("ctp-calendar-time-picker", className),
1887
+ style,
1888
+ role: inline ? void 0 : "dialog",
1889
+ "aria-modal": inline ? void 0 : true,
1890
+ "aria-labelledby": titleId,
1891
+ children: [
1892
+ /* @__PURE__ */ jsx("div", { className: "ctp-header", children: /* @__PURE__ */ jsx("span", { id: titleId, className: "ctp-range-title", children: statusText }) }),
1893
+ /* @__PURE__ */ jsxs("div", { className: "ctp-body ctp-body-calendar-date", children: [
1894
+ /* @__PURE__ */ jsx(
1895
+ CalendarHeader,
1896
+ {
1897
+ viewMonth: snap.viewMonth,
1898
+ setViewMonth: (next) => controller.setViewMonth(next),
1899
+ panel: snap.calPanel,
1900
+ onPanelChange: (p) => controller.setCalPanel(p),
1901
+ locale: snap.locale,
1902
+ labels: snap.labels
1903
+ }
1904
+ ),
1905
+ snap.calPanel === "day" && /* @__PURE__ */ jsxs(
1906
+ "div",
1907
+ {
1908
+ className: "ctp-main-calendar",
1909
+ role: "grid",
1910
+ "aria-label": snap.labels.chooseDateRange,
1911
+ tabIndex: 0,
1912
+ onKeyDown: onGridKeyDown,
1913
+ children: [
1914
+ snap.weekdayLabels.map((label) => /* @__PURE__ */ jsx(
1915
+ "div",
1916
+ {
1917
+ className: "ctp-box ctp-box-days",
1918
+ role: "columnheader",
1919
+ children: label
1920
+ },
1921
+ label
1922
+ )),
1923
+ snap.weeks.map(
1924
+ (week) => week.map((dayData) => {
1925
+ const focused = dayData.date.isSame(snap.focusedDay, "day");
1926
+ const disabled = !dayData.isCurrentMonth || dayData.isDisabled;
1927
+ return /* @__PURE__ */ jsx(
1928
+ "button",
1929
+ {
1930
+ type: "button",
1931
+ role: "gridcell",
1932
+ tabIndex: focused ? 0 : -1,
1933
+ "aria-selected": Boolean(
1934
+ dayData.isRangeStart || dayData.isRangeEnd
1935
+ ),
1936
+ "aria-disabled": disabled,
1937
+ disabled,
1938
+ "aria-label": formatLocalized(
1939
+ dayData.date,
1940
+ "dddd, MMMM D, YYYY",
1941
+ snap.locale
1942
+ ),
1943
+ className: cx4(
1944
+ "ctp-box",
1945
+ "ctp-box-date",
1946
+ !dayData.isCurrentMonth && "not-current-month",
1947
+ dayData.isDisabled && "disabled-date",
1948
+ dayData.isWeekend && "weekend-day",
1949
+ dayData.isCurrentDate && "ctp-today",
1950
+ dayData.isInRange && "ctp-in-range",
1951
+ dayData.isRangeStart && "ctp-range-start",
1952
+ dayData.isRangeEnd && "ctp-range-end"
1953
+ ),
1954
+ onClick: () => {
1955
+ if (!disabled) {
1956
+ controller.pickDay(dayData.date);
1957
+ }
1958
+ },
1959
+ onMouseEnter: () => {
1960
+ if (!disabled && snap.start && !snap.end) {
1961
+ controller.setHoverEnd(dayData.date);
1962
+ }
1963
+ },
1964
+ children: dayData.date.format("D")
1965
+ },
1966
+ dayData.date.format("YYYY-MM-DD")
1967
+ );
1968
+ })
1969
+ )
1970
+ ]
1971
+ }
1972
+ )
1973
+ ] }),
1974
+ /* @__PURE__ */ jsxs("div", { className: "ctp-footer", children: [
1975
+ /* @__PURE__ */ jsx(
1976
+ "button",
1977
+ {
1978
+ type: "button",
1979
+ className: "close-button",
1980
+ onClick: () => {
1981
+ controller.clear();
1982
+ close();
1983
+ },
1984
+ children: snap.labels.clear
1985
+ }
1986
+ ),
1987
+ !inline && /* @__PURE__ */ jsx("button", { type: "button", className: "ctp-cancel", onClick: close, children: snap.labels.close }),
1988
+ /* @__PURE__ */ jsx(
1989
+ "button",
1990
+ {
1991
+ type: "button",
1992
+ onClick: () => {
1993
+ controller.confirm();
1994
+ close();
1995
+ },
1996
+ disabled: !snap.start || !snap.end,
1997
+ children: snap.labels.ok
1998
+ }
1999
+ )
2000
+ ] })
2001
+ ]
2002
+ }
2003
+ );
2004
+ if (inline) {
2005
+ return picker;
2006
+ }
2007
+ return createPortal(
2008
+ /* @__PURE__ */ jsx(
2009
+ "div",
2010
+ {
2011
+ className: "ctp-calendar-time-picker-absolute-container",
2012
+ onClick: (event) => {
2013
+ if (event.target === event.currentTarget) {
2014
+ close();
2015
+ }
2016
+ },
2017
+ children: picker
2018
+ }
2019
+ ),
2020
+ document.body
2021
+ );
2022
+ }
2023
+
2024
+ // src/index.ts
2025
+ var DateTimeWithExtras = DateTime;
2026
+ DateTimeWithExtras.Input = DateTimeInput;
2027
+ DateTimeWithExtras.Range = DateTimeRange;
2028
+ var src_default = DateTimeWithExtras;
2029
+
2030
+ export { DATE_FORMAT, DEFAULT_FORMAT, DEFAULT_LABELS, DateTime, DateTimeInput, DateTimeRange, TIME_FORMAT, buildCalendarMonth, src_default as default };