Advertisement
Guest User

Untitled

a guest
Dec 8th, 2017
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         d = function(e) {
  2.             function t(e, n) {
  3.                 i(this, t);
  4.                 var r = a(this, (t.__proto__ || Object.getPrototypeOf(t)).call(this, e, n)),
  5.                     o = r.props.hasOwnProperty("value") ? r.props.value : r.props.defaultValue;
  6.                 return r.state = {
  7.                     value: o,
  8.                     prevPropsValue: r.props.defaultValue,
  9.                     formattedValue: r._formatValue(o),
  10.                     hasBeenModified: !1
  11.                 }, 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
  12.             }
  13.             return o(t, e), s(t, [{
  14.                 key: "componentWillReceiveProps",
  15.                 value: function(e) {
  16.                     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({
  17.                         value: e.defaultValue
  18.                     }), e.defaultValue !== this.state.prevPropsValue && this.setState({
  19.                         prevPropsValue: e.defaultValue,
  20.                         formattedValue: this._formatValue(e.defaultValue)
  21.                     }))), e.value !== this.props.value && this.setState({
  22.                         value: e.value,
  23.                         formattedValue: this._formatValue(e.value)
  24.                     })
  25.                 }
  26.             }, {
  27.                 key: "componentDidUpdate",
  28.                 value: function(e, t) {
  29.                     t.value !== this.state.value && this.props.onChange && this.props.onChange(this.state.value, this.state.formattedValue)
  30.                 }
  31.             }, {
  32.                 key: "componentWillUnmount",
  33.                 value: function() {
  34.                     this.props.onBlur && this.props.onBlur()
  35.                 }
  36.             }, {
  37.                 key: "_formatValue",
  38.                 value: function(e) {
  39.                     return void 0 === e || null === e ? "" : this.props.formatter(e)
  40.                 }
  41.             }, {
  42.                 key: "_onEdit",
  43.                 value: function(e) {
  44.                     e.stopPropagation(), e.nativeEvent.stopPropagation();
  45.                     var t = e.nativeEvent.target.value;
  46.                     "." === t && (t = "0.");
  47.                     var n = null;
  48.                     "" !== t && (n = parseFloat(t));
  49.                     var r = this.props.value ? this.props.value : this.state.value;
  50.                     n = this._checkValAgainstMinMax(r, n), null !== n && isNaN(n) || this.setState({
  51.                         value: n,
  52.                         formattedValue: t,
  53.                         orderOfMagnitude: c.default.orderOfMagnitude(n),
  54.                         hasBeenModified: !0
  55.                     })
  56.                 }
  57.             }, {
  58.                 key: "_onFocus",
  59.                 value: function(e) {
  60.                     this.setState({
  61.                         focused: !0
  62.                     }), this.props.onFocus && this.props.onFocus(e, this)
  63.                 }
  64.             }, {
  65.                 key: "_onBlur",
  66.                 value: function(e) {
  67.                     var t = void 0,
  68.                         n = void 0,
  69.                         r = !1,
  70.                         i = !1;
  71.                     if (null !== this.state.value) {
  72.                         if (void 0 === this.state.value || isNaN(this.state.value)) t = this.props.defaultValue, n = this._formatValue(this.props.defaultValue), i = r = !0;
  73.                         else if (t = this.state.value, n = this._formatValue(this.state.value), this.props.getRange) {
  74.                             var a = this.props.getRange();
  75.                             if (a) {
  76.                                 var o = a.clip(t);
  77.                                 o !== t && (t = o, n = this._formatValue(o), i = !0)
  78.                             }
  79.                         } else if (this.props.hasOwnProperty("min") && this.props.hasOwnProperty("max")) {
  80.                             var s = new f.default(this.props.min, this.props.max),
  81.                                 l = s.clip(t);
  82.                             l !== t && (t = l, n = this._formatValue(l), i = !0)
  83.                         }
  84.                     } else t = this.props.defaultValue, n = this._formatValue(this.props.defaultValue), i = r = !0;
  85.                     this.setState({
  86.                         focused: !1,
  87.                         value: t,
  88.                         orderOfMagnitude: c.default.orderOfMagnitude(t),
  89.                         formattedValue: n,
  90.                         hasBeenModified: r === !1
  91.                     }), r && this.props.onChange && this.props.onChange(this.props.defaultValue), this.props.onBlur && this.props.onBlur(e)
  92.                 }
  93.             }, {
  94.                 key: "clear",
  95.                 value: function() {
  96.                     this.set(null)
  97.                 }
  98.             }, {
  99.                 key: "set",
  100.                 value: function(e) {
  101.                     e === 1 / 0 && (e = 0, t = "-"), this.props.getRange && this.props.getRange(), e = this._checkValAgainstMinMax(this.state.value, e);
  102.                     var t = this._formatValue(e);
  103.                     this.setState({
  104.                         value: e,
  105.                         orderOfMagnitude: c.default.orderOfMagnitude(e),
  106.                         formattedValue: t,
  107.                         hasBeenModified: !0
  108.                     }), this._calculateIncrements()
  109.                 }
  110.             }, {
  111.                 key: "focus",
  112.                 value: function() {
  113.                     var e = ReactDOM.findDOMNode(this.refs.input);
  114.                     e && e.focus()
  115.                 }
  116.             }, {
  117.                 key: "selectAll",
  118.                 value: function() {
  119.                     ReactDOM.findDOMNode(this.refs.input).select()
  120.                 }
  121.             }, {
  122.                 key: "_onKeydown",
  123.                 value: function(e) {
  124.                     switch (e.stopPropagation(), e.which) {
  125.                         case 13:
  126.                             this.props.onEnter && this.props.onEnter(this.state.value);
  127.                             break;
  128.                         case 38:
  129.                             e.altKey ? this.increment(this.getIncrementAlt()) : this.increment(this.getIncrementMain());
  130.                             break;
  131.                         case 40:
  132.                             e.altKey ? this.increment(-this.getIncrementAlt()) : this.increment(-this.getIncrementMain())
  133.                     }
  134.                 }
  135.             }, {
  136.                 key: "getIncrementMain",
  137.                 value: function() {
  138.                     return this.props.increment ? this.props.increment : (this.props.incrementMain || this._calculateIncrements(), this.state.incrementMain)
  139.                 }
  140.             }, {
  141.                 key: "getIncrementAlt",
  142.                 value: function() {
  143.                     return this.props.increment ? this.props.increment : (this.props.incrementAlt || this._calculateIncrements(), this.state.incrementAlt)
  144.                 }
  145.             }, {
  146.                 key: "increment",
  147.                 value: function(e) {
  148.                     var t = this.props.hasOwnProperty("value") ? this.props.value : this.state.value;
  149.                     if (null !== t) {
  150.                         var n = t + e,
  151.                             r = c.default.toLongerPrecision(n, e, t);
  152.                         r = this._checkValAgainstMinMax(this.state.value, r), this.set(r)
  153.                     }
  154.                 }
  155.             }, {
  156.                 key: "_onKeyUp",
  157.                 value: function(e) {
  158.                     switch (e.stopPropagation(), e.which) {
  159.                         case 38:
  160.                         case 40:
  161.                             this._calculateIncrements()
  162.                     }
  163.                 }
  164.             }, {
  165.                 key: "_calculateIncrements",
  166.                 value: function() {
  167.                     if (this.props.incrementAlt) return this.props.incrementAlt;
  168.                     var e = c.default.orderOfMagnitude(this.state.value);
  169.                     this.state.incrementMain = e / 100, this.state.incrementAlt = e / 1e3
  170.                 }
  171.             }, {
  172.                 key: "_checkValAgainstMinMax",
  173.                 value: function(e, t) {
  174.                     return this.props.hasOwnProperty("min") && t < this.props.min ? e : this.props.hasOwnProperty("max") && t > this.props.max ? e : t
  175.                 }
  176.             }, {
  177.                 key: "render",
  178.                 value: function() {
  179.                     return React.createElement("input", {
  180.                         ref: "input",
  181.                         type: "text",
  182.                         style: this.props.style,
  183.                         className: this.props.className,
  184.                         id: this.props.id,
  185.                         value: this.state.formattedValue || "",
  186.                         onChange: this._onEdit,
  187.                         onKeyDown: this._onKeydown.bind(this),
  188.                         onKeyUp: this._onKeyUp.bind(this),
  189.                         onFocus: this._onFocus,
  190.                         onBlur: this._onBlur,
  191.                         tabIndex: this.props.tabindex
  192.                     })
  193.                 }
  194.             }]), t
  195.         }(React.Component);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement