@superdispatch/dates 0.25.2 → 0.26.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.
@@ -24,12 +24,10 @@ function setDefaultTimeZone(offset) {
24
24
  luxon.Settings.defaultZoneName = offset;
25
25
  } else {
26
26
  var zone = luxon.FixedOffsetZone.instance(offset);
27
-
28
27
  if (zone.isValid) {
29
28
  luxon.Settings.defaultZoneName = zone.name;
30
29
  }
31
30
  }
32
-
33
31
  return luxon.Settings.defaultZoneName;
34
32
  }
35
33
  function useDefaultTimeZone(offset) {
@@ -64,6 +62,7 @@ function DateConfigProvider(_ref) {
64
62
  });
65
63
  }
66
64
 
65
+ //
67
66
  // Config
68
67
  //
69
68
 
@@ -93,7 +92,9 @@ var DATE_DISPLAY_VARIANTS = {
93
92
  hour: 'numeric',
94
93
  minute: 'numeric'
95
94
  }
96
- }; //
95
+ };
96
+
97
+ //
97
98
  // Date Utils
98
99
  //
99
100
 
@@ -101,72 +102,57 @@ function toPrimitiveDateInput(input) {
101
102
  if (typeof input == 'number' || typeof input == 'string') {
102
103
  return input;
103
104
  }
104
-
105
105
  if (input instanceof Date || input instanceof luxon.DateTime) {
106
106
  return input.valueOf();
107
107
  }
108
-
109
108
  return NaN;
110
109
  }
111
110
  function parseDate(input) {
112
111
  var {
113
112
  format
114
113
  } = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultDateConfig;
115
-
116
114
  if (input instanceof luxon.DateTime) {
117
115
  var {
118
116
  defaultZone
119
117
  } = luxon.Settings;
120
-
121
118
  if (!defaultZone.equals(input.zone)) {
122
119
  return input.setZone(defaultZone);
123
120
  }
124
-
125
121
  return input;
126
122
  }
127
-
128
123
  if (input instanceof Date) {
129
124
  return luxon.DateTime.fromJSDate(input);
130
125
  }
131
-
132
126
  if (typeof input === 'number') {
133
127
  return luxon.DateTime.fromMillis(input);
134
128
  }
135
-
136
129
  if (typeof input == 'string') {
137
130
  switch (format) {
138
131
  case 'DateISO':
139
132
  case 'DateTimeISO':
140
133
  return luxon.DateTime.fromISO(input);
141
-
142
134
  default:
143
135
  return luxon.DateTime.fromFormat(input, DATE_FORMATS[format]);
144
136
  }
145
137
  }
146
-
147
138
  return luxon.DateTime.invalid('invalid input');
148
139
  }
149
140
  function stringifyDate(input) {
150
141
  var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultDateConfig;
151
142
  var date = parseDate(input, config);
152
-
153
143
  if (date.isValid) {
154
144
  var {
155
145
  format
156
146
  } = config;
157
-
158
147
  switch (format) {
159
148
  case 'DateISO':
160
149
  return date.toISODate();
161
-
162
150
  case 'DateTimeISO':
163
151
  return date.toISO();
164
-
165
152
  default:
166
153
  return date.toFormat(DATE_FORMATS[format]);
167
154
  }
168
155
  }
169
-
170
156
  return null;
171
157
  }
172
158
  function formatDate(input, _ref) {
@@ -176,24 +162,19 @@ function formatDate(input, _ref) {
176
162
  } = _ref;
177
163
  var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultDateConfig;
178
164
  var date = parseDate(input, config);
179
-
180
165
  if (!date.isValid) {
181
166
  return fallback;
182
167
  }
183
-
184
168
  return date.toLocaleString(DATE_DISPLAY_VARIANTS[variant]);
185
169
  }
186
-
187
170
  function formatUnit(unit) {
188
171
  switch (unit) {
189
172
  case 'months':
190
173
  return 'mo';
191
-
192
174
  default:
193
175
  return unit.charAt(0);
194
176
  }
195
177
  }
