@servicetitan/anvil2 1.28.0 → 1.29.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.
Files changed (80) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/dist/{Combobox-JAm3x-tw.js → Combobox-DCrEfyl2.js} +235 -124
  3. package/dist/Combobox-DCrEfyl2.js.map +1 -0
  4. package/dist/Combobox.css +100 -68
  5. package/dist/Combobox.js +1 -1
  6. package/dist/{DateField-5mNXaJ7q.js → DateField-4jR9NvbC.js} +327 -320
  7. package/dist/DateField-4jR9NvbC.js.map +1 -0
  8. package/dist/DateField.js +1 -1
  9. package/dist/{Dialog-B4M0DXxG.js → Dialog-CL3bfZuB.js} +2 -2
  10. package/dist/{Dialog-B4M0DXxG.js.map → Dialog-CL3bfZuB.js.map} +1 -1
  11. package/dist/{Dialog-CUK5YvVY-Dv5edacC.js → Dialog-CYBt_JdP-CmF0MUHL.js} +77 -48
  12. package/dist/Dialog-CYBt_JdP-CmF0MUHL.js.map +1 -0
  13. package/dist/Dialog.js +1 -1
  14. package/dist/{Drawer-BqqZB3Sn.js → Drawer-8nHrKktU.js} +2 -2
  15. package/dist/{Drawer-BqqZB3Sn.js.map → Drawer-8nHrKktU.js.map} +1 -1
  16. package/dist/{Drawer-CrXiK2w0-BMzKuNFt.js → Drawer-UQlX-LQG-BSCnMRad.js} +84 -57
  17. package/dist/Drawer-UQlX-LQG-BSCnMRad.js.map +1 -0
  18. package/dist/{Drawer-CrXiK2w0.css → Drawer-UQlX-LQG.css} +26 -25
  19. package/dist/Drawer.js +1 -1
  20. package/dist/InputMask-B8N8PP1W-DlUKpMR4.js +323 -0
  21. package/dist/InputMask-B8N8PP1W-DlUKpMR4.js.map +1 -0
  22. package/dist/{InputMask-BmXj5mob.js → InputMask-jsL7rSOk.js} +2 -2
  23. package/dist/{InputMask-BmXj5mob.js.map → InputMask-jsL7rSOk.js.map} +1 -1
  24. package/dist/InputMask.js +1 -1
  25. package/dist/{Label-CbYy5kwu-BCTOKxOk.js → Label-CUVr-jvI-BXhER5eQ.js} +3 -3
  26. package/dist/{Label-CbYy5kwu-BCTOKxOk.js.map → Label-CUVr-jvI-BXhER5eQ.js.map} +1 -1
  27. package/dist/{Menu-IEBrkdoN.js → Menu-CsfX8-_z.js} +4 -3
  28. package/dist/Menu-CsfX8-_z.js.map +1 -0
  29. package/dist/Menu.js +1 -1
  30. package/dist/{Page-qlpHVAMH.js → Page-vKi5JkDS.js} +5 -5
  31. package/dist/{Page-qlpHVAMH.js.map → Page-vKi5JkDS.js.map} +1 -1
  32. package/dist/Page.js +1 -1
  33. package/dist/{Popover-B7K3o_l4.js → Popover-OFlyW8gN.js} +2 -2
  34. package/dist/{Popover-B7K3o_l4.js.map → Popover-OFlyW8gN.js.map} +1 -1
  35. package/dist/{Popover-C1B3UJXp-B5obSIvA.js → Popover-tu_N1aS6-CSLR1Xzc.js} +5 -5
  36. package/dist/Popover-tu_N1aS6-CSLR1Xzc.js.map +1 -0
  37. package/dist/Popover.js +1 -1
  38. package/dist/{ProgressBar-BLg29adn-CMz5eu5f.js → ProgressBar-DQ1lsFk2-Ci4eqzM0.js} +3 -3
  39. package/dist/{ProgressBar-BLg29adn-CMz5eu5f.js.map → ProgressBar-DQ1lsFk2-Ci4eqzM0.js.map} +1 -1
  40. package/dist/{ProgressBar-_DyYSgfx.js → ProgressBar-gVRLaKPz.js} +2 -2
  41. package/dist/{ProgressBar-_DyYSgfx.js.map → ProgressBar-gVRLaKPz.js.map} +1 -1
  42. package/dist/ProgressBar.js +1 -1
  43. package/dist/{TextField-Lwe9XAou-tH8gcQTq.js → TextField-B8LHWOoC-DSV9zY-z.js} +2 -2
  44. package/dist/{TextField-Lwe9XAou-tH8gcQTq.js.map → TextField-B8LHWOoC-DSV9zY-z.js.map} +1 -1
  45. package/dist/{TextField-tF-ERwA8.js → TextField-DgxJO1a7.js} +2 -2
  46. package/dist/{TextField-tF-ERwA8.js.map → TextField-DgxJO1a7.js.map} +1 -1
  47. package/dist/TextField.js +1 -1
  48. package/dist/{Textarea-BrzxOEx3.js → Textarea-B-Dv2RXs.js} +2 -2
  49. package/dist/Textarea-B-Dv2RXs.js.map +1 -0
  50. package/dist/Textarea.js +1 -1
  51. package/dist/Toast.js +1 -1
  52. package/dist/{Toolbar-D9fMSiGU.js → Toolbar-7BeCY61H.js} +2 -2
  53. package/dist/{Toolbar-D9fMSiGU.js.map → Toolbar-7BeCY61H.js.map} +1 -1
  54. package/dist/Toolbar.js +1 -1
  55. package/dist/{Tooltip-BEo0IRDf.js → Tooltip-BVBq-KxK.js} +2 -2
  56. package/dist/{Tooltip-BEo0IRDf.js.map → Tooltip-BVBq-KxK.js.map} +1 -1
  57. package/dist/{Tooltip-36nMbVT3-DMkvo60s.js → Tooltip-C8sCGmKM-CLrDofvy.js} +4 -4
  58. package/dist/{Tooltip-36nMbVT3-DMkvo60s.js.map → Tooltip-C8sCGmKM-CLrDofvy.js.map} +1 -1
  59. package/dist/Tooltip.js +1 -1
  60. package/dist/components/Dialog/Dialog.d.ts +1 -0
  61. package/dist/components/Drawer/Drawer.d.ts +1 -0
  62. package/dist/index.js +14 -14
  63. package/dist/{toast-DkO9HWpH.js → toast-CbokOkfo.js} +6 -2
  64. package/dist/toast-CbokOkfo.js.map +1 -0
  65. package/package.json +3 -3
  66. package/dist/Combobox-JAm3x-tw.js.map +0 -1
  67. package/dist/DateField-5mNXaJ7q.js.map +0 -1
  68. package/dist/Dialog-CUK5YvVY-Dv5edacC.js.map +0 -1
  69. package/dist/Drawer-CrXiK2w0-BMzKuNFt.js.map +0 -1
  70. package/dist/InputMask-CQzrMoEy-CLNvXsm7.js +0 -195
  71. package/dist/InputMask-CQzrMoEy-CLNvXsm7.js.map +0 -1
  72. package/dist/Menu-IEBrkdoN.js.map +0 -1
  73. package/dist/Popover-C1B3UJXp-B5obSIvA.js.map +0 -1
  74. package/dist/Textarea-BrzxOEx3.js.map +0 -1
  75. package/dist/toast-DkO9HWpH.js.map +0 -1
  76. /package/dist/{Dialog-CUK5YvVY.css → Dialog-CYBt_JdP.css} +0 -0
  77. /package/dist/{Label-CbYy5kwu.css → Label-CUVr-jvI.css} +0 -0
  78. /package/dist/{Popover-C1B3UJXp.css → Popover-tu_N1aS6.css} +0 -0
  79. /package/dist/{ProgressBar-BLg29adn.css → ProgressBar-DQ1lsFk2.css} +0 -0
  80. /package/dist/{Tooltip-36nMbVT3.css → Tooltip-C8sCGmKM.css} +0 -0
