rsuite 6.0.0-canary-20250827 → 6.0.0-canary-20250904

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 (40) hide show
  1. package/cjs/Calendar/CalendarBody.js +4 -1
  2. package/cjs/Calendar/CalendarContainer.js +0 -2
  3. package/cjs/Calendar/CalendarProvider.d.ts +0 -6
  4. package/cjs/Calendar/Grid/Grid.d.ts +2 -1
  5. package/cjs/Calendar/Grid/Grid.js +2 -2
  6. package/cjs/Calendar/Grid/GridRow.d.ts +8 -2
  7. package/cjs/Calendar/Grid/GridRow.js +63 -28
  8. package/cjs/Calendar/hooks/useCalendar.d.ts +0 -1
  9. package/cjs/Navbar/Navbar.d.ts +5 -1
  10. package/cjs/Navbar/Navbar.js +2 -1
  11. package/cjs/Navbar/NavbarContent.d.ts +8 -3
  12. package/cjs/Navbar/NavbarContent.js +30 -5
  13. package/cjs/internals/utils/date/getWeekStartDates.d.ts +4 -3
  14. package/cjs/internals/utils/date/getWeekStartDates.js +10 -5
  15. package/cjs/internals/utils/date/plainDate.d.ts +7 -0
  16. package/cjs/internals/utils/date/plainDate.js +26 -2
  17. package/cjs/internals/utils/date/types.d.ts +9 -0
  18. package/cjs/internals/utils/date/types.js +6 -0
  19. package/dist/rsuite.js +11 -11
  20. package/dist/rsuite.min.js +1 -1
  21. package/dist/rsuite.min.js.map +1 -1
  22. package/esm/Calendar/CalendarBody.js +4 -1
  23. package/esm/Calendar/CalendarContainer.js +1 -3
  24. package/esm/Calendar/CalendarProvider.d.ts +0 -6
  25. package/esm/Calendar/Grid/Grid.d.ts +2 -1
  26. package/esm/Calendar/Grid/Grid.js +2 -2
  27. package/esm/Calendar/Grid/GridRow.d.ts +8 -2
  28. package/esm/Calendar/Grid/GridRow.js +65 -29
  29. package/esm/Calendar/hooks/useCalendar.d.ts +0 -1
  30. package/esm/Navbar/Navbar.d.ts +5 -1
  31. package/esm/Navbar/Navbar.js +4 -3
  32. package/esm/Navbar/NavbarContent.d.ts +8 -3
  33. package/esm/Navbar/NavbarContent.js +29 -5
  34. package/esm/internals/utils/date/getWeekStartDates.d.ts +4 -3
  35. package/esm/internals/utils/date/getWeekStartDates.js +9 -4
  36. package/esm/internals/utils/date/plainDate.d.ts +7 -0
  37. package/esm/internals/utils/date/plainDate.js +24 -2
  38. package/esm/internals/utils/date/types.d.ts +9 -0
  39. package/esm/internals/utils/date/types.js +6 -0
  40. package/package.json +1 -1