196
-
197
178
  function formatRelativeTime(input) {
198
179
  var {
199
180
  round = true,
@@ -206,36 +187,28 @@ function formatRelativeTime(input) {
206
187
  var base = baseOption == null ? luxon.DateTime.now() : parseDate(baseOption, config);
207
188
  var date = parseDate(input, config);
208
189
  var padding = paddingOption ? date < base ? -paddingOption : paddingOption : 0;
209
-
210
190
  function format(value, unit) {
211
191
  var isPast = Object.is(value, -0) || value < 0;
212
192
  var diff = Math.abs(!round ? value : Math.trunc(value));
213
193
  var formattedUnit = formatUnit(unit);
214
194
  return isPast ? "".concat(diff).concat(formattedUnit, " ago") : "in ".concat(diff).concat(formattedUnit);
215
195
  }
216
-
217
196
  function differ(unit) {
218
197
  return date.plus(padding).diff(base, unit).get(unit);
219
198
  }
220
-
221
199
  if (date.isValid && base.isValid) {
222
200
  var units = ['years', 'months', 'days', 'hours', 'minutes', 'seconds'];
223
-
224
201
  if (unitOption) {
225
202
  return format(differ(unitOption), unitOption);
226
203
  }
227
-
228
204
  for (var unit of units) {
229
205
  var diff = differ(unit);
230
-
231
206
  if (Math.abs(diff) >= 1) {
232
207
  return format(diff, unit);
233
208
  }
234
209
  }
235
-
236
210
  return format(0, 'seconds');
237
211
  }
238
-
239
212
  return fallback;
240
213
  }
241
214
  function toDatePayload(input) {
@@ -246,7 +219,9 @@ function toDatePayload(input) {
246
219
  dateValue,
247
220
  stringValue: stringifyDate(dateValue, config)
248
221
  };
249
- } //
222
+ }
223
+
224
+ //
250
225
  // Date Range Utils
251
226
  //
252
227
 
@@ -254,17 +229,14 @@ function toPrimitiveDateRangeInput(input) {
254
229
  if (!Array.isArray(input)) {
255
230
  return [undefined, undefined];
256
231
  }
257
-
258
232
  return [toPrimitiveDateInput(input[0]), toPrimitiveDateInput(input[1])];
259
233
  }
260
234
  function parseDateRange(input, config) {
261
235
  var start = null;
262
236
  var finish = null;
263
-
264
237
  if (Array.isArray(input)) {
265
238
  [start = null, finish = null] = input.map(value => parseDate(value, config)).filter(date => date.isValid).sort((a, b) => a.valueOf() - b.valueOf());
266
239
  }
267
-
268
240
  return [start, finish];
269
241
  }
270
242
  function stringifyDateRange(input, config) {
@@ -277,11 +249,9 @@ function formatDateRange(input, _ref2) {
277
249
  } = _ref2;
278
250
  var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultDateConfig;
279
251
  var [start, finish] = parseDateRange(input, config);
280
-
281
252
  if (!start) {
282
253
  return fallback;
283
254
  }
284
-
285
255
  var startVariant = !(finish !== null && finish !== void 0 && finish.hasSame(start, 'year')) ? 'Date' : 'ShortDate';
286
256
  var startText = formatDate(start, {
287
257
  variant: startVariant
@@ -306,14 +276,12 @@ function useDateTime(input, options) {
306
276
  var primitiveInput = toPrimitiveDateInput(input);
307
277
  return react.useMemo(() => {
308
278
  var date = parseDate(primitiveInput, config);
309
-
310
279
  if (process.env.NODE_ENV !== 'production') {
311
280
  if (!date.isValid && typeof primitiveInput === 'string') {
312
281
  // eslint-disable-next-line no-console
313
282
  console.error("[useDateTime] Failed to parse \"".concat(primitiveInput, "\" string with \"").concat(config.format, "\" format."));
314
283
  }
315
284
  }
316
-
317
285
  return date;
318
286
  }, [config, primitiveInput]);
319
287
  }
@@ -592,9 +560,12 @@ var useStyles = /*#__PURE__*/styles.makeStyles(theme => ({
592
560
  todayButton: {}
593
561
  }), {
594
562
  name: 'SD-Calendar'
595
- }); //
563
+ });
564
+
565
+ //
596
566
  // Utility Types
597
567
  //
568
+
598
569
  //
599
570
  // Internal Utils
600
571
  //
@@ -603,7 +574,6 @@ function toDayPickerModifier(config, modifier) {
603
574
  if (!modifier) {
604
575
  return undefined;
605
576
  }
606
-
607
577
  return localDate => {
608
578
  var dateValue = luxon.DateTime.fromObject({
609
579
  year: localDate.getFullYear(),
@@ -621,12 +591,10 @@ function toDayPickerModifier(config, modifier) {
621
591
  });
622
592
  };
623
593
  }
624
-
625
594
  function toDayPickerHandler(config, classes, initialTime, handler) {
626
595
  if (!handler) {
627
596
  return undefined;
628
597
  }
629
-
630
598
  return (localDate, modifiers) => {
631
599
  var dateValue = luxon.DateTime.fromObject({
632
600
  year: localDate.getFullYear(),
@@ -645,35 +613,35 @@ function toDayPickerHandler(config, classes, initialTime, handler) {
645
613
  stringValue: stringifyDate(dateValue, config)
646
614
  });
647
615
  };
648
- } //
616
+ }
617
+
618
+ //
649
619
  // Calendar
650
620
  //
651
621
 
652
-
653
622
  var Calendar = /*#__PURE__*/react.forwardRef((_ref, ref) => {
654
623
  var {
655
- footer,
656
- classes,
657
- direction,
658
- quickSelection,
659
- selectedDays,
660
- disabledDays,
661
- onDayClick,
662
- onDayKeyDown,
663
- onDayMouseEnter,
664
- onDayMouseLeave,
665
- onDayMouseDown,
666
- onDayMouseUp,
667
- onDayTouchEnd,
668
- onDayTouchStart,
669
- modifiers,
670
- highlightedDays,
671
- format: formatProp,
672
- initialTime: initialTimeInputProp,
673
- initialMonth: initialMonthInputProp
674
- } = _ref,
675
- dayPickerProps = _objectWithoutProperties(_ref, _excluded);
676
-
624
+ footer,
625
+ classes,
626
+ direction,
627
+ quickSelection,
628
+ selectedDays,
629
+ disabledDays,
630
+ onDayClick,
631
+ onDayKeyDown,
632
+ onDayMouseEnter,
633
+ onDayMouseLeave,
634
+ onDayMouseDown,
635
+ onDayMouseUp,
636
+ onDayTouchEnd,
637
+ onDayTouchStart,
638
+ modifiers,
639
+ highlightedDays,
640
+ format: formatProp,
641
+ initialTime: initialTimeInputProp,
642
+ initialMonth: initialMonthInputProp
643
+ } = _ref,
644
+ dayPickerProps = _objectWithoutProperties(_ref, _excluded);
677
645
  var styles = useStyles({
678
646
  classes
679
647
  });
@@ -685,15 +653,12 @@ var Calendar = /*#__PURE__*/react.forwardRef((_ref, ref) => {
685
653
  var [initialTime, initialMonth] = react.useMemo(() => {
686
654
  var time = initialTimeInput;
687
655
  var month = initialMonthInput;
688
-
689
656
  if (!month.isValid) {
690
657
  month = luxon.DateTime.local().startOf('month');
691
658
  }
692
-
693
659
  if (!time.isValid) {
694
660
  time = month;
695
661
  }
696
-
697
662
  return [time, new Date(month.year, month.month - 1, month.day, month.hour, month.minute, month.second, month.millisecond)];
698
663
  }, [initialTimeInput, initialMonthInput]);
699
664
  var wrapModifier = toDayPickerModifier.bind(null, config);
@@ -712,19 +677,16 @@ var Calendar = /*#__PURE__*/react.forwardRef((_ref, ref) => {
712
677
  return dateValue.day === dateValue.daysInMonth;
713
678
  })
714
679
  };
715
-
716
680
  if (modifiers) {
717
681
  for (var [key, modifier] of Object.entries(modifiers)) {
718
682
  dayPickerModifiers[key] = wrapModifier(modifier);
719
683
  }
720
684
  }
721
-
722
685
  if (highlightedDays) {
723
686
  for (var [_key, _modifier] of Object.entries(highlightedDays)) {
724
687
  dayPickerModifiers[styles[_key]] = wrapModifier(_modifier);
725
688
  }
726
689
  }
727
-
728
690
  return /*#__PURE__*/jsxRuntime.jsxs(core.Grid, {
729
691
  ref: ref,
730
692
  container: true,
@@ -822,41 +784,38 @@ var Popover = /*#__PURE__*/styled(core.Popover).withConfig({
822
784
  })([".MuiPaper-rounded{border:1px solid ", ";box-shadow:0px 0px 4px 0px rgba(0,0,0,0.05),0px 4px 8px 0px rgba(0,0,0,0.12);}"], ui.Color.Silver400);
823
785
  var BaseDatePicker = /*#__PURE__*/react.forwardRef((_ref, ref) => {
824
786
  var {
825
- id,
826
- api,
827
- onClear,
828
- onClick: _onClick,
829
- onClose,
830
- onKeyDown: _onKeyDown,
831
- disabled,
832
- children,
833
- enableClearable,
834
- inputRef: inputRefProp,
835
- InputProps: inputProps
836
- } = _ref,
837
- textFieldProps = _objectWithoutProperties(_ref, _excluded$1);
838
-
787
+ id,
788
+ api,
789
+ onClear,
790
+ onClick: _onClick,
791
+ onClose,
792
+ onKeyDown: _onKeyDown,
793
+ disabled,
794
+ children,
795
+ enableClearable,
796
+ inputRef: inputRefProp,
797
+ InputProps: inputProps
798
+ } = _ref,
799
+ textFieldProps = _objectWithoutProperties(_ref, _excluded$1);
839
800
  var uid = ui.useUID(id);
840
801
  var labelID = "".concat(uid, "-label");
841
802
  var clearIconID = "".concat(uid, "-clear-icon");
842
803
  var inputRef = react.useRef(null);
843
804
  var textFieldRef = react.useRef(null);
844
805
  var [popoverAnchor, setPopoverAnchor] = react.useState(null);
845
-
846
806
  function handleOpen() {
847
807
  if (!disabled && textFieldRef.current) {
848
808
  setPopoverAnchor(textFieldRef.current);
849
809
  }
850
810
  }
851
-
852
811
  function handleClose() {
853
812
  setPopoverAnchor(null);
854
813
  }
855
-
856
814
  react.useImperativeHandle(api, () => ({
857
815
  close: handleClose
858
- })); // We want to trigger close event only when UI will be ready after updates.
816
+ }));
859
817
 
818
+ // We want to trigger close event only when UI will be ready after updates.
860
819
  hooks.useValueObserver(popoverAnchor, () => {
861
820
  if (!popoverAnchor) {
862
821
  onClose === null || onClose === void 0 ? void 0 : onClose();
@@ -883,14 +842,12 @@ var BaseDatePicker = /*#__PURE__*/react.forwardRef((_ref, ref) => {
883
842
  inputRef: ui.mergeRefs(inputRef, inputRefProp),
884
843
  onClick: event => {
885
844
  _onClick === null || _onClick === void 0 ? void 0 : _onClick(event);
886
-
887
845
  if (!event.defaultPrevented) {
888
846
  handleOpen();
889
847
  }
890
848
  },
891
849
  onKeyDown: event => {
892
850
  _onKeyDown === null || _onKeyDown === void 0 ? void 0 : _onKeyDown(event);
893
-
894
851
  if (!event.defaultPrevented && (event.key === ' ' || event.key === 'Enter')) {
895
852
  handleOpen();
896
853
  }
@@ -929,14 +886,13 @@ var BaseDatePicker = /*#__PURE__*/react.forwardRef((_ref, ref) => {
929
886
  if (process.env.NODE_ENV !== "production") BaseDatePicker.displayName = "BaseDatePicker";
930
887
 
931
888
  var _excluded$2 = ["variant", "fallback"],
932
- _excluded2 = ["date", "fallback"];
889
+ _excluded2 = ["date", "fallback"];
933
890
  function useFormattedDate(input, _ref) {
934
891
  var {
935
- variant,
936
- fallback
937
- } = _ref,
938
- dateConfig = _objectWithoutProperties(_ref, _excluded$2);
939
-
892
+ variant,
893
+ fallback
894
+ } = _ref,
895
+ dateConfig = _objectWithoutProperties(_ref, _excluded$2);
940
896
  var config = useDateConfig(dateConfig);
941
897
  var date = useDateTime(input, config);
942
898
  return react.useMemo(() => formatDate(date, {
@@ -946,11 +902,10 @@ function useFormattedDate(input, _ref) {
946
902
  }
947
903
  function FormattedDate(_ref2) {
948
904
  var {
949
- date,
950
- fallback = 'Invalid Date'
951
- } = _ref2,
952
- options = _objectWithoutProperties(_ref2, _excluded2);
953
-
905
+ date,
906
+ fallback = 'Invalid Date'
907
+ } = _ref2,
908
+ options = _objectWithoutProperties(_ref2, _excluded2);
954
909
  var formatted = useFormattedDate(date, _objectSpread(_objectSpread({}, options), {}, {
955
910
  fallback: ''
956
911
  }));
@@ -958,27 +913,26 @@ function FormattedDate(_ref2) {
958
913
  }
959
914
 
960
915
  var _excluded$3 = ["onDayClick"],
961
- _excluded2$1 = ["onBlur", "onFocus", "onChange", "renderFooter", "renderQuickSelection", "value", "format", "fallback", "variant", "enableClearable", "disableCloseOnSelect", "CalendarProps"];
916
+ _excluded2$1 = ["onBlur", "onFocus", "onChange", "renderFooter", "renderQuickSelection", "value", "format", "fallback", "variant", "enableClearable", "disableCloseOnSelect", "CalendarProps"];
962
917
  var DateField = /*#__PURE__*/react.forwardRef((_ref, ref) => {
963
918
  var {
964
- onBlur,
965
- onFocus,
966
- onChange,
967
- renderFooter,
968
- renderQuickSelection,
969
- value: valueProp,
970
- format: formatProp,
971
- fallback = '',
972
- variant = 'Date',
973
- enableClearable,
974
- disableCloseOnSelect,
975
- CalendarProps: {
976
- onDayClick: _onDayClick
977
- } = {}
978
- } = _ref,
979
- calendarProps = _objectWithoutProperties(_ref.CalendarProps, _excluded$3),
980
- textFieldProps = _objectWithoutProperties(_ref, _excluded2$1);
981
-
919
+ onBlur,
920
+ onFocus,
921
+ onChange,
922
+ renderFooter,
923
+ renderQuickSelection,
924
+ value: valueProp,
925
+ format: formatProp,
926
+ fallback = '',
927
+ variant = 'Date',
928
+ enableClearable,
929
+ disableCloseOnSelect,
930
+ CalendarProps: {
931
+ onDayClick: _onDayClick
932
+ } = {}
933
+ } = _ref,
934
+ calendarProps = _objectWithoutProperties(_ref.CalendarProps, _excluded$3),
935
+ textFieldProps = _objectWithoutProperties(_ref, _excluded2$1);
982
936
  var config = useDateConfig({
983
937
  format: formatProp
984
938
  });
@@ -989,23 +943,18 @@ var DateField = /*#__PURE__*/react.forwardRef((_ref, ref) => {
989
943
  fallback
990
944
  }, config));
991
945
  var dateString = react.useMemo(() => stringifyDate(date, config), [date, config]);
992
-
993
946
  function handleClose() {
994
947
  var _apiRef$current;
995
-
996
948
  (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 ? void 0 : _apiRef$current.close();
997
949
  }
998
-
999
950
  function handleChange(nextInput) {
1000
951
  if (onChange) {
1001
952
  onChange(toDatePayload(nextInput, config));
1002
953
  }
1003
-
1004
954
  if (!disableCloseOnSelect) {
1005
955
  handleClose();
1006
956
  }
1007
957
  }
1008
-
1009
958
  var api = {
1010
959
  config,
1011
960
  dateValue: date,
@@ -1034,7 +983,6 @@ var DateField = /*#__PURE__*/react.forwardRef((_ref, ref) => {
1034
983
  },
1035
984
  onDayClick: event => {
1036
985
  _onDayClick === null || _onDayClick === void 0 ? void 0 : _onDayClick(event);
1037
-
1038
986
  if (!event.disabled) {
1039
987
  handleChange(event.dateValue);
1040
988
  }
@@ -1053,8 +1001,8 @@ function useDateTimeRange(input, options) {
1053
1001
  }
1054
1002
 
1055
1003
  var _excluded$4 = ["modifiers", "onDayClick", "onDayMouseEnter"],
1056
- _excluded2$2 = ["onBlur", "onFocus", "onChange", "renderFooter", "renderQuickSelection", "value", "format", "fallback", "enableClearable", "disableCloseOnSelect", "CalendarProps"],
1057
- _excluded3 = ["rangeStart", "rangeFinish"];
1004
+ _excluded2$2 = ["onBlur", "onFocus", "onChange", "renderFooter", "renderQuickSelection", "value", "format", "fallback", "enableClearable", "disableCloseOnSelect", "CalendarProps"],
1005
+ _excluded3 = ["rangeStart", "rangeFinish"];
1058
1006
  var useStyles$1 = /*#__PURE__*/styles.makeStyles(theme => ({
1059
1007
  rangeStart: {},
1060
1008
  rangeFinish: {},
@@ -1092,34 +1040,31 @@ var useStyles$1 = /*#__PURE__*/styles.makeStyles(theme => ({
1092
1040
  });
1093
1041
  var DateRangeField = /*#__PURE__*/react.forwardRef((_ref, ref) => {
1094
1042
  var {
1095
- onBlur,
1096
- onFocus,
1097
- onChange,
1098
- renderFooter,
1099
- renderQuickSelection,
1100
- value: valueProp,
1101
- format: formatProp,
1102
- fallback = '',
1103
- enableClearable,
1104
- disableCloseOnSelect,
1105
- CalendarProps: {
1106
- modifiers,
1107
- onDayClick: _onDayClick,
1108
- onDayMouseEnter: _onDayMouseEnter
1109
- } = {}
1110
- } = _ref,
1111
- calendarProps = _objectWithoutProperties(_ref.CalendarProps, _excluded$4),
1112
- textFieldProps = _objectWithoutProperties(_ref, _excluded2$2);
1113
-
1043
+ onBlur,
1044
+ onFocus,
1045
+ onChange,
1046
+ renderFooter,
1047
+ renderQuickSelection,
1048
+ value: valueProp,
1049
+ format: formatProp,
1050
+ fallback = '',
1051
+ enableClearable,
1052
+ disableCloseOnSelect,
1053
+ CalendarProps: {
1054
+ modifiers,
1055
+ onDayClick: _onDayClick,
1056
+ onDayMouseEnter: _onDayMouseEnter
1057
+ } = {}
1058
+ } = _ref,
1059
+ calendarProps = _objectWithoutProperties(_ref.CalendarProps, _excluded$4),
1060
+ textFieldProps = _objectWithoutProperties(_ref, _excluded2$2);
1114
1061
  var apiRef = react.useRef(null);
1115
-
1116
1062
  var _useStyles = useStyles$1({}),
1117
- {
1118
- rangeStart,
1119
- rangeFinish
1120
- } = _useStyles,
1121
- styles = _objectWithoutProperties(_useStyles, _excluded3);
1122
-
1063
+ {
1064
+ rangeStart,
1065
+ rangeFinish
1066
+ } = _useStyles,
1067
+ styles = _objectWithoutProperties(_useStyles, _excluded3);
1123
1068
  var config = useDateConfig({
1124
1069
  format: formatProp
1125
1070
  });
@@ -1133,18 +1078,13 @@ var DateRangeField = /*#__PURE__*/react.forwardRef((_ref, ref) => {
1133
1078
  var [nextCalendarStartDate, nextCalendarFinishDate] = parseDateRange([startDate, finishDate || hoveredDate], config);
1134
1079
  return [nextCalendarStartDate === null || nextCalendarStartDate === void 0 ? void 0 : nextCalendarStartDate.startOf('day'), nextCalendarFinishDate === null || nextCalendarFinishDate === void 0 ? void 0 : nextCalendarFinishDate.endOf('day')];
1135
1080
  }, [config, startDate, finishDate, hoveredDate]);
1136
-
1137
1081
  function handleClose() {
1138
1082
  var _apiRef$current;
1139
-
1140
1083
  (_apiRef$current = apiRef.current) === null || _apiRef$current === void 0 ? void 0 : _apiRef$current.close();
1141
1084
  }
1142
-
1143
1085
  function handleChange(nextValue) {
1144
1086
  var _nextFinishDate;
1145
-
1146
1087
  var [nextStartDate, nextFinishDate] = parseDateRange(nextValue, config);
1147
-
1148
1088
  if (onChange) {
1149
1089
  if (nextStartDate) {
1150
1090
  if (startDate) {
@@ -1158,19 +1098,15 @@ var DateRangeField = /*#__PURE__*/react.forwardRef((_ref, ref) => {
1158
1098
  nextStartDate = nextStartDate.startOf('day');
1159
1099
  }
1160
1100
  }
1161
-
1162
1101
  if (nextFinishDate) {
1163
1102
  nextFinishDate = nextFinishDate.endOf('day');
1164
1103
  }
1165
-
1166
1104
  onChange(toDateRangePayload([nextStartDate, nextFinishDate], config));
1167
1105
  }
1168
-
1169
1106
  if (!disableCloseOnSelect && (_nextFinishDate = nextFinishDate) !== null && _nextFinishDate !== void 0 && _nextFinishDate.isValid) {
1170
1107
  handleClose();
1171
1108
  }
1172
1109
  }
1173
-
1174
1110
  var api = {
1175
1111
  config,
1176
1112
  close: handleClose,
@@ -1213,15 +1149,12 @@ var DateRangeField = /*#__PURE__*/react.forwardRef((_ref, ref) => {
1213
1149
  var {
1214
1150
  dateValue
1215
1151
  } = _ref4;
1216
-
1217
1152
  if (calendarStartDate) {
1218
1153
  if (!calendarFinishDate) {
1219
1154
  return calendarStartDate.hasSame(dateValue, 'day');
1220
1155
  }
1221
-
1222
1156
  return calendarStartDate <= dateValue && dateValue <= calendarFinishDate;
1223
1157
  }
1224
-
1225
1158
  return false;
1226
1159
  },
1227
1160
  footer: renderFooter === null || renderFooter === void 0 ? void 0 : renderFooter(api),
@@ -1232,7 +1165,6 @@ var DateRangeField = /*#__PURE__*/react.forwardRef((_ref, ref) => {
1232
1165
  },
1233
1166
  onDayClick: event => {
1234
1167
  _onDayClick === null || _onDayClick === void 0 ? void 0 : _onDayClick(event);
1235
-
1236
1168
  if (!event.disabled) {
1237
1169
  if (startDate && !finishDate) {
1238
1170
  handleChange([startDateString, event.stringValue]);
@@ -1250,69 +1182,88 @@ if (process.env.NODE_ENV !== "production") DateRangeField.displayName = "DateRan
1250
1182
 
1251
1183
  /** @deprecated */
1252
1184
 
1185
+ /** @deprecated */
1186
+
1187
+ /** @deprecated */
1188
+
1189
+ /** @deprecated */
1190
+
1191
+ /** @deprecated */
1192
+
1193
+ /** @deprecated */
1194
+
1195
+ /** @deprecated */
1196
+
1197
+ /** @deprecated */
1198
+
1199
+ /** @deprecated */
1200
+
1201
+ /** @deprecated */
1253
1202
  function toDateTime(value) {
1254
1203
  return typeof value === 'number' ? luxon.DateTime.fromMillis(value) : luxon.DateTime.fromJSDate(value);
1255
1204
  }
1256
- /** @deprecated */
1257
-
1258
1205
 
1206
+ /** @deprecated */
1259
1207
  function isDate(value) {
1260
1208
  return value != null && value instanceof Date;
1261
1209
  }
1262
- /** @deprecated */
1263
1210
 
1211
+ /** @deprecated */
1264
1212
  function isDateLike(value) {
1265
1213
  return isDate(value) || typeof value === 'number' && Number.isInteger(value);
1266
1214
  }
1267
- /** @deprecated */
1268
1215
 
1216
+ /** @deprecated */
1269
1217
  function isValidDate(value) {
1270
1218
  return isDate(value) && Number.isFinite(value.getTime());
1271
1219
  }
1272
- /** @deprecated */
1273
1220
 
1221
+ /** @deprecated */
1274
1222
  function checkRange(range, validator) {
1275
1223
  if (!Array.isArray(range) || range.length > 2) {
1276
1224
  return false;
1277
1225
  }
1278
-
1279
1226
  var [start, finish] = range;
1280
1227
  return (start == null || validator(start)) && (finish == null || validator(finish));
1281
1228
  }
1282
- /** @deprecated */
1283
-
1284
1229
 
1230
+ /** @deprecated */
1285
1231
  function isDateRange(range) {
1286
1232
  return checkRange(range, isDate);
1287
1233
  }
1288
- /** @deprecated */
1289
1234
 
1235
+ /** @deprecated */
1290
1236
  function isDateRangeLike(range) {
1291
1237
  return checkRange(range, isDateLike);
1292
1238
  }
1293
- /** @deprecated */
1294
1239
 
1240
+ /** @deprecated */
1295
1241
  function isValidDateRange(range) {
1296
1242
  return checkRange(range, isValidDate);
1297
1243
  }
1298
- /** @deprecated */
1299
1244
 
1245
+ /** @deprecated */
1300
1246
  function toDate(value) {
1301
1247
  return !isDateLike(value) ? new Date(NaN) : new Date(value);
1302
1248
  }
1303
- /** @deprecated */
1304
1249
 
1250
+ /** @deprecated */
1305
1251
  function toDateRange(range) {
1306
1252
  if (range == null || !isDateRangeLike(range)) {
1307
1253
  return [];
1308
1254
  }
1309
-
1310
1255
  return range.filter(x => x != null).map(x => x == null ? undefined : toDate(x)).sort((a, b) => !isValidDate(a) ? -1 : !isValidDate(b) ? 1 : a.valueOf() - b.valueOf());
1311
1256
  }
1257
+
1258
+ /** @deprecated */
1259
+
1312
1260
  /** @deprecated */
1313
1261
 
1314
1262
  /** @deprecated */
1315
1263
 
1264
+ /** @deprecated */
1265
+
1266
+ /** @deprecated */
1316
1267
  class DateUtils {
1317
1268
  /** @deprecated */
1318
1269
  toObject(value) {
@@ -1337,9 +1288,8 @@ class DateUtils {
1337
1288
  millisecond
1338
1289
  };
1339
1290
  }
1340
- /** @deprecated */
1341
-
1342
1291
 
1292
+ /** @deprecated */
1343
1293
  fromObject(_ref) {
1344
1294
  var {
1345
1295
  year = 0,
@@ -1350,11 +1300,9 @@ class DateUtils {
1350
1300
  second = 0,
1351
1301
  millisecond = 0
1352
1302
  } = _ref;
1353
-
1354
1303
  if (Number.isNaN(year) || Number.isNaN(month) || Number.isNaN(day) || Number.isNaN(hour) || Number.isNaN(minute) || Number.isNaN(second) || Number.isNaN(millisecond)) {
1355
1304
  return new Date(NaN);
1356
1305
  }
1357
-
1358
1306
  return luxon.DateTime.fromObject({
1359
1307
  year,
1360
1308
  month,
@@ -1365,15 +1313,13 @@ class DateUtils {
1365
1313
  millisecond
1366
1314
  }).toJSDate();
1367
1315
  }
1368
- /** @deprecated */
1369
-
1370
1316
 
1317
+ /** @deprecated */
1371
1318
  update(value, values) {
1372
1319
  return toDateTime(value).set(values).toJSDate();
1373
1320
  }
1374
- /** @deprecated */
1375
-
1376
1321
 
1322
+ /** @deprecated */
1377
1323
  mergeDateAndTime(date, time) {
1378
1324
  var {
1379
1325
  hour,
@@ -1381,11 +1327,9 @@ class DateUtils {
1381
1327
  second,
1382
1328
  millisecond
1383
1329
  } = this.toObject(time);
1384
-
1385
1330
  if (Number.isNaN(hour) || Number.isNaN(minute) || Number.isNaN(second) || Number.isNaN(millisecond)) {
1386
1331
  return new Date(NaN);
1387
1332
  }
1388
-
1389
1333
  return this.update(date, {
1390
1334
  hour,
1391
1335
  minute,
@@ -1393,73 +1337,61 @@ class DateUtils {
1393
1337
  millisecond
1394
1338
  });
1395
1339
  }
1396
- /** @deprecated */
1397
-
1398
1340
 
1341
+ /** @deprecated */
1399
1342
  startOf(value, unit) {
1400
1343
  return toDateTime(value).startOf(unit).toJSDate();
1401
1344
  }
1402
- /** @deprecated */
1403
-
1404
1345
 
1346
+ /** @deprecated */
1405
1347
  endOf(value, unit) {
1406
1348
  return toDateTime(value).endOf(unit).toJSDate();
1407
1349
  }
1408
- /** @deprecated */
1409
-
1410
1350
 
1351
+ /** @deprecated */
1411
1352
  plus(value, values) {
1412
1353
  return toDateTime(value).plus(values).toJSDate();
1413
1354
  }
1414
- /** @deprecated */
1415
-
1416
1355
 
1356
+ /** @deprecated */
1417
1357
  minus(value, values) {
1418
1358
  return toDateTime(value).minus(values).toJSDate();
1419
1359
  }
1420
- /** @deprecated */
1421
-
1422
1360
 
1361
+ /** @deprecated */
1423
1362
  isSameDate(value, compare) {
1424
1363
  var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'millisecond';
1425
-
1426
1364
  if (value == null && compare == null) {
1427
1365
  return true;
1428
1366
  }
1429
-
1430
1367
  if (value == null || compare == null) {
1431
1368
  return false;
1432
1369
  }
1433
-
1434
1370
  var dateTimeValue = toDateTime(value);
1435
1371
  var dateTimeCompare = toDateTime(compare);
1436
1372
  return dateTimeValue.isValid && dateTimeCompare.isValid && dateTimeValue.startOf(unit).equals(dateTimeCompare.startOf(unit));
1437
1373
  }
1438
- /** @deprecated */
1439
-
1440
1374
 
1375
+ /** @deprecated */
1441
1376
  isSameDateRange(value, compare, unit) {
1442
1377
  var range1 = toDateRange(value);
1443
1378
  var range2 = toDateRange(compare);
1444
1379
  return !range1.some((date, idx) => !this.isSameDate(date, range2[idx], unit));
1445
1380
  }
1446
- /** @deprecated */
1447
-
1448
1381
 
1382
+ /** @deprecated */
1449
1383
  diff(value, compare, unit) {
1450
1384
  var valueDateTime = toDateTime(value);
1451
1385
  var compareDateTime = toDateTime(compare);
1452
1386
  return valueDateTime.diff(compareDateTime, unit).as(unit);
1453
1387
  }
1454
- /** @deprecated */
1455
-
1456
1388
 
1389
+ /** @deprecated */
1457
1390
  toLocaleString(value, options) {
1458
1391
  return toDateTime(value).toLocaleString(options);
1459
1392
  }
1460
- /** @deprecated */
1461
-
1462
1393
 
1394
+ /** @deprecated */
1463
1395
  format(value, variant) {
1464
1396
  return this.toLocaleString(value, variant === 'date' ? {
1465
1397
  day: '2-digit',
@@ -1479,30 +1411,24 @@ class DateUtils {
1479
1411
  minute: 'numeric'
1480
1412
  });
1481
1413
  }
1482
- /** @deprecated */
1483
-
1484
1414
 
1415
+ /** @deprecated */
1485
1416
  formatRange(value) {
1486
1417
  var emptyText = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
1487
1418
  var range = toDateRange(value);
1488
-
1489
1419
  if (!isValidDateRange(range)) {
1490
1420
  return 'Invalid Date Range';
1491
1421
  }
1492
-
1493
1422
  var [start, finish] = range;
1494
-
1495
1423
  if (!start) {
1496
1424
  return emptyText;
1497
1425
  }
1498
-
1499
1426
  var startText = this.format(start, !this.isSameDate(start, finish, 'year') ? 'date' : 'shortDate');
1500
1427
  var finishText = !finish ? '…' : this.format(finish, 'date');
1501
1428
  return "".concat(startText, " - ").concat(finishText);
1502
1429
  }
1503
- /** @deprecated */
1504
-
1505
1430
 
1431
+ /** @deprecated */
1506
1432
  formatRelativeTime(value) {
1507
1433
  var {
1508
1434
  style = 'long',
@@ -1515,25 +1441,23 @@ class DateUtils {
1515
1441
  base: compareDateTime
1516
1442
  });
1517
1443
  }
1518
-
1519
1444
  }
1520
1445
  function useDateUtils() {
1521
1446
  return react.useMemo(() => new DateUtils(), []);
1522
1447
  }
1523
1448
 
1524
1449
  var _excluded$5 = ["unit", "round", "padding", "fallback", "base"],
1525
- _excluded2$3 = ["date", "fallback"];
1450
+ _excluded2$3 = ["date", "fallback"];
1526
1451
  function useFormattedRelativeTime(input) {
1527
1452
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
1528
- {
1529
- unit,
1530
- round,
1531
- padding,
1532
- fallback,
1533
- base: baseOption
1534
- } = _ref,
1535
- dateConfig = _objectWithoutProperties(_ref, _excluded$5);
1536
-
1453
+ {
1454
+ unit,
1455
+ round,
1456
+ padding,
1457
+ fallback,
1458
+ base: baseOption
1459
+ } = _ref,
1460
+ dateConfig = _objectWithoutProperties(_ref, _excluded$5);
1537
1461
  var config = useDateConfig(dateConfig);
1538
1462
  var date = useDateTime(input, config);
1539
1463
  var baseOptionDate = useDateTime(baseOption, config);
@@ -1548,11 +1472,10 @@ function useFormattedRelativeTime(input) {
1548
1472
  }
1549
1473
  function FormattedRelativeTime(_ref2) {
1550
1474
  var {
1551
- date,
1552
- fallback = 'Invalid Date'
1553
- } = _ref2,
1554
- options = _objectWithoutProperties(_ref2, _excluded2$3);
1555
-
1475
+ date,
1476
+ fallback = 'Invalid Date'
1477
+ } = _ref2,
1478
+ options = _objectWithoutProperties(_ref2, _excluded2$3);
1556
1479
  var formatted = useFormattedRelativeTime(date, _objectSpread(_objectSpread({}, options), {}, {
1557
1480
  fallback: ''
1558
1481
  }));
@@ -1561,7 +1484,6 @@ function FormattedRelativeTime(_ref2) {
1561
1484
 
1562
1485
  var _excluded$6 = ["disabled", "onChange", "value", "format"];
1563
1486
  var TIME_MATCH_FORMATS = ['h:mm a', 'h:mma', 'H:mm', 'h:mm', 'hmm', 'Hmm', 'h', 'H'];
1564
-
1565
1487
  function toTimeFieldOption(date, config) {
1566
1488
  return {
1567
1489
  value: date.valueOf(),
@@ -1571,52 +1493,42 @@ function toTimeFieldOption(date, config) {
1571
1493
  pattern: new RegExp("^(".concat(TIME_MATCH_FORMATS.map(format => date.toFormat(format)).join('|'), ")"), 'i')
1572
1494
  };
1573
1495
  }
1574
-
1575
1496
  function normalizeInputValue(inputValue) {
1576
1497
  return inputValue.replace(/[\s]/g, '').toLowerCase();
1577
1498
  }
1578
-
1579
1499
  function makeOptions(config) {
1580
1500
  var options = [];
1581
1501
  var now = luxon.DateTime.local().startOf('day');
1582
-
1583
1502
  for (var i = 0; i < 96; i++) {
1584
1503
  options.push(toTimeFieldOption(now.set({
1585
1504
  minute: i * 15
1586
1505
  }), config));
1587
1506
  }
1588
-
1589
1507
  var cache = new Map();
1590
1508
  return [options, (_, _ref) => {
1591
1509
  var {
1592
1510
  inputValue
1593
1511
  } = _ref;
1594
1512
  var query = normalizeInputValue(inputValue);
1595
-
1596
1513
  if (!query) {
1597
1514
  return options;
1598
1515
  }
1599
-
1600
1516
  var filtered = cache.get(query);
1601
-
1602
1517
  if (!filtered) {
1603
1518
  filtered = options.filter(option => option.pattern.test(query));
1604
1519
  cache.set(query, filtered);
1605
1520
  }
1606
-
1607
1521
  return filtered;
1608
1522
  }];
1609
1523
  }
1610
-
1611
1524
  var TimeField = /*#__PURE__*/react.forwardRef((_ref2, ref) => {
1612
1525
  var {
1613
- disabled,
1614
- onChange,
1615
- value: valueProp,
1616
- format: formatProp
1617
- } = _ref2,
1618
- props = _objectWithoutProperties(_ref2, _excluded$6);
1619
-
1526
+ disabled,
1527
+ onChange,
1528
+ value: valueProp,
1529
+ format: formatProp
1530
+ } = _ref2,
1531
+ props = _objectWithoutProperties(_ref2, _excluded$6);
1620
1532
  var config = useDateConfig({
1621
1533
  format: formatProp
1622
1534
  });
@@ -1624,19 +1536,15 @@ var TimeField = /*#__PURE__*/react.forwardRef((_ref2, ref) => {
1624
1536
  var selectedOption = react.useMemo(() => !date.isValid ? undefined : toTimeFieldOption(date, config), [date, config]);
1625
1537
  var [options, filterOptions] = react.useMemo(() => makeOptions(config), [config]);
1626
1538
  var [inputValue, setInputValue] = react.useState('');
1627
-
1628
1539
  function handleChange(nextValue) {
1629
1540
  if (onChange) {
1630
1541
  onChange(toDatePayload(nextValue, config));
1631
1542
  }
1632
1543
  }
1633
-
1634
1544
  function handleType(text) {
1635
1545
  text = normalizeInputValue(text);
1636
-
1637
1546
  for (var timeFormat of TIME_MATCH_FORMATS) {
1638
1547
  var nextDate = luxon.DateTime.fromFormat(text, timeFormat);
1639
-
1640
1548
  if (nextDate.isValid) {
1641
1549
  if (onChange) {
1642
1550
  if (date.isValid) {
@@ -1646,17 +1554,13 @@ var TimeField = /*#__PURE__*/react.forwardRef((_ref2, ref) => {
1646
1554
  day: date.day
1647
1555
  });
1648
1556
  }
1649
-
1650
1557
  onChange(toDatePayload(nextDate, config));
1651
1558
  }
1652
-
1653
1559
  return;
1654
1560
  }
1655
1561
  }
1656
-
1657
1562
  setInputValue((selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) || '');
1658
1563
  }
1659
-
1660
1564
  react.useEffect(() => {
1661
1565
  if (!date.isValid) {
1662
1566
  setInputValue('');