Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- d = function(e) {
- function t(e, n) {
- i(this, t);
- var r = a(this, (t.__proto__ || Object.getPrototypeOf(t)).call(this, e, n)),
- o = r.props.hasOwnProperty("value") ? r.props.value : r.props.defaultValue;
- return r.state = {
- value: o,
- prevPropsValue: r.props.defaultValue,
- formattedValue: r._formatValue(o),
- hasBeenModified: !1
- }, r._onBlur = r._onBlur.bind(r), r._onEdit = r._onEdit.bind(r), r._onFocus = r._onFocus.bind(r), r._onKeydown = r._onKeydown.bind(r), r.clear = r.clear.bind(r), r.set = r.set.bind(r), r.selectAll = r.selectAll.bind(r), r
- }
- return o(t, e), s(t, [{
- key: "componentWillReceiveProps",
- value: function(e) {
- void 0 !== e.defaultValue && e.defaultValue !== this.props.defaultValue && e.defaultValue !== this.state.value && (null !== this.state.value && this.state.value !== this.props.defaultValue || (this.setState({
- value: e.defaultValue
- }), e.defaultValue !== this.state.prevPropsValue && this.setState({
- prevPropsValue: e.defaultValue,
- formattedValue: this._formatValue(e.defaultValue)
- }))), e.value !== this.props.value && this.setState({
- value: e.value,
- formattedValue: this._formatValue(e.value)
- })
- }
- }, {
- key: "componentDidUpdate",
- value: function(e, t) {
- t.value !== this.state.value && this.props.onChange && this.props.onChange(this.state.value, this.state.formattedValue)
- }
- }, {
- key: "componentWillUnmount",
- value: function() {
- this.props.onBlur && this.props.onBlur()
- }
- }, {
- key: "_formatValue",
- value: function(e) {
- return void 0 === e || null === e ? "" : this.props.formatter(e)
- }
- }, {
- key: "_onEdit",
- value: function(e) {
- e.stopPropagation(), e.nativeEvent.stopPropagation();
- var t = e.nativeEvent.target.value;
- "." === t && (t = "0.");
- var n = null;
- "" !== t && (n = parseFloat(t));
- var r = this.props.value ? this.props.value : this.state.value;
- n = this._checkValAgainstMinMax(r, n), null !== n && isNaN(n) || this.setState({
- value: n,
- formattedValue: t,
- orderOfMagnitude: c.default.orderOfMagnitude(n),
- hasBeenModified: !0
- })
- }
- }, {
- key: "_onFocus",
- value: function(e) {
- this.setState({
- focused: !0
- }), this.props.onFocus && this.props.onFocus(e, this)
- }
- }, {
- key: "_onBlur",
- value: function(e) {
- var t = void 0,
- n = void 0,
- r = !1,
- i = !1;
- if (null !== this.state.value) {
- if (void 0 === this.state.value || isNaN(this.state.value)) t = this.props.defaultValue, n = this._formatValue(this.props.defaultValue), i = r = !0;
- else if (t = this.state.value, n = this._formatValue(this.state.value), this.props.getRange) {
- var a = this.props.getRange();
- if (a) {
- var o = a.clip(t);
- o !== t && (t = o, n = this._formatValue(o), i = !0)
- }
- } else if (this.props.hasOwnProperty("min") && this.props.hasOwnProperty("max")) {
- var s = new f.default(this.props.min, this.props.max),
- l = s.clip(t);
- l !== t && (t = l, n = this._formatValue(l), i = !0)
- }
- } else t = this.props.defaultValue, n = this._formatValue(this.props.defaultValue), i = r = !0;
- this.setState({
- focused: !1,
- value: t,
- orderOfMagnitude: c.default.orderOfMagnitude(t),
- formattedValue: n,
- hasBeenModified: r === !1
- }), r && this.props.onChange && this.props.onChange(this.props.defaultValue), this.props.onBlur && this.props.onBlur(e)
- }
- }, {
- key: "clear",
- value: function() {
- this.set(null)
- }
- }, {
- key: "set",
- value: function(e) {
- e === 1 / 0 && (e = 0, t = "-"), this.props.getRange && this.props.getRange(), e = this._checkValAgainstMinMax(this.state.value, e);
- var t = this._formatValue(e);
- this.setState({
- value: e,
- orderOfMagnitude: c.default.orderOfMagnitude(e),
- formattedValue: t,
- hasBeenModified: !0
- }), this._calculateIncrements()
- }
- }, {
- key: "focus",
- value: function() {
- var e = ReactDOM.findDOMNode(this.refs.input);
- e && e.focus()
- }
- }, {
- key: "selectAll",
- value: function() {
- ReactDOM.findDOMNode(this.refs.input).select()
- }
- }, {
- key: "_onKeydown",
- value: function(e) {
- switch (e.stopPropagation(), e.which) {
- case 13:
- this.props.onEnter && this.props.onEnter(this.state.value);
- break;
- case 38:
- e.altKey ? this.increment(this.getIncrementAlt()) : this.increment(this.getIncrementMain());
- break;
- case 40:
- e.altKey ? this.increment(-this.getIncrementAlt()) : this.increment(-this.getIncrementMain())
- }
- }
- }, {
- key: "getIncrementMain",
- value: function() {
- return this.props.increment ? this.props.increment : (this.props.incrementMain || this._calculateIncrements(), this.state.incrementMain)
- }
- }, {
- key: "getIncrementAlt",
- value: function() {
- return this.props.increment ? this.props.increment : (this.props.incrementAlt || this._calculateIncrements(), this.state.incrementAlt)
- }
- }, {
- key: "increment",
- value: function(e) {
- var t = this.props.hasOwnProperty("value") ? this.props.value : this.state.value;
- if (null !== t) {
- var n = t + e,
- r = c.default.toLongerPrecision(n, e, t);
- r = this._checkValAgainstMinMax(this.state.value, r), this.set(r)
- }
- }
- }, {
- key: "_onKeyUp",
- value: function(e) {
- switch (e.stopPropagation(), e.which) {
- case 38:
- case 40:
- this._calculateIncrements()
- }
- }
- }, {
- key: "_calculateIncrements",
- value: function() {
- if (this.props.incrementAlt) return this.props.incrementAlt;
- var e = c.default.orderOfMagnitude(this.state.value);
- this.state.incrementMain = e / 100, this.state.incrementAlt = e / 1e3
- }
- }, {
- key: "_checkValAgainstMinMax",
- value: function(e, t) {
- return this.props.hasOwnProperty("min") && t < this.props.min ? e : this.props.hasOwnProperty("max") && t > this.props.max ? e : t
- }
- }, {
- key: "render",
- value: function() {
- return React.createElement("input", {
- ref: "input",
- type: "text",
- style: this.props.style,
- className: this.props.className,
- id: this.props.id,
- value: this.state.formattedValue || "",
- onChange: this._onEdit,
- onKeyDown: this._onKeydown.bind(this),
- onKeyUp: this._onKeyUp.bind(this),
- onFocus: this._onFocus,
- onBlur: this._onBlur,
- tabIndex: this.props.tabindex
- })
- }
- }]), t
- }(React.Component);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement