@sheinx/hooks 3.2.3 → 3.2.5-beta.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.
- package/cjs/components/use-button/use-button.d.ts +1 -1
- package/cjs/components/use-datepicker/use-datepicker-format.d.ts +1 -1
- package/cjs/components/use-form/use-form.d.ts.map +1 -1
- package/cjs/components/use-form/use-form.js +4 -3
- package/cjs/components/use-image/use-image.d.ts +1 -1
- package/cjs/components/use-table/use-table-virtual.d.ts.map +1 -1
- package/cjs/components/use-table/use-table-virtual.js +14 -3
- package/esm/components/use-button/use-button.d.ts +1 -1
- package/esm/components/use-datepicker/use-datepicker-format.d.ts +1 -1
- package/esm/components/use-form/use-form.d.ts.map +1 -1
- package/esm/components/use-form/use-form.js +4 -3
- package/esm/components/use-image/use-image.d.ts +1 -1
- package/esm/components/use-table/use-table-virtual.d.ts.map +1 -1
- package/esm/components/use-table/use-table-virtual.js +14 -3
- package/package.json +1 -1
@@ -28,7 +28,7 @@ declare const useButton: (props?: BaseButtonProps) => {
|
|
28
28
|
buttonRef?: React.Ref<HTMLButtonElement> | undefined;
|
29
29
|
} & TOther_1 & {
|
30
30
|
disabled: boolean | undefined;
|
31
|
-
htmlType: "button" | "
|
31
|
+
htmlType: "button" | "submit" | "reset" | undefined;
|
32
32
|
onClick: (event: React.MouseEvent<HTMLButtonElement> | React.MouseEvent<HTMLAnchorElement>) => void;
|
33
33
|
};
|
34
34
|
getSpaceChildren: (children: React.ReactNode, space?: boolean, className?: string) => React.ReactNode;
|
@@ -4,7 +4,7 @@ declare const useDatePickerFormat: <Value extends DatePickerValueType>(props: Us
|
|
4
4
|
resultArr: (string | undefined)[];
|
5
5
|
targetResultArr: (string | undefined)[];
|
6
6
|
dateArr: (Date | undefined)[];
|
7
|
-
disabledStatus: "
|
7
|
+
disabledStatus: "left" | "right" | "all" | undefined;
|
8
8
|
currentArr: Date[];
|
9
9
|
mode: DatePickerModeType[];
|
10
10
|
isEmpty: boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";
|
1
|
+
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AAyBA,OAAO,EAAe,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAmK8B;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;aAAE;8BARzB,MAAM;oCAuDD,OAAO;;6BAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;qCAiI5D,MAAM;gCAzCE,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;;;;;;oBA1CpB;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE;0BARzB,MAAM;gCAuDD,OAAO;;yBAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;iCAiI5D,MAAM;4BAzCE,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;;CA4P9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -11,6 +11,7 @@ var _useLatestObj = _interopRequireDefault(require("../../common/use-latest-obj"
|
|
11
11
|
var _usePersistFn = _interopRequireDefault(require("../../common/use-persist-fn"));
|
12
12
|
var _attribute = require("../../utils/attribute");
|
13
13
|
var _flat = require("../../utils/flat");
|
14
|
+
var _useDefaultValue = require("../../common/use-default-value");
|
14
15
|
var _immer = require("../../utils/immer");
|
15
16
|
var _utils = require("../../utils");
|
16
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
@@ -49,6 +50,7 @@ var useForm = function useForm(props) {
|
|
49
50
|
removeUndefined: removeUndefined,
|
50
51
|
forceSet: true
|
51
52
|
};
|
53
|
+
var preValue = (0, _useDefaultValue.usePrevious)(props.value);
|
52
54
|
var formRef = React.useRef();
|
53
55
|
var _React$useRef = React.useRef({
|
54
56
|
defaultValues: {},
|
@@ -419,8 +421,8 @@ var useForm = function useForm(props) {
|
|
419
421
|
var updateValue = function updateValue() {
|
420
422
|
if (props.value !== context.lastValue && props.value !== context.value) {
|
421
423
|
context.value = (0, _utils.deepClone)(props.value) || emptyObj;
|
422
|
-
context.lastValue = props.value;
|
423
424
|
}
|
425
|
+
context.lastValue = props.value;
|
424
426
|
};
|
425
427
|
updateValue();
|
426
428
|
React.useEffect(function () {
|
@@ -443,14 +445,13 @@ var useForm = function useForm(props) {
|
|
443
445
|
if (props.value === context.value) return;
|
444
446
|
if (initValidate && !context.resetTime) {
|
445
447
|
var keys = Object.keys(context.validateMap).filter(function (key) {
|
446
|
-
var oldValue = (0, _utils.deepGet)(
|
448
|
+
var oldValue = (0, _utils.deepGet)(preValue || emptyObj, key);
|
447
449
|
var newValue = (0, _utils.deepGet)(context.value || emptyObj, key);
|
448
450
|
return !(0, _utils.shallowEqual)(oldValue, newValue);
|
449
451
|
});
|
450
452
|
validateFields(keys).catch(function () {});
|
451
453
|
}
|
452
454
|
update();
|
453
|
-
context.lastValue = props.value;
|
454
455
|
context.resetTime = 0;
|
455
456
|
}, [props.value]);
|
456
457
|
React.useEffect(function () {
|
@@ -10,7 +10,7 @@ declare const useImage: (props?: BaseImageProps) => {
|
|
10
10
|
getRootProps: <TOther extends ObjectType = ObjectType>(externalProps?: TOther) => {
|
11
11
|
[x: string]: (event: any) => void;
|
12
12
|
} & TOther & {
|
13
|
-
ref: React.RefObject<
|
13
|
+
ref: React.RefObject<HTMLAnchorElement | HTMLDivElement>;
|
14
14
|
onClick: (event: React.MouseEvent<HTMLImageElement | HTMLDivElement>) => void;
|
15
15
|
};
|
16
16
|
getImageProps: <TOther_1 extends ObjectType = ObjectType>(externalProps?: TOther_1) => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-table-virtual.d.ts","sourceRoot":"","sources":["use-table-virtual.tsx"],"names":[],"mappings":";
|
1
|
+
{"version":3,"file":"use-table-virtual.d.ts","sourceRoot":"","sources":["use-table-virtual.tsx"],"names":[],"mappings":";AAGA,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;CACjB;AACD,QAAA,MAAM,eAAe,UAAW,oBAAoB;;;;;;;oBA+GpC,MAAM;mBACP,MAAM;WACd,MAAM;gBACD,MAAM;kBACJ,OAAO;;0BAtEuB,MAAM,UAAU,MAAM;0BAxBtB,MAAM,QAAQ,MAAM;2BAkInB,MAAM;CAmElD,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.default = void 0;
|
7
|
-
var _usePrevious = require("../.../../../common/use-previous");
|
8
7
|
var _usePersistFn = require("../../common/use-persist-fn");
|
9
8
|
var _react = require("react");
|
10
9
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
@@ -34,7 +33,6 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
34
33
|
_useState8 = _slicedToArray(_useState7, 2),
|
35
34
|
startIndex = _useState8[0],
|
36
35
|
setStartIndex = _useState8[1];
|
37
|
-
var preIndex = (0, _usePrevious.usePrevious)(startIndex);
|
38
36
|
var _useState9 = (0, _react.useState)(0),
|
39
37
|
_useState10 = _slicedToArray(_useState9, 2),
|
40
38
|
offsetY = _useState10[0],
|
@@ -47,7 +45,8 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
47
45
|
rateTimer: null,
|
48
46
|
topTimer: null,
|
49
47
|
controlScrollRate: null,
|
50
|
-
heightCallback: null
|
48
|
+
heightCallback: null,
|
49
|
+
preIndex: null
|
51
50
|
}),
|
52
51
|
context = _useRef.current;
|
53
52
|
var getTranslate = (0, _usePersistFn.usePersistFn)(function (left, top) {
|
@@ -80,6 +79,8 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
80
79
|
if (context.shouldUpdateHeight) {
|
81
80
|
setHeight(getContentHeight(props.data.length - 1));
|
82
81
|
}
|
82
|
+
var preIndex = context.preIndex;
|
83
|
+
// 解决: 从下往上滚 由于高度变化会导致滚动条跳动
|
83
84
|
if (preIndex && preIndex > startIndex && startIndex === index) {
|
84
85
|
// 发生在顶部
|
85
86
|
if (context.heightCallback) return;
|
@@ -184,6 +185,16 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
184
185
|
props.scrollRef.current.scrollTop = beforeHeight;
|
185
186
|
}
|
186
187
|
});
|
188
|
+
(0, _react.useEffect)(function () {
|
189
|
+
// 记录preIndex
|
190
|
+
context.preIndex = startIndex;
|
191
|
+
}, [startIndex]);
|
192
|
+
(0, _react.useEffect)(function () {
|
193
|
+
// 数据变化的时候清空掉 preIndex, 如果之前有缓存的index, setRowHeight 会有问题
|
194
|
+
return function () {
|
195
|
+
context.preIndex = null;
|
196
|
+
};
|
197
|
+
}, [props.data]);
|
187
198
|
(0, _react.useEffect)(function () {
|
188
199
|
if (props.disabled) return;
|
189
200
|
if (offsetY) {
|
@@ -28,7 +28,7 @@ declare const useButton: (props?: BaseButtonProps) => {
|
|
28
28
|
buttonRef?: React.Ref<HTMLButtonElement> | undefined;
|
29
29
|
} & TOther_1 & {
|
30
30
|
disabled: boolean | undefined;
|
31
|
-
htmlType: "button" | "
|
31
|
+
htmlType: "button" | "submit" | "reset" | undefined;
|
32
32
|
onClick: (event: React.MouseEvent<HTMLButtonElement> | React.MouseEvent<HTMLAnchorElement>) => void;
|
33
33
|
};
|
34
34
|
getSpaceChildren: (children: React.ReactNode, space?: boolean, className?: string) => React.ReactNode;
|
@@ -4,7 +4,7 @@ declare const useDatePickerFormat: <Value extends DatePickerValueType>(props: Us
|
|
4
4
|
resultArr: (string | undefined)[];
|
5
5
|
targetResultArr: (string | undefined)[];
|
6
6
|
dateArr: (Date | undefined)[];
|
7
|
-
disabledStatus: "
|
7
|
+
disabledStatus: "left" | "right" | "all" | undefined;
|
8
8
|
currentArr: Date[];
|
9
9
|
mode: DatePickerModeType[];
|
10
10
|
isEmpty: boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";
|
1
|
+
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AAyBA,OAAO,EAAe,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAmK8B;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;aAAE;8BARzB,MAAM;oCAuDD,OAAO;;6BAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;qCAiI5D,MAAM;gCAzCE,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;;;;;;oBA1CpB;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE;0BARzB,MAAM;gCAuDD,OAAO;;yBAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;iCAiI5D,MAAM;4BAzCE,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;;CA4P9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -13,6 +13,7 @@ import useLatestObj from "../../common/use-latest-obj";
|
|
13
13
|
import usePersistFn from "../../common/use-persist-fn";
|
14
14
|
import { getDataAttributeName } from "../../utils/attribute";
|
15
15
|
import { insertValue, spliceValue } from "../../utils/flat";
|
16
|
+
import { usePrevious } from "../../common/use-default-value";
|
16
17
|
var globalKey = '__global__&&@@';
|
17
18
|
import { current, produce } from "../../utils/immer";
|
18
19
|
import { deepGet, deepRemove, deepSet, docScroll, extractEventHandlers, isArray, isObject, shallowEqual, wrapFormError, deepClone } from "../../utils";
|
@@ -40,6 +41,7 @@ var useForm = function useForm(props) {
|
|
40
41
|
removeUndefined: removeUndefined,
|
41
42
|
forceSet: true
|
42
43
|
};
|
44
|
+
var preValue = usePrevious(props.value);
|
43
45
|
var formRef = React.useRef();
|
44
46
|
var _React$useRef = React.useRef({
|
45
47
|
defaultValues: {},
|
@@ -410,8 +412,8 @@ var useForm = function useForm(props) {
|
|
410
412
|
var updateValue = function updateValue() {
|
411
413
|
if (props.value !== context.lastValue && props.value !== context.value) {
|
412
414
|
context.value = deepClone(props.value) || emptyObj;
|
413
|
-
context.lastValue = props.value;
|
414
415
|
}
|
416
|
+
context.lastValue = props.value;
|
415
417
|
};
|
416
418
|
updateValue();
|
417
419
|
React.useEffect(function () {
|
@@ -434,14 +436,13 @@ var useForm = function useForm(props) {
|
|
434
436
|
if (props.value === context.value) return;
|
435
437
|
if (initValidate && !context.resetTime) {
|
436
438
|
var keys = Object.keys(context.validateMap).filter(function (key) {
|
437
|
-
var oldValue = deepGet(
|
439
|
+
var oldValue = deepGet(preValue || emptyObj, key);
|
438
440
|
var newValue = deepGet(context.value || emptyObj, key);
|
439
441
|
return !shallowEqual(oldValue, newValue);
|
440
442
|
});
|
441
443
|
validateFields(keys).catch(function () {});
|
442
444
|
}
|
443
445
|
update();
|
444
|
-
context.lastValue = props.value;
|
445
446
|
context.resetTime = 0;
|
446
447
|
}, [props.value]);
|
447
448
|
React.useEffect(function () {
|
@@ -10,7 +10,7 @@ declare const useImage: (props?: BaseImageProps) => {
|
|
10
10
|
getRootProps: <TOther extends ObjectType = ObjectType>(externalProps?: TOther) => {
|
11
11
|
[x: string]: (event: any) => void;
|
12
12
|
} & TOther & {
|
13
|
-
ref: React.RefObject<
|
13
|
+
ref: React.RefObject<HTMLAnchorElement | HTMLDivElement>;
|
14
14
|
onClick: (event: React.MouseEvent<HTMLImageElement | HTMLDivElement>) => void;
|
15
15
|
};
|
16
16
|
getImageProps: <TOther_1 extends ObjectType = ObjectType>(externalProps?: TOther_1) => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-table-virtual.d.ts","sourceRoot":"","sources":["use-table-virtual.tsx"],"names":[],"mappings":";
|
1
|
+
{"version":3,"file":"use-table-virtual.d.ts","sourceRoot":"","sources":["use-table-virtual.tsx"],"names":[],"mappings":";AAGA,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;CACjB;AACD,QAAA,MAAM,eAAe,UAAW,oBAAoB;;;;;;;oBA+GpC,MAAM;mBACP,MAAM;WACd,MAAM;gBACD,MAAM;kBACJ,OAAO;;0BAtEuB,MAAM,UAAU,MAAM;0BAxBtB,MAAM,QAAQ,MAAM;2BAkInB,MAAM;CAmElD,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
@@ -8,7 +8,6 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
8
8
|
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; }
|
9
9
|
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; } }
|
10
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
11
|
-
import { usePrevious } from "../.../../../common/use-previous";
|
12
11
|
import { usePersistFn } from "../../common/use-persist-fn";
|
13
12
|
import { useState, useRef, useEffect } from 'react';
|
14
13
|
var useTableVirtual = function useTableVirtual(props) {
|
@@ -28,7 +27,6 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
28
27
|
_useState8 = _slicedToArray(_useState7, 2),
|
29
28
|
startIndex = _useState8[0],
|
30
29
|
setStartIndex = _useState8[1];
|
31
|
-
var preIndex = usePrevious(startIndex);
|
32
30
|
var _useState9 = useState(0),
|
33
31
|
_useState10 = _slicedToArray(_useState9, 2),
|
34
32
|
offsetY = _useState10[0],
|
@@ -41,7 +39,8 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
41
39
|
rateTimer: null,
|
42
40
|
topTimer: null,
|
43
41
|
controlScrollRate: null,
|
44
|
-
heightCallback: null
|
42
|
+
heightCallback: null,
|
43
|
+
preIndex: null
|
45
44
|
}),
|
46
45
|
context = _useRef.current;
|
47
46
|
var getTranslate = usePersistFn(function (left, top) {
|
@@ -74,6 +73,8 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
74
73
|
if (context.shouldUpdateHeight) {
|
75
74
|
setHeight(getContentHeight(props.data.length - 1));
|
76
75
|
}
|
76
|
+
var preIndex = context.preIndex;
|
77
|
+
// 解决: 从下往上滚 由于高度变化会导致滚动条跳动
|
77
78
|
if (preIndex && preIndex > startIndex && startIndex === index) {
|
78
79
|
// 发生在顶部
|
79
80
|
if (context.heightCallback) return;
|
@@ -178,6 +179,16 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
178
179
|
props.scrollRef.current.scrollTop = beforeHeight;
|
179
180
|
}
|
180
181
|
});
|
182
|
+
useEffect(function () {
|
183
|
+
// 记录preIndex
|
184
|
+
context.preIndex = startIndex;
|
185
|
+
}, [startIndex]);
|
186
|
+
useEffect(function () {
|
187
|
+
// 数据变化的时候清空掉 preIndex, 如果之前有缓存的index, setRowHeight 会有问题
|
188
|
+
return function () {
|
189
|
+
context.preIndex = null;
|
190
|
+
};
|
191
|
+
}, [props.data]);
|
181
192
|
useEffect(function () {
|
182
193
|
if (props.disabled) return;
|
183
194
|
if (offsetY) {
|