@hi-ui/table 4.0.13 → 4.1.0-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/CHANGELOG.md +23 -0
- package/lib/cjs/BaseTable.js +7 -4
- package/lib/cjs/Table.js +19 -6
- package/lib/cjs/TableBody.js +83 -2
- package/lib/cjs/TableCell.js +42 -1
- package/lib/cjs/TableRow.js +42 -2
- package/lib/cjs/_virtual/index.js +18 -0
- package/lib/cjs/_virtual/index2.js +18 -0
- package/lib/cjs/_virtual/react-is.development.js +16 -0
- package/lib/cjs/_virtual/react-is.production.min.js +16 -0
- package/lib/cjs/hooks/use-check.js +28 -4
- package/lib/cjs/hooks/use-col-width.js +37 -8
- package/lib/cjs/hooks/use-pagination.js +51 -9
- package/lib/cjs/node_modules/classnames/index.js +76 -0
- package/lib/cjs/node_modules/rc-resize-observer/es/index.js +236 -0
- package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/Children/toArray.js +51 -0
- package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/Dom/findDOMNode.js +40 -0
- package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/ref.js +77 -0
- package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/warning.js +42 -0
- package/lib/cjs/node_modules/rc-util/es/Dom/canUseDom.js +20 -0
- package/lib/cjs/node_modules/rc-util/es/Dom/findDOMNode.js +40 -0
- package/lib/cjs/node_modules/rc-util/es/hooks/useLayoutEffect.js +49 -0
- package/lib/cjs/node_modules/rc-util/es/raf.js +72 -0
- package/lib/cjs/node_modules/rc-virtual-list/es/Filler.js +135 -0
- package/lib/cjs/node_modules/rc-virtual-list/es/Item.js +53 -0
- package/lib/cjs/node_modules/rc-virtual-list/es/List.js +550 -0
- package/lib/cjs/node_modules/rc-virtual-list/es/ScrollBar.js +431 -0
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useChildren.js +60 -0
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useDiffItem.js +129 -0
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useFrameWheel.js +64 -0
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useHeights.js +182 -0
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useMobileTouchMove.js +93 -0
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useOriginScroll.js +56 -0
- package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useScrollTo.js +154 -0
- package/lib/cjs/node_modules/rc-virtual-list/es/index.js +18 -0
- package/lib/cjs/node_modules/rc-virtual-list/es/utils/CacheMap.js +65 -0
- package/lib/cjs/node_modules/rc-virtual-list/es/utils/algorithmUtil.js +85 -0
- package/lib/cjs/node_modules/rc-virtual-list/es/utils/isFirefox.js +27 -0
- package/lib/cjs/node_modules/react-is/cjs/react-is.development.js +208 -0
- package/lib/cjs/node_modules/react-is/cjs/react-is.production.min.js +158 -0
- package/lib/cjs/node_modules/react-is/index.js +26 -0
- package/lib/cjs/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +1127 -0
- package/lib/cjs/styles/index.scss.js +1 -1
- package/lib/cjs/use-table.js +4 -2
- package/lib/esm/BaseTable.js +24 -21
- package/lib/esm/Table.js +28 -15
- package/lib/esm/TableAdvancedFilter.js +13 -13
- package/lib/esm/TableBody.js +95 -15
- package/lib/esm/TableCell.js +50 -9
- package/lib/esm/TableColumnMenu.js +16 -16
- package/lib/esm/TableEmbedRow.js +4 -4
- package/lib/esm/TableHeader.js +10 -10
- package/lib/esm/TableRow.js +53 -13
- package/lib/esm/TableSettingMenu.js +14 -14
- package/lib/esm/_virtual/index.js +13 -0
- package/lib/esm/_virtual/index2.js +13 -0
- package/lib/esm/_virtual/react-is.development.js +11 -0
- package/lib/esm/_virtual/react-is.production.min.js +11 -0
- package/lib/esm/hooks/use-check.js +32 -8
- package/lib/esm/hooks/use-col-width.js +44 -15
- package/lib/esm/hooks/use-colgroup.js +4 -4
- package/lib/esm/hooks/use-drag.js +2 -2
- package/lib/esm/hooks/use-embed-expand.js +2 -2
- package/lib/esm/hooks/use-pagination.js +51 -10
- package/lib/esm/icons/index.js +5 -5
- package/lib/esm/node_modules/classnames/index.js +69 -0
- package/lib/esm/node_modules/rc-resize-observer/es/index.js +177 -0
- package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/Children/toArray.js +33 -0
- package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/Dom/findDOMNode.js +23 -0
- package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/ref.js +57 -0
- package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/warning.js +34 -0
- package/lib/esm/node_modules/rc-util/es/Dom/canUseDom.js +14 -0
- package/lib/esm/node_modules/rc-util/es/Dom/findDOMNode.js +23 -0
- package/lib/esm/node_modules/rc-util/es/hooks/useLayoutEffect.js +17 -0
- package/lib/esm/node_modules/rc-util/es/raf.js +66 -0
- package/lib/esm/node_modules/rc-virtual-list/es/Filler.js +103 -0
- package/lib/esm/node_modules/rc-virtual-list/es/Item.js +23 -0
- package/lib/esm/node_modules/rc-virtual-list/es/List.js +508 -0
- package/lib/esm/node_modules/rc-virtual-list/es/ScrollBar.js +399 -0
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useChildren.js +29 -0
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useDiffItem.js +98 -0
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useFrameWheel.js +55 -0
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useHeights.js +150 -0
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useMobileTouchMove.js +85 -0
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useOriginScroll.js +50 -0
- package/lib/esm/node_modules/rc-virtual-list/es/hooks/useScrollTo.js +123 -0
- package/lib/esm/node_modules/rc-virtual-list/es/index.js +11 -0
- package/lib/esm/node_modules/rc-virtual-list/es/utils/CacheMap.js +59 -0
- package/lib/esm/node_modules/rc-virtual-list/es/utils/algorithmUtil.js +80 -0
- package/lib/esm/node_modules/rc-virtual-list/es/utils/isFirefox.js +21 -0
- package/lib/esm/node_modules/react-is/cjs/react-is.development.js +200 -0
- package/lib/esm/node_modules/react-is/cjs/react-is.production.min.js +151 -0
- package/lib/esm/node_modules/react-is/index.js +20 -0
- package/lib/esm/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +1122 -0
- package/lib/esm/styles/index.scss.js +1 -1
- package/lib/esm/use-table.js +12 -10
- package/lib/types/Table.d.ts +1 -1
- package/lib/types/TableCell.d.ts +4 -0
- package/lib/types/context.d.ts +2 -0
- package/lib/types/hooks/use-check.d.ts +1 -1
- package/lib/types/hooks/use-col-width.d.ts +2 -1
- package/lib/types/hooks/use-pagination.d.ts +7 -2
- package/lib/types/types.d.ts +7 -3
- package/lib/types/use-table.d.ts +14 -1
- package/package.json +5 -5
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
var React = require('react');
|
|
17
|
+
|
|
18
|
+
var findDOMNode = require('../../../rc-util/es/Dom/findDOMNode.js');
|
|
19
|
+
|
|
20
|
+
var raf = require('../../../rc-util/es/raf.js');
|
|
21
|
+
|
|
22
|
+
var CacheMap = require('../utils/CacheMap.js');
|
|
23
|
+
|
|
24
|
+
function _interopNamespace(e) {
|
|
25
|
+
if (e && e.__esModule) return e;
|
|
26
|
+
var n = Object.create(null);
|
|
27
|
+
|
|
28
|
+
if (e) {
|
|
29
|
+
Object.keys(e).forEach(function (k) {
|
|
30
|
+
if (k !== 'default') {
|
|
31
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
32
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return e[k];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
n["default"] = e;
|
|
43
|
+
return Object.freeze(n);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
47
|
+
|
|
48
|
+
function _slicedToArray(arr, i) {
|
|
49
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function _nonIterableRest() {
|
|
53
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
57
|
+
if (!o) return;
|
|
58
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
59
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
60
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
61
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
62
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function _arrayLikeToArray(arr, len) {
|
|
66
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
67
|
+
|
|
68
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) {
|
|
69
|
+
arr2[i] = arr[i];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return arr2;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function _iterableToArrayLimit(arr, i) {
|
|
76
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
77
|
+
|
|
78
|
+
if (_i == null) return;
|
|
79
|
+
var _arr = [];
|
|
80
|
+
var _n = true;
|
|
81
|
+
var _d = false;
|
|
82
|
+
|
|
83
|
+
var _s, _e;
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
87
|
+
_arr.push(_s.value);
|
|
88
|
+
|
|
89
|
+
if (i && _arr.length === i) break;
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
_d = true;
|
|
93
|
+
_e = err;
|
|
94
|
+
} finally {
|
|
95
|
+
try {
|
|
96
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
97
|
+
} finally {
|
|
98
|
+
if (_d) throw _e;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return _arr;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function _arrayWithHoles(arr) {
|
|
106
|
+
if (Array.isArray(arr)) return arr;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* To get exact height to avoid scrolling deviation
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
function getOuterHeight(el) {
|
|
114
|
+
var height = el.offsetHeight;
|
|
115
|
+
var computedStyle = window.getComputedStyle(el);
|
|
116
|
+
height += parseInt(computedStyle.marginTop, 10);
|
|
117
|
+
height += parseInt(computedStyle.marginBottom, 10);
|
|
118
|
+
return height;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function useHeights(getKey, onItemAdd, onItemRemove) {
|
|
122
|
+
var _React$useState = React__namespace.useState(0),
|
|
123
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
124
|
+
updatedMark = _React$useState2[0],
|
|
125
|
+
setUpdatedMark = _React$useState2[1];
|
|
126
|
+
|
|
127
|
+
var instanceRef = React.useRef(new Map());
|
|
128
|
+
var heightsRef = React.useRef(new CacheMap["default"]());
|
|
129
|
+
var collectRafRef = React.useRef();
|
|
130
|
+
|
|
131
|
+
function cancelRaf() {
|
|
132
|
+
raf["default"].cancel(collectRafRef.current);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function collectHeight() {
|
|
136
|
+
cancelRaf();
|
|
137
|
+
collectRafRef.current = raf["default"](function () {
|
|
138
|
+
instanceRef.current.forEach(function (element, key) {
|
|
139
|
+
if (element && element.offsetParent) {
|
|
140
|
+
var htmlElement = findDOMNode["default"](element);
|
|
141
|
+
var outerHeight = getOuterHeight(htmlElement);
|
|
142
|
+
|
|
143
|
+
if (heightsRef.current.get(key) !== outerHeight) {
|
|
144
|
+
heightsRef.current.set(key, outerHeight);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}); // Always trigger update mark to tell parent that should re-calculate heights when resized
|
|
148
|
+
|
|
149
|
+
setUpdatedMark(function (c) {
|
|
150
|
+
return c + 1;
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function setInstanceRef(item, instance) {
|
|
156
|
+
var key = getKey(item);
|
|
157
|
+
var origin = instanceRef.current.get(key);
|
|
158
|
+
|
|
159
|
+
if (instance) {
|
|
160
|
+
instanceRef.current.set(key, instance);
|
|
161
|
+
collectHeight();
|
|
162
|
+
} else {
|
|
163
|
+
instanceRef.current["delete"](key);
|
|
164
|
+
} // Instance changed
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
if (!origin !== !instance) {
|
|
168
|
+
if (instance) {
|
|
169
|
+
onItemAdd === null || onItemAdd === void 0 ? void 0 : onItemAdd(item);
|
|
170
|
+
} else {
|
|
171
|
+
onItemRemove === null || onItemRemove === void 0 ? void 0 : onItemRemove(item);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
React.useEffect(function () {
|
|
177
|
+
return cancelRaf;
|
|
178
|
+
}, []);
|
|
179
|
+
return [setInstanceRef, collectHeight, heightsRef.current, updatedMark];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
exports["default"] = useHeights;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
var React = require('react');
|
|
17
|
+
|
|
18
|
+
var useLayoutEffect = require('../../../rc-util/es/hooks/useLayoutEffect.js');
|
|
19
|
+
|
|
20
|
+
var SMOOTH_PTG = 14 / 15;
|
|
21
|
+
|
|
22
|
+
function useMobileTouchMove(inVirtual, listRef, callback) {
|
|
23
|
+
var touchedRef = React.useRef(false);
|
|
24
|
+
var touchYRef = React.useRef(0);
|
|
25
|
+
var elementRef = React.useRef(null); // Smooth scroll
|
|
26
|
+
|
|
27
|
+
var intervalRef = React.useRef(null);
|
|
28
|
+
/* eslint-disable prefer-const */
|
|
29
|
+
|
|
30
|
+
var cleanUpEvents;
|
|
31
|
+
|
|
32
|
+
var onTouchMove = function onTouchMove(e) {
|
|
33
|
+
if (touchedRef.current) {
|
|
34
|
+
var currentY = Math.ceil(e.touches[0].pageY);
|
|
35
|
+
var offsetY = touchYRef.current - currentY;
|
|
36
|
+
touchYRef.current = currentY;
|
|
37
|
+
|
|
38
|
+
if (callback(offsetY)) {
|
|
39
|
+
e.preventDefault();
|
|
40
|
+
} // Smooth interval
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
clearInterval(intervalRef.current);
|
|
44
|
+
intervalRef.current = setInterval(function () {
|
|
45
|
+
offsetY *= SMOOTH_PTG;
|
|
46
|
+
|
|
47
|
+
if (!callback(offsetY, true) || Math.abs(offsetY) <= 0.1) {
|
|
48
|
+
clearInterval(intervalRef.current);
|
|
49
|
+
}
|
|
50
|
+
}, 16);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
var onTouchEnd = function onTouchEnd() {
|
|
55
|
+
touchedRef.current = false;
|
|
56
|
+
cleanUpEvents();
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
var onTouchStart = function onTouchStart(e) {
|
|
60
|
+
cleanUpEvents();
|
|
61
|
+
|
|
62
|
+
if (e.touches.length === 1 && !touchedRef.current) {
|
|
63
|
+
touchedRef.current = true;
|
|
64
|
+
touchYRef.current = Math.ceil(e.touches[0].pageY);
|
|
65
|
+
elementRef.current = e.target;
|
|
66
|
+
elementRef.current.addEventListener('touchmove', onTouchMove);
|
|
67
|
+
elementRef.current.addEventListener('touchend', onTouchEnd);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
cleanUpEvents = function cleanUpEvents() {
|
|
72
|
+
if (elementRef.current) {
|
|
73
|
+
elementRef.current.removeEventListener('touchmove', onTouchMove);
|
|
74
|
+
elementRef.current.removeEventListener('touchend', onTouchEnd);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
useLayoutEffect["default"](function () {
|
|
79
|
+
if (inVirtual) {
|
|
80
|
+
listRef.current.addEventListener('touchstart', onTouchStart);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return function () {
|
|
84
|
+
var _listRef$current;
|
|
85
|
+
|
|
86
|
+
(_listRef$current = listRef.current) === null || _listRef$current === void 0 ? void 0 : _listRef$current.removeEventListener('touchstart', onTouchStart);
|
|
87
|
+
cleanUpEvents();
|
|
88
|
+
clearInterval(intervalRef.current);
|
|
89
|
+
};
|
|
90
|
+
}, [inVirtual]);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
exports["default"] = useMobileTouchMove;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
var React = require('react');
|
|
17
|
+
|
|
18
|
+
var useOriginScroll = function useOriginScroll(isScrollAtTop, isScrollAtBottom) {
|
|
19
|
+
// Do lock for a wheel when scrolling
|
|
20
|
+
var lockRef = React.useRef(false);
|
|
21
|
+
var lockTimeoutRef = React.useRef(null);
|
|
22
|
+
|
|
23
|
+
function lockScroll() {
|
|
24
|
+
clearTimeout(lockTimeoutRef.current);
|
|
25
|
+
lockRef.current = true;
|
|
26
|
+
lockTimeoutRef.current = setTimeout(function () {
|
|
27
|
+
lockRef.current = false;
|
|
28
|
+
}, 50);
|
|
29
|
+
} // Pass to ref since global add is in closure
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
var scrollPingRef = React.useRef({
|
|
33
|
+
top: isScrollAtTop,
|
|
34
|
+
bottom: isScrollAtBottom
|
|
35
|
+
});
|
|
36
|
+
scrollPingRef.current.top = isScrollAtTop;
|
|
37
|
+
scrollPingRef.current.bottom = isScrollAtBottom;
|
|
38
|
+
return function (deltaY) {
|
|
39
|
+
var smoothOffset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
40
|
+
var originScroll = // Pass origin wheel when on the top
|
|
41
|
+
deltaY < 0 && scrollPingRef.current.top || // Pass origin wheel when on the bottom
|
|
42
|
+
deltaY > 0 && scrollPingRef.current.bottom;
|
|
43
|
+
|
|
44
|
+
if (smoothOffset && originScroll) {
|
|
45
|
+
// No need lock anymore when it's smooth offset from touchMove interval
|
|
46
|
+
clearTimeout(lockTimeoutRef.current);
|
|
47
|
+
lockRef.current = false;
|
|
48
|
+
} else if (!originScroll || lockRef.current) {
|
|
49
|
+
lockScroll();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return !lockRef.current && originScroll;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
exports["default"] = useOriginScroll;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
var React = require('react');
|
|
17
|
+
|
|
18
|
+
var raf = require('../../../rc-util/es/raf.js');
|
|
19
|
+
|
|
20
|
+
function _interopNamespace(e) {
|
|
21
|
+
if (e && e.__esModule) return e;
|
|
22
|
+
var n = Object.create(null);
|
|
23
|
+
|
|
24
|
+
if (e) {
|
|
25
|
+
Object.keys(e).forEach(function (k) {
|
|
26
|
+
if (k !== 'default') {
|
|
27
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
28
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function get() {
|
|
31
|
+
return e[k];
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
n["default"] = e;
|
|
39
|
+
return Object.freeze(n);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
43
|
+
|
|
44
|
+
function _typeof(obj) {
|
|
45
|
+
"@babel/helpers - typeof";
|
|
46
|
+
|
|
47
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
48
|
+
return typeof obj;
|
|
49
|
+
} : function (obj) {
|
|
50
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
51
|
+
}, _typeof(obj);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function useScrollTo(containerRef, data, heights, itemHeight, getKey, collectHeight, syncScrollTop, triggerFlash) {
|
|
55
|
+
var scrollRef = React__namespace.useRef();
|
|
56
|
+
return function (arg) {
|
|
57
|
+
// When not argument provided, we think dev may want to show the scrollbar
|
|
58
|
+
if (arg === null || arg === undefined) {
|
|
59
|
+
triggerFlash();
|
|
60
|
+
return;
|
|
61
|
+
} // Normal scroll logic
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
raf["default"].cancel(scrollRef.current);
|
|
65
|
+
|
|
66
|
+
if (typeof arg === 'number') {
|
|
67
|
+
syncScrollTop(arg);
|
|
68
|
+
} else if (arg && _typeof(arg) === 'object') {
|
|
69
|
+
var index;
|
|
70
|
+
var align = arg.align;
|
|
71
|
+
|
|
72
|
+
if ('index' in arg) {
|
|
73
|
+
index = arg.index;
|
|
74
|
+
} else {
|
|
75
|
+
index = data.findIndex(function (item) {
|
|
76
|
+
return getKey(item) === arg.key;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
var _arg$offset = arg.offset,
|
|
81
|
+
offset = _arg$offset === void 0 ? 0 : _arg$offset; // We will retry 3 times in case dynamic height shaking
|
|
82
|
+
|
|
83
|
+
var syncScroll = function syncScroll(times, targetAlign) {
|
|
84
|
+
if (times < 0 || !containerRef.current) return;
|
|
85
|
+
var height = containerRef.current.clientHeight;
|
|
86
|
+
var needCollectHeight = false;
|
|
87
|
+
var newTargetAlign = targetAlign; // Go to next frame if height not exist
|
|
88
|
+
|
|
89
|
+
if (height) {
|
|
90
|
+
var mergedAlign = targetAlign || align; // Get top & bottom
|
|
91
|
+
|
|
92
|
+
var stackTop = 0;
|
|
93
|
+
var itemTop = 0;
|
|
94
|
+
var itemBottom = 0;
|
|
95
|
+
var maxLen = Math.min(data.length, index);
|
|
96
|
+
|
|
97
|
+
for (var i = 0; i <= maxLen; i += 1) {
|
|
98
|
+
var key = getKey(data[i]);
|
|
99
|
+
itemTop = stackTop;
|
|
100
|
+
var cacheHeight = heights.get(key);
|
|
101
|
+
itemBottom = itemTop + (cacheHeight === undefined ? itemHeight : cacheHeight);
|
|
102
|
+
stackTop = itemBottom;
|
|
103
|
+
|
|
104
|
+
if (i === index && cacheHeight === undefined) {
|
|
105
|
+
needCollectHeight = true;
|
|
106
|
+
}
|
|
107
|
+
} // Scroll to
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
var targetTop = null;
|
|
111
|
+
|
|
112
|
+
switch (mergedAlign) {
|
|
113
|
+
case 'top':
|
|
114
|
+
targetTop = itemTop - offset;
|
|
115
|
+
break;
|
|
116
|
+
|
|
117
|
+
case 'bottom':
|
|
118
|
+
targetTop = itemBottom - height + offset;
|
|
119
|
+
break;
|
|
120
|
+
|
|
121
|
+
default:
|
|
122
|
+
{
|
|
123
|
+
var scrollTop = containerRef.current.scrollTop;
|
|
124
|
+
var scrollBottom = scrollTop + height;
|
|
125
|
+
|
|
126
|
+
if (itemTop < scrollTop) {
|
|
127
|
+
newTargetAlign = 'top';
|
|
128
|
+
} else if (itemBottom > scrollBottom) {
|
|
129
|
+
newTargetAlign = 'bottom';
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (targetTop !== null && targetTop !== containerRef.current.scrollTop) {
|
|
135
|
+
syncScrollTop(targetTop);
|
|
136
|
+
}
|
|
137
|
+
} // We will retry since element may not sync height as it described
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
scrollRef.current = raf["default"](function () {
|
|
141
|
+
if (needCollectHeight) {
|
|
142
|
+
collectHeight();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
syncScroll(times - 1, newTargetAlign);
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
syncScroll(3);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
exports["default"] = useScrollTo;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
var List = require('./List.js');
|
|
17
|
+
|
|
18
|
+
exports["default"] = List["default"];
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
function _classCallCheck(instance, Constructor) {
|
|
17
|
+
if (!(instance instanceof Constructor)) {
|
|
18
|
+
throw new TypeError("Cannot call a class as a function");
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function _defineProperties(target, props) {
|
|
23
|
+
for (var i = 0; i < props.length; i++) {
|
|
24
|
+
var descriptor = props[i];
|
|
25
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
26
|
+
descriptor.configurable = true;
|
|
27
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
28
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
33
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
34
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
35
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
36
|
+
writable: false
|
|
37
|
+
});
|
|
38
|
+
return Constructor;
|
|
39
|
+
} // Firefox has low performance of map.
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
var CacheMap = /*#__PURE__*/function () {
|
|
43
|
+
function CacheMap() {
|
|
44
|
+
_classCallCheck(this, CacheMap);
|
|
45
|
+
|
|
46
|
+
this.maps = void 0;
|
|
47
|
+
this.maps = Object.create(null);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
_createClass(CacheMap, [{
|
|
51
|
+
key: "set",
|
|
52
|
+
value: function set(key, value) {
|
|
53
|
+
this.maps[key] = value;
|
|
54
|
+
}
|
|
55
|
+
}, {
|
|
56
|
+
key: "get",
|
|
57
|
+
value: function get(key) {
|
|
58
|
+
return this.maps[key];
|
|
59
|
+
}
|
|
60
|
+
}]);
|
|
61
|
+
|
|
62
|
+
return CacheMap;
|
|
63
|
+
}();
|
|
64
|
+
|
|
65
|
+
exports["default"] = CacheMap;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Get index with specific start index one by one. e.g.
|
|
17
|
+
* min: 3, max: 9, start: 6
|
|
18
|
+
*
|
|
19
|
+
* Return index is:
|
|
20
|
+
* [0]: 6
|
|
21
|
+
* [1]: 7
|
|
22
|
+
* [2]: 5
|
|
23
|
+
* [3]: 8
|
|
24
|
+
* [4]: 4
|
|
25
|
+
* [5]: 9
|
|
26
|
+
* [6]: 3
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* We assume that 2 list has only 1 item diff and others keeping the order.
|
|
31
|
+
* So we can use dichotomy algorithm to find changed one.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
function findListDiffIndex(originList, targetList, getKey) {
|
|
35
|
+
var originLen = originList.length;
|
|
36
|
+
var targetLen = targetList.length;
|
|
37
|
+
var shortList;
|
|
38
|
+
var longList;
|
|
39
|
+
|
|
40
|
+
if (originLen === 0 && targetLen === 0) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (originLen < targetLen) {
|
|
45
|
+
shortList = originList;
|
|
46
|
+
longList = targetList;
|
|
47
|
+
} else {
|
|
48
|
+
shortList = targetList;
|
|
49
|
+
longList = originList;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
var notExistKey = {
|
|
53
|
+
__EMPTY_ITEM__: true
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
function getItemKey(item) {
|
|
57
|
+
if (item !== undefined) {
|
|
58
|
+
return getKey(item);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return notExistKey;
|
|
62
|
+
} // Loop to find diff one
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
var diffIndex = null;
|
|
66
|
+
var multiple = Math.abs(originLen - targetLen) !== 1;
|
|
67
|
+
|
|
68
|
+
for (var i = 0; i < longList.length; i += 1) {
|
|
69
|
+
var shortKey = getItemKey(shortList[i]);
|
|
70
|
+
var longKey = getItemKey(longList[i]);
|
|
71
|
+
|
|
72
|
+
if (shortKey !== longKey) {
|
|
73
|
+
diffIndex = i;
|
|
74
|
+
multiple = multiple || shortKey !== getItemKey(longList[i + 1]);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return diffIndex === null ? null : {
|
|
80
|
+
index: diffIndex,
|
|
81
|
+
multiple: multiple
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.findListDiffIndex = findListDiffIndex;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** @LICENSE
|
|
2
|
+
* @hi-ui/table
|
|
3
|
+
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/table#readme
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) HiUI <mi-hiui@xiaomi.com>.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, '__esModule', {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
function _typeof(obj) {
|
|
17
|
+
"@babel/helpers - typeof";
|
|
18
|
+
|
|
19
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
20
|
+
return typeof obj;
|
|
21
|
+
} : function (obj) {
|
|
22
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
23
|
+
}, _typeof(obj);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
var isFF = (typeof navigator === "undefined" ? "undefined" : _typeof(navigator)) === 'object' && /Firefox/i.test(navigator.userAgent);
|
|
27
|
+
exports["default"] = isFF;
|