From 8fe52a2a1954d27abb4e9e13bbd7558c03eaf13d Mon Sep 17 00:00:00 2001 From: Andrey Pokidov Date: Tue, 25 Feb 2020 17:37:24 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BF=D1=83=D1=81=D1=82=D0=BE=D0=B5=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=B5=20=D0=B4=D0=B0=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- es5/smart-date.js | 10 ++++++---- es5/smart-date.min.js | 2 +- es6/smart-date.js | 9 ++++++--- es6/smart-date.min.js | 2 +- src-es6/SmartDateField.js | 9 ++++++--- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/es5/smart-date.js b/es5/smart-date.js index e2615ed..e853310 100644 --- a/es5/smart-date.js +++ b/es5/smart-date.js @@ -950,7 +950,9 @@ function () { this._field.addEventListener('blur', function () { _this.correctValue(true); - _this.returnLastCorrectValue(); + if (!_this._isEmptyValue(_this._field.value)) { + _this.returnLastCorrectValue(); + } }); } }, { @@ -1005,7 +1007,7 @@ function () { return; } - this._setValueToFieled(parsedValue); + this._setValueToField(parsedValue); } }, { key: "setValue", @@ -1037,8 +1039,8 @@ function () { return this._formatter.getCorrectedValue(); } }, { - key: "_setValueToFieled", - value: function _setValueToFieled(newValue) { + key: "_setValueToField", + value: function _setValueToField(newValue) { var position = this._field.selectionStart; var isAtEnd = position === this._field.value.length; this._field.value = newValue; diff --git a/es5/smart-date.min.js b/es5/smart-date.min.js index 1e9cc15..46573b7 100644 --- a/es5/smart-date.min.js +++ b/es5/smart-date.min.js @@ -1 +1 @@ -"use strict";function _get(a,b,c){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(a,b,c){var d=_superPropBase(a,b);if(d){var e=Object.getOwnPropertyDescriptor(d,b);return e.get?e.get.call(c):e.value}},_get(a,b,c||a)}function _superPropBase(a,b){for(;!Object.prototype.hasOwnProperty.call(a,b)&&(a=_getPrototypeOf(a),null!==a););return a}function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function _possibleConstructorReturn(a,b){return b&&("object"===_typeof(b)||"function"==typeof b)?b:_assertThisInitialized(a)}function _assertThisInitialized(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function _getPrototypeOf(a){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},_getPrototypeOf(a)}function _inherits(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&_setPrototypeOf(a,b)}function _setPrototypeOf(a,b){return _setPrototypeOf=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},_setPrototypeOf(a,b)}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d=a}},{key:"check",value:function(){return!1}}]),a}();AbstractSmartDatePart.STATE_NONE=0,AbstractSmartDatePart.STATE_INCOMPLETE=1,AbstractSmartDatePart.STATE_COMPLETE=2;var SmartDateStaticPart=function(a){function b(a){var c;return _classCallCheck(this,b),c=_possibleConstructorReturn(this,_getPrototypeOf(b).call(this,a,!0)),c._cleanedValue=a,c}return _inherits(b,a),_createClass(b,[{key:"parse",value:function(a){for(var b=a.value(),c=a.valueIndex();cthis._size?b.substring(0,this._size):b.lengthb&&d--,+a.substring(c,d)}},{key:"scanValue",value:function(a,b){for(var c=a.valueIndex(),d=a.value(),e=0;cb&&c--;var f=d.substring(a.valueIndex(),c);return a.setValueIndex(c),f}},{key:"_defineParsingState",value:function(a,b){return 0=this._size||!b)?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):10*this._numericValue>a?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):void(this._state=AbstractSmartDatePart.STATE_INCOMPLETE)}},{key:"_defineCleanValue",value:function(){return this._cleanedValue="",this.isNoState()?void 0:this.isComplete()?void(this._cleanedValue=this.formatValue(this._numericValue)):void(0b.MAXIMAL_VALUE&&(this._numericValue=b.MAXIMAL_VALUE),this.isComplete()&&this._numericValue=this._size?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):void(this._state=AbstractSmartDatePart.STATE_INCOMPLETE)}},{key:"_defineCleanValue",value:function(){this._cleanedValue=0=this._value.length}},{key:"value",value:function(){return this._value}},{key:"valueIndex",value:function(){return this._valueIndex}},{key:"setValueIndex",value:function(a){this._valueIndexb||b>=SmartDateMonthPart.MAXIMAL_VALUE?SmartDateMonthPart.MAXIMAL_VALUE:1===b&&c?a.BASIC_MONTH_SIZES[b]+1:a.BASIC_MONTH_SIZES[b]}},{key:"_isLeaPYear",value:function(a){return 0==a%4&&(0!=a%100||0==a%400)}},{key:"getCorrectedValue",value:function(){for(var a=0,b="";athis._maximalDate.valueOf()){var a=this._minimalDate;this._minimalDate=this._maximalDate,this._maximalDate=a}null===this._defaultDate||(this._defaultDate.valueOf()this._maximalDate.valueOf()&&(this._defaultDate=this._maximalDate))}},{key:"_parseDateValue",value:function(a){if("object"===_typeof(a)&&null!==a&&a instanceof Date)return a;if("string"!=typeof a||""===a.trim())return null;var b=this._dateYmdParser.exec(a);return null===b?(b=this._dateDmyParser.exec(a),null===b?null:new Date(+b[3],+b[2]-1,+b[1])):new Date(+b[1],+b[2]-1,+b[3])}},{key:"_initField",value:function(a){this._field=a,this._field.placeholder=this._formatter.getPlaceHolder(),this._isEmptyValue(this._field.value)?this._field.value=null===this._defaultDate?"":this._formatter.formatDate(this._defaultDate):this.correctValue(!0)}},{key:"_subscribeEvents",value:function(){var a=this,b=function(b){(null===b||"keyup"!==b.type)&&a.correctValue(!0),a._isServiceCode(b.keyCode)||(27===b.keyCode&&a.returnLastCorrectValue(),a.correctValue(!0))};this._field.addEventListener("change",b),this._field.addEventListener("keyup",b),this._field.addEventListener("blur",function(){a.correctValue(!0),a.returnLastCorrectValue()})}},{key:"_isServiceCode",value:function(a){return 8===a||46===a||16===a||17===a||18===a||20===a||35===a||36===a||37===a||39===a||46===a}},{key:"_isEmptyValue",value:function(a){return""===a.trim()}},{key:"getDefaultValue",value:function(){return null===this._defaultDate?"":this._formatter.formatDate(this._defaultDate)}},{key:"correctValue",value:function(a){this._formatter.parse(this._field.value,a);var b=this._getLimitedParsedValue();this._formatter.isComplete()&&(this._lastCorrectValue=b),this._field.value===b||this._setValueToFieled(b)}},{key:"setValue",value:function(a){var b=this._parseDateValue(a);null===b||b.valueOf()this._maximalDate.valueOf()||(this._lastCorrectValue=this._formatter.formatDate(b),this._field.value=this._lastCorrectValue)}},{key:"_getLimitedParsedValue",value:function(){if(!this._formatter.isComplete())return this._formatter.getCorrectedValue();var a=this._formatter.getParsedDate();return a.valueOf()this._maximalDate.valueOf()?this._formatter.formatDate(this._maximalDate):this._formatter.getCorrectedValue()}},{key:"_setValueToFieled",value:function(a){var b=this._field.selectionStart,c=b===this._field.value.length;this._field.value=a,!c&&b=a}},{key:"check",value:function(){return!1}}]),a}();AbstractSmartDatePart.STATE_NONE=0,AbstractSmartDatePart.STATE_INCOMPLETE=1,AbstractSmartDatePart.STATE_COMPLETE=2;var SmartDateStaticPart=function(a){function b(a){var c;return _classCallCheck(this,b),c=_possibleConstructorReturn(this,_getPrototypeOf(b).call(this,a,!0)),c._cleanedValue=a,c}return _inherits(b,a),_createClass(b,[{key:"parse",value:function(a){for(var b=a.value(),c=a.valueIndex();cthis._size?b.substring(0,this._size):b.lengthb&&d--,+a.substring(c,d)}},{key:"scanValue",value:function(a,b){for(var c=a.valueIndex(),d=a.value(),e=0;cb&&c--;var f=d.substring(a.valueIndex(),c);return a.setValueIndex(c),f}},{key:"_defineParsingState",value:function(a,b){return 0=this._size||!b)?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):10*this._numericValue>a?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):void(this._state=AbstractSmartDatePart.STATE_INCOMPLETE)}},{key:"_defineCleanValue",value:function(){return this._cleanedValue="",this.isNoState()?void 0:this.isComplete()?void(this._cleanedValue=this.formatValue(this._numericValue)):void(0b.MAXIMAL_VALUE&&(this._numericValue=b.MAXIMAL_VALUE),this.isComplete()&&this._numericValue=this._size?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):void(this._state=AbstractSmartDatePart.STATE_INCOMPLETE)}},{key:"_defineCleanValue",value:function(){this._cleanedValue=0=this._value.length}},{key:"value",value:function(){return this._value}},{key:"valueIndex",value:function(){return this._valueIndex}},{key:"setValueIndex",value:function(a){this._valueIndexb||b>=SmartDateMonthPart.MAXIMAL_VALUE?SmartDateMonthPart.MAXIMAL_VALUE:1===b&&c?a.BASIC_MONTH_SIZES[b]+1:a.BASIC_MONTH_SIZES[b]}},{key:"_isLeaPYear",value:function(a){return 0==a%4&&(0!=a%100||0==a%400)}},{key:"getCorrectedValue",value:function(){for(var a=0,b="";athis._maximalDate.valueOf()){var a=this._minimalDate;this._minimalDate=this._maximalDate,this._maximalDate=a}null===this._defaultDate||(this._defaultDate.valueOf()this._maximalDate.valueOf()&&(this._defaultDate=this._maximalDate))}},{key:"_parseDateValue",value:function(a){if("object"===_typeof(a)&&null!==a&&a instanceof Date)return a;if("string"!=typeof a||""===a.trim())return null;var b=this._dateYmdParser.exec(a);return null===b?(b=this._dateDmyParser.exec(a),null===b?null:new Date(+b[3],+b[2]-1,+b[1])):new Date(+b[1],+b[2]-1,+b[3])}},{key:"_initField",value:function(a){this._field=a,this._field.placeholder=this._formatter.getPlaceHolder(),this._isEmptyValue(this._field.value)?this._field.value=null===this._defaultDate?"":this._formatter.formatDate(this._defaultDate):this.correctValue(!0)}},{key:"_subscribeEvents",value:function(){var a=this,b=function(b){(null===b||"keyup"!==b.type)&&a.correctValue(!0),a._isServiceCode(b.keyCode)||(27===b.keyCode&&a.returnLastCorrectValue(),a.correctValue(!0))};this._field.addEventListener("change",b),this._field.addEventListener("keyup",b),this._field.addEventListener("blur",function(){a.correctValue(!0),a._isEmptyValue(a._field.value)||a.returnLastCorrectValue()})}},{key:"_isServiceCode",value:function(a){return 8===a||46===a||16===a||17===a||18===a||20===a||35===a||36===a||37===a||39===a||46===a}},{key:"_isEmptyValue",value:function(a){return""===a.trim()}},{key:"getDefaultValue",value:function(){return null===this._defaultDate?"":this._formatter.formatDate(this._defaultDate)}},{key:"correctValue",value:function(a){this._formatter.parse(this._field.value,a);var b=this._getLimitedParsedValue();this._formatter.isComplete()&&(this._lastCorrectValue=b),this._field.value===b||this._setValueToField(b)}},{key:"setValue",value:function(a){var b=this._parseDateValue(a);null===b||b.valueOf()this._maximalDate.valueOf()||(this._lastCorrectValue=this._formatter.formatDate(b),this._field.value=this._lastCorrectValue)}},{key:"_getLimitedParsedValue",value:function(){if(!this._formatter.isComplete())return this._formatter.getCorrectedValue();var a=this._formatter.getParsedDate();return a.valueOf()this._maximalDate.valueOf()?this._formatter.formatDate(this._maximalDate):this._formatter.getCorrectedValue()}},{key:"_setValueToField",value:function(a){var b=this._field.selectionStart,c=b===this._field.value.length;this._field.value=a,!c&&b=a}check(a){return!1}}AbstractSmartDatePart.STATE_NONE=0,AbstractSmartDatePart.STATE_INCOMPLETE=1,AbstractSmartDatePart.STATE_COMPLETE=2;class SmartDateStaticPart extends AbstractSmartDatePart{constructor(a){super(a,!0),this._cleanedValue=a}parse(a){let b=a.value(),c=a.valueIndex();for(;cthis._size?b.substring(0,this._size):b.lengthb&&d--,+a.substring(c,d)}scanValue(a,b){let c=a.valueIndex(),d=a.value(),e=0;for(;cb&&c--;let f=d.substring(a.valueIndex(),c);return a.setValueIndex(c),f}_defineParsingState(a,b){return 0=this._size||!b)?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):10*this._numericValue>a?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):void(this._state=AbstractSmartDatePart.STATE_INCOMPLETE)}_defineCleanValue(){return this._cleanedValue="",this.isNoState()?void 0:this.isComplete()?void(this._cleanedValue=this.formatValue(this._numericValue)):void(0SmartDateYearPart.MAXIMAL_VALUE&&(this._numericValue=SmartDateYearPart.MAXIMAL_VALUE),this.isComplete()&&this._numericValue=this._size?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):void(this._state=AbstractSmartDatePart.STATE_INCOMPLETE)}_defineCleanValue(){this._cleanedValue=0=this._value.length}value(){return this._value}valueIndex(){return this._valueIndex}setValueIndex(a){this._valueIndexa||a>=SmartDateMonthPart.MAXIMAL_VALUE?SmartDateMonthPart.MAXIMAL_VALUE:1===a&&b?SmartDateFormat.BASIC_MONTH_SIZES[a]+1:SmartDateFormat.BASIC_MONTH_SIZES[a]}_isLeaPYear(a){return 0==a%4&&(0!=a%100||0==a%400)}getCorrectedValue(){let a=0,b="";for(;athis._maximalDate.valueOf()){let a=this._minimalDate;this._minimalDate=this._maximalDate,this._maximalDate=a}null===this._defaultDate||(this._defaultDate.valueOf()this._maximalDate.valueOf()&&(this._defaultDate=this._maximalDate))}_parseDateValue(a){if("object"==typeof a&&null!==a&&a instanceof Date)return a;if("string"!=typeof a||""===a.trim())return null;let b=this._dateYmdParser.exec(a);return null===b?(b=this._dateDmyParser.exec(a),null===b?null:new Date(+b[3],+b[2]-1,+b[1])):new Date(+b[1],+b[2]-1,+b[3])}_initField(a){this._field=a,this._field.placeholder=this._formatter.getPlaceHolder(),this._isEmptyValue(this._field.value)?this._field.value=null===this._defaultDate?"":this._formatter.formatDate(this._defaultDate):this.correctValue(!0)}_subscribeEvents(){let a=this,b=function(b){(null===b||"keyup"!==b.type)&&a.correctValue(!0);a._isServiceCode(b.keyCode)||(27===b.keyCode&&a.returnLastCorrectValue(),a.correctValue(!0))};this._field.addEventListener("change",b),this._field.addEventListener("keyup",b),this._field.addEventListener("blur",function(){a.correctValue(!0),a.returnLastCorrectValue()})}_isServiceCode(a){return 8===a||46===a||16===a||17===a||18===a||20===a||35===a||36===a||37===a||39===a||46===a}_isEmptyValue(a){return""===a.trim()}getDefaultValue(){return null===this._defaultDate?"":this._formatter.formatDate(this._defaultDate)}correctValue(a){this._formatter.parse(this._field.value,a);let b=this._getLimitedParsedValue();this._formatter.isComplete()&&(this._lastCorrectValue=b);this._field.value===b||this._setValueToFieled(b)}setValue(a){let b=this._parseDateValue(a);null===b||b.valueOf()this._maximalDate.valueOf()||(this._lastCorrectValue=this._formatter.formatDate(b),this._field.value=this._lastCorrectValue)}_getLimitedParsedValue(){if(!this._formatter.isComplete())return this._formatter.getCorrectedValue();let a=this._formatter.getParsedDate();if(a.valueOf()this._maximalDate.valueOf()?this._formatter.formatDate(this._maximalDate):this._formatter.getCorrectedValue()}_setValueToFieled(a){let b=this._field.selectionStart,c=b===this._field.value.length;this._field.value=a,!c&&b=a}check(a){return!1}}AbstractSmartDatePart.STATE_NONE=0,AbstractSmartDatePart.STATE_INCOMPLETE=1,AbstractSmartDatePart.STATE_COMPLETE=2;class SmartDateStaticPart extends AbstractSmartDatePart{constructor(a){super(a,!0),this._cleanedValue=a}parse(a){let b=a.value(),c=a.valueIndex();for(;cthis._size?b.substring(0,this._size):b.lengthb&&d--,+a.substring(c,d)}scanValue(a,b){let c=a.valueIndex(),d=a.value(),e=0;for(;cb&&c--;let f=d.substring(a.valueIndex(),c);return a.setValueIndex(c),f}_defineParsingState(a,b){return 0=this._size||!b)?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):10*this._numericValue>a?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):void(this._state=AbstractSmartDatePart.STATE_INCOMPLETE)}_defineCleanValue(){return this._cleanedValue="",this.isNoState()?void 0:this.isComplete()?void(this._cleanedValue=this.formatValue(this._numericValue)):void(0SmartDateYearPart.MAXIMAL_VALUE&&(this._numericValue=SmartDateYearPart.MAXIMAL_VALUE),this.isComplete()&&this._numericValue=this._size?void(this._state=AbstractSmartDatePart.STATE_COMPLETE):void(this._state=AbstractSmartDatePart.STATE_INCOMPLETE)}_defineCleanValue(){this._cleanedValue=0=this._value.length}value(){return this._value}valueIndex(){return this._valueIndex}setValueIndex(a){this._valueIndexa||a>=SmartDateMonthPart.MAXIMAL_VALUE?SmartDateMonthPart.MAXIMAL_VALUE:1===a&&b?SmartDateFormat.BASIC_MONTH_SIZES[a]+1:SmartDateFormat.BASIC_MONTH_SIZES[a]}_isLeaPYear(a){return 0==a%4&&(0!=a%100||0==a%400)}getCorrectedValue(){let a=0,b="";for(;athis._maximalDate.valueOf()){let a=this._minimalDate;this._minimalDate=this._maximalDate,this._maximalDate=a}null===this._defaultDate||(this._defaultDate.valueOf()this._maximalDate.valueOf()&&(this._defaultDate=this._maximalDate))}_parseDateValue(a){if("object"==typeof a&&null!==a&&a instanceof Date)return a;if("string"!=typeof a||""===a.trim())return null;let b=this._dateYmdParser.exec(a);return null===b?(b=this._dateDmyParser.exec(a),null===b?null:new Date(+b[3],+b[2]-1,+b[1])):new Date(+b[1],+b[2]-1,+b[3])}_initField(a){this._field=a,this._field.placeholder=this._formatter.getPlaceHolder(),this._isEmptyValue(this._field.value)?this._field.value=null===this._defaultDate?"":this._formatter.formatDate(this._defaultDate):this.correctValue(!0)}_subscribeEvents(){let a=this,b=function(b){(null===b||"keyup"!==b.type)&&a.correctValue(!0);a._isServiceCode(b.keyCode)||(27===b.keyCode&&a.returnLastCorrectValue(),a.correctValue(!0))};this._field.addEventListener("change",b),this._field.addEventListener("keyup",b),this._field.addEventListener("blur",function(){a.correctValue(!0),a._isEmptyValue(a._field.value)||a.returnLastCorrectValue()})}_isServiceCode(a){return 8===a||46===a||16===a||17===a||18===a||20===a||35===a||36===a||37===a||39===a||46===a}_isEmptyValue(a){return""===a.trim()}getDefaultValue(){return null===this._defaultDate?"":this._formatter.formatDate(this._defaultDate)}correctValue(a){this._formatter.parse(this._field.value,a);let b=this._getLimitedParsedValue();this._formatter.isComplete()&&(this._lastCorrectValue=b);this._field.value===b||this._setValueToField(b)}setValue(a){let b=this._parseDateValue(a);null===b||b.valueOf()this._maximalDate.valueOf()||(this._lastCorrectValue=this._formatter.formatDate(b),this._field.value=this._lastCorrectValue)}_getLimitedParsedValue(){if(!this._formatter.isComplete())return this._formatter.getCorrectedValue();let a=this._formatter.getParsedDate();if(a.valueOf()this._maximalDate.valueOf()?this._formatter.formatDate(this._maximalDate):this._formatter.getCorrectedValue()}_setValueToField(a){let b=this._field.selectionStart,c=b===this._field.value.length;this._field.value=a,!c&&b