@nutui/nutui-react-taro 1.4.7 → 1.4.8

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 (98) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/dist/esm/Badge.js +2 -2
  3. package/dist/esm/Barrage.js +2 -2
  4. package/dist/esm/Calendar.js +3 -4
  5. package/dist/esm/CalendarItem.js +2 -3
  6. package/dist/esm/Cascader.js +4 -4
  7. package/dist/esm/Checkbox.js +2 -2
  8. package/dist/esm/CheckboxGroup.js +2 -2
  9. package/dist/esm/Col.js +3 -2
  10. package/dist/esm/Dialog.js +3 -2
  11. package/dist/esm/Ellipsis.js +2 -2
  12. package/dist/esm/InputNumber.js +2 -2
  13. package/dist/esm/Popover.js +2 -2
  14. package/dist/esm/Row.js +3 -2
  15. package/dist/esm/ShortPassword.js +2 -2
  16. package/dist/esm/Swipe.js +3 -2
  17. package/dist/esm/TabPane.js +2 -2
  18. package/dist/esm/Tabbar.js +2 -2
  19. package/dist/esm/Tabs.js +2 -2
  20. package/dist/esm/TextArea.js +2 -2
  21. package/dist/esm/Uploader.js +2 -2
  22. package/dist/esm/{badge.taro-11e2ec95.js → badge.taro-116b2521.js} +1 -0
  23. package/dist/esm/barrage.taro-5dbab093.js +94 -0
  24. package/dist/esm/calendar.taro-c95e6998.js +61 -0
  25. package/dist/esm/calendaritem.taro-86412398.js +761 -0
  26. package/dist/esm/{cascader.taro-e6610dd1.js → cascader.taro-e0fb7e63.js} +16 -22
  27. package/dist/esm/{checkbox.taro-04da7151.js → checkbox.taro-b76b1c82.js} +9 -6
  28. package/dist/esm/{col.taro-b61c7cba.js → col.taro-9e4c5cc0.js} +2 -1
  29. package/dist/esm/{dialog.taro-54df2e3f.js → dialog.taro-7608bd26.js} +7 -12
  30. package/dist/esm/{ellipsis.taro-aa39faf7.js → ellipsis.taro-5aa23940.js} +4 -3
  31. package/dist/esm/{inputnumber.taro-e909d932.js → inputnumber.taro-94c75663.js} +11 -21
  32. package/dist/esm/nutui-react.es.js +19 -19
  33. package/dist/esm/{popover.taro-fc7b9a73.js → popover.taro-f144cd02.js} +9 -7
  34. package/dist/esm/{row.taro-37a895de.js → row.taro-4e697aa2.js} +2 -1
  35. package/dist/esm/{shortpassword.taro-02ea4499.js → shortpassword.taro-53b7ee7b.js} +3 -2
  36. package/dist/esm/{swipe.taro-1eb95b21.js → swipe.taro-6532405d.js} +16 -24
  37. package/dist/esm/{tabbar.taro-08e48c43.js → tabbar.taro-17d898d9.js} +12 -7
  38. package/dist/esm/{tabpane.taro-91cd6cf4.js → tabpane.taro-9512e308.js} +3 -3
  39. package/dist/esm/{tabs.taro-5030ce68.js → tabs.taro-4629d66c.js} +5 -2
  40. package/dist/esm/{textarea.taro-42600f8c.js → textarea.taro-47addd05.js} +5 -1
  41. package/dist/esm/types/src/packages/calendar/calendar.taro.d.ts +22 -2
  42. package/dist/esm/types/src/packages/calendaritem/calendaritem.taro.d.ts +21 -3
  43. package/dist/esm/types/src/packages/cascader/cascader.d.ts +1 -0
  44. package/dist/esm/types/src/packages/cascader/cascader.taro.d.ts +1 -0
  45. package/dist/esm/types/src/packages/cascader/cascaderItem.d.ts +1 -0
  46. package/dist/esm/types/src/packages/cascader/cascaderItem.taro.d.ts +1 -0
  47. package/dist/esm/types/src/packages/checkbox/demo.d.ts +0 -1
  48. package/dist/esm/types/src/packages/checkboxgroup/checkboxgroup.d.ts +5 -0
  49. package/dist/esm/types/src/packages/checkboxgroup/checkboxgroup.taro.d.ts +5 -0
  50. package/dist/esm/types/src/packages/dialog/DialogWrap.d.ts +1 -1
  51. package/dist/esm/types/src/packages/dialog/DialogWrapper.taro.d.ts +11 -0
  52. package/dist/esm/types/src/packages/dialog/dialog.taro.d.ts +3 -2
  53. package/dist/esm/types/src/packages/dialog/index.taro.d.ts +2 -2
  54. package/dist/esm/types/src/packages/form/form.d.ts +3 -0
  55. package/dist/esm/types/src/packages/formitem/formitem.d.ts +2 -1
  56. package/dist/esm/types/src/packages/formitem/types.d.ts +1 -1
  57. package/dist/esm/types/src/packages/popover/popover.taro.d.ts +1 -1
  58. package/dist/esm/types/src/packages/shortpassword/shortpassword.d.ts +1 -0
  59. package/dist/esm/types/src/packages/shortpassword/shortpassword.taro.d.ts +1 -0
  60. package/dist/esm/types/src/packages/switch/switch.d.ts +2 -1
  61. package/dist/esm/types/src/packages/tabbar/tabbar.d.ts +1 -1
  62. package/dist/esm/types/src/packages/tabbar/tabbar.taro.d.ts +1 -1
  63. package/dist/esm/types/src/packages/tabbar/use-props-value.d.ts +7 -0
  64. package/dist/esm/types/src/packages/tabpane/tabpane.taro.d.ts +0 -1
  65. package/dist/esm/types/src/packages/tabs/tabs.d.ts +1 -0
  66. package/dist/esm/types/src/packages/tabs/tabs.taro.d.ts +1 -0
  67. package/dist/esm/types/src/packages/uploader/uploader.taro.d.ts +1 -0
  68. package/dist/esm/{uploader.taro-b7b770e6.js → uploader.taro-c830b573.js} +3 -2
  69. package/dist/locales/base.js +1 -1
  70. package/dist/locales/en-US.js +1 -1
  71. package/dist/locales/id-ID.js +1 -1
  72. package/dist/locales/zh-CN.js +1 -1
  73. package/dist/locales/zh-TW.js +1 -1
  74. package/dist/locales/zh-UG.js +1 -1
  75. package/dist/nutui.react.es.js +690 -412
  76. package/dist/nutui.react.umd.js +689 -411
  77. package/dist/packages/badge/badge.scss +11 -5
  78. package/dist/packages/barrage/barrage.scss +3 -3
  79. package/dist/packages/button/button.scss +1 -0
  80. package/dist/packages/cascader/cascader.scss +19 -5
  81. package/dist/packages/checkboxgroup/checkboxgroup.scss +33 -0
  82. package/dist/packages/collapseitem/collapseitem.scss +41 -17
  83. package/dist/packages/form/form.scss +3 -0
  84. package/dist/packages/inputnumber/inputnumber.scss +18 -1
  85. package/dist/packages/popover/popover.scss +71 -46
  86. package/dist/packages/radiogroup/radiogroup.scss +9 -8
  87. package/dist/packages/step/step.scss +135 -98
  88. package/dist/packages/switch/switch.scss +1 -1
  89. package/dist/packages/tabs/tabs.scss +24 -2
  90. package/dist/packages/textarea/textarea.scss +7 -1
  91. package/dist/style.css +1 -1
  92. package/dist/style.es.js +1 -1
  93. package/dist/styles/variables.scss +155 -33
  94. package/dist/types/index.d.ts +57 -33
  95. package/package.json +1 -1
  96. package/dist/esm/barrage.taro-e4fe81ae.js +0 -73
  97. package/dist/esm/calendar.taro-02479e8b.js +0 -38
  98. package/dist/esm/calendaritem.taro-3cfd4186.js +0 -571
@@ -0,0 +1,761 @@
1
+ import React__default, { useState, useRef, useEffect } from 'react';
2
+ import classNames from 'classnames';
3
+ import { c as cn } from './bem-893ad28d.js';
4
+ import { u as useConfig } from './configprovider.taro-26882dd2.js';
5
+
6
+ const Utils = {
7
+ /**
8
+ * 是否为闫年
9
+ * @return {Boolse} true|false
10
+ */
11
+ isLeapYear(y) {
12
+ return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
13
+ },
14
+ /**
15
+ * 返回星期数
16
+ * @return {String}
17
+ */
18
+ getWhatDay(year, month, day) {
19
+ const date = new Date(`${year}/${month}/${day}`);
20
+ const index = date.getDay();
21
+ const dayNames = [
22
+ '星期日',
23
+ '星期一',
24
+ '星期二',
25
+ '星期三',
26
+ '星期四',
27
+ '星期五',
28
+ '星期六',
29
+ ];
30
+ return dayNames[index];
31
+ },
32
+ /**
33
+ * 返回星期数
34
+ * @return {Number}
35
+ */
36
+ getMonthPreDay(year, month) {
37
+ const date = new Date(`${year}/${month}/01`);
38
+ let day = date.getDay();
39
+ if (day == 0) {
40
+ day = 7;
41
+ }
42
+ return day;
43
+ },
44
+ /**
45
+ * 返回月份天数
46
+ * @return {Number}
47
+ */
48
+ getMonthDays(year, month) {
49
+ if (/^0/.test(month)) {
50
+ month = month.split('')[1];
51
+ }
52
+ return [
53
+ 0,
54
+ 31,
55
+ this.isLeapYear(Number(year)) ? 29 : 28,
56
+ 31,
57
+ 30,
58
+ 31,
59
+ 30,
60
+ 31,
61
+ 31,
62
+ 30,
63
+ 31,
64
+ 30,
65
+ 31,
66
+ ][month];
67
+ },
68
+ /**
69
+ * 补齐数字位数
70
+ * @return {string}
71
+ */
72
+ getNumTwoBit(n) {
73
+ n = Number(n);
74
+ return (n > 9 ? '' : '0') + n;
75
+ },
76
+ /**
77
+ * 日期对象转成字符串
78
+ * @return {string}
79
+ */
80
+ date2Str(date, split) {
81
+ split = split || '-';
82
+ const y = date.getFullYear();
83
+ const m = this.getNumTwoBit(date.getMonth() + 1);
84
+ const d = this.getNumTwoBit(date.getDate());
85
+ return [y, m, d].join(split);
86
+ },
87
+ /**
88
+ * 返回日期格式字符串
89
+ * @param {Number} 0返回今天的日期、1返回明天的日期,2返回后天得日期,依次类推
90
+ * @return {string} '2014-12-31'
91
+ */
92
+ getDay(i) {
93
+ i = i || 0;
94
+ let date = new Date();
95
+ const diff = i * (1000 * 60 * 60 * 24);
96
+ date = new Date(date.getTime() + diff);
97
+ return this.date2Str(date);
98
+ },
99
+ /**
100
+ * 时间比较
101
+ * @return {Boolean}
102
+ */
103
+ compareDate(date1, date2) {
104
+ const startTime = new Date(date1.replace('-', '/').replace('-', '/'));
105
+ const endTime = new Date(date2.replace('-', '/').replace('-', '/'));
106
+ if (startTime >= endTime) {
107
+ return false;
108
+ }
109
+ return true;
110
+ },
111
+ /**
112
+ * 时间是否相等
113
+ * @return {Boolean}
114
+ */
115
+ isEqual(date1, date2) {
116
+ const startTime = new Date(date1).getTime();
117
+ const endTime = new Date(date2).getTime();
118
+ if (startTime == endTime) {
119
+ return true;
120
+ }
121
+ return false;
122
+ },
123
+ };
124
+
125
+ function requestAniFrame() {
126
+ if (typeof window !== 'undefined') {
127
+ return (window.requestAnimationFrame ||
128
+ function (callback) {
129
+ window.setTimeout(callback, 1000 / 60);
130
+ });
131
+ }
132
+ return function (callback) {
133
+ setTimeout(callback, 1000 / 60);
134
+ };
135
+ }
136
+ var requestAniFrame$1 = requestAniFrame();
137
+
138
+ const defaultProps = {
139
+ type: 'one',
140
+ isAutoBackFill: false,
141
+ poppable: true,
142
+ visible: false,
143
+ title: '日历选择',
144
+ defaultValue: '',
145
+ startDate: Utils.getDay(0),
146
+ endDate: Utils.getDay(365),
147
+ showToday: true,
148
+ startText: '开始',
149
+ endText: '结束',
150
+ confirmText: '确认',
151
+ showTitle: true,
152
+ showSubTitle: true,
153
+ toDateAnimation: true,
154
+ onBtn: undefined,
155
+ onDay: undefined,
156
+ onTopInfo: undefined,
157
+ onBottomInfo: undefined,
158
+ onChoose: (data) => { },
159
+ onUpdate: () => { },
160
+ onSelected: (data) => { },
161
+ };
162
+ const CalendarItem = React__default.forwardRef((props, ref) => {
163
+ const { locale } = useConfig();
164
+ const { type, isAutoBackFill, poppable, title, defaultValue, showToday, startText, endText, confirmText, showTitle, showSubTitle, toDateAnimation, onBtn, onDay, onTopInfo, onBottomInfo, onChoose, onUpdate, onSelected, } = { ...defaultProps, ...props };
165
+ const weeks = locale.calendaritem.weekdays;
166
+ const [yearMonthTitle, setYearMonthTitle] = useState('');
167
+ const [monthsData, setMonthsData] = useState([]);
168
+ const [translateY, setTranslateY] = useState(0);
169
+ const [monthDefaultRange, setMonthDefaultRange] = useState([]);
170
+ const [state] = useState({
171
+ currDate: '',
172
+ propStartDate: '',
173
+ propEndDate: '',
174
+ unLoadPrev: false,
175
+ touchParams: {
176
+ startY: 0,
177
+ endY: 0,
178
+ startTime: 0,
179
+ endTime: 0,
180
+ lastY: 0,
181
+ lastTime: 0,
182
+ },
183
+ transformY: 0,
184
+ scrollDistance: 0,
185
+ defaultData: [],
186
+ chooseData: [],
187
+ monthsData: [],
188
+ dayPrefix: 'calendar-month-day',
189
+ startData: '',
190
+ endData: '',
191
+ isRange: props.type === 'range',
192
+ timer: 0,
193
+ currentIndex: 0,
194
+ avgHeight: 0,
195
+ monthsNum: 0,
196
+ });
197
+ const weeksPanel = useRef(null);
198
+ const months = useRef(null);
199
+ const monthsPanel = useRef(null);
200
+ const viewArea = useRef(null);
201
+ let viewHeight = 0;
202
+ const b = cn('calendar');
203
+ const classes = classNames({
204
+ [`${b('')}-tile`]: !poppable,
205
+ [`${b('')}-nofooter`]: !!isAutoBackFill,
206
+ }, b(''));
207
+ const headerClasses = classNames({
208
+ [`${b('')}-header`]: true,
209
+ [`${b('')}-header-tile`]: !poppable,
210
+ });
211
+ const monthitemclasses = classNames({
212
+ 'calendar-month-item': true,
213
+ [`${type === 'range' ? 'month-item-range' : ''}`]: true,
214
+ });
215
+ const splitDate = (date) => {
216
+ return date.split('-');
217
+ };
218
+ const isStart = (currDate) => {
219
+ return Utils.isEqual(state.currDate[0], currDate);
220
+ };
221
+ const isEnd = (currDate) => {
222
+ return Utils.isEqual(state.currDate[1], currDate);
223
+ };
224
+ const isMultiple = (currDate) => {
225
+ if (state.currDate.length > 0) {
226
+ return state.currDate.some((item) => {
227
+ return Utils.isEqual(item, currDate);
228
+ });
229
+ }
230
+ return false;
231
+ };
232
+ const getCurrDate = (day, month) => {
233
+ return `${month.curData[0]}-${month.curData[1]}-${Utils.getNumTwoBit(+day.day)}`;
234
+ };
235
+ const getClass = (day, month) => {
236
+ const currDate = getCurrDate(day, month);
237
+ if (day.type === 'curr') {
238
+ if (Utils.isEqual(state.currDate, currDate) ||
239
+ (type === 'range' && (isStart(currDate) || isEnd(currDate))) ||
240
+ (type === 'multiple' && isMultiple(currDate))) {
241
+ return `${state.dayPrefix}-active`;
242
+ }
243
+ if ((state.propStartDate &&
244
+ Utils.compareDate(currDate, state.propStartDate)) ||
245
+ (state.propEndDate && Utils.compareDate(state.propEndDate, currDate))) {
246
+ return `${state.dayPrefix}-disabled`;
247
+ }
248
+ if (type === 'range' &&
249
+ Array.isArray(state.currDate) &&
250
+ Object.values(state.currDate).length === 2 &&
251
+ Utils.compareDate(state.currDate[0], currDate) &&
252
+ Utils.compareDate(currDate, state.currDate[1])) {
253
+ return `${state.dayPrefix}-choose`;
254
+ }
255
+ return null;
256
+ }
257
+ return `${state.dayPrefix}-disabled`;
258
+ };
259
+ const isActive = (day, month) => {
260
+ return (state.isRange &&
261
+ day.type === 'curr' &&
262
+ getClass(day, month) === 'calendar-month-day-active');
263
+ };
264
+ const isCurrDay = (month, day) => {
265
+ const date = `${month.curData[0]}-${month.curData[1]}-${day}`;
266
+ return Utils.isEqual(date, Utils.date2Str(new Date()));
267
+ };
268
+ const confirm = () => {
269
+ const { type } = props;
270
+ if ((type === 'range' && state.chooseData.length === 2) ||
271
+ type !== 'range') {
272
+ const chooseData = state.chooseData.slice(0);
273
+ onChoose && onChoose(chooseData);
274
+ if (poppable) {
275
+ onUpdate && onUpdate();
276
+ }
277
+ }
278
+ };
279
+ const chooseDay = (day, month, isFirst) => {
280
+ if (getClass(day, month) !== `${state.dayPrefix}-disabled`) {
281
+ const { type } = props;
282
+ const days = [...month.curData];
283
+ days[2] =
284
+ typeof day.day === 'number' ? Utils.getNumTwoBit(day.day) : day.day;
285
+ days[3] = `${days[0]}-${days[1]}-${days[2]}`;
286
+ days[4] = Utils.getWhatDay(+days[0], +days[1], +days[2]);
287
+ if (type === 'multiple') {
288
+ if (state.currDate.length > 0) {
289
+ let hasIndex = '';
290
+ state.currDate.forEach((item, index) => {
291
+ if (item === days[3]) {
292
+ hasIndex = index;
293
+ }
294
+ });
295
+ if (isFirst) {
296
+ state.chooseData.push([...days]);
297
+ }
298
+ else if (hasIndex !== '') {
299
+ state.currDate.splice(hasIndex, 1);
300
+ state.chooseData.splice(hasIndex, 1);
301
+ }
302
+ else {
303
+ state.currDate.push(days[3]);
304
+ state.chooseData.push([...days]);
305
+ }
306
+ }
307
+ else {
308
+ state.currDate = [days[3]];
309
+ state.chooseData = [[...days]];
310
+ }
311
+ }
312
+ else if (type === 'range') {
313
+ const curDataLength = Object.values(state.currDate).length;
314
+ if (curDataLength === 2 || curDataLength === 0) {
315
+ state.currDate = [days[3]];
316
+ }
317
+ else if (Utils.compareDate(state.currDate[0], days[3])) {
318
+ Array.isArray(state.currDate) && state.currDate.push(days[3]);
319
+ }
320
+ else {
321
+ Array.isArray(state.currDate) && state.currDate.unshift(days[3]);
322
+ }
323
+ if (state.chooseData.length === 2 || !state.chooseData.length) {
324
+ state.chooseData = [[...days]];
325
+ }
326
+ else if (Utils.compareDate(state.chooseData[0][3], days[3])) {
327
+ state.chooseData = [...state.chooseData, [...days]];
328
+ }
329
+ else {
330
+ state.chooseData = [[...days], ...state.chooseData];
331
+ }
332
+ }
333
+ else {
334
+ state.currDate = days[3];
335
+ state.chooseData = [...days];
336
+ }
337
+ if (!isFirst) {
338
+ // 点击日期 触发
339
+ onSelected && onSelected(state.chooseData);
340
+ if (isAutoBackFill || !poppable) {
341
+ confirm();
342
+ }
343
+ }
344
+ setMonthsData(state.monthsData.slice());
345
+ }
346
+ };
347
+ const isStartTip = (day, month) => {
348
+ return isActive(day, month) && isStart(getCurrDate(day, month));
349
+ };
350
+ // 是否有结束提示
351
+ const isEndTip = (day, month) => {
352
+ if (state.currDate.length >= 2 && isEnd(getCurrDate(day, month))) {
353
+ return isActive(day, month);
354
+ }
355
+ return false;
356
+ };
357
+ // 开始结束时间是否相等
358
+ const rangeTip = () => {
359
+ if (state.currDate.length >= 2) {
360
+ return Utils.isEqual(state.currDate[0], state.currDate[1]);
361
+ }
362
+ return false;
363
+ };
364
+ // 获取当前月数据
365
+ const getCurrData = (type) => {
366
+ const monthData = type === 'prev'
367
+ ? state.monthsData[0]
368
+ : state.monthsData[state.monthsData.length - 1];
369
+ let year = parseInt(monthData.curData[0]);
370
+ let month = parseInt(monthData.curData[1].toString().replace(/^0/, ''));
371
+ switch (type) {
372
+ case 'prev':
373
+ month === 1 && (year -= 1);
374
+ month = month === 1 ? 12 : --month;
375
+ break;
376
+ case 'next':
377
+ month === 12 && (year += 1);
378
+ month = month === 12 ? 1 : ++month;
379
+ break;
380
+ }
381
+ return [
382
+ year,
383
+ Utils.getNumTwoBit(month),
384
+ Utils.getMonthDays(String(year), String(month)),
385
+ ];
386
+ };
387
+ // 获取日期状态
388
+ const getDaysStatus = (days, type, dateInfo) => {
389
+ // 修复:当某个月的1号是周日时,月份下方会空出来一行
390
+ const { year, month } = dateInfo;
391
+ if (type === 'prev' && days >= 7) {
392
+ days -= 7;
393
+ }
394
+ return Array.from(Array(days), (v, k) => {
395
+ return {
396
+ day: k + 1,
397
+ type,
398
+ year,
399
+ month,
400
+ };
401
+ });
402
+ };
403
+ // 获取上一个月的最后一周天数,填充当月空白
404
+ const getPreDaysStatus = (days, type, dateInfo, preCurrMonthDays) => {
405
+ // 修复:当某个月的1号是周日时,月份下方会空出来一行
406
+ const { year, month } = dateInfo;
407
+ if (type === 'prev' && days >= 7) {
408
+ days -= 7;
409
+ }
410
+ const months = Array.from(Array(preCurrMonthDays), (v, k) => {
411
+ return {
412
+ day: k + 1,
413
+ type,
414
+ year,
415
+ month,
416
+ };
417
+ });
418
+ return months.slice(preCurrMonthDays - days);
419
+ };
420
+ // 获取月数据
421
+ const getMonth = (curData, type) => {
422
+ const preMonthDays = Utils.getMonthPreDay(+curData[0], +curData[1]);
423
+ let preMonth = +curData[1] - 1;
424
+ let preYear = curData[0];
425
+ if (preMonth <= 0) {
426
+ preMonth = 12;
427
+ preYear += 1;
428
+ }
429
+ const currMonthDays = Utils.getMonthDays(curData[0], curData[1]);
430
+ const preCurrMonthDays = Utils.getMonthDays(`${preYear}`, `${preMonth}`);
431
+ const title = {
432
+ year: curData[0],
433
+ month: curData[1],
434
+ };
435
+ const monthInfo = {
436
+ curData,
437
+ title: locale.calendaritem.monthTitle(title.year, title.month),
438
+ monthData: [
439
+ ...getPreDaysStatus(preMonthDays, 'prev', { month: preMonth, year: preYear }, preCurrMonthDays),
440
+ ...getDaysStatus(currMonthDays, 'curr', title),
441
+ ],
442
+ };
443
+ monthInfo.cssHeight = 39 + (monthInfo.monthData.length > 35 ? 384 : 320);
444
+ let cssScrollHeight = 0;
445
+ if (state.monthsData.length > 0) {
446
+ cssScrollHeight =
447
+ state.monthsData[state.monthsData.length - 1].cssScrollHeight +
448
+ state.monthsData[state.monthsData.length - 1].cssHeight;
449
+ }
450
+ monthInfo.cssScrollHeight = cssScrollHeight;
451
+ if (type === 'next') {
452
+ if (!state.endData ||
453
+ !Utils.compareDate(`${state.endData[0]}-${state.endData[1]}-${Utils.getMonthDays(state.endData[0], state.endData[1])}`, `${curData[0]}-${curData[1]}-${curData[2]}`)) {
454
+ state.monthsData.push(monthInfo);
455
+ }
456
+ }
457
+ else if (!state.startData ||
458
+ !Utils.compareDate(`${curData[0]}-${curData[1]}-${curData[2]}`, `${state.startData[0]}-${state.startData[1]}-01`)) {
459
+ state.monthsData.unshift(monthInfo);
460
+ }
461
+ setMonthsData(state.monthsData);
462
+ };
463
+ const setDefaultRange = (monthsNum, current) => {
464
+ let start = 0;
465
+ let end = 0;
466
+ if (monthsNum >= 3) {
467
+ if (current > 0 && current < monthsNum) {
468
+ start = current - 1;
469
+ end = current + 3;
470
+ }
471
+ else if (current === 0) {
472
+ start = current;
473
+ end = current + 4;
474
+ }
475
+ else if (current === monthsNum) {
476
+ start = current - 2;
477
+ end = current + 2;
478
+ }
479
+ }
480
+ else {
481
+ start = 0;
482
+ end = monthsNum + 2;
483
+ }
484
+ setMonthDefaultRange([start, end]);
485
+ setTranslateY(state.monthsData[start].cssScrollHeight);
486
+ };
487
+ const mothsViewScroll = (e) => {
488
+ if (state.monthsData.length <= 1) {
489
+ return;
490
+ }
491
+ const target = e.target;
492
+ const currentScrollTop = target.scrollTop;
493
+ let current = Math.floor(currentScrollTop / state.avgHeight);
494
+ if (current === 0) {
495
+ if (currentScrollTop >= state.monthsData[current + 1].cssScrollHeight) {
496
+ current += 1;
497
+ }
498
+ }
499
+ else if (current > 0 && current < state.monthsNum - 1) {
500
+ if (currentScrollTop >= state.monthsData[current + 1].cssScrollHeight) {
501
+ current += 1;
502
+ }
503
+ if (currentScrollTop < state.monthsData[current].cssScrollHeight) {
504
+ current -= 1;
505
+ }
506
+ }
507
+ else {
508
+ const viewPosition = Math.round(currentScrollTop + viewHeight);
509
+ if (viewPosition <
510
+ state.monthsData[current].cssScrollHeight +
511
+ state.monthsData[current].cssHeight &&
512
+ currentScrollTop > state.monthsData[current - 1].cssScrollHeight) {
513
+ current -= 1;
514
+ }
515
+ if (current + 1 <= state.monthsNum &&
516
+ viewPosition >=
517
+ state.monthsData[current + 1].cssScrollHeight +
518
+ state.monthsData[current + 1].cssHeight) {
519
+ current += 1;
520
+ }
521
+ if (current >= 1 &&
522
+ currentScrollTop < state.monthsData[current - 1].cssScrollHeight) {
523
+ current -= 1;
524
+ }
525
+ }
526
+ if (state.currentIndex !== current) {
527
+ state.currentIndex = current;
528
+ setDefaultRange(state.monthsNum, current);
529
+ }
530
+ setYearMonthTitle(state.monthsData[current].title);
531
+ };
532
+ const initData = () => {
533
+ // 初始化开始结束数据
534
+ const propStartDate = props.startDate ? props.startDate : Utils.getDay(0);
535
+ const propEndDate = props.endDate ? props.endDate : Utils.getDay(365);
536
+ state.propStartDate = propStartDate;
537
+ state.propEndDate = propEndDate;
538
+ state.startData = splitDate(propStartDate);
539
+ state.endData = splitDate(propEndDate);
540
+ // 根据是否存在默认时间,初始化当前日期
541
+ if (defaultValue ||
542
+ (Array.isArray(defaultValue) && defaultValue.length > 0)) {
543
+ state.currDate =
544
+ props.type !== 'one'
545
+ ? [...props.defaultValue]
546
+ : props.defaultValue;
547
+ }
548
+ // 判断时间范围内存在多少个月
549
+ const startDate = {
550
+ year: Number(state.startData[0]),
551
+ month: Number(state.startData[1]),
552
+ };
553
+ const endDate = {
554
+ year: Number(state.endData[0]),
555
+ month: Number(state.endData[1]),
556
+ };
557
+ let monthsNum = endDate.month - startDate.month;
558
+ if (endDate.year - startDate.year > 0) {
559
+ monthsNum += 12 * (endDate.year - startDate.year);
560
+ }
561
+ if (monthsNum <= 0) {
562
+ monthsNum = 1;
563
+ }
564
+ // 设置月份数据
565
+ getMonth(state.startData, 'next');
566
+ let i = 1;
567
+ do {
568
+ getMonth(getCurrData('next'), 'next');
569
+ } while (i++ < monthsNum);
570
+ state.monthsNum = monthsNum;
571
+ // 日期转化为数组,限制初始日期。判断时间范围
572
+ if (type === 'range' && Array.isArray(state.currDate)) {
573
+ if (state.currDate.length > 0) {
574
+ if (propStartDate &&
575
+ Utils.compareDate(state.currDate[0], propStartDate)) {
576
+ state.currDate.splice(0, 1, propStartDate);
577
+ }
578
+ if (propEndDate &&
579
+ Utils.compareDate(propEndDate, state.currDate[1])) {
580
+ state.currDate.splice(1, 1, propEndDate);
581
+ }
582
+ state.defaultData = [
583
+ ...splitDate(state.currDate[0]),
584
+ ...splitDate(state.currDate[1]),
585
+ ];
586
+ }
587
+ }
588
+ else if (props.type === 'multiple' && Array.isArray(state.currDate)) {
589
+ if (state.currDate.length > 0) {
590
+ const defaultArr = [];
591
+ const obj = {};
592
+ state.currDate.forEach((item) => {
593
+ if (propStartDate &&
594
+ !Utils.compareDate(item, propStartDate) &&
595
+ propEndDate &&
596
+ !Utils.compareDate(propEndDate, item)) {
597
+ if (!Object.hasOwnProperty.call(obj, item)) {
598
+ defaultArr.push(item);
599
+ obj[item] = item;
600
+ }
601
+ }
602
+ });
603
+ state.currDate = [...defaultArr];
604
+ state.defaultData = [...splitDate(defaultArr[0])];
605
+ }
606
+ }
607
+ else if (state.currDate) {
608
+ if (propStartDate &&
609
+ Utils.compareDate(state.currDate, propStartDate)) {
610
+ state.currDate = propStartDate;
611
+ }
612
+ else if (propEndDate &&
613
+ !Utils.compareDate(state.currDate, propEndDate)) {
614
+ state.currDate = propEndDate;
615
+ }
616
+ state.defaultData = [...splitDate(state.currDate)];
617
+ }
618
+ // 设置默认可见区域
619
+ let current = 0;
620
+ let lastCurrent = 0;
621
+ if (state.defaultData.length > 0) {
622
+ state.monthsData.forEach((item, index) => {
623
+ if (item.title ===
624
+ locale.calendaritem.monthTitle(state.defaultData[0], state.defaultData[1])) {
625
+ current = index;
626
+ }
627
+ if (props.type === 'range') {
628
+ if (item.title ===
629
+ locale.calendaritem.monthTitle(state.defaultData[3], state.defaultData[4])) {
630
+ lastCurrent = index;
631
+ }
632
+ }
633
+ });
634
+ }
635
+ setDefaultRange(monthsNum, current);
636
+ state.currentIndex = current;
637
+ setYearMonthTitle(state.monthsData[state.currentIndex].title);
638
+ if (state.defaultData.length > 0) {
639
+ // 设置当前选中日期
640
+ if (type === 'range') {
641
+ chooseDay({ day: state.defaultData[2], type: 'curr' }, state.monthsData[state.currentIndex], true);
642
+ chooseDay({ day: state.defaultData[5], type: 'curr' }, state.monthsData[lastCurrent], true);
643
+ }
644
+ else if (type === 'multiple') {
645
+ [...state.currDate].forEach((item) => {
646
+ const dateArr = splitDate(item);
647
+ let current = state.currentIndex;
648
+ state.monthsData.forEach((item, index) => {
649
+ if (item.title ===
650
+ locale.calendaritem.monthTitle(dateArr[0], dateArr[1])) {
651
+ current = index;
652
+ }
653
+ });
654
+ chooseDay({ day: dateArr[2], type: 'curr' }, state.monthsData[current], true);
655
+ });
656
+ }
657
+ else {
658
+ chooseDay({ day: state.defaultData[2], type: 'curr' }, state.monthsData[state.currentIndex], true);
659
+ }
660
+ }
661
+ const lastItem = state.monthsData[state.monthsData.length - 1];
662
+ const containerHeight = lastItem.cssHeight + lastItem.cssScrollHeight;
663
+ requestAniFrame$1(() => {
664
+ // 初始化 日历位置
665
+ if (months && monthsPanel && viewArea) {
666
+ viewHeight = months.current.clientHeight;
667
+ monthsPanel.current.style.height = `${containerHeight}px`;
668
+ months.current.scrollTop =
669
+ state.monthsData[state.currentIndex].cssScrollHeight;
670
+ }
671
+ });
672
+ state.avgHeight = Math.floor(containerHeight / (monthsNum + 1));
673
+ };
674
+ const resetRender = () => {
675
+ state.chooseData.splice(0);
676
+ state.monthsData.splice(0);
677
+ initData();
678
+ };
679
+ // 暴露出的API
680
+ const scrollToDate = (date) => {
681
+ if (Utils.compareDate(date, state.propStartDate)) {
682
+ date = state.propStartDate;
683
+ }
684
+ else if (!Utils.compareDate(date, state.propEndDate)) {
685
+ date = state.propEndDate;
686
+ }
687
+ const dateArr = splitDate(date);
688
+ state.monthsData.forEach((item, index) => {
689
+ if (item.title === locale.calendaritem.monthTitle(dateArr[0], dateArr[1])) {
690
+ if (months.current) {
691
+ const distance = state.monthsData[index].cssScrollHeight - months.current.scrollTop;
692
+ if (toDateAnimation) {
693
+ let flag = 0;
694
+ const interval = setInterval(() => {
695
+ flag++;
696
+ if (months.current) {
697
+ const offset = distance / 10;
698
+ months.current.scrollTop += offset;
699
+ }
700
+ if (flag >= 10) {
701
+ clearInterval(interval);
702
+ if (months.current) {
703
+ months.current.scrollTop =
704
+ state.monthsData[index].cssScrollHeight;
705
+ }
706
+ }
707
+ }, 40);
708
+ }
709
+ else {
710
+ months.current.scrollTop = state.monthsData[index].cssScrollHeight;
711
+ }
712
+ }
713
+ }
714
+ });
715
+ };
716
+ useEffect(() => {
717
+ initData();
718
+ }, []);
719
+ useEffect(() => {
720
+ poppable && resetRender();
721
+ }, [defaultValue]);
722
+ React__default.useImperativeHandle(ref, () => ({
723
+ scrollToDate,
724
+ }));
725
+ return (React__default.createElement(React__default.Fragment, null,
726
+ React__default.createElement("div", { className: classes },
727
+ React__default.createElement("div", { className: headerClasses },
728
+ showTitle && (React__default.createElement("div", { className: "calendar-title" }, title || locale.calendaritem.title)),
729
+ onBtn && React__default.createElement("div", { className: "calendar-top-slot" }, onBtn()),
730
+ showSubTitle && (React__default.createElement("div", { className: "calendar-curr-month" }, yearMonthTitle)),
731
+ React__default.createElement("div", { className: "calendar-weeks", ref: weeksPanel }, weeks.map((item) => (React__default.createElement("div", { className: "calendar-week-item", key: item }, item))))),
732
+ React__default.createElement("div", { className: "nut-calendar-content", onScroll: mothsViewScroll, ref: months },
733
+ React__default.createElement("div", { className: "calendar-months-panel", ref: monthsPanel },
734
+ React__default.createElement("div", { className: "viewArea", ref: viewArea, style: { transform: `translateY(${translateY}px)` } }, state.monthsData
735
+ .slice(monthDefaultRange[0], monthDefaultRange[1])
736
+ .map((month, key) => {
737
+ return (React__default.createElement("div", { className: "calendar-month", key: key },
738
+ React__default.createElement("div", { className: "calendar-month-title" }, month.title),
739
+ React__default.createElement("div", { className: "calendar-month-con" },
740
+ React__default.createElement("div", { className: monthitemclasses }, month.monthData.map((day, i) => (React__default.createElement("div", { className: [
741
+ 'calendar-month-day',
742
+ getClass(day, month),
743
+ ].join(' '), onClick: () => {
744
+ chooseDay(day, month);
745
+ }, key: i },
746
+ React__default.createElement("div", { className: "calendar-day" }, onDay ? onDay(day) : day.day),
747
+ onTopInfo && (React__default.createElement("div", { className: "calendar-curr-tips calendar-curr-tips-top" }, onTopInfo(day))),
748
+ onBottomInfo && (React__default.createElement("div", { className: "calendar-curr-tips calendar-curr-tips-bottom" }, onBottomInfo(day))),
749
+ !onBottomInfo &&
750
+ showToday &&
751
+ isCurrDay(month, day.day) && (React__default.createElement("div", { className: "calendar-curr-tip-curr" }, locale.calendaritem.today)),
752
+ isStartTip(day, month) && (React__default.createElement("div", { className: `calendar-day-tip ${rangeTip() ? 'calendar-curr-tips-top' : ''}` }, startText || locale.calendaritem.start)),
753
+ isEndTip(day, month) && (React__default.createElement("div", { className: "calendar-day-tip" }, endText || locale.calendaritem.end)))))))));
754
+ })))),
755
+ poppable && !isAutoBackFill ? (React__default.createElement("div", { className: "nut-calendar-footer" },
756
+ React__default.createElement("div", { className: "calendar-confirm-btn", onClick: confirm }, confirmText || locale.confirm))) : (''))));
757
+ });
758
+ CalendarItem.defaultProps = defaultProps;
759
+ CalendarItem.displayName = 'NutCalendarItem';
760
+
761
+ export { CalendarItem as C, Utils as U };