@seafile/seafile-calendar 1.0.21 → 1.0.23-avb.71

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.
@@ -2,6 +2,10 @@
2
2
 
3
3
  exports.__esModule = true;
4
4
 
5
+ var _extends4 = require('babel-runtime/helpers/extends');
6
+
7
+ var _extends5 = _interopRequireDefault(_extends4);
8
+
5
9
  var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
6
10
 
7
11
  var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
@@ -28,6 +32,8 @@ var _dayjs2 = _interopRequireDefault(_dayjs);
28
32
 
29
33
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
30
34
 
35
+ var MIN_SCROLLBAR_THUMB_HEIGHT = 24;
36
+
31
37
  var CalendarRightPanel = function (_React$Component) {
32
38
  (0, _inherits3['default'])(CalendarRightPanel, _React$Component);
33
39
 
@@ -36,6 +42,90 @@ var CalendarRightPanel = function (_React$Component) {
36
42
 
37
43
  var _this = (0, _possibleConstructorReturn3['default'])(this, _React$Component.call(this, props));
38
44
 
45
+ _this.getTimeColumnContainer = function (type) {
46
+ return type === 'hour' ? _this.hoursRef.current : _this.minutesRef.current;
47
+ };
48
+
49
+ _this.onTimeColumnScroll = function (type, container) {
50
+ var clientHeight = container.clientHeight,
51
+ scrollHeight = container.scrollHeight,
52
+ scrollTop = container.scrollTop;
53
+
54
+ if (scrollHeight <= clientHeight) return;
55
+
56
+ var trackHeight = clientHeight;
57
+ var height = Math.min(trackHeight, Math.max(MIN_SCROLLBAR_THUMB_HEIGHT, clientHeight / scrollHeight * trackHeight));
58
+ var maxTop = trackHeight - height;
59
+ var maxScrollTop = scrollHeight - clientHeight;
60
+ var top = maxScrollTop > 0 ? scrollTop / maxScrollTop * maxTop : 0;
61
+
62
+ clearTimeout(_this.scrollbarTimeouts[type]);
63
+ _this.setState(function (prevState) {
64
+ var _extends2;
65
+
66
+ return {
67
+ scrollbars: (0, _extends5['default'])({}, prevState.scrollbars, (_extends2 = {}, _extends2[type] = { visible: true, top: top, height: height }, _extends2))
68
+ };
69
+ });
70
+ _this.scrollbarTimeouts[type] = setTimeout(function () {
71
+ _this.setState(function (prevState) {
72
+ var _extends3;
73
+
74
+ return {
75
+ scrollbars: (0, _extends5['default'])({}, prevState.scrollbars, (_extends3 = {}, _extends3[type] = (0, _extends5['default'])({}, prevState.scrollbars[type], { visible: false }), _extends3))
76
+ };
77
+ });
78
+ }, 800);
79
+ };
80
+
81
+ _this.onScrollbarThumbMouseDown = function (type, event) {
82
+ var container = _this.getTimeColumnContainer(type);
83
+ var _this$state$scrollbar = _this.state.scrollbars[type],
84
+ top = _this$state$scrollbar.top,
85
+ height = _this$state$scrollbar.height;
86
+
87
+ if (!container || !height) return;
88
+
89
+ event.preventDefault();
90
+ _this.draggingScrollbar = {
91
+ type: type,
92
+ startClientY: event.clientY,
93
+ startTop: top
94
+ };
95
+ window.addEventListener('mousemove', _this.onScrollbarThumbMouseMove);
96
+ window.addEventListener('mouseup', _this.onScrollbarThumbMouseUp);
97
+ };
98
+
99
+ _this.onScrollbarThumbMouseMove = function (event) {
100
+ if (!_this.draggingScrollbar) return;
101
+
102
+ var _this$draggingScrollb = _this.draggingScrollbar,
103
+ type = _this$draggingScrollb.type,
104
+ startClientY = _this$draggingScrollb.startClientY,
105
+ startTop = _this$draggingScrollb.startTop;
106
+
107
+ var container = _this.getTimeColumnContainer(type);
108
+ var height = _this.state.scrollbars[type].height;
109
+
110
+ if (!container) return;
111
+
112
+ var maxTop = Math.max(0, container.clientHeight - height);
113
+ var top = Math.max(0, Math.min(maxTop, startTop + event.clientY - startClientY));
114
+ var maxScrollTop = container.scrollHeight - container.clientHeight;
115
+ container.scrollTop = maxTop > 0 ? top / maxTop * maxScrollTop : 0;
116
+ _this.onTimeColumnScroll(type, container);
117
+ };
118
+
119
+ _this.onScrollbarThumbMouseUp = function () {
120
+ _this.draggingScrollbar = null;
121
+ _this.removeScrollbarDragListeners();
122
+ };
123
+
124
+ _this.removeScrollbarDragListeners = function () {
125
+ window.removeEventListener('mousemove', _this.onScrollbarThumbMouseMove);
126
+ window.removeEventListener('mouseup', _this.onScrollbarThumbMouseUp);
127
+ };
128
+
39
129
  _this.centerScroll = function (container, index) {
40
130
  if (!container || index < 0) return;
41
131
  var firstItem = container.querySelector('li');
@@ -101,10 +191,35 @@ var CalendarRightPanel = function (_React$Component) {
101
191
  return v ? v.format('mm') : null;
102
192
  };
103
193
 
194
+ _this.renderScrollbar = function (type, prefixCls) {
195
+ var _this$state$scrollbar2 = _this.state.scrollbars[type],
196
+ visible = _this$state$scrollbar2.visible,
197
+ top = _this$state$scrollbar2.top,
198
+ height = _this$state$scrollbar2.height;
199
+
200
+ var visibleClassName = prefixCls + '-right-panel-scrollbar-visible';
201
+ var className = prefixCls + '-right-panel-scrollbar' + (visible ? ' ' + visibleClassName : '');
202
+ return _react2['default'].createElement(
203
+ 'div',
204
+ { className: className, 'aria-hidden': 'true' },
205
+ _react2['default'].createElement('div', {
206
+ className: prefixCls + '-right-panel-scrollbar-thumb',
207
+ style: { height: height, transform: 'translateY(' + top + 'px)' },
208
+ onMouseDown: function onMouseDown(event) {
209
+ return _this.onScrollbarThumbMouseDown(type, event);
210
+ }
211
+ })
212
+ );
213
+ };
214
+
104
215
  var format = Array.isArray(_this.props.format) ? _this.props.format[0] : _this.props.format;
105
216
  _this.state = {
106
217
  highlightTime: _this.props.selectedValue || null,
107
- localeFormat: format
218
+ localeFormat: format,
219
+ scrollbars: {
220
+ hour: { visible: false, top: 0, height: 0 },
221
+ minute: { visible: false, top: 0, height: 0 }
222
+ }
108
223
  };
109
224
 
110
225
  _this.hoursRef = _react2['default'].createRef();
@@ -113,6 +228,8 @@ var CalendarRightPanel = function (_React$Component) {
113
228
  _this.minutes = _this.getMinutes();
114
229
 
115
230
  _this.skipScrollUpdates = 0;
231
+ _this.scrollbarTimeouts = {};
232
+ _this.draggingScrollbar = null;
116
233
  return _this;
117
234
  }
118
235
 
@@ -197,88 +314,118 @@ var CalendarRightPanel = function (_React$Component) {
197
314
  }
198
315
  };
199
316
 
200
- CalendarRightPanel.prototype.render = function render() {
317
+ CalendarRightPanel.prototype.componentWillUnmount = function componentWillUnmount() {
201
318
  var _this4 = this;
202
319
 
320
+ Object.keys(this.scrollbarTimeouts).forEach(function (type) {
321
+ clearTimeout(_this4.scrollbarTimeouts[type]);
322
+ });
323
+ this.removeScrollbarDragListeners();
324
+ };
325
+
326
+ CalendarRightPanel.prototype.render = function render() {
327
+ var _this5 = this;
328
+
203
329
  var prefixCls = this.props.prefixCls;
204
330
 
205
331
  var selectedHour = this.getSelectedHour();
206
332
  var selectedMinute = this.getSelectedMinute();
207
333
  var currentHour = (0, _dayjs2['default'])().format('HH');
208
334
  var currentMinute = (0, _dayjs2['default'])().format('mm');
209
- var displayHour = selectedHour || currentHour;
210
- var displayMinute = selectedMinute || currentMinute;
211
335
 
212
336
  return _react2['default'].createElement(
213
337
  'div',
214
338
  { className: prefixCls + '-right-panel' },
215
- _react2['default'].createElement(
216
- 'div',
217
- { className: prefixCls + '-right-panel-header ' + prefixCls + '-header' },
218
- displayHour,
219
- ':',
220
- displayMinute
221
- ),
222
339
  _react2['default'].createElement(
223
340
  'div',
224
341
  { className: prefixCls + '-right-panel-body' },
225
342
  _react2['default'].createElement(
226
343
  'div',
227
- { className: prefixCls + '-right-panel-col', ref: this.hoursRef },
344
+ { className: prefixCls + '-right-panel-col-wrap ' + prefixCls + '-right-panel-col-hour' },
228
345
  _react2['default'].createElement(
229
- 'ul',
230
- null,
231
- this.hours.map(function (h) {
232
- var isSelected = selectedHour && h === selectedHour;
233
- var isCurrent = !selectedHour && h === currentHour;
234
- var className = prefixCls + '-right-panel-item-text ' + (isSelected ? prefixCls + '-right-panel-item-selected' : '') + ' ' + (isCurrent ? prefixCls + '-right-panel-item-current' : '');
235
- return _react2['default'].createElement(
236
- 'li',
237
- {
238
- key: h,
239
- onClick: function onClick() {
240
- return _this4.onSelectHour(h);
241
- },
242
- className: prefixCls + '-right-panel-item',
243
- title: h
244
- },
245
- _react2['default'].createElement(
246
- 'span',
247
- { className: className },
248
- h
249
- )
250
- );
251
- })
252
- )
346
+ 'div',
347
+ {
348
+ className: prefixCls + '-right-panel-col',
349
+ ref: this.hoursRef,
350
+ onScroll: function onScroll(event) {
351
+ return _this5.onTimeColumnScroll('hour', event.currentTarget);
352
+ }
353
+ },
354
+ _react2['default'].createElement(
355
+ 'div',
356
+ { className: prefixCls + '-right-panel-col-item' },
357
+ _react2['default'].createElement(
358
+ 'ul',
359
+ null,
360
+ this.hours.map(function (h) {
361
+ var isSelected = selectedHour && h === selectedHour;
362
+ var isCurrent = !selectedHour && h === currentHour;
363
+ var className = prefixCls + '-right-panel-item-text ' + (isSelected ? prefixCls + '-right-panel-item-selected' : '') + ' ' + (isCurrent ? prefixCls + '-right-panel-item-current' : '');
364
+ return _react2['default'].createElement(
365
+ 'li',
366
+ {
367
+ key: h,
368
+ onClick: function onClick() {
369
+ return _this5.onSelectHour(h);
370
+ },
371
+ className: prefixCls + '-right-panel-item',
372
+ title: h
373
+ },
374
+ _react2['default'].createElement(
375
+ 'span',
376
+ { className: className },
377
+ h
378
+ )
379
+ );
380
+ })
381
+ )
382
+ )
383
+ ),
384
+ this.renderScrollbar('hour', prefixCls)
253
385
  ),
254
386
  _react2['default'].createElement(
255
387
  'div',
256
- { className: prefixCls + '-right-panel-col', ref: this.minutesRef },
388
+ { className: prefixCls + '-right-panel-col-wrap' },
257
389
  _react2['default'].createElement(
258
- 'ul',
259
- null,
260
- this.minutes.map(function (m) {
261
- var isSelected = selectedMinute && m === selectedMinute;
262
- var isCurrent = !selectedMinute && m === currentMinute;
263
- var className = prefixCls + '-right-panel-item-text ' + (isSelected ? prefixCls + '-right-panel-item-selected' : '') + ' ' + (isCurrent ? prefixCls + '-right-panel-item-current' : '');
264
- return _react2['default'].createElement(
265
- 'li',
266
- {
267
- key: m,
268
- onClick: function onClick() {
269
- return _this4.onSelectMinute(m);
270
- },
271
- className: prefixCls + '-right-panel-item',
272
- title: m
273
- },
274
- _react2['default'].createElement(
275
- 'span',
276
- { className: className },
277
- m
278
- )
279
- );
280
- })
281
- )
390
+ 'div',
391
+ {
392
+ className: prefixCls + '-right-panel-col',
393
+ ref: this.minutesRef,
394
+ onScroll: function onScroll(event) {
395
+ return _this5.onTimeColumnScroll('minute', event.currentTarget);
396
+ }
397
+ },
398
+ _react2['default'].createElement(
399
+ 'div',
400
+ { className: prefixCls + '-right-panel-col-item' },
401
+ _react2['default'].createElement(
402
+ 'ul',
403
+ null,
404
+ this.minutes.map(function (m) {
405
+ var isSelected = selectedMinute && m === selectedMinute;
406
+ var isCurrent = !selectedMinute && m === currentMinute;
407
+ var className = prefixCls + '-right-panel-item-text ' + (isSelected ? prefixCls + '-right-panel-item-selected' : '') + ' ' + (isCurrent ? prefixCls + '-right-panel-item-current' : '');
408
+ return _react2['default'].createElement(
409
+ 'li',
410
+ {
411
+ key: m,
412
+ onClick: function onClick() {
413
+ return _this5.onSelectMinute(m);
414
+ },
415
+ className: prefixCls + '-right-panel-item',
416
+ title: m
417
+ },
418
+ _react2['default'].createElement(
419
+ 'span',
420
+ { className: className },
421
+ m
422
+ )
423
+ );
424
+ })
425
+ )
426
+ )
427
+ ),
428
+ this.renderScrollbar('minute', prefixCls)
282
429
  )
283
430
  )
284
431
  );
@@ -92,7 +92,7 @@ var DateTHead = function (_React$Component) {
92
92
  null,
93
93
  _react2['default'].createElement(
94
94
  'tr',
95
- { role: 'row' },
95
+ { role: 'row', className: prefixCls + '-week-date-header' },
96
96
  showWeekNumberEl,
97
97
  weekDaysEls
98
98
  )
@@ -140,8 +140,8 @@ var TimeInput = function (_React$Component) {
140
140
  TimeInput.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, state) {
141
141
  var newState = null;
142
142
  if (!state.hasFocus) {
143
- var base = nextProps.selectedValue || null;
144
- newState = { str: base ? formatTime(base, nextProps.format) : '' };
143
+ var base = nextProps.selectedValue || (0, _dayjs2['default'])();
144
+ newState = { str: formatTime(base, nextProps.format) };
145
145
  }
146
146
  return newState;
147
147
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seafile/seafile-calendar",
3
- "version": "1.0.21",
3
+ "version": "1.0.23avb.71",
4
4
  "description": "React Calendar",
5
5
  "keywords": [
6
6
  "react",