x25 5.1.11 → 5.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,7 +7,27 @@ exports.DateInput = undefined;
7
7
 
8
8
  var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
9
9
 
10
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
10
+ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); /* eslint-disable react/no-unsafe */
11
+
12
+ // type DateInputPropTypes = {
13
+ // readonly customClass?: any;
14
+ // readonly input: any;
15
+ // readonly meta: {
16
+ // error?: string;
17
+ // submitting: boolean;
18
+ // touched: boolean;
19
+ // };
20
+ // readonly placeholder?: string;
21
+ // readonly value?: string;
22
+ // readonly tabIndex?: string;
23
+ // readonly currency?: boolean;
24
+ // readonly formatValue: (raw: string) => string;
25
+ // readonly normalizeValue: (raw: string) => any;
26
+ // readonly onBlur?: () => void;
27
+ // readonly onChange?: (event: any) => void;
28
+ // readonly onRegisterRef?: (callback: (node: any) => void) => void;
29
+ // }
30
+
11
31
 
12
32
  var _react = require("react");
13
33
 
@@ -19,30 +39,44 @@ var _classnames2 = _interopRequireDefault(_classnames);
19
39
 
20
40
  var _utility = require("../utility");
21
41
 
42
+ var _validation = require("../utility/validation");
43
+
22
44
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
45
 
