@sheinx/hooks 3.4.0-beta.7 → 3.4.0-beta.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,10 +50,10 @@ function useInputAble(props) {
50
50
  clearTimeout(context.timer);
51
51
  context.timer = null;
52
52
  }
53
- if (delay && props.value !== stateValue) {
53
+ if (delay && control && props.value !== stateValue) {
54
54
  changeStateValue(props.value);
55
55
  }
56
- }, [props.value, delay]);
56
+ }, [props.value, delay, control]);
57
57
  var forceDelayChange = (0, _usePersistFn.default)(function () {
58
58
  if (context.timer && context.delayChange) {
59
59
  clearTimeout(context.timer);
@@ -1 +1 @@
1
- {"version":3,"file":"use-input-number.d.ts","sourceRoot":"","sources":["use-input-number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAK3D,QAAA,MAAM,eAAe,UAAW,gBAAgB;;;;;;;;CA6H/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;;;;;;;;CAkJ/C,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1,20 +1,29 @@
1
1
  "use strict";
2
2
 
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.default = void 0;
8
+ var _react = _interopRequireWildcard(require("react"));
7
9
  var _usePersistFn = _interopRequireDefault(require("../../common/use-persist-fn"));
8
10
  var _useInputFormat = _interopRequireDefault(require("./use-input-format"));
9
11
  var _number = require("../../utils/number");
10
12
  var _is = require("../../utils/is");
11
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
14
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
15
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
16
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
17
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
18
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
16
19
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
17
20
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
21
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
22
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
23
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
24
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
25
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
26
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
18
27
  var useNumberFormat = function useNumberFormat(props) {
19
28
  var onChange = props.onChange,
20
29
  value = props.value,
@@ -37,6 +46,15 @@ var useNumberFormat = function useNumberFormat(props) {
37
46
  }
38
47
  return value || '';
39
48
  };
49
+ var _React$useState = _react.default.useState(getStringValue(props.value)),
50
+ _React$useState2 = _slicedToArray(_React$useState, 2),
51
+ inernalInputValue = _React$useState2[0],
52
+ setInternalInputValue = _React$useState2[1];
53
+ (0, _react.useEffect)(function () {
54
+ if (props.value !== inernalInputValue) {
55
+ setInternalInputValue(getStringValue(props.value));
56
+ }
57
+ }, [props.value]);
40
58
  var getNumberValue = function getNumberValue(value) {
41
59
  if (isNaN(value)) return 0;
42
60
  if (typeof value === 'number') {
@@ -54,6 +72,17 @@ var useNumberFormat = function useNumberFormat(props) {
54
72
  }
55
73
  return num;
56
74
  };
75
+ var onInnerChange = (0, _usePersistFn.default)(function (val) {
76
+ setInternalInputValue(getStringValue(val));
77
+ if (typeof val === 'string') {
78
+ var num = parseFloat(val);
79
+ if (isNaN(num)) return;
80
+ onChange === null || onChange === void 0 || onChange(num);
81
+ } else {
82
+ onChange === null || onChange === void 0 || onChange(val);
83
+ }
84
+ ;
85
+ });
57
86
  var onNumberBlur = (0, _usePersistFn.default)(function (e) {
58
87
  var target = e.target;
59
88
  var newValue = target.value;
@@ -64,7 +93,7 @@ var useNumberFormat = function useNumberFormat(props) {
64
93
  return;
65
94
  }
66
95
  if (newValue === '' && allowNull) {
67
- onChange === null || onChange === void 0 || onChange(null);
96
+ onInnerChange(null);
68
97
  onBlur === null || onBlur === void 0 || onBlur(e);
69
98
  return;
70
99
  }
@@ -79,15 +108,18 @@ var useNumberFormat = function useNumberFormat(props) {
79
108
  num = parseFloat(num.toFixed(digits));
80
109
  }
81
110
  num = commonFormat(num);
111
+
112
+ // 失焦时,将非法值转换为合法值
113
+ setInternalInputValue(getStringValue(num));
82
114
  if (num !== value) {
83
115
  target.value = typeof num === 'number' ? String(num) : '';
84
- if (!cancelBlurChange) onChange === null || onChange === void 0 || onChange(num);
116
+ if (!cancelBlurChange) onInnerChange(num);
85
117
  }
86
118
  onBlur === null || onBlur === void 0 || onBlur(e);
87
119
  });
88
120
  var onNumberChange = (0, _usePersistFn.default)(function (value) {
89
121
  var result = value;
90
- onChange === null || onChange === void 0 || onChange(result);
122
+ onInnerChange(result);
91
123
  });
92
124
  var changeValue = function changeValue(mod) {
93
125
  var num = getNumberValue(props.value);
@@ -113,7 +145,7 @@ var useNumberFormat = function useNumberFormat(props) {
113
145
  changeValue(-step);
114
146
  });
115
147
  return _objectSpread(_objectSpread({}, (0, _useInputFormat.default)({
116
- value: getStringValue(props.value),
148
+ value: inernalInputValue,
117
149
  type: 'number',
118
150
  numType: numType,
119
151
  integerLimit: integerLimit,
@@ -26,7 +26,7 @@ declare const useTableVirtual: (props: UseTableVirtualProps) => {
26
26
  }) => void;
27
27
  setRowHeight: (index: number, height: number) => void;
28
28
  getTranslate: (left?: number, top?: number) => string;
29
- scrollToIndex: (index: number) => void;
29
+ scrollToIndex: (index: number, callback?: () => void) => void;
30
30
  };
31
31
  export default useTableVirtual;
32
32
  //# sourceMappingURL=use-table-virtual.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-table-virtual.d.ts","sourceRoot":"","sources":["use-table-virtual.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,UAAU,oBAAoB;IAC5B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC3C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;CACnC;AACD,QAAA,MAAM,eAAe,UAAW,oBAAoB;;;;;;;oBAsLpC,MAAM;mBACP,MAAM;WACd,MAAM;gBACD,MAAM;kBACJ,OAAO;;0BAtFuB,MAAM,UAAU,MAAM;0BAxBtB,MAAM,QAAQ,MAAM;2BAkJnB,MAAM;CAwFlD,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"use-table-virtual.d.ts","sourceRoot":"","sources":["use-table-virtual.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,UAAU,oBAAoB;IAC5B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC3C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;CACnC;AACD,QAAA,MAAM,eAAe,UAAW,oBAAoB;;;;;;;oBAsLpC,MAAM;mBACP,MAAM;WACd,MAAM;gBACD,MAAM;kBACJ,OAAO;;0BAtFuB,MAAM,UAAU,MAAM;0BAxBtB,MAAM,QAAQ,MAAM;2BAkJnB,MAAM,aAAa,MAAM,IAAI;CA4FzE,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -241,7 +241,7 @@ var useTableVirtual = function useTableVirtual(props) {
241
241
  updateIndexAndTopFromTop(scrollTop);
242
242
  }
243
243
  };
244
- var scrollToIndex = (0, _usePersistFn.usePersistFn)(function (index) {
244
+ var scrollToIndex = (0, _usePersistFn.usePersistFn)(function (index, callback) {
245
245
  if (props.disabled) return;
246
246
  if (props.scrollRef.current) {
247
247
  context.shouldUpdateHeight = true;
@@ -252,6 +252,9 @@ var useTableVirtual = function useTableVirtual(props) {
252
252
  if (beforeHeight2 !== beforeHeight) {
253
253
  scrollToIndex(index);
254
254
  }
255
+ if (callback && typeof callback === 'function') {
256
+ callback();
257
+ }
255
258
  };
256
259
  props.scrollRef.current.scrollTop = beforeHeight;
257
260
  }
@@ -87,7 +87,7 @@ declare const useTransfer: <DataItem, Value extends KeygenResult[]>(props: BaseT
87
87
  filterTargetText: string;
88
88
  sourceSelectedKeys: KeygenResult[];
89
89
  targetSelectedKeys: KeygenResult[];
90
- onSelectChange: ((sourceKeys: KeygenResult[], targetKeys?: KeygenResult[] | undefined) => void) | ((selectKeys: KeygenResult[]) => void);
90
+ onSelectChange: (_value: KeygenResult[], source: KeygenResult[], target: KeygenResult[]) => void;
91
91
  onFilter: (text: string, listType: TransferListType) => void;
92
92
  };
93
93
  export default useTransfer;
@@ -1 +1 @@
1
- {"version":3,"file":"use-transfer.d.ts","sourceRoot":"","sources":["use-transfer.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE1E,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAqHa,MAAM,YAAY,gBAAgB;CAsB/D,CAAC;AAEF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"use-transfer.d.ts","sourceRoot":"","sources":["use-transfer.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE1E,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BA0BL,YAAY,EAAE,UACd,YAAY,EAAE,UACd,YAAY,EAAE;qBAqFI,MAAM,YAAY,gBAAgB;CAsB/D,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -43,12 +43,15 @@ var useTransfer = function useTransfer(props) {
43
43
  _useState4 = _slicedToArray(_useState3, 2),
44
44
  filterTargetText = _useState4[0],
45
45
  setFilterTargetText = _useState4[1];
46
+ var handleSelectedChange = function handleSelectedChange(_value, source, target) {
47
+ onSelectChangeProp === null || onSelectChangeProp === void 0 || onSelectChangeProp(source, target);
48
+ };
46
49
  var _useInputAble = (0, _useInputAble3.useInputAble)({
47
50
  value: selectValue,
48
51
  defaultValue: defaultSelectValue,
49
52
  control: selectControl,
50
53
  beforeChange: undefined,
51
- onChange: onSelectChangeProp
54
+ onChange: handleSelectedChange
52
55
  }),
53
56
  selectedKeys = _useInputAble.value,
54
57
  onSelectChange = _useInputAble.onChange;
@@ -105,24 +108,12 @@ var useTransfer = function useTransfer(props) {
105
108
  return keygen;
106
109
  };
107
110
  var handleSourceSelectedChange = function handleSourceSelectedChange(value) {
108
- if (selectControl) {
109
- // 受控情况下整合工作交给用户处理
110
- onSelectChange === null || onSelectChange === void 0 || onSelectChange(value, targetSelectedKeys);
111
- } else {
112
- // 非受控内部直接整合 source target
113
- var next = [].concat(_toConsumableArray(value), _toConsumableArray(targetSelectedKeys));
114
- onSelectChange === null || onSelectChange === void 0 || onSelectChange(next);
115
- }
111
+ var next = [].concat(_toConsumableArray(value), _toConsumableArray(targetSelectedKeys));
112
+ onSelectChange === null || onSelectChange === void 0 || onSelectChange(next, value, targetSelectedKeys);
116
113
  };
117
114
  var handleTargetSelectedChange = function handleTargetSelectedChange(value) {
118
- if (selectControl) {
119
- // 受控情况下整合工作交给用户处理
120
- onSelectChange === null || onSelectChange === void 0 || onSelectChange(sourceSelectedKeys, value);
121
- } else {
122
- // 非受控内部直接整合 source target
123
- var next = [].concat(_toConsumableArray(sourceSelectedKeys), _toConsumableArray(value));
124
- onSelectChange === null || onSelectChange === void 0 || onSelectChange(next);
125
- }
115
+ var next = [].concat(_toConsumableArray(sourceSelectedKeys), _toConsumableArray(value));
116
+ onSelectChange === null || onSelectChange === void 0 || onSelectChange(next, sourceSelectedKeys, value);
126
117
  };
127
118
  var sourceDatum = (0, _useListSelect.useListSelectMultiple)({
128
119
  value: sourceSelectedKeys,
@@ -43,10 +43,10 @@ export default function useInputAble(props) {
43
43
  clearTimeout(context.timer);
44
44
  context.timer = null;
45
45
  }
46
- if (delay && props.value !== stateValue) {
46
+ if (delay && control && props.value !== stateValue) {
47
47
  changeStateValue(props.value);
48
48
  }
49
- }, [props.value, delay]);
49
+ }, [props.value, delay, control]);
50
50
  var forceDelayChange = usePersistFn(function () {
51
51
  if (context.timer && context.delayChange) {
52
52
  clearTimeout(context.timer);
@@ -1 +1 @@
1
- {"version":3,"file":"use-input-number.d.ts","sourceRoot":"","sources":["use-input-number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAK3D,QAAA,MAAM,eAAe,UAAW,gBAAgB;;;;;;;;CA6H/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;;;;;;;;CAkJ/C,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -4,6 +4,13 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ import React, { useEffect } from 'react';
7
14
  import usePersistFn from "../../common/use-persist-fn";
8
15
  import useInputFormat from "./use-input-format";
9
16
  import { sub } from "../../utils/number";
@@ -30,6 +37,15 @@ var useNumberFormat = function useNumberFormat(props) {
30
37
  }
31
38
  return value || '';
32
39
  };
40
+ var _React$useState = React.useState(getStringValue(props.value)),
41
+ _React$useState2 = _slicedToArray(_React$useState, 2),
42
+ inernalInputValue = _React$useState2[0],
43
+ setInternalInputValue = _React$useState2[1];
44
+ useEffect(function () {
45
+ if (props.value !== inernalInputValue) {
46
+ setInternalInputValue(getStringValue(props.value));
47
+ }
48
+ }, [props.value]);
33
49
  var getNumberValue = function getNumberValue(value) {
34
50
  if (isNaN(value)) return 0;
35
51
  if (typeof value === 'number') {
@@ -47,6 +63,17 @@ var useNumberFormat = function useNumberFormat(props) {
47
63
  }
48
64
  return num;
49
65
  };
66
+ var onInnerChange = usePersistFn(function (val) {
67
+ setInternalInputValue(getStringValue(val));
68
+ if (typeof val === 'string') {
69
+ var num = parseFloat(val);
70
+ if (isNaN(num)) return;
71
+ onChange === null || onChange === void 0 || onChange(num);
72
+ } else {
73
+ onChange === null || onChange === void 0 || onChange(val);
74
+ }
75
+ ;
76
+ });
50
77
  var onNumberBlur = usePersistFn(function (e) {
51
78
  var target = e.target;
52
79
  var newValue = target.value;
@@ -57,7 +84,7 @@ var useNumberFormat = function useNumberFormat(props) {
57
84
  return;
58
85
  }
59
86
  if (newValue === '' && allowNull) {
60
- onChange === null || onChange === void 0 || onChange(null);
87
+ onInnerChange(null);
61
88
  onBlur === null || onBlur === void 0 || onBlur(e);
62
89
  return;
63
90
  }
@@ -72,15 +99,18 @@ var useNumberFormat = function useNumberFormat(props) {
72
99
  num = parseFloat(num.toFixed(digits));
73
100
  }
74
101
  num = commonFormat(num);
102
+
103
+ // 失焦时,将非法值转换为合法值
104
+ setInternalInputValue(getStringValue(num));
75
105
  if (num !== value) {
76
106
  target.value = typeof num === 'number' ? String(num) : '';
77
- if (!cancelBlurChange) onChange === null || onChange === void 0 || onChange(num);
107
+ if (!cancelBlurChange) onInnerChange(num);
78
108
  }
79
109
  onBlur === null || onBlur === void 0 || onBlur(e);
80
110
  });
81
111
  var onNumberChange = usePersistFn(function (value) {
82
112
  var result = value;
83
- onChange === null || onChange === void 0 || onChange(result);
113
+ onInnerChange(result);
84
114
  });
85
115
  var changeValue = function changeValue(mod) {
86
116
  var num = getNumberValue(props.value);
@@ -106,7 +136,7 @@ var useNumberFormat = function useNumberFormat(props) {
106
136
  changeValue(-step);
107
137
  });
108
138
  return _objectSpread(_objectSpread({}, useInputFormat({
109
- value: getStringValue(props.value),
139
+ value: inernalInputValue,
110
140
  type: 'number',
111
141
  numType: numType,
112
142
  integerLimit: integerLimit,
@@ -26,7 +26,7 @@ declare const useTableVirtual: (props: UseTableVirtualProps) => {
26
26
  }) => void;
27
27
  setRowHeight: (index: number, height: number) => void;
28
28
  getTranslate: (left?: number, top?: number) => string;
29
- scrollToIndex: (index: number) => void;
29
+ scrollToIndex: (index: number, callback?: () => void) => void;
30
30
  };
31
31
  export default useTableVirtual;
32
32
  //# sourceMappingURL=use-table-virtual.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-table-virtual.d.ts","sourceRoot":"","sources":["use-table-virtual.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,UAAU,oBAAoB;IAC5B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC3C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;CACnC;AACD,QAAA,MAAM,eAAe,UAAW,oBAAoB;;;;;;;oBAsLpC,MAAM;mBACP,MAAM;WACd,MAAM;gBACD,MAAM;kBACJ,OAAO;;0BAtFuB,MAAM,UAAU,MAAM;0BAxBtB,MAAM,QAAQ,MAAM;2BAkJnB,MAAM;CAwFlD,CAAC;AAEF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"use-table-virtual.d.ts","sourceRoot":"","sources":["use-table-virtual.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAGrD,UAAU,oBAAoB;IAC5B,IAAI,EAAE,GAAG,EAAE,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC3C,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,iBAAiB,CAAC,GAAG,CAAC,EAAE,CAAC;CACnC;AACD,QAAA,MAAM,eAAe,UAAW,oBAAoB;;;;;;;oBAsLpC,MAAM;mBACP,MAAM;WACd,MAAM;gBACD,MAAM;kBACJ,OAAO;;0BAtFuB,MAAM,UAAU,MAAM;0BAxBtB,MAAM,QAAQ,MAAM;2BAkJnB,MAAM,aAAa,MAAM,IAAI;CA4FzE,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -235,7 +235,7 @@ var useTableVirtual = function useTableVirtual(props) {
235
235
  updateIndexAndTopFromTop(scrollTop);
236
236
  }
237
237
  };
238
- var scrollToIndex = usePersistFn(function (index) {
238
+ var scrollToIndex = usePersistFn(function (index, callback) {
239
239
  if (props.disabled) return;
240
240
  if (props.scrollRef.current) {
241
241
  context.shouldUpdateHeight = true;
@@ -246,6 +246,9 @@ var useTableVirtual = function useTableVirtual(props) {
246
246
  if (beforeHeight2 !== beforeHeight) {
247
247
  scrollToIndex(index);
248
248
  }
249
+ if (callback && typeof callback === 'function') {
250
+ callback();
251
+ }
249
252
  };
250
253
  props.scrollRef.current.scrollTop = beforeHeight;
251
254
  }
@@ -87,7 +87,7 @@ declare const useTransfer: <DataItem, Value extends KeygenResult[]>(props: BaseT
87
87
  filterTargetText: string;
88
88
  sourceSelectedKeys: KeygenResult[];
89
89
  targetSelectedKeys: KeygenResult[];
90
- onSelectChange: ((sourceKeys: KeygenResult[], targetKeys?: KeygenResult[] | undefined) => void) | ((selectKeys: KeygenResult[]) => void);
90
+ onSelectChange: (_value: KeygenResult[], source: KeygenResult[], target: KeygenResult[]) => void;
91
91
  onFilter: (text: string, listType: TransferListType) => void;
92
92
  };
93
93
  export default useTransfer;
@@ -1 +1 @@
1
- {"version":3,"file":"use-transfer.d.ts","sourceRoot":"","sources":["use-transfer.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE1E,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAqHa,MAAM,YAAY,gBAAgB;CAsB/D,CAAC;AAEF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"use-transfer.d.ts","sourceRoot":"","sources":["use-transfer.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE1E,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BA0BL,YAAY,EAAE,UACd,YAAY,EAAE,UACd,YAAY,EAAE;qBAqFI,MAAM,YAAY,gBAAgB;CAsB/D,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -37,12 +37,15 @@ var useTransfer = function useTransfer(props) {
37
37
  _useState4 = _slicedToArray(_useState3, 2),
38
38
  filterTargetText = _useState4[0],
39
39
  setFilterTargetText = _useState4[1];
40
+ var handleSelectedChange = function handleSelectedChange(_value, source, target) {
41
+ onSelectChangeProp === null || onSelectChangeProp === void 0 || onSelectChangeProp(source, target);
42
+ };
40
43
  var _useInputAble = useInputAble({
41
44
  value: selectValue,
42
45
  defaultValue: defaultSelectValue,
43
46
  control: selectControl,
44
47
  beforeChange: undefined,
45
- onChange: onSelectChangeProp
48
+ onChange: handleSelectedChange
46
49
  }),
47
50
  selectedKeys = _useInputAble.value,
48
51
  onSelectChange = _useInputAble.onChange;
@@ -99,24 +102,12 @@ var useTransfer = function useTransfer(props) {
99
102
  return keygen;
100
103
  };
101
104
  var handleSourceSelectedChange = function handleSourceSelectedChange(value) {
102
- if (selectControl) {
103
- // 受控情况下整合工作交给用户处理
104
- onSelectChange === null || onSelectChange === void 0 || onSelectChange(value, targetSelectedKeys);
105
- } else {
106
- // 非受控内部直接整合 source target
107
- var next = [].concat(_toConsumableArray(value), _toConsumableArray(targetSelectedKeys));
108
- onSelectChange === null || onSelectChange === void 0 || onSelectChange(next);
109
- }
105
+ var next = [].concat(_toConsumableArray(value), _toConsumableArray(targetSelectedKeys));
106
+ onSelectChange === null || onSelectChange === void 0 || onSelectChange(next, value, targetSelectedKeys);
110
107
  };
111
108
  var handleTargetSelectedChange = function handleTargetSelectedChange(value) {
112
- if (selectControl) {
113
- // 受控情况下整合工作交给用户处理
114
- onSelectChange === null || onSelectChange === void 0 || onSelectChange(sourceSelectedKeys, value);
115
- } else {
116
- // 非受控内部直接整合 source target
117
- var next = [].concat(_toConsumableArray(sourceSelectedKeys), _toConsumableArray(value));
118
- onSelectChange === null || onSelectChange === void 0 || onSelectChange(next);
119
- }
109
+ var next = [].concat(_toConsumableArray(sourceSelectedKeys), _toConsumableArray(value));
110
+ onSelectChange === null || onSelectChange === void 0 || onSelectChange(next, sourceSelectedKeys, value);
120
111
  };
121
112
  var sourceDatum = useListSelectMultiple({
122
113
  value: sourceSelectedKeys,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/hooks",
3
- "version": "3.4.0-beta.7",
3
+ "version": "3.4.0-beta.9",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",