@via-profit/ui-kit 0.1.8 → 0.2.1-alpha.3

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 (157) hide show
  1. package/Accordion/index.d.ts +4 -4
  2. package/Autocomplete/AutocompleteContainer.d.ts +34 -7
  3. package/Autocomplete/AutocompleteContainer.js +28 -24
  4. package/Autocomplete/AutocompleteItem.d.ts +1 -1
  5. package/Autocomplete/AutocompleteTextField.d.ts +3 -0
  6. package/Autocomplete/AutocompleteTextField.js +63 -1
  7. package/Autocomplete/OverrideMenuList.d.ts +4 -0
  8. package/Autocomplete/OverrideMenuList.js +39 -0
  9. package/Autocomplete/context.d.ts +9 -1
  10. package/Autocomplete/context.js +15 -1
  11. package/Autocomplete/index.js +9 -10
  12. package/Autocomplete2/Autocomplete2.d.ts +12 -0
  13. package/Autocomplete2/Autocomplete2.js +83 -0
  14. package/Autocomplete2/Autocomplete2TextField.d.ts +7 -0
  15. package/Autocomplete2/Autocomplete2TextField.js +39 -0
  16. package/Autocomplete2/index.d.ts +2 -0
  17. package/Autocomplete2/index.js +7 -0
  18. package/Avatar/AvatarBase.d.ts +4 -4
  19. package/Avatar/index.js +1 -1
  20. package/Badge/BadgeBase.d.ts +4 -4
  21. package/Badge/BadgeDeleteButton.js +6 -6
  22. package/Badge/BadgeOutlined.js +2 -2
  23. package/Badge/BadgeStandard.js +1 -1
  24. package/Button/ButtonBase.d.ts +3 -3
  25. package/Button/ButtonOutlined.js +1 -1
  26. package/Button/ButtonPlain.js +1 -1
  27. package/Button/ButtonStandard.js +4 -11
  28. package/Calendar/CalendarCell.js +22 -4
  29. package/Calendar/CalendarComponent.d.ts +226 -0
  30. package/Calendar/CalendarComponent.js +572 -0
  31. package/Calendar/CalendarControlButton.js +16 -9
  32. package/Calendar/CalendarDayBadge.js +1 -1
  33. package/Calendar/CalendarEmptyCell.d.ts +2 -2
  34. package/Calendar/CalendarEmptyCell.js +8 -3
  35. package/Calendar/CalendarHeading.js +2 -1
  36. package/Calendar/CalendarMonthCell.js +0 -5
  37. package/Calendar/CalendarSubheading.js +3 -2
  38. package/Calendar/CalendarWeekDayCell.d.ts +10 -0
  39. package/Calendar/CalendarWeekDayCell.js +32 -0
  40. package/Calendar/CalendarWeekDayWeekNumber.d.ts +7 -0
  41. package/Calendar/CalendarWeekDayWeekNumber.js +38 -0
  42. package/Calendar/CalendarWeekRow.d.ts +2 -2
  43. package/Calendar/CalendarWeekRow.js +2 -1
  44. package/Calendar/CalendarWeekRowButton.d.ts +13 -0
  45. package/Calendar/CalendarWeekRowButton.js +31 -0
  46. package/Calendar/CalendarYearCell.js +5 -5
  47. package/Calendar/CalendarYearsSelector.d.ts +39 -1
  48. package/Calendar/CalendarYearsSelector.js +52 -16
  49. package/Calendar/IconChevronDown.d.ts +3 -0
  50. package/Calendar/IconChevronDown.js +31 -0
  51. package/Calendar/index.d.ts +7 -220
  52. package/Calendar/index.js +19 -274
  53. package/Calendar/use-calendar.d.ts +1 -1
  54. package/Calendar/use-calendar.js +102 -155
  55. package/Color/Color.d.ts +138 -0
  56. package/Color/Color.js +324 -0
  57. package/Color/ColorGenerator.d.ts +29 -0
  58. package/Color/ColorGenerator.js +141 -0
  59. package/Color/ColorParser.d.ts +20 -0
  60. package/Color/ColorParser.js +284 -0
  61. package/Color/index.d.ts +4 -122
  62. package/Color/index.js +18 -473
  63. package/DatePicker/index.d.ts +2 -17
  64. package/DatePicker/index.js +47 -61
  65. package/DatePicker/useDatePickerFormat.js +5 -5
  66. package/ErrorBoundary/Fallback.d.ts +3 -0
  67. package/ErrorBoundary/Fallback.js +51 -0
  68. package/ErrorBoundary/RenderError.d.ts +6 -0
  69. package/ErrorBoundary/RenderError.js +80 -0
  70. package/ErrorBoundary/index.d.ts +7 -11
  71. package/ErrorBoundary/index.js +4 -51
  72. package/Highlighted/index.d.ts +3 -3
  73. package/LoadingIndicator/Spinner.d.ts +5 -3
  74. package/LoadingIndicator/Spinner.js +61 -32
  75. package/LoadingIndicator/index.d.ts +3 -3
  76. package/LoadingIndicator/index.js +15 -2
  77. package/MaskedField/index.d.ts +1 -1
  78. package/MaskedField/index.js +11 -10
  79. package/Menu/AutoHeightWrapper.d.ts +6 -0
  80. package/Menu/AutoHeightWrapper.js +43 -0
  81. package/Menu/MeasuredItem.d.ts +10 -0
  82. package/Menu/MeasuredItem.js +51 -0
  83. package/Menu/MenuContainer.d.ts +53 -20
  84. package/Menu/MenuContainer.js +18 -11
  85. package/Menu/MenuItem.d.ts +24 -7
  86. package/Menu/MenuItem.js +13 -6
  87. package/Menu/MenuList.d.ts +4 -2
  88. package/Menu/MenuList.js +26 -6
  89. package/Menu/VirtualizedItem.d.ts +22 -0
  90. package/Menu/VirtualizedItem.js +69 -0
  91. package/Menu/VirtualizedList.d.ts +18 -0
  92. package/Menu/VirtualizedList.js +28 -0
  93. package/Menu/VirtualizedListComponent.d.ts +20 -0
  94. package/Menu/VirtualizedListComponent.js +305 -0
  95. package/Menu/index.d.ts +3 -1
  96. package/Menu/index.js +4 -7
  97. package/Modal/BaseModal/RenderModal.d.ts +3 -3
  98. package/Modal/BaseModal/index.d.ts +3 -3
  99. package/Modal/ConfirmBox/index.d.ts +5 -5
  100. package/Modal/Drawer/index.d.ts +5 -5
  101. package/Modal/MessageBox/index.d.ts +5 -5
  102. package/Popper/Popper.d.ts +148 -0
  103. package/Popper/Popper.js +113 -0
  104. package/Popper/PopperContainer.d.ts +2 -0
  105. package/Popper/PopperContainer.js +3 -6
  106. package/Popper/index.d.ts +5 -22
  107. package/Popper/index.js +18 -264
  108. package/Popper/usePopprer.d.ts +110 -0
  109. package/Popper/usePopprer.js +505 -0
  110. package/Selectbox/SelectboxButton.d.ts +5 -0
  111. package/Selectbox/SelectboxButton.js +48 -8
  112. package/Selectbox/SelectboxButtonWrapper.d.ts +2 -0
  113. package/Selectbox/SelectboxButtonWrapper.js +1 -17
  114. package/Selectbox/SelectboxMenu.d.ts +12 -0
  115. package/Selectbox/SelectboxMenu.js +50 -0
  116. package/Selectbox/index.d.ts +13 -13
  117. package/Selectbox/index.js +115 -97
  118. package/Surface/index.d.ts +5 -5
  119. package/Surface/index.js +1 -1
  120. package/Swiper/Swiper.d.ts +44 -0
  121. package/Swiper/Swiper.js +139 -0
  122. package/Swiper/SwiperContainer.d.ts +7 -0
  123. package/Swiper/SwiperContainer.js +14 -0
  124. package/Swiper/SwiperSlide.d.ts +7 -0
  125. package/Swiper/SwiperSlide.js +55 -0
  126. package/Swiper/SwiperTrack.d.ts +14 -0
  127. package/Swiper/SwiperTrack.js +58 -0
  128. package/Swiper/SwiperWrapper.d.ts +14 -0
  129. package/Swiper/SwiperWrapper.js +60 -0
  130. package/Swiper/index.d.ts +7 -0
  131. package/Swiper/index.js +26 -0
  132. package/Switch/SwitchDot.js +1 -1
  133. package/Switch/SwitchTrack.js +1 -1
  134. package/Switch/index.d.ts +8 -8
  135. package/TextArea/index.d.ts +7 -7
  136. package/TextField/TextFieldContainer.d.ts +2 -2
  137. package/TextField/TextFieldContainer.js +5 -3
  138. package/TextField/TextFieldErrorText.d.ts +2 -2
  139. package/TextField/TextFieldErrorText.js +5 -4
  140. package/TextField/TextFieldIconWrapper.d.ts +3 -3
  141. package/TextField/TextFieldIconWrapper.js +5 -3
  142. package/TextField/TextFieldInput.d.ts +2 -2
  143. package/TextField/TextFieldInput.js +6 -4
  144. package/TextField/TextFieldInputWrapper.d.ts +2 -2
  145. package/TextField/TextFieldInputWrapper.js +5 -3
  146. package/TextField/TextFieldLabel.d.ts +2 -2
  147. package/TextField/TextFieldLabel.js +5 -3
  148. package/TextField/TextFieldLabelAsterisk.d.ts +2 -2
  149. package/TextField/TextFieldLabelAsterisk.js +5 -3
  150. package/TextField/index.d.ts +15 -8
  151. package/TextField/index.js +49 -22
  152. package/ThemeProvider/createTheme.js +2 -2
  153. package/package.json +1 -1
  154. package/Calendar/reducer.d.ts +0 -14
  155. package/Calendar/reducer.js +0 -26
  156. /package/Calendar/{IconChevronRight.d.ts → CalendarIconNext.d.ts} +0 -0
  157. /package/Calendar/{IconChevronRight.js → CalendarIconNext.js} +0 -0
