@sheinx/hooks 3.9.14-beta.9 → 3.9.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.
@@ -3,6 +3,7 @@ import { InputNumberProps } from './use-input-number.type';
3
3
  declare const useNumberFormat: (props: InputNumberProps) => {
4
4
  onPlus: () => void;
5
5
  onMinus: () => void;
6
+ onClear: () => void;
6
7
  onChange: (v: string | undefined) => void;
7
8
  onBlur: (e: React.FocusEvent<HTMLInputElement, Element>) => void;
8
9
  onFocus: (e: React.FocusEvent<HTMLInputElement, Element>) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"use-input-number.d.ts","sourceRoot":"","sources":["use-input-number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAK3D,QAAA,MAAM,eAAe,UAAW,gBAAgB;;;;;;;;CA6L/C,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"use-input-number.d.ts","sourceRoot":"","sources":["use-input-number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAK3D,QAAA,MAAM,eAAe,UAAW,gBAAgB;;;;;;;;;CAiM/C,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -34,6 +34,7 @@ var useNumberFormat = function useNumberFormat(props) {
34
34
  min = props.min,
35
35
  max = props.max,
36
36
  allowNull = props.allowNull,
37
+ clearToUndefined = props.clearToUndefined,
37
38
  _props$step = props.step,
38
39
  step = _props$step === void 0 ? 1 : _props$step,
39
40
  cancelBlurChange = props.cancelBlurChange,
@@ -54,11 +55,8 @@ var useNumberFormat = function useNumberFormat(props) {
54
55
  setInternalInputValue = _React$useState2[1];
55
56
  var focusedRef = _react.default.useRef(false);
56
57
  (0, _react.useEffect)(function () {
57
- // 将外部值转为字符串后再比较,避免 number 5 vs string "5" 的类型不匹配误判
58
58
  var stringValue = getStringValue(props.value);
59
- // 聚焦编辑期间不同步外部值,避免 form 回填 defaultValue 覆盖用户输入
60
- // 但当外部值被清空时(如 clearable 触发),即使聚焦也需要同步
61
- if (stringValue !== inernalInputValue && (!focusedRef.current || props.value == null || props.value === '')) {
59
+ if (stringValue !== inernalInputValue && (!focusedRef.current || props.value == null)) {
62
60
  setInternalInputValue(stringValue);
63
61
  }
64
62
  }, [props.value]);
@@ -185,6 +183,10 @@ var useNumberFormat = function useNumberFormat(props) {
185
183
  var num = changeValue(-step);
186
184
  if (num !== undefined) setInternalInputValue(getStringValue(num));
187
185
  });
186
+ var handleClear = (0, _usePersistFn.default)(function () {
187
+ setInternalInputValue('');
188
+ onChange === null || onChange === void 0 || onChange(clearToUndefined ? undefined : allowNull ? null : '');
189
+ });
188
190
  return _objectSpread(_objectSpread({}, (0, _useInputFormat.default)({
189
191
  value: inernalInputValue,
190
192
  type: 'number',
@@ -198,7 +200,8 @@ var useNumberFormat = function useNumberFormat(props) {
198
200
  cancelBlurChange: true
199
201
  })), {}, {
200
202
  onPlus: handlePlus,
201
- onMinus: handleMinus
203
+ onMinus: handleMinus,
204
+ onClear: handleClear
202
205
  });
203
206
  };
204
207
  var _default = exports.default = useNumberFormat;
@@ -23,6 +23,7 @@ export interface InputNumberProps extends Omit<InputFormatProps, 'value' | 'onCh
23
23
  * @cn 清空后值为 null
24
24
  */
25
25
  allowNull?: boolean;
26
+ clearToUndefined?: boolean;
26
27
  /**
27
28
  * @en Change the digital span. It can be decimal
28
29
  * @cn 改变数字跨度,可为小数
@@ -1 +1 @@
1
- {"version":3,"file":"use-input-number.type.d.ts","sourceRoot":"","sources":["use-input-number.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CA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C;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
@@ -3,6 +3,7 @@ import { InputNumberProps } from './use-input-number.type';
3
3
  declare const useNumberFormat: (props: InputNumberProps) => {
4
4
  onPlus: () => void;
5
5
  onMinus: () => void;
6
+ onClear: () => void;
6
7
  onChange: (v: string | undefined) => void;
7
8
  onBlur: (e: React.FocusEvent<HTMLInputElement, Element>) => void;
8
9
  onFocus: (e: React.FocusEvent<HTMLInputElement, Element>) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"use-input-number.d.ts","sourceRoot":"","sources":["use-input-number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAK3D,QAAA,MAAM,eAAe,UAAW,gBAAgB;;;;;;;;CA6L/C,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"use-input-number.d.ts","sourceRoot":"","sources":["use-input-number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAK3D,QAAA,MAAM,eAAe,UAAW,gBAAgB;;;;;;;;;CAiM/C,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -25,6 +25,7 @@ var useNumberFormat = function useNumberFormat(props) {
25
25
  min = props.min,
26
26
  max = props.max,
27
27
  allowNull = props.allowNull,
28
+ clearToUndefined = props.clearToUndefined,
28
29
  _props$step = props.step,
29
30
  step = _props$step === void 0 ? 1 : _props$step,
30
31
  cancelBlurChange = props.cancelBlurChange,
@@ -45,11 +46,8 @@ var useNumberFormat = function useNumberFormat(props) {
45
46
  setInternalInputValue = _React$useState2[1];
46
47
  var focusedRef = React.useRef(false);
47
48
  useEffect(function () {
48
- // 将外部值转为字符串后再比较,避免 number 5 vs string "5" 的类型不匹配误判
49
49
  var stringValue = getStringValue(props.value);
50
- // 聚焦编辑期间不同步外部值,避免 form 回填 defaultValue 覆盖用户输入
51
- // 但当外部值被清空时(如 clearable 触发),即使聚焦也需要同步
52
- if (stringValue !== inernalInputValue && (!focusedRef.current || props.value == null || props.value === '')) {
50
+ if (stringValue !== inernalInputValue && (!focusedRef.current || props.value == null)) {
53
51
  setInternalInputValue(stringValue);
54
52
  }
55
53
  }, [props.value]);
@@ -176,6 +174,10 @@ var useNumberFormat = function useNumberFormat(props) {
176
174
  var num = changeValue(-step);
177
175
  if (num !== undefined) setInternalInputValue(getStringValue(num));
178
176
  });
177
+ var handleClear = usePersistFn(function () {
178
+ setInternalInputValue('');
179
+ onChange === null || onChange === void 0 || onChange(clearToUndefined ? undefined : allowNull ? null : '');
180
+ });
179
181
  return _objectSpread(_objectSpread({}, useInputFormat({
180
182
  value: inernalInputValue,
181
183
  type: 'number',
@@ -189,7 +191,8 @@ var useNumberFormat = function useNumberFormat(props) {
189
191
  cancelBlurChange: true
190
192
  })), {}, {
191
193
  onPlus: handlePlus,
192
- onMinus: handleMinus
194
+ onMinus: handleMinus,
195
+ onClear: handleClear
193
196
  });
194
197
  };
195
198
  export default useNumberFormat;
@@ -23,6 +23,7 @@ export interface InputNumberProps extends Omit<InputFormatProps, 'value' | 'onCh
23
23
  * @cn 清空后值为 null
24
24
  */
25
25
  allowNull?: boolean;
26
+ clearToUndefined?: boolean;
26
27
  /**
27
28
  * @en Change the digital span. It can be decimal
28
29
  * @cn 改变数字跨度,可为小数
@@ -1 +1 @@
1
- {"version":3,"file":"use-input-number.type.d.ts","sourceRoot":"","sources":["use-input-number.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;AAC7D,MAAM,WAAW,gBACf,SAAQ,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IAClF,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,SAAS,CAAC;IACnD;;;OAGG;IACH,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
1
+ {"version":3,"file":"use-input-number.type.d.ts","sourceRoot":"","sources":["use-input-number.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,CAAC;AAC7D,MAAM,WAAW,gBACf,SAAQ,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;IAClF,KAAK,EAAE,WAAW,CAAC;IACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,IAAI,GAAG,SAAS,CAAC;IACnD;;;OAGG;IACH,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B;;;;OAIG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/hooks",
3
- "version": "3.9.14-beta.9",
3
+ "version": "3.9.14",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",