Comparing version 2.0.0 to 3.0.0-next
@@ -19,8 +19,2 @@ 'use strict'; | ||
var _lodash = require('lodash'); | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
var _BrowserDetection = require('./utils/BrowserDetection'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -36,14 +30,4 @@ | ||
function isTextField(target) { | ||
return target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement; | ||
} | ||
function createFormControl(Component) { | ||
// if now is in composition session | ||
var isOnComposition = false; | ||
// for safari use only, innervalue can't setState when compositionend occurred | ||
var isInnerChangeFromOnChange = false; | ||
var propTypes = { | ||
@@ -59,14 +43,8 @@ /*eslint-disable */ | ||
function FormControl(props, context) { | ||
function FormControl(props) { | ||
_classCallCheck(this, FormControl); | ||
var _this = _possibleConstructorReturn(this, (FormControl.__proto__ || Object.getPrototypeOf(FormControl)).call(this, props, context)); | ||
var _this = _possibleConstructorReturn(this, (FormControl.__proto__ || Object.getPrototypeOf(FormControl)).call(this, props)); | ||
var value = props.value || props.defaultValue || ''; | ||
_this.state = { | ||
inputValue: value, | ||
innerValue: value | ||
}; | ||
_this.handleChange = _this.handleChange.bind(_this); | ||
_this.handleComposition = _this.handleComposition.bind(_this); | ||
return _this; | ||
@@ -76,93 +54,10 @@ } | ||
_createClass(FormControl, [{ | ||
key: 'componentWillReceiveProps', | ||
value: function componentWillReceiveProps(nextProps) { | ||
if (!_lodash2.default.isEqual(nextProps.value, this.props.value)) { | ||
this.state = { | ||
inputValue: nextProps.value, | ||
innerValue: nextProps.value | ||
}; | ||
} | ||
} | ||
}, { | ||
key: 'handleChange', | ||
value: function handleChange(e) { | ||
var _props$onChange = this.props.onChange, | ||
onChange = _props$onChange === undefined ? function () {} : _props$onChange; | ||
var onChange = this.props.onChange; | ||
var value = e.target.value; | ||
// Flow check | ||
if (!isTextField(e.target)) { | ||
onChange(value, e); | ||
return; | ||
} | ||
if (isInnerChangeFromOnChange) { | ||
this.setState({ | ||
inputValue: value, | ||
innerValue: value | ||
}); | ||
onChange(value, e); | ||
isInnerChangeFromOnChange = false; | ||
return; | ||
} | ||
// when is on composition, change inputValue only | ||
// when not in composition change inputValue and innerValue both | ||
if (!isOnComposition) { | ||
this.setState({ | ||
inputValue: value, | ||
innerValue: value | ||
}); | ||
onChange(value, e); | ||
} else { | ||
this.setState({ inputValue: value }); | ||
} | ||
onChange && onChange(value, e); | ||
} | ||
/* istanbul ignore next */ | ||
}, { | ||
key: 'handleComposition', | ||
value: function handleComposition(e) { | ||
var _props$onChange2 = this.props.onChange, | ||
onChange = _props$onChange2 === undefined ? function () {} : _props$onChange2; | ||
// Flow check | ||
if (!isTextField(e.target)) { | ||
return; | ||
} | ||
if (e.type === 'compositionend') { | ||
var value = e.target.value; | ||
// Chrome is ok for only setState innerValue | ||
// Opera, IE and Edge is like Chrome | ||
if (_BrowserDetection.isChrome || _BrowserDetection.isIE || _BrowserDetection.isEdge || _BrowserDetection.isOpera) { | ||
this.setState({ innerValue: value }); | ||
onChange(value, e); | ||
} | ||
// Firefox need to setState inputValue again... | ||
if (_BrowserDetection.isFirefox) { | ||
this.setState({ | ||
innerValue: value, | ||
inputValue: value | ||
}); | ||
onChange(value, e); | ||
} | ||
// Safari think e.target.value in composition event is keyboard char, | ||
// but it will fired another change after compositionend | ||
if (_BrowserDetection.isSafari) { | ||
// do change in the next change event | ||
isInnerChangeFromOnChange = true; | ||
} | ||
isOnComposition = false; | ||
} else { | ||
isOnComposition = true; | ||
} | ||
} | ||
}, { | ||
key: 'render', | ||
@@ -172,14 +67,6 @@ value: function render() { | ||
className = _props.className, | ||
value = _props.value, | ||
props = _objectWithoutProperties(_props, ['className', 'value']); | ||
props = _objectWithoutProperties(_props, ['className']); | ||
if (!_lodash2.default.isUndefined(value)) { | ||
props.value = this.state.inputValue; | ||
} | ||
return _react2.default.createElement(Component, _extends({}, props, { | ||
className: 'form-control ' + (className || ''), | ||
onCompositionStart: this.handleComposition, | ||
onCompositionUpdate: this.handleComposition, | ||
onCompositionEnd: this.handleComposition, | ||
onChange: this.handleChange | ||
@@ -186,0 +73,0 @@ })); |
@@ -19,6 +19,14 @@ 'use strict'; | ||
var _lodash = require('lodash'); | ||
var _debounce = require('lodash/debounce'); | ||
var _lodash2 = _interopRequireDefault(_lodash); | ||
var _debounce2 = _interopRequireDefault(_debounce); | ||
var _isEqual = require('lodash/isEqual'); | ||
var _isEqual2 = _interopRequireDefault(_isEqual); | ||
var _omit = require('lodash/omit'); | ||
var _omit2 = _interopRequireDefault(_omit); | ||
var _rsuiteSchema = require('rsuite-schema'); | ||
@@ -95,4 +103,4 @@ | ||
_this.handleFieldChange = _this.handleFieldChange.bind(_this); | ||
_this.handleFieldError = _lodash2.default.debounce(_this.handleFieldError.bind(_this), props.checkDelay); | ||
_this.handleFieldSuccess = _lodash2.default.debounce(_this.handleFieldSuccess.bind(_this), props.checkDelay); | ||
_this.handleFieldError = (0, _debounce2.default)(_this.handleFieldError.bind(_this), props.checkDelay); | ||
_this.handleFieldSuccess = (0, _debounce2.default)(_this.handleFieldSuccess.bind(_this), props.checkDelay); | ||
_this.check = _this.check.bind(_this); | ||
@@ -129,3 +137,3 @@ return _this; | ||
value: function componentWillReceiveProps(nextProps) { | ||
if (!_lodash2.default.isEqual(nextProps.errors, this.props.errors)) { | ||
if (!(0, _isEqual2.default)(nextProps.errors, this.props.errors)) { | ||
this.setState({ | ||
@@ -136,3 +144,3 @@ errors: nextProps.errors | ||
if (!_lodash2.default.isEqual(nextProps.values, this.props.values)) { | ||
if (!(0, _isEqual2.default)(nextProps.values, this.props.values)) { | ||
this.setState({ | ||
@@ -258,3 +266,3 @@ values: nextProps.values | ||
var elementProps = _lodash2.default.omit(props, Object.keys(propTypes)); | ||
var elementProps = (0, _omit2.default)(props, Object.keys(propTypes)); | ||
@@ -261,0 +269,0 @@ return _react2.default.createElement('form', _extends({}, elementProps, { |
@@ -19,5 +19,3 @@ 'use strict'; | ||
/*eslint-disable */ | ||
// Internet Explorer 6-11 | ||
var isIE = /*@cc_on!@*/exports.isIE = false || !!document.documentMode; | ||
var isIE = exports.isIE = !!navigator.userAgent.match(/MSIE/); | ||
@@ -24,0 +22,0 @@ // Edge 20+ |
{ | ||
"name": "form-lib", | ||
"version": "2.0.0", | ||
"version": "3.0.0-next", | ||
"description": "Form component for React", | ||
@@ -32,2 +32,3 @@ "main": "lib/index.js", | ||
"CHANGELOG.md", | ||
"src", | ||
"lib" | ||
@@ -58,2 +59,3 @@ ], | ||
"babel-preset-stage-0": "^6.5.0", | ||
"brfs": "^1.4.3", | ||
"chai": "^4.1.0", | ||
@@ -90,12 +92,12 @@ "coveralls": "^2.13.1", | ||
"mocha": "^2.5.3", | ||
"react": "^0.14.9", | ||
"react": "15.6.2", | ||
"react-code-view": "^1.0.12", | ||
"react-dom": "^0.14.9", | ||
"react-dom": "15.6.2", | ||
"react-hot-loader": "^3.0.0-beta.6", | ||
"react-markdown-reader": "^1.0.1", | ||
"rsuite": "1.1.3", | ||
"rsuite": "^2.0.12", | ||
"rsuite-docs": "^0.2.2", | ||
"rsuite-schema": ">=0.0.4", | ||
"rsuite-schema": "^0.0.10", | ||
"rsuite-selectpicker": "^1.0.1", | ||
"rsuite-theme": "^2.0.16", | ||
"rsuite-theme": "^2.0.19", | ||
"sinon": "^1.17.4", | ||
@@ -102,0 +104,0 @@ "sinon-chai": "^2.8.0", |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
37232
14
764
58
2