@orfium/ictinus 4.76.0 → 4.77.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.
@@ -59,7 +59,8 @@ var Day = function Day(_ref) {
59
59
  isFirst: isFirst,
60
60
  isToday: isToday,
61
61
  disabled: disabled
62
- })
62
+ }),
63
+ "data-testid": day + "_" + (month + 1) + "_" + year + ("" + (isSelected ? '_selected' : ''))
63
64
  }, (0, _react2.jsx)("div", {
64
65
  css: (0, _Day.dayStyle)({
65
66
  isSelected: isSelected,
@@ -16,12 +16,6 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
16
16
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
18
18
  _dayjs["default"].extend(_isBetween["default"]);
19
- function getNumWeeksForMonth(year, month) {
20
- var date = new Date(year, month - 1, 1);
21
- var day = date.getDay();
22
- var numDaysInMonth = new Date(year, month, 0).getDate();
23
- return Math.ceil((numDaysInMonth + day) / 7);
24
- }
25
19
  var DAYS = ['Monday', 'Tuesday', 'Wednesday', 'Thurdsday', 'Friday', 'Saturday', 'Sunday'];
26
20
  var Month = function Month(_ref) {
27
21
  var year = _ref.year,
@@ -32,9 +26,14 @@ var Month = function Month(_ref) {
32
26
  var weeksWithDays = React.useMemo(function () {
33
27
  var monthDate = _utils.currentDay.month(month).year(year).date(1);
34
28
  var daysOfMonth = monthDate.daysInMonth();
35
- var startDay = monthDate.day();
29
+ /**
30
+ * Dayjs uses 0-6 (Sun-Sat) indexing for days of the week, while the reduce callback on line 48 uses
31
+ * 1-7 (Mon-Sun) indexing for calculating the days array for the calendar grid. To resolve this conflict,
32
+ * we replace the 0 used for Sunday with 7, so that Dayjs can match our internal indexing.
33
+ */
34
+ var startDay = monthDate.day() || 7;
36
35
  var daysPerWeekCount = 7;
37
- var weeksCount = getNumWeeksForMonth(year, month);
36
+ var weeksCount = (0, _Month2.getNumWeeksForMonth)(year, month);
38
37
  var daysForThisMonthsWeeks = Array(weeksCount * daysPerWeekCount).fill(null);
39
38
  var days = daysForThisMonthsWeeks.reduce(function (acc, __day, index) {
40
39
  var dayIndex = index + 1; // to start for monday
@@ -4,3 +4,4 @@ export declare const calculateDisabledDays: (day: number | undefined, month: num
4
4
  export declare const calculatedDayIsBetween: (day: number | undefined, month: number, year: number, from: Dayjs | undefined, to: Dayjs | undefined) => boolean | undefined;
5
5
  export declare const calculateSelectedDayPosition: (day: number | undefined, position: "first" | "last" | undefined, month: number, year: number, from: Dayjs | undefined, to: Dayjs | undefined) => boolean | 0 | undefined;
6
6
  export declare const calculateSelectedDay: (day: number, month: number, year: number, from: Dayjs | undefined, to: Dayjs | undefined) => boolean;
7
+ export declare const getNumWeeksForMonth: (year: number, month: number) => number;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.calculatedDayIsBetween = exports.calculateSelectedDayPosition = exports.calculateSelectedDay = exports.calculateDisabledDays = void 0;
4
+ exports.getNumWeeksForMonth = exports.calculatedDayIsBetween = exports.calculateSelectedDayPosition = exports.calculateSelectedDay = exports.calculateDisabledDays = void 0;
5
5
  var _dayjs = _interopRequireDefault(require("dayjs"));
6
6
  var _utils = require("../utils");
7
7
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
@@ -52,4 +52,29 @@ var calculateSelectedDay = function calculateSelectedDay(day, month, year, from,
52
52
  var date = _utils.currentDay.month(month).year(year).date(day);
53
53
  return [from == null ? void 0 : from.format('D,M,YYYY'), to == null ? void 0 : to.format('D,M,YYYY')].includes(date.format('D,M,YYYY'));
54
54
  };
55
- exports.calculateSelectedDay = calculateSelectedDay;
55
+ exports.calculateSelectedDay = calculateSelectedDay;
56
+ var getNumWeeksForMonth = function getNumWeeksForMonth(year, month) {
57
+ // Create a date object for the first day of the month
58
+ var firstDayOfMonth = new Date(year, month, 1);
59
+
60
+ // Get the day of the week for the first day (0 = Monday, 1 = Tuesday, ..., 6 = Sunday)
61
+ var firstDayOfWeek = (firstDayOfMonth.getDay() + 6) % 7; // Adjusting the index to start from Monday
62
+
63
+ // Calculate the number of days in the month
64
+ var lastDayOfMonth = new Date(year, month + 1, 0);
65
+ var totalDaysInMonth = lastDayOfMonth.getDate();
66
+
67
+ // Calculate the number of days needed to complete the first week
68
+ var daysToCompleteFirstWeek = 7 - firstDayOfWeek;
69
+
70
+ // Calculate the number of remaining days after completing the first week
71
+ var remainingDays = totalDaysInMonth - daysToCompleteFirstWeek;
72
+
73
+ // Calculate the number of additional weeks needed for the remaining days
74
+ var additionalWeeks = Math.ceil(remainingDays / 7);
75
+
76
+ // Total weeks needed, including the first partial week
77
+ var totalWeeks = 1 + additionalWeeks;
78
+ return totalWeeks;
79
+ };
80
+ exports.getNumWeeksForMonth = getNumWeeksForMonth;
@@ -4,9 +4,9 @@ exports.__esModule = true;
4
4
  exports["default"] = void 0;
5
5
  var React = _interopRequireWildcard(require("react"));
6
6
  var _Button = _interopRequireDefault(require("../../Button"));
7
- var _utils = require("../utils");
8
7
  var _MonthWrapper = _interopRequireDefault(require("./components/MonthWrapper/MonthWrapper"));
9
8
  var _OverlayComponent = require("./OverlayComponent.style");
9
+ var _utils = require("./utils");
10
10
  var _react2 = require("@emotion/react");
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
12
12
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -26,10 +26,10 @@ var OverlayComponent = function OverlayComponent(_ref) {
26
26
  onCancel = _ref$onCancel === void 0 ? function () {} : _ref$onCancel,
27
27
  _ref$onApply = _ref.onApply,
28
28
  onApply = _ref$onApply === void 0 ? function () {} : _ref$onApply;
29
- var _useState = (0, React.useState)(_utils.currentDay),
29
+ var _useState = (0, React.useState)((0, _utils.getLeftCalendarDate)(selectedDays)),
30
30
  date = _useState[0],
31
31
  setDate = _useState[1];
32
- var _useState2 = (0, React.useState)(_utils.currentDay),
32
+ var _useState2 = (0, React.useState)((0, _utils.getRightCalendarDate)(selectedDays)),
33
33
  date2 = _useState2[0],
34
34
  setDate2 = _useState2[1];
35
35
  var handleArrow = (0, React.useCallback)(function (direction) {
@@ -75,7 +75,7 @@ var OverlayComponent = function OverlayComponent(_ref) {
75
75
  disabledDates: disabledDates,
76
76
  isRangePicker: isRangePicker
77
77
  }), isRangePicker && (0, _react2.jsx)(_MonthWrapper["default"], {
78
- date: date2.month(date2.month() + 1),
78
+ date: date2,
79
79
  onDaySelect: onDaySelect,
80
80
  selectedDays: selectedDays,
81
81
  setDate: setDate2,
@@ -55,6 +55,7 @@ var MonthWrapper = function MonthWrapper(_ref) {
55
55
  onClick: function onClick() {
56
56
  return handleArrow('back');
57
57
  },
58
+ "data-testid": "month_back",
58
59
  css: (0, _MonthWrapper.monthHeaderNavigationIconWrapperStyle)({
59
60
  position: 'left'
60
61
  })
@@ -83,8 +84,11 @@ var MonthWrapper = function MonthWrapper(_ref) {
83
84
  name: 'triangleDown',
84
85
  size: 10,
85
86
  color: theme.utils.getColor('darkGrey', 850)
86
- })
87
- }, date.format('MMMM'), " ", date.format('YYYY')) : (0, _react2.jsx)("div", null, date.format('MMMM'), " ", date.format('YYYY'))), open && (0, _react2.jsx)(_SelectMenu["default"], {
87
+ }),
88
+ dataTestId: 'month'
89
+ }, date.format('MMMM'), " ", date.format('YYYY')) : (0, _react2.jsx)("div", {
90
+ "data-testid": (showedArrows !== 'both' ? showedArrows + '_' : '') + "month"
91
+ }, date.format('MMMM'), " ", date.format('YYYY'))), open && (0, _react2.jsx)(_SelectMenu["default"], {
88
92
  filteredOptions: years,
89
93
  handleOptionClick: function handleOptionClick(e) {
90
94
  setDate(date.year(Number(e.value)));
@@ -97,7 +101,8 @@ var MonthWrapper = function MonthWrapper(_ref) {
97
101
  },
98
102
  css: (0, _MonthWrapper.monthHeaderNavigationIconWrapperStyle)({
99
103
  position: 'right'
100
- })
104
+ }),
105
+ "data-testid": "month_forward"
101
106
  }, (0, _react2.jsx)(_Icon["default"], {
102
107
  name: 'chevronSmallRight',
103
108
  color: theme.utils.getColor('darkGrey', 850),
@@ -0,0 +1,4 @@
1
+ import { Dayjs } from 'dayjs';
2
+ import { Range } from './OverlayComponent';
3
+ export declare const getLeftCalendarDate: (selectedDays: Range) => Dayjs;
4
+ export declare const getRightCalendarDate: (selectedDays: Range) => Dayjs;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.getRightCalendarDate = exports.getLeftCalendarDate = void 0;
5
+ var _utils = require("../utils");
6
+ var getLeftCalendarDate = function getLeftCalendarDate(selectedDays) {
7
+ var _selectedDays$from;
8
+ return (_selectedDays$from = selectedDays.from) != null ? _selectedDays$from : _utils.currentDay;
9
+ };
10
+ exports.getLeftCalendarDate = getLeftCalendarDate;
11
+ var getRightCalendarDate = function getRightCalendarDate(selectedDays) {
12
+ var _selectedDays$from$mo, _selectedDays$from2, _selectedDays$from3;
13
+ return (_selectedDays$from$mo = (_selectedDays$from2 = selectedDays.from) == null ? void 0 : _selectedDays$from2.month(((_selectedDays$from3 = selectedDays.from) == null ? void 0 : _selectedDays$from3.month()) + 1)) != null ? _selectedDays$from$mo : _utils.currentDay.month(_utils.currentDay.month() + 1);
14
+ };
15
+ exports.getRightCalendarDate = getRightCalendarDate;
@@ -1,6 +1,6 @@
1
- import dayjs from 'dayjs';
1
+ import { Dayjs } from 'dayjs';
2
2
  import { Range } from './OverlayComponent/OverlayComponent';
3
- export declare const currentDay: dayjs.Dayjs;
3
+ export declare const currentDay: Dayjs;
4
4
  export declare const initDates: (value: {
5
5
  from?: Date;
6
6
  to?: Date;
@@ -16,7 +16,7 @@ export declare type SelectOption = {
16
16
  } & SelectOptionValues;
17
17
  export declare type Props = {
18
18
  /** The function that is used to return the selected options */
19
- handleSelectedOption?: (selectedOption: SelectOption) => void;
19
+ handleSelectedOption?: (selectedOption?: SelectOption) => void;
20
20
  /** the default value of the select if needed */
21
21
  /** TODO: defaultValue is duplication of selectedOption*/
22
22
  defaultValue?: SelectOption;
@@ -59,7 +59,7 @@ export declare type Props = {
59
59
  } & TextFieldProps;
60
60
  declare const Select: React.ForwardRefExoticComponent<{
61
61
  /** The function that is used to return the selected options */
62
- handleSelectedOption?: ((selectedOption: SelectOption) => void) | undefined;
62
+ handleSelectedOption?: ((selectedOption?: SelectOption | undefined) => void) | undefined;
63
63
  /** the default value of the select if needed */
64
64
  /** TODO: defaultValue is duplication of selectedOption*/
65
65
  defaultValue?: SelectOption | undefined;
@@ -226,6 +226,7 @@ var Select = /*#__PURE__*/_react["default"].forwardRef(function (_ref, ref) {
226
226
  var isBackspace = event.key === 'Backspace';
227
227
  if (isBackspace) {
228
228
  setInputValue(emptyValue);
229
+ handleSelectedOption(undefined);
229
230
  debouncedOnChange('');
230
231
  }
231
232
  };
@@ -63,6 +63,9 @@ var useMultiselectUtils = function useMultiselectUtils(_ref) {
63
63
  if (!lastItem.isCreated) {
64
64
  setAvailableMultiSelectOptions([].concat(availableMultiSelectOptions, [lastItem]));
65
65
  }
66
+ if (onOptionDelete) {
67
+ onOptionDelete(lastItem);
68
+ }
66
69
  }
67
70
  }
68
71
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orfium/ictinus",
3
- "version": "4.76.0",
3
+ "version": "4.77.1",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "MIT",