@geotab/zenith 3.17.1-beta.0 → 3.17.1-beta.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.
Files changed (35) hide show
  1. package/README.md +1 -0
  2. package/dist/calendar/components/calendarGrid.d.ts +3 -1
  3. package/dist/calendar/components/calendarGrid.js +8 -3
  4. package/dist/calendar/hooks/useTouchTap.d.ts +9 -0
  5. package/dist/calendar/hooks/useTouchTap.js +28 -0
  6. package/dist/calendarNew/components/template.js +2 -1
  7. package/dist/dateInputRawNew/hooks/useDateInputRawNew.js +14 -3
  8. package/dist/datePickerCommon/utils/isTypedDateAllowed.d.ts +12 -0
  9. package/dist/datePickerCommon/utils/isTypedDateAllowed.js +21 -0
  10. package/dist/dateRangeInnerNew/components/template.js +11 -7
  11. package/dist/dateRangeRawNew/hooks/useDateRangeNewParts.js +4 -0
  12. package/dist/dateRangeRawNew/hooks/useRangeEntry.d.ts +5 -1
  13. package/dist/dateRangeRawNew/hooks/useRangeEntry.js +24 -16
  14. package/dist/dateRangeRawNew/utils/applyRangeLocks.d.ts +6 -0
  15. package/dist/dateRangeRawNew/utils/applyRangeLocks.js +14 -0
  16. package/dist/dateRangeRawNew/utils/pinLockedEnds.d.ts +3 -0
  17. package/dist/dateRangeRawNew/utils/pinLockedEnds.js +9 -0
  18. package/dist/index.css +3 -0
  19. package/esm/calendar/components/calendarGrid.d.ts +3 -1
  20. package/esm/calendar/components/calendarGrid.js +8 -3
  21. package/esm/calendar/hooks/useTouchTap.d.ts +9 -0
  22. package/esm/calendar/hooks/useTouchTap.js +24 -0
  23. package/esm/calendarNew/components/template.js +2 -1
  24. package/esm/dateInputRawNew/hooks/useDateInputRawNew.js +14 -3
  25. package/esm/datePickerCommon/utils/isTypedDateAllowed.d.ts +12 -0
  26. package/esm/datePickerCommon/utils/isTypedDateAllowed.js +17 -0
  27. package/esm/dateRangeInnerNew/components/template.js +12 -8
  28. package/esm/dateRangeRawNew/hooks/useDateRangeNewParts.js +4 -0
  29. package/esm/dateRangeRawNew/hooks/useRangeEntry.d.ts +5 -1
  30. package/esm/dateRangeRawNew/hooks/useRangeEntry.js +24 -16
  31. package/esm/dateRangeRawNew/utils/applyRangeLocks.d.ts +6 -0
  32. package/esm/dateRangeRawNew/utils/applyRangeLocks.js +10 -0
  33. package/esm/dateRangeRawNew/utils/pinLockedEnds.d.ts +3 -0
  34. package/esm/dateRangeRawNew/utils/pinLockedEnds.js +5 -0
  35. package/package.json +4 -1
package/README.md CHANGED
@@ -55,6 +55,7 @@ Zenith library provides components defined in Zenith Design System. It includes
55
55
  - [MYG-151577](https://geotab.atlassian.net/browse/MYG-151577): allow an inline loading spinner in place of the Banner icon.
56
56
  - [MYG-121322](https://geotab.atlassian.net/browse/MYG-121322): revise the date picker to match the new visual styling and interaction design.
57
57
  - [MYG-145390](https://geotab.atlassian.net/browse/MYG-145390): prevent `FiltersBarPeriodPicker` from firing `onChange` before a Custom date range is applied.
58
+ - [MYG-155693](https://geotab.atlassian.net/browse/MYG-155693): enforce typed-date limits and locked range endpoints, keep mobile time edits in order, prevent touch-scroll selection, respect user time zones, and preserve the calendar-only mobile layout.
58
59
 
59
60
  ### 3.17.0
60
61
 
@@ -4,6 +4,8 @@ type ICalendarGrid = Pick<ICalendarContext, "id" | "dates" | "monthStart" | "mon
4
4
  hideOtherMonthDates?: boolean;
5
5
  /** The day to mark as today, as a Date that reads as the user's wall clock; the browser's day when absent. */
6
6
  today?: Date;
7
+ /** A touch selects a day when released on it instead of when it lands, so scrolling the month list does not select. */
8
+ selectTouchOnRelease?: boolean;
7
9
  };
8
- export declare const CalendarGrid: ({ id, dates, monthStart, monthEnd, fromDate, toDate, hoverDate, rangePreview, previewRangeOnHover, focusDate, viewDate, dateRangeMode, isMobileView, isTabStop, currentActiveField, memoizedVisibleFocus, getDayOfWeek, fullDayLabels, isDisabledDay, onPointerDown, handleDateKeyDown, setHoverDate, handleFocusDateChange, getBeforeDecorator, getAfterDecorator, translate, hideThead, hideOtherMonthDates, today }: ICalendarGrid) => import("react/jsx-runtime").JSX.Element;
10
+ export declare const CalendarGrid: ({ id, dates, monthStart, monthEnd, fromDate, toDate, hoverDate, rangePreview, previewRangeOnHover, focusDate, viewDate, dateRangeMode, isMobileView, isTabStop, currentActiveField, memoizedVisibleFocus, getDayOfWeek, fullDayLabels, isDisabledDay, onPointerDown, handleDateKeyDown, setHoverDate, handleFocusDateChange, getBeforeDecorator, getAfterDecorator, translate, hideThead, hideOtherMonthDates, today, selectTouchOnRelease }: ICalendarGrid) => import("react/jsx-runtime").JSX.Element;
9
11
  export {};
@@ -4,13 +4,15 @@ exports.CalendarGrid = void 0;
4
4
  const jsx_runtime_1 = require("react/jsx-runtime");
5
5
  const classNames_1 = require("../../commonHelpers/classNames/classNames");
6
6
  const calendarUtils_1 = require("../calendarUtils");
7
+ const useTouchTap_1 = require("../hooks/useTouchTap");
7
8
  const isPreviewEnd = (rangePreview, hoverDate, date, isOtherMonth, isActive) => {
8
9
  if (!rangePreview || isOtherMonth || (date !== rangePreview.from && date !== rangePreview.to))
9
10
  return false;
10
11
  return !!rangePreview.outlineEnds || (date === hoverDate && !isActive);
11
12
  };
12
13
  const isTintedByItself = (isRangeMode, isRowEdge, isInRange, hasFade, isPreviewEndDay) => (isRangeMode && !isRowEdge && isInRange && !hasFade) || isPreviewEndDay;
13
- const CalendarGrid = ({ id, dates, monthStart, monthEnd, fromDate, toDate, hoverDate, rangePreview, previewRangeOnHover, focusDate, viewDate, dateRangeMode, isMobileView, isTabStop, currentActiveField, memoizedVisibleFocus, getDayOfWeek, fullDayLabels, isDisabledDay, onPointerDown, handleDateKeyDown, setHoverDate, handleFocusDateChange, getBeforeDecorator, getAfterDecorator, translate, hideThead = false, hideOtherMonthDates = false, today }) => {
14
+ const CalendarGrid = ({ id, dates, monthStart, monthEnd, fromDate, toDate, hoverDate, rangePreview, previewRangeOnHover, focusDate, viewDate, dateRangeMode, isMobileView, isTabStop, currentActiveField, memoizedVisibleFocus, getDayOfWeek, fullDayLabels, isDisabledDay, onPointerDown, handleDateKeyDown, setHoverDate, handleFocusDateChange, getBeforeDecorator, getAfterDecorator, translate, hideThead = false, hideOtherMonthDates = false, today, selectTouchOnRelease = false }) => {
15
+ const touchTap = (0, useTouchTap_1.useTouchTap)(selectTouchOnRelease, onPointerDown);
14
16
  const todayKey = (0, calendarUtils_1.toDateKey)(today !== null && today !== void 0 ? today : new Date());
15
17
  const tintFrom = rangePreview ? rangePreview.from : fromDate;
16
18
  const tintTo = rangePreview ? rangePreview.to : toDate;
@@ -59,8 +61,11 @@ const CalendarGrid = ({ id, dates, monthStart, monthEnd, fromDate, toDate, hover
59
61
  : ""
60
62
  ]), onPointerDown: evt => {
61
63
  evt.preventDefault();
62
- !isDisabled && !isHidden && evt.button !== 2 && onPointerDown(date, isOtherMonth);
63
- }, onPointerEnter: evt => {
64
+ if (isDisabled || isHidden || evt.button === 2)
65
+ return;
66
+ if (!touchTap.press(evt.pointerType, date))
67
+ onPointerDown(date, isOtherMonth);
68
+ }, onPointerUp: evt => touchTap.release(evt.pointerType, date, isOtherMonth), onPointerCancel: touchTap.cancel, onPointerEnter: evt => {
64
69
  // A touch has no hover; the one it leaves behind would preview a range that was never pointed at.
65
70
  if (previewRangeOnHover && evt.pointerType === "touch")
66
71
  return;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * A finger that lands on a day may be about to scroll the month list, which the browser reports as a cancelled pointer. A touch
3
+ * press therefore waits for its release, and only a release on the day the finger landed on, with no cancel in between, is a tap.
4
+ */
5
+ export declare const useTouchTap: (enabled: boolean, onTap: (date: string, isOtherMonth: boolean) => void) => {
6
+ press: (pointerType: string, date: string) => boolean;
7
+ release: (pointerType: string, date: string, isOtherMonth: boolean) => void;
8
+ cancel: () => void;
9
+ };
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useTouchTap = void 0;
4
+ const react_1 = require("react");
5
+ /**
6
+ * A finger that lands on a day may be about to scroll the month list, which the browser reports as a cancelled pointer. A touch
7
+ * press therefore waits for its release, and only a release on the day the finger landed on, with no cancel in between, is a tap.
8
+ */
9
+ const useTouchTap = (enabled, onTap) => {
10
+ const pressedDate = (0, react_1.useRef)(undefined);
11
+ const press = (0, react_1.useCallback)((pointerType, date) => {
12
+ if (!enabled || pointerType !== "touch")
13
+ return false;
14
+ pressedDate.current = date;
15
+ return true;
16
+ }, [enabled]);
17
+ const release = (0, react_1.useCallback)((pointerType, date, isOtherMonth) => {
18
+ const isTap = enabled && pointerType === "touch" && pressedDate.current === date;
19
+ pressedDate.current = undefined;
20
+ if (isTap)
21
+ onTap(date, isOtherMonth);
22
+ }, [enabled, onTap]);
23
+ const cancel = (0, react_1.useCallback)(() => {
24
+ pressedDate.current = undefined;
25
+ }, []);
26
+ return { press, release, cancel };
27
+ };
28
+ exports.useTouchTap = useTouchTap;
@@ -252,7 +252,8 @@ const Template = ctx => {
252
252
  getDayOfWeek: getDayOfWeek2Letter,
253
253
  hideThead: isMobile,
254
254
  hideOtherMonthDates: hideOtherMonthDates,
255
- today: toLocalDateTime(new Date())
255
+ today: toLocalDateTime(new Date()),
256
+ selectTouchOnRelease: true
256
257
  }))]
257
258
  });
258
259
  };