package/Calendar/index.js CHANGED
@@ -10,6 +10,18 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
12
  }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
13
25
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
27
  };
@@ -17,278 +29,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
30
  };
19
31
  Object.defineProperty(exports, "__esModule", { value: true });
20
- const react_1 = __importDefault(require("react"));
21
- const CalendarBody_1 = __importDefault(require("./CalendarBody"));
22
- const CalendarCell_1 = __importDefault(require("./CalendarCell"));
23
- const CalendarEmptyCell_1 = __importDefault(require("./CalendarEmptyCell"));
24
- const CalendarPaper_1 = __importDefault(require("./CalendarPaper"));
25
- const CalendarHeader_1 = __importDefault(require("./CalendarHeader"));
26
- const CalendarWeekRow_1 = __importDefault(require("./CalendarWeekRow"));
27
- const CalendarDateContainer_1 = __importDefault(require("./CalendarDateContainer"));
28
- const CalendarToolbar_1 = __importDefault(require("./CalendarToolbar"));
29
- const CalendarYearsSelector_1 = __importDefault(require("./CalendarYearsSelector"));
30
- const CalendarMonthsSelector_1 = __importDefault(require("./CalendarMonthsSelector"));
31
- const CalendarMonthCell_1 = __importDefault(require("./CalendarMonthCell"));
32
- const CalendarYearCell_1 = __importDefault(require("./CalendarYearCell"));
33
- const CalendarDayBadge_1 = __importDefault(require("./CalendarDayBadge"));
34
- const CalendarFooter_1 = __importDefault(require("./CalendarFooter"));
35
- const CalendarControlButton_1 = __importDefault(require("./CalendarControlButton"));
36
- const CalendarHeading_1 = __importDefault(require("./CalendarHeading"));
37
- const CalendarSubheading_1 = __importDefault(require("./CalendarSubheading"));
38
- const CalendarIconPrev_1 = __importDefault(require("./CalendarIconPrev"));
39
- const IconChevronRight_1 = __importDefault(require("./IconChevronRight"));
40
- const CalendarWeekDaysBar_1 = __importDefault(require("./CalendarWeekDaysBar"));
41
- const use_calendar_1 = require("./use-calendar");
42
- const reducer_1 = require("./reducer");
43
- __exportStar(require("./use-calendar"), exports);
44
- __exportStar(require("./CalendarWeekDaysBar"), exports);
45
- const Calendar = (props) => {
46
- const { minDate = new Date(new Date().getFullYear() - 100, 0, 1, 0, 0, 0), maxDate = new Date(new Date().getFullYear() + 100, 0, 1, 0, 0, 0), weekStartDay = 'monday', locale = 'ru-RU', displayLeadingZero = false, onChange, badges = [], value, defaultValue, markToday, weekDayLabelFormat = 'short', accentColor = 'primary', prevMonthButtonTooltip, nextMonthButtonTooltip, changeMonthButtonTooltip, changeYearButtonTooltip, initialView = (0, reducer_1.createDefaultState)(false).calendarCurrentView, resetButtonLabel, toodayButtonLabel, heading, subheading, footer, overrides, range = false, } = props;
47
- if (typeof value !== 'undefined' && typeof onChange === 'undefined') {
48
- throw new Error('You provided a `value` prop to a form field without an `onChange` handler. This will render a read-only field. If the field should be mutable use `defaultValue`. Otherwise, set either `onChange`.');
49
- }
50
- const overridesMap = react_1.default.useMemo(() => ({
51
- Body: (overrides === null || overrides === void 0 ? void 0 : overrides.Body) || CalendarBody_1.default,
52
- Cell: (overrides === null || overrides === void 0 ? void 0 : overrides.Cell) || CalendarCell_1.default,
53
- EmptyCell: (overrides === null || overrides === void 0 ? void 0 : overrides.EmptyCell) || CalendarEmptyCell_1.default,
54
- Paper: (overrides === null || overrides === void 0 ? void 0 : overrides.Paper) || CalendarPaper_1.default,
55
- Header: (overrides === null || overrides === void 0 ? void 0 : overrides.Header) || CalendarHeader_1.default,
56
- WeekRow: (overrides === null || overrides === void 0 ? void 0 : overrides.WeekRow) || CalendarWeekRow_1.default,
57
- DateContainer: (overrides === null || overrides === void 0 ? void 0 : overrides.DateContainer) || CalendarDateContainer_1.default,
58
- Toolbar: (overrides === null || overrides === void 0 ? void 0 : overrides.Toolbar) || CalendarToolbar_1.default,
59
- YearsSelector: (overrides === null || overrides === void 0 ? void 0 : overrides.YearsSelector) || CalendarYearsSelector_1.default,
60
- MonthsSelector: (overrides === null || overrides === void 0 ? void 0 : overrides.MonthsSelector) || CalendarMonthsSelector_1.default,
61
- MonthCell: (overrides === null || overrides === void 0 ? void 0 : overrides.MonthCell) || CalendarMonthCell_1.default,
62
- YearCell: (overrides === null || overrides === void 0 ? void 0 : overrides.YearCell) || CalendarYearCell_1.default,
63
- DayBadge: (overrides === null || overrides === void 0 ? void 0 : overrides.DayBadge) || CalendarDayBadge_1.default,
64
- Footer: (overrides === null || overrides === void 0 ? void 0 : overrides.Footer) || CalendarFooter_1.default,
65
- ControlButton: (overrides === null || overrides === void 0 ? void 0 : overrides.ControlButton) || CalendarControlButton_1.default,
66
- Heading: (overrides === null || overrides === void 0 ? void 0 : overrides.Heading) || CalendarHeading_1.default,
67
- Subheading: (overrides === null || overrides === void 0 ? void 0 : overrides.Subheading) || CalendarSubheading_1.default,
68
- IconPrev: (overrides === null || overrides === void 0 ? void 0 : overrides.IconPrev) || CalendarIconPrev_1.default,
69
- IconNext: (overrides === null || overrides === void 0 ? void 0 : overrides.IconNext) || IconChevronRight_1.default,
70
- WeekDaysBar: (overrides === null || overrides === void 0 ? void 0 : overrides.WeekDaysBar) || CalendarWeekDaysBar_1.default,
71
- }), [overrides]);
72
- const realValue = react_1.default.useMemo(() => typeof value !== 'undefined'
73
- ? value
74
- : typeof defaultValue !== 'undefined'
75
- ? defaultValue
76
- : new Date(), [value, defaultValue]);
77
- const initialProps = react_1.default.useRef({
78
- value: realValue,
79
- badges,
80
- initialView,
81
- });
82
- const initialState = Object.assign(Object.assign({}, (0, reducer_1.createDefaultState)(range)), { calendarValue: realValue, calendarDate: Array.isArray(realValue) ? realValue[0] : realValue, calendarCurrentView: initialView });
83
- const [state, dispatch] = react_1.default.useReducer(reducer_1.reducer, initialState);
84
- const { isSameDay, getWeeks, getDayLabel, getMonthLabel, getYearLabel, getYearsRange, getMonthsRange, } = (0, use_calendar_1.useCalendar)({
85
- minDate,
86
- maxDate,
87
- weekStartDay,
88
- locale,
89
- displayLeadingZero,
90
- });
91
- const { calendarCurrentView, calendarViewVariants, calendarValue, calendarDate } = state;
92
- /**
93
- * Prev and next month buttons
94
- */
95
- const handleChangeMonthClick = react_1.default.useCallback((type) => () => {
96
- const newDate = type === 'prev'
97
- ? new Date(calendarDate.getFullYear(), calendarDate.getMonth() - 1, 1)
98
- : new Date(calendarDate.getFullYear(), calendarDate.getMonth() + 1, 1);
99
- dispatch({ type: 'setPartial', payload: { calendarDate: newDate } });
100
- }, [calendarDate]);
101
- /**
102
- * Date props was changed
103
- */
104
- react_1.default.useEffect(() => {
105
- if (typeof value !== 'undefined') {
106
- dispatch({
107
- type: 'setPartial',
108
- payload: {
109
- calendarValue: value,
110
- // calendarDate: Array.isArray(value) ? value[0] : value,
111
- },
112
- });
113
- }
114
- }, [value, calendarValue, isSameDay, dispatch]);
115
- /**
116
- * Handle click on Day button
117
- */
118
- const handleCellDateClick = react_1.default.useCallback((selectedDate) => () => {
119
- if (typeof onChange === 'function') {
120
- if (range) {
121
- const [fromDate, toDate] = calendarValue;
122
- dispatch({
123
- type: 'setPartial',
124
- payload: { calendarDate: selectedDate },
125
- });
126
- if (selectedDate.getTime() >= toDate.getTime()) {
127
- onChange([fromDate, selectedDate]);
128
- return;
129
- }
130
- if (selectedDate.getTime() < fromDate.getTime()) {
131
- onChange([selectedDate, toDate]);
132
- return;
133
- }
134
- if (selectedDate.getTime() > fromDate.getTime() &&
135
- selectedDate.getTime() < toDate.getTime()) {
136
- const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
137
- const daysBetweenFromDate = Math.round(Math.abs((fromDate.getTime() - selectedDate.getTime()) / oneDay));
138
- const daysBetweenToDate = Math.round(Math.abs((toDate.getTime() - selectedDate.getTime()) / oneDay));
139
- if (daysBetweenToDate <= daysBetweenFromDate) {
140
- onChange([fromDate, selectedDate]);
141
- return;
142
- }
143
- if (daysBetweenToDate > daysBetweenFromDate) {
144
- onChange([selectedDate, toDate]);
145
- return;
146
- }
147
- }
148
- throw new Error('Oooops. I don`t know whats is it');
149
- }
150
- else {
151
- onChange(selectedDate);
152
- }
153
- }
154
- if (!calendarValue) {
155
- dispatch({
156
- type: 'setPartial',
157
- payload: {
158
- calendarValue: selectedDate,
159
- },
160
- });
161
- }
162
- }, [onChange, calendarValue, range]);
163
- /**
164
- * Handle of click on year item
165
- */
166
- const handleYearSelected = react_1.default.useCallback((selectedYear) => () => {
167
- const newDate = new Date(calendarDate);
168
- newDate.setFullYear(selectedYear);
169
- newDate.setMonth(calendarDate.getMonth());
170
- newDate.setDate(1);
171
- newDate.setHours(0);
172
- newDate.setMinutes(0);
173
- newDate.setMilliseconds(0);
174
- if (calendarDate.getFullYear() !== newDate.getFullYear()) {
175
- dispatch({
176
- type: 'setPartial',
177
- payload: {
178
- calendarDate: newDate,
179
- calendarCurrentView: 'days',
180
- },
181
- });
182
- }
183
- }, [calendarDate]);
184
- /**
185
- * Handle of click on month item
186
- */
187
- const handleMonthSelected = react_1.default.useCallback((monthIndex) => () => {
188
- const newDate = new Date(calendarDate);
189
- newDate.setMonth(monthIndex);
190
- newDate.setDate(1);
191
- newDate.setHours(0);
192
- newDate.setMinutes(0);
193
- newDate.setMilliseconds(0);
194
- if (calendarDate.getMonth() !== newDate.getMonth()) {
195
- dispatch({
196
- type: 'setPartial',
197
- payload: {
198
- calendarDate: newDate,
199
- calendarCurrentView: 'days',
200
- },
201
- });
202
- }
203
- }, [calendarDate]);
204
- /**
205
- * Manual view changing
206
- */
207
- const handleChangeView = react_1.default.useCallback((selectedView) => () => {
208
- dispatch({
209
- type: 'setPartial',
210
- payload: {
211
- calendarCurrentView: selectedView,
212
- },
213
- });
214
- }, []);
215
- /**
216
- * Handle click on «Reset» button
217
- */
218
- const handleReset = react_1.default.useCallback(() => {
219
- dispatch({
220
- type: 'setPartial',
221
- payload: {
222
- calendarCurrentView: initialProps.current.initialView,
223
- calendarDate: initialProps.current.value,
224
- calendarValue: initialProps.current.value,
225
- },
226
- });
227
- if (typeof onChange === 'function') {
228
- onChange(initialProps.current.value);
229
- }
230
- }, [onChange]);
231
- /**
232
- * Handle click on «Today» button
233
- */
234
- const handleToday = react_1.default.useCallback(() => {
235
- const today = new Date();
236
- today.setHours(0);
237
- today.setMinutes(0);
238
- today.setSeconds(0);
239
- today.setMilliseconds(0);
240
- dispatch({
241
- type: 'setPartial',
242
- payload: {
243
- calendarDate: today,
244
- },
245
- });
246
- }, []);
247
- return (react_1.default.createElement(overridesMap.Paper, null,
248
- react_1.default.createElement(overridesMap.Header, null,
249
- typeof heading !== 'undefined' && react_1.default.createElement(overridesMap.Heading, null, heading),
250
- typeof subheading !== 'undefined' && (react_1.default.createElement(overridesMap.Subheading, null, subheading)),
251
- react_1.default.createElement(overridesMap.Toolbar, null,
252
- react_1.default.createElement(overridesMap.ControlButton, { iconOnly: true, onClick: handleChangeMonthClick('prev'), title: prevMonthButtonTooltip, disabled: calendarCurrentView !== 'days' },
253
- react_1.default.createElement(overridesMap.IconPrev, null)),
254
- react_1.default.createElement(overridesMap.ControlButton, { title: changeMonthButtonTooltip, isActive: calendarCurrentView === 'months', disabled: !calendarViewVariants.includes('months'), onClick: handleChangeView(calendarCurrentView === 'months' ? 'days' : 'months') }, getMonthLabel(calendarDate)),
255
- react_1.default.createElement(overridesMap.ControlButton, { isActive: calendarCurrentView === 'years', disabled: !calendarViewVariants.includes('years'), title: changeYearButtonTooltip, onClick: handleChangeView(calendarCurrentView === 'years' ? 'days' : 'years') }, getYearLabel(calendarDate)),
256
- react_1.default.createElement(overridesMap.ControlButton, { iconOnly: true, onClick: handleChangeMonthClick('next'), title: nextMonthButtonTooltip, disabled: calendarCurrentView !== 'days' },
257
- react_1.default.createElement(overridesMap.IconNext, null)))),
258
- react_1.default.createElement(overridesMap.WeekDaysBar, { locale: locale, week: getWeeks(calendarDate)[0], format: weekDayLabelFormat || 'short' }),
259
- react_1.default.createElement(overridesMap.Body, null,
260
- calendarCurrentView === 'years' && (react_1.default.createElement(overridesMap.YearsSelector, null, getYearsRange(minDate, maxDate).map(year => {
261
- const a = Array.isArray(calendarValue) ? calendarValue : [calendarValue];
262
- const isSelected = a.find(d => d.getFullYear() === year) !== undefined;
263
- return (react_1.default.createElement(overridesMap.YearCell, { key: year, accentColor: accentColor, isSelected: isSelected, onClick: handleYearSelected(year) }, getYearLabel(new Date(year, calendarDate.getMonth(), calendarDate.getDate(), 0, 0, 0, 0))));
264
- }))),
265
- calendarCurrentView === 'months' && (react_1.default.createElement(overridesMap.MonthsSelector, null, getMonthsRange(minDate, maxDate).map(monthIndex => {
266
- const a = Array.isArray(calendarValue) ? calendarValue : [calendarValue];
267
- const isSelected = a.find(d => d.getMonth() === monthIndex) !== undefined;
268
- return (react_1.default.createElement(overridesMap.MonthCell, { key: monthIndex, accentColor: accentColor, isSelected: isSelected, onClick: handleMonthSelected(monthIndex) }, getMonthLabel(new Date(calendarDate.getFullYear(), monthIndex, 1, 0, 0, 0, 0))));
269
- }))),
270
- calendarCurrentView === 'days' && (react_1.default.createElement(overridesMap.DateContainer, null, getWeeks(calendarDate).map(week => (react_1.default.createElement(overridesMap.WeekRow, { key: week.weekNumber.toString() }, week.days.map(day => {
271
- if (day.date.getMonth() === calendarDate.getMonth()) {
272
- const badge = badges.find(b => isSameDay(b.date, day.date));
273
- const a = Array.isArray(calendarValue)
274
- ? calendarValue
275
- : [calendarValue, calendarValue];
276
- const isSelected = isSameDay(a[0], day.date) || isSameDay(a[1], day.date);
277
- const fill = Array.isArray(calendarValue)
278
- ? day.date.getTime() > calendarValue[0].getTime() &&
279
- day.date.getTime() < calendarValue[1].getTime()
280
- : false;
281
- return (react_1.default.createElement(overridesMap.Cell, { key: day.date.getTime(), isToday: markToday && day.isToday, isDisabled: day.isDisabled, accentColor: accentColor, isSelected: isSelected, onClick: handleCellDateClick(day.date), fill: fill },
282
- getDayLabel(day.date),
283
- typeof badge !== 'undefined' && (react_1.default.createElement(overridesMap.DayBadge, { badgeContent: badge.badgeContent, isToday: day.isToday, accentColor: badge.accentColor }))));
284
- }
285
- return react_1.default.createElement(overridesMap.EmptyCell, { key: day.date.getTime() });
286
- }))))))),
287
- (typeof resetButtonLabel !== 'undefined' ||
288
- typeof toodayButtonLabel !== 'undefined' ||
289
- typeof footer !== 'undefined') && (react_1.default.createElement(overridesMap.Footer, null,
290
- typeof footer !== 'undefined' && react_1.default.createElement(react_1.default.Fragment, null, footer),
291
- typeof toodayButtonLabel !== 'undefined' && (react_1.default.createElement(overridesMap.ControlButton, { onClick: handleToday }, toodayButtonLabel)),
292
- typeof resetButtonLabel !== 'undefined' && (react_1.default.createElement(overridesMap.ControlButton, { onClick: handleReset }, resetButtonLabel))))));
293
- };
32
+ const React = __importStar(require("react"));
33
+ const CalendarComponent_1 = require("./CalendarComponent");
34
+ const ErrorBoundary_1 = __importDefault(require("../ErrorBoundary"));
35
+ __exportStar(require("./CalendarComponent"), exports);
36
+ const Calendar = React.forwardRef((props, ref) => (React.createElement(ErrorBoundary_1.default, null,
37
+ React.createElement(CalendarComponent_1.CalendarComponent, Object.assign({}, props, { ref: ref })))));
38
+ Calendar.displayName = 'Calendar';
294
39
  exports.default = Calendar;
