@hi-ui/input 4.0.10 → 4.0.11

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.
@@ -9,67 +9,53 @@
9
9
  */
10
10
  'use strict';
11
11
 
12
- Object.defineProperty(exports, '__esModule', {
13
- value: true
14
- });
15
-
16
12
  var React = require('react');
17
-
18
13
  var typeAssertion = require('@hi-ui/type-assertion');
19
-
20
14
  var defaultSeparator = ' ';
21
-
22
15
  var useInputCursor = function useInputCursor(_ref) {
23
16
  var inputElementRef = _ref.inputElementRef,
24
- value = _ref.value,
25
- formatter = _ref.formatter,
26
- _ref$separator = _ref.separator,
27
- separator = _ref$separator === void 0 ? defaultSeparator : _ref$separator;
28
-
17
+ value = _ref.value,
18
+ formatter = _ref.formatter,
19
+ _ref$separator = _ref.separator,
20
+ separator = _ref$separator === void 0 ? defaultSeparator : _ref$separator;
29
21
  var _useState = React.useState(0),
30
- position = _useState[0],
31
- setPosition = _useState[1];
32
-
33
- var startPositionRef = React.useRef(0); // 记录值变化前的位置
34
-
22
+ position = _useState[0],
23
+ setPosition = _useState[1];
24
+ var startPositionRef = React.useRef(0);
25
+ // 记录值变化前的位置
35
26
  var handleOnKeyDown = React.useCallback(function () {
36
27
  var _a, _b;
37
-
38
28
  startPositionRef.current = (_b = (_a = inputElementRef.current) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : 0;
39
29
  }, [inputElementRef]);
40
30
  var handleChange = React.useCallback(function (evt) {
41
31
  var _a, _b;
42
-
43
32
  if (typeAssertion.isNullish(value)) {
44
33
  return;
45
34
  }
46
-
47
- var val = evt.target.value; // 处理后的字符串
48
-
49
- var str = typeof formatter === 'function' ? formatter(val) : val; // 光标变化后的位置
50
-
51
- var endPosition = (_b = (_a = inputElementRef.current) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : 0; // 字符串添加
52
-
35
+ var val = evt.target.value;
36
+ // 处理后的字符串
37
+ var str = typeof formatter === 'function' ? formatter(val) : val;
38
+ // 光标变化后的位置
39
+ var endPosition = (_b = (_a = inputElementRef.current) === null || _a === void 0 ? void 0 : _a.selectionStart) !== null && _b !== void 0 ? _b : 0;
40
+ // 字符串添加
53
41
  if (str.length > value.length) {
54
42
  // 值变化的长度
55
- var len = str.length - value.length; // 取出变化的值
56
-
57
- var addStr = str.substring(startPositionRef.current, startPositionRef.current + len); // 光标应该移动的格数
58
-
43
+ var len = str.length - value.length;
44
+ // 取出变化的值
45
+ var addStr = str.substring(startPositionRef.current, startPositionRef.current + len);
46
+ // 光标应该移动的格数
59
47
  var step = getSeparatorNum(addStr, separator);
60
48
  setPosition(endPosition + step);
61
- } // 字符串删除
62
-
63
-
49
+ }
50
+ // 字符串删除
64
51
  if (str.length < value.length) {
65
52
  if (str.charAt(endPosition - 1) === separator) {
66
53
  setPosition(endPosition - 1);
67
54
  } else {
68
55
  setPosition(endPosition);
69
56
  }
70
- } // 没有变化
71
-
72
-
57
+ }
58
+ // 没有变化
73
59
  if (str.length === value.length) {
74
60
  if (str.charAt(startPositionRef.current) === separator) {
75
61
  setPosition(endPosition + 1);
@@ -89,22 +75,16 @@ var useInputCursor = function useInputCursor(_ref) {
89
75
  * @param str
90
76
  * @returns
91
77
  */
92
-
93
-
94
78
  var getSeparatorNum = function getSeparatorNum(str, separator) {
95
79
  if (separator === void 0) {
96
80
  separator = defaultSeparator;
97
81
  }
98
-
99
82
  var index = str.indexOf(separator);
100
83
  var num = 0;
101
-
102
84
  while (index !== -1) {
103
85
  index = str.indexOf(separator, index + 1);
104
86
  num++;
105
87
  }
106
-
107
88
  return num;
108
89
  };
109
-
110
90
  exports.useInputCursor = useInputCursor;
@@ -9,68 +9,53 @@
9
9
  */
10
10
  'use strict';
11
11
 
12
- Object.defineProperty(exports, '__esModule', {
13
- value: true
14
- });
15
-
16
12
  var React = require('react');
17
-
18
13
  var useUncontrolledState = require('@hi-ui/use-uncontrolled-state');
19
-
20
14
  var useLatest = require('@hi-ui/use-latest');
21
-
22
15
  var domUtils = require('@hi-ui/dom-utils');
23
-
24
16
  var funcUtils = require('@hi-ui/func-utils');
25
-
26
17
  var index = require('./utils/index.js');
27
-
28
18
  var useInputCursor = require('./use-input-cursor.js');
29
-
30
- var EXTRA_TYPE = ['text', 'id', 'tel', 'card', 'amount', 'email']; // 需要格式化后校对光标的类型
31
-
19
+ var EXTRA_TYPE = ['text', 'id', 'tel', 'card', 'amount', 'email'];
20
+ // 需要格式化后校对光标的类型
32
21
  var RESET_CURSOR_TYPE = ['id', 'tel', 'card'];
33
-
34
22
  var useInput = function useInput(_ref) {
35
23
  var name = _ref.name,
36
- _ref$autoFocus = _ref.autoFocus,
37
- autoFocus = _ref$autoFocus === void 0 ? false : _ref$autoFocus,
38
- _ref$disabled = _ref.disabled,
39
- disabled = _ref$disabled === void 0 ? false : _ref$disabled,
40
- _ref$readOnly = _ref.readOnly,
41
- readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
42
- maxLength = _ref.maxLength,
43
- placeholder = _ref.placeholder,
44
- _ref$defaultValue = _ref.defaultValue,
45
- defaultValue = _ref$defaultValue === void 0 ? '' : _ref$defaultValue,
46
- valueProp = _ref.value,
47
- onChange = _ref.onChange,
48
- onFocus = _ref.onFocus,
49
- onBlur = _ref.onBlur,
50
- onKeyDown = _ref.onKeyDown,
51
- _ref$trimValueOnBlur = _ref.trimValueOnBlur,
52
- trimValueOnBlur = _ref$trimValueOnBlur === void 0 ? false : _ref$trimValueOnBlur,
53
- _ref$type = _ref.type,
54
- type = _ref$type === void 0 ? 'text' : _ref$type,
55
- clearElementRef = _ref.clearElementRef,
56
- inputElementRef = _ref.inputElementRef; // Object.is 避免 trimValueOnBlur 和 点击 clearIcon 触发 2 次相同的 onCHange
57
-
24
+ _ref$autoFocus = _ref.autoFocus,
25
+ autoFocus = _ref$autoFocus === void 0 ? false : _ref$autoFocus,
26
+ _ref$disabled = _ref.disabled,
27
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled,
28
+ _ref$readOnly = _ref.readOnly,
29
+ readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
30
+ maxLength = _ref.maxLength,
31
+ placeholder = _ref.placeholder,
32
+ _ref$defaultValue = _ref.defaultValue,
33
+ defaultValue = _ref$defaultValue === void 0 ? '' : _ref$defaultValue,
34
+ valueProp = _ref.value,
35
+ onChange = _ref.onChange,
36
+ onFocus = _ref.onFocus,
37
+ onBlur = _ref.onBlur,
38
+ onKeyDown = _ref.onKeyDown,
39
+ _ref$trimValueOnBlur = _ref.trimValueOnBlur,
40
+ trimValueOnBlur = _ref$trimValueOnBlur === void 0 ? false : _ref$trimValueOnBlur,
41
+ _ref$type = _ref.type,
42
+ type = _ref$type === void 0 ? 'text' : _ref$type,
43
+ clearElementRef = _ref.clearElementRef,
44
+ inputElementRef = _ref.inputElementRef;
45
+ // Object.is 避免 trimValueOnBlur 和 点击 clearIcon 触发 2 次相同的 onCHange
58
46
  var _useUncontrolledState = useUncontrolledState.useUncontrolledState(defaultValue, valueProp, onChange, Object.is),
59
- value = _useUncontrolledState[0],
60
- tryChangeValue = _useUncontrolledState[1];
61
-
47
+ value = _useUncontrolledState[0],
48
+ tryChangeValue = _useUncontrolledState[1];
62
49
  var _useInputCursor = useInputCursor.useInputCursor({
63
- inputElementRef: inputElementRef,
64
- value: index.format(value, type)
65
- }),
66
- formatHandleChange = _useInputCursor.handleChange,
67
- handleOnKeyDown = _useInputCursor.handleOnKeyDown,
68
- position = _useInputCursor.position;
50
+ inputElementRef: inputElementRef,
51
+ value: index.format(value, type)
52
+ }),
53
+ formatHandleChange = _useInputCursor.handleChange,
54
+ handleOnKeyDown = _useInputCursor.handleOnKeyDown,
55
+ position = _useInputCursor.position;
69
56
  /**
70
57
  * 修复值格式化时光标位置问题:https://github.com/XiaoMi/hiui/issues/2438
71
58
  */
72
-
73
-
74
59
  var needResetCursorPosition = React.useMemo(function () {
75
60
  return RESET_CURSOR_TYPE.includes(type);
76
61
  }, [type]);
@@ -78,18 +63,15 @@ var useInput = function useInput(_ref) {
78
63
  if (trim === void 0) {
79
64
  trim = false;
80
65
  }
81
-
82
66
  evt.persist();
83
67
  var nextValue = evt.target.value;
84
- var valueTrue = index.pure(nextValue, type); // 防溢出,保证 onChange 拿到的是值是最新的 formatted value
85
-
68
+ var valueTrue = index.pure(nextValue, type);
69
+ // 防溢出,保证 onChange 拿到的是值是最新的 formatted value
86
70
  var value = index.format(nextValue, type);
87
-
88
71
  if (trim) {
89
72
  valueTrue = valueTrue.trim();
90
73
  value = value.trim();
91
74
  }
92
-
93
75
  var event = Object.create(evt);
94
76
  event.target = Object.assign(Object.assign({}, evt.target), {
95
77
  value: value
@@ -97,31 +79,27 @@ var useInput = function useInput(_ref) {
97
79
  tryChangeValue(valueTrue, event);
98
80
  needResetCursorPosition && formatHandleChange(event);
99
81
  }, [formatHandleChange, needResetCursorPosition, tryChangeValue, type]);
100
-
101
82
  var _useState = React.useState(autoFocus),
102
- focused = _useState[0],
103
- setFocused = _useState[1];
104
-
83
+ focused = _useState[0],
84
+ setFocused = _useState[1];
105
85
  var handleFocus = useLatest.useLatestCallback(function (evt) {
106
86
  setFocused(true);
107
87
  onFocus === null || onFocus === void 0 ? void 0 : onFocus(evt);
108
88
  });
109
89
  var handleBlur = useLatest.useLatestCallback(function (event) {
110
- var relatedTarget = event.relatedTarget; // 拦截 clearIcon 点击清空,阻止其触发 input 失焦
111
-
90
+ var relatedTarget = event.relatedTarget;
91
+ // 拦截 clearIcon 点击清空,阻止其触发 input 失焦
112
92
  if (clearElementRef && clearElementRef.current && clearElementRef.current === relatedTarget) {
113
93
  return;
114
94
  }
115
-
116
- setFocused(false); // amount 自动添加小数
117
-
95
+ setFocused(false);
96
+ // amount 自动添加小数
118
97
  if (type === 'amount') {
119
98
  event.target.value = index.formatAmount(value, true);
120
99
  handleChange(event, trimValueOnBlur);
121
100
  } else if (trimValueOnBlur) {
122
101
  handleChange(event, true);
123
102
  }
124
-
125
103
  onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
126
104
  });
127
105
  var nativeInputProps = React.useMemo(function () {
@@ -160,5 +138,4 @@ var useInput = function useInput(_ref) {
160
138
  getInputProps: getInputProps
161
139
  };
162
140
  };
163
-
164
141
  exports.useInput = useInput;
@@ -9,21 +9,15 @@
9
9
  */
10
10
  'use strict';
11
11
 
12
- Object.defineProperty(exports, '__esModule', {
13
- value: true
14
- });
15
12
  /**
16
13
  * 格式化身份证
17
14
  */
18
-
19
15
  var formatId = function formatId(val) {
20
16
  val = val.replace(/[^a-zA-Z0-9]/g, '');
21
17
  var len = val.length;
22
-
23
18
  if (val === '' || len < 7) {
24
19
  return val;
25
20
  }
26
-
27
21
  if (len < 11) {
28
22
  return val.slice(0, 6) + ' ' + val.slice(6, 10);
29
23
  } else if (len < 15) {
@@ -32,7 +26,6 @@ var formatId = function formatId(val) {
32
26
  return val.slice(0, 6) + ' ' + val.slice(6, 10) + ' ' + val.slice(10, 14) + ' ' + val.slice(14, 18);
33
27
  }
34
28
  };
35
-
36
29
  var pureId = function pureId(val) {
37
30
  var tmp = val.replace(/[^\d|.]/g, '');
38
31
  return tmp.slice(0, 18);
@@ -40,23 +33,18 @@ var pureId = function pureId(val) {
40
33
  /**
41
34
  * 格式化手机号
42
35
  */
43
-
44
-
45
36
  var formatTel = function formatTel(val) {
46
37
  val = val.replace(/\D/g, '');
47
38
  var len = val.length;
48
-
49
39
  if (val === '' || len < 4) {
50
40
  return val;
51
41
  }
52
-
53
42
  if (len < 8) {
54
43
  return val.slice(0, 3) + ' ' + val.slice(3, 7);
55
44
  } else {
56
45
  return val.slice(0, 3) + ' ' + val.slice(3, 7) + ' ' + val.slice(7, 11);
57
46
  }
58
47
  };
59
-
60
48
  var pureTel = function pureTel(val) {
61
49
  var tmp = val.replace(/[^\d|.]/g, '');
62
50
  return tmp.slice(0, 11);
@@ -64,16 +52,12 @@ var pureTel = function pureTel(val) {
64
52
  /**
65
53
  * 格式化银行卡号
66
54
  */
67
-
68
-
69
55
  var formatCard = function formatCard(val) {
70
56
  val = val.replace(/\D/g, '');
71
57
  var len = val.length;
72
-
73
58
  if (val === '' || val.length < 5) {
74
59
  return val;
75
60
  }
76
-
77
61
  if (len < 9) {
78
62
  return val.slice(0, 4) + ' ' + val.slice(4, 8);
79
63
  } else if (len < 13) {
@@ -84,7 +68,6 @@ var formatCard = function formatCard(val) {
84
68
  return val.slice(0, 4) + ' ' + val.slice(4, 8) + ' ' + val.slice(8, 12) + ' ' + val.slice(12, 16) + ' ' + val.slice(16, 19);
85
69
  }
86
70
  };
87
-
88
71
  var pureCard = function pureCard(val) {
89
72
  var tmp = val.replace(/[^\d|.]/g, '');
90
73
  return tmp.slice(0, 19);
@@ -93,59 +76,44 @@ var pureCard = function pureCard(val) {
93
76
  * 金额自动生成小数
94
77
  * @param {string} val 需要处理的值
95
78
  */
96
-
97
-
98
79
  var formatAmount = function formatAmount(val, fill) {
99
80
  if (fill === void 0) {
100
81
  fill = false;
101
82
  }
102
-
103
83
  val = val.replace(/[^\d|.|,]/g, '').replace(/(\.\d*?)(\.|,).*/, function (_, $1) {
104
84
  return $1;
105
85
  });
106
-
107
86
  if (fill) {
108
87
  if (!val) return val;
109
88
  return val.indexOf('.') > -1 ? val : val + '.00';
110
89
  }
111
-
112
90
  return val;
113
91
  };
114
-
115
92
  var pureAmount = function pureAmount(val) {
116
93
  var tmp = val.replace(/[^\d|.]/g, '');
117
94
  return tmp;
118
95
  };
119
-
120
96
  var formatEmail = function formatEmail(val) {
121
97
  return val.replace(/\W/g, '');
122
98
  };
123
-
124
99
  var pureEmail = function pureEmail(val) {
125
100
  return val;
126
101
  };
127
102
  /**
128
103
  * 输入规则
129
104
  */
130
-
131
-
132
105
  var format = function format(val, type) {
133
106
  switch (type) {
134
107
  case 'id':
135
108
  return formatId(val);
136
-
137
109
  case 'tel':
138
110
  return formatTel(val);
139
-
140
111
  case 'card':
141
112
  return formatCard(val);
142
-
143
113
  case 'email':
144
114
  return formatEmail(val);
145
-
146
115
  case 'amount':
147
116
  return formatAmount(val);
148
-
149
117
  default:
150
118
  return val;
151
119
  }
@@ -153,30 +121,22 @@ var format = function format(val, type) {
153
121
  /**
154
122
  * 净化规则
155
123
  */
156
-
157
-
158
124
  var pure = function pure(val, type) {
159
125
  switch (type) {
160
126
  case 'id':
161
127
  return pureId(val);
162
-
163
128
  case 'tel':
164
129
  return pureTel(val);
165
-
166
130
  case 'card':
167
131
  return pureCard(val);
168
-
169
132
  case 'email':
170
133
  return pureEmail(val);
171
-
172
134
  case 'amount':
173
135
  return pureAmount(val);
174
-
175
136
  default:
176
137
  return val;
177
138
  }
178
139
  };
179
-
180
140
  exports.format = format;
181
141
  exports.formatAmount = formatAmount;
182
142
  exports.formatCard = formatCard;
package/lib/esm/Input.js CHANGED
@@ -14,113 +14,101 @@ import { __DEV__ } from '@hi-ui/env';
14
14
  import { useMergeRefs } from '@hi-ui/use-merge-refs';
15
15
  import { CloseCircleFilled } from '@hi-ui/icons';
16
16
  import { useInput } from './use-input.js';
17
-
18
17
  var _prefix = getPrefixCls('input');
19
18
  /**
20
19
  * 输入框
21
20
  */
22
-
23
-
24
21
  var Input = /*#__PURE__*/forwardRef(function (_a, ref) {
25
22
  var _a$prefixCls = _a.prefixCls,
26
- prefixCls = _a$prefixCls === void 0 ? _prefix : _a$prefixCls,
27
- _a$role = _a.role,
28
- role = _a$role === void 0 ? 'input' : _a$role,
29
- className = _a.className,
30
- style = _a.style,
31
- _a$size = _a.size,
32
- size = _a$size === void 0 ? 'md' : _a$size,
33
- _a$appearance = _a.appearance,
34
- appearance = _a$appearance === void 0 ? 'line' : _a$appearance,
35
- prepend = _a.prepend,
36
- append = _a.append,
37
- prefix = _a.prefix,
38
- suffix = _a.suffix,
39
- _a$clearableTrigger = _a.clearableTrigger,
40
- clearableTrigger = _a$clearableTrigger === void 0 ? 'hover' : _a$clearableTrigger,
41
- _a$clearable = _a.clearable,
42
- clearable = _a$clearable === void 0 ? false : _a$clearable,
43
- _a$invalid = _a.invalid,
44
- invalid = _a$invalid === void 0 ? false : _a$invalid,
45
- name = _a.name,
46
- autoFocus = _a.autoFocus,
47
- disabled = _a.disabled,
48
- readOnly = _a.readOnly,
49
- maxLength = _a.maxLength,
50
- placeholder = _a.placeholder,
51
- defaultValue = _a.defaultValue,
52
- valueProp = _a.value,
53
- onChange = _a.onChange,
54
- onFocus = _a.onFocus,
55
- onBlur = _a.onBlur,
56
- onKeyDown = _a.onKeyDown,
57
- trimValueOnBlur = _a.trimValueOnBlur,
58
- onClear = _a.onClear,
59
- type = _a.type,
60
- containerRef = _a.containerRef,
61
- rest = __rest(_a, ["prefixCls", "role", "className", "style", "size", "appearance", "prepend", "append", "prefix", "suffix", "clearableTrigger", "clearable", "invalid", "name", "autoFocus", "disabled", "readOnly", "maxLength", "placeholder", "defaultValue", "value", "onChange", "onFocus", "onBlur", "onKeyDown", "trimValueOnBlur", "onClear", "type", "containerRef"]); // @TODO: 临时方案,后面迁移至 InputGroup
62
-
63
-
23
+ prefixCls = _a$prefixCls === void 0 ? _prefix : _a$prefixCls,
24
+ _a$role = _a.role,
25
+ role = _a$role === void 0 ? 'input' : _a$role,
26
+ className = _a.className,
27
+ style = _a.style,
28
+ _a$size = _a.size,
29
+ size = _a$size === void 0 ? 'md' : _a$size,
30
+ _a$appearance = _a.appearance,
31
+ appearance = _a$appearance === void 0 ? 'line' : _a$appearance,
32
+ prepend = _a.prepend,
33
+ append = _a.append,
34
+ prefix = _a.prefix,
35
+ suffix = _a.suffix,
36
+ _a$clearableTrigger = _a.clearableTrigger,
37
+ clearableTrigger = _a$clearableTrigger === void 0 ? 'hover' : _a$clearableTrigger,
38
+ _a$clearable = _a.clearable,
39
+ clearable = _a$clearable === void 0 ? false : _a$clearable,
40
+ _a$invalid = _a.invalid,
41
+ invalid = _a$invalid === void 0 ? false : _a$invalid,
42
+ name = _a.name,
43
+ autoFocus = _a.autoFocus,
44
+ disabled = _a.disabled,
45
+ readOnly = _a.readOnly,
46
+ maxLength = _a.maxLength,
47
+ placeholder = _a.placeholder,
48
+ defaultValue = _a.defaultValue,
49
+ valueProp = _a.value,
50
+ onChange = _a.onChange,
51
+ onFocus = _a.onFocus,
52
+ onBlur = _a.onBlur,
53
+ onKeyDown = _a.onKeyDown,
54
+ trimValueOnBlur = _a.trimValueOnBlur,
55
+ onClear = _a.onClear,
56
+ type = _a.type,
57
+ containerRef = _a.containerRef,
58
+ rest = __rest(_a, ["prefixCls", "role", "className", "style", "size", "appearance", "prepend", "append", "prefix", "suffix", "clearableTrigger", "clearable", "invalid", "name", "autoFocus", "disabled", "readOnly", "maxLength", "placeholder", "defaultValue", "value", "onChange", "onFocus", "onBlur", "onKeyDown", "trimValueOnBlur", "onClear", "type", "containerRef"]);
59
+ // @TODO: 临时方案,后面迁移至 InputGroup
64
60
  var _useMemo = useMemo(function () {
65
- var shouldUnset = [false, false]; // @ts-ignore
66
- // @ts-ignore
67
-
68
- if ( /*#__PURE__*/isValidElement(prepend) && ['Select', 'Button'].includes(prepend.type.HiName)) {
69
- shouldUnset[0] = true;
70
- } // @ts-ignore
71
- // @ts-ignore
72
-
73
-
74
- if ( /*#__PURE__*/isValidElement(append) && ['Select', 'Button'].includes(append.type.HiName)) {
75
- shouldUnset[1] = true;
76
- }
77
-
78
- return shouldUnset;
79
- }, [prepend, append]),
80
- unsetPrepend = _useMemo[0],
81
- unsetAppend = _useMemo[1];
82
-
61
+ var shouldUnset = [false, false];
62
+ // @ts-ignore
63
+ // @ts-ignore
64
+ if ( /*#__PURE__*/isValidElement(prepend) && ['Select', 'Button'].includes(prepend.type.HiName)) {
65
+ shouldUnset[0] = true;
66
+ }
67
+ // @ts-ignore
68
+ // @ts-ignore
69
+ if ( /*#__PURE__*/isValidElement(append) && ['Select', 'Button'].includes(append.type.HiName)) {
70
+ shouldUnset[1] = true;
71
+ }
72
+ return shouldUnset;
73
+ }, [prepend, append]),
74
+ unsetPrepend = _useMemo[0],
75
+ unsetAppend = _useMemo[1];
83
76
  var inputElementRef = useRef(null);
84
77
  var proxyOnChange = useCallback(function (value, evt) {
85
78
  if (!onChange) return;
86
79
  onChangeMock(onChange, evt, inputElementRef.current, value);
87
80
  }, [onChange]);
88
81
  var clearElementRef = useRef(null);
89
-
90
82
  var _useInput = useInput({
91
- clearElementRef: clearElementRef,
92
- inputElementRef: inputElementRef,
93
- name: name,
94
- autoFocus: autoFocus,
95
- disabled: disabled,
96
- readOnly: readOnly,
97
- maxLength: maxLength,
98
- placeholder: placeholder,
99
- defaultValue: defaultValue,
100
- value: valueProp,
101
- onChange: proxyOnChange,
102
- onFocus: onFocus,
103
- onBlur: onBlur,
104
- onKeyDown: onKeyDown,
105
- trimValueOnBlur: trimValueOnBlur,
106
- type: type
107
- }),
108
- tryChangeValue = _useInput.tryChangeValue,
109
- focused = _useInput.focused,
110
- value = _useInput.value,
111
- getInputProps = _useInput.getInputProps;
112
-
83
+ clearElementRef: clearElementRef,
84
+ inputElementRef: inputElementRef,
85
+ name: name,
86
+ autoFocus: autoFocus,
87
+ disabled: disabled,
88
+ readOnly: readOnly,
89
+ maxLength: maxLength,
90
+ placeholder: placeholder,
91
+ defaultValue: defaultValue,
92
+ value: valueProp,
93
+ onChange: proxyOnChange,
94
+ onFocus: onFocus,
95
+ onBlur: onBlur,
96
+ onKeyDown: onKeyDown,
97
+ trimValueOnBlur: trimValueOnBlur,
98
+ type: type
99
+ }),
100
+ tryChangeValue = _useInput.tryChangeValue,
101
+ focused = _useInput.focused,
102
+ value = _useInput.value,
103
+ getInputProps = _useInput.getInputProps;
113
104
  var focus = useCallback(function () {
114
105
  var _a;
115
-
116
106
  (_a = inputElementRef.current) === null || _a === void 0 ? void 0 : _a.focus();
117
107
  }, []);
118
-
119
108
  var _useState = useState(false),
120
- hover = _useState[0],
121
- setHover = _useState[1]; // 在开启 clearable 下展示 清除内容按钮,可点击进行内容清楚
122
-
123
-
109
+ hover = _useState[0],
110
+ setHover = _useState[1];
111
+ // 在开启 clearable 下展示 清除内容按钮,可点击进行内容清楚
124
112
  var showClearableIcon = clearable && !!value && !disabled;
125
113
  var mergedRef = useMergeRefs(ref, inputElementRef);
126
114
  var cls = cx(prefixCls, className, prefixCls + "--size-" + size, prefixCls + "--appearance-" + appearance);
@@ -163,7 +151,6 @@ var Input = /*#__PURE__*/forwardRef(function (_a, ref) {
163
151
  className: prefixCls + "__append"
164
152
  }, append) : null));
165
153
  });
166
-
167
154
  if (__DEV__) {
168
155
  Input.displayName = 'Input';
169
156
  }
@@ -176,11 +163,9 @@ if (__DEV__) {
176
163
  * @param targetValue
177
164
  * @returns
178
165
  */
179
-
180
-
181
166
  function onChangeMock(onChange, evt, target, targetValue) {
182
- var event = evt; // 点击 clearIcon 或者 失焦 trim 时,都会代理 onChange 的事件对象 target 指向 input.target
183
-
167
+ var event = evt;
168
+ // 点击 clearIcon 或者 失焦 trim 时,都会代理 onChange 的事件对象 target 指向 input.target
184
169
  if (evt.type !== 'change') {
185
170
  if (!target) return;
186
171
  var originalTargetValue = target.value;
@@ -188,13 +173,11 @@ function onChangeMock(onChange, evt, target, targetValue) {
188
173
  event.target = target;
189
174
  event.currentTarget = target;
190
175
  target.value = targetValue;
191
- onChange(event, targetValue); // 重置为之前值
192
-
176
+ onChange(event, targetValue);
177
+ // 重置为之前值
193
178
  target.value = originalTargetValue;
194
179
  return;
195
180
  }
196
-
197
181
  onChange(event, targetValue);
198
182
  }
199
-
200
183
  export { Input, onChangeMock };