@@ -3,13 +3,14 @@ import * as React from 'react';
3
3
  import { forwardRef, useState, useRef, useMemo, useEffect } from 'react';
4
4
  import { useTrackingId } from './useTrackingId.js';
5
5
  import { c as childrenToString } from './childrenToString-Bz9MqbHb-Bz9MqbHb.js';
6
- import { I as InputMask } from './InputMask-CQzrMoEy-CLNvXsm7.js';
7
- import { T as TextField } from './TextField-Lwe9XAou-tH8gcQTq.js';
6
+ import { I as InputMask } from './InputMask-B8N8PP1W-DlUKpMR4.js';
8
7
  import { D as DateTime, t as toDateString, i as isValidDate, C as Calendar } from './Calendar-9iYMS0Iw-D_XWYjOE.js';
9
8
  import { I as Icon } from './Icon-DbHA5GV1-DwO2aGkj.js';
10
9
  import { s as supportsPopover } from './supportsPopover-8aJR37cf-8aJR37cf.js';
11
- import { e as PopoverLegacy, d as Popover } from './Popover-C1B3UJXp-B5obSIvA.js';
10
+ import { T as TextField } from './TextField-B8LHWOoC-DSV9zY-z.js';
11
+ import { e as PopoverLegacy, d as Popover } from './Popover-tu_N1aS6-CSLR1Xzc.js';
12
12
  import { u as useMergeRefs } from './floating-ui.react-4AwURJA3.js';
13
+ import { u as useKeyboardFocusables } from './useKeyboardFocusables-CwVMAe5C-DtjYOAmt.js';
13
14
  import { u as useMergeRefs$1 } from './useMergeRefs-Bde85AWI-Bde85AWI.js';
14
15
 
