universal-datetime-picker 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/angular/index.d.mts +2 -2
- package/dist/angular/index.d.ts +2 -2
- package/dist/angular/index.js +159 -72
- package/dist/angular/index.mjs +159 -72
- package/dist/cdn/universal-datetime-picker.iife.js +1 -1
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +49 -16
- package/dist/core/index.mjs +49 -16
- package/dist/index.js +69 -29
- package/dist/index.mjs +69 -29
- package/dist/{rangeController-Bq35aBwe.d.mts → rangeController-BBZcdM0Z.d.mts} +3 -0
- package/dist/{rangeController-Bq35aBwe.d.ts → rangeController-BBZcdM0Z.d.ts} +3 -0
- package/dist/{rangeRenderer-AVv6PJbW.d.mts → rangeRenderer-CE99Ji3Q.d.mts} +1 -1
- package/dist/{rangeRenderer-a3hFk-kK.d.ts → rangeRenderer-CeLuwT6V.d.ts} +1 -1
- package/dist/svelte/index.d.mts +2 -2
- package/dist/svelte/index.d.ts +2 -2
- package/dist/svelte/index.js +159 -72
- package/dist/svelte/index.mjs +159 -72
- package/dist/vanilla/index.d.mts +2 -2
- package/dist/vanilla/index.d.ts +2 -2
- package/dist/vanilla/index.js +159 -72
- package/dist/vanilla/index.mjs +159 -72
- package/dist/vue/index.d.mts +2 -2
- package/dist/vue/index.d.ts +2 -2
- package/dist/vue/index.js +159 -72
- package/dist/vue/index.mjs +159 -72
- package/dist/wc/index.d.mts +2 -2
- package/dist/wc/index.d.ts +2 -2
- package/dist/wc/index.js +160 -73
- package/dist/wc/index.mjs +160 -73
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -568,23 +568,28 @@ var PickerController = class {
|
|
|
568
568
|
this.draft = this.draft.year(day.year()).month(day.month()).date(day.date());
|
|
569
569
|
this.focusedDay = day;
|
|
570
570
|
this.emit();
|
|
571
|
+
this.maybeCommitInline();
|
|
571
572
|
}
|
|
572
573
|
setHour(hourValue) {
|
|
573
574
|
this.draft = this.draft.hour(hourValue);
|
|
574
575
|
this.emit();
|
|
576
|
+
this.maybeCommitInline();
|
|
575
577
|
}
|
|
576
578
|
setMinute(minute) {
|
|
577
579
|
this.draft = this.draft.minute(minute);
|
|
578
580
|
this.emit();
|
|
581
|
+
this.maybeCommitInline();
|
|
579
582
|
}
|
|
580
583
|
setSecond(second) {
|
|
581
584
|
this.draft = this.draft.second(second);
|
|
582
585
|
this.emit();
|
|
586
|
+
this.maybeCommitInline();
|
|
583
587
|
}
|
|
584
588
|
setAmPm(isAm) {
|
|
585
589
|
const { hour } = to12Hour(this.draft.hour());
|
|
586
590
|
this.draft = this.draft.hour(to24Hour(hour, isAm));
|
|
587
591
|
this.emit();
|
|
592
|
+
this.maybeCommitInline();
|
|
588
593
|
}
|
|
589
594
|
toggleHours() {
|
|
590
595
|
this.showHours = !this.showHours;
|
|
@@ -630,22 +635,26 @@ var PickerController = class {
|
|
|
630
635
|
}
|
|
631
636
|
this.showHours = false;
|
|
632
637
|
this.emit();
|
|
638
|
+
this.maybeCommitInline();
|
|
633
639
|
}
|
|
634
640
|
selectMinuteOption(opt) {
|
|
635
641
|
this.draft = this.draft.minute(Number(opt));
|
|
636
642
|
this.showMinutes = false;
|
|
637
643
|
this.emit();
|
|
644
|
+
this.maybeCommitInline();
|
|
638
645
|
}
|
|
639
646
|
selectSecondOption(opt) {
|
|
640
647
|
this.draft = this.draft.second(Number(opt));
|
|
641
648
|
this.showSecondsOpen = false;
|
|
642
649
|
this.emit();
|
|
650
|
+
this.maybeCommitInline();
|
|
643
651
|
}
|
|
644
652
|
selectAmPmOption(opt) {
|
|
645
653
|
const { hour } = to12Hour(this.draft.hour());
|
|
646
654
|
this.draft = this.draft.hour(to24Hour(hour, opt === "AM"));
|
|
647
655
|
this.showAmPm = false;
|
|
648
656
|
this.emit();
|
|
657
|
+
this.maybeCommitInline();
|
|
649
658
|
}
|
|
650
659
|
handleGridKeyDown(key) {
|
|
651
660
|
const snap = this.snapshot;
|
|
@@ -695,23 +704,30 @@ var PickerController = class {
|
|
|
695
704
|
this.emit();
|
|
696
705
|
return true;
|
|
697
706
|
}
|
|
698
|
-
|
|
707
|
+
buildPayload() {
|
|
699
708
|
const snap = this.snapshot;
|
|
700
|
-
let payload;
|
|
701
709
|
if (snap.asString === false) {
|
|
702
710
|
if (snap.mode === "time") {
|
|
703
|
-
|
|
704
|
-
} else if (snap.mode === "date") {
|
|
705
|
-
payload = this.draft.startOf("day").toDate();
|
|
706
|
-
} else {
|
|
707
|
-
payload = this.draft.toDate();
|
|
711
|
+
return buildTimeValue(this.draft, snap.resolvedFormat);
|
|
708
712
|
}
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
warnAsStringDeprecation();
|
|
713
|
+
if (snap.mode === "date") {
|
|
714
|
+
return this.draft.startOf("day").toDate();
|
|
712
715
|
}
|
|
713
|
-
|
|
716
|
+
return this.draft.toDate();
|
|
717
|
+
}
|
|
718
|
+
if (snap.asString === void 0) {
|
|
719
|
+
warnAsStringDeprecation();
|
|
720
|
+
}
|
|
721
|
+
return formatValue(this.draft, snap.resolvedFormat);
|
|
722
|
+
}
|
|
723
|
+
maybeCommitInline() {
|
|
724
|
+
if (!this.options.inline) {
|
|
725
|
+
return;
|
|
714
726
|
}
|
|
727
|
+
this.options.onChange?.(this.buildPayload());
|
|
728
|
+
}
|
|
729
|
+
confirm() {
|
|
730
|
+
const payload = this.buildPayload();
|
|
715
731
|
this.options.onChange?.(payload);
|
|
716
732
|
this.close();
|
|
717
733
|
return payload;
|
|
@@ -885,6 +901,11 @@ function useControllableState(options) {
|
|
|
885
901
|
);
|
|
886
902
|
return [state, setState];
|
|
887
903
|
}
|
|
904
|
+
function useLatest(value) {
|
|
905
|
+
const ref = react.useRef(value);
|
|
906
|
+
ref.current = value;
|
|
907
|
+
return ref;
|
|
908
|
+
}
|
|
888
909
|
function cx2(...parts) {
|
|
889
910
|
return parts.filter(Boolean).join(" ");
|
|
890
911
|
}
|
|
@@ -990,10 +1011,12 @@ function DateTime(props) {
|
|
|
990
1011
|
});
|
|
991
1012
|
}
|
|
992
1013
|
const controller = controllerRef.current;
|
|
1014
|
+
const onChangeRef = useLatest(onChange);
|
|
1015
|
+
const setOpenRef = useLatest(setOpen);
|
|
993
1016
|
react.useEffect(() => {
|
|
994
1017
|
controller.setOptions({
|
|
995
1018
|
value,
|
|
996
|
-
onChange,
|
|
1019
|
+
onChange: (next) => onChangeRef.current?.(next),
|
|
997
1020
|
asString,
|
|
998
1021
|
showSeconds,
|
|
999
1022
|
format,
|
|
@@ -1013,12 +1036,11 @@ function DateTime(props) {
|
|
|
1013
1036
|
open,
|
|
1014
1037
|
popover,
|
|
1015
1038
|
anchorEl,
|
|
1016
|
-
onOpenChange:
|
|
1039
|
+
onOpenChange: (next) => setOpenRef.current(next)
|
|
1017
1040
|
});
|
|
1018
1041
|
}, [
|
|
1019
1042
|
controller,
|
|
1020
1043
|
value,
|
|
1021
|
-
onChange,
|
|
1022
1044
|
asString,
|
|
1023
1045
|
showSeconds,
|
|
1024
1046
|
format,
|
|
@@ -1037,8 +1059,7 @@ function DateTime(props) {
|
|
|
1037
1059
|
theme,
|
|
1038
1060
|
open,
|
|
1039
1061
|
popover,
|
|
1040
|
-
anchorEl
|
|
1041
|
-
setOpen
|
|
1062
|
+
anchorEl
|
|
1042
1063
|
]);
|
|
1043
1064
|
const snap = react.useSyncExternalStore(
|
|
1044
1065
|
controller.subscribe,
|
|
@@ -1304,7 +1325,7 @@ function DateTime(props) {
|
|
|
1304
1325
|
}
|
|
1305
1326
|
),
|
|
1306
1327
|
!inline && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "ctp-cancel", onClick: close, children: snap.labels.close }),
|
|
1307
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
1328
|
+
!inline && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1308
1329
|
"button",
|
|
1309
1330
|
{
|
|
1310
1331
|
type: "button",
|
|
@@ -1459,6 +1480,7 @@ function DateTimeInput(props) {
|
|
|
1459
1480
|
onChange: onOpenChange
|
|
1460
1481
|
});
|
|
1461
1482
|
const display = internalValue ?? "";
|
|
1483
|
+
const pickerValue = asString === false ? value !== void 0 ? value : defaultValue : internalValue;
|
|
1462
1484
|
const setInputRef = react.useCallback((node) => {
|
|
1463
1485
|
setAnchorEl(node);
|
|
1464
1486
|
}, []);
|
|
@@ -1503,7 +1525,7 @@ function DateTimeInput(props) {
|
|
|
1503
1525
|
use12Hours,
|
|
1504
1526
|
asString,
|
|
1505
1527
|
showSeconds,
|
|
1506
|
-
value:
|
|
1528
|
+
value: pickerValue,
|
|
1507
1529
|
open,
|
|
1508
1530
|
onOpenChange: setOpen,
|
|
1509
1531
|
popover: true,
|
|
@@ -1547,6 +1569,15 @@ var RangeController = class {
|
|
|
1547
1569
|
end: parseValue(range?.end ?? null, format)
|
|
1548
1570
|
};
|
|
1549
1571
|
}
|
|
1572
|
+
sameDay(a, b) {
|
|
1573
|
+
if (a === null && b === null) {
|
|
1574
|
+
return true;
|
|
1575
|
+
}
|
|
1576
|
+
if (a === null || b === null) {
|
|
1577
|
+
return false;
|
|
1578
|
+
}
|
|
1579
|
+
return a.isSame(b, "day");
|
|
1580
|
+
}
|
|
1550
1581
|
setOptions(partial) {
|
|
1551
1582
|
this.options = { ...this.options, ...partial };
|
|
1552
1583
|
if (partial.open !== void 0) {
|
|
@@ -1560,11 +1591,14 @@ var RangeController = class {
|
|
|
1560
1591
|
} else if (partial.value !== void 0) {
|
|
1561
1592
|
const format = this.options.format ?? DATE_FORMAT;
|
|
1562
1593
|
const parsed = this.parseRange(partial.value, format);
|
|
1563
|
-
this.start
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
this.
|
|
1567
|
-
|
|
1594
|
+
const unchanged = this.sameDay(parsed.start, this.start) && this.sameDay(parsed.end, this.end);
|
|
1595
|
+
if (!unchanged) {
|
|
1596
|
+
this.start = parsed.start;
|
|
1597
|
+
this.end = parsed.end;
|
|
1598
|
+
if (parsed.start) {
|
|
1599
|
+
this.viewMonth = parsed.start.startOf("month");
|
|
1600
|
+
this.focusedDay = parsed.start;
|
|
1601
|
+
}
|
|
1568
1602
|
}
|
|
1569
1603
|
}
|
|
1570
1604
|
}
|
|
@@ -1696,6 +1730,11 @@ var RangeController = class {
|
|
|
1696
1730
|
this.focusedDay = day;
|
|
1697
1731
|
}
|
|
1698
1732
|
this.emit();
|
|
1733
|
+
if (this.options.asString === false) {
|
|
1734
|
+
this.emitRange(this.start, this.end);
|
|
1735
|
+
} else if (this.options.inline && this.start && this.end) {
|
|
1736
|
+
this.emitRange(this.start, this.end);
|
|
1737
|
+
}
|
|
1699
1738
|
}
|
|
1700
1739
|
setHoverEnd(day) {
|
|
1701
1740
|
if (this.start && !this.end) {
|
|
@@ -1824,10 +1863,12 @@ function DateTimeRange(props) {
|
|
|
1824
1863
|
});
|
|
1825
1864
|
}
|
|
1826
1865
|
const controller = controllerRef.current;
|
|
1866
|
+
const onChangeRef = useLatest(onChange);
|
|
1867
|
+
const setOpenRef = useLatest(setOpen);
|
|
1827
1868
|
react.useEffect(() => {
|
|
1828
1869
|
controller.setOptions({
|
|
1829
1870
|
value,
|
|
1830
|
-
onChange,
|
|
1871
|
+
onChange: (next) => onChangeRef.current?.(next),
|
|
1831
1872
|
asString,
|
|
1832
1873
|
format,
|
|
1833
1874
|
minDate,
|
|
@@ -1840,12 +1881,11 @@ function DateTimeRange(props) {
|
|
|
1840
1881
|
inline,
|
|
1841
1882
|
className,
|
|
1842
1883
|
open,
|
|
1843
|
-
onOpenChange:
|
|
1884
|
+
onOpenChange: (next) => setOpenRef.current(next)
|
|
1844
1885
|
});
|
|
1845
1886
|
}, [
|
|
1846
1887
|
controller,
|
|
1847
1888
|
value,
|
|
1848
|
-
onChange,
|
|
1849
1889
|
asString,
|
|
1850
1890
|
format,
|
|
1851
1891
|
minDate,
|
|
@@ -1857,8 +1897,7 @@ function DateTimeRange(props) {
|
|
|
1857
1897
|
labelsProp,
|
|
1858
1898
|
inline,
|
|
1859
1899
|
className,
|
|
1860
|
-
open
|
|
1861
|
-
setOpen
|
|
1900
|
+
open
|
|
1862
1901
|
]);
|
|
1863
1902
|
const snap = react.useSyncExternalStore(
|
|
1864
1903
|
controller.subscribe,
|
|
@@ -1922,6 +1961,7 @@ function DateTimeRange(props) {
|
|
|
1922
1961
|
"aria-label": snap.labels.chooseDateRange,
|
|
1923
1962
|
tabIndex: 0,
|
|
1924
1963
|
onKeyDown: onGridKeyDown,
|
|
1964
|
+
onMouseLeave: () => controller.setHoverEnd(null),
|
|
1925
1965
|
children: [
|
|
1926
1966
|
snap.weekdayLabels.map((label) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1927
1967
|
"div",
|
|
@@ -1997,7 +2037,7 @@ function DateTimeRange(props) {
|
|
|
1997
2037
|
}
|
|
1998
2038
|
),
|
|
1999
2039
|
!inline && /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", className: "ctp-cancel", onClick: close, children: snap.labels.close }),
|
|
2000
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2040
|
+
!inline && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2001
2041
|
"button",
|
|
2002
2042
|
{
|
|
2003
2043
|
type: "button",
|
package/dist/index.mjs
CHANGED
|
@@ -556,23 +556,28 @@ var PickerController = class {
|
|
|
556
556
|
this.draft = this.draft.year(day.year()).month(day.month()).date(day.date());
|
|
557
557
|
this.focusedDay = day;
|
|
558
558
|
this.emit();
|
|
559
|
+
this.maybeCommitInline();
|
|
559
560
|
}
|
|
560
561
|
setHour(hourValue) {
|
|
561
562
|
this.draft = this.draft.hour(hourValue);
|
|
562
563
|
this.emit();
|
|
564
|
+
this.maybeCommitInline();
|
|
563
565
|
}
|
|
564
566
|
setMinute(minute) {
|
|
565
567
|
this.draft = this.draft.minute(minute);
|
|
566
568
|
this.emit();
|
|
569
|
+
this.maybeCommitInline();
|
|
567
570
|
}
|
|
568
571
|
setSecond(second) {
|
|
569
572
|
this.draft = this.draft.second(second);
|
|
570
573
|
this.emit();
|
|
574
|
+
this.maybeCommitInline();
|
|
571
575
|
}
|
|
572
576
|
setAmPm(isAm) {
|
|
573
577
|
const { hour } = to12Hour(this.draft.hour());
|
|
574
578
|
this.draft = this.draft.hour(to24Hour(hour, isAm));
|
|
575
579
|
this.emit();
|
|
580
|
+
this.maybeCommitInline();
|
|
576
581
|
}
|
|
577
582
|
toggleHours() {
|
|
578
583
|
this.showHours = !this.showHours;
|
|
@@ -618,22 +623,26 @@ var PickerController = class {
|
|
|
618
623
|
}
|
|
619
624
|
this.showHours = false;
|
|
620
625
|
this.emit();
|
|
626
|
+
this.maybeCommitInline();
|
|
621
627
|
}
|
|
622
628
|
selectMinuteOption(opt) {
|
|
623
629
|
this.draft = this.draft.minute(Number(opt));
|
|
624
630
|
this.showMinutes = false;
|
|
625
631
|
this.emit();
|
|
632
|
+
this.maybeCommitInline();
|
|
626
633
|
}
|
|
627
634
|
selectSecondOption(opt) {
|
|
628
635
|
this.draft = this.draft.second(Number(opt));
|
|
629
636
|
this.showSecondsOpen = false;
|
|
630
637
|
this.emit();
|
|
638
|
+
this.maybeCommitInline();
|
|
631
639
|
}
|
|
632
640
|
selectAmPmOption(opt) {
|
|
633
641
|
const { hour } = to12Hour(this.draft.hour());
|
|
634
642
|
this.draft = this.draft.hour(to24Hour(hour, opt === "AM"));
|
|
635
643
|
this.showAmPm = false;
|
|
636
644
|
this.emit();
|
|
645
|
+
this.maybeCommitInline();
|
|
637
646
|
}
|
|
638
647
|
handleGridKeyDown(key) {
|
|
639
648
|
const snap = this.snapshot;
|
|
@@ -683,23 +692,30 @@ var PickerController = class {
|
|
|
683
692
|
this.emit();
|
|
684
693
|
return true;
|
|
685
694
|
}
|
|
686
|
-
|
|
695
|
+
buildPayload() {
|
|
687
696
|
const snap = this.snapshot;
|
|
688
|
-
let payload;
|
|
689
697
|
if (snap.asString === false) {
|
|
690
698
|
if (snap.mode === "time") {
|
|
691
|
-
|
|
692
|
-
} else if (snap.mode === "date") {
|
|
693
|
-
payload = this.draft.startOf("day").toDate();
|
|
694
|
-
} else {
|
|
695
|
-
payload = this.draft.toDate();
|
|
699
|
+
return buildTimeValue(this.draft, snap.resolvedFormat);
|
|
696
700
|
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
warnAsStringDeprecation();
|
|
701
|
+
if (snap.mode === "date") {
|
|
702
|
+
return this.draft.startOf("day").toDate();
|
|
700
703
|
}
|
|
701
|
-
|
|
704
|
+
return this.draft.toDate();
|
|
705
|
+
}
|
|
706
|
+
if (snap.asString === void 0) {
|
|
707
|
+
warnAsStringDeprecation();
|
|
708
|
+
}
|
|
709
|
+
return formatValue(this.draft, snap.resolvedFormat);
|
|
710
|
+
}
|
|
711
|
+
maybeCommitInline() {
|
|
712
|
+
if (!this.options.inline) {
|
|
713
|
+
return;
|
|
702
714
|
}
|
|
715
|
+
this.options.onChange?.(this.buildPayload());
|
|
716
|
+
}
|
|
717
|
+
confirm() {
|
|
718
|
+
const payload = this.buildPayload();
|
|
703
719
|
this.options.onChange?.(payload);
|
|
704
720
|
this.close();
|
|
705
721
|
return payload;
|
|
@@ -873,6 +889,11 @@ function useControllableState(options) {
|
|
|
873
889
|
);
|
|
874
890
|
return [state, setState];
|
|
875
891
|
}
|
|
892
|
+
function useLatest(value) {
|
|
893
|
+
const ref = useRef(value);
|
|
894
|
+
ref.current = value;
|
|
895
|
+
return ref;
|
|
896
|
+
}
|
|
876
897
|
function cx2(...parts) {
|
|
877
898
|
return parts.filter(Boolean).join(" ");
|
|
878
899
|
}
|
|
@@ -978,10 +999,12 @@ function DateTime(props) {
|
|
|
978
999
|
});
|
|
979
1000
|
}
|
|
980
1001
|
const controller = controllerRef.current;
|
|
1002
|
+
const onChangeRef = useLatest(onChange);
|
|
1003
|
+
const setOpenRef = useLatest(setOpen);
|
|
981
1004
|
useEffect(() => {
|
|
982
1005
|
controller.setOptions({
|
|
983
1006
|
value,
|
|
984
|
-
onChange,
|
|
1007
|
+
onChange: (next) => onChangeRef.current?.(next),
|
|
985
1008
|
asString,
|
|
986
1009
|
showSeconds,
|
|
987
1010
|
format,
|
|
@@ -1001,12 +1024,11 @@ function DateTime(props) {
|
|
|
1001
1024
|
open,
|
|
1002
1025
|
popover,
|
|
1003
1026
|
anchorEl,
|
|
1004
|
-
onOpenChange:
|
|
1027
|
+
onOpenChange: (next) => setOpenRef.current(next)
|
|
1005
1028
|
});
|
|
1006
1029
|
}, [
|
|
1007
1030
|
controller,
|
|
1008
1031
|
value,
|
|
1009
|
-
onChange,
|
|
1010
1032
|
asString,
|
|
1011
1033
|
showSeconds,
|
|
1012
1034
|
format,
|
|
@@ -1025,8 +1047,7 @@ function DateTime(props) {
|
|
|
1025
1047
|
theme,
|
|
1026
1048
|
open,
|
|
1027
1049
|
popover,
|
|
1028
|
-
anchorEl
|
|
1029
|
-
setOpen
|
|
1050
|
+
anchorEl
|
|
1030
1051
|
]);
|
|
1031
1052
|
const snap = useSyncExternalStore(
|
|
1032
1053
|
controller.subscribe,
|
|
@@ -1292,7 +1313,7 @@ function DateTime(props) {
|
|
|
1292
1313
|
}
|
|
1293
1314
|
),
|
|
1294
1315
|
!inline && /* @__PURE__ */ jsx("button", { type: "button", className: "ctp-cancel", onClick: close, children: snap.labels.close }),
|
|
1295
|
-
/* @__PURE__ */ jsx(
|
|
1316
|
+
!inline && /* @__PURE__ */ jsx(
|
|
1296
1317
|
"button",
|
|
1297
1318
|
{
|
|
1298
1319
|
type: "button",
|
|
@@ -1447,6 +1468,7 @@ function DateTimeInput(props) {
|
|
|
1447
1468
|
onChange: onOpenChange
|
|
1448
1469
|
});
|
|
1449
1470
|
const display = internalValue ?? "";
|
|
1471
|
+
const pickerValue = asString === false ? value !== void 0 ? value : defaultValue : internalValue;
|
|
1450
1472
|
const setInputRef = useCallback((node) => {
|
|
1451
1473
|
setAnchorEl(node);
|
|
1452
1474
|
}, []);
|
|
@@ -1491,7 +1513,7 @@ function DateTimeInput(props) {
|
|
|
1491
1513
|
use12Hours,
|
|
1492
1514
|
asString,
|
|
1493
1515
|
showSeconds,
|
|
1494
|
-
value:
|
|
1516
|
+
value: pickerValue,
|
|
1495
1517
|
open,
|
|
1496
1518
|
onOpenChange: setOpen,
|
|
1497
1519
|
popover: true,
|
|
@@ -1535,6 +1557,15 @@ var RangeController = class {
|
|
|
1535
1557
|
end: parseValue(range?.end ?? null, format)
|
|
1536
1558
|
};
|
|
1537
1559
|
}
|
|
1560
|
+
sameDay(a, b) {
|
|
1561
|
+
if (a === null && b === null) {
|
|
1562
|
+
return true;
|
|
1563
|
+
}
|
|
1564
|
+
if (a === null || b === null) {
|
|
1565
|
+
return false;
|
|
1566
|
+
}
|
|
1567
|
+
return a.isSame(b, "day");
|
|
1568
|
+
}
|
|
1538
1569
|
setOptions(partial) {
|
|
1539
1570
|
this.options = { ...this.options, ...partial };
|
|
1540
1571
|
if (partial.open !== void 0) {
|
|
@@ -1548,11 +1579,14 @@ var RangeController = class {
|
|
|
1548
1579
|
} else if (partial.value !== void 0) {
|
|
1549
1580
|
const format = this.options.format ?? DATE_FORMAT;
|
|
1550
1581
|
const parsed = this.parseRange(partial.value, format);
|
|
1551
|
-
this.start
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
this.
|
|
1555
|
-
|
|
1582
|
+
const unchanged = this.sameDay(parsed.start, this.start) && this.sameDay(parsed.end, this.end);
|
|
1583
|
+
if (!unchanged) {
|
|
1584
|
+
this.start = parsed.start;
|
|
1585
|
+
this.end = parsed.end;
|
|
1586
|
+
if (parsed.start) {
|
|
1587
|
+
this.viewMonth = parsed.start.startOf("month");
|
|
1588
|
+
this.focusedDay = parsed.start;
|
|
1589
|
+
}
|
|
1556
1590
|
}
|
|
1557
1591
|
}
|
|
1558
1592
|
}
|
|
@@ -1684,6 +1718,11 @@ var RangeController = class {
|
|
|
1684
1718
|
this.focusedDay = day;
|
|
1685
1719
|
}
|
|
1686
1720
|
this.emit();
|
|
1721
|
+
if (this.options.asString === false) {
|
|
1722
|
+
this.emitRange(this.start, this.end);
|
|
1723
|
+
} else if (this.options.inline && this.start && this.end) {
|
|
1724
|
+
this.emitRange(this.start, this.end);
|
|
1725
|
+
}
|
|
1687
1726
|
}
|
|
1688
1727
|
setHoverEnd(day) {
|
|
1689
1728
|
if (this.start && !this.end) {
|
|
@@ -1812,10 +1851,12 @@ function DateTimeRange(props) {
|
|
|
1812
1851
|
});
|
|
1813
1852
|
}
|
|
1814
1853
|
const controller = controllerRef.current;
|
|
1854
|
+
const onChangeRef = useLatest(onChange);
|
|
1855
|
+
const setOpenRef = useLatest(setOpen);
|
|
1815
1856
|
useEffect(() => {
|
|
1816
1857
|
controller.setOptions({
|
|
1817
1858
|
value,
|
|
1818
|
-
onChange,
|
|
1859
|
+
onChange: (next) => onChangeRef.current?.(next),
|
|
1819
1860
|
asString,
|
|
1820
1861
|
format,
|
|
1821
1862
|
minDate,
|
|
@@ -1828,12 +1869,11 @@ function DateTimeRange(props) {
|
|
|
1828
1869
|
inline,
|
|
1829
1870
|
className,
|
|
1830
1871
|
open,
|
|
1831
|
-
onOpenChange:
|
|
1872
|
+
onOpenChange: (next) => setOpenRef.current(next)
|
|
1832
1873
|
});
|
|
1833
1874
|
}, [
|
|
1834
1875
|
controller,
|
|
1835
1876
|
value,
|
|
1836
|
-
onChange,
|
|
1837
1877
|
asString,
|
|
1838
1878
|
format,
|
|
1839
1879
|
minDate,
|
|
@@ -1845,8 +1885,7 @@ function DateTimeRange(props) {
|
|
|
1845
1885
|
labelsProp,
|
|
1846
1886
|
inline,
|
|
1847
1887
|
className,
|
|
1848
|
-
open
|
|
1849
|
-
setOpen
|
|
1888
|
+
open
|
|
1850
1889
|
]);
|
|
1851
1890
|
const snap = useSyncExternalStore(
|
|
1852
1891
|
controller.subscribe,
|
|
@@ -1910,6 +1949,7 @@ function DateTimeRange(props) {
|
|
|
1910
1949
|
"aria-label": snap.labels.chooseDateRange,
|
|
1911
1950
|
tabIndex: 0,
|
|
1912
1951
|
onKeyDown: onGridKeyDown,
|
|
1952
|
+
onMouseLeave: () => controller.setHoverEnd(null),
|
|
1913
1953
|
children: [
|
|
1914
1954
|
snap.weekdayLabels.map((label) => /* @__PURE__ */ jsx(
|
|
1915
1955
|
"div",
|
|
@@ -1985,7 +2025,7 @@ function DateTimeRange(props) {
|
|
|
1985
2025
|
}
|
|
1986
2026
|
),
|
|
1987
2027
|
!inline && /* @__PURE__ */ jsx("button", { type: "button", className: "ctp-cancel", onClick: close, children: snap.labels.close }),
|
|
1988
|
-
/* @__PURE__ */ jsx(
|
|
2028
|
+
!inline && /* @__PURE__ */ jsx(
|
|
1989
2029
|
"button",
|
|
1990
2030
|
{
|
|
1991
2031
|
type: "button",
|
|
@@ -204,6 +204,8 @@ declare class PickerController {
|
|
|
204
204
|
selectSecondOption(opt: string): void;
|
|
205
205
|
selectAmPmOption(opt: string): void;
|
|
206
206
|
handleGridKeyDown(key: string): boolean;
|
|
207
|
+
private buildPayload;
|
|
208
|
+
private maybeCommitInline;
|
|
207
209
|
confirm(): DateTimeChangeValue;
|
|
208
210
|
clear(): void;
|
|
209
211
|
/** Year window helpers for month/year panels */
|
|
@@ -248,6 +250,7 @@ declare class RangeController {
|
|
|
248
250
|
subscribe: (listener: Listener) => (() => void);
|
|
249
251
|
getSnapshot: () => RangeSnapshot;
|
|
250
252
|
getServerSnapshot: () => RangeSnapshot;
|
|
253
|
+
private sameDay;
|
|
251
254
|
setOptions(partial: Partial<DateTimeRangeOptions>): void;
|
|
252
255
|
private getLabels;
|
|
253
256
|
private emit;
|
|
@@ -204,6 +204,8 @@ declare class PickerController {
|
|
|
204
204
|
selectSecondOption(opt: string): void;
|
|
205
205
|
selectAmPmOption(opt: string): void;
|
|
206
206
|
handleGridKeyDown(key: string): boolean;
|
|
207
|
+
private buildPayload;
|
|
208
|
+
private maybeCommitInline;
|
|
207
209
|
confirm(): DateTimeChangeValue;
|
|
208
210
|
clear(): void;
|
|
209
211
|
/** Year window helpers for month/year panels */
|
|
@@ -248,6 +250,7 @@ declare class RangeController {
|
|
|
248
250
|
subscribe: (listener: Listener) => (() => void);
|
|
249
251
|
getSnapshot: () => RangeSnapshot;
|
|
250
252
|
getServerSnapshot: () => RangeSnapshot;
|
|
253
|
+
private sameDay;
|
|
251
254
|
setOptions(partial: Partial<DateTimeRangeOptions>): void;
|
|
252
255
|
private getLabels;
|
|
253
256
|
private emit;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { j as PickerControllerOptions, P as PickerController, i as DateTimeRangeOptions, R as RangeController } from './rangeController-
|
|
1
|
+
import { j as PickerControllerOptions, P as PickerController, i as DateTimeRangeOptions, R as RangeController } from './rangeController-BBZcdM0Z.mjs';
|
|
2
2
|
|
|
3
3
|
interface DateTimePickerHandle {
|
|
4
4
|
update: (options: Partial<PickerControllerOptions>) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { j as PickerControllerOptions, P as PickerController, i as DateTimeRangeOptions, R as RangeController } from './rangeController-
|
|
1
|
+
import { j as PickerControllerOptions, P as PickerController, i as DateTimeRangeOptions, R as RangeController } from './rangeController-BBZcdM0Z.js';
|
|
2
2
|
|
|
3
3
|
interface DateTimePickerHandle {
|
|
4
4
|
update: (options: Partial<PickerControllerOptions>) => void;
|
package/dist/svelte/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { defineCustomElements } from '../wc/index.mjs';
|
|
2
|
-
import '../rangeRenderer-
|
|
3
|
-
import '../rangeController-
|
|
2
|
+
import '../rangeRenderer-CE99Ji3Q.mjs';
|
|
3
|
+
import '../rangeController-BBZcdM0Z.mjs';
|
|
4
4
|
import 'dayjs';
|
|
5
5
|
|
|
6
6
|
/** Svelte action: mounts nothing; ensures custom elements are defined. */
|
package/dist/svelte/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { defineCustomElements } from '../wc/index.js';
|
|
2
|
-
import '../rangeRenderer-
|
|
3
|
-
import '../rangeController-
|
|
2
|
+
import '../rangeRenderer-CeLuwT6V.js';
|
|
3
|
+
import '../rangeController-BBZcdM0Z.js';
|
|
4
4
|
import 'dayjs';
|
|
5
5
|
|
|
6
6
|
/** Svelte action: mounts nothing; ensures custom elements are defined. */
|