@zag-js/date-utils 0.0.0-dev-20230107162446 → 0.0.0-dev-20230107200900

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/align.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { CalendarDate, DateDuration, DateValue } from '@internationalized/date';
2
- import { D as DateAlignment } from './types-cbf8b45a.js';
2
+ import { DateAlignment } from './types.js';
3
3
 
4
4
  declare function alignDate(date: CalendarDate, alignment: DateAlignment, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): CalendarDate;
5
5
  declare function alignStartDate(date: CalendarDate, startDate: CalendarDate, endDate: CalendarDate, duration: DateDuration, locale: string, min?: DateValue | undefined, max?: DateValue | undefined): CalendarDate;
@@ -1,13 +1,13 @@
1
1
  import { CalendarDate, DateValue } from '@internationalized/date';
2
- import { a as DateAvailableFn } from './types-cbf8b45a.js';
2
+ import { DateAvailableFn } from './types.js';
3
3
 
4
4
  declare function isTodayDate(date: CalendarDate, timeZone: string): boolean;
5
- declare function isDateEqual(dateA: CalendarDate, dateB: CalendarDate | null): boolean;
6
- declare function isDateInvalid(date: DateValue, minValue: DateValue | null, maxValue: DateValue | null): boolean;
7
- declare function isDateDisabled(date: DateValue, startDate: DateValue, endDate: DateValue, minValue: DateValue | null, maxValue: DateValue | null): boolean;
8
- declare function isDateUnavailable(date: DateValue | null, isUnavailable: DateAvailableFn | null, minValue: DateValue | null, maxValue: DateValue | null): boolean;
5
+ declare function isDateEqual(dateA: CalendarDate, dateB?: CalendarDate | null): boolean;
6
+ declare function isDateInvalid(date: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
7
+ declare function isDateDisabled(date: DateValue, startDate: DateValue, endDate: DateValue, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
8
+ declare function isDateUnavailable(date: DateValue | null, isUnavailable: DateAvailableFn | undefined, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
9
9
  declare function isDateOutsideVisibleRange(date: CalendarDate, startDate: CalendarDate, endDate: CalendarDate): boolean;
10
- declare function isPreviousVisibleRangeInvalid(startDate: CalendarDate, minValue: DateValue | null, maxValue: DateValue | null): boolean;
11
- declare function isNextVisibleRangeInvalid(endDate: CalendarDate, minValue: DateValue | null, maxValue: DateValue | null): boolean;
10
+ declare function isPreviousVisibleRangeInvalid(startDate: CalendarDate, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
11
+ declare function isNextVisibleRangeInvalid(endDate: CalendarDate, minValue?: DateValue | null, maxValue?: DateValue | null): boolean;
12
12
 
13
13
  export { isDateDisabled, isDateEqual, isDateInvalid, isDateOutsideVisibleRange, isDateUnavailable, isNextVisibleRangeInvalid, isPreviousVisibleRangeInvalid, isTodayDate };
@@ -187,6 +187,7 @@ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, loc
187
187
  }
188
188
 
189
189
  export {
190
+ getAdjustedDateFn,
190
191
  getNextPage,
191
192
  getPreviousPage,
192
193
  getNextRow,
@@ -0,0 +1,42 @@
1
+ import {
2
+ getSegmentLimits
3
+ } from "./chunk-HL7SOSTW.mjs";
4
+ import {
5
+ getTodayPlaceholderDate
6
+ } from "./chunk-DZM5JUL2.mjs";
7
+ import {
8
+ isSegmentEditable
9
+ } from "./chunk-RJCAPB5F.mjs";
10
+
11
+ // src/segment-parts.ts
12
+ function getAllSegments(segments) {
13
+ return segments.filter((segment) => isSegmentEditable(segment.type)).reduce((acc, segment) => (acc[segment.type] = true, acc), {});
14
+ }
15
+ function getPlaceholder(options) {
16
+ const placeholder = { day: "dd", month: "mm", year: "yyyy" };
17
+ return placeholder[options.field];
18
+ }
19
+ function getSegments(date, validSegments, formatter, timeZone) {
20
+ const dateValue = date || getTodayPlaceholderDate(timeZone);
21
+ const segments = formatter.formatToParts(dateValue.toDate(timeZone));
22
+ return segments.map((segment) => {
23
+ let isEditable = isSegmentEditable(segment.type);
24
+ if (segment.type === "era")
25
+ isEditable = false;
26
+ let isPlaceholder = isSegmentEditable(segment.type) && !validSegments[segment.type];
27
+ let placeholder = isSegmentEditable(segment.type) ? getPlaceholder({ field: segment.type }) : null;
28
+ return {
29
+ type: segment.type,
30
+ text: isPlaceholder ? placeholder : segment.value,
31
+ ...getSegmentLimits(dateValue, segment.type, formatter.resolvedOptions()),
32
+ isPlaceholder: !!isPlaceholder,
33
+ placeholder,
34
+ isEditable: !!isEditable
35
+ };
36
+ });
37
+ }
38
+
39
+ export {
40
+ getAllSegments,
41
+ getSegments
42
+ };
@@ -0,0 +1,22 @@
1
+ // src/placeholder.ts
2
+ import { now, toCalendarDate } from "@internationalized/date";
3
+ function getTodayPlaceholderDate(timeZone) {
4
+ return now(timeZone).set({
5
+ hour: 0,
6
+ minute: 0,
7
+ second: 0,
8
+ millisecond: 0
9
+ });
10
+ }
11
+ function createPlaceholderDate(granularity, timeZone) {
12
+ let date = getTodayPlaceholderDate(timeZone);
13
+ if (granularity === "year" || granularity === "month" || granularity === "day") {
14
+ return toCalendarDate(date);
15
+ }
16
+ return date;
17
+ }
18
+
19
+ export {
20
+ getTodayPlaceholderDate,
21
+ createPlaceholderDate
22
+ };
@@ -65,7 +65,11 @@ function getSegmentLimits(date, type, options) {
65
65
  };
66
66
  }
67
67
  }
68
- return {};
68
+ return {
69
+ value: -1,
70
+ min: -1,
71
+ max: -1
72
+ };
69
73
  }
70
74
 
71
75
  export {
@@ -20,8 +20,13 @@ var SEGMENT_PAGE_STEP = {
20
20
  function isSegmentEditable(segment) {
21
21
  return EDITABLE_SEGMENTS[segment];
22
22
  }
23
+ function getSegmentPageStep(segment) {
24
+ var _a;
25
+ return (_a = SEGMENT_PAGE_STEP[segment]) != null ? _a : 1;
26
+ }
23
27
 
24
28
  export {
25
29
  SEGMENT_PAGE_STEP,
26
- isSegmentEditable
30
+ isSegmentEditable,
31
+ getSegmentPageStep
27
32
  };
@@ -4,6 +4,6 @@ declare function alignCenter(date: CalendarDate, duration: DateDuration, locale:
4
4
  declare function alignStart(date: CalendarDate, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): CalendarDate;
5
5
  declare function alignEnd(date: CalendarDate, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): CalendarDate;
6
6
  declare function constrainStart(date: CalendarDate, aligned: CalendarDate, duration: DateDuration, locale: string, min?: DateValue, max?: DateValue): CalendarDate;
7
- declare function constrainValue(date: CalendarDate, minValue: DateValue, maxValue: DateValue): CalendarDate;
7
+ declare function constrainValue(date: CalendarDate, minValue?: DateValue, maxValue?: DateValue): CalendarDate;
8
8
 
9
9
  export { alignCenter, alignEnd, alignStart, constrainStart, constrainValue };
@@ -1,5 +1,5 @@
1
1
  import { CalendarDate } from '@internationalized/date';
2
- import { G as GetFormatterFn } from './types-cbf8b45a.js';
2
+ import { GetFormatterFn } from './types.js';
3
3
 
4
4
  declare function formatSelectedDate(startDate: CalendarDate, endDate: CalendarDate | null, getFormatter: GetFormatterFn, isSelectingRange: boolean, timeZone: string): string;
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { CalendarDate } from '@internationalized/date';
2
- import { G as GetFormatterFn } from './types-cbf8b45a.js';
2
+ import { GetFormatterFn } from './types.js';
3
3
 
4
4
  declare function formatVisibleRange(startDate: CalendarDate | null, endDate: CalendarDate | null, getFormatter: GetFormatterFn, isAria: boolean, timeZone: string): string | undefined;
5
5
 
@@ -1,6 +1,6 @@
1
1
  import * as _internationalized_date from '@internationalized/date';
2
2
  import { CalendarDate } from '@internationalized/date';
3
- import { G as GetFormatterFn } from './types-cbf8b45a.js';
3
+ import { GetFormatterFn } from './types.js';
4
4
 
5
5
  declare function getDateFormatter(startDate: CalendarDate, endDate: CalendarDate | null, getDateFormatter: GetFormatterFn, timeZone: string): _internationalized_date.DateFormatter;
6
6
  declare function getMonthFormatter(startDate: CalendarDate, endDate: CalendarDate | null, getDateFormatter: GetFormatterFn, timeZone: string): _internationalized_date.DateFormatter;
package/dist/index.d.ts CHANGED
@@ -5,12 +5,15 @@ export { getEndDate, getUnitDuration } from './duration.js';
5
5
  export { formatRange } from './format-range.js';
6
6
  export { formatSelectedDate } from './format-selected-date.js';
7
7
  export { formatVisibleRange } from './format-visible-range.js';
8
- export { DatesInWeek, getDatesInWeek, getWeekDates } from './get-week-dates.js';
9
8
  export { getMonthDates } from './get-month-dates.js';
9
+ export { DatesInWeek, getDatesInWeek, getWeekDates } from './get-week-dates.js';
10
10
  export { YearsRange, getYearsRange } from './get-year-range.js';
11
11
  export { getNextDay, getPreviousAvailableDate, getPreviousDay, getTodayDate, setCalendar, setDate, setMonth, setYear } from './mutation.js';
12
- export { getNextPage, getNextRow, getNextSection, getPreviousPage, getPreviousRow, getPreviousSection, getSectionEnd, getSectionStart } from './pagination.js';
13
- export { b as DateGranularity, c as DateSegments, S as SEGMENT_PAGE_STEP, i as isSegmentEditable } from './types-cbf8b45a.js';
12
+ export { getAdjustedDateFn, getNextPage, getNextRow, getNextSection, getPreviousPage, getPreviousRow, getPreviousSection, getSectionEnd, getSectionStart } from './pagination.js';
13
+ export { createPlaceholderDate, getTodayPlaceholderDate } from './placeholder.js';
14
+ export { DateSegment, DateSegments, SEGMENT_PAGE_STEP, getSegmentPageStep, isSegmentEditable } from './segment-constants.js';
14
15
  export { getSegmentLimits } from './segment-limit.js';
15
16
  export { addSegment, setSegment } from './segment-mutation.js';
17
+ export { DateSegmentDetails, getAllSegments, getSegments } from './segment-parts.js';
18
+ export { DateAdjustFn, DateGranularity, DateSegmentPart } from './types.js';
16
19
  import '@internationalized/date';
package/dist/index.js CHANGED
@@ -29,9 +29,12 @@ __export(src_exports, {
29
29
  alignStartDate: () => alignStartDate,
30
30
  constrainStart: () => constrainStart,
31
31
  constrainValue: () => constrainValue,
32
+ createPlaceholderDate: () => createPlaceholderDate,
32
33
  formatRange: () => formatRange,
33
34
  formatSelectedDate: () => formatSelectedDate,
34
35
  formatVisibleRange: () => formatVisibleRange,
36
+ getAdjustedDateFn: () => getAdjustedDateFn,
37
+ getAllSegments: () => getAllSegments,
35
38
  getDatesInWeek: () => getDatesInWeek,
36
39
  getEndDate: () => getEndDate,
37
40
  getMonthDates: () => getMonthDates,
@@ -47,7 +50,10 @@ __export(src_exports, {
47
50
  getSectionEnd: () => getSectionEnd,
48
51
  getSectionStart: () => getSectionStart,
49
52
  getSegmentLimits: () => getSegmentLimits,
53
+ getSegmentPageStep: () => getSegmentPageStep,
54
+ getSegments: () => getSegments,
50
55
  getTodayDate: () => getTodayDate,
56
+ getTodayPlaceholderDate: () => getTodayPlaceholderDate,
51
57
  getUnitDuration: () => getUnitDuration,
52
58
  getWeekDates: () => getWeekDates,
53
59
  getYearsRange: () => getYearsRange,
@@ -291,6 +297,9 @@ function formatVisibleRange(startDate, endDate, getFormatter, isAria, timeZone)
291
297
  }
292
298
  }
293
299
 
300
+ // src/get-month-dates.ts
301
+ var import_date6 = require("@internationalized/date");
302
+
294
303
  // src/get-week-dates.ts
295
304
  var import_date5 = require("@internationalized/date");
296
305
  function getDatesInWeek(weekIndex, fromDate, locale) {
@@ -323,7 +332,6 @@ function getWeekDates(fromDate, timeZone, locale) {
323
332
  }
324
333
 
325
334
  // src/get-month-dates.ts
326
- var import_date6 = require("@internationalized/date");
327
335
  function getMonthDates(startDate, duration, locale) {
328
336
  var _a;
329
337
  let weeksInMonth = (0, import_date6.getWeeksInMonth)(startDate, locale);
@@ -555,6 +563,24 @@ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, loc
555
563
  }
556
564
  }
557
565
 
566
+ // src/placeholder.ts
567
+ var import_date9 = require("@internationalized/date");
568
+ function getTodayPlaceholderDate(timeZone) {
569
+ return (0, import_date9.now)(timeZone).set({
570
+ hour: 0,
571
+ minute: 0,
572
+ second: 0,
573
+ millisecond: 0
574
+ });
575
+ }
576
+ function createPlaceholderDate(granularity, timeZone) {
577
+ let date = getTodayPlaceholderDate(timeZone);
578
+ if (granularity === "year" || granularity === "month" || granularity === "day") {
579
+ return (0, import_date9.toCalendarDate)(date);
580
+ }
581
+ return date;
582
+ }
583
+
558
584
  // src/segment-constants.ts
559
585
  var EDITABLE_SEGMENTS = {
560
586
  year: true,
@@ -577,9 +603,13 @@ var SEGMENT_PAGE_STEP = {
577
603
  function isSegmentEditable(segment) {
578
604
  return EDITABLE_SEGMENTS[segment];
579
605
  }
606
+ function getSegmentPageStep(segment) {
607
+ var _a;
608
+ return (_a = SEGMENT_PAGE_STEP[segment]) != null ? _a : 1;
609
+ }
580
610
 
581
611
  // src/segment-limit.ts
582
- var import_date9 = require("@internationalized/date");
612
+ var import_date10 = require("@internationalized/date");
583
613
  function getSegmentLimits(date, type, options) {
584
614
  switch (type) {
585
615
  case "era": {
@@ -599,13 +629,13 @@ function getSegmentLimits(date, type, options) {
599
629
  case "month":
600
630
  return {
601
631
  value: date.month,
602
- min: (0, import_date9.getMinimumMonthInYear)(date),
632
+ min: (0, import_date10.getMinimumMonthInYear)(date),
603
633
  max: date.calendar.getMonthsInYear(date)
604
634
  };
605
635
  case "day":
606
636
  return {
607
637
  value: date.day,
608
- min: (0, import_date9.getMinimumDayInMonth)(date),
638
+ min: (0, import_date10.getMinimumDayInMonth)(date),
609
639
  max: date.calendar.getDaysInMonth(date)
610
640
  };
611
641
  }
@@ -645,7 +675,11 @@ function getSegmentLimits(date, type, options) {
645
675
  };
646
676
  }
647
677
  }
648
- return {};
678
+ return {
679
+ value: -1,
680
+ min: -1,
681
+ max: -1
682
+ };
649
683
  }
650
684
 
651
685
  // src/segment-mutation.ts
@@ -709,6 +743,34 @@ function setSegment(date, part, value, options) {
709
743
  }
710
744
  return date;
711
745
  }
746
+
747
+ // src/segment-parts.ts
748
+ function getAllSegments(segments) {
749
+ return segments.filter((segment) => isSegmentEditable(segment.type)).reduce((acc, segment) => (acc[segment.type] = true, acc), {});
750
+ }
751
+ function getPlaceholder(options) {
752
+ const placeholder = { day: "dd", month: "mm", year: "yyyy" };
753
+ return placeholder[options.field];
754
+ }
755
+ function getSegments(date, validSegments, formatter, timeZone) {
756
+ const dateValue = date || getTodayPlaceholderDate(timeZone);
757
+ const segments = formatter.formatToParts(dateValue.toDate(timeZone));
758
+ return segments.map((segment) => {
759
+ let isEditable = isSegmentEditable(segment.type);
760
+ if (segment.type === "era")
761
+ isEditable = false;
762
+ let isPlaceholder = isSegmentEditable(segment.type) && !validSegments[segment.type];
763
+ let placeholder = isSegmentEditable(segment.type) ? getPlaceholder({ field: segment.type }) : null;
764
+ return {
765
+ type: segment.type,
766
+ text: isPlaceholder ? placeholder : segment.value,
767
+ ...getSegmentLimits(dateValue, segment.type, formatter.resolvedOptions()),
768
+ isPlaceholder: !!isPlaceholder,
769
+ placeholder,
770
+ isEditable: !!isEditable
771
+ };
772
+ });
773
+ }
712
774
  // Annotate the CommonJS export names for ESM import in node:
713
775
  0 && (module.exports = {
714
776
  SEGMENT_PAGE_STEP,
@@ -720,9 +782,12 @@ function setSegment(date, part, value, options) {
720
782
  alignStartDate,
721
783
  constrainStart,
722
784
  constrainValue,
785
+ createPlaceholderDate,
723
786
  formatRange,
724
787
  formatSelectedDate,
725
788
  formatVisibleRange,
789
+ getAdjustedDateFn,
790
+ getAllSegments,
726
791
  getDatesInWeek,
727
792
  getEndDate,
728
793
  getMonthDates,
@@ -738,7 +803,10 @@ function setSegment(date, part, value, options) {
738
803
  getSectionEnd,
739
804
  getSectionStart,
740
805
  getSegmentLimits,
806
+ getSegmentPageStep,
807
+ getSegments,
741
808
  getTodayDate,
809
+ getTodayPlaceholderDate,
742
810
  getUnitDuration,
743
811
  getWeekDates,
744
812
  getYearsRange,
package/dist/index.mjs CHANGED
@@ -2,9 +2,13 @@ import {
2
2
  addSegment,
3
3
  setSegment
4
4
  } from "./chunk-CAV5WKCZ.mjs";
5
+ import {
6
+ getAllSegments,
7
+ getSegments
8
+ } from "./chunk-DETLHDDR.mjs";
5
9
  import {
6
10
  getSegmentLimits
7
- } from "./chunk-L3YHK2WH.mjs";
11
+ } from "./chunk-HL7SOSTW.mjs";
8
12
  import {
9
13
  getMonthDates
10
14
  } from "./chunk-HUBKWHIN.mjs";
@@ -26,6 +30,7 @@ import {
26
30
  setYear
27
31
  } from "./chunk-ZZPZ2BFS.mjs";
28
32
  import {
33
+ getAdjustedDateFn,
29
34
  getNextPage,
30
35
  getNextRow,
31
36
  getNextSection,
@@ -34,11 +39,16 @@ import {
34
39
  getPreviousSection,
35
40
  getSectionEnd,
36
41
  getSectionStart
37
- } from "./chunk-MY373KF2.mjs";
42
+ } from "./chunk-BRQVXAVZ.mjs";
43
+ import {
44
+ createPlaceholderDate,
45
+ getTodayPlaceholderDate
46
+ } from "./chunk-DZM5JUL2.mjs";
38
47
  import {
39
48
  SEGMENT_PAGE_STEP,
49
+ getSegmentPageStep,
40
50
  isSegmentEditable
41
- } from "./chunk-6NI2PIAA.mjs";
51
+ } from "./chunk-RJCAPB5F.mjs";
42
52
  import {
43
53
  alignDate,
44
54
  alignStartDate
@@ -84,9 +94,12 @@ export {
84
94
  alignStartDate,
85
95
  constrainStart,
86
96
  constrainValue,
97
+ createPlaceholderDate,
87
98
  formatRange,
88
99
  formatSelectedDate,
89
100
  formatVisibleRange,
101
+ getAdjustedDateFn,
102
+ getAllSegments,
90
103
  getDatesInWeek,
91
104
  getEndDate,
92
105
  getMonthDates,
@@ -102,7 +115,10 @@ export {
102
115
  getSectionEnd,
103
116
  getSectionStart,
104
117
  getSegmentLimits,
118
+ getSegmentPageStep,
119
+ getSegments,
105
120
  getTodayDate,
121
+ getTodayPlaceholderDate,
106
122
  getUnitDuration,
107
123
  getWeekDates,
108
124
  getYearsRange,
@@ -1,5 +1,5 @@
1
1
  import { CalendarDate, Calendar, DateValue } from '@internationalized/date';
2
- import { a as DateAvailableFn } from './types-cbf8b45a.js';
2
+ import { DateAvailableFn } from './types.js';
3
3
 
4
4
  declare function getTodayDate(timezone: string): CalendarDate;
5
5
  declare function getNextDay(date: CalendarDate): CalendarDate;
@@ -1,44 +1,52 @@
1
- import { CalendarDate, DateDuration } from '@internationalized/date';
1
+ import { DateDuration, CalendarDate } from '@internationalized/date';
2
2
 
3
- declare function getNextPage(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue: CalendarDate, maxValue: CalendarDate): {
3
+ declare function getAdjustedDateFn(visibleDuration: DateDuration, locale: string, minValue?: CalendarDate, maxValue?: CalendarDate): (options: {
4
+ startDate: CalendarDate;
5
+ focusedDate: CalendarDate;
6
+ }) => {
7
+ startDate: CalendarDate;
8
+ focusedDate: CalendarDate;
9
+ endDate: CalendarDate;
10
+ };
11
+ declare function getNextPage(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue?: CalendarDate, maxValue?: CalendarDate): {
4
12
  startDate: CalendarDate;
5
13
  focusedDate: CalendarDate;
6
14
  endDate: CalendarDate;
7
15
  };
8
- declare function getPreviousPage(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue: CalendarDate, maxValue: CalendarDate): {
16
+ declare function getPreviousPage(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue?: CalendarDate, maxValue?: CalendarDate): {
9
17
  startDate: CalendarDate;
10
18
  focusedDate: CalendarDate;
11
19
  endDate: CalendarDate;
12
20
  };
13
- declare function getNextRow(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue: CalendarDate, maxValue: CalendarDate): {
21
+ declare function getNextRow(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue?: CalendarDate, maxValue?: CalendarDate): {
14
22
  startDate: CalendarDate;
15
23
  focusedDate: CalendarDate;
16
24
  endDate: CalendarDate;
17
25
  } | undefined;
18
- declare function getPreviousRow(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue: CalendarDate, maxValue: CalendarDate): {
26
+ declare function getPreviousRow(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue?: CalendarDate, maxValue?: CalendarDate): {
19
27
  startDate: CalendarDate;
20
28
  focusedDate: CalendarDate;
21
29
  endDate: CalendarDate;
22
30
  } | undefined;
23
- declare function getSectionStart(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue: CalendarDate, maxValue: CalendarDate): {
31
+ declare function getSectionStart(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue?: CalendarDate, maxValue?: CalendarDate): {
24
32
  startDate: CalendarDate;
25
33
  focusedDate: CalendarDate;
26
34
  endDate: CalendarDate;
27
35
  } | undefined;
28
- declare function getSectionEnd(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue: CalendarDate, maxValue: CalendarDate): {
36
+ declare function getSectionEnd(focusedDate: CalendarDate, startDate: CalendarDate, visibleDuration: DateDuration, locale: string, minValue?: CalendarDate, maxValue?: CalendarDate): {
29
37
  startDate: CalendarDate;
30
38
  focusedDate: CalendarDate;
31
39
  endDate: CalendarDate;
32
40
  } | undefined;
33
- declare function getNextSection(focusedDate: CalendarDate, startDate: CalendarDate, larger: boolean, visibleDuration: DateDuration, locale: string, minValue: CalendarDate, maxValue: CalendarDate): {
41
+ declare function getNextSection(focusedDate: CalendarDate, startDate: CalendarDate, larger: boolean, visibleDuration: DateDuration, locale: string, minValue?: CalendarDate, maxValue?: CalendarDate): {
34
42
  startDate: CalendarDate;
35
43
  focusedDate: CalendarDate;
36
44
  endDate: CalendarDate;
37
45
  } | undefined;
38
- declare function getPreviousSection(focusedDate: CalendarDate, startDate: CalendarDate, larger: boolean, visibleDuration: DateDuration, locale: string, minValue: CalendarDate, maxValue: CalendarDate): {
46
+ declare function getPreviousSection(focusedDate: CalendarDate, startDate: CalendarDate, larger: boolean, visibleDuration: DateDuration, locale: string, minValue?: CalendarDate, maxValue?: CalendarDate): {
39
47
  startDate: CalendarDate;
40
48
  focusedDate: CalendarDate;
41
49
  endDate: CalendarDate;
42
50
  } | undefined;
43
51
 
44
- export { getNextPage, getNextRow, getNextSection, getPreviousPage, getPreviousRow, getPreviousSection, getSectionEnd, getSectionStart };
52
+ export { getAdjustedDateFn, getNextPage, getNextRow, getNextSection, getPreviousPage, getPreviousRow, getPreviousSection, getSectionEnd, getSectionStart };
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/pagination.ts
21
21
  var pagination_exports = {};
22
22
  __export(pagination_exports, {
23
+ getAdjustedDateFn: () => getAdjustedDateFn,
23
24
  getNextPage: () => getNextPage,
24
25
  getNextRow: () => getNextRow,
25
26
  getNextSection: () => getNextSection,
@@ -276,6 +277,7 @@ function getPreviousSection(focusedDate, startDate, larger, visibleDuration, loc
276
277
  }
277
278
  // Annotate the CommonJS export names for ESM import in node:
278
279
  0 && (module.exports = {
280
+ getAdjustedDateFn,
279
281
  getNextPage,
280
282
  getNextRow,
281
283
  getNextSection,
@@ -1,4 +1,5 @@
1
1
  import {
2
+ getAdjustedDateFn,
2
3
  getNextPage,
3
4
  getNextRow,
4
5
  getNextSection,
@@ -7,11 +8,12 @@ import {
7
8
  getPreviousSection,
8
9
  getSectionEnd,
9
10
  getSectionStart
10
- } from "./chunk-MY373KF2.mjs";
11
+ } from "./chunk-BRQVXAVZ.mjs";
11
12
  import "./chunk-6EJZROXM.mjs";
12
13
  import "./chunk-MGPXEJO4.mjs";
13
14
  import "./chunk-ZSLC7OI2.mjs";
14
15
  export {
16
+ getAdjustedDateFn,
15
17
  getNextPage,
16
18
  getNextRow,
17
19
  getNextSection,
@@ -1,5 +1,5 @@
1
1
  import * as _internationalized_date from '@internationalized/date';
2
- import { b as DateGranularity } from './types-cbf8b45a.js';
2
+ import { DateGranularity } from './types.js';
3
3
 
4
4
  declare function getTodayPlaceholderDate(timeZone: string): _internationalized_date.ZonedDateTime;
5
5
  declare function createPlaceholderDate(granularity: DateGranularity, timeZone: string): _internationalized_date.CalendarDate | _internationalized_date.ZonedDateTime;
@@ -1,20 +1,7 @@
1
- // src/placeholder.ts
2
- import { now, toCalendarDate } from "@internationalized/date";
3
- function getTodayPlaceholderDate(timeZone) {
4
- return now(timeZone).set({
5
- hour: 0,
6
- minute: 0,
7
- second: 0,
8
- millisecond: 0
9
- });
10
- }
11
- function createPlaceholderDate(granularity, timeZone) {
12
- let date = getTodayPlaceholderDate(timeZone);
13
- if (granularity === "year" || granularity === "month" || granularity === "day") {
14
- return toCalendarDate(date);
15
- }
16
- return date;
17
- }
1
+ import {
2
+ createPlaceholderDate,
3
+ getTodayPlaceholderDate
4
+ } from "./chunk-DZM5JUL2.mjs";
18
5
  export {
19
6
  createPlaceholderDate,
20
7
  getTodayPlaceholderDate
@@ -1,2 +1,27 @@
1
- export { c as DateSegments, S as SEGMENT_PAGE_STEP, i as isSegmentEditable } from './types-cbf8b45a.js';
1
+ import { DateSegmentPart } from './types.js';
2
2
  import '@internationalized/date';
3
+
4
+ declare const EDITABLE_SEGMENTS: {
5
+ year: boolean;
6
+ month: boolean;
7
+ day: boolean;
8
+ hour: boolean;
9
+ minute: boolean;
10
+ second: boolean;
11
+ dayPeriod: boolean;
12
+ era: boolean;
13
+ };
14
+ type DateSegments = Partial<typeof EDITABLE_SEGMENTS>;
15
+ type DateSegment = keyof DateSegments;
16
+ declare const SEGMENT_PAGE_STEP: {
17
+ year: number;
18
+ month: number;
19
+ day: number;
20
+ hour: number;
21
+ minute: number;
22
+ second: number;
23
+ };
24
+ declare function isSegmentEditable(segment: DateSegmentPart): any;
25
+ declare function getSegmentPageStep(segment: DateSegmentPart): any;
26
+
27
+ export { DateSegment, DateSegments, SEGMENT_PAGE_STEP, getSegmentPageStep, isSegmentEditable };
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var segment_constants_exports = {};
22
22
  __export(segment_constants_exports, {
23
23
  SEGMENT_PAGE_STEP: () => SEGMENT_PAGE_STEP,
24
+ getSegmentPageStep: () => getSegmentPageStep,
24
25
  isSegmentEditable: () => isSegmentEditable
25
26
  });
26
27
  module.exports = __toCommonJS(segment_constants_exports);
@@ -45,8 +46,13 @@ var SEGMENT_PAGE_STEP = {
45
46
  function isSegmentEditable(segment) {
46
47
  return EDITABLE_SEGMENTS[segment];
47
48
  }
49
+ function getSegmentPageStep(segment) {
50
+ var _a;
51
+ return (_a = SEGMENT_PAGE_STEP[segment]) != null ? _a : 1;
52
+ }
48
53
  // Annotate the CommonJS export names for ESM import in node:
49
54
  0 && (module.exports = {
50
55
  SEGMENT_PAGE_STEP,
56
+ getSegmentPageStep,
51
57
  isSegmentEditable
52
58
  });
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  SEGMENT_PAGE_STEP,
3
+ getSegmentPageStep,
3
4
  isSegmentEditable
4
- } from "./chunk-6NI2PIAA.mjs";
5
+ } from "./chunk-RJCAPB5F.mjs";
5
6
  export {
6
7
  SEGMENT_PAGE_STEP,
8
+ getSegmentPageStep,
7
9
  isSegmentEditable
8
10
  };
@@ -1,14 +1,10 @@
1
1
  import { DateValue } from '@internationalized/date';
2
- import { d as DateSegmentPart, e as DateFormatOptions } from './types-cbf8b45a.js';
2
+ import { DateSegmentPart, DateFormatOptions } from './types.js';
3
3
 
4
4
  declare function getSegmentLimits(date: DateValue, type: DateSegmentPart, options?: Pick<DateFormatOptions, "hour12">): {
5
5
  value: number;
6
6
  min: number;
7
7
  max: number;
8
- } | {
9
- value?: undefined;
10
- min?: undefined;
11
- max?: undefined;
12
8
  };
13
9
 
14
10
  export { getSegmentLimits };
@@ -89,7 +89,11 @@ function getSegmentLimits(date, type, options) {
89
89
  };
90
90
  }
91
91
  }
92
- return {};
92
+ return {
93
+ value: -1,
94
+ min: -1,
95
+ max: -1
96
+ };
93
97
  }
94
98
  // Annotate the CommonJS export names for ESM import in node:
95
99
  0 && (module.exports = {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  getSegmentLimits
3
- } from "./chunk-L3YHK2WH.mjs";
3
+ } from "./chunk-HL7SOSTW.mjs";
4
4
  export {
5
5
  getSegmentLimits
6
6
  };
@@ -1,5 +1,5 @@
1
1
  import { DateValue } from '@internationalized/date';
2
- import { d as DateSegmentPart, e as DateFormatOptions } from './types-cbf8b45a.js';
2
+ import { DateSegmentPart, DateFormatOptions } from './types.js';
3
3
 
4
4
  declare function addSegment(date: DateValue, part: DateSegmentPart, amount: number, options?: Pick<DateFormatOptions, "hour12">): DateValue;
5
5
  declare function setSegment(date: DateValue, part: DateSegmentPart, value: number, options?: Pick<DateFormatOptions, "hour12">): DateValue;
@@ -1,8 +1,9 @@
1
1
  import { DateValue, DateFormatter } from '@internationalized/date';
2
- import { c as DateSegments } from './types-cbf8b45a.js';
2
+ import { DateSegments } from './segment-constants.js';
3
+ import './types.js';
3
4
 
4
5
  declare function getAllSegments(segments: Intl.DateTimeFormatPart[]): {};
5
- declare function getSegments(date: DateValue, validSegments: DateSegments, formatter: DateFormatter, timeZone: string): ({
6
+ declare function getSegments(date: DateValue | undefined, validSegments: DateSegments, formatter: DateFormatter, timeZone: string): {
6
7
  isPlaceholder: boolean;
7
8
  placeholder: any;
8
9
  isEditable: boolean;
@@ -11,15 +12,16 @@ declare function getSegments(date: DateValue, validSegments: DateSegments, forma
11
12
  max: number;
12
13
  type: keyof Intl.DateTimeFormatPartTypesRegistry;
13
14
  text: any;
14
- } | {
15
+ }[];
16
+ type DateSegmentDetails = {
17
+ type: keyof Intl.DateTimeFormatPartTypesRegistry;
18
+ text: string;
19
+ value?: number;
20
+ min?: number;
21
+ max?: number;
15
22
  isPlaceholder: boolean;
16
- placeholder: any;
23
+ placeholder: string;
17
24
  isEditable: boolean;
18
- value?: undefined;
19
- min?: undefined;
20
- max?: undefined;
21
- type: keyof Intl.DateTimeFormatPartTypesRegistry;
22
- text: any;
23
- })[];
25
+ };
24
26
 
25
- export { getAllSegments, getSegments };
27
+ export { DateSegmentDetails, getAllSegments, getSegments };
@@ -25,6 +25,17 @@ __export(segment_parts_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(segment_parts_exports);
27
27
 
28
+ // src/placeholder.ts
29
+ var import_date = require("@internationalized/date");
30
+ function getTodayPlaceholderDate(timeZone) {
31
+ return (0, import_date.now)(timeZone).set({
32
+ hour: 0,
33
+ minute: 0,
34
+ second: 0,
35
+ millisecond: 0
36
+ });
37
+ }
38
+
28
39
  // src/segment-constants.ts
29
40
  var EDITABLE_SEGMENTS = {
30
41
  year: true,
@@ -41,7 +52,7 @@ function isSegmentEditable(segment) {
41
52
  }
42
53
 
43
54
  // src/segment-limit.ts
44
- var import_date = require("@internationalized/date");
55
+ var import_date2 = require("@internationalized/date");
45
56
  function getSegmentLimits(date, type, options) {
46
57
  switch (type) {
47
58
  case "era": {
@@ -61,13 +72,13 @@ function getSegmentLimits(date, type, options) {
61
72
  case "month":
62
73
  return {
63
74
  value: date.month,
64
- min: (0, import_date.getMinimumMonthInYear)(date),
75
+ min: (0, import_date2.getMinimumMonthInYear)(date),
65
76
  max: date.calendar.getMonthsInYear(date)
66
77
  };
67
78
  case "day":
68
79
  return {
69
80
  value: date.day,
70
- min: (0, import_date.getMinimumDayInMonth)(date),
81
+ min: (0, import_date2.getMinimumDayInMonth)(date),
71
82
  max: date.calendar.getDaysInMonth(date)
72
83
  };
73
84
  }
@@ -107,19 +118,24 @@ function getSegmentLimits(date, type, options) {
107
118
  };
108
119
  }
109
120
  }
110
- return {};
121
+ return {
122
+ value: -1,
123
+ min: -1,
124
+ max: -1
125
+ };
111
126
  }
112
127
 
113
128
  // src/segment-parts.ts
114
129
  function getAllSegments(segments) {
115
130
  return segments.filter((segment) => isSegmentEditable(segment.type)).reduce((acc, segment) => (acc[segment.type] = true, acc), {});
116
131
  }
117
- function getPlaceholder(params) {
132
+ function getPlaceholder(options) {
118
133
  const placeholder = { day: "dd", month: "mm", year: "yyyy" };
119
- return placeholder[params.field];
134
+ return placeholder[options.field];
120
135
  }
121
136
  function getSegments(date, validSegments, formatter, timeZone) {
122
- const segments = formatter.formatToParts(date.toDate(timeZone));
137
+ const dateValue = date || getTodayPlaceholderDate(timeZone);
138
+ const segments = formatter.formatToParts(dateValue.toDate(timeZone));
123
139
  return segments.map((segment) => {
124
140
  let isEditable = isSegmentEditable(segment.type);
125
141
  if (segment.type === "era")
@@ -129,7 +145,7 @@ function getSegments(date, validSegments, formatter, timeZone) {
129
145
  return {
130
146
  type: segment.type,
131
147
  text: isPlaceholder ? placeholder : segment.value,
132
- ...getSegmentLimits(date, segment.type, formatter.resolvedOptions()),
148
+ ...getSegmentLimits(dateValue, segment.type, formatter.resolvedOptions()),
133
149
  isPlaceholder: !!isPlaceholder,
134
150
  placeholder,
135
151
  isEditable: !!isEditable
@@ -1,36 +1,10 @@
1
1
  import {
2
- getSegmentLimits
3
- } from "./chunk-L3YHK2WH.mjs";
4
- import {
5
- isSegmentEditable
6
- } from "./chunk-6NI2PIAA.mjs";
7
-
8
- // src/segment-parts.ts
9
- function getAllSegments(segments) {
10
- return segments.filter((segment) => isSegmentEditable(segment.type)).reduce((acc, segment) => (acc[segment.type] = true, acc), {});
11
- }
12
- function getPlaceholder(params) {
13
- const placeholder = { day: "dd", month: "mm", year: "yyyy" };
14
- return placeholder[params.field];
15
- }
16
- function getSegments(date, validSegments, formatter, timeZone) {
17
- const segments = formatter.formatToParts(date.toDate(timeZone));
18
- return segments.map((segment) => {
19
- let isEditable = isSegmentEditable(segment.type);
20
- if (segment.type === "era")
21
- isEditable = false;
22
- let isPlaceholder = isSegmentEditable(segment.type) && !validSegments[segment.type];
23
- let placeholder = isSegmentEditable(segment.type) ? getPlaceholder({ field: segment.type }) : null;
24
- return {
25
- type: segment.type,
26
- text: isPlaceholder ? placeholder : segment.value,
27
- ...getSegmentLimits(date, segment.type, formatter.resolvedOptions()),
28
- isPlaceholder: !!isPlaceholder,
29
- placeholder,
30
- isEditable: !!isEditable
31
- };
32
- });
33
- }
2
+ getAllSegments,
3
+ getSegments
4
+ } from "./chunk-DETLHDDR.mjs";
5
+ import "./chunk-HL7SOSTW.mjs";
6
+ import "./chunk-DZM5JUL2.mjs";
7
+ import "./chunk-RJCAPB5F.mjs";
34
8
  export {
35
9
  getAllSegments,
36
10
  getSegments
package/dist/types.d.ts CHANGED
@@ -1,2 +1,22 @@
1
- import '@internationalized/date';
2
- export { D as DateAlignment, a as DateAvailableFn, e as DateFormatOptions, b as DateGranularity, d as DateSegmentPart, c as DateSegments, G as GetFormatterFn, f as GetPlaceholderFn } from './types-cbf8b45a.js';
1
+ import { DateFormatter, DateValue, CalendarDate } from '@internationalized/date';
2
+
3
+ type DateGranularity = "day" | "hour" | "minute" | "second" | "year" | "month";
4
+ type DateAlignment = "start" | "end" | "center";
5
+ type GetFormatterFn = (options: Intl.DateTimeFormatOptions) => DateFormatter;
6
+ type DateAvailableFn = (date: DateValue) => boolean;
7
+ type GetPlaceholderFn = (options: {
8
+ field: string;
9
+ locale: string;
10
+ }) => string;
11
+ type DateAdjustFn = (options: {
12
+ startDate: CalendarDate;
13
+ focusedDate: CalendarDate;
14
+ }) => {
15
+ startDate: CalendarDate;
16
+ focusedDate: CalendarDate;
17
+ endDate: CalendarDate;
18
+ };
19
+ type DateSegmentPart = Intl.DateTimeFormatPartTypes;
20
+ type DateFormatOptions = Intl.ResolvedDateTimeFormatOptions;
21
+
22
+ export { DateAdjustFn, DateAlignment, DateAvailableFn, DateFormatOptions, DateGranularity, DateSegmentPart, GetFormatterFn, GetPlaceholderFn };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/date-utils",
3
- "version": "0.0.0-dev-20230107162446",
3
+ "version": "0.0.0-dev-20230107200900",
4
4
  "description": "Date utilities for zag.js",
5
5
  "keywords": [
6
6
  "js",
@@ -1,35 +0,0 @@
1
- import { DateFormatter, DateValue } from '@internationalized/date';
2
-
3
- declare const EDITABLE_SEGMENTS: {
4
- year: boolean;
5
- month: boolean;
6
- day: boolean;
7
- hour: boolean;
8
- minute: boolean;
9
- second: boolean;
10
- dayPeriod: boolean;
11
- era: boolean;
12
- };
13
- type DateSegments = Partial<typeof EDITABLE_SEGMENTS>;
14
- declare const SEGMENT_PAGE_STEP: {
15
- year: number;
16
- month: number;
17
- day: number;
18
- hour: number;
19
- minute: number;
20
- second: number;
21
- };
22
- declare function isSegmentEditable(segment: DateSegmentPart): any;
23
-
24
- type DateGranularity = "day" | "hour" | "minute" | "second" | "year" | "month";
25
- type DateAlignment = "start" | "end" | "center";
26
- type GetFormatterFn = (options: Intl.DateTimeFormatOptions) => DateFormatter;
27
- type DateAvailableFn = (date: DateValue) => boolean;
28
- type GetPlaceholderFn = (options: {
29
- field: string;
30
- locale: string;
31
- }) => string;
32
- type DateSegmentPart = Intl.DateTimeFormatPartTypes;
33
- type DateFormatOptions = Intl.ResolvedDateTimeFormatOptions;
34
-
35
- export { DateAlignment as D, GetFormatterFn as G, SEGMENT_PAGE_STEP as S, DateAvailableFn as a, DateGranularity as b, DateSegments as c, DateSegmentPart as d, DateFormatOptions as e, GetPlaceholderFn as f, isSegmentEditable as i };