@@ -15,6 +15,7 @@ const toEditableFormat_1 = require("../../datePickerNew/components/dateSegmentIn
15
15
  const toEditableTimeFormat_1 = require("../../datePickerNew/components/dateSegmentInput/utils/toEditableTimeFormat");
16
16
  const strictDeformatDate_1 = require("../../datePickerNew/utils/strictDeformatDate");
17
17
  const typedDateToIso_1 = require("../../datePickerNew/utils/typedDateToIso");
18
+ const isTypedDateAllowed_1 = require("../../datePickerCommon/utils/isTypedDateAllowed");
18
19
  const formatDate_1 = require("../../utils/formatDate");
19
20
  const userFormatContext_1 = require("../../utils/userFormat/userFormatContext");
20
21
  /** The new picker says "Select date" while empty and labels a value in the time format its segments edit. */
@@ -57,7 +58,11 @@ const useDateInputRawNew = props => {
57
58
  handleApplyClick: applyCore
58
59
  } = ctx;
59
60
  const {
60
- timeSelect
61
+ timeSelect,
62
+ disableFutureDates,
63
+ disablePastDates,
64
+ disableDatesBefore,
65
+ disableDatesAfter
61
66
  } = props;
62
67
  // The segmented trigger is typed into, so it works in a numeric format even when the user's own
63
68
  // format has month or day names; the user's format is kept for how the label reads.
@@ -112,7 +117,13 @@ const useDateInputRawNew = props => {
112
117
  }, [onChange, requireSelection, setCustomDate, setIsOpen, setPrevValue]);
113
118
  const onTriggerTextChange = (0, react_1.useCallback)(text => {
114
119
  const parsed = (0, strictDeformatDate_1.strictDeformatDate)(text, editFormat, translate);
115
- if (!parsed) return;
120
+ const limits = {
121
+ disableFutureDates,
122
+ disablePastDates,
123
+ disableDatesBefore,
124
+ disableDatesAfter
125
+ };
126
+ if (!parsed || !(0, isTypedDateAllowed_1.isTypedDateAllowed)(parsed, limits, toReverseOffsetDateTime)) return;
116
127
  // The typed date names a day in the user's time zone, and the typed time (if any) its hour and minute, like a
117
128
  // value shown through toLocalDateTime; it goes back to an instant through toReverseOffsetDateTime either way.
118
129
  let time;
@@ -131,7 +142,7 @@ const useDateInputRawNew = props => {
131
142
  setCustomDate(iso);
132
143
  setPrevValue(iso);
133
144
  onChange(iso);
134
- }, [customDate, editFormat, onChange, setCustomDate, setPrevValue, timeSelect, toLocalDateTime, toReverseOffsetDateTime, translate, value]);
145
+ }, [customDate, disableDatesAfter, disableDatesBefore, disableFutureDates, disablePastDates, editFormat, onChange, setCustomDate, setPrevValue, timeSelect, toLocalDateTime, toReverseOffsetDateTime, translate, value]);
135
146
  const handleApplyClick = (0, react_1.useCallback)(() => {
136
147
  draftRef.current = undefined;
137
148
  applyCore();
@@ -0,0 +1,12 @@
1
+ export interface ITypedDateLimits {
2
+ disableFutureDates?: boolean;
3
+ disablePastDates?: boolean;
4
+ disableDatesBefore?: string;
5
+ disableDatesAfter?: string;
6
+ }
7
+ /**
8
+ * Whether a day typed into a segmented field may be committed. The calendar disables the days outside the limits, so a
9
+ * typed day goes through the same limits instead of bypassing them. The day names a day on the user's wall clock, and
10
+ * today is neither past nor future whatever the time is now.
11
+ */
12
+ export declare const isTypedDateAllowed: (day: Date, limits: ITypedDateLimits, toReverseOffsetDateTime: (date: Date | string) => Date) => boolean;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTypedDateAllowed = void 0;
4
+ const dateUtils_1 = require("../../calendar/dateUtils");
5
+ /** The last instant of the typed day on the user's wall clock, as a real instant. */
6
+ const getEndOfDay = (day, toReverseOffsetDateTime) => toReverseOffsetDateTime(new Date(day.getFullYear(), day.getMonth(), day.getDate() + 1)).getTime() - 1;
7
+ /**
8
+ * Whether a day typed into a segmented field may be committed. The calendar disables the days outside the limits, so a
9
+ * typed day goes through the same limits instead of bypassing them. The day names a day on the user's wall clock, and
10
+ * today is neither past nor future whatever the time is now.
11
+ */
12
+ const isTypedDateAllowed = (day, limits, toReverseOffsetDateTime) => {
13
+ const startOfDay = toReverseOffsetDateTime(day).getTime();
14
+ const now = Date.now();
15
+ if (limits.disableFutureDates && startOfDay > now)
16
+ return false;
17
+ if (limits.disablePastDates && getEndOfDay(day, toReverseOffsetDateTime) < now)
18
+ return false;
19
+ return !(0, dateUtils_1.isValidationDateError)(day, toReverseOffsetDateTime, false, false, limits.disableDatesBefore, limits.disableDatesAfter);
20
+ };
21
+ exports.isTypedDateAllowed = isTypedDateAllowed;
@@ -271,6 +271,10 @@ const Template = ({
271
271
  presetPreview,
272
272
  setHoveredPill
273
273
  } = (0, usePresetPreview_1.usePresetPreview)(options, toLocalDateTime);
274
+ // The calendar reads a day, and the range it is given, on the user's wall clock, so the limits (real instants) go in the same way
275
+ // useDateInputInner hands them over.
276
+ const calendarDisableDatesBefore = (0, react_1.useMemo)(() => disableDatesBefore ? toLocalDateTime(disableDatesBefore).toISOString() : undefined, [toLocalDateTime, disableDatesBefore]);
277
+ const calendarDisableDatesAfter = (0, react_1.useMemo)(() => disableDatesAfter ? toLocalDateTime(disableDatesAfter).toISOString() : undefined, [toLocalDateTime, disableDatesAfter]);
274
278
  const handlePillChange = (0, react_1.useCallback)(val => {
275
279
  setActivePill(val);
276
280
  if (!val) {
@@ -327,7 +331,7 @@ const Template = ({
327
331
  const banner = adjustedDate && (adjustedDate === "end" ? translate("End date has been adjusted.") : translate("Start date has been adjusted."));
328
332
  if (isMobile) {
329
333
  return (0, jsx_runtime_1.jsxs)("div", {
330
- className: "zen-date-range-inner zen-date-range-inner--new zen-date-range-inner--new-mobile",
334
+ className: `zen-date-range-inner zen-date-range-inner--new zen-date-range-inner--new-mobile${hasPills ? "" : " zen-date-range-inner--no-pills"}`,
331
335
  children: [(0, jsx_runtime_1.jsx)(dayLabelsRow_1.DayLabelsRow, {
332
336
  startDayOfWeek: startDayOfWeek
333
337
  }), (0, jsx_runtime_1.jsx)(virtualMonthList_1.VirtualMonthList, {
@@ -343,8 +347,8 @@ const Template = ({
343
347
  previewRange: presetPreview,
344
348
  disableFutureDates: disableFutureDates,
345
349
  disablePastDates: disablePastDates,
346
- disableDatesBefore: disableDatesBefore,
347
- disableDatesAfter: disableDatesAfter,
350
+ disableDatesBefore: calendarDisableDatesBefore,
351
+ disableDatesAfter: calendarDisableDatesAfter,
348
352
  scrollTrigger: mobileScrollTrigger
349
353
  }), hasPills && (0, jsx_runtime_1.jsx)(pillBar_1.PillBar, {
350
354
  options: pillOptions,
@@ -415,8 +419,8 @@ const Template = ({
415
419
  dateRangeMode: true,
416
420
  disableFutureDates: disableFutureDates,
417
421
  disablePastDates: disablePastDates,
418
- disableDatesAfter: disableDatesAfter,
419
- disableDatesBefore: disableDatesBefore,
422
+ disableDatesAfter: calendarDisableDatesAfter,
423
+ disableDatesBefore: calendarDisableDatesBefore,
420
424
  startDayOfWeek: startDayOfWeek,
421
425
  viewDate: leftViewDate,
422
426
  onViewDateChange: showMonthOf,
@@ -434,8 +438,8 @@ const Template = ({
434
438
  dateRangeMode: true,
435
439
  disableFutureDates: disableFutureDates,
436
440
  disablePastDates: disablePastDates,
437
- disableDatesAfter: disableDatesAfter,
438
- disableDatesBefore: disableDatesBefore,
441
+ disableDatesAfter: calendarDisableDatesAfter,
442
+ disableDatesBefore: calendarDisableDatesBefore,
439
443
  startDayOfWeek: startDayOfWeek,
440
444
  viewDate: rightViewDate,
441
445
  onViewDateChange: showMonthOf,
@@ -30,6 +30,10 @@ const useDateRangeNewParts = ({ isOpen, setIsOpen, isMobile, customDate, setCust
30
30
  isOpen,
31
31
  lockStartDate,
32
32
  lockEndDate,
33
+ disableFutureDates,
34
+ disablePastDates,
35
+ disableDatesBefore,
36
+ disableDatesAfter,
33
37
  timeSelect,
34
38
  dateFormat,
35
39
  timeFormat,
@@ -9,6 +9,10 @@ interface IUseRangeEntry {
9
9
  isOpen: boolean;
10
10
  lockStartDate?: string;
11
11
  lockEndDate?: string;
12
+ disableFutureDates?: boolean;
13
+ disablePastDates?: boolean;
14
+ disableDatesBefore?: string;
15
+ disableDatesAfter?: string;
12
16
  timeSelect?: boolean;
13
17
  dateFormat: string;
14
18
  timeFormat: string;
@@ -21,7 +25,7 @@ interface IUseRangeEntry {
21
25
  * segmented field. Every way ends in the draft range (`customDate`) -- nothing is committed before Apply -- and a way that
22
26
  * has to move the other end to keep the range in order raises the banner that says so.
23
27
  */
24
- export declare const useRangeEntry: ({ customDate, setCustomDate, setSelectedRange, isOpen, lockStartDate, lockEndDate, timeSelect, dateFormat, timeFormat, toLocalDateTime, toReverseOffsetDateTime, translate }: IUseRangeEntry) => {
28
+ export declare const useRangeEntry: ({ customDate, setCustomDate, setSelectedRange, isOpen, lockStartDate, lockEndDate, disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter, timeSelect, dateFormat, timeFormat, toLocalDateTime, toReverseOffsetDateTime, translate }: IUseRangeEntry) => {
25
29
  rangeAdjustment: import("../utils/rangeOrder").TRangeAdjustment;
26
30
  range: {
27
31
  from: string | undefined;
@@ -8,6 +8,9 @@ const toEditableTimeFormat_1 = require("../../datePickerNew/components/dateSegme
8
8
  const parseToSegments_1 = require("../../datePickerNew/components/dateSegmentInput/utils/parseToSegments");
9
9
  const formatDate_1 = require("../../utils/formatDate");
10
10
  const rangeOrder_1 = require("../utils/rangeOrder");
11
+ const applyRangeLocks_1 = require("../utils/applyRangeLocks");
12
+ const pinLockedEnds_1 = require("../utils/pinLockedEnds");
13
+ const isTypedDateAllowed_1 = require("../../datePickerCommon/utils/isTypedDateAllowed");
11
14
  const strictDeformatDate_1 = require("../../datePickerNew/utils/strictDeformatDate");
12
15
  const typedDateToIso_1 = require("../../datePickerNew/utils/typedDateToIso");
13
16
  const useRangeAdjustment_1 = require("./useRangeAdjustment");
@@ -16,7 +19,7 @@ const useRangeAdjustment_1 = require("./useRangeAdjustment");
16
19
  * segmented field. Every way ends in the draft range (`customDate`) -- nothing is committed before Apply -- and a way that
17
20
  * has to move the other end to keep the range in order raises the banner that says so.
18
21
  */
19
- const useRangeEntry = ({ customDate, setCustomDate, setSelectedRange, isOpen, lockStartDate, lockEndDate, timeSelect, dateFormat, timeFormat, toLocalDateTime, toReverseOffsetDateTime, translate }) => {
22
+ const useRangeEntry = ({ customDate, setCustomDate, setSelectedRange, isOpen, lockStartDate, lockEndDate, disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter, timeSelect, dateFormat, timeFormat, toLocalDateTime, toReverseOffsetDateTime, translate }) => {
20
23
  // The banner explains one specific correction, so it is tied to the range that produced it.
21
24
  const { rangeAdjustment, raiseAdjustment } = (0, useRangeAdjustment_1.useRangeAdjustment)(customDate, isOpen);
22
25
  // The calendar reads its range in the browser's zone, and a day clicked in it comes back as the browser's midnight. The
@@ -57,6 +60,15 @@ const useRangeEntry = ({ customDate, setCustomDate, setSelectedRange, isOpen, lo
57
60
  markCustom(next);
58
61
  raiseAdjustment(adjusted, next);
59
62
  }, [customDate, lockEndDate, lockStartDate, markCustom, raiseAdjustment, rebaseToDay, setCustomDate, toLocalDateTime, toReverseOffsetDateTime]);
63
+ // A range edited by hand, dates typed or a time picked, is put in order and a locked end is kept; the banner says when an end moved.
64
+ const commitEdited = (0, react_1.useCallback)((next) => {
65
+ const { range: ordered, adjusted } = (0, rangeOrder_1.resolveRangeOrder)(customDate, (0, pinLockedEnds_1.pinLockedEnds)(next, lockStartDate, lockEndDate), rebaseToDay);
66
+ const locked = (0, applyRangeLocks_1.applyRangeLocks)(customDate, ordered, lockStartDate, lockEndDate);
67
+ setCustomDate(locked);
68
+ markCustom(locked);
69
+ // The banner says an end moved, so it is raised only for an edit that was kept.
70
+ raiseAdjustment(locked === customDate ? undefined : adjusted, locked);
71
+ }, [customDate, lockEndDate, lockStartDate, markCustom, raiseAdjustment, rebaseToDay, setCustomDate]);
60
72
  // A time picked for one end (mobile). Unlike picking a day, the typed time replaces the end's own.
61
73
  const handleTimeSelect = (0, react_1.useCallback)((field, timeText) => {
62
74
  const current = customDate[field];
@@ -69,10 +81,8 @@ const useRangeEntry = ({ customDate, setCustomDate, setSelectedRange, isOpen, lo
69
81
  hours,
70
82
  minutes
71
83
  });
72
- const next = Object.assign(Object.assign({}, customDate), { [field]: iso });
73
- setCustomDate(next);
74
- markCustom(next);
75
- }, [customDate, markCustom, setCustomDate, toLocalDateTime, toReverseOffsetDateTime]);
84
+ commitEdited(Object.assign(Object.assign({}, customDate), { [field]: iso }));
85
+ }, [commitEdited, customDate, toLocalDateTime, toReverseOffsetDateTime]);
76
86
  // The segmented trigger is typed into, so it works in a numeric format even when the user's own
77
87
  // format has month or day names; the user's format is kept for how the label reads.
78
88
  const editFormat = (0, react_1.useMemo)(() => (0, toEditableFormat_1.toEditableFormat)(dateFormat), [dateFormat]);
@@ -95,23 +105,21 @@ const useRangeEntry = ({ customDate, setCustomDate, setSelectedRange, isOpen, lo
95
105
  const parsed = (0, strictDeformatDate_1.strictDeformatDate)(text, triggerFormat, translate);
96
106
  if (!parsed)
97
107
  return undefined;
108
+ // A day outside the limits is not taken: that end stays as it was.
109
+ if (!(0, isTypedDateAllowed_1.isTypedDateAllowed)(parsed, { disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter }, toReverseOffsetDateTime))
110
+ return previous;
98
111
  const { hour, minute } = (0, parseToSegments_1.parseToSegments)(text, triggerFormat);
99
112
  const time = timeSelect && hour !== undefined && minute !== undefined ? { hours: hour, minutes: minute } : undefined;
100
113
  return (0, typedDateToIso_1.typedDateToIso)(parsed, previous, isEnd, toLocalDateTime, toReverseOffsetDateTime, time);
101
114
  };
102
- const { range: ordered, adjusted } = (0, rangeOrder_1.resolveRangeOrder)(customDate, {
103
- from: toIso(next.start, customDate.from, false),
104
- to: toIso(next.end, customDate.to, true)
105
- }, rebaseToDay);
106
- setCustomDate(ordered);
107
- markCustom(ordered);
108
- raiseAdjustment(adjusted, ordered);
115
+ commitEdited({ from: toIso(next.start, customDate.from, false), to: toIso(next.end, customDate.to, true) });
109
116
  }, [
117
+ commitEdited,
110
118
  customDate,
111
- markCustom,
112
- raiseAdjustment,
113
- rebaseToDay,
114
- setCustomDate,
119
+ disableDatesAfter,
120
+ disableDatesBefore,
121
+ disableFutureDates,
122
+ disablePastDates,
115
123
  timeSelect,
116
124
  toLocalDateTime,
117
125
  toReverseOffsetDateTime,
@@ -0,0 +1,6 @@
1
+ import { IRangeDates } from "./rangeOrder";
2
+ /**
3
+ * A locked end stays what it is whatever was typed. When keeping the lock leaves the end before the start, the typed
4
+ * edit is dropped and the range stays as it was.
5
+ */
6
+ export declare const applyRangeLocks: (prev: IRangeDates, next: IRangeDates, lockStartDate?: string, lockEndDate?: string) => IRangeDates;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.applyRangeLocks = void 0;
4
+ const pinLockedEnds_1 = require("./pinLockedEnds");
5
+ const rangeOrder_1 = require("./rangeOrder");
6
+ /**
7
+ * A locked end stays what it is whatever was typed. When keeping the lock leaves the end before the start, the typed
8
+ * edit is dropped and the range stays as it was.
9
+ */
10
+ const applyRangeLocks = (prev, next, lockStartDate, lockEndDate) => {
11
+ const locked = (0, pinLockedEnds_1.pinLockedEnds)(next, lockStartDate, lockEndDate);
12
+ return (0, rangeOrder_1.isEndBeforeStart)(locked.from, locked.to) ? prev : locked;
13
+ };
14
+ exports.applyRangeLocks = applyRangeLocks;
@@ -0,0 +1,3 @@
1
+ import { IRangeDates } from "./rangeOrder";
2
+ /** A locked end keeps its value whatever was edited, so an edit to it must not take part in putting the range in order. */
3
+ export declare const pinLockedEnds: (range: IRangeDates, lockStartDate?: string, lockEndDate?: string) => IRangeDates;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pinLockedEnds = void 0;
4
+ /** A locked end keeps its value whatever was edited, so an edit to it must not take part in putting the range in order. */
5
+ const pinLockedEnds = (range, lockStartDate, lockEndDate) => ({
6
+ from: lockStartDate || range.from,
7
+ to: lockEndDate || range.to
8
+ });
9
+ exports.pinLockedEnds = pinLockedEnds;
package/dist/index.css CHANGED
@@ -14001,6 +14001,9 @@ html:lang(ar) .zen-date-range-inner__mobile-custom-label {
14001
14001
  margin-block-end: -3.75rem;
14002
14002
  z-index: 0;
14003
14003
  }
14004
+ .zen-date-range-inner--new-mobile.zen-date-range-inner--no-pills .zen-virtual-month-list {
14005
+ margin-block-end: 0;
14006
+ }
14004
14007
  .zen-date-range-inner--new-mobile .zen-pill-bar {
14005
14008
  margin-block: 0;
14006
14009
  box-sizing: border-box;
@@ -4,6 +4,8 @@ type ICalendarGrid = Pick<ICalendarContext, "id" | "dates" | "monthStart" | "mon
4
4
  hideOtherMonthDates?: boolean;
5
5
  /** The day to mark as today, as a Date that reads as the user's wall clock; the browser's day when absent. */
6
6
  today?: Date;
7
+ /** A touch selects a day when released on it instead of when it lands, so scrolling the month list does not select. */
8
+ selectTouchOnRelease?: boolean;
7
9
  };
8
- export declare const CalendarGrid: ({ id, dates, monthStart, monthEnd, fromDate, toDate, hoverDate, rangePreview, previewRangeOnHover, focusDate, viewDate, dateRangeMode, isMobileView, isTabStop, currentActiveField, memoizedVisibleFocus, getDayOfWeek, fullDayLabels, isDisabledDay, onPointerDown, handleDateKeyDown, setHoverDate, handleFocusDateChange, getBeforeDecorator, getAfterDecorator, translate, hideThead, hideOtherMonthDates, today }: ICalendarGrid) => import("react/jsx-runtime").JSX.Element;
10
+ export declare const CalendarGrid: ({ id, dates, monthStart, monthEnd, fromDate, toDate, hoverDate, rangePreview, previewRangeOnHover, focusDate, viewDate, dateRangeMode, isMobileView, isTabStop, currentActiveField, memoizedVisibleFocus, getDayOfWeek, fullDayLabels, isDisabledDay, onPointerDown, handleDateKeyDown, setHoverDate, handleFocusDateChange, getBeforeDecorator, getAfterDecorator, translate, hideThead, hideOtherMonthDates, today, selectTouchOnRelease }: ICalendarGrid) => import("react/jsx-runtime").JSX.Element;
9
11
  export {};
@@ -1,13 +1,15 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { classNames } from "../../commonHelpers/classNames/classNames";
3
3
  import { getButtonLabel, getRangeEdgeFade, isDateInRange, toDateKey } from "../calendarUtils";
4
+ import { useTouchTap } from "../hooks/useTouchTap";
4
5
  const isPreviewEnd = (rangePreview, hoverDate, date, isOtherMonth, isActive) => {
5
6
  if (!rangePreview || isOtherMonth || (date !== rangePreview.from && date !== rangePreview.to))
6
7
  return false;
7
8
  return !!rangePreview.outlineEnds || (date === hoverDate && !isActive);
8
9
  };
9
10
  const isTintedByItself = (isRangeMode, isRowEdge, isInRange, hasFade, isPreviewEndDay) => (isRangeMode && !isRowEdge && isInRange && !hasFade) || isPreviewEndDay;
10
- export const CalendarGrid = ({ id, dates, monthStart, monthEnd, fromDate, toDate, hoverDate, rangePreview, previewRangeOnHover, focusDate, viewDate, dateRangeMode, isMobileView, isTabStop, currentActiveField, memoizedVisibleFocus, getDayOfWeek, fullDayLabels, isDisabledDay, onPointerDown, handleDateKeyDown, setHoverDate, handleFocusDateChange, getBeforeDecorator, getAfterDecorator, translate, hideThead = false, hideOtherMonthDates = false, today }) => {
11
+ export const CalendarGrid = ({ id, dates, monthStart, monthEnd, fromDate, toDate, hoverDate, rangePreview, previewRangeOnHover, focusDate, viewDate, dateRangeMode, isMobileView, isTabStop, currentActiveField, memoizedVisibleFocus, getDayOfWeek, fullDayLabels, isDisabledDay, onPointerDown, handleDateKeyDown, setHoverDate, handleFocusDateChange, getBeforeDecorator, getAfterDecorator, translate, hideThead = false, hideOtherMonthDates = false, today, selectTouchOnRelease = false }) => {
12
+ const touchTap = useTouchTap(selectTouchOnRelease, onPointerDown);
11
13
  const todayKey = toDateKey(today !== null && today !== void 0 ? today : new Date());
12
14
  const tintFrom = rangePreview ? rangePreview.from : fromDate;
13
15
  const tintTo = rangePreview ? rangePreview.to : toDate;
@@ -56,8 +58,11 @@ export const CalendarGrid = ({ id, dates, monthStart, monthEnd, fromDate, toDate
56
58
  : ""
57
59
  ]), onPointerDown: evt => {
58
60
  evt.preventDefault();
59
- !isDisabled && !isHidden && evt.button !== 2 && onPointerDown(date, isOtherMonth);
60
- }, onPointerEnter: evt => {
61
+ if (isDisabled || isHidden || evt.button === 2)
62
+ return;
63
+ if (!touchTap.press(evt.pointerType, date))
64
+ onPointerDown(date, isOtherMonth);
65
+ }, onPointerUp: evt => touchTap.release(evt.pointerType, date, isOtherMonth), onPointerCancel: touchTap.cancel, onPointerEnter: evt => {
61
66
  // A touch has no hover; the one it leaves behind would preview a range that was never pointed at.
62
67
  if (previewRangeOnHover && evt.pointerType === "touch")
63
68
  return;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * A finger that lands on a day may be about to scroll the month list, which the browser reports as a cancelled pointer. A touch
3
+ * press therefore waits for its release, and only a release on the day the finger landed on, with no cancel in between, is a tap.
4
+ */
5
+ export declare const useTouchTap: (enabled: boolean, onTap: (date: string, isOtherMonth: boolean) => void) => {
6
+ press: (pointerType: string, date: string) => boolean;
7
+ release: (pointerType: string, date: string, isOtherMonth: boolean) => void;
8
+ cancel: () => void;
9
+ };
@@ -0,0 +1,24 @@
1
+ import { useCallback, useRef } from "react";
2
+ /**
3
+ * A finger that lands on a day may be about to scroll the month list, which the browser reports as a cancelled pointer. A touch
4
+ * press therefore waits for its release, and only a release on the day the finger landed on, with no cancel in between, is a tap.
5
+ */
6
+ export const useTouchTap = (enabled, onTap) => {
7
+ const pressedDate = useRef(undefined);
8
+ const press = useCallback((pointerType, date) => {
9
+ if (!enabled || pointerType !== "touch")
10
+ return false;
11
+ pressedDate.current = date;
12
+ return true;
13
+ }, [enabled]);
14
+ const release = useCallback((pointerType, date, isOtherMonth) => {
15
+ const isTap = enabled && pointerType === "touch" && pressedDate.current === date;
16
+ pressedDate.current = undefined;
17
+ if (isTap)
18
+ onTap(date, isOtherMonth);
19
+ }, [enabled, onTap]);
20
+ const cancel = useCallback(() => {
21
+ pressedDate.current = undefined;
22
+ }, []);
23
+ return { press, release, cancel };
24
+ };
@@ -244,7 +244,8 @@ export const Template = ctx => {
244
244
  getDayOfWeek: getDayOfWeek2Letter,
245
245
  hideThead: isMobile,
246
246
  hideOtherMonthDates: hideOtherMonthDates,
247
- today: toLocalDateTime(new Date())
247
+ today: toLocalDateTime(new Date()),
248
+ selectTouchOnRelease: true
248
249
  }))]
249
250
  });
250
251
  };
@@ -7,6 +7,7 @@ import { toEditableFormat } from "../../datePickerNew/components/dateSegmentInpu
7
7
  import { toEditableTimeFormat } from "../../datePickerNew/components/dateSegmentInput/utils/toEditableTimeFormat";
8
8
  import { strictDeformatDate } from "../../datePickerNew/utils/strictDeformatDate";
9
9
  import { typedDateToIso } from "../../datePickerNew/utils/typedDateToIso";
10
+ import { isTypedDateAllowed } from "../../datePickerCommon/utils/isTypedDateAllowed";
10
11
  import { formatDate } from "../../utils/formatDate";
11
12
  import { userFormatContext } from "../../utils/userFormat/userFormatContext";
12
13
  /** The new picker says "Select date" while empty and labels a value in the time format its segments edit. */
@@ -49,7 +50,11 @@ export const useDateInputRawNew = props => {
49
50
  handleApplyClick: applyCore
50
51
  } = ctx;
51
52
  const {
52
- timeSelect
53
+ timeSelect,
54
+ disableFutureDates,
55
+ disablePastDates,
56
+ disableDatesBefore,
57
+ disableDatesAfter
53
58
  } = props;
54
59
  // The segmented trigger is typed into, so it works in a numeric format even when the user's own
55
60
  // format has month or day names; the user's format is kept for how the label reads.
@@ -104,7 +109,13 @@ export const useDateInputRawNew = props => {
104
109
  }, [onChange, requireSelection, setCustomDate, setIsOpen, setPrevValue]);
105
110
  const onTriggerTextChange = useCallback(text => {
106
111
  const parsed = strictDeformatDate(text, editFormat, translate);
107
- if (!parsed) return;
112
+ const limits = {
113
+ disableFutureDates,
114
+ disablePastDates,
115
+ disableDatesBefore,
116
+ disableDatesAfter
117
+ };
118
+ if (!parsed || !isTypedDateAllowed(parsed, limits, toReverseOffsetDateTime)) return;
108
119
  // The typed date names a day in the user's time zone, and the typed time (if any) its hour and minute, like a
109
120
  // value shown through toLocalDateTime; it goes back to an instant through toReverseOffsetDateTime either way.
110
121
  let time;
@@ -123,7 +134,7 @@ export const useDateInputRawNew = props => {
123
134
  setCustomDate(iso);
124
135
  setPrevValue(iso);
125
136
  onChange(iso);
126
- }, [customDate, editFormat, onChange, setCustomDate, setPrevValue, timeSelect, toLocalDateTime, toReverseOffsetDateTime, translate, value]);
137
+ }, [customDate, disableDatesAfter, disableDatesBefore, disableFutureDates, disablePastDates, editFormat, onChange, setCustomDate, setPrevValue, timeSelect, toLocalDateTime, toReverseOffsetDateTime, translate, value]);
127
138
  const handleApplyClick = useCallback(() => {
128
139
  draftRef.current = undefined;
129
140
  applyCore();
@@ -0,0 +1,12 @@
1
+ export interface ITypedDateLimits {
2
+ disableFutureDates?: boolean;
3
+ disablePastDates?: boolean;
4
+ disableDatesBefore?: string;
5
+ disableDatesAfter?: string;
6
+ }
7
+ /**
8
+ * Whether a day typed into a segmented field may be committed. The calendar disables the days outside the limits, so a
9
+ * typed day goes through the same limits instead of bypassing them. The day names a day on the user's wall clock, and
10
+ * today is neither past nor future whatever the time is now.
11
+ */
12
+ export declare const isTypedDateAllowed: (day: Date, limits: ITypedDateLimits, toReverseOffsetDateTime: (date: Date | string) => Date) => boolean;
@@ -0,0 +1,17 @@
1
+ import { isValidationDateError } from "../../calendar/dateUtils";
2
+ /** The last instant of the typed day on the user's wall clock, as a real instant. */
3
+ const getEndOfDay = (day, toReverseOffsetDateTime) => toReverseOffsetDateTime(new Date(day.getFullYear(), day.getMonth(), day.getDate() + 1)).getTime() - 1;
4
+ /**
5
+ * Whether a day typed into a segmented field may be committed. The calendar disables the days outside the limits, so a
6
+ * typed day goes through the same limits instead of bypassing them. The day names a day on the user's wall clock, and
7
+ * today is neither past nor future whatever the time is now.
8
+ */
9
+ export const isTypedDateAllowed = (day, limits, toReverseOffsetDateTime) => {
10
+ const startOfDay = toReverseOffsetDateTime(day).getTime();
11
+ const now = Date.now();
12
+ if (limits.disableFutureDates && startOfDay > now)
13
+ return false;
14
+ if (limits.disablePastDates && getEndOfDay(day, toReverseOffsetDateTime) < now)
15
+ return false;
16
+ return !isValidationDateError(day, toReverseOffsetDateTime, false, false, limits.disableDatesBefore, limits.disableDatesAfter);
17
+ };
@@ -1,6 +1,6 @@
1
1
  import { injectString } from "../../utils/localization/translationsDictionary";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useState, useCallback, useContext, useEffect, useRef } from "react";
3
+ import { useState, useCallback, useContext, useEffect, useMemo, useRef } from "react";
4
4
  import { userFormatContext } from "../../utils/userFormat/userFormatContext";
5
5
  import { formatDate } from "../../utils/formatDate";
6
6
  import { addMonth } from "../../calendar/dateUtils";
@@ -263,6 +263,10 @@ export const Template = ({
263
263
  presetPreview,
264
264
  setHoveredPill
265
265
  } = usePresetPreview(options, toLocalDateTime);
266
+ // The calendar reads a day, and the range it is given, on the user's wall clock, so the limits (real instants) go in the same way
267
+ // useDateInputInner hands them over.
268
+ const calendarDisableDatesBefore = useMemo(() => disableDatesBefore ? toLocalDateTime(disableDatesBefore).toISOString() : undefined, [toLocalDateTime, disableDatesBefore]);
269
+ const calendarDisableDatesAfter = useMemo(() => disableDatesAfter ? toLocalDateTime(disableDatesAfter).toISOString() : undefined, [toLocalDateTime, disableDatesAfter]);
266
270
  const handlePillChange = useCallback(val => {
267
271
  setActivePill(val);
268
272
  if (!val) {
@@ -319,7 +323,7 @@ export const Template = ({
319
323
  const banner = adjustedDate && (adjustedDate === "end" ? translate("End date has been adjusted.") : translate("Start date has been adjusted."));
320
324
  if (isMobile) {
321
325
  return _jsxs("div", {
322
- className: "zen-date-range-inner zen-date-range-inner--new zen-date-range-inner--new-mobile",
326
+ className: `zen-date-range-inner zen-date-range-inner--new zen-date-range-inner--new-mobile${hasPills ? "" : " zen-date-range-inner--no-pills"}`,
323
327
  children: [_jsx(DayLabelsRow, {
324
328
  startDayOfWeek: startDayOfWeek
325
329
  }), _jsx(VirtualMonthList, {
@@ -335,8 +339,8 @@ export const Template = ({
335
339
  previewRange: presetPreview,
336
340
  disableFutureDates: disableFutureDates,
337
341
  disablePastDates: disablePastDates,
338
- disableDatesBefore: disableDatesBefore,
339
- disableDatesAfter: disableDatesAfter,
342
+ disableDatesBefore: calendarDisableDatesBefore,
343
+ disableDatesAfter: calendarDisableDatesAfter,
340
344
  scrollTrigger: mobileScrollTrigger
341
345
  }), hasPills && _jsx(PillBar, {
342
346
  options: pillOptions,
@@ -407,8 +411,8 @@ export const Template = ({
407
411
  dateRangeMode: true,
408
412
  disableFutureDates: disableFutureDates,
409
413
  disablePastDates: disablePastDates,
410
- disableDatesAfter: disableDatesAfter,
411
- disableDatesBefore: disableDatesBefore,
414
+ disableDatesAfter: calendarDisableDatesAfter,
415
+ disableDatesBefore: calendarDisableDatesBefore,
412
416
  startDayOfWeek: startDayOfWeek,
413
417
  viewDate: leftViewDate,
414
418
  onViewDateChange: showMonthOf,
@@ -426,8 +430,8 @@ export const Template = ({
426
430
  dateRangeMode: true,
427
431
  disableFutureDates: disableFutureDates,
428
432
  disablePastDates: disablePastDates,
429
- disableDatesAfter: disableDatesAfter,
430
- disableDatesBefore: disableDatesBefore,
433
+ disableDatesAfter: calendarDisableDatesAfter,
434
+ disableDatesBefore: calendarDisableDatesBefore,
431
435
  startDayOfWeek: startDayOfWeek,
432
436
  viewDate: rightViewDate,
433
437
  onViewDateChange: showMonthOf,
@@ -27,6 +27,10 @@ export const useDateRangeNewParts = ({ isOpen, setIsOpen, isMobile, customDate,
27
27
  isOpen,
28
28
  lockStartDate,
29
29
  lockEndDate,
30
+ disableFutureDates,
31
+ disablePastDates,
32
+ disableDatesBefore,
33
+ disableDatesAfter,
30
34
  timeSelect,
31
35
  dateFormat,
32
36
  timeFormat,
@@ -9,6 +9,10 @@ interface IUseRangeEntry {
9
9
  isOpen: boolean;
10
10
  lockStartDate?: string;
11
11
  lockEndDate?: string;
12
+ disableFutureDates?: boolean;
13
+ disablePastDates?: boolean;
14
+ disableDatesBefore?: string;
15
+ disableDatesAfter?: string;
12
16
  timeSelect?: boolean;
13
17
  dateFormat: string;
14
18
  timeFormat: string;
@@ -21,7 +25,7 @@ interface IUseRangeEntry {
21
25
  * segmented field. Every way ends in the draft range (`customDate`) -- nothing is committed before Apply -- and a way that
22
26
  * has to move the other end to keep the range in order raises the banner that says so.
23
27
  */
24
- export declare const useRangeEntry: ({ customDate, setCustomDate, setSelectedRange, isOpen, lockStartDate, lockEndDate, timeSelect, dateFormat, timeFormat, toLocalDateTime, toReverseOffsetDateTime, translate }: IUseRangeEntry) => {
28
+ export declare const useRangeEntry: ({ customDate, setCustomDate, setSelectedRange, isOpen, lockStartDate, lockEndDate, disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter, timeSelect, dateFormat, timeFormat, toLocalDateTime, toReverseOffsetDateTime, translate }: IUseRangeEntry) => {
25
29
  rangeAdjustment: import("../utils/rangeOrder").TRangeAdjustment;
26
30
  range: {
27
31
  from: string | undefined;
@@ -5,6 +5,9 @@ import { toEditableTimeFormat } from "../../datePickerNew/components/dateSegment
5
5
  import { parseToSegments } from "../../datePickerNew/components/dateSegmentInput/utils/parseToSegments";
6
6
  import { formatDate } from "../../utils/formatDate";
7
7
  import { resolveCalendarPick, resolveRangeOrder } from "../utils/rangeOrder";
8
+ import { applyRangeLocks } from "../utils/applyRangeLocks";
9
+ import { pinLockedEnds } from "../utils/pinLockedEnds";
10
+ import { isTypedDateAllowed } from "../../datePickerCommon/utils/isTypedDateAllowed";
8
11
  import { strictDeformatDate } from "../../datePickerNew/utils/strictDeformatDate";
9
12
  import { typedDateToIso } from "../../datePickerNew/utils/typedDateToIso";
10
13
  import { useRangeAdjustment } from "./useRangeAdjustment";
@@ -13,7 +16,7 @@ import { useRangeAdjustment } from "./useRangeAdjustment";
13
16
  * segmented field. Every way ends in the draft range (`customDate`) -- nothing is committed before Apply -- and a way that
14
17
  * has to move the other end to keep the range in order raises the banner that says so.
15
18
  */
16
- export const useRangeEntry = ({ customDate, setCustomDate, setSelectedRange, isOpen, lockStartDate, lockEndDate, timeSelect, dateFormat, timeFormat, toLocalDateTime, toReverseOffsetDateTime, translate }) => {
19
+ export const useRangeEntry = ({ customDate, setCustomDate, setSelectedRange, isOpen, lockStartDate, lockEndDate, disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter, timeSelect, dateFormat, timeFormat, toLocalDateTime, toReverseOffsetDateTime, translate }) => {
17
20
  // The banner explains one specific correction, so it is tied to the range that produced it.
18
21
  const { rangeAdjustment, raiseAdjustment } = useRangeAdjustment(customDate, isOpen);
19
22
  // The calendar reads its range in the browser's zone, and a day clicked in it comes back as the browser's midnight. The
@@ -54,6 +57,15 @@ export const useRangeEntry = ({ customDate, setCustomDate, setSelectedRange, isO
54
57
  markCustom(next);
55
58
  raiseAdjustment(adjusted, next);
56
59
  }, [customDate, lockEndDate, lockStartDate, markCustom, raiseAdjustment, rebaseToDay, setCustomDate, toLocalDateTime, toReverseOffsetDateTime]);
60
+ // A range edited by hand, dates typed or a time picked, is put in order and a locked end is kept; the banner says when an end moved.
61
+ const commitEdited = useCallback((next) => {
62
+ const { range: ordered, adjusted } = resolveRangeOrder(customDate, pinLockedEnds(next, lockStartDate, lockEndDate), rebaseToDay);
63
+ const locked = applyRangeLocks(customDate, ordered, lockStartDate, lockEndDate);
64
+ setCustomDate(locked);
65
+ markCustom(locked);
66
+ // The banner says an end moved, so it is raised only for an edit that was kept.
67
+ raiseAdjustment(locked === customDate ? undefined : adjusted, locked);
68
+ }, [customDate, lockEndDate, lockStartDate, markCustom, raiseAdjustment, rebaseToDay, setCustomDate]);
57
69
  // A time picked for one end (mobile). Unlike picking a day, the typed time replaces the end's own.
58
70
  const handleTimeSelect = useCallback((field, timeText) => {
59
71
  const current = customDate[field];
@@ -66,10 +78,8 @@ export const useRangeEntry = ({ customDate, setCustomDate, setSelectedRange, isO
66
78
  hours,
67
79
  minutes
68
80
  });
69
- const next = Object.assign(Object.assign({}, customDate), { [field]: iso });
70
- setCustomDate(next);
71
- markCustom(next);
72
- }, [customDate, markCustom, setCustomDate, toLocalDateTime, toReverseOffsetDateTime]);
81
+ commitEdited(Object.assign(Object.assign({}, customDate), { [field]: iso }));
82
+ }, [commitEdited, customDate, toLocalDateTime, toReverseOffsetDateTime]);
73
83
  // The segmented trigger is typed into, so it works in a numeric format even when the user's own
74
84
  // format has month or day names; the user's format is kept for how the label reads.
75
85
  const editFormat = useMemo(() => toEditableFormat(dateFormat), [dateFormat]);
@@ -92,23 +102,21 @@ export const useRangeEntry = ({ customDate, setCustomDate, setSelectedRange, isO
92
102
  const parsed = strictDeformatDate(text, triggerFormat, translate);
93
103
  if (!parsed)
94
104
  return undefined;
105
+ // A day outside the limits is not taken: that end stays as it was.
106
+ if (!isTypedDateAllowed(parsed, { disableFutureDates, disablePastDates, disableDatesBefore, disableDatesAfter }, toReverseOffsetDateTime))
107
+ return previous;
95
108
  const { hour, minute } = parseToSegments(text, triggerFormat);
96
109
  const time = timeSelect && hour !== undefined && minute !== undefined ? { hours: hour, minutes: minute } : undefined;
97
110
  return typedDateToIso(parsed, previous, isEnd, toLocalDateTime, toReverseOffsetDateTime, time);
98
111
  };
99
- const { range: ordered, adjusted } = resolveRangeOrder(customDate, {
100
- from: toIso(next.start, customDate.from, false),
101
- to: toIso(next.end, customDate.to, true)
102
- }, rebaseToDay);
103
- setCustomDate(ordered);
104
- markCustom(ordered);
105
- raiseAdjustment(adjusted, ordered);
112
+ commitEdited({ from: toIso(next.start, customDate.from, false), to: toIso(next.end, customDate.to, true) });
106
113
  }, [
114
+ commitEdited,
107
115
  customDate,
108
- markCustom,
109
- raiseAdjustment,
110
- rebaseToDay,
111
- setCustomDate,
116
+ disableDatesAfter,
117
+ disableDatesBefore,
118
+ disableFutureDates,
119
+ disablePastDates,
112
120
  timeSelect,
113
121
  toLocalDateTime,
114
122
  toReverseOffsetDateTime,
@@ -0,0 +1,6 @@
1
+ import { IRangeDates } from "./rangeOrder";
2
+ /**
3
+ * A locked end stays what it is whatever was typed. When keeping the lock leaves the end before the start, the typed
4
+ * edit is dropped and the range stays as it was.
5
+ */
6
+ export declare const applyRangeLocks: (prev: IRangeDates, next: IRangeDates, lockStartDate?: string, lockEndDate?: string) => IRangeDates;
@@ -0,0 +1,10 @@
1
+ import { pinLockedEnds } from "./pinLockedEnds";
2
+ import { isEndBeforeStart } from "./rangeOrder";
3
+ /**
4
+ * A locked end stays what it is whatever was typed. When keeping the lock leaves the end before the start, the typed
5
+ * edit is dropped and the range stays as it was.
6
+ */
7
+ export const applyRangeLocks = (prev, next, lockStartDate, lockEndDate) => {
8
+ const locked = pinLockedEnds(next, lockStartDate, lockEndDate);
9
+ return isEndBeforeStart(locked.from, locked.to) ? prev : locked;
10
+ };
@@ -0,0 +1,3 @@
1
+ import { IRangeDates } from "./rangeOrder";
2
+ /** A locked end keeps its value whatever was edited, so an edit to it must not take part in putting the range in order. */
3
+ export declare const pinLockedEnds: (range: IRangeDates, lockStartDate?: string, lockEndDate?: string) => IRangeDates;
@@ -0,0 +1,5 @@
1
+ /** A locked end keeps its value whatever was edited, so an edit to it must not take part in putting the range in order. */
2
+ export const pinLockedEnds = (range, lockStartDate, lockEndDate) => ({
3
+ from: lockStartDate || range.from,
4
+ to: lockEndDate || range.to
5
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geotab/zenith",
3
- "version": "3.17.1-beta.0",
3
+ "version": "3.17.1-beta.1",
4
4
  "description": "Zenith components library on React",
5
5
  "main": "dist/index.js",
6
6
  "types": "esm/index.d.ts",
@@ -156,5 +156,8 @@
156
156
  "minimatch@<9": {
157
157
  "brace-expansion": "^1.1.18"
158
158
  }
159
+ },
160
+ "publishConfig": {
161
+ "access": "public"
159
162
  }
160
163
  }