shineout 1.9.2 → 1.10.0-rc.1

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.
@@ -33,6 +33,19 @@ var _styles2 = require("./styles");
33
33
 
34
34
  var _InputTitle = _interopRequireDefault(require("../InputTitle"));
35
35
 
36
+ function isNumberType(n) {
37
+ return !Number.isNaN(parseFloat(n)) && !Number.isNaN(n - 0);
38
+ }
39
+
40
+ function regLength(size) {
41
+ return /\d+/.test(size) && size > 0 ? "{0," + size + "}" : '*';
42
+ }
43
+
44
+ function fillNumber(val) {
45
+ return val.replace(/^(-)?(\.\d+)(?!=\.).*/g, '$10$2') // eslint-disable-next-line no-useless-escape
46
+ .replace(/^0+(?=0\.?|[^0\.])/g, '').replace(/\.$/, '');
47
+ }
48
+
36
49
  var Input =
37
50
  /*#__PURE__*/
38
51
  function (_PureComponent) {
@@ -54,6 +67,7 @@ function (_PureComponent) {
54
67
  _this.handleKeyDown = _this.handleKeyDown.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
55
68
  _this.handleKeyUp = _this.handleKeyUp.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
56
69
  _this.handleBlur = _this.handleBlur.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
70
+ _this.handleAutoSelect = _this.handleAutoSelect.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
57
71
  _this.bindRef = _this.bindRef.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
58
72
  return _this;
59
73
  }
@@ -66,16 +80,71 @@ function (_PureComponent) {
66
80
  if (forwardedRef) forwardedRef(el);
67
81
  };
68
82
 
69
- _proto.invalidNumber = function invalidNumber(value) {
83
+ _proto.isValidNumber = function isValidNumber(val) {
84
+ var positive = this.props.positive;
85
+ var regExp = new RegExp("^(" + (positive ? '' : '-') + ")?\\d*\\.?\\d*$", 'g');
86
+ return regExp.test(val);
87
+ };
88
+
89
+ _proto.formatValue = function formatValue(val) {
90
+ var value = val;
70
91
  var _this$props = this.props,
92
+ type = _this$props.type,
71
93
  digits = _this$props.digits,
72
- type = _this$props.type;
94
+ integerLimit = _this$props.integerLimit,
95
+ positive = _this$props.positive;
96
+ if (type !== 'number') return value; // if (positive) {
97
+ // value = value.replace(/^0/g, '')
98
+ // }
99
+
100
+ var regExp = new RegExp("^(" + (positive ? '' : '-') + ")?(\\d" + regLength(integerLimit) + ")(" + (digits !== 0 ? "\\.\\d" + regLength(digits) : '') + ")?.*$", 'g');
101
+ console.log(value, typeof value);
102
+ value = value.replace(regExp, '$1$2$3');
103
+ return value;
104
+ };
105
+
106
+ _proto.fixValue = function fixValue(val) {
107
+ var _this$props2 = this.props,
108
+ type = _this$props2.type,
109
+ digits = _this$props2.digits,
110
+ autoFix = _this$props2.autoFix,
111
+ cancelChange = _this$props2.cancelChange,
112
+ positive = _this$props2.positive;
113
+ if (type !== 'number' || val === '') return val;
114
+ if (!isNumberType(val)) return '';
115
+ var fixVal = fillNumber(val);
116
+ if (positive && fixVal <= 0) return '';
117
+
118
+ if (digits !== undefined && autoFix) {
119
+ if (digits > 0) {
120
+ fixVal = parseFloat(fixVal).toFixed(digits);
121
+ } else {
122
+ fixVal = parseInt(fixVal, 10).toString();
123
+ }
124
+
125
+ if (cancelChange) cancelChange();
126
+ }
127
+
128
+ return fixVal;
129
+ };
130
+
131
+ _proto.invalidNumber = function invalidNumber(value) {
132
+ var _this$props3 = this.props,
133
+ digits = _this$props3.digits,
134
+ type = _this$props3.type,
135
+ integerLimit = _this$props3.integerLimit;
73
136
  if (type !== 'number') return false;
74
- var reg = '^-?\\d*';
137
+ var reg = '^-?';
138
+
139
+ if (!integerLimit) {
140
+ reg += "\\d*";
141
+ } else if (integerLimit > 0) {
142
+ reg += "\\d{0," + integerLimit + "}";
143
+ }
75
144
 
76
145
  if (digits === undefined) {
77
146
  reg += '\\.?\\d*';
78
- } else if (digits > 0) {
147
+ } else if (digits >= 0) {
79
148
  reg += "\\.?\\d{0," + digits + "}";
80
149
  }
81
150
 
@@ -85,10 +154,9 @@ function (_PureComponent) {
85
154
  };
86
155
 
87
156
  _proto.handleChange = function handleChange(e, clearClick) {
88
- var _this$props2 = this.props,
89
- type = _this$props2.type,
90
- clearable = _this$props2.clearable,
91
- digits = _this$props2.digits;
157
+ var _this$props4 = this.props,
158
+ type = _this$props4.type,
159
+ clearable = _this$props4.clearable;
92
160
 
93
161
  if (clearClick) {
94
162
  this.ref.focus();
@@ -102,20 +170,16 @@ function (_PureComponent) {
102
170
  return;
103
171
  }
104
172
 
105
- if (type === 'number' && typeof value !== 'number') value = String(value).replace(/。/g, '.');
173
+ if (type === 'number') {
174
+ if (typeof value !== 'number') {
175
+ value = String(value).replace(/。/g, '.');
176
+ }
106
177
 
107
- if (this.invalidNumber(value)) {
108
- // For numbers with a decimal point, use toFixed to correct the number of decimal points.
109
- if (digits >= 0 && /^-?\d*\.?\d*$/.test(value)) {
110
- if (digits === 0) {
111
- value = value === '.' ? '' : Number(value).toFixed(digits);
112
- } else {
113
- value = Number(value).toFixed(digits + 1).slice(0, -1);
114
- }
115
- } else {
116
- // digits <= 0 || not of number
178
+ if (!this.isValidNumber(value)) {
117
179
  return;
118
180
  }
181
+
182
+ value = this.formatValue(value);
119
183
  }
120
184
 
121
185
  this.props.onChange(value);
@@ -128,9 +192,9 @@ function (_PureComponent) {
128
192
  };
129
193
 
130
194
  _proto.handleKeyUp = function handleKeyUp(e) {
131
- var _this$props3 = this.props,
132
- onKeyUp = _this$props3.onKeyUp,
133
- onEnterPress = _this$props3.onEnterPress;
195
+ var _this$props5 = this.props,
196
+ onKeyUp = _this$props5.onKeyUp,
197
+ onEnterPress = _this$props5.onEnterPress;
134
198
 
135
199
  if (this.enterPress && e.keyCode === 13 && onEnterPress) {
136
200
  onEnterPress(e.target.value, e);
@@ -142,18 +206,34 @@ function (_PureComponent) {
142
206
 
143
207
  _proto.handleBlur = function handleBlur(e) {
144
208
  var value = e.target.value;
145
- var _this$props4 = this.props,
146
- forceChange = _this$props4.forceChange,
147
- onBlur = _this$props4.onBlur,
148
- clearToUndefined = _this$props4.clearToUndefined;
209
+ var _this$props6 = this.props,
210
+ forceChange = _this$props6.forceChange,
211
+ onBlur = _this$props6.onBlur,
212
+ clearToUndefined = _this$props6.clearToUndefined,
213
+ cancelChange = _this$props6.cancelChange;
214
+ if (cancelChange) cancelChange();
215
+ var newVal = this.fixValue(value);
149
216
  if (onBlur) onBlur(e);
150
- if (this.invalidNumber(value)) return;
217
+ if (this.invalidNumber(newVal)) return;
151
218
 
152
- if (clearToUndefined && value === '' && this.props.value === undefined) {
219
+ if (clearToUndefined && newVal === '' && this.props.value === undefined) {
153
220
  return;
154
221
  }
155
222
 
156
- if (forceChange) forceChange(value);
223
+ if (forceChange) forceChange(newVal);
224
+ };
225
+
226
+ _proto.handleAutoSelect = function handleAutoSelect(event) {
227
+ var onFocus = this.props.onFocus;
228
+ var autoSelect = this.props.autoSelect;
229
+
230
+ if (autoSelect) {
231
+ event.currentTarget.select();
232
+ }
233
+
234
+ if (typeof onFocus === 'function') {
235
+ onFocus(event);
236
+ }
157
237
  };
158
238
 
159
239
  _proto.renderInfo = function renderInfo() {
@@ -176,21 +256,21 @@ function (_PureComponent) {
176
256
  };
177
257
 
178
258
  _proto.render = function render() {
179
- var _this$props5 = this.props,
180
- type = _this$props5.type,
181
- defaultValue = _this$props5.defaultValue,
182
- digits = _this$props5.digits,
183
- className = _this$props5.className,
184
- clearable = _this$props5.clearable,
185
- htmlName = _this$props5.htmlName,
186
- forceChange = _this$props5.forceChange,
187
- onEnterPress = _this$props5.onEnterPress,
188
- forwardedRef = _this$props5.forwardedRef,
189
- innerTitle = _this$props5.innerTitle,
190
- inputFocus = _this$props5.inputFocus,
191
- clearToUndefined = _this$props5.clearToUndefined,
192
- placeholder = _this$props5.placeholder,
193
- other = (0, _objectWithoutPropertiesLoose2.default)(_this$props5, ["type", "defaultValue", "digits", "className", "clearable", "htmlName", "forceChange", "onEnterPress", "forwardedRef", "innerTitle", "inputFocus", "clearToUndefined", "placeholder"]);
259
+ var _this$props7 = this.props,
260
+ type = _this$props7.type,
261
+ defaultValue = _this$props7.defaultValue,
262
+ digits = _this$props7.digits,
263
+ className = _this$props7.className,
264
+ clearable = _this$props7.clearable,
265
+ htmlName = _this$props7.htmlName,
266
+ forceChange = _this$props7.forceChange,
267
+ onEnterPress = _this$props7.onEnterPress,
268
+ forwardedRef = _this$props7.forwardedRef,
269
+ innerTitle = _this$props7.innerTitle,
270
+ inputFocus = _this$props7.inputFocus,
271
+ clearToUndefined = _this$props7.clearToUndefined,
272
+ placeholder = _this$props7.placeholder,
273
+ other = (0, _objectWithoutPropertiesLoose2.default)(_this$props7, ["type", "defaultValue", "digits", "className", "clearable", "htmlName", "forceChange", "onEnterPress", "forwardedRef", "innerTitle", "inputFocus", "clearToUndefined", "placeholder"]);
194
274
  var value = this.props.value == null || this.props.value === undefined ? '' : this.props.value;
195
275
  var needClearUndefined = clearToUndefined && this.props.value !== undefined;
196
276
  var showClear = !other.disabled && clearable && (value !== '' || needClearUndefined);
@@ -212,7 +292,8 @@ function (_PureComponent) {
212
292
  onChange: this.handleChange,
213
293
  onKeyDown: this.handleKeyDown,
214
294
  onKeyUp: this.handleKeyUp,
215
- onBlur: this.handleBlur
295
+ onBlur: this.handleBlur,
296
+ onFocus: this.handleAutoSelect
216
297
  }))), showClear && _react.default.createElement(_clear.default, {
217
298
  onClick: this.handleChange,
218
299
  key: "close",
@@ -227,10 +308,15 @@ Input.propTypes = {
227
308
  className: _propTypes.default.string,
228
309
  defaultValue: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
229
310
  digits: _propTypes.default.number,
311
+ integerLimit: _propTypes.default.number,
312
+ positive: _propTypes.default.bool,
313
+ autoSelect: _propTypes.default.bool,
314
+ autoFix: _propTypes.default.bool,
230
315
  forceChange: _propTypes.default.func,
231
316
  htmlName: _propTypes.default.string,
232
317
  onBlur: _propTypes.default.func,
233
318
  onChange: _propTypes.default.func.isRequired,
319
+ cancelChange: _propTypes.default.func,
234
320
  onEnterPress: _propTypes.default.func,
235
321
  type: _propTypes.default.string,
236
322
  value: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
@@ -69,17 +69,21 @@ function (_PureComponent) {
69
69
  return;
70
70
  }
71
71
 
72
- if (typeof this.props.digits === 'number') {
73
- value = parseFloat(value.toFixed(this.props.digits));
72
+ var _this$props = this.props,
73
+ digits = _this$props.digits,
74
+ step = _this$props.step;
75
+
76
+ if (typeof digits === 'number') {
77
+ value = parseFloat(value.toFixed(digits));
74
78
  } else {
75
- var stepStr = this.props.step.toString();
79
+ var stepStr = step.toString();
76
80
  var dot = stepStr.lastIndexOf('.');
77
81
  if (dot >= 0) value = parseFloat(value.toFixed(stepStr.length - dot));
78
82
  }
79
83
 
80
- var _this$props = this.props,
81
- min = _this$props.min,
82
- max = _this$props.max;
84
+ var _this$props2 = this.props,
85
+ min = _this$props2.min,
86
+ max = _this$props2.max;
83
87
  if (max !== undefined && value > max) value = max;
84
88
  if (min !== undefined && value < min) value = min;
85
89
 
@@ -115,7 +119,20 @@ function (_PureComponent) {
115
119
  var value = parseFloat(("" + (val || '')).replace(/,/g, '')); // eslint-disable-next-line
116
120
 
117
121
  if (isNaN(value)) value = 0;
118
- this.handleChange((0, _numbers.sub)(value, mod), true);
122
+ var _this$props3 = this.props,
123
+ positive = _this$props3.positive,
124
+ integerLimit = _this$props3.integerLimit;
125
+ var calculateVal = (0, _numbers.sub)(value, mod);
126
+
127
+ if (positive && calculateVal <= 0) {
128
+ calculateVal = value;
129
+ }
130
+
131
+ if (integerLimit && String(parseInt(calculateVal, 10)).length > integerLimit) {
132
+ calculateVal = value;
133
+ }
134
+
135
+ this.handleChange(calculateVal, true);
119
136
  };
120
137
 
121
138
  _proto.longPress = function longPress(mod) {
@@ -191,11 +208,11 @@ function (_PureComponent) {
191
208
  };
192
209
 
193
210
  _proto.renderRTL = function renderRTL() {
194
- var _this$props2 = this.props,
195
- onChange = _this$props2.onChange,
196
- allowNull = _this$props2.allowNull,
197
- hideArrow = _this$props2.hideArrow,
198
- other = (0, _objectWithoutPropertiesLoose2.default)(_this$props2, ["onChange", "allowNull", "hideArrow"]);
211
+ var _this$props4 = this.props,
212
+ onChange = _this$props4.onChange,
213
+ allowNull = _this$props4.allowNull,
214
+ hideArrow = _this$props4.hideArrow,
215
+ other = (0, _objectWithoutPropertiesLoose2.default)(_this$props4, ["onChange", "allowNull", "hideArrow"]);
199
216
  return [].concat(this.renderArrowGroup(), [_react.default.createElement(_Input.default, (0, _extends2.default)({
200
217
  key: "input"
201
218
  }, other, {
@@ -211,11 +228,11 @@ function (_PureComponent) {
211
228
  };
212
229
 
213
230
  _proto.render = function render() {
214
- var _this$props3 = this.props,
215
- onChange = _this$props3.onChange,
216
- allowNull = _this$props3.allowNull,
217
- hideArrow = _this$props3.hideArrow,
218
- other = (0, _objectWithoutPropertiesLoose2.default)(_this$props3, ["onChange", "allowNull", "hideArrow"]);
231
+ var _this$props5 = this.props,
232
+ onChange = _this$props5.onChange,
233
+ allowNull = _this$props5.allowNull,
234
+ hideArrow = _this$props5.hideArrow,
235
+ other = (0, _objectWithoutPropertiesLoose2.default)(_this$props5, ["onChange", "allowNull", "hideArrow"]);
219
236
  var rtl = (0, _config.isRTL)();
220
237
 
221
238
  if (rtl) {
@@ -249,6 +266,9 @@ Number.propTypes = {
249
266
  onChange: _propTypes.default.func.isRequired,
250
267
  step: _propTypes.default.number,
251
268
  digits: _propTypes.default.number,
269
+ integerLimit: _propTypes.default.number,
270
+ positive: _propTypes.default.bool,
271
+ autoSelect: _propTypes.default.bool,
252
272
  allowNull: _propTypes.default.bool,
253
273
  hideArrow: _propTypes.default.bool,
254
274
  clearToUndefined: _propTypes.default.bool,
@@ -188,7 +188,57 @@ FormItemStandardProps<Value> {
188
188
  * default: -
189
189
  *
190
190
  */
191
- clearToUndefined?: boolean
191
+ clearToUndefined?: boolean,
192
+
193
+ /**
194
+ * the digits of number 仅在type = number 下生效
195
+ *
196
+ * Decimal place limit (valid when type is number)
197
+ *
198
+ * default: -
199
+ */
200
+ digits?: number;
201
+
202
+ /**
203
+ * 整数位数限制, 仅在type = number 下生效
204
+ *
205
+ * Integer bit limit (valid when type is number)
206
+ *
207
+ * default: -
208
+ *
209
+ */
210
+ integerLimit?: number,
211
+
212
+ /**
213
+ * 非负数,仅在type = number 下生效
214
+ *
215
+ * positive number
216
+ *
217
+ * default: -
218
+ *
219
+ */
220
+ positive?: boolean,
221
+
222
+ /**
223
+ * 鼠标点击后自动全选数据
224
+ *
225
+ * Automatically select all data after mouse click
226
+ *
227
+ * default: false
228
+ *
229
+ */
230
+ autoSelect?: boolean,
231
+
232
+ /**
233
+ * 失焦后自动按照 digits 精度限制补足 (type 为 number 时生效)
234
+ *
235
+ * Automatically fill up according to the precision limit of digits after out of focus
236
+ *
237
+ * default: false
238
+ *
239
+ */
240
+ autoFix?: boolean,
241
+
192
242
  }
193
243
 
194
244
  export interface InputNumberProps <Value> extends InputProps<Value> {
@@ -220,15 +270,6 @@ export interface InputNumberProps <Value> extends InputProps<Value> {
220
270
  */
221
271
  step?: number;
222
272
 
223
- /**
224
- * the digits of number
225
- *
226
- * 数值的精度
227
- *
228
- * default: -
229
- */
230
- digits?: number;
231
-
232
273
  /**
233
274
  * allow value is null
234
275
  *
package/css/hoc/delay.js CHANGED
@@ -42,6 +42,7 @@ var _default = (0, _func.curry)(function (defaultDelay, Origin) {
42
42
  };
43
43
  _this.handleChange = _this.handleChange.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
44
44
  _this.forceChange = _this.forceChange.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
45
+ _this.cancelChange = _this.cancelChange.bind((0, _assertThisInitialized2.default)((0, _assertThisInitialized2.default)(_this)));
45
46
  return _this;
46
47
  }
47
48
 
@@ -91,6 +92,10 @@ var _default = (0, _func.curry)(function (defaultDelay, Origin) {
91
92
  }, delay);
92
93
  };
93
94
 
95
+ _proto.cancelChange = function cancelChange() {
96
+ if (this.changeTimer) clearTimeout(this.changeTimer);
97
+ };
98
+
94
99
  _proto.forceChange = function forceChange(value) {
95
100
  var _this$props2;
96
101
 
@@ -115,7 +120,8 @@ var _default = (0, _func.curry)(function (defaultDelay, Origin) {
115
120
  return _react.default.createElement(Origin, (0, _extends2.default)({}, props, {
116
121
  value: this.getValue(),
117
122
  onChange: this.handleChange,
118
- forceChange: this.forceChange
123
+ forceChange: this.forceChange,
124
+ cancelChange: this.cancelChange
119
125
  }));
120
126
  };
121
127
 
package/css/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  // Created by scripts/src-index.js.
2
2
  import * as utils from './utils'
3
3
 
4
- export default { utils, version: '1.9.2' }
4
+ export default { utils, version: '1.10.0-rc.1' }
5
5
  export { utils }
6
6
  export { setLocale } from './locale'
7
7
  export { color, style } from './utils/expose'
package/css/index.js CHANGED
@@ -224,6 +224,6 @@ exports.Upload = _Upload.default;
224
224
  // Created by scripts/src-index.js.
225
225
  var _default = {
226
226
  utils: utils,
227
- version: '1.9.2'
227
+ version: '1.10.0-rc.1'
228
228
  };
229
229
  exports.default = _default;
@@ -7,7 +7,7 @@ exports.default = cleanProps;
7
7
 
8
8
  var _immer = _interopRequireDefault(require("immer"));
9
9
 
10
- var names = ['delay', 'onDatumBind', 'rules', 'formDatum', 'forceChange', 'trim', 'beforeChange', 'validateHook', 'innerFormNamePath', 'fieldSetValidate', 'combineRules', 'popoverProps', 'inputFocus', 'placeTitle'];
10
+ var names = ['delay', 'onDatumBind', 'rules', 'formDatum', 'forceChange', 'trim', 'beforeChange', 'validateHook', 'innerFormNamePath', 'fieldSetValidate', 'combineRules', 'popoverProps', 'inputFocus', 'placeTitle', 'cancelChange', 'integerLimit', 'autoSelect', 'autoFix', 'positive'];
11
11
  /**
12
12
  * delete some props if needed, will not modify the pass argument
13
13
  * @param props