@@ -1,4 +1,4 @@
1
- export type CalendarValue<Multiple> = Multiple extends undefined ? Date : [Date, Date];
1
+ export type CalendarValue<Range> = Range extends undefined ? Date | null : [Date, Date] | [Date | null] | null;
2
2
  export type WeekDayName = 'sunday' | 'monday' | 'tuesday' | 'wednesday' | 'thursday' | 'friday' | 'saturday';
3
3
  export type Day = {
4
4
  readonly date: Date;
@@ -6,65 +6,78 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.useCalendar = void 0;
7
7
  const react_1 = __importDefault(require("react"));
8
8
  const WHITESPACE = '\u{0020}';
9
+ const WEEK_IN_MS = 604800000; // 7 * 24 * 60 * 60 * 1000
10
+ // Константа для маппинга дней недели
11
+ const WEEK_DAYS_MAP = {
12
+ sunday: 0,
13
+ monday: 1,
14
+ tuesday: 2,
15
+ wednesday: 3,
16
+ thursday: 4,
17
+ friday: 5,
18
+ saturday: 6,
19
+ };
9
20
  const useCalendar = (props) => {
10
21
  const { minDate, maxDate, weekStartDay, displayLeadingZero, locale } = props;
22
+ // Мемоизируем timestamp граничных дат для оптимизации проверок isDisabled
23
+ const minTime = react_1.default.useMemo(() => minDate.getTime(), [minDate]);
24
+ const maxTime = react_1.default.useMemo(() => maxDate.getTime(), [maxDate]);
25
+ // Мемоизируем номер дня начала недели
26
+ const weekStartDayNumber = react_1.default.useMemo(() => WEEK_DAYS_MAP[weekStartDay], [weekStartDay]);
27
+ // Оптимизированная функция isSameDay
11
28
  const isSameDay = react_1.default.useCallback((a, b) => a.getFullYear() === b.getFullYear() &&
12
29
  a.getMonth() === b.getMonth() &&
13
30
  a.getDate() === b.getDate(), []);
14
- const isToday = react_1.default.useCallback((dateValue) => isSameDay(dateValue, new Date()), [isSameDay]);
15
- const isDisabled = react_1.default.useCallback((dateValue) => {
16
- const min = minDate.getTime() || 0;
17
- const max = maxDate.getTime() || Number.MAX_VALUE;
18
- const current = dateValue.getTime();
19
- return current > max || current < min;
20
- }, [maxDate, minDate]);
21
- const calculateWeekNumber = react_1.default.useCallback((dt) => {
22
- const tdt = new Date(dt.valueOf());
23
- const dayn = (dt.getDay() + 6) % 7;
24
- tdt.setDate(tdt.getDate() - dayn + 3);
25
- const firstThursday = tdt.valueOf();
26
- tdt.setMonth(0, 1);
27
- if (tdt.getDay() !== 4) {
28
- tdt.setMonth(0, 1 + ((4 - tdt.getDay() + 7) % 7));
29
- }
30
- return 1 + Math.ceil((firstThursday - tdt.getTime()) / 604800000);
31
+ // Мемоизируем сегодняшнюю дату для isToday
32
+ const today = react_1.default.useMemo(() => {
33
+ const now = new Date();
34
+ return new Date(now.getFullYear(), now.getMonth(), now.getDate());
31
35
  }, []);
32
- const weekDaysMap = react_1.default.useMemo(() => ({
33
- sunday: 0,
34
- monday: 1,
35
- tuesday: 2,
36
- wednesday: 3,
37
- thursday: 4,
38
- friday: 5,
39
- saturday: 6,
40
- }), []);
36
+ const isToday = react_1.default.useCallback((dateValue) => isSameDay(dateValue, today), [isSameDay, today]);
37
+ const isDisabled = react_1.default.useCallback((dateValue) => {
38
+ const currentTime = dateValue.getTime();
39
+ return currentTime > maxTime || currentTime < minTime;
40
+ }, [maxTime, minTime]);
41
+ const calculateWeekNumber = react_1.default.useCallback((date) => {
42
+ // Используем UTC методы для избежания проблем с часовыми поясами
43
+ const year = date.getFullYear();
44
+ const month = date.getMonth();
45
+ const day = date.getDate();
46
+ // Создаем дату без времени
47
+ const d = new Date(Date.UTC(year, month, day));
48
+ // День недели (0-6)
49
+ const dayOfWeek = d.getUTCDay();
50
+ // Смещение от начала недели
51
+ const diff = (dayOfWeek - weekStartDayNumber + 7) % 7;
52
+ // Первый день недели
53
+ const weekStart = new Date(Date.UTC(year, month, day - diff));
54
+ // Первый день года
55
+ const yearStart = new Date(Date.UTC(year, 0, 1));
56
+ // Вычисляем номер недели
57
+ return Math.floor((weekStart.getTime() - yearStart.getTime()) / WEEK_IN_MS) + 1;
58
+ }, [weekStartDayNumber]);
41
59
  const getDayLabel = react_1.default.useCallback((day) => {
42
60
  const dateNum = day.getDate();
43
- if (!displayLeadingZero) {
44
- return dateNum.toString();
45
- }
46
- const numStr = `0${dateNum}`;
47
- return numStr.substring(numStr.length - 2);
61
+ return displayLeadingZero ? dateNum.toString().padStart(2, '0') : dateNum.toString();
48
62
  }, [displayLeadingZero]);
63
+ // Мемоизируем Intl форматеры для производительности
64
+ const monthFormatter = react_1.default.useMemo(() => (typeof Intl !== 'undefined' ? new Intl.DateTimeFormat(locale, { month: 'long' }) : null), [locale]);
65
+ const yearFormatter = react_1.default.useMemo(() => typeof Intl !== 'undefined' ? new Intl.DateTimeFormat(locale, { year: 'numeric' }) : null, [locale]);
49
66
  const getMonthLabel = react_1.default.useCallback((dateValue) => {
50
- const title = typeof Intl !== 'undefined'
51
- ? new Intl.DateTimeFormat(locale, {
52
- month: 'long',
53
- }).format(dateValue)
54
- : WHITESPACE;
67
+ if (!monthFormatter)
68
+ return WHITESPACE;
69
+ const title = monthFormatter.format(dateValue);
55
70
  return title.charAt(0).toUpperCase() + title.slice(1);
56
- }, [locale]);
57
- const getYearLabel = react_1.default.useCallback((dateValue) => typeof Intl !== 'undefined'
58
- ? new Intl.DateTimeFormat(locale, {
59
- year: 'numeric',
60
- }).format(dateValue)
61
- : WHITESPACE, [locale]);
71
+ }, [monthFormatter]);
72
+ const getYearLabel = react_1.default.useCallback((dateValue) => { var _a; return (_a = yearFormatter === null || yearFormatter === void 0 ? void 0 : yearFormatter.format(dateValue)) !== null && _a !== void 0 ? _a : WHITESPACE; }, [yearFormatter]);
62
73
  const getYearsRange = react_1.default.useCallback((minDate, maxDate) => {
63
- const y = [];
64
- for (let year = minDate.getFullYear(); year >= minDate.getFullYear() && year <= maxDate.getFullYear(); year++) {
65
- y.push(year);
74
+ const years = [];
75
+ const startYear = minDate.getFullYear();
76
+ const endYear = maxDate.getFullYear();
77
+ for (let year = startYear; year <= endYear; year++) {
78
+ years.push(year);
66
79
  }
67
- return y;
80
+ return years;
68
81
  }, []);
69
82
  const getMonthsRange = react_1.default.useCallback((minDate, maxDate) => {
70
83
  const m = [];
@@ -77,122 +90,56 @@ const useCalendar = (props) => {
77
90
  }
78
91
  return m;
79
92
  }, []);
93
+ const weeksCache = react_1.default.useRef(new Map());
80
94
  const getWeeks = react_1.default.useCallback((needleDate) => {
81
- const list = [];
82
- const startOfDate = new Date(needleDate.getFullYear(), needleDate.getMonth(), 1, 0, 0, 0, 0);
83
- const lastOfDate = new Date(needleDate.getFullYear(), needleDate.getMonth() + 1, 0, 0, 0, 0);
84
- const startDayNum = weekDaysMap[weekStartDay];
85
- const week = new Set();
86
- const d = new Date(needleDate);
87
- for (let dateNum = 1; dateNum < lastOfDate.getDate() + 1; dateNum++) {
88
- d.setDate(dateNum);
89
- // if is start of the week then set a new week
90
- if (d.getDay() === startDayNum) {
91
- const days = [...week].map(day => ({
92
- date: day,
93
- isToday: isToday(day),
94
- isDisabled: isDisabled(day),
95
- }));
96
- if (days.length) {
97
- list.push({
98
- weekNumber: calculateWeekNumber(days[0].date),
99
- days,
100
- });
101
- }
102
- week.clear();
103
- }
104
- week.add(new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0, 0));
105
- // if is last of iteration
106
- if (dateNum === lastOfDate.getDate()) {
107
- const days = [...week].map(day => ({
108
- date: day,
109
- isToday: isToday(day),
110
- isDisabled: isDisabled(day),
111
- }));
112
- if (days.length) {
113
- list.push({
114
- weekNumber: calculateWeekNumber(days[0].date),
115
- days,
116
- });
117
- }
118
- week.clear();
119
- }
120
- }
121
- // Fill the prev days
122
- if (list[0].days.length < 7) {
123
- const fillDays = 7 - list[0].days.length;
124
- const days = list[0].days;
125
- for (let fillIndex = 0; fillIndex < fillDays; fillIndex++) {
126
- const day = new Date(startOfDate.getFullYear(), startOfDate.getMonth(), -fillIndex, 0, 0, 0, 0);
127
- days.unshift({
128
- date: day,
129
- isDisabled: isDisabled(day),
130
- isToday: isToday(day),
131
- });
132
- }
133
- list[0] = {
134
- days,
135
- weekNumber: calculateWeekNumber(days[0].date),
136
- };
95
+ const year = needleDate.getFullYear();
96
+ const month = needleDate.getMonth();
97
+ const cacheKey = `${year}-${month}-${weekStartDay}-${minTime}-${maxTime}`;
98
+ const cached = weeksCache.current.get(cacheKey);
99
+ if (cached) {
100
+ return cached;
137
101
  }
138
- // fill the next days
139
- if (list[list.length - 1].days.length < 7) {
140
- const fillDays = 7 - list[list.length - 1].days.length;
141
- const days = list[list.length - 1].days;
142
- for (let fillIndex = 0; fillIndex < fillDays; fillIndex++) {
143
- const day = new Date(lastOfDate.getFullYear(), lastOfDate.getMonth() + 1, fillIndex + 1, 0, 0, 0, 0);
144
- days.push({
145
- date: day,
146
- isDisabled: isDisabled(day),
147
- isToday: isToday(day),
148
- });
102
+ // Первый и последний день месяца
103
+ const firstDay = new Date(year, month, 1);
104
+ const lastDay = new Date(year, month + 1, 0);
105
+ // Вычисляем начало календарной сетки
106
+ const startOffset = (firstDay.getDay() - weekStartDayNumber + 7) % 7;
107
+ const startDate = new Date(year, month, 1 - startOffset);
108
+ // Вычисляем конец календарной сетки
109
+ const endOffset = (weekStartDayNumber + 6 - lastDay.getDay() + 7) % 7;
110
+ const endDate = new Date(year, month, lastDay.getDate() + endOffset);
111
+ const weeks = [];
112
+ const currentDate = new Date(startDate);
113
+ // Предаллоцируем массив для дней недели
114
+ const weekDays = new Array(7);
115
+ while (currentDate <= endDate) {
116
+ // Заполняем дни недели
117
+ for (let i = 0; i < 7; i++) {
118
+ const date = new Date(currentDate);
119
+ weekDays[i] = {
120
+ date,
121
+ isToday: isToday(date),
122
+ isDisabled: isDisabled(date),
123
+ };
124
+ currentDate.setDate(currentDate.getDate() + 1);
149
125
  }
150
- list[list.length - 1] = {
151
- days,
152
- weekNumber: calculateWeekNumber(days[0].date),
153
- };
154
- }
155
- // if weeks length is 4 only
156
- // then prepend week
157
- if (list.length === 4) {
158
- const fillDays = 7;
159
- const days = [];
160
- const firstWeek = list[0];
161
- const firstDate = firstWeek.days[0].date;
162
- for (let fillIndex = 0; fillIndex < fillDays; fillIndex++) {
163
- const day = new Date(firstDate.getFullYear(), firstDate.getMonth(), firstDate.getDate() - fillIndex, 0, 0, 0, 0);
164
- days.unshift({
165
- date: day,
166
- isDisabled: isDisabled(day),
167
- isToday: isToday(day),
168
- });
169
- }
170
- list.unshift({
171
- days,
172
- weekNumber: calculateWeekNumber(days[0].date),
126
+ // Создаем копию массива дней для недели
127
+ weeks.push({
128
+ weekNumber: calculateWeekNumber(weekDays[0].date),
129
+ days: [...weekDays],
173
130
  });
174
131
  }
175
- // if weeks length is 5 only
176
- // then append week
177
- if (list.length === 5) {
178
- const lastWeek = list[list.length - 1];
179
- const lastDate = lastWeek.days[lastWeek.days.length - 1].date;
180
- const days = [];
181
- for (let fillIndex = 0; fillIndex < 7; fillIndex++) {
182
- const day = new Date(lastDate.getFullYear(), lastDate.getMonth(), lastDate.getDate() + fillIndex + 1, 0, 0, 0, 0);
183
- days.push({
184
- date: day,
185
- isDisabled: isDisabled(day),
186
- isToday: isToday(day),
187
- });
132
+ // Сохраняем в кэш
133
+ weeksCache.current.set(cacheKey, weeks);
134
+ // Очищаем старые записи кэша (если больше 10)
135
+ if (weeksCache.current.size > 10) {
136
+ const keys = Array.from(weeksCache.current.keys());
137
+ for (let i = 0; i < keys.length - 10; i++) {
138
+ weeksCache.current.delete(keys[i]);
188
139
  }
189
- list.push({
190
- days,
191
- weekNumber: calculateWeekNumber(days[0].date),
192
- });
193
140
  }
194
- return list;
195
- }, [weekDaysMap, weekStartDay, isToday, isDisabled, calculateWeekNumber]);
141
+ return weeks;
142
+ }, [weekStartDay, minTime, maxTime, weekStartDayNumber, calculateWeekNumber, isToday, isDisabled]);
196
143
  return {
197
144
  isSameDay,
198
145
  isToday,