24
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
46
+ var addZeroIfNeeded = function addZeroIfNeeded(raw) {
25
47
 
26
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
48
+ var nrOfElements = 3,
49
+ canAddZero = typeof raw === "string" && raw.split(".").length === nrOfElements;
27
50
 
28
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
29
- /* eslint-disable */
51
+ if (!canAddZero) {
52
+ return raw;
53
+ }
30
54
 
31
- var normalizeRawDate = function normalizeRawDate(raw) {
55
+ var perform = function perform(value) {
56
+ return value.length === 1 ? "0" + value : value;
57
+ },
58
+ parts = raw.split("."),
59
+ part1 = perform(parts[0]),
60
+ part2 = perform(parts[1]),
61
+ _parts = _slicedToArray(parts, 3),
62
+ part3 = _parts[2],
63
+ newValue = [part1, part2, part3].join(".");
32
64
 
33
- /* eslint-disable no-magic-numbers */
34
65
 
35
- if ((0, _utility.isValidDate)(raw)) {
36
- return (0, _utility.normalizeDate)(raw);
66
+ if ((0, _validation.isValidDate)(newValue)) {
67
+ return newValue;
37
68
  }
38
69
 
39
70
  return raw;
40
- };
41
-
42
- var formatRawDate = function formatRawDate(raw) {
43
-
44
- /* eslint-disable no-magic-numbers */
71
+ },
72
+ normalizeRawDate = function normalizeRawDate(raw) {
73
+ if ((0, _validation.isValidDate)(raw)) {
74
+ return (0, _utility.normalizeDate)(raw);
75
+ }
45
76
 
77
+ return "";
78
+ },
79
+ formatRawDate = function formatRawDate(raw) {
46
80
  if (typeof raw !== "undefined") {
47
81
  return (0, _utility.formatDate)(raw);
48
82
  }
@@ -50,123 +84,57 @@ var formatRawDate = function formatRawDate(raw) {
50
84
  return "";
51
85
  };
52
86
 
53
- var DateInput = exports.DateInput = function (_React$Component) {
54
- _inherits(DateInput, _React$Component);
55
-
56
- function DateInput(props) {
57
- _classCallCheck(this, DateInput);
58
-
59
- var _this = _possibleConstructorReturn(this, (DateInput.__proto__ || Object.getPrototypeOf(DateInput)).call(this));
60
-
61
- _this.state = {
62
- value: formatRawDate(props.input.value)
63
- };
64
-
65
- _this.handleKeyDown = function (event) {
66
- if (event.key === "Enter") {
67
- _this.handleBlur();
68
- }
69
- };
70
-
71
- _this.handleBlur = function () {
72
- var onBlur = _this.props.input.onBlur;
73
- var _this$props = _this.props,
74
- input = _this$props.input,
75
- normalizeValue = _this$props.normalizeValue;
76
- var currentValue = _this.state.value;
77
-
78
-
79
- var normalizedValue = normalizeValue(currentValue),
80
- shouldRenderAgain = normalizedValue !== "" && currentValue !== normalizedValue;
81
-
82
- input.onChange(normalizedValue);
83
-
84
- /*
85
- * Swallow the event to prevent Redux Form from
86
- * extracting the form value
87
- */
88
- onBlur();
89
-
90
- if (shouldRenderAgain) {
91
- _this.setState({
92
- value: (0, _utility.formatDate)(normalizedValue)
93
- });
94
- }
95
- };
96
-
97
- _this.handleChange = function (_ref) {
98
- var value = _ref.target.value;
99
-
100
- _this.props.input.onChange();
101
-
102
- /*
103
- * Update the internal state to trigger a re-render
104
- * using the formatted value
105
- */
106
- _this.setState({ value: value });
107
- };
108
- return _this;
109
- }
110
-
111
- _createClass(DateInput, [{
112
- key: "UNSAFE_componentWillReceiveProps",
113
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
114
- var newValue = nextProps.input.value;
115
- var currentValue = this.state.value;
116
-
117
-
118
- var shouldRenderAgain = (0, _utility.isValidDate)(newValue) && currentValue !== newValue;
119
-
120
- if (newValue === "") {
121
- this.setState({
122
- value: ""
123
- });
124
- }
125
-
126
- if (shouldRenderAgain) {
127
- this.setState({
128
- value: (0, _utility.formatDate)(newValue)
129
- });
130
- }
131
- }
132
- }, {
133
- key: "render",
134
- value: function render() {
135
- var _props = this.props,
136
- customClass = _props.customClass,
137
- input = _props.input,
138
- onRegisterRef = _props.onRegisterRef,
139
- _props$meta = _props.meta,
140
- submitting = _props$meta.submitting,
141
- touched = _props$meta.touched,
142
- error = _props$meta.error,
143
- tabIndex = _props.tabIndex,
144
- formatValue = _props.formatValue,
145
- placeholder = _props.placeholder;
146
-
147
-
148
- return _react2.default.createElement("input", _extends({}, input, {
149
- className: (0, _classnames2.default)("form-control " + (customClass || ""), {
150
- "is-invalid": touched && error
151
- }),
152
- disabled: submitting,
153
- id: input.name,
154
- onBlur: this.handleBlur,
155
- onChange: this.handleChange,
156
- onKeyDown: this.handleKeyDown,
157
- placeholder: placeholder || "ZZ.LL.ANUL",
158
- ref: onRegisterRef,
159
- tabIndex: tabIndex,
160
- type: "text",
161
- value: formatValue(this.state.value)
162
- }));
87
+ // eslint-disable-next-line no-undef
88
+ var DateInput = exports.DateInput = function DateInput(props) {
89
+ var customClass = props.customClass,
90
+ input = props.input,
91
+ onRegisterRef = props.onRegisterRef,
92
+ tabIndex = props.tabIndex,
93
+ placeholder = props.placeholder,
94
+ _props$meta = props.meta,
95
+ submitting = _props$meta.submitting,
96
+ touched = _props$meta.touched,
97
+ error = _props$meta.error,
98
+ _React$useState = _react2.default.useState(input.value),
99
+ _React$useState2 = _slicedToArray(_React$useState, 2),
100
+ value = _React$useState2[0],
101
+ setValue = _React$useState2[1],
102
+ valueToShow = formatRawDate(value),
103
+ updateValue = function updateValue(targetValue) {
104
+
105
+ var normalizedValue = normalizeRawDate(addZeroIfNeeded(targetValue));
106
+
107
+ setValue(targetValue);
108
+ props.input.onChange(normalizedValue);
109
+ },
110
+ handleBlur = function handleBlur(_ref) {
111
+ var targetValue = _ref.target.value;
112
+
113
+ var newValue = addZeroIfNeeded(targetValue),
114
+ hasChanged = targetValue !== newValue;
115
+
116
+ if (hasChanged) {
117
+ updateValue(newValue);
163
118
  }
164
- }]);
165
-
166
- return DateInput;
167
- }(_react2.default.Component);
168
-
169
- DateInput.defaultProps = {
170
- formatValue: formatRawDate,
171
- normalizeValue: normalizeRawDate
119
+ },
120
+ handleChange = function handleChange(_ref2) {
121
+ var targetValue = _ref2.target.value;
122
+
123
+ updateValue(targetValue);
124
+ };
125
+
126
+ return _react2.default.createElement("input", _extends({}, input, {
127
+ className: (0, _classnames2.default)("form-control " + (customClass || ""), {
128
+ "is-invalid": touched && error
129
+ }),
130
+ disabled: submitting,
131
+ id: input.name,
132
+ onBlur: handleBlur,
133
+ onChange: handleChange,
134
+ placeholder: placeholder || _utility.words.DateFormat,
135
+ ref: onRegisterRef,
136
+ tabIndex: tabIndex,
137
+ type: "text",
138
+ value: valueToShow
139
+ }));
172
140
  };
@@ -3,11 +3,32 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.DateTemplate = undefined;
6
+ exports.DateInput = undefined;
7
7
 
8
8
  var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
9
9
 
10
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
10
+ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); // type DateInputPropTypes = {
11
+ // readonly customClass?: any;
12
+ // readonly input: any;
13
+ // readonly meta: {
14
+ // error?: string;
15
+ // submitting: boolean;
16
+ // touched: boolean;
17
+ // };
18
+ // readonly placeholder?: string;
19
+ // readonly value?: string;
20
+ // readonly tabIndex?: string;
21
+ // readonly currency?: boolean;
22
+ // readonly formatValue: (raw: string) => string;
23
+ // readonly normalizeValue: (raw: string) => any;
24
+ // readonly onBlur?: () => void;
25
+ // readonly onChange?: (event: any) => void;
26
+ // readonly onRegisterRef?: (callback: (node: any) => void) => void;
27
+ // right?: string;
28
+ // left?: string;
29
+ // label:string;
30
+ // }
31
+
11
32
 
12
33
  var _react = require("react");
13
34
 
@@ -19,30 +40,43 @@ var _classnames2 = _interopRequireDefault(_classnames);
19
40
 
20
41
  var _utility = require("../utility");
21
42
 
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
43
+ var _validation = require("../utility/validation");
23
44
 
24
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
45
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
46
 
26
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
47
+ var addZeroIfNeeded = function addZeroIfNeeded(raw) {
48
+ var nrOfElements = 3,
49
+ canAddZero = typeof raw === "string" && raw.split(".").length === nrOfElements;
27
50
 
28
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
29
- /* eslint-disable */
51
+ if (!canAddZero) {
52
+ return raw;
53
+ }
30
54
 
31
- var normalizeRawDate = function normalizeRawDate(raw) {
55
+ var perform = function perform(value) {
56
+ return value.length === 1 ? "0" + value : value;
57
+ },
58
+ parts = raw.split("."),
59
+ part1 = perform(parts[0]),
60
+ part2 = perform(parts[1]),
61
+ _parts = _slicedToArray(parts, 3),
62
+ part3 = _parts[2],
63
+ newValue = [part1, part2, part3].join(".");
32
64
 
33
- /* eslint-disable no-magic-numbers */
34
65
 
35
- if ((0, _utility.isValidDate)(raw)) {
36
- return (0, _utility.normalizeDate)(raw);
66
+ if ((0, _validation.isValidDate)(newValue)) {
67
+ return newValue;
37
68
  }
38
69
 
39
70
  return raw;
40
- };
41
-
42
- var formatRawDate = function formatRawDate(raw) {
43
-
44
- /* eslint-disable no-magic-numbers */
71
+ },
72
+ normalizeRawDate = function normalizeRawDate(raw) {
73
+ if ((0, _validation.isValidDate)(raw)) {
74
+ return (0, _utility.normalizeDate)(raw);
75
+ }
45
76
 
77
+ return "";
78
+ },
79
+ formatRawDate = function formatRawDate(raw) {
46
80
  if (typeof raw !== "undefined") {
47
81
  return (0, _utility.formatDate)(raw);
48
82
  }
@@ -50,151 +84,87 @@ var formatRawDate = function formatRawDate(raw) {
50
84
  return "";
51
85
  };
52
86
 
53
- var DateTemplate = exports.DateTemplate = function (_React$Component) {
54
- _inherits(DateTemplate, _React$Component);
55
-
56
- function DateTemplate(props) {
57
- _classCallCheck(this, DateTemplate);
58
-
59
- var _this = _possibleConstructorReturn(this, (DateTemplate.__proto__ || Object.getPrototypeOf(DateTemplate)).call(this));
60
-
61
- _this.state = {
62
- value: formatRawDate(props.input.value)
63
- };
64
-
65
- _this.handleKeyDown = function (event) {
66
- if (event.key === "Enter") {
67
- _this.handleBlur();
68
- }
69
- };
70
-
71
- _this.handleBlur = function () {
72
- var onBlur = _this.props.input.onBlur;
73
- var _this$props = _this.props,
74
- input = _this$props.input,
75
- normalizeValue = _this$props.normalizeValue;
76
- var currentValue = _this.state.value;
77
-
78
-
79
- var normalizedValue = normalizeValue(currentValue),
80
- shouldRenderAgain = normalizedValue !== "" && currentValue !== normalizedValue;
81
-
82
- input.onChange(normalizedValue);
83
-
84
- /*
85
- * Swallow the event to prevent Redux Form from
86
- * extracting the form value
87
- */
88
- onBlur();
89
-
90
- if (shouldRenderAgain) {
91
- _this.setState({
92
- value: (0, _utility.formatDate)(normalizedValue)
93
- });
94
- }
95
- };
96
-
97
- _this.handleChange = function (_ref) {
98
- var value = _ref.target.value;
99
-
100
- _this.props.input.onChange();
101
-
102
- /*
103
- * Update the internal state to trigger a re-render
104
- * using the formatted value
105
- */
106
- _this.setState({ value: value });
107
- };
108
- return _this;
109
- }
110
-
111
- _createClass(DateTemplate, [{
112
- key: "UNSAFE_componentWillReceiveProps",
113
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
114
- var newValue = nextProps.input.value;
115
- var currentValue = this.state.value;
116
-
117
-
118
- var shouldRenderAgain = (0, _utility.isValidDate)(newValue) && currentValue !== newValue;
119
-
120
- if (newValue === "") {
121
- this.setState({
122
- value: ""
123
- });
124
- }
125
-
126
- if (shouldRenderAgain) {
127
- this.setState({
128
- value: (0, _utility.formatDate)(newValue)
129
- });
130
- }
87
+ // eslint-disable-next-line no-undef
88
+ var DateInput = exports.DateInput = function DateInput(props) {
89
+ var customClass = props.customClass,
90
+ input = props.input,
91
+ onRegisterRef = props.onRegisterRef,
92
+ tabIndex = props.tabIndex,
93
+ placeholder = props.placeholder,
94
+ _props$meta = props.meta,
95
+ submitting = _props$meta.submitting,
96
+ touched = _props$meta.touched,
97
+ error = _props$meta.error,
98
+ right = props.right,
99
+ left = props.left,
100
+ label = props.label,
101
+ _React$useState = _react2.default.useState(input.value),
102
+ _React$useState2 = _slicedToArray(_React$useState, 2),
103
+ value = _React$useState2[0],
104
+ setValue = _React$useState2[1],
105
+ valueToShow = formatRawDate(value),
106
+ updateValue = function updateValue(targetValue) {
107
+
108
+ var normalizedValue = normalizeRawDate(addZeroIfNeeded(targetValue));
109
+
110
+ setValue(targetValue);
111
+ props.input.onChange(normalizedValue);
112
+ },
113
+ handleBlur = function handleBlur(_ref) {
114
+ var targetValue = _ref.target.value;
115
+
116
+ var newValue = addZeroIfNeeded(targetValue),
117
+ hasChanged = targetValue !== newValue;
118
+
119
+ if (hasChanged) {
120
+ updateValue(newValue);
131
121
  }
132
- }, {
133
- key: "render",
134
- value: function render() {
135
- var _props = this.props,
136
- customClass = _props.customClass,
137
- input = _props.input,
138
- label = _props.label,
139
- onRegisterRef = _props.onRegisterRef,
140
- _props$meta = _props.meta,
141
- submitting = _props$meta.submitting,
142
- touched = _props$meta.touched,
143
- error = _props$meta.error,
144
- left = _props.left,
145
- right = _props.right,
146
- tabIndex = _props.tabIndex,
147
- formatValue = _props.formatValue,
148
- placeholder = _props.placeholder;
149
-
150
-
151
- return _react2.default.createElement(
122
+ },
123
+ handleChange = function handleChange(_ref2) {
124
+ var targetValue = _ref2.target.value;
125
+
126
+ updateValue(targetValue);
127
+ };
128
+
129
+ return _react2.default.createElement(
130
+ "div",
131
+ {
132
+ className: (0, _classnames2.default)("form-group row", { "is-invalid": touched && error }) },
133
+ _react2.default.createElement(
134
+ "label",
135
+ {
136
+ className: (left ? left : "col-md-4 text-md-right") + " form-control-label",
137
+ htmlFor: input.name },
138
+ label
139
+ ),
140
+ _react2.default.createElement(
141
+ "div",
142
+ { className: right ? right : "col-md-8" },
143
+ _react2.default.createElement("input", _extends({}, input, {
144
+ "aria-label": label,
145
+ className: (0, _classnames2.default)("form-control " + (customClass || ""), {
146
+ "is-invalid": touched && error
147
+ }),
148
+ disabled: submitting,
149
+ id: input.name,
150
+ onBlur: handleBlur,
151
+ onChange: handleChange,
152
+ placeholder: placeholder || _utility.words.DateFormat,
153
+ ref: onRegisterRef,
154
+ tabIndex: tabIndex,
155
+ type: "text",
156
+ value: valueToShow
157
+ })),
158
+ _react2.default.createElement(
152
159
  "div",
153
- { className: (0, _classnames2.default)("form-group row", { "is-invalid": touched && error }) },
154
- _react2.default.createElement(
155
- "label",
156
- {
157
- className: (left ? left : "col-md-4 text-md-right") + " form-control-label",
158
- htmlFor: input.name },
159
- label
160
- ),
161
- _react2.default.createElement(
162
- "div",
163
- { className: right ? right : "col-md-8" },
164
- _react2.default.createElement("input", _extends({}, input, {
165
- "aria-label": label,
166
- className: (0, _classnames2.default)("form-control " + (customClass || ""), {
167
- "is-invalid": touched && error
168
- }),
169
- disabled: submitting,
170
- id: input.name,
171
- onBlur: this.handleBlur,
172
- onChange: this.handleChange,
173
- onKeyDown: this.handleKeyDown,
174
- placeholder: placeholder || "ZZ.LL.ANUL",
175
- ref: onRegisterRef,
176
- tabIndex: tabIndex,
177
- type: "text",
178
- value: formatValue(this.state.value)
179
- })),
180
- _react2.default.createElement(
181
- "div",
182
- { className: "invalid-feedback" },
183
- touched && error && _react2.default.createElement(
184
- "span",
185
- null,
186
- error
187
- )
188
- )
160
+ {
161
+ className: "invalid-feedback" },
162
+ touched && error && _react2.default.createElement(
163
+ "span",
164
+ null,
165
+ error
189
166
  )
190
- );
191
- }
192
- }]);
193
-
194
- return DateTemplate;
195
- }(_react2.default.Component);
196
-
197
- DateTemplate.defaultProps = {
198
- formatValue: formatRawDate,
199
- normalizeValue: normalizeRawDate
167
+ )
168
+ )
169
+ );
200
170
  };
@@ -3,9 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.NumericInput = undefined;
7
6
 
8
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
7
+ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); /* eslint-disable require-unicode-regexp */
8
+ /* eslint-disable no-magic-numbers */
9
+ /* eslint-disable react/no-unsafe */
9
10
 
10
11
  var _react = require("react");
11
12
 
@@ -17,123 +18,87 @@ var _classnames2 = _interopRequireDefault(_classnames);
17
18
 
18
19
  var _utility = require("../utility");
19
20
 
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23
-
24
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
25
-
26
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /* eslint-disable */
27
-
28
-
29
- var NumericInput = exports.NumericInput = function (_React$Component) {
30
- _inherits(NumericInput, _React$Component);
31
-
32
- function NumericInput(props) {
33
- _classCallCheck(this, NumericInput);
34
-
35
- var _this = _possibleConstructorReturn(this, (NumericInput.__proto__ || Object.getPrototypeOf(NumericInput)).call(this));
36
-
37
- _this.state = {
38
- value: props.input.value
39
- };
40
-
41
- _this.handleKeyDown = function (event) {
42
- if (event.key === "Enter") {
43
- _this.handleBlur();
44
- }
45
- };
46
-
47
- _this.handleBlur = function () {
48
- (0, _utility.handleBlur)(_this);
49
- };
21
+ var _common = require("./common");
50
22
 
51
- _this.handleChange = function (_ref) {
52
- var value = _ref.target.value;
53
-
54
- _this.props.input.onChange();
55
-
56
- /*
57
- * Update the internal state to trigger a re-render
58
- * using the formatted value
59
- */
60
- _this.setState({ value: value });
61
- };
62
- return _this;
63
- }
64
-
65
- _createClass(NumericInput, [{
66
- key: "UNSAFE_componentWillReceiveProps",
67
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
68
- (0, _utility.cwrp)(this, nextProps);
69
- }
70
- }, {
71
- key: "render",
72
- value: function render() {
73
- var _props = this.props,
74
- customClass = _props.customClass,
75
- input = _props.input,
76
- label = _props.label,
77
- currency = _props.currency,
78
- tabIndex = _props.tabIndex,
79
- onRegisterRef = _props.onRegisterRef,
80
- _props$meta = _props.meta,
81
- submitting = _props$meta.submitting,
82
- touched = _props$meta.touched,
83
- error = _props$meta.error,
84
- formatValue = _props.formatValue,
85
- size = _props.size,
86
- placeholder = _props.placeholder;
87
-
88
-
89
- var inputComponent = _react2.default.createElement("input", {
90
- "aria-label": label,
91
- className: (0, _classnames2.default)("form-control " + (customClass || ""), {
92
- "is-invalid": touched && error
93
- }),
94
- disabled: submitting,
95
- id: input.name,
96
- maxLength: size,
97
- onBlur: this.handleBlur,
98
- onChange: this.handleChange,
99
- onFocus: input.onFocus,
100
- onKeyDown: this.handleKeyDown,
101
- placeholder: placeholder || label,
102
- ref: onRegisterRef,
103
- tabIndex: tabIndex,
104
- type: "text",
105
- value: formatValue(this.state.value, this.props.optional)
106
- });
107
-
108
- if (typeof currency === "undefined" || currency === false) {
109
- return _react2.default.createElement(
110
- "div",
111
- { className: "form-group-inline" },
112
- inputComponent
113
- );
114
- }
23
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
115
24
 
116
- return _react2.default.createElement(
117
- "div",
118
- { className: "input-group" },
119
- inputComponent,
120
- _react2.default.createElement(
121
- "div",
122
- { className: "input-group-append" },
123
- _react2.default.createElement(
124
- "span",
125
- { className: "input-group-text" },
126
- currency
127
- )
128
- )
129
- );
25
+ var NumericInput = function NumericInput(props) {
26
+ var customClass = props.customClass,
27
+ input = props.input,
28
+ label = props.label,
29
+ currency = props.currency,
30
+ tabIndex = props.tabIndex,
31
+ onRegisterRef = props.onRegisterRef,
32
+ _props$formatValue = props.formatValue,
33
+ formatValue = _props$formatValue === undefined ? _utility.formatZeroValue : _props$formatValue,
34
+ size = props.size,
35
+ placeholder = props.placeholder,
36
+ _props$meta = props.meta,
37
+ submitting = _props$meta.submitting,
38
+ touched = _props$meta.touched,
39
+ error = _props$meta.error,
40
+ _React$useState = _react2.default.useState(props.input.value),
41
+ _React$useState2 = _slicedToArray(_React$useState, 2),
42
+ value = _React$useState2[0],
43
+ setValue = _React$useState2[1],
44
+ noCurrency = typeof currency === "undefined" || currency === false,
45
+ valueToShow = formatValue(value, props.optional),
46
+ updateValue = function updateValue(targetValue) {
47
+ setValue(targetValue);
48
+ props.input.onChange((0, _common.getFloatValueToStore)(targetValue));
49
+ },
50
+ handleBlur = function handleBlur() {
51
+ var newValue = (0, _common.clearFloatOnBlur)(value),
52
+ hasChanged = value !== newValue;
53
+
54
+ if (hasChanged) {
55
+ updateValue(newValue);
130
56
  }
131
- }]);
132
-
133
- return NumericInput;
134
- }(_react2.default.Component);
57
+ },
58
+ handleChange = function handleChange(_ref) {
59
+ var targetValue = _ref.target.value;
60
+
61
+ updateValue(targetValue);
62
+ },
63
+ inputComponent = _react2.default.createElement("input", {
64
+ "aria-label": label,
65
+ className: (0, _classnames2.default)("form-control " + (customClass || ""), {
66
+ "is-invalid": touched && error
67
+ }),
68
+ disabled: submitting,
69
+ id: input.name,
70
+ maxLength: size,
71
+ onBlur: handleBlur,
72
+ onChange: handleChange,
73
+ placeholder: placeholder || label,
74
+ ref: onRegisterRef,
75
+ tabIndex: tabIndex,
76
+ type: "text",
77
+ value: valueToShow
78
+ });
79
+
80
+ if (noCurrency) {
81
+ return _react2.default.createElement(
82
+ "div",
83
+ { className: "form-group-inline" },
84
+ inputComponent
85
+ );
86
+ }
135
87
 
136
- NumericInput.defaultProps = {
137
- formatValue: _utility.formatZeroValue,
138
- normalizeValue: _utility.normalizeFloat
139
- };
88
+ return _react2.default.createElement(
89
+ "div",
90
+ { className: "input-group" },
91
+ inputComponent,
92
+ _react2.default.createElement(
93
+ "div",
94
+ { className: "input-group-append" },
95
+ _react2.default.createElement(
96
+ "span",
97
+ { className: "input-group-text" },
98
+ currency
99
+ )
100
+ )
101
+ );
102
+ };
103
+
104
+ exports.default = NumericInput;
@@ -3,9 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.NumericTemplate = undefined;
7
6
 
8
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
7
+ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
8
+ /* eslint-disable require-unicode-regexp */
9
+ /* eslint-disable no-magic-numbers */
10
+ /* eslint-disable react/no-unsafe */
9
11
 
10
12
  var _react = require("react");
11
13
 
@@ -15,134 +17,96 @@ var _classnames = require("classnames");
15
17
 
16
18
  var _classnames2 = _interopRequireDefault(_classnames);
17
19
 
18
- var _utility = require("../utility");
20
+ var _common = require("./common");
19
21
 
20
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
23
 
22
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
23
-
24
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
25
-
26
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /* eslint-disable */
27
-
28
-
29
- var NumericTemplate = exports.NumericTemplate = function (_React$Component) {
30
- _inherits(NumericTemplate, _React$Component);
31
-
32
- function NumericTemplate(props) {
33
- _classCallCheck(this, NumericTemplate);
34
-
35
- var _this = _possibleConstructorReturn(this, (NumericTemplate.__proto__ || Object.getPrototypeOf(NumericTemplate)).call(this));
36
-
37
- _this.state = {
38
- value: props.input.value
39
- };
40
-
41
- _this.handleKeyDown = function (event) {
42
- if (event.key === "Enter") {
43
- _this.handleBlur();
44
- }
45
- };
46
-
47
- _this.handleBlur = function () {
48
- (0, _utility.handleBlur)(_this);
49
- };
50
-
51
- _this.handleChange = function (_ref) {
52
- var value = _ref.target.value;
53
-
54
- _this.props.input.onChange();
55
-
56
- /*
57
- * Update the internal state to trigger a re-render
58
- * using the formatted value
59
- */
60
- _this.setState({ value: value });
61
- };
62
- return _this;
63
- }
64
-
65
- _createClass(NumericTemplate, [{
66
- key: "UNSAFE_componentWillReceiveProps",
67
- value: function UNSAFE_componentWillReceiveProps(nextProps) {
68
- (0, _utility.cwrp)(this, nextProps);
24
+ var NumericTemplate = function NumericTemplate(props) {
25
+ var input = props.input,
26
+ right = props.right,
27
+ tabIndex = props.tabIndex,
28
+ divClass = props.divClass,
29
+ label = props.label,
30
+ onRegisterRef = props.onRegisterRef,
31
+ _props$meta = props.meta,
32
+ submitting = _props$meta.submitting,
33
+ touched = _props$meta.touched,
34
+ error = _props$meta.error,
35
+ formatValue = props.formatValue,
36
+ type = props.type,
37
+ autoFocus = props.autoFocus,
38
+ inputClass = props.inputClass,
39
+ placeholder = props.placeholder,
40
+ left = props.left,
41
+ size = props.size,
42
+ _React$useState = _react2.default.useState(props.input.value),
43
+ _React$useState2 = _slicedToArray(_React$useState, 2),
44
+ value = _React$useState2[0],
45
+ setValue = _React$useState2[1],
46
+ valueToShow = formatValue(value, props.optional),
47
+ updateValue = function updateValue(targetValue) {
48
+ setValue(targetValue);
49
+ props.input.onChange((0, _common.getFloatValueToStore)(targetValue));
50
+ },
51
+ handleBlur = function handleBlur() {
52
+ var newValue = (0, _common.clearFloatOnBlur)(value),
53
+ hasChanged = value !== newValue;
54
+
55
+ if (hasChanged) {
56
+ updateValue(newValue);
69
57
  }
70
- }, {
71
- key: "render",
72
- value: function render() {
73
- var _props = this.props,
74
- input = _props.input,
75
- label = _props.label,
76
- onRegisterRef = _props.onRegisterRef,
77
- _props$meta = _props.meta,
78
- submitting = _props$meta.submitting,
79
- touched = _props$meta.touched,
80
- error = _props$meta.error,
81
- formatValue = _props.formatValue,
82
- type = _props.type,
83
- autoFocus = _props.autoFocus,
84
- inputClass = _props.inputClass,
85
- placeholder = _props.placeholder,
86
- left = _props.left,
87
- size = _props.size,
88
- right = _props.right,
89
- tabIndex = _props.tabIndex,
90
- divClass = _props.divClass;
91
-
92
-
93
- var warningClass = "" + (touched && error ? " is-invalid" : ""),
94
- customClass = "" + (inputClass ? " " + inputClass : ""),
95
- classForInput = "form-control " + warningClass + customClass,
96
- classForDiv = "form-group row " + (divClass ? divClass : "");
97
-
98
- return _react2.default.createElement(
58
+ },
59
+ handleChange = function handleChange(_ref) {
60
+ var targetValue = _ref.target.value;
61
+
62
+ updateValue(targetValue);
63
+ },
64
+ warningClass = "" + (touched && error ? " is-invalid" : ""),
65
+ customClass = "" + (inputClass ? " " + inputClass : ""),
66
+ classForInput = "form-control " + warningClass + customClass,
67
+ classForDiv = "form-group row " + (divClass ? divClass : "");
68
+
69
+ return _react2.default.createElement(
70
+ "div",
71
+ { className: (0, _classnames2.default)(classForDiv, {
72
+ "is-invalid": touched && error
73
+ }) },
74
+ _react2.default.createElement(
75
+ "label",
76
+ {
77
+ className: (left ? left : "col-md-4 text-md-right") + " form-control-label",
78
+ htmlFor: input.name },
79
+ label
80
+ ),
81
+ _react2.default.createElement(
82
+ "div",
83
+ { className: right ? right : "col-md-8" },
84
+ _react2.default.createElement("input", {
85
+ "aria-label": label,
86
+ autoFocus: autoFocus,
87
+ className: classForInput,
88
+ disabled: submitting,
89
+ id: input.name,
90
+ maxLength: size,
91
+ onBlur: handleBlur,
92
+ onChange: handleChange,
93
+ placeholder: placeholder,
94
+ ref: onRegisterRef,
95
+ tabIndex: tabIndex,
96
+ type: type,
97
+ value: formatValue(valueToShow, props.optional)
98
+ }),
99
+ _react2.default.createElement(
99
100
  "div",
100
- { className: (0, _classnames2.default)(classForDiv, { "is-invalid": touched && error }) },
101
- _react2.default.createElement(
102
- "label",
103
- {
104
- className: (left ? left : "col-md-4 text-md-right") + " form-control-label",
105
- htmlFor: input.name },
106
- label
107
- ),
108
- _react2.default.createElement(
109
- "div",
110
- { className: right ? right : "col-md-8" },
111
- _react2.default.createElement("input", {
112
- "aria-label": label,
113
- autoFocus: autoFocus,
114
- className: classForInput,
115
- disabled: submitting,
116
- id: input.name,
117
- maxLength: size,
118
- onBlur: this.handleBlur,
119
- onChange: this.handleChange,
120
- onFocus: input.onFocus,
121
- onKeyDown: this.handleKeyDown,
122
- placeholder: placeholder,
123
- ref: onRegisterRef,
124
- tabIndex: tabIndex,
125
- type: type,
126
- value: formatValue(this.state.value, this.props.optional)
127
- }),
128
- _react2.default.createElement(
129
- "div",
130
- { className: "invalid-feedback" },
131
- touched && error && _react2.default.createElement(
132
- "span",
133
- null,
134
- error
135
- )
136
- )
101
+ { className: "invalid-feedback" },
102
+ touched && error && _react2.default.createElement(
103
+ "span",
104
+ null,
105
+ error
137
106
  )
138
- );
139
- }
140
- }]);
141
-
142
- return NumericTemplate;
143
- }(_react2.default.Component);
107
+ )
108
+ )
109
+ );
110
+ };
144
111
 
145
- NumericTemplate.defaultProps = {
146
- formatValue: _utility.formatZeroValue,
147
- normalizeValue: _utility.normalizeFloat
148
- };
112
+ exports.default = NumericTemplate;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
8
+
9
+ /* eslint-disable require-unicode-regexp */
10
+
11
+ var isFloat = function isFloat(raw) {
12
+ var floatRegex = /^-?\d+(?:[.]\d*?)?$/;
13
+
14
+ return floatRegex.test(raw);
15
+ },
16
+ floatToEnglishComma = function floatToEnglishComma(raw) {
17
+ return String(raw).replace(",", ".");
18
+ },
19
+ floatToLocalComma = function floatToLocalComma(raw) {
20
+ return String(raw).replace(".", ",");
21
+ };
22
+
23
+ var getFloatValueToStore = exports.getFloatValueToStore = function getFloatValueToStore(raw) {
24
+ var parsedFloat = floatToEnglishComma(raw),
25
+ parsedValue = parseFloat(parsedFloat),
26
+ canGetNumericValue = isFloat(parsedFloat) && !isNaN(parsedValue);
27
+
28
+ if (canGetNumericValue) {
29
+ return parsedValue;
30
+ }
31
+
32
+ return 0;
33
+ },
34
+ clearFloatOnBlur = exports.clearFloatOnBlur = function clearFloatOnBlur(value) {
35
+ var parts = floatToLocalComma(value).split(","),
36
+ shouldRemoveComma = parts.length === 2 && (parts[1] === "" || Number(parts[1]) === 0),
37
+ shouldCutTo2Decimals = parts.length === 2 && parts[1].length > 2;
38
+
39
+ if (shouldRemoveComma) {
40
+ return parts[0];
41
+ }
42
+
43
+ if (shouldCutTo2Decimals) {
44
+ var _parts = _slicedToArray(parts, 1),
45
+ beforeDot = _parts[0],
46
+ afterDot = parts[1].substring(0, 2);
47
+
48
+ return beforeDot + "," + afterDot;
49
+ }
50
+
51
+ return value;
52
+ };
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "5.1.11",
2
+ "version": "5.1.14",
3
3
  "name": "x25",
4
4
  "description": "x25",
5
5
  "scripts": {