Socket
Socket
Sign inDemoInstall

rc-calendar

Package Overview
Dependencies
Maintainers
5
Versions
239
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rc-calendar - npm Package Compare versions

Comparing version 9.6.1 to 9.6.2

es/util/toTime.js

58

es/Calendar.js

@@ -14,39 +14,6 @@ import _extends from 'babel-runtime/helpers/extends';

import { getTimeConfig, getTodayTime, syncTime } from './util';
import { goStartMonth, goEndMonth, goTime as _goTime } from './util/toTime';
function noop() {}
function goStartMonth() {
var next = this.state.value.clone();
next.startOf('month');
this.setValue(next);
}
function goEndMonth() {
var next = this.state.value.clone();
next.endOf('month');
this.setValue(next);
}
function goTime(direction, unit) {
var next = this.state.value.clone();
next.add(direction, unit);
this.setValue(next);
}
function goMonth(direction) {
return goTime.call(this, direction, 'months');
}
function goYear(direction) {
return goTime.call(this, direction, 'years');
}
function goWeek(direction) {
return goTime.call(this, direction, 'weeks');
}
function goDay(direction) {
return goTime.call(this, direction, 'days');
}
var Calendar = createReactClass({

@@ -115,7 +82,7 @@ displayName: 'Calendar',

case KeyCode.DOWN:
goWeek.call(this, 1);
this.goTime(1, 'weeks');
event.preventDefault();
return 1;
case KeyCode.UP:
goWeek.call(this, -1);
this.goTime(-1, 'weeks');
event.preventDefault();

@@ -125,5 +92,5 @@ return 1;

if (ctrlKey) {
goYear.call(this, -1);
this.goTime(-1, 'years');
} else {
goDay.call(this, -1);
this.goTime(-1, 'days');
}

@@ -134,5 +101,5 @@ event.preventDefault();

if (ctrlKey) {
goYear.call(this, 1);
this.goTime(1, 'years');
} else {
goDay.call(this, 1);
this.goTime(1, 'days');
}

@@ -142,15 +109,15 @@ event.preventDefault();

case KeyCode.HOME:
goStartMonth.call(this);
this.setValue(goStartMonth(this.state.value));
event.preventDefault();
return 1;
case KeyCode.END:
goEndMonth.call(this);
this.setValue(goEndMonth(this.state.value));
event.preventDefault();
return 1;
case KeyCode.PAGE_DOWN:
goMonth.call(this, 1);
this.goTime(1, 'month');
event.preventDefault();
return 1;
case KeyCode.PAGE_UP:
goMonth.call(this, -1);
this.goTime(-1, 'month');
event.preventDefault();

@@ -225,2 +192,5 @@ return 1;

},
goTime: function goTime(direction, unit) {
this.setValue(_goTime(this.state.value, direction, unit));
},
render: function render() {

@@ -227,0 +197,0 @@ var props = this.props,

@@ -88,2 +88,3 @@ import React from 'react';

var passed = 0;
for (iIndex = 0; iIndex < DateConstants.DATE_ROW_COUNT; iIndex++) {

@@ -233,3 +234,4 @@ for (jIndex = 0; jIndex < DateConstants.DATE_COL_COUNT; jIndex++) {

role: 'gridcell',
title: getTitleString(current), className: cls
title: getTitleString(current),
className: cls
},

@@ -236,0 +238,0 @@ dateHtml

@@ -88,3 +88,5 @@ import _extends from 'babel-runtime/helpers/extends';

'div',
{ className: rangeClassName + '-part ' + rangeClassName + '-' + direction },
{
className: rangeClassName + '-part ' + rangeClassName + '-' + direction
},
dateInputElement,

@@ -91,0 +93,0 @@ React.createElement(

@@ -7,2 +7,3 @@ import _extends from 'babel-runtime/helpers/extends';

import classnames from 'classnames';
import KeyCode from 'rc-util/es/KeyCode';
import CalendarPart from './range-calendar/CalendarPart';

@@ -13,3 +14,4 @@ import TodayButton from './calendar/TodayButton';

import CommonMixin from './mixin/CommonMixin';
import { syncTime, getTodayTime, isAllowedDate } from './util/';
import { syncTime, getTodayTime, isAllowedDate } from './util';
import { goTime, goStartMonth, goEndMonth, includesTime } from './util/toTime';

@@ -205,7 +207,164 @@ function noop() {}

},
onKeyDown: function onKeyDown(event) {
var _this = this;
if (event.target.nodeName.toLowerCase() === 'input') {
return;
}
var keyCode = event.keyCode;
var ctrlKey = event.ctrlKey || event.metaKey;
var _state2 = this.state,
selectedValue = _state2.selectedValue,
hoverValue = _state2.hoverValue,
firstSelectedValue = _state2.firstSelectedValue,
value = _state2.value;
var _props = this.props,
onKeyDown = _props.onKeyDown,
disabledDate = _props.disabledDate;
// Update last time of the picker
var updateHoverPoint = function updateHoverPoint(func) {
// Change hover to make focus in UI
var currentHoverTime = void 0;
var nextHoverTime = void 0;
var nextHoverValue = void 0;
if (!firstSelectedValue) {
currentHoverTime = hoverValue[0] || selectedValue[0] || value[0] || moment();
nextHoverTime = func(currentHoverTime);
nextHoverValue = [nextHoverTime];
_this.fireHoverValueChange(nextHoverValue);
} else {
if (hoverValue.length === 1) {
currentHoverTime = hoverValue[0].clone();
nextHoverTime = func(currentHoverTime);
nextHoverValue = _this.onDayHover(nextHoverTime);
} else {
currentHoverTime = hoverValue[0].isSame(firstSelectedValue, 'day') ? hoverValue[1] : hoverValue[0];
nextHoverTime = func(currentHoverTime);
nextHoverValue = _this.onDayHover(nextHoverTime);
}
}
// Find origin hover time on value index
if (nextHoverValue.length >= 2) {
var miss = nextHoverValue.some(function (ht) {
return !includesTime(value, ht, 'month');
});
if (miss) {
var newValue = nextHoverValue.slice().sort(function (t1, t2) {
return t1.valueOf() - t2.valueOf();
});
if (newValue[0].isSame(newValue[1], 'month')) {
newValue[1] = newValue[0].clone().add(1, 'month');
}
_this.fireValueChange(newValue);
}
} else if (nextHoverValue.length === 1) {
// If only one value, let's keep the origin panel
var oriValueIndex = value.findIndex(function (time) {
return time.isSame(currentHoverTime, 'month');
});
if (oriValueIndex === -1) oriValueIndex = 0;
if (value.every(function (time) {
return !time.isSame(nextHoverTime, 'month');
})) {
var _newValue = value.slice();
_newValue[oriValueIndex] = nextHoverTime.clone();
_this.fireValueChange(_newValue);
}
}
event.preventDefault();
return nextHoverTime;
};
switch (keyCode) {
case KeyCode.DOWN:
updateHoverPoint(function (time) {
return goTime(time, 1, 'weeks');
});
return;
case KeyCode.UP:
updateHoverPoint(function (time) {
return goTime(time, -1, 'weeks');
});
return;
case KeyCode.LEFT:
if (ctrlKey) {
updateHoverPoint(function (time) {
return goTime(time, -1, 'years');
});
} else {
updateHoverPoint(function (time) {
return goTime(time, -1, 'days');
});
}
return;
case KeyCode.RIGHT:
if (ctrlKey) {
updateHoverPoint(function (time) {
return goTime(time, 1, 'years');
});
} else {
updateHoverPoint(function (time) {
return goTime(time, 1, 'days');
});
}
return;
case KeyCode.HOME:
updateHoverPoint(function (time) {
return goStartMonth(time);
});
return;
case KeyCode.END:
updateHoverPoint(function (time) {
return goEndMonth(time);
});
return;
case KeyCode.PAGE_DOWN:
updateHoverPoint(function (time) {
return goTime(time, 1, 'month');
});
return;
case KeyCode.PAGE_UP:
updateHoverPoint(function (time) {
return goTime(time, -1, 'month');
});
return;
case KeyCode.ENTER:
{
var lastValue = void 0;
if (hoverValue.length === 0) {
lastValue = updateHoverPoint(function (time) {
return time;
});
} else if (hoverValue.length === 1) {
lastValue = hoverValue[0];
} else {
lastValue = hoverValue[0].isSame(firstSelectedValue, 'day') ? hoverValue[1] : hoverValue[0];
}
if (lastValue && (!disabledDate || !disabledDate(lastValue))) {
this.onSelect(lastValue);
}
event.preventDefault();
return;
}
default:
if (onKeyDown) {
onKeyDown(event);
}
}
},
onDayHover: function onDayHover(value) {
var hoverValue = [];
var _state2 = this.state,
selectedValue = _state2.selectedValue,
firstSelectedValue = _state2.firstSelectedValue;
var _state3 = this.state,
selectedValue = _state3.selectedValue,
firstSelectedValue = _state3.firstSelectedValue;
var type = this.props.type;

@@ -219,3 +378,6 @@

if (!firstSelectedValue) {
return;
if (this.state.hoverValue.length) {
this.setState({ hoverValue: [] });
}
return hoverValue;
}

@@ -225,2 +387,4 @@ hoverValue = this.compare(value, firstSelectedValue) < 0 ? [value, firstSelectedValue] : [firstSelectedValue, value];

this.fireHoverValueChange(hoverValue);
return hoverValue;
},

@@ -315,6 +479,6 @@ onToday: function onToday() {

getEndValue: function getEndValue() {
var _state3 = this.state,
value = _state3.value,
selectedValue = _state3.selectedValue,
showTimePicker = _state3.showTimePicker;
var _state4 = this.state,
value = _state4.value,
selectedValue = _state4.selectedValue,
showTimePicker = _state4.showTimePicker;

@@ -334,5 +498,5 @@ var endValue = value[1] ? value[1].clone() : value[0].clone().add(1, 'month');

getEndDisableTime: function getEndDisableTime() {
var _state4 = this.state,
selectedValue = _state4.selectedValue,
value = _state4.value;
var _state5 = this.state,
selectedValue = _state5.selectedValue,
value = _state5.value;
var disabledTime = this.props.disabledTime;

@@ -522,2 +686,7 @@

var isClosestMonths = nextMonthOfStart.year() === endValue.year() && nextMonthOfStart.month() === endValue.month();
// console.warn('Render:', selectedValue.map(t => t.format('YYYY-MM-DD')).join(', '));
// console.log('start:', startValue.format('YYYY-MM-DD'));
// console.log('end:', endValue.format('YYYY-MM-DD'));
return React.createElement(

@@ -529,3 +698,4 @@ 'div',

style: props.style,
tabIndex: '0'
tabIndex: '0',
onKeyDown: this.onKeyDown
},

@@ -532,0 +702,0 @@ props.renderSidebar(),

@@ -55,2 +55,4 @@ 'use strict';

var _toTime = require('./util/toTime');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

@@ -60,36 +62,2 @@

function goStartMonth() {
var next = this.state.value.clone();
next.startOf('month');
this.setValue(next);
}
function goEndMonth() {
var next = this.state.value.clone();
next.endOf('month');
this.setValue(next);
}
function goTime(direction, unit) {
var next = this.state.value.clone();
next.add(direction, unit);
this.setValue(next);
}
function goMonth(direction) {
return goTime.call(this, direction, 'months');
}
function goYear(direction) {
return goTime.call(this, direction, 'years');
}
function goWeek(direction) {
return goTime.call(this, direction, 'weeks');
}
function goDay(direction) {
return goTime.call(this, direction, 'days');
}
var Calendar = (0, _createReactClass2['default'])({

@@ -158,7 +126,7 @@ displayName: 'Calendar',

case _KeyCode2['default'].DOWN:
goWeek.call(this, 1);
this.goTime(1, 'weeks');
event.preventDefault();
return 1;
case _KeyCode2['default'].UP:
goWeek.call(this, -1);
this.goTime(-1, 'weeks');
event.preventDefault();

@@ -168,5 +136,5 @@ return 1;

if (ctrlKey) {
goYear.call(this, -1);
this.goTime(-1, 'years');
} else {
goDay.call(this, -1);
this.goTime(-1, 'days');
}

@@ -177,5 +145,5 @@ event.preventDefault();

if (ctrlKey) {
goYear.call(this, 1);
this.goTime(1, 'years');
} else {
goDay.call(this, 1);
this.goTime(1, 'days');
}

@@ -185,15 +153,15 @@ event.preventDefault();

case _KeyCode2['default'].HOME:
goStartMonth.call(this);
this.setValue((0, _toTime.goStartMonth)(this.state.value));
event.preventDefault();
return 1;
case _KeyCode2['default'].END:
goEndMonth.call(this);
this.setValue((0, _toTime.goEndMonth)(this.state.value));
event.preventDefault();
return 1;
case _KeyCode2['default'].PAGE_DOWN:
goMonth.call(this, 1);
this.goTime(1, 'month');
event.preventDefault();
return 1;
case _KeyCode2['default'].PAGE_UP:
goMonth.call(this, -1);
this.goTime(-1, 'month');
event.preventDefault();

@@ -268,2 +236,5 @@ return 1;

},
goTime: function goTime(direction, unit) {
this.setValue((0, _toTime.goTime)(this.state.value, direction, unit));
},
render: function render() {

@@ -270,0 +241,0 @@ var props = this.props,

@@ -109,2 +109,3 @@ 'use strict';

var passed = 0;
for (iIndex = 0; iIndex < _DateConstants2['default'].DATE_ROW_COUNT; iIndex++) {

@@ -254,3 +255,4 @@ for (jIndex = 0; jIndex < _DateConstants2['default'].DATE_COL_COUNT; jIndex++) {

role: 'gridcell',
title: (0, _util.getTitleString)(current), className: cls
title: (0, _util.getTitleString)(current),
className: cls
},

@@ -257,0 +259,0 @@ dateHtml

@@ -115,3 +115,5 @@ 'use strict';

'div',
{ className: rangeClassName + '-part ' + rangeClassName + '-' + direction },
{
className: rangeClassName + '-part ' + rangeClassName + '-' + direction
},
dateInputElement,

@@ -118,0 +120,0 @@ _react2['default'].createElement(

@@ -29,2 +29,6 @@ 'use strict';

var _KeyCode = require('rc-util/lib/KeyCode');
var _KeyCode2 = _interopRequireDefault(_KeyCode);
var _CalendarPart = require('./range-calendar/CalendarPart');

@@ -50,4 +54,6 @@

var _util = require('./util/');
var _util = require('./util');
var _toTime = require('./util/toTime');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

@@ -244,7 +250,164 @@

},
onKeyDown: function onKeyDown(event) {
var _this = this;
if (event.target.nodeName.toLowerCase() === 'input') {
return;
}
var keyCode = event.keyCode;
var ctrlKey = event.ctrlKey || event.metaKey;
var _state2 = this.state,
selectedValue = _state2.selectedValue,
hoverValue = _state2.hoverValue,
firstSelectedValue = _state2.firstSelectedValue,
value = _state2.value;
var _props = this.props,
onKeyDown = _props.onKeyDown,
disabledDate = _props.disabledDate;
// Update last time of the picker
var updateHoverPoint = function updateHoverPoint(func) {
// Change hover to make focus in UI
var currentHoverTime = void 0;
var nextHoverTime = void 0;
var nextHoverValue = void 0;
if (!firstSelectedValue) {
currentHoverTime = hoverValue[0] || selectedValue[0] || value[0] || (0, _moment2['default'])();
nextHoverTime = func(currentHoverTime);
nextHoverValue = [nextHoverTime];
_this.fireHoverValueChange(nextHoverValue);
} else {
if (hoverValue.length === 1) {
currentHoverTime = hoverValue[0].clone();
nextHoverTime = func(currentHoverTime);
nextHoverValue = _this.onDayHover(nextHoverTime);
} else {
currentHoverTime = hoverValue[0].isSame(firstSelectedValue, 'day') ? hoverValue[1] : hoverValue[0];
nextHoverTime = func(currentHoverTime);
nextHoverValue = _this.onDayHover(nextHoverTime);
}
}
// Find origin hover time on value index
if (nextHoverValue.length >= 2) {
var miss = nextHoverValue.some(function (ht) {
return !(0, _toTime.includesTime)(value, ht, 'month');
});
if (miss) {
var newValue = nextHoverValue.slice().sort(function (t1, t2) {
return t1.valueOf() - t2.valueOf();
});
if (newValue[0].isSame(newValue[1], 'month')) {
newValue[1] = newValue[0].clone().add(1, 'month');
}
_this.fireValueChange(newValue);
}
} else if (nextHoverValue.length === 1) {
// If only one value, let's keep the origin panel
var oriValueIndex = value.findIndex(function (time) {
return time.isSame(currentHoverTime, 'month');
});
if (oriValueIndex === -1) oriValueIndex = 0;
if (value.every(function (time) {
return !time.isSame(nextHoverTime, 'month');
})) {
var _newValue = value.slice();
_newValue[oriValueIndex] = nextHoverTime.clone();
_this.fireValueChange(_newValue);
}
}
event.preventDefault();
return nextHoverTime;
};
switch (keyCode) {
case _KeyCode2['default'].DOWN:
updateHoverPoint(function (time) {
return (0, _toTime.goTime)(time, 1, 'weeks');
});
return;
case _KeyCode2['default'].UP:
updateHoverPoint(function (time) {
return (0, _toTime.goTime)(time, -1, 'weeks');
});
return;
case _KeyCode2['default'].LEFT:
if (ctrlKey) {
updateHoverPoint(function (time) {
return (0, _toTime.goTime)(time, -1, 'years');
});
} else {
updateHoverPoint(function (time) {
return (0, _toTime.goTime)(time, -1, 'days');
});
}
return;
case _KeyCode2['default'].RIGHT:
if (ctrlKey) {
updateHoverPoint(function (time) {
return (0, _toTime.goTime)(time, 1, 'years');
});
} else {
updateHoverPoint(function (time) {
return (0, _toTime.goTime)(time, 1, 'days');
});
}
return;
case _KeyCode2['default'].HOME:
updateHoverPoint(function (time) {
return (0, _toTime.goStartMonth)(time);
});
return;
case _KeyCode2['default'].END:
updateHoverPoint(function (time) {
return (0, _toTime.goEndMonth)(time);
});
return;
case _KeyCode2['default'].PAGE_DOWN:
updateHoverPoint(function (time) {
return (0, _toTime.goTime)(time, 1, 'month');
});
return;
case _KeyCode2['default'].PAGE_UP:
updateHoverPoint(function (time) {
return (0, _toTime.goTime)(time, -1, 'month');
});
return;
case _KeyCode2['default'].ENTER:
{
var lastValue = void 0;
if (hoverValue.length === 0) {
lastValue = updateHoverPoint(function (time) {
return time;
});
} else if (hoverValue.length === 1) {
lastValue = hoverValue[0];
} else {
lastValue = hoverValue[0].isSame(firstSelectedValue, 'day') ? hoverValue[1] : hoverValue[0];
}
if (lastValue && (!disabledDate || !disabledDate(lastValue))) {
this.onSelect(lastValue);
}
event.preventDefault();
return;
}
default:
if (onKeyDown) {
onKeyDown(event);
}
}
},
onDayHover: function onDayHover(value) {
var hoverValue = [];
var _state2 = this.state,
selectedValue = _state2.selectedValue,
firstSelectedValue = _state2.firstSelectedValue;
var _state3 = this.state,
selectedValue = _state3.selectedValue,
firstSelectedValue = _state3.firstSelectedValue;
var type = this.props.type;

@@ -258,3 +421,6 @@

if (!firstSelectedValue) {
return;
if (this.state.hoverValue.length) {
this.setState({ hoverValue: [] });
}
return hoverValue;
}

@@ -264,2 +430,4 @@ hoverValue = this.compare(value, firstSelectedValue) < 0 ? [value, firstSelectedValue] : [firstSelectedValue, value];

this.fireHoverValueChange(hoverValue);
return hoverValue;
},

@@ -354,6 +522,6 @@ onToday: function onToday() {

getEndValue: function getEndValue() {
var _state3 = this.state,
value = _state3.value,
selectedValue = _state3.selectedValue,
showTimePicker = _state3.showTimePicker;
var _state4 = this.state,
value = _state4.value,
selectedValue = _state4.selectedValue,
showTimePicker = _state4.showTimePicker;

@@ -373,5 +541,5 @@ var endValue = value[1] ? value[1].clone() : value[0].clone().add(1, 'month');

getEndDisableTime: function getEndDisableTime() {
var _state4 = this.state,
selectedValue = _state4.selectedValue,
value = _state4.value;
var _state5 = this.state,
selectedValue = _state5.selectedValue,
value = _state5.value;
var disabledTime = this.props.disabledTime;

@@ -561,2 +729,7 @@

var isClosestMonths = nextMonthOfStart.year() === endValue.year() && nextMonthOfStart.month() === endValue.month();
// console.warn('Render:', selectedValue.map(t => t.format('YYYY-MM-DD')).join(', '));
// console.log('start:', startValue.format('YYYY-MM-DD'));
// console.log('end:', endValue.format('YYYY-MM-DD'));
return _react2['default'].createElement(

@@ -568,3 +741,4 @@ 'div',

style: props.style,
tabIndex: '0'
tabIndex: '0',
onKeyDown: this.onKeyDown
},

@@ -571,0 +745,0 @@ props.renderSidebar(),

{
"name": "rc-calendar",
"version": "9.6.1",
"version": "9.6.2",
"description": "React Calendar",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc