@sheinx/hooks 3.5.4-beta.2 → 3.5.4-beta.4
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-form/use-form-context.d.ts +1 -1
- package/cjs/components/use-form/use-form-context.js +2 -2
- package/cjs/components/use-table/use-table-virtual.d.ts.map +1 -1
- package/cjs/components/use-table/use-table-virtual.js +20 -16
- package/esm/components/use-form/use-form-context.d.ts +1 -1
- package/esm/components/use-form/use-form-context.js +1 -1
- package/esm/components/use-table/use-table-virtual.d.ts.map +1 -1
- package/esm/components/use-table/use-table-virtual.js +20 -16
- package/package.json +1 -1
|
@@ -2,5 +2,5 @@ import React from 'react';
|
|
|
2
2
|
import { FormRef } from './use-form-context.type';
|
|
3
3
|
export declare const FormContext: React.Context<any>;
|
|
4
4
|
export declare function useFormRef<V>(): [FormRef<V>, ((formRef: FormRef<V>) => void)];
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function useFormInstance<V>(): FormRef<V>;
|
|
6
6
|
//# sourceMappingURL=use-form-context.d.ts.map
|
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.FormContext = void 0;
|
|
7
|
+
exports.useFormInstance = useFormInstance;
|
|
7
8
|
exports.useFormRef = useFormRef;
|
|
8
|
-
exports.useFromInstance = useFromInstance;
|
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
11
|
var FormContext = exports.FormContext = /*#__PURE__*/_react.default.createContext({});
|
|
@@ -16,7 +16,7 @@ function useFormRef() {
|
|
|
16
16
|
};
|
|
17
17
|
return [ref.current, setFormRef];
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function useFormInstance() {
|
|
20
20
|
var formCtx = _react.default.useContext(FormContext);
|
|
21
21
|
return formCtx;
|
|
22
22
|
}
|
|
@@ -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;
|
|
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;AAWrD,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;IAClC,QAAQ,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;CAC3C;AACD,QAAA,MAAM,eAAe,UAAW,oBAAoB;;;;;;;oBA8LpC,MAAM;mBACP,MAAM;WACd,MAAM;gBACD,MAAM;kBACJ,OAAO;;0BA1FuB,MAAM,UAAU,MAAM;0BAxBtB,MAAM,QAAQ,MAAM;2BAsJnB,MAAM,aAAa,MAAM,IAAI;qCAoBnB,MAAM;mCAWR,MAAM,GAAG,MAAM;CA6FnE,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -34,7 +34,6 @@ function getMaxRowSpanLength(input) {
|
|
|
34
34
|
}
|
|
35
35
|
return Math.max.apply(Math, _toConsumableArray(Array.from(map.values())));
|
|
36
36
|
}
|
|
37
|
-
var MAX_ROW_SPAN = 200;
|
|
38
37
|
var useTableVirtual = function useTableVirtual(props) {
|
|
39
38
|
var _useState = (0, _react.useState)(0),
|
|
40
39
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -67,7 +66,7 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
|
67
66
|
var totalLength = props.data.length;
|
|
68
67
|
var _loop = function _loop(i) {
|
|
69
68
|
var startIndex = i;
|
|
70
|
-
var
|
|
69
|
+
var _rowSpanInfo = rowSpanColumns.map(function (col) {
|
|
71
70
|
var rowSpan = col.rowSpan;
|
|
72
71
|
function getRowSpanCount(index, _count) {
|
|
73
72
|
var count = _count;
|
|
@@ -83,7 +82,7 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
|
83
82
|
var count = getRowSpanCount(i, 1);
|
|
84
83
|
return [startIndex, startIndex + count - 1];
|
|
85
84
|
});
|
|
86
|
-
_rowSpanInfos.push(
|
|
85
|
+
_rowSpanInfos.push(_rowSpanInfo);
|
|
87
86
|
};
|
|
88
87
|
for (var i = 0; i < totalLength; i++) {
|
|
89
88
|
_loop(i);
|
|
@@ -109,10 +108,12 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
|
109
108
|
});
|
|
110
109
|
return Math.min.apply(Math, _toConsumableArray(startIndexs));
|
|
111
110
|
});
|
|
112
|
-
|
|
113
|
-
|
|
111
|
+
|
|
112
|
+
// 根据data计算出实际需要的最大合并行数
|
|
113
|
+
var _maxRowSpan = getMaxRowSpanLength(resultArr);
|
|
114
|
+
return _maxRowSpan > 1 ? {
|
|
114
115
|
rowSpanIndexArray: resultArr,
|
|
115
|
-
maxRowSpan:
|
|
116
|
+
maxRowSpan: _maxRowSpan
|
|
116
117
|
} : null;
|
|
117
118
|
}, [props.data, props.columns]);
|
|
118
119
|
var _useRef = (0, _react.useRef)({
|
|
@@ -169,32 +170,31 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
|
169
170
|
}
|
|
170
171
|
});
|
|
171
172
|
var updateIndexAndTopFromTop = function updateIndexAndTopFromTop(scrollTop) {
|
|
173
|
+
var _props$scrollRef$curr;
|
|
172
174
|
if (props.disabled) return;
|
|
173
175
|
var sum = 0;
|
|
174
176
|
var currentIndex = 0;
|
|
175
177
|
var top = 0;
|
|
176
178
|
var maxIndex = Math.max(props.data.length - rowsInView, 0);
|
|
177
|
-
var
|
|
178
|
-
if (rowSpanInfo) {
|
|
179
|
-
maxRowSpanLenth = Math.min(rowSpanInfo.rowSpanIndexArray.length,
|
|
180
|
-
// 根据data计算出实际需要的最大合并行数(rowSpanInfo.maxRowSpan),当rowSpanInfo.maxRowSpan大于外部传的rowsInView时,使用rowSpanInfo.maxRowSpan
|
|
181
|
-
Math.max(rowSpanInfo.maxRowSpan, props.rowsInView > MAX_ROW_SPAN ? props.rowsInView : props.rowsInView || MAX_ROW_SPAN));
|
|
182
|
-
}
|
|
179
|
+
var scrollContainerHeight = Math.max(((_props$scrollRef$curr = props.scrollRef.current) === null || _props$scrollRef$curr === void 0 ? void 0 : _props$scrollRef$curr.clientHeight) || 0, 200);
|
|
183
180
|
for (var i = 0; i <= maxIndex; i++) {
|
|
184
181
|
context.rowSpanRows = 0;
|
|
185
182
|
sum += context.cachedHeight[i] || props.rowHeight;
|
|
186
183
|
var rowSpanHeight = 0;
|
|
187
184
|
if (rowSpanInfo) {
|
|
188
185
|
var siblingsIndexs = [];
|
|
189
|
-
for (var k = i; k <
|
|
186
|
+
for (var k = i; k < rowSpanInfo.maxRowSpan + i; k++) {
|
|
190
187
|
if (rowSpanInfo.rowSpanIndexArray[k] <= i && k > i) {
|
|
191
188
|
siblingsIndexs.push(k);
|
|
192
189
|
}
|
|
193
190
|
}
|
|
194
191
|
for (var j = 0; j < siblingsIndexs.length; j++) {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
192
|
+
// 在当前滚动容器滚动一屏上方销毁tr,不在可见区域内销毁重建,避免引起可见的单元格(合并的)内容闪烁
|
|
193
|
+
if (rowSpanHeight < scrollContainerHeight) {
|
|
194
|
+
var index = siblingsIndexs[j];
|
|
195
|
+
context.rowSpanRows += 1;
|
|
196
|
+
rowSpanHeight += context.cachedHeight[index] || props.rowHeight;
|
|
197
|
+
}
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
if (scrollTop < sum + rowSpanHeight || i === maxIndex) {
|
|
@@ -368,6 +368,10 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
|
368
368
|
}, [scrollHeight]);
|
|
369
369
|
var finalRowsInView = rowsInView + context.rowSpanRows + context.autoAddRows;
|
|
370
370
|
var renderData = props.disabled ? props.data : _toConsumableArray(props.data).slice(startIndex, startIndex + finalRowsInView);
|
|
371
|
+
console.log('======================');
|
|
372
|
+
console.log('startIndex: >>', startIndex);
|
|
373
|
+
console.log('finalRowsInView: >>', finalRowsInView);
|
|
374
|
+
console.log('======================');
|
|
371
375
|
return {
|
|
372
376
|
scrollHeight: scrollHeight,
|
|
373
377
|
startIndex: startIndex,
|
|
@@ -2,5 +2,5 @@ import React from 'react';
|
|
|
2
2
|
import { FormRef } from './use-form-context.type';
|
|
3
3
|
export declare const FormContext: React.Context<any>;
|
|
4
4
|
export declare function useFormRef<V>(): [FormRef<V>, ((formRef: FormRef<V>) => void)];
|
|
5
|
-
export declare function
|
|
5
|
+
export declare function useFormInstance<V>(): FormRef<V>;
|
|
6
6
|
//# sourceMappingURL=use-form-context.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;
|
|
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;AAWrD,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;IAClC,QAAQ,EAAE,CAAC,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,EAAE,CAAC;CAC3C;AACD,QAAA,MAAM,eAAe,UAAW,oBAAoB;;;;;;;oBA8LpC,MAAM;mBACP,MAAM;WACd,MAAM;gBACD,MAAM;kBACJ,OAAO;;0BA1FuB,MAAM,UAAU,MAAM;0BAxBtB,MAAM,QAAQ,MAAM;2BAsJnB,MAAM,aAAa,MAAM,IAAI;qCAoBnB,MAAM;mCAWR,MAAM,GAAG,MAAM;CA6FnE,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -28,7 +28,6 @@ function getMaxRowSpanLength(input) {
|
|
|
28
28
|
}
|
|
29
29
|
return Math.max.apply(Math, _toConsumableArray(Array.from(map.values())));
|
|
30
30
|
}
|
|
31
|
-
var MAX_ROW_SPAN = 200;
|
|
32
31
|
var useTableVirtual = function useTableVirtual(props) {
|
|
33
32
|
var _useState = useState(0),
|
|
34
33
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -61,7 +60,7 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
|
61
60
|
var totalLength = props.data.length;
|
|
62
61
|
var _loop = function _loop(i) {
|
|
63
62
|
var startIndex = i;
|
|
64
|
-
var
|
|
63
|
+
var _rowSpanInfo = rowSpanColumns.map(function (col) {
|
|
65
64
|
var rowSpan = col.rowSpan;
|
|
66
65
|
function getRowSpanCount(index, _count) {
|
|
67
66
|
var count = _count;
|
|
@@ -77,7 +76,7 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
|
77
76
|
var count = getRowSpanCount(i, 1);
|
|
78
77
|
return [startIndex, startIndex + count - 1];
|
|
79
78
|
});
|
|
80
|
-
_rowSpanInfos.push(
|
|
79
|
+
_rowSpanInfos.push(_rowSpanInfo);
|
|
81
80
|
};
|
|
82
81
|
for (var i = 0; i < totalLength; i++) {
|
|
83
82
|
_loop(i);
|
|
@@ -103,10 +102,12 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
|
103
102
|
});
|
|
104
103
|
return Math.min.apply(Math, _toConsumableArray(startIndexs));
|
|
105
104
|
});
|
|
106
|
-
|
|
107
|
-
|
|
105
|
+
|
|
106
|
+
// 根据data计算出实际需要的最大合并行数
|
|
107
|
+
var _maxRowSpan = getMaxRowSpanLength(resultArr);
|
|
108
|
+
return _maxRowSpan > 1 ? {
|
|
108
109
|
rowSpanIndexArray: resultArr,
|
|
109
|
-
maxRowSpan:
|
|
110
|
+
maxRowSpan: _maxRowSpan
|
|
110
111
|
} : null;
|
|
111
112
|
}, [props.data, props.columns]);
|
|
112
113
|
var _useRef = useRef({
|
|
@@ -163,32 +164,31 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
|
163
164
|
}
|
|
164
165
|
});
|
|
165
166
|
var updateIndexAndTopFromTop = function updateIndexAndTopFromTop(scrollTop) {
|
|
167
|
+
var _props$scrollRef$curr;
|
|
166
168
|
if (props.disabled) return;
|
|
167
169
|
var sum = 0;
|
|
168
170
|
var currentIndex = 0;
|
|
169
171
|
var top = 0;
|
|
170
172
|
var maxIndex = Math.max(props.data.length - rowsInView, 0);
|
|
171
|
-
var
|
|
172
|
-
if (rowSpanInfo) {
|
|
173
|
-
maxRowSpanLenth = Math.min(rowSpanInfo.rowSpanIndexArray.length,
|
|
174
|
-
// 根据data计算出实际需要的最大合并行数(rowSpanInfo.maxRowSpan),当rowSpanInfo.maxRowSpan大于外部传的rowsInView时,使用rowSpanInfo.maxRowSpan
|
|
175
|
-
Math.max(rowSpanInfo.maxRowSpan, props.rowsInView > MAX_ROW_SPAN ? props.rowsInView : props.rowsInView || MAX_ROW_SPAN));
|
|
176
|
-
}
|
|
173
|
+
var scrollContainerHeight = Math.max(((_props$scrollRef$curr = props.scrollRef.current) === null || _props$scrollRef$curr === void 0 ? void 0 : _props$scrollRef$curr.clientHeight) || 0, 200);
|
|
177
174
|
for (var i = 0; i <= maxIndex; i++) {
|
|
178
175
|
context.rowSpanRows = 0;
|
|
179
176
|
sum += context.cachedHeight[i] || props.rowHeight;
|
|
180
177
|
var rowSpanHeight = 0;
|
|
181
178
|
if (rowSpanInfo) {
|
|
182
179
|
var siblingsIndexs = [];
|
|
183
|
-
for (var k = i; k <
|
|
180
|
+
for (var k = i; k < rowSpanInfo.maxRowSpan + i; k++) {
|
|
184
181
|
if (rowSpanInfo.rowSpanIndexArray[k] <= i && k > i) {
|
|
185
182
|
siblingsIndexs.push(k);
|
|
186
183
|
}
|
|
187
184
|
}
|
|
188
185
|
for (var j = 0; j < siblingsIndexs.length; j++) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
186
|
+
// 在当前滚动容器滚动一屏上方销毁tr,不在可见区域内销毁重建,避免引起可见的单元格(合并的)内容闪烁
|
|
187
|
+
if (rowSpanHeight < scrollContainerHeight) {
|
|
188
|
+
var index = siblingsIndexs[j];
|
|
189
|
+
context.rowSpanRows += 1;
|
|
190
|
+
rowSpanHeight += context.cachedHeight[index] || props.rowHeight;
|
|
191
|
+
}
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
if (scrollTop < sum + rowSpanHeight || i === maxIndex) {
|
|
@@ -362,6 +362,10 @@ var useTableVirtual = function useTableVirtual(props) {
|
|
|
362
362
|
}, [scrollHeight]);
|
|
363
363
|
var finalRowsInView = rowsInView + context.rowSpanRows + context.autoAddRows;
|
|
364
364
|
var renderData = props.disabled ? props.data : _toConsumableArray(props.data).slice(startIndex, startIndex + finalRowsInView);
|
|
365
|
+
console.log('======================');
|
|
366
|
+
console.log('startIndex: >>', startIndex);
|
|
367
|
+
console.log('finalRowsInView: >>', finalRowsInView);
|
|
368
|
+
console.log('======================');
|
|
365
369
|
return {
|
|
366
370
|
scrollHeight: scrollHeight,
|
|
367
371
|
startIndex: startIndex,
|