15
16
  const SvgEvent = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("path", { d: "M16 13h-3c-.55 0-1 .45-1 1v3c0 .55.45 1 1 1h3c.55 0 1-.45 1-1v-3c0-.55-.45-1-1-1zm0-10v1H8V3c0-.55-.45-1-1-1s-1 .45-1 1v1H5c-1.11 0-1.99.9-1.99 2L3 20a2 2 0 0 0 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-1V3c0-.55-.45-1-1-1s-1 .45-1 1zm2 17H6c-.55 0-1-.45-1-1V9h14v10c0 .55-.45 1-1 1z" }));
@@ -540,7 +541,7 @@ const DateFieldLegacy = forwardRef(
540
541
  );
541
542
  DateFieldLegacy.displayName = "DateFieldLegacy";
542
543
 
543
- const RANGE_DIVIDER = " ";
544
+ const RANGE_DIVIDER = " ";
544
545
  const DateField$1 = forwardRef(
545
546
  (props, ref) => {
546
547
  const {
@@ -549,6 +550,7 @@ const DateField$1 = forwardRef(
549
550
  onFocus,
550
551
  onBlur,
551
552
  onChange,
553
+ onClick,
552
554
  format = "MM/dd/yyyy",
553
555
  disableHint,
554
556
  // Calendar
@@ -575,72 +577,40 @@ const DateField$1 = forwardRef(
575
577
  _setOpen(val);
576
578
  };
577
579
  const [internalValue, setInternalValue] = useState();
578
- const [disableFocusLock, setDisableFocusLock] = useState(true);
579
580
  const inputRef = useRef(null);
580
- const calRef = useRef(null);
581
- const iconRef = useRef(null);
582
- const docRef = useRef(null);
583
- const floatRef = useRef(null);
584
- const isClickOutside = useRef(false);
585
- const formatMask = format.replace(/[^/]/g, "_");
581
+ const popperRef = useRef(null);
582
+ const documentRef = useRef(document.body);
586
583
  const hint = useMemo(
587
584
  () => disableHint ? undefined : `format: ${format.replace(/M/g, "m")}`,
588
585
  [format, disableHint]
589
586
  );
587
+ const { focusables } = useKeyboardFocusables(documentRef, {
588
+ observeChange: true
589
+ });
590
+ const { focusables: popoverFocusables } = useKeyboardFocusables(popperRef, {
591
+ observeChange: true
592
+ });
593
+ const pageFocusables = focusables?.filter(
594
+ (item) => !popoverFocusables?.includes(item)
595
+ );
596
+ const [popoverRef, setPopoverRef] = useState();
597
+ const combinedRef = useMergeRefs$1([popoverRef, inputRef]);
590
598
  useEffect(() => {
591
- if (!docRef.current) {
592
- if (document != null) {
593
- docRef.current = document;
594
- return;
595
- }
596
- const doc = inputRef.current?.closest("body")?.ownerDocument;
597
- doc && (docRef.current = doc);
598
- if (docRef.current == null && inputRef.current?.parentNode != null) {
599
- let node = inputRef.current?.parentNode;
600
- while (node.parentNode != null) {
601
- node = node.parentNode;
602
- }
603
- docRef.current = node;
604
- }
605
- }
606
- const clickOutHandler = (ev) => {
607
- const realTarget = ev.composedPath()[0];
608
- if (!floatRef.current?.contains(realTarget) && !iconRef.current?.contains(realTarget) && inputRef.current !== realTarget) {
609
- setOpen(false);
610
- setDisableFocusLock(true);
611
- onBlur?.(ev);
612
- }
613
- };
614
- if (open) {
615
- docRef.current?.addEventListener("click", clickOutHandler);
616
- } else {
617
- docRef.current?.removeEventListener("click", clickOutHandler);
618
- }
619
- return () => {
620
- docRef.current?.removeEventListener("click", clickOutHandler);
621
- };
622
- }, [open, onBlur]);
623
- useEffect(() => {
599
+ if (!defaultValue) return;
624
600
  if (range) {
625
- let start;
626
- let end;
627
- if (typeof inputValue === "string") {
628
- const parts = inputValue.split(RANGE_DIVIDER);
629
- start = parts[0];
630
- end = parts[1];
631
- } else {
632
- start = inputValue?.start ?? "";
633
- end = inputValue?.end ?? "";
634
- }
635
- const startDate = DateTime.fromFormat(start ?? "", format, {
636
- zone: defaultTimeZone
637
- }).startOf("day");
638
- const endDate = DateTime.fromFormat(end ?? "", format, {
601
+ const startDate = DateTime.fromFormat(
602
+ defaultValue.start ?? "",
603
+ format,
604
+ {
605
+ zone: defaultTimeZone
606
+ }
607
+ ).startOf("day");
608
+ const endDate = DateTime.fromFormat(defaultValue.end ?? "", format, {
639
609
  zone: defaultTimeZone
640
610
  }).startOf("day");
641
- const newData = {
611
+ const newValue2 = {
642
612
  start: {
643
- value: start,
613
+ value: defaultValue.start ?? "",
644
614
  date: toDateString(startDate),
645
615
  isValid: startDate.isValid && isValidDate(
646
616
  startDate,
@@ -655,7 +625,7 @@ const DateField$1 = forwardRef(
655
625
  )
656
626
  },
657
627
  end: {
658
- value: end,
628
+ value: defaultValue.end ?? "",
659
629
  date: toDateString(endDate),
660
630
  isValid: startDate.isValid && isValidDate(
661
631
  endDate,
@@ -669,105 +639,87 @@ const DateField$1 = forwardRef(
669
639
  defaultTimeZone
670
640
  )
671
641
  },
672
- value: `${start || formatMask}${RANGE_DIVIDER}${end || formatMask}`
642
+ value: defaultValue.start + RANGE_DIVIDER + defaultValue.end
673
643
  };
674
- setInternalValue(newData);
675
- } else {
676
- if (typeof inputValue !== "string") return;
677
- const inputDate = DateTime.fromFormat(inputValue, format, {
678
- zone: defaultTimeZone
679
- }).startOf("day");
680
- const newData = {
681
- value: inputValue,
682
- date: toDateString(inputDate),
683
- isValid: inputDate.isValid && isValidDate(
684
- inputDate,
685
- minDate,
686
- maxDate,
687
- new Set(unavailableDates || unavailable?.dates),
688
- {
689
- dates: new Set(unavailable?.dates),
690
- daysOfWeek: new Set(unavailable?.daysOfWeek)
691
- },
692
- defaultTimeZone
693
- )
694
- };
695
- setInternalValue(newData);
696
- }
697
- }, [inputValue]);
698
- const mask = useMemo(() => {
699
- const maskPart = format.replace(/[Mdy]/g, "9");
700
- if (range) {
701
- return maskPart + RANGE_DIVIDER + maskPart;
702
- } else {
703
- return maskPart;
644
+ setInternalValue(newValue2);
645
+ return;
704
646
  }
705
- }, [format, range]);
706
- useEffect(() => {
707
- if (typeof inputValue === "string") return;
708
- if (defaultValue) {
647
+ const date = DateTime.fromFormat(defaultValue, format, {
648
+ zone: defaultTimeZone
649
+ }).startOf("day");
650
+ const newValue = {
651
+ value: defaultValue,
652
+ date: toDateString(date),
653
+ isValid: date.isValid && isValidDate(
654
+ date,
655
+ minDate,
656
+ maxDate,
657
+ new Set(unavailableDates || unavailable?.dates),
658
+ {
659
+ dates: new Set(unavailable?.dates),
660
+ daysOfWeek: new Set(unavailable?.daysOfWeek)
661
+ },
662
+ defaultTimeZone
663
+ )
664
+ };
665
+ setInternalValue(newValue);
666
+ }, []);
667
+ const getCurrentValue = () => {
668
+ if (inputValue !== undefined) {
709
669
  if (range) {
710
- const defValStart = defaultValue.start;
711
- const defValEnd = defaultValue.end;
712
- const initValStart = defValStart + (formatMask + RANGE_DIVIDER + formatMask).slice(
713
- defValStart?.length
714
- );
715
- const initValEnd = defValEnd + (formatMask + RANGE_DIVIDER + formatMask).slice(defValEnd?.length);
716
- const newValue = initValStart + RANGE_DIVIDER + initValEnd;
717
- const inputDateStart = DateTime.fromFormat(
718
- defValStart || "",
670
+ const startDate = DateTime.fromFormat(
671
+ inputValue.start ?? "",
719
672
  format,
720
673
  {
721
674
  zone: defaultTimeZone
722
675
  }
723
676
  ).startOf("day");
724
- const inputDateEnd = DateTime.fromFormat(defValEnd || "", format, {
677
+ const endDate = DateTime.fromFormat(inputValue.end ?? "", format, {
725
678
  zone: defaultTimeZone
726
679
  }).startOf("day");
727
- const isValidStart = inputDateStart.isValid && isValidDate(
728
- inputDateStart,
729
- minDate,
730
- maxDate,
731
- new Set(unavailableDates || unavailable?.dates),
732
- {
733
- dates: new Set(unavailable?.dates),
734
- daysOfWeek: new Set(unavailable?.daysOfWeek)
735
- },
736
- defaultTimeZone
737
- );
738
- const isValidEnd = inputDateEnd.isValid && isValidDate(
739
- inputDateEnd,
740
- minDate,
741
- maxDate,
742
- new Set(unavailableDates || unavailable?.dates),
743
- {
744
- dates: new Set(unavailable?.dates),
745
- daysOfWeek: new Set(unavailable?.daysOfWeek)
746
- },
747
- defaultTimeZone
748
- );
749
- const initCalendarValue = {
680
+ const returnValue = {
750
681
  start: {
751
- value: initValStart,
752
- date: toDateString(inputDateStart),
753
- isValid: isValidStart
682
+ value: inputValue.start ?? "",
683
+ date: toDateString(startDate),
684
+ isValid: startDate.isValid && isValidDate(
685
+ startDate,
686
+ minDate,
687
+ maxDate,
688
+ new Set(unavailableDates || unavailable?.dates),
689
+ {
690
+ dates: new Set(unavailable?.dates),
691
+ daysOfWeek: new Set(unavailable?.daysOfWeek)
692
+ },
693
+ defaultTimeZone
694
+ )
754
695
  },
755
696
  end: {
756
- value: initValEnd,
757
- date: toDateString(inputDateEnd),
758
- isValid: isValidEnd
697
+ value: inputValue.end ?? "",
698
+ date: toDateString(endDate),
699
+ isValid: startDate.isValid && isValidDate(
700
+ endDate,
701
+ minDate,
702
+ maxDate,
703
+ new Set(unavailableDates || unavailable?.dates),
704
+ {
705
+ dates: new Set(unavailable?.dates),
706
+ daysOfWeek: new Set(unavailable?.daysOfWeek)
707
+ },
708
+ defaultTimeZone
709
+ )
759
710
  },
760
- value: newValue
711
+ value: inputValue.start + RANGE_DIVIDER + inputValue.end
761
712
  };
762
- setInternalValue(initCalendarValue);
763
- } else {
764
- const defVal = defaultValue;
765
- const initVal = defVal + formatMask.slice(defVal.length);
766
- const inputDate = DateTime.fromFormat(defVal, format, {
767
- zone: defaultTimeZone
768
- }).startOf("day");
769
- const isValid = inputDate.isValid && isValidDate(
770
- inputDate,
713
+ return returnValue;
714
+ }
715
+ const date = DateTime.fromFormat(inputValue, format, {
716
+ zone: defaultTimeZone
717
+ }).startOf("day");
718
+ return {
719
+ value: inputValue,
720
+ date: toDateString(date),
721
+ isValid: date.isValid && isValidDate(
722
+ date,
771
723
  minDate,
772
724
  maxDate,
773
725
  new Set(unavailableDates || unavailable?.dates),
@@ -776,38 +728,73 @@ const DateField$1 = forwardRef(
776
728
  daysOfWeek: new Set(unavailable?.daysOfWeek)
777
729
  },
778
730
  defaultTimeZone
779
- );
780
- const initCalendarValue = {
781
- value: initVal,
782
- date: toDateString(inputDate),
783
- isValid
784
- };
785
- setInternalValue(initCalendarValue);
786
- }
731
+ )
732
+ };
787
733
  }
788
- }, []);
789
- const focusToCalendar = () => {
790
- if (calRef.current) {
791
- const currentFocusable = calRef.current.querySelectorAll('[tabindex = "0"]')[0];
792
- if (currentFocusable) {
793
- currentFocusable.focus();
794
- }
734
+ return internalValue;
735
+ };
736
+ const handleInputFocus = (ev) => {
737
+ onFocus?.(ev);
738
+ };
739
+ const handleInputBlur = (ev) => {
740
+ if (!popperRef.current?.contains(ev.relatedTarget)) {
741
+ setOpen(false);
742
+ onBlur?.(ev);
795
743
  }
796
744
  };
797
745
  const handleInputKeyDown = (ev) => {
746
+ let currentFocusIndex = 0;
798
747
  switch (ev.key) {
748
+ case "Escape":
749
+ setOpen(false);
750
+ break;
799
751
  case "Tab":
752
+ if (!open || !pageFocusables?.length) {
753
+ break;
754
+ }
755
+ ev.preventDefault();
756
+ currentFocusIndex = pageFocusables.indexOf(inputRef.current) || 0;
800
757
  setOpen(false);
758
+ if (ev.shiftKey) {
759
+ if (currentFocusIndex === 0) {
760
+ requestAnimationFrame(
761
+ () => pageFocusables[pageFocusables.length - 1].focus()
762
+ );
763
+ } else {
764
+ requestAnimationFrame(
765
+ () => pageFocusables[currentFocusIndex - 1].focus()
766
+ );
767
+ }
768
+ break;
769
+ }
770
+ if (pageFocusables.length > currentFocusIndex + 1) {
771
+ requestAnimationFrame(
772
+ () => pageFocusables[currentFocusIndex + 1].focus()
773
+ );
774
+ } else {
775
+ requestAnimationFrame(() => pageFocusables[0].focus());
776
+ }
801
777
  break;
802
778
  case "ArrowDown":
803
779
  if (!open) {
804
780
  setOpen(true);
805
- setTimeout(focusToCalendar, 100);
781
+ setTimeout(focusToCalendar, 200);
806
782
  } else {
807
783
  focusToCalendar();
808
784
  }
809
785
  }
810
786
  };
787
+ const handleCalendarKeyDown = (ev) => {
788
+ switch (ev.key) {
789
+ case "Escape":
790
+ setOpen(false);
791
+ inputRef.current?.focus();
792
+ }
793
+ };
794
+ const handleInputClick = (ev) => {
795
+ setOpen(true);
796
+ onClick?.(ev);
797
+ };
811
798
  const handleInputChange = (ev) => {
812
799
  if (range) {
813
800
  const parts = ev.target.value.split(RANGE_DIVIDER);
@@ -851,198 +838,226 @@ const DateField$1 = forwardRef(
851
838
  },
852
839
  value: ev.target.value
853
840
  };
854
- if (!inputValue) {
855
- setInternalValue(returnValue);
856
- }
841
+ setInternalValue(returnValue);
857
842
  onChange?.(ev, returnValue);
858
- } else {
859
- if (ev.target.value === internalValue?.date) return;
860
- const inputDate = DateTime.fromFormat(ev.target.value, format, {
861
- zone: defaultTimeZone
862
- }).startOf("day");
863
- const returnValue = {
864
- value: ev.target.value,
865
- date: toDateString(inputDate),
866
- isValid: inputDate.isValid && isValidDate(
867
- inputDate,
868
- minDate,
869
- maxDate,
870
- new Set(unavailableDates || unavailable?.dates),
871
- {
872
- dates: new Set(unavailable?.dates),
873
- daysOfWeek: new Set(unavailable?.daysOfWeek)
874
- },
875
- defaultTimeZone
876
- )
877
- };
878
- if (!inputValue) {
879
- setInternalValue(returnValue);
880
- }
881
- onChange?.(ev, returnValue);
882
- }
883
- };
884
- const handleInputBlur = (ev) => {
885
- if (isClickOutside.current) {
886
- isClickOutside.current = false;
887
843
  return;
888
844
  }
889
- if (!calRef.current?.contains(ev.relatedTarget)) {
890
- setOpen(false);
891
- onBlur?.(ev);
892
- }
893
- };
894
- const handleCalendarKeyDown = (ev) => {
895
- switch (ev.key) {
896
- case "Escape":
897
- setDisableFocusLock(true);
898
- inputRef.current?.focus();
899
- break;
900
- }
901
- };
902
- const handleCalendarBlur = (ev) => {
903
- if (!(inputRef.current === ev.currentTarget || calRef.current === ev.currentTarget)) {
904
- setOpen(false);
905
- onBlur?.(ev);
906
- }
907
- if (!(calRef.current === ev.currentTarget)) {
908
- setDisableFocusLock(true);
909
- }
910
- };
911
- const handleCalendarFocus = (ev) => {
912
- disableFocusLock && setDisableFocusLock(false);
845
+ const date = DateTime.fromFormat(ev.target.value, format, {
846
+ zone: defaultTimeZone
847
+ }).startOf("day");
848
+ const newDate = {
849
+ value: ev.target.value,
850
+ date: toDateString(date),
851
+ isValid: date.isValid && isValidDate(
852
+ date,
853
+ minDate,
854
+ maxDate,
855
+ new Set(unavailableDates || unavailable?.dates),
856
+ {
857
+ dates: new Set(unavailable?.dates),
858
+ daysOfWeek: new Set(unavailable?.daysOfWeek)
859
+ },
860
+ defaultTimeZone
861
+ )
862
+ };
863
+ setInternalValue(newDate);
864
+ onChange?.(ev, newDate);
913
865
  };
914
866
  const handleCalendarSelection = (data) => {
915
867
  if (range) {
916
- const calSelectData = data;
917
- const startVal = DateTime.fromISO(calSelectData?.value?.start || "", {
868
+ const startDate = data.value?.start ?? "";
869
+ const endDate = data.value?.end ?? "";
870
+ const startVal = DateTime.fromISO(startDate, {
918
871
  zone: defaultTimeZone
919
872
  });
920
- const endVal = DateTime.fromISO(calSelectData?.value?.end || "", {
873
+ const startValue = startVal.toFormat(format);
874
+ const endVal = DateTime.fromISO(endDate, {
921
875
  zone: defaultTimeZone
922
876
  });
923
- let newValue = "";
924
- const newInternalValue = { value: "" };
925
- if (startVal.isValid) {
926
- newInternalValue.start = {
927
- value: startVal.toFormat(format),
928
- date: calSelectData?.value?.start,
877
+ const endValue = endVal.toFormat(format);
878
+ const newDateRange = {
879
+ start: {
880
+ value: startValue,
881
+ date: startDate,
929
882
  isValid: true
930
- };
931
- newValue += startVal.toFormat(format);
932
- } else {
933
- newValue += formatMask;
934
- }
935
- newValue += RANGE_DIVIDER;
936
- if (endVal.isValid) {
937
- newInternalValue.end = {
938
- value: endVal.toFormat(format),
939
- date: calSelectData?.value?.end,
883
+ },
884
+ end: {
885
+ value: endValue,
886
+ date: endDate,
940
887
  isValid: true
941
- };
942
- newValue += endVal.toFormat(format);
943
- } else {
944
- newValue += formatMask;
945
- }
946
- if (typeof inputValue !== "string") {
947
- setInternalValue(newInternalValue);
948
- }
949
- newInternalValue.value = newValue;
950
- const event = {
951
- target: {
952
- value: newValue
953
- }
954
- };
955
- onChange?.(event, newInternalValue);
956
- } else {
957
- const calSelectData = data;
958
- const val = DateTime.fromISO(calSelectData.value || "", {
959
- zone: defaultTimeZone
960
- });
961
- const newValue = val.toFormat(format);
962
- const newInternalValue = {
963
- value: newValue,
964
- date: calSelectData.value,
965
- isValid: val.isValid && isValidDate(
966
- val,
967
- minDate,
968
- maxDate,
969
- new Set(unavailableDates || unavailable?.dates),
970
- {
971
- dates: new Set(unavailable?.dates),
972
- daysOfWeek: new Set(unavailable?.daysOfWeek)
973
- },
974
- defaultTimeZone
975
- )
888
+ },
889
+ value: startValue + RANGE_DIVIDER + endValue
976
890
  };
977
- if (typeof inputValue !== "string") {
978
- setInternalValue(newInternalValue);
979
- }
980
- const event = {
891
+ setInternalValue(newDateRange);
892
+ const event2 = {
981
893
  target: {
982
- value: newValue
894
+ value: startValue + RANGE_DIVIDER + endValue
983
895
  }
984
896
  };
985
- onChange?.(event, newInternalValue);
897
+ handleInputChange(event2);
898
+ return;
986
899
  }
900
+ const date = data.value;
901
+ const val = DateTime.fromISO(date || "", {
902
+ zone: defaultTimeZone
903
+ });
904
+ const value = val.toFormat(format);
905
+ const newDate = {
906
+ value,
907
+ date,
908
+ isValid: true
909
+ };
910
+ setInternalValue(newDate);
911
+ const event = {
912
+ target: {
913
+ value
914
+ }
915
+ };
916
+ handleInputChange(event);
987
917
  };
988
- const handleInputFocus = (ev) => {
989
- if (!open) {
990
- setOpen(true);
991
- onFocus?.(ev);
918
+ const focusToCalendar = () => {
919
+ if (popperRef.current) {
920
+ const currentFocusable = popperRef.current.querySelectorAll('[tabindex = "0"]')[0];
921
+ if (currentFocusable) {
922
+ currentFocusable.focus();
923
+ }
992
924
  }
993
925
  };
994
- const [popoverRef, setPopoverRef] = useState();
995
- const combinedRef = useMergeRefs$1([popoverRef, inputRef]);
926
+ const handleClickOutside = () => {
927
+ setOpen(false);
928
+ };
929
+ const currentValue = getCurrentValue();
996
930
  if (!supportsPopover())
997
931
  return /* @__PURE__ */ jsx(DateFieldLegacy, { ...props, ref });
998
932
  return /* @__PURE__ */ jsxs(
999
933
  Popover,
1000
934
  {
1001
- open: openCalendar || open,
935
+ open: openCalendar ?? open,
1002
936
  modal: true,
1003
937
  placement: "bottom-start",
1004
938
  disableTriggerFocus: true,
1005
- disableFocusLock,
939
+ onOutsidePress: handleClickOutside,
1006
940
  children: [
1007
941
  /* @__PURE__ */ jsx(Popover.Trigger, { children: ({ ref: iRef, ...props2 }) => {
1008
942
  setPopoverRef(iRef);
1009
- return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
943
+ return range ? /* @__PURE__ */ jsx(
1010
944
  InputMask,
1011
945
  {
1012
- mask,
946
+ mask: "99/99/9999" + RANGE_DIVIDER + "99/99/9999",
947
+ ref: combinedRef,
948
+ onChange: handleInputChange,
949
+ value: currentValue?.value,
1013
950
  inputProps: {
1014
- onKeyDown: handleInputKeyDown,
951
+ onFocus: handleInputFocus,
952
+ prefix: /* @__PURE__ */ jsx(Icon, { svg: SvgEvent }),
1015
953
  onBlur: handleInputBlur,
1016
- onChange: handleInputChange,
1017
- onFocus: handleInputFocus
954
+ onKeyDown: handleInputKeyDown,
955
+ onClick: handleInputClick,
956
+ hint,
957
+ ...inputProps
1018
958
  },
1019
- value: internalValue?.value || "",
1020
- ...props2,
959
+ customMaskHandler: [
960
+ {
961
+ match: {
962
+ matchPattern: new RegExp(/^(\d)\//),
963
+ startPosition: 0,
964
+ endPosition: 2
965
+ },
966
+ apply: {
967
+ applyPattern: "0$1",
968
+ caretOffset: 2
969
+ }
970
+ },
971
+ {
972
+ match: {
973
+ matchPattern: new RegExp(/^(\d)\//),
974
+ startPosition: 3,
975
+ endPosition: 5
976
+ },
977
+ apply: {
978
+ applyPattern: "0$1",
979
+ caretOffset: 2
980
+ }
981
+ },
982
+ {
983
+ match: {
984
+ matchPattern: new RegExp(/^(\d)\//),
985
+ startPosition: 13,
986
+ endPosition: 15
987
+ },
988
+ apply: {
989
+ applyPattern: "0$1",
990
+ caretOffset: 2
991
+ }
992
+ },
993
+ {
994
+ match: {
995
+ matchPattern: new RegExp(/^(\d)\//),
996
+ startPosition: 16,
997
+ endPosition: 18
998
+ },
999
+ apply: {
1000
+ applyPattern: "0$1",
1001
+ caretOffset: 2
1002
+ }
1003
+ }
1004
+ ]
1005
+ }
1006
+ ) : /* @__PURE__ */ jsx(
1007
+ InputMask,
1008
+ {
1009
+ mask: "99/99/9999",
1021
1010
  ref: combinedRef,
1022
- children: /* @__PURE__ */ jsx(
1023
- TextField,
1011
+ onChange: handleInputChange,
1012
+ value: currentValue?.value,
1013
+ inputProps: {
1014
+ onFocus: handleInputFocus,
1015
+ prefix: /* @__PURE__ */ jsx(Icon, { svg: SvgEvent }),
1016
+ onBlur: handleInputBlur,
1017
+ onKeyDown: handleInputKeyDown,
1018
+ onClick: handleInputClick,
1019
+ hint,
1020
+ autoComplete: "off",
1021
+ ...inputProps
1022
+ },
1023
+ customMaskHandler: [
1024
+ {
1025
+ match: {
1026
+ matchPattern: new RegExp(/^(\d)\//),
1027
+ startPosition: 0,
1028
+ endPosition: 2
1029
+ },
1030
+ apply: {
1031
+ applyPattern: "0$1",
1032
+ caretOffset: 2
1033
+ }
1034
+ },
1024
1035
  {
1025
- hint,
1026
- ref,
1027
- prefix: /* @__PURE__ */ jsx(Icon, { svg: SvgEvent, ref: iconRef }),
1028
- ...inputProps,
1029
- required
1036
+ match: {
1037
+ matchPattern: new RegExp(/^(\d)\//),
1038
+ startPosition: 3,
1039
+ endPosition: 5
1040
+ },
1041
+ apply: {
1042
+ applyPattern: "0$1",
1043
+ caretOffset: 2
1044
+ }
1030
1045
  }
1031
- )
1046
+ ]
1032
1047
  }
1033
- ) });
1048
+ );
1034
1049
  } }),
1035
- /* @__PURE__ */ jsx(Popover.Content, { ref: floatRef, children: !range ? /* @__PURE__ */ jsx(
1050
+ /* @__PURE__ */ jsx(Popover.Content, { ref: popperRef, "data-calendar-popover": true, children: range ? /* @__PURE__ */ jsx(
1036
1051
  Calendar,
1037
1052
  {
1038
- ref: calRef,
1053
+ range: true,
1039
1054
  onKeyDown: handleCalendarKeyDown,
1040
- defaultFocusedDate: internalValue?.date,
1041
- value: internalValue?.date || undefined,
1042
- locale,
1043
- onBlur: handleCalendarBlur,
1055
+ defaultFocusedDate: internalValue?.start?.date,
1056
+ value: {
1057
+ start: currentValue?.start?.date || undefined,
1058
+ end: currentValue?.end?.date || undefined
1059
+ },
1044
1060
  onSelection: handleCalendarSelection,
1045
- onFocus: handleCalendarFocus,
1046
1061
  minDate,
1047
1062
  maxDate,
1048
1063
  unavailableDates,
@@ -1053,24 +1068,16 @@ const DateField$1 = forwardRef(
1053
1068
  ) : /* @__PURE__ */ jsx(
1054
1069
  Calendar,
1055
1070
  {
1056
- ref: calRef,
1057
1071
  onKeyDown: handleCalendarKeyDown,
1058
- defaultFocusedDate: internalValue?.start?.date,
1059
- value: internalValue ? {
1060
- start: internalValue?.start?.date || undefined,
1061
- end: internalValue?.end?.date || undefined
1062
- } : undefined,
1063
- locale,
1064
- onBlur: handleCalendarBlur,
1072
+ defaultFocusedDate: internalValue?.date,
1073
+ value: currentValue?.date || undefined,
1065
1074
  onSelection: handleCalendarSelection,
1066
- onFocus: handleCalendarFocus,
1067
1075
  minDate,
1068
1076
  maxDate,
1069
1077
  unavailableDates,
1070
1078
  unavailable,
1071
1079
  defaultTimeZone,
1072
- startDay,
1073
- range: true
1080
+ startDay
1074
1081
  }
1075
1082
  ) })
1076
1083
  ]
@@ -1099,4 +1106,4 @@ const DateField = forwardRef(
1099
1106
  );
1100
1107
 
1101
1108
  export { DateField as D };
1102
- //# sourceMappingURL=DateField-5mNXaJ7q.js.map
1109
+ //# sourceMappingURL=DateField-4jR9NvbC.js.map