@sheinx/hooks 3.4.0-beta.4 → 3.4.0-beta.6
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/common/use-position-style/index.d.ts +4 -1
- package/cjs/common/use-position-style/index.d.ts.map +1 -1
- package/cjs/common/use-position-style/index.js +98 -11
- package/cjs/components/use-datepicker/use-date.d.ts +2 -2
- package/cjs/components/use-datepicker/use-date.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-date.js +2 -2
- package/cjs/components/use-datepicker/use-date.type.d.ts +1 -1
- package/cjs/components/use-datepicker/use-date.type.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-datepicker-format.d.ts +1 -1
- package/cjs/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-datepicker-format.js +4 -2
- package/cjs/components/use-datepicker/use-datepicker-format.type.d.ts +1 -0
- package/cjs/components/use-datepicker/use-datepicker-format.type.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-month.d.ts +2 -2
- package/cjs/components/use-datepicker/use-month.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-month.js +2 -2
- package/cjs/components/use-datepicker/use-month.type.d.ts +1 -1
- package/cjs/components/use-datepicker/use-month.type.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-quarter.d.ts +2 -2
- package/cjs/components/use-datepicker/use-quarter.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-quarter.js +2 -2
- package/cjs/components/use-datepicker/use-year.d.ts +2 -2
- package/cjs/components/use-datepicker/use-year.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-year.js +2 -2
- package/cjs/components/use-datepicker/use-year.type.d.ts +1 -1
- package/cjs/components/use-datepicker/use-year.type.d.ts.map +1 -1
- package/cjs/components/use-datepicker/util.d.ts +1 -1
- package/cjs/components/use-datepicker/util.d.ts.map +1 -1
- package/cjs/components/use-datepicker/util.js +2 -1
- package/cjs/components/use-form/use-form-control/use-form-control.js +2 -2
- package/cjs/components/use-form/use-form.d.ts.map +1 -1
- package/cjs/components/use-form/use-form.js +40 -19
- package/cjs/components/use-form/use-form.type.d.ts +11 -6
- package/cjs/components/use-form/use-form.type.d.ts.map +1 -1
- package/cjs/components/use-input/use-input-format.d.ts +1 -1
- package/cjs/components/use-input/use-input-number.d.ts +1 -1
- package/cjs/components/use-popup/use-popup.d.ts +1 -0
- package/cjs/components/use-popup/use-popup.d.ts.map +1 -1
- package/cjs/components/use-popup/use-popup.js +7 -4
- package/cjs/components/use-table/use-table-virtual.d.ts.map +1 -1
- package/cjs/components/use-table/use-table-virtual.js +28 -3
- package/cjs/utils/position.d.ts +1 -1
- package/cjs/utils/position.d.ts.map +1 -1
- package/cjs/utils/position.js +20 -5
- package/esm/common/use-position-style/index.d.ts +4 -1
- package/esm/common/use-position-style/index.d.ts.map +1 -1
- package/esm/common/use-position-style/index.js +99 -12
- package/esm/components/use-datepicker/use-date.d.ts +2 -2
- package/esm/components/use-datepicker/use-date.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-date.js +2 -2
- package/esm/components/use-datepicker/use-date.type.d.ts +1 -1
- package/esm/components/use-datepicker/use-date.type.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-datepicker-format.d.ts +1 -1
- package/esm/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-datepicker-format.js +4 -2
- package/esm/components/use-datepicker/use-datepicker-format.type.d.ts +1 -0
- package/esm/components/use-datepicker/use-datepicker-format.type.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-month.d.ts +2 -2
- package/esm/components/use-datepicker/use-month.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-month.js +2 -2
- package/esm/components/use-datepicker/use-month.type.d.ts +1 -1
- package/esm/components/use-datepicker/use-month.type.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-quarter.d.ts +2 -2
- package/esm/components/use-datepicker/use-quarter.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-quarter.js +2 -2
- package/esm/components/use-datepicker/use-year.d.ts +2 -2
- package/esm/components/use-datepicker/use-year.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-year.js +2 -2
- package/esm/components/use-datepicker/use-year.type.d.ts +1 -1
- package/esm/components/use-datepicker/use-year.type.d.ts.map +1 -1
- package/esm/components/use-datepicker/util.d.ts +1 -1
- package/esm/components/use-datepicker/util.d.ts.map +1 -1
- package/esm/components/use-datepicker/util.js +2 -1
- package/esm/components/use-form/use-form-control/use-form-control.js +2 -2
- package/esm/components/use-form/use-form.d.ts.map +1 -1
- package/esm/components/use-form/use-form.js +40 -19
- package/esm/components/use-form/use-form.type.d.ts +11 -6
- package/esm/components/use-form/use-form.type.d.ts.map +1 -1
- package/esm/components/use-input/use-input-format.d.ts +1 -1
- package/esm/components/use-input/use-input-number.d.ts +1 -1
- package/esm/components/use-popup/use-popup.d.ts +1 -0
- package/esm/components/use-popup/use-popup.d.ts.map +1 -1
- package/esm/components/use-popup/use-popup.js +7 -4
- package/esm/components/use-table/use-table-virtual.d.ts.map +1 -1
- package/esm/components/use-table/use-table-virtual.js +28 -3
- package/esm/utils/position.d.ts +1 -1
- package/esm/utils/position.d.ts.map +1 -1
- package/esm/utils/position.js +20 -5
- package/package.json +1 -1
@@ -10,6 +10,7 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
10
10
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
11
11
|
import { usePersistFn } from "../../common/use-persist-fn";
|
12
12
|
import { useState, useRef, useEffect, useMemo } from 'react';
|
13
|
+
var MAX_ROW_SPAN = 200;
|
13
14
|
var useTableVirtual = function useTableVirtual(props) {
|
14
15
|
var _useState = useState(0),
|
15
16
|
_useState2 = _slicedToArray(_useState, 2),
|
@@ -92,7 +93,9 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
92
93
|
topTimer: null,
|
93
94
|
controlScrollRate: null,
|
94
95
|
heightCallback: null,
|
95
|
-
preIndex: null
|
96
|
+
preIndex: null,
|
97
|
+
rowSpanRows: 0,
|
98
|
+
autoAddRows: 0
|
96
99
|
}),
|
97
100
|
context = _useRef.current;
|
98
101
|
var getTranslate = usePersistFn(function (left, top) {
|
@@ -143,17 +146,20 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
143
146
|
var top = 0;
|
144
147
|
var maxIndex = Math.max(props.data.length - rowsInView, 0);
|
145
148
|
for (var i = 0; i <= maxIndex; i++) {
|
149
|
+
context.rowSpanRows = 0;
|
146
150
|
sum += context.cachedHeight[i] || props.rowHeight;
|
147
151
|
var rowSpanHeight = 0;
|
148
152
|
if (rowSpanInfos) {
|
153
|
+
var maxRowSpanLenth = Math.min(rowSpanInfos.length, props.rowsInView > MAX_ROW_SPAN ? props.rowsInView : props.rowsInView || MAX_ROW_SPAN);
|
149
154
|
var siblingsIndexs = [];
|
150
|
-
for (var k = 0; k <
|
155
|
+
for (var k = 0; k < maxRowSpanLenth; k++) {
|
151
156
|
if (rowSpanInfos[k] <= i && k > i) {
|
152
157
|
siblingsIndexs.push(k);
|
153
158
|
}
|
154
159
|
}
|
155
160
|
for (var j = 0; j < siblingsIndexs.length; j++) {
|
156
161
|
var index = siblingsIndexs[j];
|
162
|
+
context.rowSpanRows += 1;
|
157
163
|
rowSpanHeight += context.cachedHeight[index] || props.rowHeight;
|
158
164
|
}
|
159
165
|
}
|
@@ -244,6 +250,24 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
244
250
|
props.scrollRef.current.scrollTop = beforeHeight;
|
245
251
|
}
|
246
252
|
});
|
253
|
+
useEffect(function () {
|
254
|
+
var scrollRefHeight = props.scrollRef.current ? props.scrollRef.current.clientHeight : 0;
|
255
|
+
var tableRefHeight = props.innerRef.current ? props.innerRef.current.clientHeight : 0;
|
256
|
+
var remainHeight = scrollRefHeight - tableRefHeight;
|
257
|
+
if (remainHeight > 0) {
|
258
|
+
var addonHeight = 0;
|
259
|
+
var addonCount = 0;
|
260
|
+
for (var i = startIndex + rowsInView; i < props.data.length; i++) {
|
261
|
+
var height = context.cachedHeight[i] || props.rowHeight;
|
262
|
+
addonHeight += height;
|
263
|
+
addonCount += 1;
|
264
|
+
if (addonHeight >= remainHeight + context.cachedHeight[0]) break;
|
265
|
+
}
|
266
|
+
if (addonCount > 0) {
|
267
|
+
context.autoAddRows = addonCount;
|
268
|
+
}
|
269
|
+
}
|
270
|
+
}, []);
|
247
271
|
useEffect(function () {
|
248
272
|
// 记录preIndex
|
249
273
|
context.preIndex = startIndex;
|
@@ -278,7 +302,8 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
278
302
|
cb();
|
279
303
|
}
|
280
304
|
}, [scrollHeight]);
|
281
|
-
var
|
305
|
+
var finalRowsInView = rowsInView + context.rowSpanRows + context.autoAddRows;
|
306
|
+
var renderData = props.disabled ? props.data : _toConsumableArray(props.data).slice(startIndex, startIndex + finalRowsInView);
|
282
307
|
return {
|
283
308
|
scrollHeight: scrollHeight,
|
284
309
|
startIndex: startIndex,
|
package/esm/utils/position.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export declare const getPosition: (target: HTMLElement | null, priorityDirection: "vertical" | "horizontal" | "auto" | undefined, mode: 'popover' | 'menu' | 'list') => "bottom" | "left" | "right" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "left-top" | "left-bottom" | "right-top" | "right-bottom";
|
1
|
+
export declare const getPosition: (target: HTMLElement | null, priorityDirection: "vertical" | "horizontal" | "auto" | undefined, mode: 'popover' | 'menu' | 'list', popup?: HTMLElement) => "bottom" | "left" | "right" | "top" | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "left-top" | "left-bottom" | "right-top" | "right-bottom";
|
2
2
|
//# sourceMappingURL=position.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["position.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"position.d.ts","sourceRoot":"","sources":["position.ts"],"names":[],"mappings":"AAiGA,eAAO,MAAM,WAAW,WACd,WAAW,GAAG,IAAI,2EAEpB,SAAS,GAAG,MAAM,GAAG,MAAM,UACzB,WAAW,gKAKpB,CAAC"}
|
package/esm/utils/position.js
CHANGED
@@ -35,6 +35,7 @@ var getMenuPosition = function getMenuPosition(target) {
|
|
35
35
|
};
|
36
36
|
var getPopoverPosition = function getPopoverPosition(target) {
|
37
37
|
var priorityDirection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'vertical';
|
38
|
+
var popup = arguments.length > 2 ? arguments[2] : undefined;
|
38
39
|
var position = 'bottom-left';
|
39
40
|
if (!target) return position;
|
40
41
|
var rect = target.getBoundingClientRect();
|
@@ -56,11 +57,24 @@ var getPopoverPosition = function getPopoverPosition(target) {
|
|
56
57
|
position += '-top';
|
57
58
|
}
|
58
59
|
} else {
|
60
|
+
var popupRect = popup === null || popup === void 0 ? void 0 : popup.getBoundingClientRect();
|
59
61
|
if (verticalPoint > windowHeight / 2) position = 'top';else position = 'bottom';
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
|
63
|
+
// 如果渲染了弹出内容,则根据弹出内容宽度计算是否自动调整位置
|
64
|
+
if (popupRect) {
|
65
|
+
if ((popupRect === null || popupRect === void 0 ? void 0 : popupRect.width) / 2 > rect.left) {
|
66
|
+
position += '-left';
|
67
|
+
}
|
68
|
+
if ((popupRect === null || popupRect === void 0 ? void 0 : popupRect.width) / 2 > windowWidth - rect.right) {
|
69
|
+
position += '-right';
|
70
|
+
}
|
71
|
+
} else {
|
72
|
+
// 兜底计算
|
73
|
+
if (horizontalPoint > windowWidth * 0.6) {
|
74
|
+
position += '-right';
|
75
|
+
} else if (horizontalPoint < windowWidth * 0.4) {
|
76
|
+
position += '-left';
|
77
|
+
}
|
64
78
|
}
|
65
79
|
}
|
66
80
|
return position;
|
@@ -68,7 +82,8 @@ var getPopoverPosition = function getPopoverPosition(target) {
|
|
68
82
|
export var getPosition = function getPosition(target) {
|
69
83
|
var priorityDirection = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'vertical';
|
70
84
|
var mode = arguments.length > 2 ? arguments[2] : undefined;
|
71
|
-
|
85
|
+
var popup = arguments.length > 3 ? arguments[3] : undefined;
|
86
|
+
if (mode === 'popover') return getPopoverPosition(target, priorityDirection, popup);
|
72
87
|
if (mode === 'menu') return getMenuPosition(target, priorityDirection);
|
73
88
|
return 'bottom-left';
|
74
89
|
};
|