@@ -38,7 +38,10 @@ const CalendarBody = (0, _utils.forwardRef)((props, ref) => {
38
38
  ref: ref,
39
39
  className: classes
40
40
  }), /*#__PURE__*/_react.default.createElement(_Grid.default, {
41
- rows: (0, _date.getWeekStartDates)(thisMonthDate, {
41
+ rows: (0, _date.getWeekStartDates)({
42
+ year: date.getFullYear(),
43
+ month: date.getMonth() + 1
44
+ }, {
42
45
  weekStart,
43
46
  locale: locale === null || locale === void 0 ? void 0 : locale.dateLocale
44
47
  }),
@@ -88,7 +88,6 @@ const CalendarContainer = (0, _utils.forwardRef)((props, ref) => {
88
88
  } = (0, _date.useDateMode)(format);
89
89
  const timeMode = calendarState === _hooks2.CalendarState.TIME || mode === _date.DateMode.Time;
90
90
  const monthMode = calendarState === _hooks2.CalendarState.MONTH || mode === _date.DateMode.Month;
91
- const inSameThisMonthDate = date => (0, _date.isSameMonth)(calendarDate, date);
92
91
  const calendarClasses = merge(className, withPrefix({
93
92
  'time-view': timeMode,
94
93
  'month-view': monthMode,
@@ -114,7 +113,6 @@ const CalendarContainer = (0, _utils.forwardRef)((props, ref) => {
114
113
  monthDropdownProps,
115
114
  cellClassName,
116
115
  disabledDate: isDateDisabled,
117
- inSameMonth: inSameThisMonthDate,
118
116
  onChangeMonth: handleChangeMonth,
119
117
  onChangeTime,
120
118
  onMouseMove,
@@ -55,12 +55,6 @@ export interface CalendarInnerContextValue {
55
55
  * @returns True if the date is disabled, false otherwise.
56
56
  */
57
57
  disabledDate?: (date: Date, selectRangeValue?: Date[], type?: string) => boolean;
58
- /**
59
- * A function that determines if a date is in the same month as the current date in the calendar.
60
- * @param date - The date to check.
61
- * @returns True if the date is in the same month, false otherwise.
62
- */
63
- inSameMonth?: (date: Date) => boolean;
64
58
  /**
65
59
  * A callback function that is called when the month is changed in the calendar.
66
60
  * @param nextPageDate - The next page date.
@@ -1,6 +1,7 @@
1
1
  import { WithAsProps } from '../../internals/types';
2
+ import type { PlainDate } from '../../internals/utils/date';
2
3
  export interface GridProps extends WithAsProps {
3
- rows: any[];
4
+ rows: readonly PlainDate[];
4
5
  }
5
6
  declare const Grid: import("../../internals/types").InternalRefForwardingComponent<"div", GridProps, never> & Record<string, never>;
6
7
  export default Grid;
@@ -34,9 +34,9 @@ const Grid = (0, _utils.forwardRef)((props, ref) => {
34
34
  }, rest, {
35
35
  ref: ref,
36
36
  className: classes
37
- }), /*#__PURE__*/_react.default.createElement(_GridHeaderRow.default, null), rows.map((week, index) => /*#__PURE__*/_react.default.createElement(_GridRow.default, {
37
+ }), /*#__PURE__*/_react.default.createElement(_GridHeaderRow.default, null), rows.map((rowStartingDate, index) => /*#__PURE__*/_react.default.createElement(_GridRow.default, {
38
38
  key: index,
39
- weekendDate: week,
39
+ startingDate: rowStartingDate,
40
40
  rowIndex: index + 1
41
41
  })));
42
42
  });
@@ -1,7 +1,13 @@
1
+ import { type PlainDate } from '../../internals/utils/date';
1
2
  import { WithAsProps } from '../../internals/types';
3
+ /**
4
+ * A row in the calendar month view grid, i.e. a week of days.
5
+ */
2
6
  export interface GridRowProps extends WithAsProps {
3
- /** The weekend: Sunday */
4
- weekendDate?: Date;
7
+ /**
8
+ * The starting day of the row of dates.
9
+ */
10
+ startingDate: PlainDate;
5
11
  /** The index of the row */
6
12
  rowIndex?: number;
7
13
  }
@@ -12,14 +12,19 @@ var _date = require("../../internals/utils/date");
12
12
  var _constants = require("../../internals/constants");
13
13
  var _hooks = require("../../internals/hooks");
14
14
  var _hooks2 = require("../hooks");
15
+ var _plainDate = require("../../internals/utils/date/plainDate");
15
16
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
17
+ /**
18
+ * A row in the calendar month view grid, i.e. a week of days.
19
+ */
20
+
16
21
  const GridRow = (0, _utils.forwardRef)((props, ref) => {
17
22
  var _locale$dateLocale$op, _locale$dateLocale;
18
23
  const {
19
24
  as: Component = 'div',
20
25
  className,
21
26
  classPrefix = 'calendar-table',
22
- weekendDate = new Date(),
27
+ startingDate,
23
28
  rowIndex,
24
29
  ...rest
25
30
  } = props;
@@ -31,7 +36,6 @@ const GridRow = (0, _utils.forwardRef)((props, ref) => {
31
36
  weekStart,
32
37
  showWeekNumbers,
33
38
  locale,
34
- inSameMonth,
35
39
  disabledDate,
36
40
  onSelect
37
41
  } = (0, _hooks2.useCalendar)();
@@ -47,53 +51,84 @@ const GridRow = (0, _utils.forwardRef)((props, ref) => {
47
51
  }, [onSelect]);
48
52
  const renderDays = () => {
49
53
  const days = [];
50
- const [selectedStartDate, selectedEndDate] = dateRange || [];
51
- const [hoverStartDate, hoverEndDate] = hoverRangeValue !== null && hoverRangeValue !== void 0 ? hoverRangeValue : [];
54
+ // The start and end dates of the range selection
55
+ // Note that they can be
56
+ // - Invalid date - when the user is inputting the date with text input
57
+ // - undefined - when the range selection isn't completed
58
+ const [selectedStartDateJS, selectedEndDateJS] = dateRange || [];
59
+ const [hoverStartDateJS, hoverEndDateJS] = hoverRangeValue !== null && hoverRangeValue !== void 0 ? hoverRangeValue : [];
52
60
  const isRangeSelectionMode = typeof dateRange !== 'undefined';
53
61
  for (let i = 0; i < 7; i += 1) {
54
- const thisDate = (0, _date.addDays)(weekendDate, i);
55
- const disabled = disabledDate === null || disabledDate === void 0 ? void 0 : disabledDate(thisDate, dateRange, _constants.DATERANGE_DISABLED_TARGET.CALENDAR);
56
- const unSameMonth = !(inSameMonth !== null && inSameMonth !== void 0 && inSameMonth(thisDate));
57
- const rangeStart = !unSameMonth && selectedStartDate && (0, _date.isSameDay)(thisDate, selectedStartDate);
58
- const rangeEnd = !unSameMonth && selectedEndDate && (0, _date.isSameDay)(thisDate, selectedEndDate);
59
- const isSelected = isRangeSelectionMode ? rangeStart || rangeEnd : (0, _date.isSameDay)(thisDate, selected);
62
+ const thisDate = (0, _plainDate.addDays)(startingDate, i);
63
+ const thisDateJS = new Date(thisDate.year, thisDate.month - 1, thisDate.day);
64
+ const disabled = disabledDate === null || disabledDate === void 0 ? void 0 : disabledDate(thisDateJS, dateRange, _constants.DATERANGE_DISABLED_TARGET.CALENDAR);
65
+
66
+ // Whether this date is in a different month from the selected date
67
+ const isSameMonth = selected.getFullYear() === thisDate.year && selected.getMonth() + 1 === thisDate.month;
68
+
69
+ // Whether this date is the range start date and is in the same month with the selected date
70
+ const isRangeStart = isSameMonth && selectedStartDateJS && (0, _plainDate.isSameDay)(thisDate, selectedStartDateJS);
71
+
72
+ // Whether this date is the range end date and is in the same month with the selected date
73
+ const isRangeEnd = isSameMonth && selectedEndDateJS && (0, _plainDate.isSameDay)(thisDate, selectedEndDateJS);
74
+
75
+ // Whether this date should be displayed in the "selected" state
76
+ // Either
77
+ // - In range selection mode, it's either the range start or end date
78
+ // - Otherwise, it's the selected date itself
79
+ const isSelected = isRangeSelectionMode ? isRangeStart || isRangeEnd : (0, _plainDate.isSameDay)(thisDate, selected);
60
80
 
61
81
  // TODO-Doma Move those logic that's for DatePicker/DateRangePicker to a separate component
62
82
  // Calendar is not supposed to be reused this way
63
83
  let inRange = false;
64
84
  // for Selected
65
- if (selectedStartDate && selectedEndDate) {
66
- if ((0, _date.isBefore)(thisDate, selectedEndDate) && (0, _date.isAfter)(thisDate, selectedStartDate)) {
85
+ if (selectedStartDateJS && selectedEndDateJS) {
86
+ const selectedStartDate = {
87
+ year: selectedStartDateJS.getFullYear(),
88
+ month: selectedStartDateJS.getMonth() + 1,
89
+ day: selectedStartDateJS.getDate()
90
+ };
91
+ const selectedEndDate = {
92
+ year: selectedEndDateJS.getFullYear(),
93
+ month: selectedEndDateJS.getMonth() + 1,
94
+ day: selectedEndDateJS.getDate()
95
+ };
96
+ if ((0, _plainDate.compare)(thisDate, selectedEndDate) < 0 && (0, _plainDate.compare)(thisDate, selectedStartDate) > 0) {
67
97
  inRange = true;
68
98
  }
69
- if ((0, _date.isBefore)(thisDate, selectedStartDate) && (0, _date.isAfter)(thisDate, selectedEndDate)) {
99
+ if ((0, _plainDate.compare)(thisDate, selectedStartDate) < 0 && (0, _plainDate.compare)(thisDate, selectedEndDate) > 0) {
70
100
  inRange = true;
71
101
  }
72
102
  }
73
103
 
74
104
  // for Hovering
75
- if (!isSelected && hoverStartDate && hoverEndDate) {
76
- if (!(0, _date.isAfter)(thisDate, hoverEndDate) && !(0, _date.isBefore)(thisDate, hoverStartDate)) {
105
+ if (!isSelected && hoverStartDateJS && hoverEndDateJS) {
106
+ const hoverStartDate = {
107
+ year: hoverStartDateJS.getFullYear(),
108
+ month: hoverStartDateJS.getMonth() + 1,
109
+ day: hoverStartDateJS.getDate()
110
+ };
111
+ const hoverEndDate = {
112
+ year: hoverEndDateJS.getFullYear(),
113
+ month: hoverEndDateJS.getMonth() + 1,
114
+ day: hoverEndDateJS.getDate()
115
+ };
116
+ if ((0, _plainDate.compare)(thisDate, hoverEndDate) <= 0 && (0, _plainDate.compare)(thisDate, hoverStartDate) >= 0) {
77
117
  inRange = true;
78
118
  }
79
- if (!(0, _date.isAfter)(thisDate, hoverStartDate) && !(0, _date.isBefore)(thisDate, hoverEndDate)) {
119
+ if ((0, _plainDate.compare)(thisDate, hoverStartDate) <= 0 && (0, _plainDate.compare)(thisDate, hoverEndDate) >= 0) {
80
120
  inRange = true;
81
121
  }
82
122
  }
83
- const thisDatePlain = {
84
- year: thisDate.getFullYear(),
85
- month: thisDate.getMonth() + 1,
86
- day: thisDate.getDate()
87
- };
88
123
  days.push(/*#__PURE__*/_react.default.createElement(_GridCell.default, {
89
- key: (0, _date.format)(thisDate, 'yyyy-MM-dd'),
90
- date: thisDatePlain,
124
+ key: (0, _date.format)(thisDateJS, 'yyyy-MM-dd'),
125
+ date: thisDate,
91
126
  disabled: disabled,
92
127
  selected: isSelected,
93
128
  onSelect: handleSelect,
94
- unSameMonth: unSameMonth,
95
- rangeStart: rangeStart,
96
- rangeEnd: rangeEnd,
129
+ unSameMonth: !isSameMonth,
130
+ rangeStart: isRangeStart,
131
+ rangeEnd: isRangeEnd,
97
132
  inRange: inRange
98
133
  }));
99
134
  }
@@ -104,8 +139,8 @@ const GridRow = (0, _utils.forwardRef)((props, ref) => {
104
139
  firstWeekContainsDate
105
140
  } = (_locale$dateLocale$op = locale === null || locale === void 0 || (_locale$dateLocale = locale.dateLocale) === null || _locale$dateLocale === void 0 ? void 0 : _locale$dateLocale.options) !== null && _locale$dateLocale$op !== void 0 ? _locale$dateLocale$op : {};
106
141
  // ISO week starts on Monday
107
- const date = isoWeek ? (0, _date.addDays)(weekendDate, 1) : weekendDate;
108
- const week = (0, _date.format)(date, isoWeek ? 'I' : 'w', {
142
+ const date = isoWeek ? (0, _plainDate.addDays)(startingDate, 1) : startingDate;
143
+ const week = (0, _date.format)(new Date(date.year, date.month - 1, date.day), isoWeek ? 'I' : 'w', {
109
144
  locale: locale === null || locale === void 0 ? void 0 : locale.dateLocale,
110
145
  firstWeekContainsDate,
111
146
  weekStartsOn: weekStart
@@ -9,7 +9,6 @@ export declare const useCalendar: () => {
9
9
  targetId?: string | undefined;
10
10
  monthDropdownProps?: import("../types").MonthDropdownProps | undefined;
11
11
  disabledDate?: ((date: Date, selectRangeValue?: Date[] | undefined, type?: string | undefined) => boolean) | undefined;
12
- inSameMonth?: ((date: Date) => boolean) | undefined;
13
12
  onChangeMonth?: ((nextPageDate: Date, event: import("react").MouseEvent<Element, MouseEvent>) => void) | undefined;
14
13
  onChangeTime?: ((nextPageTime: Date, event: import("react").MouseEvent<Element, MouseEvent>) => void) | undefined;
15
14
  onMouseMove?: ((date: Date) => void) | undefined;
@@ -5,6 +5,10 @@ export interface NavbarProps extends BoxProps {
5
5
  * The appearance style of the Navbar component.
6
6
  */
7
7
  appearance?: 'default' | 'inverse' | 'subtle';
8
+ /**
9
+ * The open state of the drawer.
10
+ */
11
+ drawerOpen?: boolean;
8
12
  /**
9
13
  * Callback when the drawer is opened or closed.
10
14
  */
@@ -16,7 +20,7 @@ export interface NavbarProps extends BoxProps {
16
20
  */
17
21
  declare const Navbar: import("../internals/types").InternalRefForwardingComponent<"div", NavbarProps, never> & {
18
22
  Brand: import("../internals/types").InternalRefForwardingComponent<"a", Partial<import("../internals/utils").ComponentProps>, never> & Record<string, never>;
19
- Content: import("../internals/types").InternalRefForwardingComponent<import("../internals/types").InternalRefForwardingComponent<"div", BoxProps, never> & Record<string, never>, Partial<import("./NavbarContent").NavbarContentProps>, never> & Record<string, never>;
23
+ Content: React.ForwardRefExoticComponent<import("./NavbarContent").NavbarContentProps & React.RefAttributes<any>>;
20
24
  Toggle: React.ForwardRefExoticComponent<import("./NavbarToggle").NavbarToggleProps & React.RefAttributes<any>>;
21
25
  Drawer: React.ForwardRefExoticComponent<import("..").DrawerProps & React.RefAttributes<any>>;
22
26
  };
@@ -35,6 +35,7 @@ const Navbar = (0, _utils.forwardRef)((props, ref) => {
35
35
  as = 'nav',
36
36
  classPrefix = 'navbar',
37
37
  appearance = 'default',
38
+ drawerOpen,
38
39
  onDrawerOpenChange,
39
40
  ...rest
40
41
  } = propsWithDefaults;
@@ -43,7 +44,7 @@ const Navbar = (0, _utils.forwardRef)((props, ref) => {
43
44
  merge
44
45
  } = (0, _hooks.useStyles)(classPrefix);
45
46
  const classes = merge(className, withPrefix());
46
- const [open, setOpen] = (0, _react.useState)(false);
47
+ const [open, setOpen] = (0, _hooks.useControlled)(drawerOpen, false);
47
48
  const handleToggle = (0, _hooks.useEventCallback)(nextOpen => {
48
49
  setOpen(nextOpen);
49
50
  onDrawerOpenChange === null || onDrawerOpenChange === void 0 || onDrawerOpenChange(nextOpen);
@@ -1,5 +1,10 @@
1
- import { ComponentProps } from '../internals/utils';
1
+ import React from 'react';
2
2
  import { BoxProps } from '../internals/Box';
3
- export type NavbarContentProps = ComponentProps & BoxProps;
4
- declare const NavbarContent: import("../internals/types").InternalRefForwardingComponent<import("../internals/types").InternalRefForwardingComponent<"div", BoxProps, never> & Record<string, never>, Partial<NavbarContentProps>, never> & Record<string, never>;
3
+ interface ChildProps {
4
+ onClose: () => void;
5
+ }
6
+ export interface NavbarContentProps extends Omit<BoxProps, 'children'> {
7
+ children?: React.ReactNode | (({ onClose }: ChildProps) => React.ReactNode);
8
+ }
9
+ declare const NavbarContent: React.ForwardRefExoticComponent<NavbarContentProps & React.RefAttributes<any>>;
5
10
  export default NavbarContent;
@@ -4,11 +4,36 @@
4
4
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
5
  exports.__esModule = true;
6
6
  exports.default = void 0;
7
- var _utils = require("../internals/utils");
7
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
8
+ var _react = _interopRequireWildcard(require("react"));
8
9
  var _Box = _interopRequireDefault(require("../internals/Box"));
9
- const NavbarContent = (0, _utils.createComponent)({
10
- name: 'NavbarContent',
11
- componentAs: _Box.default,
12
- componentClassPrefix: 'navbar-content'
10
+ var _hooks = require("../internals/hooks");
11
+ var _NavbarContext = require("./NavbarContext");
12
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
13
+ const NavbarContent = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
14
+ const {
15
+ className,
16
+ classPrefix = 'navbar-content',
17
+ children,
18
+ ...rest
19
+ } = props;
20
+ const {
21
+ onToggle
22
+ } = (0, _react.useContext)(_NavbarContext.NavbarContext) || {};
23
+ const {
24
+ withPrefix,
25
+ merge
26
+ } = (0, _hooks.useStyles)(classPrefix);
27
+ const classes = merge(className, withPrefix());
28
+ const onClose = (0, _react.useCallback)(() => {
29
+ onToggle === null || onToggle === void 0 || onToggle(false);
30
+ }, [onToggle]);
31
+ return /*#__PURE__*/_react.default.createElement(_Box.default, (0, _extends2.default)({
32
+ ref: ref,
33
+ className: classes
34
+ }, rest), typeof children === 'function' ? children({
35
+ onClose
36
+ }) : children);
13
37
  });
38
+ NavbarContent.displayName = 'NavbarContent';
14
39
  var _default = exports.default = NavbarContent;
@@ -1,13 +1,14 @@
1
1
  import type { Locale } from 'date-fns';
2
+ import type { PlainDate, PlainYearMonth } from './types';
2
3
  /**
3
4
  * Get the first days of weeks in a month。
4
- * @param firstDayOfMonth The first day of the month
5
+ * @param month The month
5
6
  * @param options.weekStart the index of the first day of the week (0 - Sunday)
6
7
  * @param options.isoWeek Whether to use ISO week
7
8
  * @returns A list of first days of weeks in a month
8
9
  */
9
- export declare function getWeekStartDates(firstDayOfMonth: Date, options: {
10
+ export declare function getWeekStartDates(month: PlainYearMonth, options: {
10
11
  weekStart?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
11
12
  locale?: Locale;
12
- }): Date[];
13
+ }): PlainDate[];
13
14
  export default getWeekStartDates;
@@ -4,27 +4,32 @@
4
4
  exports.__esModule = true;
5
5
  exports.default = void 0;
6
6
  exports.getWeekStartDates = getWeekStartDates;
7
- var _addDays = require("date-fns/addDays");
8
7
  var _startOfWeek = require("date-fns/startOfWeek");
8
+ var _plainDate = require("./plainDate");
9
9
  /**
10
10
  * Get the first days of weeks in a month。
11
- * @param firstDayOfMonth The first day of the month
11
+ * @param month The month
12
12
  * @param options.weekStart the index of the first day of the week (0 - Sunday)
13
13
  * @param options.isoWeek Whether to use ISO week
14
14
  * @returns A list of first days of weeks in a month
15
15
  */
16
- function getWeekStartDates(firstDayOfMonth, options) {
16
+ function getWeekStartDates(month, options) {
17
17
  const {
18
18
  weekStart,
19
19
  locale
20
20
  } = options;
21
- const firstDay = (0, _startOfWeek.startOfWeek)(firstDayOfMonth, {
21
+ const firstDayJs = (0, _startOfWeek.startOfWeek)(new Date(month.year, month.month - 1, 1), {
22
22
  weekStartsOn: weekStart,
23
23
  locale
24
24
  });
25
+ const firstDay = {
26
+ year: firstDayJs.getFullYear(),
27
+ month: firstDayJs.getMonth() + 1,
28
+ day: firstDayJs.getDate()
29
+ };
25
30
  const days = [firstDay];
26
31
  for (let i = 1; i < 6; i++) {
27
- days.push((0, _addDays.addDays)(firstDay, i * 7));
32
+ days.push((0, _plainDate.addDays)(firstDay, i * 7));
28
33
  }
29
34
  return days;
30
35
  }
@@ -1,2 +1,9 @@
1
1
  import type { PlainDate } from './types';
2
+ /**
3
+ * Resembles the behavior of `Temporal.PlainDate.compare`.
4
+ *
5
+ * @see https://tc39.es/proposal-temporal/docs/plaindatetime.html#compare
6
+ */
7
+ export declare function compare(date1: PlainDate, date2: PlainDate): -1 | 0 | 1;
2
8
  export declare function isSameDay(date: PlainDate, jsDate: Date): boolean;
9
+ export declare function addDays(date: PlainDate, days: number): PlainDate;
@@ -2,6 +2,8 @@
2
2
  "use strict";
3
3
 
4
4
  exports.__esModule = true;
5
+ exports.addDays = addDays;
6
+ exports.compare = compare;
5
7
  exports.isSameDay = isSameDay;
6
8
  function toPlainDate(date) {
7
9
  return {
@@ -10,7 +12,13 @@ function toPlainDate(date) {
10
12
  day: date.getDate()
11
13
  };
12
14
  }
13
- function comparePlainDates(date1, date2) {
15
+
16
+ /**
17
+ * Resembles the behavior of `Temporal.PlainDate.compare`.
18
+ *
19
+ * @see https://tc39.es/proposal-temporal/docs/plaindatetime.html#compare
20
+ */
21
+ function compare(date1, date2) {
14
22
  if (date1.year < date2.year) return -1;
15
23
  if (date1.year > date2.year) return 1;
16
24
  if (date1.month < date2.month) return -1;
@@ -19,6 +27,22 @@ function comparePlainDates(date1, date2) {
19
27
  if (date1.day > date2.day) return 1;
20
28
  return 0;
21
29
  }
30
+
31
+ /**
32
+ * Resembles the behavior of `Temporal.PlainDate.prototype.equals`.
33
+ *
34
+ * @see https://tc39.es/proposal-temporal/docs/plaindatetime.html#equals
35
+ */
36
+ function equals(date1, date2) {
37
+ return compare(date1, date2) === 0;
38
+ }
22
39
  function isSameDay(date, jsDate) {
23
- return comparePlainDates(date, toPlainDate(jsDate)) === 0;
40
+ // If jsDate is an invalid date, always return false
41
+ if (Number.isNaN(jsDate.valueOf())) return false;
42
+ return equals(date, toPlainDate(jsDate));
43
+ }
44
+ function addDays(date, days) {
45
+ const jsDate = new Date(date.year, date.month - 1, date.day);
46
+ jsDate.setDate(jsDate.getDate() + days);
47
+ return toPlainDate(jsDate);
24
48
  }
@@ -75,3 +75,12 @@ export type PlainDate = {
75
75
  readonly month: number;
76
76
  readonly day: number;
77
77
  };
78
+ /**
79
+ * Resembles Temporal.PlainYearMonth
80
+ *
81
+ * @see https://tc39.es/proposal-temporal/docs/plainyearmonth.html
82
+ */
83
+ export type PlainYearMonth = {
84
+ readonly year: number;
85
+ readonly month: number;
86
+ };
@@ -22,4 +22,10 @@ const calendarOnlyProps = exports.calendarOnlyProps = [TimeProp.DisabledHours, T
22
22
  *
23
23
  * Resembles Temporal.PlainDate
24
24
  * @see https://tc39.es/proposal-temporal/docs/plaindate.html
25
+ */
26
+
27
+ /**
28
+ * Resembles Temporal.PlainYearMonth
29
+ *
30
+ * @see https://tc39.es/proposal-temporal/docs/plainyearmonth.html
25
31
  */