react-datetime
Advanced tools
Comparing version 2.4.0 to 2.5.0
Changelog | ||
========= | ||
## 2.5.0 | ||
* Added pre-commit hook for tests. | ||
* Added the `timeConstraints` prop. | ||
## 2.4.0 | ||
@@ -4,0 +8,0 @@ * Added ES linting. |
@@ -34,2 +34,3 @@ 'use strict'; | ||
inputProps: TYPES.object, | ||
timeConstraints: TYPES.object, | ||
viewMode: TYPES.oneOf(['years', 'months', 'days', 'time']), | ||
@@ -54,2 +55,3 @@ isValidDate: TYPES.func, | ||
timeFormat: true, | ||
timeConstraints: {}, | ||
dateFormat: true, | ||
@@ -189,3 +191,3 @@ strictParsing: true, | ||
onInputKey: function( e ){ | ||
if( e.which === 9 && this.props.closeOnTab ){ | ||
if ( e.which === 9 && this.props.closeOnTab ){ | ||
this.closeCalendar(); | ||
@@ -340,3 +342,3 @@ } | ||
componentProps: { | ||
fromProps: ['value', 'isValidDate', 'renderDay', 'renderMonth', 'renderYear'], | ||
fromProps: ['value', 'isValidDate', 'renderDay', 'renderMonth', 'renderYear', 'timeConstraints'], | ||
fromState: ['viewDate', 'selectedDate', 'updateOn'], | ||
@@ -343,0 +345,0 @@ fromThis: ['setDate', 'setTime', 'showView', 'addTime', 'subtractTime', 'updateSelectedDate', 'localMoment'] |
/* | ||
react-datetime v2.4.0 | ||
react-datetime v2.5.0 | ||
https://github.com/arqex/react-datetime | ||
@@ -62,3 +62,3 @@ MIT: https://github.com/arqex/react-datetime/raw/master/LICENSE | ||
eval("'use strict';\n\nvar assign = __webpack_require__(1),\n\tReact = __webpack_require__(2),\n\tDaysView = __webpack_require__(3),\n\tMonthsView = __webpack_require__(5),\n\tYearsView = __webpack_require__(6),\n\tTimeView = __webpack_require__(7),\n\tmoment = __webpack_require__(4)\n;\n\nvar TYPES = React.PropTypes;\nvar Datetime = React.createClass({\n\tmixins: [\n\t\t__webpack_require__(8)\n\t],\n\tviewComponents: {\n\t\tdays: DaysView,\n\t\tmonths: MonthsView,\n\t\tyears: YearsView,\n\t\ttime: TimeView\n\t},\n\tpropTypes: {\n\t\t// value: TYPES.object | TYPES.string,\n\t\t// defaultValue: TYPES.object | TYPES.string,\n\t\tonFocus: TYPES.func,\n\t\tonBlur: TYPES.func,\n\t\tonChange: TYPES.func,\n\t\tlocale: TYPES.string,\n\t\tinput: TYPES.bool,\n\t\t// dateFormat: TYPES.string | TYPES.bool,\n\t\t// timeFormat: TYPES.string | TYPES.bool,\n\t\tinputProps: TYPES.object,\n\t\tviewMode: TYPES.oneOf(['years', 'months', 'days', 'time']),\n\t\tisValidDate: TYPES.func,\n\t\topen: TYPES.bool,\n\t\tstrictParsing: TYPES.bool,\n\t\tcloseOnSelect: TYPES.bool,\n\t\tcloseOnTab: TYPES.bool\n\t},\n\n\tgetDefaultProps: function() {\n\t\tvar nof = function(){};\n\t\treturn {\n\t\t\tclassName: '',\n\t\t\tdefaultValue: '',\n\t\t\tinputProps: {},\n\t\t\tinput: true,\n\t\t\tonFocus: nof,\n\t\t\tonBlur: nof,\n\t\t\tonChange: nof,\n\t\t\ttimeFormat: true,\n\t\t\tdateFormat: true,\n\t\t\tstrictParsing: true,\n\t\t\tcloseOnSelect: false,\n\t\t\tcloseOnTab: true\n\t\t};\n\t},\n\n\tgetInitialState: function() {\n\t\tvar state = this.getStateFromProps( this.props );\n\n\t\tif ( state.open === undefined )\n\t\t\tstate.open = !this.props.input;\n\n\t\tstate.currentView = this.props.dateFormat ? (this.props.viewMode || state.updateOn || 'days') : 'time';\n\n\t\treturn state;\n\t},\n\n\tgetStateFromProps: function( props ){\n\t\tvar formats = this.getFormats( props ),\n\t\t\tdate = props.value || props.defaultValue,\n\t\t\tselectedDate, viewDate, updateOn\n\t\t;\n\n\t\tif ( date && typeof date === 'string' )\n\t\t\tselectedDate = this.localMoment( date, formats.datetime );\n\t\telse if ( date )\n\t\t\tselectedDate = this.localMoment( date );\n\n\t\tif ( selectedDate && !selectedDate.isValid() )\n\t\t\tselectedDate = null;\n\n\t\tviewDate = selectedDate ?\n\t\t\tselectedDate.clone().startOf('month') :\n\t\t\tthis.localMoment().startOf('month')\n\t\t;\n\n\t\tupdateOn = this.getUpdateOn(formats);\n\n\t\treturn {\n\t\t\tupdateOn: updateOn,\n\t\t\tinputFormat: formats.datetime,\n\t\t\tviewDate: viewDate,\n\t\t\tselectedDate: selectedDate,\n\t\t\tinputValue: selectedDate ? selectedDate.format( formats.datetime ) : (date || ''),\n\t\t\topen: props.open\n\t\t};\n\t},\n\n\tgetUpdateOn: function(formats){\n\t\tif ( formats.date.match(/[lLD]/) ){\n\t\t\treturn 'days';\n\t\t}\n\t\telse if ( formats.date.indexOf('M') !== -1 ){\n\t\t\treturn 'months';\n\t\t}\n\t\telse if ( formats.date.indexOf('Y') !== -1 ){\n\t\t\treturn 'years';\n\t\t}\n\n\t\treturn 'days';\n\t},\n\n\tgetFormats: function( props ){\n\t\tvar formats = {\n\t\t\t\tdate: props.dateFormat || '',\n\t\t\t\ttime: props.timeFormat || ''\n\t\t\t},\n\t\t\tlocale = this.localMoment( props.date ).localeData()\n\t\t;\n\n\t\tif ( formats.date === true ){\n\t\t\tformats.date = locale.longDateFormat('L');\n\t\t}\n\t\telse if ( this.getUpdateOn(formats) !== 'days' ){\n\t\t\tformats.time = '';\n\t\t}\n\n\t\tif ( formats.time === true ){\n\t\t\tformats.time = locale.longDateFormat('LT');\n\t\t}\n\n\t\tformats.datetime = formats.date && formats.time ?\n\t\t\tformats.date + ' ' + formats.time :\n\t\t\tformats.date || formats.time\n\t\t;\n\n\t\treturn formats;\n\t},\n\n\tcomponentWillReceiveProps: function(nextProps) {\n\t\tvar formats = this.getFormats( nextProps ),\n\t\t\tupdate = {}\n\t\t;\n\n\t\tif ( nextProps.value !== this.props.value ){\n\t\t\tupdate = this.getStateFromProps( nextProps );\n\t\t}\n\t\tif ( formats.datetime !== this.getFormats( this.props ).datetime ) {\n\t\t\tupdate.inputFormat = formats.datetime;\n\t\t}\n\n\t\tif ( update.open === undefined ){\n\t\t\tif ( this.props.closeOnSelect && this.state.currentView !== 'time' ){\n\t\t\t\tupdate.open = false;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tupdate.open = this.state.open;\n\t\t\t}\n\t\t}\n\n\t\tthis.setState( update );\n\t},\n\n\tonInputChange: function( e ) {\n\t\tvar value = e.target === null ? e : e.target.value,\n\t\t\tlocalMoment = this.localMoment( value, this.state.inputFormat ),\n\t\t\tupdate = { inputValue: value }\n\t\t;\n\n\t\tif ( localMoment.isValid() && !this.props.value ) {\n\t\t\tupdate.selectedDate = localMoment;\n\t\t\tupdate.viewDate = localMoment.clone().startOf('month');\n\t\t}\n\t\telse {\n\t\t\tupdate.selectedDate = null;\n\t\t}\n\n\t\treturn this.setState( update, function() {\n\t\t\treturn this.props.onChange( localMoment.isValid() ? localMoment : this.state.inputValue );\n\t\t});\n\t},\n\n\tonInputKey: function( e ){\n\t\tif( e.which === 9 && this.props.closeOnTab ){\n\t\t\tthis.closeCalendar();\n\t\t}\n\t},\n\n\tshowView: function( view ){\n\t\tvar me = this;\n\t\treturn function(){\n\t\t\tme.setState({ currentView: view });\n\t\t};\n\t},\n\n\tsetDate: function( type ){\n\t\tvar me = this,\n\t\t\tnextViews = {\n\t\t\t\tmonth: 'days',\n\t\t\t\tyear: 'months'\n\t\t\t}\n\t\t;\n\t\treturn function( e ){\n\t\t\tme.setState({\n\t\t\t\tviewDate: me.state.viewDate.clone()[ type ]( parseInt(e.target.getAttribute('data-value'), 10) ).startOf( type ),\n\t\t\t\tcurrentView: nextViews[ type ]\n\t\t\t});\n\t\t};\n\t},\n\n\taddTime: function( amount, type, toSelected ){\n\t\treturn this.updateTime( 'add', amount, type, toSelected );\n\t},\n\n\tsubtractTime: function( amount, type, toSelected ){\n\t\treturn this.updateTime( 'subtract', amount, type, toSelected );\n\t},\n\n\tupdateTime: function( op, amount, type, toSelected ){\n\t\tvar me = this;\n\n\t\treturn function(){\n\t\t\tvar update = {},\n\t\t\t\tdate = toSelected ? 'selectedDate' : 'viewDate'\n\t\t\t;\n\n\t\t\tupdate[ date ] = me.state[ date ].clone()[ op ]( amount, type );\n\n\t\t\tme.setState( update );\n\t\t};\n\t},\n\n\tallowedSetTime: ['hours', 'minutes', 'seconds', 'milliseconds'],\n\tsetTime: function( type, value ){\n\t\tvar index = this.allowedSetTime.indexOf( type ) + 1,\n\t\t\tstate = this.state,\n\t\t\tdate = (state.selectedDate || state.viewDate).clone(),\n\t\t\tnextType\n\t\t;\n\n\t\t// It is needed to set all the time properties\n\t\t// to not to reset the time\n\t\tdate[ type ]( value );\n\t\tfor (; index < this.allowedSetTime.length; index++) {\n\t\t\tnextType = this.allowedSetTime[index];\n\t\t\tdate[ nextType ]( date[nextType]() );\n\t\t}\n\n\t\tif ( !this.props.value ){\n\t\t\tthis.setState({\n\t\t\t\tselectedDate: date,\n\t\t\t\tinputValue: date.format( state.inputFormat )\n\t\t\t});\n\t\t}\n\t\tthis.props.onChange( date );\n\t},\n\n\tupdateSelectedDate: function( e, close ) {\n\t\tvar target = e.target,\n\t\t\tmodifier = 0,\n\t\t\tviewDate = this.state.viewDate,\n\t\t\tcurrentDate = this.state.selectedDate || viewDate,\n\t\t\tdate\n ;\n\n\t\tif (target.className.indexOf('rdtDay') !== -1){\n\t\t\tif (target.className.indexOf('rdtNew') !== -1)\n\t\t\t\tmodifier = 1;\n\t\t\telse if (target.className.indexOf('rdtOld') !== -1)\n\t\t\t\tmodifier = -1;\n\n\t\t\tdate = viewDate.clone()\n\t\t\t\t.month( viewDate.month() + modifier )\n\t\t\t\t.date( parseInt( target.getAttribute('data-value'), 10 ) );\n\t\t} else if (target.className.indexOf('rdtMonth') !== -1){\n\t\t\tdate = viewDate.clone()\n\t\t\t\t.month( parseInt( target.getAttribute('data-value'), 10 ) )\n\t\t\t\t.date( currentDate.date() );\n\t\t} else if (target.className.indexOf('rdtYear') !== -1){\n\t\t\tdate = viewDate.clone()\n\t\t\t\t.month( currentDate.month() )\n\t\t\t\t.date( currentDate.date() )\n\t\t\t\t.year( parseInt( target.getAttribute('data-value'), 10 ) );\n\t\t}\n\n\t\tdate.hours( currentDate.hours() )\n\t\t\t.minutes( currentDate.minutes() )\n\t\t\t.seconds( currentDate.seconds() )\n\t\t\t.milliseconds( currentDate.milliseconds() );\n\n\t\tif ( !this.props.value ){\n\t\t\tthis.setState({\n\t\t\t\tselectedDate: date,\n\t\t\t\tviewDate: date.clone().startOf('month'),\n\t\t\t\tinputValue: date.format( this.state.inputFormat ),\n\t\t\t\topen: !(this.props.closeOnSelect && close )\n\t\t\t});\n\t\t} else {\n\t\t\tif (this.props.closeOnSelect && close) {\n\t\t\t\tthis.closeCalendar();\n\t\t\t}\n\t\t}\n\n\t\tthis.props.onChange( date );\n\t},\n\n\topenCalendar: function() {\n\t\tif (!this.state.open) {\n\t\t\tthis.props.onFocus();\n\t\t\tthis.setState({ open: true });\n\t\t}\n\t},\n\n\tcloseCalendar: function() {\n\t\tthis.setState({ open: false });\n\t\tthis.props.onBlur( this.state.selectedDate || this.state.inputValue );\n\t},\n\n\thandleClickOutside: function(){\n\t\tif ( this.props.input && this.state.open && !this.props.open ){\n\t\t\tthis.setState({ open: false });\n\t\t\tthis.props.onBlur( this.state.selectedDate || this.state.inputValue );\n\t\t}\n\t},\n\n\tlocalMoment: function( date, format ){\n\t\tvar m = moment( date, format, this.props.strictParsing );\n\t\tif ( this.props.locale )\n\t\t\tm.locale( this.props.locale );\n\t\treturn m;\n\t},\n\n\tcomponentProps: {\n\t\tfromProps: ['value', 'isValidDate', 'renderDay', 'renderMonth', 'renderYear'],\n\t\tfromState: ['viewDate', 'selectedDate', 'updateOn'],\n\t\tfromThis: ['setDate', 'setTime', 'showView', 'addTime', 'subtractTime', 'updateSelectedDate', 'localMoment']\n\t},\n\n\tgetComponentProps: function(){\n\t\tvar me = this,\n\t\t\tformats = this.getFormats( this.props ),\n\t\t\tprops = {dateFormat: formats.date, timeFormat: formats.time}\n\t\t;\n\n\t\tthis.componentProps.fromProps.forEach( function( name ){\n\t\t\tprops[ name ] = me.props[ name ];\n\t\t});\n\t\tthis.componentProps.fromState.forEach( function( name ){\n\t\t\tprops[ name ] = me.state[ name ];\n\t\t});\n\t\tthis.componentProps.fromThis.forEach( function( name ){\n\t\t\tprops[ name ] = me[ name ];\n\t\t});\n\n\t\treturn props;\n\t},\n\n\trender: function() {\n\t\tvar Component = this.viewComponents[ this.state.currentView ],\n\t\t\tDOM = React.DOM,\n\t\t\tclassName = 'rdt ' + this.props.className,\n\t\t\tchildren = []\n\t\t;\n\n\t\tif ( this.props.input ){\n\t\t\tchildren = [ DOM.input( assign({\n\t\t\t\tkey: 'i',\n\t\t\t\ttype:'text',\n\t\t\t\tclassName: 'form-control',\n\t\t\t\tonFocus: this.openCalendar,\n\t\t\t\tonChange: this.onInputChange,\n\t\t\t\tonKeyDown: this.onInputKey,\n\t\t\t\tvalue: this.state.inputValue\n\t\t\t}, this.props.inputProps ))];\n\t\t} else {\n\t\t\tclassName += ' rdtStatic';\n\t\t}\n\n\t\tif ( this.state.open )\n\t\t\tclassName += ' rdtOpen';\n\n\t\treturn DOM.div({className: className}, children.concat(\n\t\t\tDOM.div(\n\t\t\t\t{ key: 'dt', className: 'rdtPicker' },\n\t\t\t\tReact.createElement( Component, this.getComponentProps())\n\t\t\t)\n\t\t));\n\t}\n});\n\n// Make moment accessible through the Datetime class\nDatetime.moment = moment;\n\nmodule.exports = Datetime;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./Datetime.js\n ** module id = 0\n ** module chunks = 0\n **/\n//# sourceURL=webpack:///./Datetime.js?"); | ||
eval("'use strict';\n\nvar assign = __webpack_require__(1),\n\tReact = __webpack_require__(2),\n\tDaysView = __webpack_require__(3),\n\tMonthsView = __webpack_require__(5),\n\tYearsView = __webpack_require__(6),\n\tTimeView = __webpack_require__(7),\n\tmoment = __webpack_require__(4)\n;\n\nvar TYPES = React.PropTypes;\nvar Datetime = React.createClass({\n\tmixins: [\n\t\t__webpack_require__(8)\n\t],\n\tviewComponents: {\n\t\tdays: DaysView,\n\t\tmonths: MonthsView,\n\t\tyears: YearsView,\n\t\ttime: TimeView\n\t},\n\tpropTypes: {\n\t\t// value: TYPES.object | TYPES.string,\n\t\t// defaultValue: TYPES.object | TYPES.string,\n\t\tonFocus: TYPES.func,\n\t\tonBlur: TYPES.func,\n\t\tonChange: TYPES.func,\n\t\tlocale: TYPES.string,\n\t\tinput: TYPES.bool,\n\t\t// dateFormat: TYPES.string | TYPES.bool,\n\t\t// timeFormat: TYPES.string | TYPES.bool,\n\t\tinputProps: TYPES.object,\n\t\ttimeConstraints: TYPES.object,\n\t\tviewMode: TYPES.oneOf(['years', 'months', 'days', 'time']),\n\t\tisValidDate: TYPES.func,\n\t\topen: TYPES.bool,\n\t\tstrictParsing: TYPES.bool,\n\t\tcloseOnSelect: TYPES.bool,\n\t\tcloseOnTab: TYPES.bool\n\t},\n\n\tgetDefaultProps: function() {\n\t\tvar nof = function(){};\n\t\treturn {\n\t\t\tclassName: '',\n\t\t\tdefaultValue: '',\n\t\t\tinputProps: {},\n\t\t\tinput: true,\n\t\t\tonFocus: nof,\n\t\t\tonBlur: nof,\n\t\t\tonChange: nof,\n\t\t\ttimeFormat: true,\n\t\t\ttimeConstraints: {},\n\t\t\tdateFormat: true,\n\t\t\tstrictParsing: true,\n\t\t\tcloseOnSelect: false,\n\t\t\tcloseOnTab: true\n\t\t};\n\t},\n\n\tgetInitialState: function() {\n\t\tvar state = this.getStateFromProps( this.props );\n\n\t\tif ( state.open === undefined )\n\t\t\tstate.open = !this.props.input;\n\n\t\tstate.currentView = this.props.dateFormat ? (this.props.viewMode || state.updateOn || 'days') : 'time';\n\n\t\treturn state;\n\t},\n\n\tgetStateFromProps: function( props ){\n\t\tvar formats = this.getFormats( props ),\n\t\t\tdate = props.value || props.defaultValue,\n\t\t\tselectedDate, viewDate, updateOn\n\t\t;\n\n\t\tif ( date && typeof date === 'string' )\n\t\t\tselectedDate = this.localMoment( date, formats.datetime );\n\t\telse if ( date )\n\t\t\tselectedDate = this.localMoment( date );\n\n\t\tif ( selectedDate && !selectedDate.isValid() )\n\t\t\tselectedDate = null;\n\n\t\tviewDate = selectedDate ?\n\t\t\tselectedDate.clone().startOf('month') :\n\t\t\tthis.localMoment().startOf('month')\n\t\t;\n\n\t\tupdateOn = this.getUpdateOn(formats);\n\n\t\treturn {\n\t\t\tupdateOn: updateOn,\n\t\t\tinputFormat: formats.datetime,\n\t\t\tviewDate: viewDate,\n\t\t\tselectedDate: selectedDate,\n\t\t\tinputValue: selectedDate ? selectedDate.format( formats.datetime ) : (date || ''),\n\t\t\topen: props.open\n\t\t};\n\t},\n\n\tgetUpdateOn: function(formats){\n\t\tif ( formats.date.match(/[lLD]/) ){\n\t\t\treturn 'days';\n\t\t}\n\t\telse if ( formats.date.indexOf('M') !== -1 ){\n\t\t\treturn 'months';\n\t\t}\n\t\telse if ( formats.date.indexOf('Y') !== -1 ){\n\t\t\treturn 'years';\n\t\t}\n\n\t\treturn 'days';\n\t},\n\n\tgetFormats: function( props ){\n\t\tvar formats = {\n\t\t\t\tdate: props.dateFormat || '',\n\t\t\t\ttime: props.timeFormat || ''\n\t\t\t},\n\t\t\tlocale = this.localMoment( props.date ).localeData()\n\t\t;\n\n\t\tif ( formats.date === true ){\n\t\t\tformats.date = locale.longDateFormat('L');\n\t\t}\n\t\telse if ( this.getUpdateOn(formats) !== 'days' ){\n\t\t\tformats.time = '';\n\t\t}\n\n\t\tif ( formats.time === true ){\n\t\t\tformats.time = locale.longDateFormat('LT');\n\t\t}\n\n\t\tformats.datetime = formats.date && formats.time ?\n\t\t\tformats.date + ' ' + formats.time :\n\t\t\tformats.date || formats.time\n\t\t;\n\n\t\treturn formats;\n\t},\n\n\tcomponentWillReceiveProps: function(nextProps) {\n\t\tvar formats = this.getFormats( nextProps ),\n\t\t\tupdate = {}\n\t\t;\n\n\t\tif ( nextProps.value !== this.props.value ){\n\t\t\tupdate = this.getStateFromProps( nextProps );\n\t\t}\n\t\tif ( formats.datetime !== this.getFormats( this.props ).datetime ) {\n\t\t\tupdate.inputFormat = formats.datetime;\n\t\t}\n\n\t\tif ( update.open === undefined ){\n\t\t\tif ( this.props.closeOnSelect && this.state.currentView !== 'time' ){\n\t\t\t\tupdate.open = false;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tupdate.open = this.state.open;\n\t\t\t}\n\t\t}\n\n\t\tthis.setState( update );\n\t},\n\n\tonInputChange: function( e ) {\n\t\tvar value = e.target === null ? e : e.target.value,\n\t\t\tlocalMoment = this.localMoment( value, this.state.inputFormat ),\n\t\t\tupdate = { inputValue: value }\n\t\t;\n\n\t\tif ( localMoment.isValid() && !this.props.value ) {\n\t\t\tupdate.selectedDate = localMoment;\n\t\t\tupdate.viewDate = localMoment.clone().startOf('month');\n\t\t}\n\t\telse {\n\t\t\tupdate.selectedDate = null;\n\t\t}\n\n\t\treturn this.setState( update, function() {\n\t\t\treturn this.props.onChange( localMoment.isValid() ? localMoment : this.state.inputValue );\n\t\t});\n\t},\n\n\tonInputKey: function( e ){\n\t\tif ( e.which === 9 && this.props.closeOnTab ){\n\t\t\tthis.closeCalendar();\n\t\t}\n\t},\n\n\tshowView: function( view ){\n\t\tvar me = this;\n\t\treturn function(){\n\t\t\tme.setState({ currentView: view });\n\t\t};\n\t},\n\n\tsetDate: function( type ){\n\t\tvar me = this,\n\t\t\tnextViews = {\n\t\t\t\tmonth: 'days',\n\t\t\t\tyear: 'months'\n\t\t\t}\n\t\t;\n\t\treturn function( e ){\n\t\t\tme.setState({\n\t\t\t\tviewDate: me.state.viewDate.clone()[ type ]( parseInt(e.target.getAttribute('data-value'), 10) ).startOf( type ),\n\t\t\t\tcurrentView: nextViews[ type ]\n\t\t\t});\n\t\t};\n\t},\n\n\taddTime: function( amount, type, toSelected ){\n\t\treturn this.updateTime( 'add', amount, type, toSelected );\n\t},\n\n\tsubtractTime: function( amount, type, toSelected ){\n\t\treturn this.updateTime( 'subtract', amount, type, toSelected );\n\t},\n\n\tupdateTime: function( op, amount, type, toSelected ){\n\t\tvar me = this;\n\n\t\treturn function(){\n\t\t\tvar update = {},\n\t\t\t\tdate = toSelected ? 'selectedDate' : 'viewDate'\n\t\t\t;\n\n\t\t\tupdate[ date ] = me.state[ date ].clone()[ op ]( amount, type );\n\n\t\t\tme.setState( update );\n\t\t};\n\t},\n\n\tallowedSetTime: ['hours', 'minutes', 'seconds', 'milliseconds'],\n\tsetTime: function( type, value ){\n\t\tvar index = this.allowedSetTime.indexOf( type ) + 1,\n\t\t\tstate = this.state,\n\t\t\tdate = (state.selectedDate || state.viewDate).clone(),\n\t\t\tnextType\n\t\t;\n\n\t\t// It is needed to set all the time properties\n\t\t// to not to reset the time\n\t\tdate[ type ]( value );\n\t\tfor (; index < this.allowedSetTime.length; index++) {\n\t\t\tnextType = this.allowedSetTime[index];\n\t\t\tdate[ nextType ]( date[nextType]() );\n\t\t}\n\n\t\tif ( !this.props.value ){\n\t\t\tthis.setState({\n\t\t\t\tselectedDate: date,\n\t\t\t\tinputValue: date.format( state.inputFormat )\n\t\t\t});\n\t\t}\n\t\tthis.props.onChange( date );\n\t},\n\n\tupdateSelectedDate: function( e, close ) {\n\t\tvar target = e.target,\n\t\t\tmodifier = 0,\n\t\t\tviewDate = this.state.viewDate,\n\t\t\tcurrentDate = this.state.selectedDate || viewDate,\n\t\t\tdate\n ;\n\n\t\tif (target.className.indexOf('rdtDay') !== -1){\n\t\t\tif (target.className.indexOf('rdtNew') !== -1)\n\t\t\t\tmodifier = 1;\n\t\t\telse if (target.className.indexOf('rdtOld') !== -1)\n\t\t\t\tmodifier = -1;\n\n\t\t\tdate = viewDate.clone()\n\t\t\t\t.month( viewDate.month() + modifier )\n\t\t\t\t.date( parseInt( target.getAttribute('data-value'), 10 ) );\n\t\t} else if (target.className.indexOf('rdtMonth') !== -1){\n\t\t\tdate = viewDate.clone()\n\t\t\t\t.month( parseInt( target.getAttribute('data-value'), 10 ) )\n\t\t\t\t.date( currentDate.date() );\n\t\t} else if (target.className.indexOf('rdtYear') !== -1){\n\t\t\tdate = viewDate.clone()\n\t\t\t\t.month( currentDate.month() )\n\t\t\t\t.date( currentDate.date() )\n\t\t\t\t.year( parseInt( target.getAttribute('data-value'), 10 ) );\n\t\t}\n\n\t\tdate.hours( currentDate.hours() )\n\t\t\t.minutes( currentDate.minutes() )\n\t\t\t.seconds( currentDate.seconds() )\n\t\t\t.milliseconds( currentDate.milliseconds() );\n\n\t\tif ( !this.props.value ){\n\t\t\tthis.setState({\n\t\t\t\tselectedDate: date,\n\t\t\t\tviewDate: date.clone().startOf('month'),\n\t\t\t\tinputValue: date.format( this.state.inputFormat ),\n\t\t\t\topen: !(this.props.closeOnSelect && close )\n\t\t\t});\n\t\t} else {\n\t\t\tif (this.props.closeOnSelect && close) {\n\t\t\t\tthis.closeCalendar();\n\t\t\t}\n\t\t}\n\n\t\tthis.props.onChange( date );\n\t},\n\n\topenCalendar: function() {\n\t\tif (!this.state.open) {\n\t\t\tthis.props.onFocus();\n\t\t\tthis.setState({ open: true });\n\t\t}\n\t},\n\n\tcloseCalendar: function() {\n\t\tthis.setState({ open: false });\n\t\tthis.props.onBlur( this.state.selectedDate || this.state.inputValue );\n\t},\n\n\thandleClickOutside: function(){\n\t\tif ( this.props.input && this.state.open && !this.props.open ){\n\t\t\tthis.setState({ open: false });\n\t\t\tthis.props.onBlur( this.state.selectedDate || this.state.inputValue );\n\t\t}\n\t},\n\n\tlocalMoment: function( date, format ){\n\t\tvar m = moment( date, format, this.props.strictParsing );\n\t\tif ( this.props.locale )\n\t\t\tm.locale( this.props.locale );\n\t\treturn m;\n\t},\n\n\tcomponentProps: {\n\t\tfromProps: ['value', 'isValidDate', 'renderDay', 'renderMonth', 'renderYear', 'timeConstraints'],\n\t\tfromState: ['viewDate', 'selectedDate', 'updateOn'],\n\t\tfromThis: ['setDate', 'setTime', 'showView', 'addTime', 'subtractTime', 'updateSelectedDate', 'localMoment']\n\t},\n\n\tgetComponentProps: function(){\n\t\tvar me = this,\n\t\t\tformats = this.getFormats( this.props ),\n\t\t\tprops = {dateFormat: formats.date, timeFormat: formats.time}\n\t\t;\n\n\t\tthis.componentProps.fromProps.forEach( function( name ){\n\t\t\tprops[ name ] = me.props[ name ];\n\t\t});\n\t\tthis.componentProps.fromState.forEach( function( name ){\n\t\t\tprops[ name ] = me.state[ name ];\n\t\t});\n\t\tthis.componentProps.fromThis.forEach( function( name ){\n\t\t\tprops[ name ] = me[ name ];\n\t\t});\n\n\t\treturn props;\n\t},\n\n\trender: function() {\n\t\tvar Component = this.viewComponents[ this.state.currentView ],\n\t\t\tDOM = React.DOM,\n\t\t\tclassName = 'rdt ' + this.props.className,\n\t\t\tchildren = []\n\t\t;\n\n\t\tif ( this.props.input ){\n\t\t\tchildren = [ DOM.input( assign({\n\t\t\t\tkey: 'i',\n\t\t\t\ttype:'text',\n\t\t\t\tclassName: 'form-control',\n\t\t\t\tonFocus: this.openCalendar,\n\t\t\t\tonChange: this.onInputChange,\n\t\t\t\tonKeyDown: this.onInputKey,\n\t\t\t\tvalue: this.state.inputValue\n\t\t\t}, this.props.inputProps ))];\n\t\t} else {\n\t\t\tclassName += ' rdtStatic';\n\t\t}\n\n\t\tif ( this.state.open )\n\t\t\tclassName += ' rdtOpen';\n\n\t\treturn DOM.div({className: className}, children.concat(\n\t\t\tDOM.div(\n\t\t\t\t{ key: 'dt', className: 'rdtPicker' },\n\t\t\t\tReact.createElement( Component, this.getComponentProps())\n\t\t\t)\n\t\t));\n\t}\n});\n\n// Make moment accessible through the Datetime class\nDatetime.moment = moment;\n\nmodule.exports = Datetime;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./Datetime.js\n ** module id = 0\n ** module chunks = 0\n **/\n//# sourceURL=webpack:///./Datetime.js?"); | ||
@@ -105,3 +105,3 @@ /***/ }, | ||
eval("'use strict';\n\nvar React = __webpack_require__(2);\n\nvar DOM = React.DOM;\nvar DateTimePickerTime = React.createClass({\n\tgetInitialState: function(){\n\t\treturn this.calculateState( this.props );\n\t},\n\tcalculateState: function( props ){\n\t\tvar date = props.selectedDate || props.viewDate,\n\t\t\tformat = props.timeFormat,\n\t\t\tcounters = []\n\t\t;\n\n\t\tif ( format.indexOf('H') !== -1 || format.indexOf('h') !== -1 ){\n\t\t\tcounters.push('hours');\n\t\t\tif ( format.indexOf('m') !== -1 ){\n\t\t\t\tcounters.push('minutes');\n\t\t\t\tif ( format.indexOf('s') !== -1 ){\n\t\t\t\t\tcounters.push('seconds');\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tvar daypart = false;\n\t\tif ( this.props.timeFormat.indexOf(' A') !== -1 && this.state !== null ){\n\t\t\tdaypart = ( this.state.hours >= 12 ) ? 'PM' : 'AM';\n\t\t}\n\n\t\treturn {\n\t\t\thours: date.format('H'),\n\t\t\tminutes: date.format('mm'),\n\t\t\tseconds: date.format('ss'),\n\t\t\tmilliseconds: date.format('SSS'),\n\t\t\tdaypart: daypart,\n\t\t\tcounters: counters\n\t\t};\n\t},\n\trenderCounter: function( type ){\n\t\tif (type !== 'daypart') {\n\t\t\tvar value = this.state[ type ];\n\t\t\tif (type === 'hours' && this.props.timeFormat.indexOf(' A') !== -1 && value > 12) {\n\t\t\t\tif (value > 12){\n\t\t\t\t\tvalue = value - 12;\n\t\t\t\t}\n\t\t\t\tif (value === 0) {\n\t\t\t\t\tvalue = 12;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn DOM.div({ key: type, className: 'rdtCounter'}, [\n\t\t\t\tDOM.span({ key:'up', className: 'rdtBtn', onMouseDown: this.onStartClicking( 'increase', type ) }, '▲' ),\n\t\t\t\tDOM.div({ key:'c', className: 'rdtCount' }, value ),\n\t\t\t\tDOM.span({ key:'do', className: 'rdtBtn', onMouseDown: this.onStartClicking( 'decrease', type ) }, '▼' )\n\t\t\t]);\n\t\t}\n\t\treturn '';\n\t},\n\trender: function() {\n\t\tvar me = this,\n\t\t\tcounters = []\n\t\t;\n\n\t\tthis.state.counters.forEach( function(c){\n\t\t\tif ( counters.length )\n\t\t\t\tcounters.push( DOM.div( {key: 'sep' + counters.length, className: 'rdtCounterSeparator' }, ':' ));\n\t\t\tcounters.push( me.renderCounter( c ) );\n\t\t});\n\n\t\tif (this.state.daypart !== false) {\n\t\t\tcounters.push(DOM.div({ key: this.state.daypart, className: 'rdtDayPart'}, this.state.daypart ));\n\t\t}\n\n\t\tif ( this.state.counters.length === 3 && this.props.timeFormat.indexOf('S') !== -1 ){\n\t\t\tcounters.push( DOM.div( {className: 'rdtCounterSeparator', key: 'sep5' }, ':' ));\n\t\t\tcounters.push(\n\t\t\t\tDOM.div( {className: 'rdtCounter rdtMilli', key:'m'},\n\t\t\t\t\tDOM.input({ value: this.state.milliseconds, type: 'text', onChange: this.updateMilli })\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t}\n\n\t\treturn DOM.div( {className: 'rdtTime'},\n\t\t\tDOM.table( {}, [\n\t\t\t\tthis.renderHeader(),\n\t\t\t\tDOM.tbody({key: 'b'}, DOM.tr({}, DOM.td({},\n\t\t\t\t\tDOM.div({ className: 'rdtCounters' }, counters )\n\t\t\t\t)))\n\t\t\t])\n\t\t);\n\t},\n\tcomponentWillReceiveProps: function( nextProps ){\n\t\tthis.setState( this.calculateState( nextProps ) );\n\t},\n\tupdateMilli: function( e ){\n\t\tvar milli = parseInt( e.target.value, 10 );\n\t\tif ( milli === e.target.value && milli >= 0 && milli < 1000 ){\n\t\t\tthis.props.setTime( 'milliseconds', milli );\n\t\t\tthis.setState({ milliseconds: milli });\n\t\t}\n\t},\n\trenderHeader: function(){\n\t\tif ( !this.props.dateFormat )\n\t\t\treturn null;\n\n\t\tvar date = this.props.selectedDate || this.props.viewDate;\n\t\treturn DOM.thead({ key: 'h'}, DOM.tr({},\n\t\t\tDOM.th( {className: 'rdtSwitch', colSpan: 4, onClick: this.props.showView('days')}, date.format( this.props.dateFormat ) )\n\t\t));\n\t},\n\tonStartClicking: function( action, type ){\n\t\tvar me = this;\n\n\t\treturn function(){\n\t\t\tvar update = {};\n\t\t\tupdate[ type ] = me[ action ]( type );\n\t\t\tme.setState( update );\n\n\t\t\tme.timer = setTimeout( function(){\n\t\t\t\tme.increaseTimer = setInterval( function(){\n\t\t\t\t\tupdate[ type ] = me[ action ]( type );\n\t\t\t\t\tme.setState( update );\n\t\t\t\t}, 70);\n\t\t\t}, 500);\n\n\t\t\tme.mouseUpListener = function(){\n\t\t\t\tclearTimeout( me.timer );\n\t\t\t\tclearInterval( me.increaseTimer );\n\t\t\t\tme.props.setTime( type, me.state[ type ] );\n\t\t\t\tdocument.body.removeEventListener('mouseup', me.mouseUpListener);\n\t\t\t};\n\n\t\t\tdocument.body.addEventListener('mouseup', me.mouseUpListener);\n\t\t};\n\t},\n\n\tmaxValues: {\n\t\thours: 23,\n\t\tminutes: 59,\n\t\tseconds: 59,\n\t\tmilliseconds: 999\n\t},\n\tpadValues: {\n\t\thours: 1,\n\t\tminutes: 2,\n\t\tseconds: 2,\n\t\tmilliseconds: 3\n\t},\n\tincrease: function( type ){\n\t\tvar value = parseInt(this.state[ type ], 10) + 1;\n\t\tif ( value > this.maxValues[ type ] )\n\t\t\tvalue = 0;\n\t\treturn this.pad( type, value );\n\t},\n\tdecrease: function( type ){\n\t\tvar value = parseInt(this.state[ type ], 10) - 1;\n\t\tif ( value < 0 )\n\t\t\tvalue = this.maxValues[ type ];\n\t\treturn this.pad( type, value );\n\t},\n\tpad: function( type, value ){\n\t\tvar str = value + '';\n\t\twhile ( str.length < this.padValues[ type ] )\n\t\t\tstr = '0' + str;\n\t\treturn str;\n\t}\n});\n\nmodule.exports = DateTimePickerTime;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./src/TimeView.js\n ** module id = 7\n ** module chunks = 0\n **/\n//# sourceURL=webpack:///./src/TimeView.js?"); | ||
eval("'use strict';\n\nvar React = __webpack_require__(2),\n\tassign = __webpack_require__(1);\n\nvar DOM = React.DOM;\nvar DateTimePickerTime = React.createClass({\n\tgetInitialState: function(){\n\t\treturn this.calculateState( this.props );\n\t},\n\tcalculateState: function( props ){\n\t\tvar date = props.selectedDate || props.viewDate,\n\t\t\tformat = props.timeFormat,\n\t\t\tcounters = []\n\t\t;\n\n\t\tif ( format.indexOf('H') !== -1 || format.indexOf('h') !== -1 ){\n\t\t\tcounters.push('hours');\n\t\t\tif ( format.indexOf('m') !== -1 ){\n\t\t\t\tcounters.push('minutes');\n\t\t\t\tif ( format.indexOf('s') !== -1 ){\n\t\t\t\t\tcounters.push('seconds');\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tvar daypart = false;\n\t\tif ( this.props.timeFormat.indexOf(' A') !== -1 && this.state !== null ){\n\t\t\tdaypart = ( this.state.hours >= 12 ) ? 'PM' : 'AM';\n\t\t}\n\n\t\treturn {\n\t\t\thours: date.format('H'),\n\t\t\tminutes: date.format('mm'),\n\t\t\tseconds: date.format('ss'),\n\t\t\tmilliseconds: date.format('SSS'),\n\t\t\tdaypart: daypart,\n\t\t\tcounters: counters\n\t\t};\n\t},\n\trenderCounter: function( type ){\n\t\tif (type !== 'daypart') {\n\t\t\tvar value = this.state[ type ];\n\t\t\tif (type === 'hours' && this.props.timeFormat.indexOf(' A') !== -1 && value > 12) {\n\t\t\t\tif (value > 12){\n\t\t\t\t\tvalue = value - 12;\n\t\t\t\t}\n\t\t\t\tif (value === 0) {\n\t\t\t\t\tvalue = 12;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn DOM.div({ key: type, className: 'rdtCounter'}, [\n\t\t\t\tDOM.span({ key:'up', className: 'rdtBtn', onMouseDown: this.onStartClicking( 'increase', type ) }, '▲' ),\n\t\t\t\tDOM.div({ key:'c', className: 'rdtCount' }, value ),\n\t\t\t\tDOM.span({ key:'do', className: 'rdtBtn', onMouseDown: this.onStartClicking( 'decrease', type ) }, '▼' )\n\t\t\t]);\n\t\t}\n\t\treturn '';\n\t},\n\trender: function() {\n\t\tvar me = this,\n\t\t\tcounters = []\n\t\t;\n\n\t\tthis.state.counters.forEach( function(c){\n\t\t\tif ( counters.length )\n\t\t\t\tcounters.push( DOM.div( {key: 'sep' + counters.length, className: 'rdtCounterSeparator' }, ':' ));\n\t\t\tcounters.push( me.renderCounter( c ) );\n\t\t});\n\n\t\tif (this.state.daypart !== false) {\n\t\t\tcounters.push(DOM.div({ key: this.state.daypart, className: 'rdtDayPart'}, this.state.daypart ));\n\t\t}\n\n\t\tif ( this.state.counters.length === 3 && this.props.timeFormat.indexOf('S') !== -1 ){\n\t\t\tcounters.push( DOM.div( {className: 'rdtCounterSeparator', key: 'sep5' }, ':' ));\n\t\t\tcounters.push(\n\t\t\t\tDOM.div( {className: 'rdtCounter rdtMilli', key:'m'},\n\t\t\t\t\tDOM.input({ value: this.state.milliseconds, type: 'text', onChange: this.updateMilli })\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t}\n\n\t\treturn DOM.div( {className: 'rdtTime'},\n\t\t\tDOM.table( {}, [\n\t\t\t\tthis.renderHeader(),\n\t\t\t\tDOM.tbody({key: 'b'}, DOM.tr({}, DOM.td({},\n\t\t\t\t\tDOM.div({ className: 'rdtCounters' }, counters )\n\t\t\t\t)))\n\t\t\t])\n\t\t);\n\t},\n\tcomponentWillMount: function() {\n\t\tvar me = this;\n\t\t['hours', 'minutes', 'seconds', 'milliseconds'].forEach(function(type) {\n\t\t\tassign(me.timeConstraints[type], me.props.timeConstraints[type]);\n\t\t});\n\t},\n\tcomponentWillReceiveProps: function( nextProps ){\n\t\tthis.setState( this.calculateState( nextProps ) );\n\t},\n\tupdateMilli: function( e ){\n\t\tvar milli = parseInt( e.target.value, 10 );\n\t\tif ( milli === e.target.value && milli >= 0 && milli < 1000 ){\n\t\t\tthis.props.setTime( 'milliseconds', milli );\n\t\t\tthis.setState({ milliseconds: milli });\n\t\t}\n\t},\n\trenderHeader: function(){\n\t\tif ( !this.props.dateFormat )\n\t\t\treturn null;\n\n\t\tvar date = this.props.selectedDate || this.props.viewDate;\n\t\treturn DOM.thead({ key: 'h'}, DOM.tr({},\n\t\t\tDOM.th( {className: 'rdtSwitch', colSpan: 4, onClick: this.props.showView('days')}, date.format( this.props.dateFormat ) )\n\t\t));\n\t},\n\tonStartClicking: function( action, type ){\n\t\tvar me = this;\n\n\t\treturn function(){\n\t\t\tvar update = {};\n\t\t\tupdate[ type ] = me[ action ]( type );\n\t\t\tme.setState( update );\n\n\t\t\tme.timer = setTimeout( function(){\n\t\t\t\tme.increaseTimer = setInterval( function(){\n\t\t\t\t\tupdate[ type ] = me[ action ]( type );\n\t\t\t\t\tme.setState( update );\n\t\t\t\t}, 70);\n\t\t\t}, 500);\n\n\t\t\tme.mouseUpListener = function(){\n\t\t\t\tclearTimeout( me.timer );\n\t\t\t\tclearInterval( me.increaseTimer );\n\t\t\t\tme.props.setTime( type, me.state[ type ] );\n\t\t\t\tdocument.body.removeEventListener('mouseup', me.mouseUpListener);\n\t\t\t};\n\n\t\t\tdocument.body.addEventListener('mouseup', me.mouseUpListener);\n\t\t};\n\t},\n\ttimeConstraints: {\n\t\thours: {\n\t\t\tmin: 0,\n\t\t\tmax: 23,\n\t\t\tstep: 1\n\t\t},\n\t\tminutes: {\n\t\t\tmin: 0,\n\t\t\tmax: 59,\n\t\t\tstep: 1\n\t\t},\n\t\tseconds: {\n\t\t\tmin: 0,\n\t\t\tmax: 59,\n\t\t\tstep: 1,\n\t\t},\n\t\tmilliseconds: {\n\t\t\tmin: 0,\n\t\t\tmax: 999,\n\t\t\tstep: 1\n\t\t}\n\t},\n\tpadValues: {\n\t\thours: 1,\n\t\tminutes: 2,\n\t\tseconds: 2,\n\t\tmilliseconds: 3\n\t},\n\tincrease: function( type ){\n\t\tvar value = parseInt(this.state[ type ], 10) + this.timeConstraints[ type ].step;\n\t\tif ( value > this.timeConstraints[ type ].max )\n\t\t\tvalue = this.timeConstraints[ type ].min + ( value - ( this.timeConstraints[ type ].max + 1) );\n\t\treturn this.pad( type, value );\n\t},\n\tdecrease: function( type ){\n\t\tvar value = parseInt(this.state[ type ], 10) - this.timeConstraints[ type ].step;\n\t\tif ( value < this.timeConstraints[ type ].min )\n\t\t\tvalue = this.timeConstraints[ type ].max + 1 - ( this.timeConstraints[ type ].min - value );\n\t\treturn this.pad( type, value );\n\t},\n\tpad: function( type, value ){\n\t\tvar str = value + '';\n\t\twhile ( str.length < this.padValues[ type ] )\n\t\t\tstr = '0' + str;\n\t\treturn str;\n\t}\n});\n\nmodule.exports = DateTimePickerTime;\n\n\n/*****************\n ** WEBPACK FOOTER\n ** ./src/TimeView.js\n ** module id = 7\n ** module chunks = 0\n **/\n//# sourceURL=webpack:///./src/TimeView.js?"); | ||
@@ -108,0 +108,0 @@ /***/ }, |
/* | ||
react-datetime v2.4.0 | ||
react-datetime v2.5.0 | ||
https://github.com/arqex/react-datetime | ||
MIT: https://github.com/arqex/react-datetime/raw/master/LICENSE | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("React"),require("moment"),require("ReactDOM")):"function"==typeof define&&define.amd?define(["React","moment","ReactDOM"],e):"object"==typeof exports?exports.Datetime=e(require("React"),require("moment"),require("ReactDOM")):t.Datetime=e(t.React,t.moment,t.ReactDOM)}(this,function(t,e,s){return function(t){function e(a){if(s[a])return s[a].exports;var n=s[a]={exports:{},id:a,loaded:!1};return t[a].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var s={};return e.m=t,e.c=s,e.p="",e(0)}([function(t,e,s){"use strict";var a=s(1),n=s(2),r=s(3),i=s(5),o=s(6),c=s(7),p=s(4),u=n.PropTypes,d=n.createClass({mixins:[s(8)],viewComponents:{days:r,months:i,years:o,time:c},propTypes:{onFocus:u.func,onBlur:u.func,onChange:u.func,locale:u.string,input:u.bool,inputProps:u.object,viewMode:u.oneOf(["years","months","days","time"]),isValidDate:u.func,open:u.bool,strictParsing:u.bool,closeOnSelect:u.bool,closeOnTab:u.bool},getDefaultProps:function(){var t=function(){};return{className:"",defaultValue:"",inputProps:{},input:!0,onFocus:t,onBlur:t,onChange:t,timeFormat:!0,dateFormat:!0,strictParsing:!0,closeOnSelect:!1,closeOnTab:!0}},getInitialState:function(){var t=this.getStateFromProps(this.props);return void 0===t.open&&(t.open=!this.props.input),t.currentView=this.props.dateFormat?this.props.viewMode||t.updateOn||"days":"time",t},getStateFromProps:function(t){var e,s,a,n=this.getFormats(t),r=t.value||t.defaultValue;return r&&"string"==typeof r?e=this.localMoment(r,n.datetime):r&&(e=this.localMoment(r)),e&&!e.isValid()&&(e=null),s=e?e.clone().startOf("month"):this.localMoment().startOf("month"),a=this.getUpdateOn(n),{updateOn:a,inputFormat:n.datetime,viewDate:s,selectedDate:e,inputValue:e?e.format(n.datetime):r||"",open:t.open}},getUpdateOn:function(t){return t.date.match(/[lLD]/)?"days":-1!==t.date.indexOf("M")?"months":-1!==t.date.indexOf("Y")?"years":"days"},getFormats:function(t){var e={date:t.dateFormat||"",time:t.timeFormat||""},s=this.localMoment(t.date).localeData();return e.date===!0?e.date=s.longDateFormat("L"):"days"!==this.getUpdateOn(e)&&(e.time=""),e.time===!0&&(e.time=s.longDateFormat("LT")),e.datetime=e.date&&e.time?e.date+" "+e.time:e.date||e.time,e},componentWillReceiveProps:function(t){var e=this.getFormats(t),s={};t.value!==this.props.value&&(s=this.getStateFromProps(t)),e.datetime!==this.getFormats(this.props).datetime&&(s.inputFormat=e.datetime),void 0===s.open&&(this.props.closeOnSelect&&"time"!==this.state.currentView?s.open=!1:s.open=this.state.open),this.setState(s)},onInputChange:function(t){var e=null===t.target?t:t.target.value,s=this.localMoment(e,this.state.inputFormat),a={inputValue:e};return s.isValid()&&!this.props.value?(a.selectedDate=s,a.viewDate=s.clone().startOf("month")):a.selectedDate=null,this.setState(a,function(){return this.props.onChange(s.isValid()?s:this.state.inputValue)})},onInputKey:function(t){9===t.which&&this.props.closeOnTab&&this.closeCalendar()},showView:function(t){var e=this;return function(){e.setState({currentView:t})}},setDate:function(t){var e=this,s={month:"days",year:"months"};return function(a){e.setState({viewDate:e.state.viewDate.clone()[t](parseInt(a.target.getAttribute("data-value"),10)).startOf(t),currentView:s[t]})}},addTime:function(t,e,s){return this.updateTime("add",t,e,s)},subtractTime:function(t,e,s){return this.updateTime("subtract",t,e,s)},updateTime:function(t,e,s,a){var n=this;return function(){var r={},i=a?"selectedDate":"viewDate";r[i]=n.state[i].clone()[t](e,s),n.setState(r)}},allowedSetTime:["hours","minutes","seconds","milliseconds"],setTime:function(t,e){var s,a=this.allowedSetTime.indexOf(t)+1,n=this.state,r=(n.selectedDate||n.viewDate).clone();for(r[t](e);a<this.allowedSetTime.length;a++)s=this.allowedSetTime[a],r[s](r[s]());this.props.value||this.setState({selectedDate:r,inputValue:r.format(n.inputFormat)}),this.props.onChange(r)},updateSelectedDate:function(t,e){var s,a=t.target,n=0,r=this.state.viewDate,i=this.state.selectedDate||r;-1!==a.className.indexOf("rdtDay")?(-1!==a.className.indexOf("rdtNew")?n=1:-1!==a.className.indexOf("rdtOld")&&(n=-1),s=r.clone().month(r.month()+n).date(parseInt(a.getAttribute("data-value"),10))):-1!==a.className.indexOf("rdtMonth")?s=r.clone().month(parseInt(a.getAttribute("data-value"),10)).date(i.date()):-1!==a.className.indexOf("rdtYear")&&(s=r.clone().month(i.month()).date(i.date()).year(parseInt(a.getAttribute("data-value"),10))),s.hours(i.hours()).minutes(i.minutes()).seconds(i.seconds()).milliseconds(i.milliseconds()),this.props.value?this.props.closeOnSelect&&e&&this.closeCalendar():this.setState({selectedDate:s,viewDate:s.clone().startOf("month"),inputValue:s.format(this.state.inputFormat),open:!(this.props.closeOnSelect&&e)}),this.props.onChange(s)},openCalendar:function(){this.state.open||(this.props.onFocus(),this.setState({open:!0}))},closeCalendar:function(){this.setState({open:!1}),this.props.onBlur(this.state.selectedDate||this.state.inputValue)},handleClickOutside:function(){this.props.input&&this.state.open&&!this.props.open&&(this.setState({open:!1}),this.props.onBlur(this.state.selectedDate||this.state.inputValue))},localMoment:function(t,e){var s=p(t,e,this.props.strictParsing);return this.props.locale&&s.locale(this.props.locale),s},componentProps:{fromProps:["value","isValidDate","renderDay","renderMonth","renderYear"],fromState:["viewDate","selectedDate","updateOn"],fromThis:["setDate","setTime","showView","addTime","subtractTime","updateSelectedDate","localMoment"]},getComponentProps:function(){var t=this,e=this.getFormats(this.props),s={dateFormat:e.date,timeFormat:e.time};return this.componentProps.fromProps.forEach(function(e){s[e]=t.props[e]}),this.componentProps.fromState.forEach(function(e){s[e]=t.state[e]}),this.componentProps.fromThis.forEach(function(e){s[e]=t[e]}),s},render:function(){var t=this.viewComponents[this.state.currentView],e=n.DOM,s="rdt "+this.props.className,r=[];return this.props.input?r=[e.input(a({key:"i",type:"text",className:"form-control",onFocus:this.openCalendar,onChange:this.onInputChange,onKeyDown:this.onInputKey,value:this.state.inputValue},this.props.inputProps))]:s+=" rdtStatic",this.state.open&&(s+=" rdtOpen"),e.div({className:s},r.concat(e.div({key:"dt",className:"rdtPicker"},n.createElement(t,this.getComponentProps()))))}});d.moment=p,t.exports=d},function(t,e){"use strict";function s(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}function a(t){var e=Object.getOwnPropertyNames(t);return Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(t))),e.filter(function(e){return n.call(t,e)})}var n=Object.prototype.propertyIsEnumerable;t.exports=Object.assign||function(t,e){for(var n,r,i=s(t),o=1;o<arguments.length;o++){n=arguments[o],r=a(Object(n));for(var c=0;c<r.length;c++)i[r[c]]=n[r[c]]}return i}},function(e,s){e.exports=t},function(t,e,s){"use strict";var a=s(2),n=s(4),r=a.DOM,i=a.createClass({render:function(){var t,e=this.renderFooter(),s=this.props.viewDate,a=s.localeData();return t=[r.thead({key:"th"},[r.tr({key:"h"},[r.th({key:"p",className:"rdtPrev"},r.span({onClick:this.props.subtractTime(1,"months")},"‹")),r.th({key:"s",className:"rdtSwitch",onClick:this.props.showView("months"),colSpan:5,"data-value":this.props.viewDate.month()},a.months(s)+" "+s.year()),r.th({key:"n",className:"rdtNext"},r.span({onClick:this.props.addTime(1,"months")},"›"))]),r.tr({key:"d"},this.getDaysOfWeek(a).map(function(t,e){return r.th({key:t+e,className:"dow"},t)}))]),r.tbody({key:"tb"},this.renderDays())],e&&t.push(e),r.div({className:"rdtDays"},r.table({},t))},getDaysOfWeek:function(t){var e=t._weekdaysMin,s=t.firstDayOfWeek(),a=[],n=0;return e.forEach(function(t){a[(7+n++-s)%7]=t}),a},renderDays:function(){var t,e,s,a,i=this.props.viewDate,o=this.props.selectedDate&&this.props.selectedDate.clone(),c=i.clone().subtract(1,"months"),p=i.year(),u=i.month(),d=[],l=[],h=this.props.renderDay||this.renderDay,m=this.props.isValidDate||this.isValidDate;c.date(c.daysInMonth()).startOf("week");for(var f=c.clone().add(42,"d");c.isBefore(f);)t="rdtDay",a=c.clone(),c.year()===p&&c.month()<u||c.year()<p?t+=" rdtOld":(c.year()===p&&c.month()>u||c.year()>p)&&(t+=" rdtNew"),o&&c.isSame(o,"day")&&(t+=" rdtActive"),c.isSame(n(),"day")&&(t+=" rdtToday"),e=!m(a,o),e&&(t+=" rdtDisabled"),s={key:c.format("M_D"),"data-value":c.date(),className:t},e||(s.onClick=this.updateSelectedDate),l.push(h(s,a,o)),7===l.length&&(d.push(r.tr({key:c.format("M_D")},l)),l=[]),c.add(1,"d");return d},updateSelectedDate:function(t){this.props.updateSelectedDate(t,!0)},renderDay:function(t,e){return r.td(t,e.date())},renderFooter:function(){if(!this.props.timeFormat)return"";var t=this.props.selectedDate||this.props.viewDate;return r.tfoot({key:"tf"},r.tr({},r.td({onClick:this.props.showView("time"),colSpan:7,className:"rdtTimeToggle"},t.format(this.props.timeFormat))))},isValidDate:function(){return 1}});t.exports=i},function(t,s){t.exports=e},function(t,e,s){"use strict";function a(t){return t.charAt(0).toUpperCase()+t.slice(1)}var n=s(2),r=n.DOM,i=n.createClass({render:function(){return r.div({className:"rdtMonths"},[r.table({key:"a"},r.thead({},r.tr({},[r.th({key:"prev",className:"rdtPrev"},r.span({onClick:this.props.subtractTime(1,"years")},"‹")),r.th({key:"year",className:"rdtSwitch",onClick:this.props.showView("years"),colSpan:2,"data-value":this.props.viewDate.year()},this.props.viewDate.year()),r.th({key:"next",className:"rdtNext"},r.span({onClick:this.props.addTime(1,"years")},"›"))]))),r.table({key:"months"},r.tbody({key:"b"},this.renderMonths()))])},renderMonths:function(){for(var t,e,s=this.props.selectedDate,a=this.props.viewDate.month(),n=this.props.viewDate.year(),i=[],o=0,c=[],p=this.props.renderMonth||this.renderMonth;12>o;)t="rdtMonth",s&&o===a&&n===s.year()&&(t+=" rdtActive"),e={key:o,"data-value":o,className:t,onClick:"months"===this.props.updateOn?this.updateSelectedMonth:this.props.setDate("month")},c.push(p(e,o,n,s&&s.clone())),4===c.length&&(i.push(r.tr({key:a+"_"+i.length},c)),c=[]),o++;return i},updateSelectedMonth:function(t){this.props.updateSelectedDate(t,!0)},renderMonth:function(t,e){var s=this.props.viewDate.localeData()._monthsShort;return r.td(t,s.standalone?a(s.standalone[e]):s[e])}});t.exports=i},function(t,e,s){"use strict";var a=s(2),n=a.DOM,r=a.createClass({render:function(){var t=10*parseInt(this.props.viewDate.year()/10,10);return n.div({className:"rdtYears"},[n.table({key:"a"},n.thead({},n.tr({},[n.th({key:"prev",className:"rdtPrev"},n.span({onClick:this.props.subtractTime(10,"years")},"‹")),n.th({key:"year",className:"rdtSwitch",onClick:this.props.showView("years"),colSpan:2},t+"-"+(t+9)),n.th({key:"next",className:"rdtNext"},n.span({onClick:this.props.addTime(10,"years")},"›"))]))),n.table({key:"years"},n.tbody({},this.renderYears(t)))])},renderYears:function(t){var e,s,a=[],r=-1,i=[],o=this.props.renderYear||this.renderYear,c=this.props.selectedDate;for(t--;11>r;)e="rdtYear",-1===r|10===r&&(e+=" rdtOld"),c&&c.year()===t&&(e+=" rdtActive"),s={key:t,"data-value":t,className:e,onClick:"years"===this.props.updateOn?this.updateSelectedYear:this.props.setDate("year")},a.push(o(s,t,c&&c.clone())),4===a.length&&(i.push(n.tr({key:r},a)),a=[]),t++,r++;return i},updateSelectedYear:function(t){this.props.updateSelectedDate(t,!0)},renderYear:function(t,e){return n.td(t,e)}});t.exports=r},function(t,e,s){"use strict";var a=s(2),n=a.DOM,r=a.createClass({getInitialState:function(){return this.calculateState(this.props)},calculateState:function(t){var e=t.selectedDate||t.viewDate,s=t.timeFormat,a=[];(-1!==s.indexOf("H")||-1!==s.indexOf("h"))&&(a.push("hours"),-1!==s.indexOf("m")&&(a.push("minutes"),-1!==s.indexOf("s")&&a.push("seconds")));var n=!1;return-1!==this.props.timeFormat.indexOf(" A")&&null!==this.state&&(n=this.state.hours>=12?"PM":"AM"),{hours:e.format("H"),minutes:e.format("mm"),seconds:e.format("ss"),milliseconds:e.format("SSS"),daypart:n,counters:a}},renderCounter:function(t){if("daypart"!==t){var e=this.state[t];return"hours"===t&&-1!==this.props.timeFormat.indexOf(" A")&&e>12&&(e>12&&(e-=12),0===e&&(e=12)),n.div({key:t,className:"rdtCounter"},[n.span({key:"up",className:"rdtBtn",onMouseDown:this.onStartClicking("increase",t)},"▲"),n.div({key:"c",className:"rdtCount"},e),n.span({key:"do",className:"rdtBtn",onMouseDown:this.onStartClicking("decrease",t)},"▼")])}return""},render:function(){var t=this,e=[];return this.state.counters.forEach(function(s){e.length&&e.push(n.div({key:"sep"+e.length,className:"rdtCounterSeparator"},":")),e.push(t.renderCounter(s))}),this.state.daypart!==!1&&e.push(n.div({key:this.state.daypart,className:"rdtDayPart"},this.state.daypart)),3===this.state.counters.length&&-1!==this.props.timeFormat.indexOf("S")&&(e.push(n.div({className:"rdtCounterSeparator",key:"sep5"},":")),e.push(n.div({className:"rdtCounter rdtMilli",key:"m"},n.input({value:this.state.milliseconds,type:"text",onChange:this.updateMilli})))),n.div({className:"rdtTime"},n.table({},[this.renderHeader(),n.tbody({key:"b"},n.tr({},n.td({},n.div({className:"rdtCounters"},e))))]))},componentWillReceiveProps:function(t){this.setState(this.calculateState(t))},updateMilli:function(t){var e=parseInt(t.target.value,10);e===t.target.value&&e>=0&&1e3>e&&(this.props.setTime("milliseconds",e),this.setState({milliseconds:e}))},renderHeader:function(){if(!this.props.dateFormat)return null;var t=this.props.selectedDate||this.props.viewDate;return n.thead({key:"h"},n.tr({},n.th({className:"rdtSwitch",colSpan:4,onClick:this.props.showView("days")},t.format(this.props.dateFormat))))},onStartClicking:function(t,e){var s=this;return function(){var a={};a[e]=s[t](e),s.setState(a),s.timer=setTimeout(function(){s.increaseTimer=setInterval(function(){a[e]=s[t](e),s.setState(a)},70)},500),s.mouseUpListener=function(){clearTimeout(s.timer),clearInterval(s.increaseTimer),s.props.setTime(e,s.state[e]),document.body.removeEventListener("mouseup",s.mouseUpListener)},document.body.addEventListener("mouseup",s.mouseUpListener)}},maxValues:{hours:23,minutes:59,seconds:59,milliseconds:999},padValues:{hours:1,minutes:2,seconds:2,milliseconds:3},increase:function(t){var e=parseInt(this.state[t],10)+1;return e>this.maxValues[t]&&(e=0),this.pad(t,e)},decrease:function(t){var e=parseInt(this.state[t],10)-1;return 0>e&&(e=this.maxValues[t]),this.pad(t,e)},pad:function(t,e){for(var s=e+"";s.length<this.padValues[t];)s="0"+s;return s}});t.exports=r},function(t,e,s){"use strict";var a=s(2),n=a.version&&a.version.split(".");n&&(n[0]>0||n[1]>13)&&(a=s(9));var r=[],i=[],o="ignore-react-onclickoutside",c=function(t,e){return t===e?!0:t.correspondingElement?t.correspondingElement.classList.contains(o):t.classList.contains(o)};t.exports={componentDidMount:function(){if("function"!=typeof this.handleClickOutside)throw new Error("Component lacks a handleClickOutside(event) function for processing outside click events.");var t=this.__outsideClickHandler=function(t,e){return function(s){s.stopPropagation();for(var a=s.target,n=!1;a.parentNode;){if(n=c(a,t))return;a=a.parentNode}e(s)}}(a.findDOMNode(this),this.handleClickOutside),e=r.length;r.push(this),i[e]=t,this.props.disableOnClickOutside||this.enableOnClickOutside()},componentWillUnmount:function(){this.disableOnClickOutside(),this.__outsideClickHandler=!1;var t=r.indexOf(this);t>-1&&i[t]&&(i.splice(t,1),r.splice(t,1))},enableOnClickOutside:function(){var t=this.__outsideClickHandler;document.addEventListener("mousedown",t),document.addEventListener("touchstart",t)},disableOnClickOutside:function(){var t=this.__outsideClickHandler;document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t)}}},function(t,e){t.exports=s}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("React"),require("moment"),require("ReactDOM")):"function"==typeof define&&define.amd?define(["React","moment","ReactDOM"],e):"object"==typeof exports?exports.Datetime=e(require("React"),require("moment"),require("ReactDOM")):t.Datetime=e(t.React,t.moment,t.ReactDOM)}(this,function(t,e,s){return function(t){function e(n){if(s[n])return s[n].exports;var a=s[n]={exports:{},id:n,loaded:!1};return t[n].call(a.exports,a,a.exports,e),a.loaded=!0,a.exports}var s={};return e.m=t,e.c=s,e.p="",e(0)}([function(t,e,s){"use strict";var n=s(1),a=s(2),r=s(3),i=s(5),o=s(6),c=s(7),p=s(4),u=a.PropTypes,d=a.createClass({mixins:[s(8)],viewComponents:{days:r,months:i,years:o,time:c},propTypes:{onFocus:u.func,onBlur:u.func,onChange:u.func,locale:u.string,input:u.bool,inputProps:u.object,timeConstraints:u.object,viewMode:u.oneOf(["years","months","days","time"]),isValidDate:u.func,open:u.bool,strictParsing:u.bool,closeOnSelect:u.bool,closeOnTab:u.bool},getDefaultProps:function(){var t=function(){};return{className:"",defaultValue:"",inputProps:{},input:!0,onFocus:t,onBlur:t,onChange:t,timeFormat:!0,timeConstraints:{},dateFormat:!0,strictParsing:!0,closeOnSelect:!1,closeOnTab:!0}},getInitialState:function(){var t=this.getStateFromProps(this.props);return void 0===t.open&&(t.open=!this.props.input),t.currentView=this.props.dateFormat?this.props.viewMode||t.updateOn||"days":"time",t},getStateFromProps:function(t){var e,s,n,a=this.getFormats(t),r=t.value||t.defaultValue;return r&&"string"==typeof r?e=this.localMoment(r,a.datetime):r&&(e=this.localMoment(r)),e&&!e.isValid()&&(e=null),s=e?e.clone().startOf("month"):this.localMoment().startOf("month"),n=this.getUpdateOn(a),{updateOn:n,inputFormat:a.datetime,viewDate:s,selectedDate:e,inputValue:e?e.format(a.datetime):r||"",open:t.open}},getUpdateOn:function(t){return t.date.match(/[lLD]/)?"days":-1!==t.date.indexOf("M")?"months":-1!==t.date.indexOf("Y")?"years":"days"},getFormats:function(t){var e={date:t.dateFormat||"",time:t.timeFormat||""},s=this.localMoment(t.date).localeData();return e.date===!0?e.date=s.longDateFormat("L"):"days"!==this.getUpdateOn(e)&&(e.time=""),e.time===!0&&(e.time=s.longDateFormat("LT")),e.datetime=e.date&&e.time?e.date+" "+e.time:e.date||e.time,e},componentWillReceiveProps:function(t){var e=this.getFormats(t),s={};t.value!==this.props.value&&(s=this.getStateFromProps(t)),e.datetime!==this.getFormats(this.props).datetime&&(s.inputFormat=e.datetime),void 0===s.open&&(this.props.closeOnSelect&&"time"!==this.state.currentView?s.open=!1:s.open=this.state.open),this.setState(s)},onInputChange:function(t){var e=null===t.target?t:t.target.value,s=this.localMoment(e,this.state.inputFormat),n={inputValue:e};return s.isValid()&&!this.props.value?(n.selectedDate=s,n.viewDate=s.clone().startOf("month")):n.selectedDate=null,this.setState(n,function(){return this.props.onChange(s.isValid()?s:this.state.inputValue)})},onInputKey:function(t){9===t.which&&this.props.closeOnTab&&this.closeCalendar()},showView:function(t){var e=this;return function(){e.setState({currentView:t})}},setDate:function(t){var e=this,s={month:"days",year:"months"};return function(n){e.setState({viewDate:e.state.viewDate.clone()[t](parseInt(n.target.getAttribute("data-value"),10)).startOf(t),currentView:s[t]})}},addTime:function(t,e,s){return this.updateTime("add",t,e,s)},subtractTime:function(t,e,s){return this.updateTime("subtract",t,e,s)},updateTime:function(t,e,s,n){var a=this;return function(){var r={},i=n?"selectedDate":"viewDate";r[i]=a.state[i].clone()[t](e,s),a.setState(r)}},allowedSetTime:["hours","minutes","seconds","milliseconds"],setTime:function(t,e){var s,n=this.allowedSetTime.indexOf(t)+1,a=this.state,r=(a.selectedDate||a.viewDate).clone();for(r[t](e);n<this.allowedSetTime.length;n++)s=this.allowedSetTime[n],r[s](r[s]());this.props.value||this.setState({selectedDate:r,inputValue:r.format(a.inputFormat)}),this.props.onChange(r)},updateSelectedDate:function(t,e){var s,n=t.target,a=0,r=this.state.viewDate,i=this.state.selectedDate||r;-1!==n.className.indexOf("rdtDay")?(-1!==n.className.indexOf("rdtNew")?a=1:-1!==n.className.indexOf("rdtOld")&&(a=-1),s=r.clone().month(r.month()+a).date(parseInt(n.getAttribute("data-value"),10))):-1!==n.className.indexOf("rdtMonth")?s=r.clone().month(parseInt(n.getAttribute("data-value"),10)).date(i.date()):-1!==n.className.indexOf("rdtYear")&&(s=r.clone().month(i.month()).date(i.date()).year(parseInt(n.getAttribute("data-value"),10))),s.hours(i.hours()).minutes(i.minutes()).seconds(i.seconds()).milliseconds(i.milliseconds()),this.props.value?this.props.closeOnSelect&&e&&this.closeCalendar():this.setState({selectedDate:s,viewDate:s.clone().startOf("month"),inputValue:s.format(this.state.inputFormat),open:!(this.props.closeOnSelect&&e)}),this.props.onChange(s)},openCalendar:function(){this.state.open||(this.props.onFocus(),this.setState({open:!0}))},closeCalendar:function(){this.setState({open:!1}),this.props.onBlur(this.state.selectedDate||this.state.inputValue)},handleClickOutside:function(){this.props.input&&this.state.open&&!this.props.open&&(this.setState({open:!1}),this.props.onBlur(this.state.selectedDate||this.state.inputValue))},localMoment:function(t,e){var s=p(t,e,this.props.strictParsing);return this.props.locale&&s.locale(this.props.locale),s},componentProps:{fromProps:["value","isValidDate","renderDay","renderMonth","renderYear","timeConstraints"],fromState:["viewDate","selectedDate","updateOn"],fromThis:["setDate","setTime","showView","addTime","subtractTime","updateSelectedDate","localMoment"]},getComponentProps:function(){var t=this,e=this.getFormats(this.props),s={dateFormat:e.date,timeFormat:e.time};return this.componentProps.fromProps.forEach(function(e){s[e]=t.props[e]}),this.componentProps.fromState.forEach(function(e){s[e]=t.state[e]}),this.componentProps.fromThis.forEach(function(e){s[e]=t[e]}),s},render:function(){var t=this.viewComponents[this.state.currentView],e=a.DOM,s="rdt "+this.props.className,r=[];return this.props.input?r=[e.input(n({key:"i",type:"text",className:"form-control",onFocus:this.openCalendar,onChange:this.onInputChange,onKeyDown:this.onInputKey,value:this.state.inputValue},this.props.inputProps))]:s+=" rdtStatic",this.state.open&&(s+=" rdtOpen"),e.div({className:s},r.concat(e.div({key:"dt",className:"rdtPicker"},a.createElement(t,this.getComponentProps()))))}});d.moment=p,t.exports=d},function(t,e){"use strict";function s(t){if(null==t)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}function n(t){var e=Object.getOwnPropertyNames(t);return Object.getOwnPropertySymbols&&(e=e.concat(Object.getOwnPropertySymbols(t))),e.filter(function(e){return a.call(t,e)})}var a=Object.prototype.propertyIsEnumerable;t.exports=Object.assign||function(t,e){for(var a,r,i=s(t),o=1;o<arguments.length;o++){a=arguments[o],r=n(Object(a));for(var c=0;c<r.length;c++)i[r[c]]=a[r[c]]}return i}},function(e,s){e.exports=t},function(t,e,s){"use strict";var n=s(2),a=s(4),r=n.DOM,i=n.createClass({render:function(){var t,e=this.renderFooter(),s=this.props.viewDate,n=s.localeData();return t=[r.thead({key:"th"},[r.tr({key:"h"},[r.th({key:"p",className:"rdtPrev"},r.span({onClick:this.props.subtractTime(1,"months")},"‹")),r.th({key:"s",className:"rdtSwitch",onClick:this.props.showView("months"),colSpan:5,"data-value":this.props.viewDate.month()},n.months(s)+" "+s.year()),r.th({key:"n",className:"rdtNext"},r.span({onClick:this.props.addTime(1,"months")},"›"))]),r.tr({key:"d"},this.getDaysOfWeek(n).map(function(t,e){return r.th({key:t+e,className:"dow"},t)}))]),r.tbody({key:"tb"},this.renderDays())],e&&t.push(e),r.div({className:"rdtDays"},r.table({},t))},getDaysOfWeek:function(t){var e=t._weekdaysMin,s=t.firstDayOfWeek(),n=[],a=0;return e.forEach(function(t){n[(7+a++-s)%7]=t}),n},renderDays:function(){var t,e,s,n,i=this.props.viewDate,o=this.props.selectedDate&&this.props.selectedDate.clone(),c=i.clone().subtract(1,"months"),p=i.year(),u=i.month(),d=[],l=[],h=this.props.renderDay||this.renderDay,m=this.props.isValidDate||this.isValidDate;c.date(c.daysInMonth()).startOf("week");for(var f=c.clone().add(42,"d");c.isBefore(f);)t="rdtDay",n=c.clone(),c.year()===p&&c.month()<u||c.year()<p?t+=" rdtOld":(c.year()===p&&c.month()>u||c.year()>p)&&(t+=" rdtNew"),o&&c.isSame(o,"day")&&(t+=" rdtActive"),c.isSame(a(),"day")&&(t+=" rdtToday"),e=!m(n,o),e&&(t+=" rdtDisabled"),s={key:c.format("M_D"),"data-value":c.date(),className:t},e||(s.onClick=this.updateSelectedDate),l.push(h(s,n,o)),7===l.length&&(d.push(r.tr({key:c.format("M_D")},l)),l=[]),c.add(1,"d");return d},updateSelectedDate:function(t){this.props.updateSelectedDate(t,!0)},renderDay:function(t,e){return r.td(t,e.date())},renderFooter:function(){if(!this.props.timeFormat)return"";var t=this.props.selectedDate||this.props.viewDate;return r.tfoot({key:"tf"},r.tr({},r.td({onClick:this.props.showView("time"),colSpan:7,className:"rdtTimeToggle"},t.format(this.props.timeFormat))))},isValidDate:function(){return 1}});t.exports=i},function(t,s){t.exports=e},function(t,e,s){"use strict";function n(t){return t.charAt(0).toUpperCase()+t.slice(1)}var a=s(2),r=a.DOM,i=a.createClass({render:function(){return r.div({className:"rdtMonths"},[r.table({key:"a"},r.thead({},r.tr({},[r.th({key:"prev",className:"rdtPrev"},r.span({onClick:this.props.subtractTime(1,"years")},"‹")),r.th({key:"year",className:"rdtSwitch",onClick:this.props.showView("years"),colSpan:2,"data-value":this.props.viewDate.year()},this.props.viewDate.year()),r.th({key:"next",className:"rdtNext"},r.span({onClick:this.props.addTime(1,"years")},"›"))]))),r.table({key:"months"},r.tbody({key:"b"},this.renderMonths()))])},renderMonths:function(){for(var t,e,s=this.props.selectedDate,n=this.props.viewDate.month(),a=this.props.viewDate.year(),i=[],o=0,c=[],p=this.props.renderMonth||this.renderMonth;12>o;)t="rdtMonth",s&&o===n&&a===s.year()&&(t+=" rdtActive"),e={key:o,"data-value":o,className:t,onClick:"months"===this.props.updateOn?this.updateSelectedMonth:this.props.setDate("month")},c.push(p(e,o,a,s&&s.clone())),4===c.length&&(i.push(r.tr({key:n+"_"+i.length},c)),c=[]),o++;return i},updateSelectedMonth:function(t){this.props.updateSelectedDate(t,!0)},renderMonth:function(t,e){var s=this.props.viewDate.localeData()._monthsShort;return r.td(t,s.standalone?n(s.standalone[e]):s[e])}});t.exports=i},function(t,e,s){"use strict";var n=s(2),a=n.DOM,r=n.createClass({render:function(){var t=10*parseInt(this.props.viewDate.year()/10,10);return a.div({className:"rdtYears"},[a.table({key:"a"},a.thead({},a.tr({},[a.th({key:"prev",className:"rdtPrev"},a.span({onClick:this.props.subtractTime(10,"years")},"‹")),a.th({key:"year",className:"rdtSwitch",onClick:this.props.showView("years"),colSpan:2},t+"-"+(t+9)),a.th({key:"next",className:"rdtNext"},a.span({onClick:this.props.addTime(10,"years")},"›"))]))),a.table({key:"years"},a.tbody({},this.renderYears(t)))])},renderYears:function(t){var e,s,n=[],r=-1,i=[],o=this.props.renderYear||this.renderYear,c=this.props.selectedDate;for(t--;11>r;)e="rdtYear",-1===r|10===r&&(e+=" rdtOld"),c&&c.year()===t&&(e+=" rdtActive"),s={key:t,"data-value":t,className:e,onClick:"years"===this.props.updateOn?this.updateSelectedYear:this.props.setDate("year")},n.push(o(s,t,c&&c.clone())),4===n.length&&(i.push(a.tr({key:r},n)),n=[]),t++,r++;return i},updateSelectedYear:function(t){this.props.updateSelectedDate(t,!0)},renderYear:function(t,e){return a.td(t,e)}});t.exports=r},function(t,e,s){"use strict";var n=s(2),a=s(1),r=n.DOM,i=n.createClass({getInitialState:function(){return this.calculateState(this.props)},calculateState:function(t){var e=t.selectedDate||t.viewDate,s=t.timeFormat,n=[];(-1!==s.indexOf("H")||-1!==s.indexOf("h"))&&(n.push("hours"),-1!==s.indexOf("m")&&(n.push("minutes"),-1!==s.indexOf("s")&&n.push("seconds")));var a=!1;return-1!==this.props.timeFormat.indexOf(" A")&&null!==this.state&&(a=this.state.hours>=12?"PM":"AM"),{hours:e.format("H"),minutes:e.format("mm"),seconds:e.format("ss"),milliseconds:e.format("SSS"),daypart:a,counters:n}},renderCounter:function(t){if("daypart"!==t){var e=this.state[t];return"hours"===t&&-1!==this.props.timeFormat.indexOf(" A")&&e>12&&(e>12&&(e-=12),0===e&&(e=12)),r.div({key:t,className:"rdtCounter"},[r.span({key:"up",className:"rdtBtn",onMouseDown:this.onStartClicking("increase",t)},"▲"),r.div({key:"c",className:"rdtCount"},e),r.span({key:"do",className:"rdtBtn",onMouseDown:this.onStartClicking("decrease",t)},"▼")])}return""},render:function(){var t=this,e=[];return this.state.counters.forEach(function(s){e.length&&e.push(r.div({key:"sep"+e.length,className:"rdtCounterSeparator"},":")),e.push(t.renderCounter(s))}),this.state.daypart!==!1&&e.push(r.div({key:this.state.daypart,className:"rdtDayPart"},this.state.daypart)),3===this.state.counters.length&&-1!==this.props.timeFormat.indexOf("S")&&(e.push(r.div({className:"rdtCounterSeparator",key:"sep5"},":")),e.push(r.div({className:"rdtCounter rdtMilli",key:"m"},r.input({value:this.state.milliseconds,type:"text",onChange:this.updateMilli})))),r.div({className:"rdtTime"},r.table({},[this.renderHeader(),r.tbody({key:"b"},r.tr({},r.td({},r.div({className:"rdtCounters"},e))))]))},componentWillMount:function(){var t=this;["hours","minutes","seconds","milliseconds"].forEach(function(e){a(t.timeConstraints[e],t.props.timeConstraints[e])})},componentWillReceiveProps:function(t){this.setState(this.calculateState(t))},updateMilli:function(t){var e=parseInt(t.target.value,10);e===t.target.value&&e>=0&&1e3>e&&(this.props.setTime("milliseconds",e),this.setState({milliseconds:e}))},renderHeader:function(){if(!this.props.dateFormat)return null;var t=this.props.selectedDate||this.props.viewDate;return r.thead({key:"h"},r.tr({},r.th({className:"rdtSwitch",colSpan:4,onClick:this.props.showView("days")},t.format(this.props.dateFormat))))},onStartClicking:function(t,e){var s=this;return function(){var n={};n[e]=s[t](e),s.setState(n),s.timer=setTimeout(function(){s.increaseTimer=setInterval(function(){n[e]=s[t](e),s.setState(n)},70)},500),s.mouseUpListener=function(){clearTimeout(s.timer),clearInterval(s.increaseTimer),s.props.setTime(e,s.state[e]),document.body.removeEventListener("mouseup",s.mouseUpListener)},document.body.addEventListener("mouseup",s.mouseUpListener)}},timeConstraints:{hours:{min:0,max:23,step:1},minutes:{min:0,max:59,step:1},seconds:{min:0,max:59,step:1},milliseconds:{min:0,max:999,step:1}},padValues:{hours:1,minutes:2,seconds:2,milliseconds:3},increase:function(t){var e=parseInt(this.state[t],10)+this.timeConstraints[t].step;return e>this.timeConstraints[t].max&&(e=this.timeConstraints[t].min+(e-(this.timeConstraints[t].max+1))),this.pad(t,e)},decrease:function(t){var e=parseInt(this.state[t],10)-this.timeConstraints[t].step;return e<this.timeConstraints[t].min&&(e=this.timeConstraints[t].max+1-(this.timeConstraints[t].min-e)),this.pad(t,e)},pad:function(t,e){for(var s=e+"";s.length<this.padValues[t];)s="0"+s;return s}});t.exports=i},function(t,e,s){"use strict";var n=s(2),a=n.version&&n.version.split(".");a&&(a[0]>0||a[1]>13)&&(n=s(9));var r=[],i=[],o="ignore-react-onclickoutside",c=function(t,e){return t===e?!0:t.correspondingElement?t.correspondingElement.classList.contains(o):t.classList.contains(o)};t.exports={componentDidMount:function(){if("function"!=typeof this.handleClickOutside)throw new Error("Component lacks a handleClickOutside(event) function for processing outside click events.");var t=this.__outsideClickHandler=function(t,e){return function(s){s.stopPropagation();for(var n=s.target,a=!1;n.parentNode;){if(a=c(n,t))return;n=n.parentNode}e(s)}}(n.findDOMNode(this),this.handleClickOutside),e=r.length;r.push(this),i[e]=t,this.props.disableOnClickOutside||this.enableOnClickOutside()},componentWillUnmount:function(){this.disableOnClickOutside(),this.__outsideClickHandler=!1;var t=r.indexOf(this);t>-1&&i[t]&&(i.splice(t,1),r.splice(t,1))},enableOnClickOutside:function(){var t=this.__outsideClickHandler;document.addEventListener("mousedown",t),document.addEventListener("touchstart",t)},disableOnClickOutside:function(){var t=this.__outsideClickHandler;document.removeEventListener("mousedown",t),document.removeEventListener("touchstart",t)}}},function(t,e){t.exports=s}])}); |
{ | ||
"name": "react-datetime", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "A lightweight but complete datetime picker React.js component.", | ||
@@ -15,2 +15,3 @@ "homepage": "https://github.com/arqex/react-datetime", | ||
"test": "node node_modules/mocha/bin/mocha tests", | ||
"test:watch": "node node_modules/mocha/bin/mocha --watch tests", | ||
"dev": "webpack-dev-server --config example/webpack.config.js --devtool eval --progress --colors --hot --content-base example", | ||
@@ -42,4 +43,6 @@ "lint": "./node_modules/.bin/eslint src/ DateTime.js" | ||
"mocha": "^2.2.5", | ||
"moment": "2.14.1", | ||
"react": ">=0.13", | ||
"react-addons-test-utils": ">=0.13", | ||
"react-dom": "15.2.1", | ||
"react-tools": "^0.13.2", | ||
@@ -46,0 +49,0 @@ "webpack": "^1.5.1", |
@@ -71,2 +71,3 @@ react-datetime | ||
| **closeOnTab** | boolean | true | When `true` and the input is focused, pressing the `tab` key will close the picker. | ||
| **timeConstraints** | object | null | Allow to add some constraints to the time selector. It accepts an object with the format `{hours:{ min: 9, max: 15, step:2}}` so the hours can't be lower than 9 or higher than 15, and it will change adding or subtracting 2 hours everytime the buttons are clicked. The constraints can be added to the `hours`, `minutes`, `seconds` and `milliseconds`. | ||
@@ -73,0 +74,0 @@ ## i18n |
'use strict'; | ||
var React = require('react'); | ||
var React = require('react'), | ||
assign = require('object-assign'); | ||
@@ -92,2 +93,8 @@ var DOM = React.DOM; | ||
}, | ||
componentWillMount: function() { | ||
var me = this; | ||
['hours', 'minutes', 'seconds', 'milliseconds'].forEach(function(type) { | ||
assign(me.timeConstraints[type], me.props.timeConstraints[type]); | ||
}); | ||
}, | ||
componentWillReceiveProps: function( nextProps ){ | ||
@@ -137,8 +144,23 @@ this.setState( this.calculateState( nextProps ) ); | ||
}, | ||
maxValues: { | ||
hours: 23, | ||
minutes: 59, | ||
seconds: 59, | ||
milliseconds: 999 | ||
timeConstraints: { | ||
hours: { | ||
min: 0, | ||
max: 23, | ||
step: 1 | ||
}, | ||
minutes: { | ||
min: 0, | ||
max: 59, | ||
step: 1 | ||
}, | ||
seconds: { | ||
min: 0, | ||
max: 59, | ||
step: 1, | ||
}, | ||
milliseconds: { | ||
min: 0, | ||
max: 999, | ||
step: 1 | ||
} | ||
}, | ||
@@ -152,11 +174,11 @@ padValues: { | ||
increase: function( type ){ | ||
var value = parseInt(this.state[ type ], 10) + 1; | ||
if ( value > this.maxValues[ type ] ) | ||
value = 0; | ||
var value = parseInt(this.state[ type ], 10) + this.timeConstraints[ type ].step; | ||
if ( value > this.timeConstraints[ type ].max ) | ||
value = this.timeConstraints[ type ].min + ( value - ( this.timeConstraints[ type ].max + 1) ); | ||
return this.pad( type, value ); | ||
}, | ||
decrease: function( type ){ | ||
var value = parseInt(this.state[ type ], 10) - 1; | ||
if ( value < 0 ) | ||
value = this.maxValues[ type ]; | ||
var value = parseInt(this.state[ type ], 10) - this.timeConstraints[ type ].step; | ||
if ( value < this.timeConstraints[ type ].min ) | ||
value = this.timeConstraints[ type ].max + 1 - ( this.timeConstraints[ type ].min - value ); | ||
return this.pad( type, value ); | ||
@@ -163,0 +185,0 @@ }, |
@@ -574,2 +574,35 @@ // Create the dom before requiring react | ||
it( 'increase time with timeConstraints', function( done ){ | ||
var i = 0; | ||
createDatetime({ timeFormat: "HH:mm:ss:SSS", viewMode: 'time', defaultValue: date, onChange: function( selected ){ | ||
i++; | ||
if( i > 2 ){ | ||
assert.equal( selected.minute(), 17 ); | ||
assert.equal( selected.second(), 3 ); | ||
done(); | ||
} | ||
}, timeConstraints: { hours: { max: 6, step: 8 }, minutes: { step: 15 }}}); | ||
trigger( 'mousedown', dt.timeUp( 0 ) ); | ||
trigger('mouseup', document.body ); | ||
assert.equal( dt.hour().innerHTML, 3 ); | ||
trigger( 'mousedown', dt.timeUp( 1 ) ); | ||
trigger( 'mouseup', dt.timeUp( 1 ) ); | ||
assert.equal( dt.minute().innerHTML, 17 ); | ||
trigger( 'mousedown', dt.timeUp( 2 ) ); | ||
trigger( 'mouseup', dt.timeUp( 2 ) ); | ||
assert.equal( dt.second().innerHTML, 3 ); | ||
}); | ||
it( 'decrease time with timeConstraints', function( done ){ | ||
createDatetime({ timeFormat: "HH:mm:ss:SSS", viewMode: 'time', defaultValue: date, onChange: function( selected ){ | ||
assert.equal( selected.minute(), 47 ); | ||
done(); | ||
}, timeConstraints: { minutes: { step: 15 }}}); | ||
trigger( 'mousedown', dt.timeDown( 1 ) ); | ||
trigger( 'mouseup', dt.timeDown( 1 ) ); | ||
assert.equal( dt.minute().innerHTML, 47 ); | ||
}); | ||
it( 'invalid input value', function( done ){ | ||
@@ -576,0 +609,0 @@ createDatetime({ defaultValue: 'luis', onChange: function( updated ){ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
127060
2182
154
14