@hi-ui/table 4.0.12 → 4.1.0-beta.0

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.
Files changed (106) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/lib/cjs/BaseTable.js +7 -4
  3. package/lib/cjs/Table.js +19 -6
  4. package/lib/cjs/TableBody.js +88 -8
  5. package/lib/cjs/TableCell.js +42 -1
  6. package/lib/cjs/TableRow.js +42 -2
  7. package/lib/cjs/_virtual/index.js +18 -0
  8. package/lib/cjs/_virtual/index2.js +18 -0
  9. package/lib/cjs/_virtual/react-is.development.js +16 -0
  10. package/lib/cjs/_virtual/react-is.production.min.js +16 -0
  11. package/lib/cjs/hooks/use-check.js +28 -4
  12. package/lib/cjs/hooks/use-col-width.js +37 -8
  13. package/lib/cjs/hooks/use-pagination.js +51 -9
  14. package/lib/cjs/node_modules/classnames/index.js +76 -0
  15. package/lib/cjs/node_modules/rc-resize-observer/es/index.js +236 -0
  16. package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/Children/toArray.js +51 -0
  17. package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/Dom/findDOMNode.js +40 -0
  18. package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/ref.js +77 -0
  19. package/lib/cjs/node_modules/rc-resize-observer/node_modules/rc-util/es/warning.js +42 -0
  20. package/lib/cjs/node_modules/rc-util/es/Dom/canUseDom.js +20 -0
  21. package/lib/cjs/node_modules/rc-util/es/Dom/findDOMNode.js +40 -0
  22. package/lib/cjs/node_modules/rc-util/es/hooks/useLayoutEffect.js +49 -0
  23. package/lib/cjs/node_modules/rc-util/es/raf.js +72 -0
  24. package/lib/cjs/node_modules/rc-virtual-list/es/Filler.js +135 -0
  25. package/lib/cjs/node_modules/rc-virtual-list/es/Item.js +53 -0
  26. package/lib/cjs/node_modules/rc-virtual-list/es/List.js +550 -0
  27. package/lib/cjs/node_modules/rc-virtual-list/es/ScrollBar.js +431 -0
  28. package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useChildren.js +60 -0
  29. package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useDiffItem.js +129 -0
  30. package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useFrameWheel.js +64 -0
  31. package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useHeights.js +182 -0
  32. package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useMobileTouchMove.js +93 -0
  33. package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useOriginScroll.js +56 -0
  34. package/lib/cjs/node_modules/rc-virtual-list/es/hooks/useScrollTo.js +154 -0
  35. package/lib/cjs/node_modules/rc-virtual-list/es/index.js +18 -0
  36. package/lib/cjs/node_modules/rc-virtual-list/es/utils/CacheMap.js +65 -0
  37. package/lib/cjs/node_modules/rc-virtual-list/es/utils/algorithmUtil.js +85 -0
  38. package/lib/cjs/node_modules/rc-virtual-list/es/utils/isFirefox.js +27 -0
  39. package/lib/cjs/node_modules/react-is/cjs/react-is.development.js +208 -0
  40. package/lib/cjs/node_modules/react-is/cjs/react-is.production.min.js +158 -0
  41. package/lib/cjs/node_modules/react-is/index.js +26 -0
  42. package/lib/cjs/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +1127 -0
  43. package/lib/cjs/styles/index.scss.js +1 -1
  44. package/lib/cjs/use-table.js +4 -2
  45. package/lib/esm/BaseTable.js +24 -21
  46. package/lib/esm/Table.js +28 -15
  47. package/lib/esm/TableAdvancedFilter.js +13 -13
  48. package/lib/esm/TableBody.js +100 -21
  49. package/lib/esm/TableCell.js +50 -9
  50. package/lib/esm/TableColumnMenu.js +16 -16
  51. package/lib/esm/TableEmbedRow.js +4 -4
  52. package/lib/esm/TableHeader.js +10 -10
  53. package/lib/esm/TableRow.js +53 -13
  54. package/lib/esm/TableSettingMenu.js +14 -14
  55. package/lib/esm/_virtual/index.js +13 -0
  56. package/lib/esm/_virtual/index2.js +13 -0
  57. package/lib/esm/_virtual/react-is.development.js +11 -0
  58. package/lib/esm/_virtual/react-is.production.min.js +11 -0
  59. package/lib/esm/hooks/use-check.js +32 -8
  60. package/lib/esm/hooks/use-col-width.js +44 -15
  61. package/lib/esm/hooks/use-colgroup.js +4 -4
  62. package/lib/esm/hooks/use-drag.js +2 -2
  63. package/lib/esm/hooks/use-embed-expand.js +2 -2
  64. package/lib/esm/hooks/use-pagination.js +51 -10
  65. package/lib/esm/icons/index.js +5 -5
  66. package/lib/esm/node_modules/classnames/index.js +69 -0
  67. package/lib/esm/node_modules/rc-resize-observer/es/index.js +177 -0
  68. package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/Children/toArray.js +33 -0
  69. package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/Dom/findDOMNode.js +23 -0
  70. package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/ref.js +57 -0
  71. package/lib/esm/node_modules/rc-resize-observer/node_modules/rc-util/es/warning.js +34 -0
  72. package/lib/esm/node_modules/rc-util/es/Dom/canUseDom.js +14 -0
  73. package/lib/esm/node_modules/rc-util/es/Dom/findDOMNode.js +23 -0
  74. package/lib/esm/node_modules/rc-util/es/hooks/useLayoutEffect.js +17 -0
  75. package/lib/esm/node_modules/rc-util/es/raf.js +66 -0
  76. package/lib/esm/node_modules/rc-virtual-list/es/Filler.js +103 -0
  77. package/lib/esm/node_modules/rc-virtual-list/es/Item.js +23 -0
  78. package/lib/esm/node_modules/rc-virtual-list/es/List.js +508 -0
  79. package/lib/esm/node_modules/rc-virtual-list/es/ScrollBar.js +399 -0
  80. package/lib/esm/node_modules/rc-virtual-list/es/hooks/useChildren.js +29 -0
  81. package/lib/esm/node_modules/rc-virtual-list/es/hooks/useDiffItem.js +98 -0
  82. package/lib/esm/node_modules/rc-virtual-list/es/hooks/useFrameWheel.js +55 -0
  83. package/lib/esm/node_modules/rc-virtual-list/es/hooks/useHeights.js +150 -0
  84. package/lib/esm/node_modules/rc-virtual-list/es/hooks/useMobileTouchMove.js +85 -0
  85. package/lib/esm/node_modules/rc-virtual-list/es/hooks/useOriginScroll.js +50 -0
  86. package/lib/esm/node_modules/rc-virtual-list/es/hooks/useScrollTo.js +123 -0
  87. package/lib/esm/node_modules/rc-virtual-list/es/index.js +11 -0
  88. package/lib/esm/node_modules/rc-virtual-list/es/utils/CacheMap.js +59 -0
  89. package/lib/esm/node_modules/rc-virtual-list/es/utils/algorithmUtil.js +80 -0
  90. package/lib/esm/node_modules/rc-virtual-list/es/utils/isFirefox.js +21 -0
  91. package/lib/esm/node_modules/react-is/cjs/react-is.development.js +200 -0
  92. package/lib/esm/node_modules/react-is/cjs/react-is.production.min.js +151 -0
  93. package/lib/esm/node_modules/react-is/index.js +20 -0
  94. package/lib/esm/node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js +1122 -0
  95. package/lib/esm/styles/index.scss.js +1 -1
  96. package/lib/esm/use-table.js +12 -10
  97. package/lib/types/Table.d.ts +1 -1
  98. package/lib/types/TableCell.d.ts +4 -0
  99. package/lib/types/context.d.ts +2 -0
  100. package/lib/types/hooks/use-check.d.ts +1 -1
  101. package/lib/types/hooks/use-col-width.d.ts +2 -1
  102. package/lib/types/hooks/use-pagination.d.ts +7 -2
  103. package/lib/types/types.d.ts +7 -3
  104. package/lib/types/use-table.d.ts +14 -1
  105. package/package.json +6 -7
  106. package/LICENSE +0 -21
@@ -0,0 +1,399 @@
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
+ import * as React from 'react';
11
+ import classNames from '../../classnames/index.js';
12
+ import wrapperRaf from '../../rc-util/es/raf.js';
13
+
14
+ function _typeof(obj) {
15
+ "@babel/helpers - typeof";
16
+
17
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
18
+ return typeof obj;
19
+ } : function (obj) {
20
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
21
+ }, _typeof(obj);
22
+ }
23
+
24
+ function _defineProperty(obj, key, value) {
25
+ if (key in obj) {
26
+ Object.defineProperty(obj, key, {
27
+ value: value,
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true
31
+ });
32
+ } else {
33
+ obj[key] = value;
34
+ }
35
+
36
+ return obj;
37
+ }
38
+
39
+ function _classCallCheck(instance, Constructor) {
40
+ if (!(instance instanceof Constructor)) {
41
+ throw new TypeError("Cannot call a class as a function");
42
+ }
43
+ }
44
+
45
+ function _defineProperties(target, props) {
46
+ for (var i = 0; i < props.length; i++) {
47
+ var descriptor = props[i];
48
+ descriptor.enumerable = descriptor.enumerable || false;
49
+ descriptor.configurable = true;
50
+ if ("value" in descriptor) descriptor.writable = true;
51
+ Object.defineProperty(target, descriptor.key, descriptor);
52
+ }
53
+ }
54
+
55
+ function _createClass(Constructor, protoProps, staticProps) {
56
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
57
+ if (staticProps) _defineProperties(Constructor, staticProps);
58
+ Object.defineProperty(Constructor, "prototype", {
59
+ writable: false
60
+ });
61
+ return Constructor;
62
+ }
63
+
64
+ function _inherits(subClass, superClass) {
65
+ if (typeof superClass !== "function" && superClass !== null) {
66
+ throw new TypeError("Super expression must either be null or a function");
67
+ }
68
+
69
+ subClass.prototype = Object.create(superClass && superClass.prototype, {
70
+ constructor: {
71
+ value: subClass,
72
+ writable: true,
73
+ configurable: true
74
+ }
75
+ });
76
+ Object.defineProperty(subClass, "prototype", {
77
+ writable: false
78
+ });
79
+ if (superClass) _setPrototypeOf(subClass, superClass);
80
+ }
81
+
82
+ function _setPrototypeOf(o, p) {
83
+ _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
84
+ o.__proto__ = p;
85
+ return o;
86
+ };
87
+
88
+ return _setPrototypeOf(o, p);
89
+ }
90
+
91
+ function _createSuper(Derived) {
92
+ var hasNativeReflectConstruct = _isNativeReflectConstruct();
93
+
94
+ return function _createSuperInternal() {
95
+ var Super = _getPrototypeOf(Derived),
96
+ result;
97
+
98
+ if (hasNativeReflectConstruct) {
99
+ var NewTarget = _getPrototypeOf(this).constructor;
100
+
101
+ result = Reflect.construct(Super, arguments, NewTarget);
102
+ } else {
103
+ result = Super.apply(this, arguments);
104
+ }
105
+
106
+ return _possibleConstructorReturn(this, result);
107
+ };
108
+ }
109
+
110
+ function _possibleConstructorReturn(self, call) {
111
+ if (call && (_typeof(call) === "object" || typeof call === "function")) {
112
+ return call;
113
+ } else if (call !== void 0) {
114
+ throw new TypeError("Derived constructors may only return object or undefined");
115
+ }
116
+
117
+ return _assertThisInitialized(self);
118
+ }
119
+
120
+ function _assertThisInitialized(self) {
121
+ if (self === void 0) {
122
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
123
+ }
124
+
125
+ return self;
126
+ }
127
+
128
+ function _isNativeReflectConstruct() {
129
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
130
+ if (Reflect.construct.sham) return false;
131
+ if (typeof Proxy === "function") return true;
132
+
133
+ try {
134
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
135
+ return true;
136
+ } catch (e) {
137
+ return false;
138
+ }
139
+ }
140
+
141
+ function _getPrototypeOf(o) {
142
+ _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
143
+ return o.__proto__ || Object.getPrototypeOf(o);
144
+ };
145
+ return _getPrototypeOf(o);
146
+ }
147
+
148
+ var MIN_SIZE = 20;
149
+
150
+ function getPageY(e) {
151
+ return 'touches' in e ? e.touches[0].pageY : e.pageY;
152
+ }
153
+
154
+ var ScrollBar = /*#__PURE__*/function (_React$Component) {
155
+ _inherits(ScrollBar, _React$Component);
156
+
157
+ var _super = _createSuper(ScrollBar);
158
+
159
+ function ScrollBar() {
160
+ var _this;
161
+
162
+ _classCallCheck(this, ScrollBar);
163
+
164
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
165
+ args[_key] = arguments[_key];
166
+ }
167
+
168
+ _this = _super.call.apply(_super, [this].concat(args));
169
+ _this.moveRaf = null;
170
+ _this.scrollbarRef = /*#__PURE__*/React.createRef();
171
+ _this.thumbRef = /*#__PURE__*/React.createRef();
172
+ _this.visibleTimeout = null;
173
+ _this.state = {
174
+ dragging: false,
175
+ pageY: null,
176
+ startTop: null,
177
+ visible: false
178
+ };
179
+
180
+ _this.delayHidden = function () {
181
+ clearTimeout(_this.visibleTimeout);
182
+
183
+ _this.setState({
184
+ visible: true
185
+ });
186
+
187
+ _this.visibleTimeout = setTimeout(function () {
188
+ _this.setState({
189
+ visible: false
190
+ });
191
+ }, 2000);
192
+ };
193
+
194
+ _this.onScrollbarTouchStart = function (e) {
195
+ e.preventDefault();
196
+ };
197
+
198
+ _this.onContainerMouseDown = function (e) {
199
+ e.stopPropagation();
200
+ e.preventDefault();
201
+ };
202
+
203
+ _this.patchEvents = function () {
204
+ window.addEventListener('mousemove', _this.onMouseMove);
205
+ window.addEventListener('mouseup', _this.onMouseUp);
206
+
207
+ _this.thumbRef.current.addEventListener('touchmove', _this.onMouseMove);
208
+
209
+ _this.thumbRef.current.addEventListener('touchend', _this.onMouseUp);
210
+ };
211
+
212
+ _this.removeEvents = function () {
213
+ var _this$scrollbarRef$cu;
214
+
215
+ window.removeEventListener('mousemove', _this.onMouseMove);
216
+ window.removeEventListener('mouseup', _this.onMouseUp);
217
+ (_this$scrollbarRef$cu = _this.scrollbarRef.current) === null || _this$scrollbarRef$cu === void 0 ? void 0 : _this$scrollbarRef$cu.removeEventListener('touchstart', _this.onScrollbarTouchStart);
218
+
219
+ if (_this.thumbRef.current) {
220
+ _this.thumbRef.current.removeEventListener('touchstart', _this.onMouseDown);
221
+
222
+ _this.thumbRef.current.removeEventListener('touchmove', _this.onMouseMove);
223
+
224
+ _this.thumbRef.current.removeEventListener('touchend', _this.onMouseUp);
225
+ }
226
+
227
+ wrapperRaf.cancel(_this.moveRaf);
228
+ };
229
+
230
+ _this.onMouseDown = function (e) {
231
+ var onStartMove = _this.props.onStartMove;
232
+
233
+ _this.setState({
234
+ dragging: true,
235
+ pageY: getPageY(e),
236
+ startTop: _this.getTop()
237
+ });
238
+
239
+ onStartMove();
240
+
241
+ _this.patchEvents();
242
+
243
+ e.stopPropagation();
244
+ e.preventDefault();
245
+ };
246
+
247
+ _this.onMouseMove = function (e) {
248
+ var _this$state = _this.state,
249
+ dragging = _this$state.dragging,
250
+ pageY = _this$state.pageY,
251
+ startTop = _this$state.startTop;
252
+ var onScroll = _this.props.onScroll;
253
+ wrapperRaf.cancel(_this.moveRaf);
254
+
255
+ if (dragging) {
256
+ var offsetY = getPageY(e) - pageY;
257
+ var newTop = startTop + offsetY;
258
+
259
+ var enableScrollRange = _this.getEnableScrollRange();
260
+
261
+ var enableHeightRange = _this.getEnableHeightRange();
262
+
263
+ var ptg = enableHeightRange ? newTop / enableHeightRange : 0;
264
+ var newScrollTop = Math.ceil(ptg * enableScrollRange);
265
+ _this.moveRaf = wrapperRaf(function () {
266
+ onScroll(newScrollTop);
267
+ });
268
+ }
269
+ };
270
+
271
+ _this.onMouseUp = function () {
272
+ var onStopMove = _this.props.onStopMove;
273
+
274
+ _this.setState({
275
+ dragging: false
276
+ });
277
+
278
+ onStopMove();
279
+
280
+ _this.removeEvents();
281
+ };
282
+
283
+ _this.getSpinHeight = function () {
284
+ var _this$props = _this.props,
285
+ height = _this$props.height,
286
+ count = _this$props.count;
287
+ var baseHeight = height / count * 10;
288
+ baseHeight = Math.max(baseHeight, MIN_SIZE);
289
+ baseHeight = Math.min(baseHeight, height / 2);
290
+ return Math.floor(baseHeight);
291
+ };
292
+
293
+ _this.getEnableScrollRange = function () {
294
+ var _this$props2 = _this.props,
295
+ scrollHeight = _this$props2.scrollHeight,
296
+ height = _this$props2.height;
297
+ return scrollHeight - height || 0;
298
+ };
299
+
300
+ _this.getEnableHeightRange = function () {
301
+ var height = _this.props.height;
302
+
303
+ var spinHeight = _this.getSpinHeight();
304
+
305
+ return height - spinHeight || 0;
306
+ };
307
+
308
+ _this.getTop = function () {
309
+ var scrollTop = _this.props.scrollTop;
310
+
311
+ var enableScrollRange = _this.getEnableScrollRange();
312
+
313
+ var enableHeightRange = _this.getEnableHeightRange();
314
+
315
+ if (scrollTop === 0 || enableScrollRange === 0) {
316
+ return 0;
317
+ }
318
+
319
+ var ptg = scrollTop / enableScrollRange;
320
+ return ptg * enableHeightRange;
321
+ };
322
+
323
+ _this.showScroll = function () {
324
+ var _this$props3 = _this.props,
325
+ height = _this$props3.height,
326
+ scrollHeight = _this$props3.scrollHeight;
327
+ return scrollHeight > height;
328
+ };
329
+
330
+ return _this;
331
+ }
332
+
333
+ _createClass(ScrollBar, [{
334
+ key: "componentDidMount",
335
+ value: function componentDidMount() {
336
+ this.scrollbarRef.current.addEventListener('touchstart', this.onScrollbarTouchStart);
337
+ this.thumbRef.current.addEventListener('touchstart', this.onMouseDown);
338
+ }
339
+ }, {
340
+ key: "componentDidUpdate",
341
+ value: function componentDidUpdate(prevProps) {
342
+ if (prevProps.scrollTop !== this.props.scrollTop) {
343
+ this.delayHidden();
344
+ }
345
+ }
346
+ }, {
347
+ key: "componentWillUnmount",
348
+ value: function componentWillUnmount() {
349
+ this.removeEvents();
350
+ clearTimeout(this.visibleTimeout);
351
+ }
352
+ }, {
353
+ key: "render",
354
+ value: // ====================== Render =======================
355
+ function render() {
356
+ var _this$state2 = this.state,
357
+ dragging = _this$state2.dragging,
358
+ visible = _this$state2.visible;
359
+ var prefixCls = this.props.prefixCls;
360
+ var spinHeight = this.getSpinHeight();
361
+ var top = this.getTop();
362
+ var canScroll = this.showScroll();
363
+ var mergedVisible = canScroll && visible;
364
+ return /*#__PURE__*/React.createElement("div", {
365
+ ref: this.scrollbarRef,
366
+ className: classNames("".concat(prefixCls, "-scrollbar"), _defineProperty({}, "".concat(prefixCls, "-scrollbar-show"), canScroll)),
367
+ style: {
368
+ width: 8,
369
+ top: 0,
370
+ bottom: 0,
371
+ right: 0,
372
+ position: 'absolute',
373
+ display: mergedVisible ? null : 'none'
374
+ },
375
+ onMouseDown: this.onContainerMouseDown,
376
+ onMouseMove: this.delayHidden
377
+ }, /*#__PURE__*/React.createElement("div", {
378
+ ref: this.thumbRef,
379
+ className: classNames("".concat(prefixCls, "-scrollbar-thumb"), _defineProperty({}, "".concat(prefixCls, "-scrollbar-thumb-moving"), dragging)),
380
+ style: {
381
+ width: '100%',
382
+ height: spinHeight,
383
+ top: top,
384
+ left: 0,
385
+ position: 'absolute',
386
+ background: 'rgba(0, 0, 0, 0.5)',
387
+ borderRadius: 99,
388
+ cursor: 'pointer',
389
+ userSelect: 'none'
390
+ },
391
+ onMouseDown: this.onMouseDown
392
+ }));
393
+ }
394
+ }]);
395
+
396
+ return ScrollBar;
397
+ }(React.Component);
398
+
399
+ export { ScrollBar as default };
@@ -0,0 +1,29 @@
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
+ import * as React from 'react';
11
+ import { Item } from '../Item.js';
12
+
13
+ function useChildren(list, startIndex, endIndex, setNodeRef, renderFunc, _ref) {
14
+ var getKey = _ref.getKey;
15
+ return list.slice(startIndex, endIndex + 1).map(function (item, index) {
16
+ var eleIndex = startIndex + index;
17
+ var node = renderFunc(item, eleIndex, {// style: status === 'MEASURE_START' ? { visibility: 'hidden' } : {},
18
+ });
19
+ var key = getKey(item);
20
+ return /*#__PURE__*/React.createElement(Item, {
21
+ key: key,
22
+ setRef: function setRef(ele) {
23
+ return setNodeRef(item, ele);
24
+ }
25
+ }, node);
26
+ });
27
+ }
28
+
29
+ export { useChildren as default };
@@ -0,0 +1,98 @@
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
+ import * as React from 'react';
11
+ import { findListDiffIndex } from '../utils/algorithmUtil.js';
12
+
13
+ function _slicedToArray(arr, i) {
14
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
15
+ }
16
+
17
+ function _nonIterableRest() {
18
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
19
+ }
20
+
21
+ function _unsupportedIterableToArray(o, minLen) {
22
+ if (!o) return;
23
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
24
+ var n = Object.prototype.toString.call(o).slice(8, -1);
25
+ if (n === "Object" && o.constructor) n = o.constructor.name;
26
+ if (n === "Map" || n === "Set") return Array.from(o);
27
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
28
+ }
29
+
30
+ function _arrayLikeToArray(arr, len) {
31
+ if (len == null || len > arr.length) len = arr.length;
32
+
33
+ for (var i = 0, arr2 = new Array(len); i < len; i++) {
34
+ arr2[i] = arr[i];
35
+ }
36
+
37
+ return arr2;
38
+ }
39
+
40
+ function _iterableToArrayLimit(arr, i) {
41
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
42
+
43
+ if (_i == null) return;
44
+ var _arr = [];
45
+ var _n = true;
46
+ var _d = false;
47
+
48
+ var _s, _e;
49
+
50
+ try {
51
+ for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
52
+ _arr.push(_s.value);
53
+
54
+ if (i && _arr.length === i) break;
55
+ }
56
+ } catch (err) {
57
+ _d = true;
58
+ _e = err;
59
+ } finally {
60
+ try {
61
+ if (!_n && _i["return"] != null) _i["return"]();
62
+ } finally {
63
+ if (_d) throw _e;
64
+ }
65
+ }
66
+
67
+ return _arr;
68
+ }
69
+
70
+ function _arrayWithHoles(arr) {
71
+ if (Array.isArray(arr)) return arr;
72
+ }
73
+
74
+ function useDiffItem(data, getKey, onDiff) {
75
+ var _React$useState = React.useState(data),
76
+ _React$useState2 = _slicedToArray(_React$useState, 2),
77
+ prevData = _React$useState2[0],
78
+ setPrevData = _React$useState2[1];
79
+
80
+ var _React$useState3 = React.useState(null),
81
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
82
+ diffItem = _React$useState4[0],
83
+ setDiffItem = _React$useState4[1];
84
+
85
+ React.useEffect(function () {
86
+ var diff = findListDiffIndex(prevData || [], data || [], getKey);
87
+
88
+ if ((diff === null || diff === void 0 ? void 0 : diff.index) !== undefined) {
89
+ onDiff === null || onDiff === void 0 ? void 0 : onDiff(diff.index);
90
+ setDiffItem(data[diff.index]);
91
+ }
92
+
93
+ setPrevData(data);
94
+ }, [data]);
95
+ return [diffItem];
96
+ }
97
+
98
+ export { useDiffItem as default };
@@ -0,0 +1,55 @@
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
+ import { useRef } from 'react';
11
+ import wrapperRaf from '../../../rc-util/es/raf.js';
12
+ import isFF from '../utils/isFirefox.js';
13
+ import useOriginScroll from './useOriginScroll.js';
14
+
15
+ function useFrameWheel(inVirtual, isScrollAtTop, isScrollAtBottom, onWheelDelta) {
16
+ var offsetRef = useRef(0);
17
+ var nextFrameRef = useRef(null); // Firefox patch
18
+
19
+ var wheelValueRef = useRef(null);
20
+ var isMouseScrollRef = useRef(false); // Scroll status sync
21
+
22
+ var originScroll = useOriginScroll(isScrollAtTop, isScrollAtBottom);
23
+
24
+ function onWheel(event) {
25
+ if (!inVirtual) return;
26
+ wrapperRaf.cancel(nextFrameRef.current);
27
+ var deltaY = event.deltaY;
28
+ offsetRef.current += deltaY;
29
+ wheelValueRef.current = deltaY; // Do nothing when scroll at the edge, Skip check when is in scroll
30
+
31
+ if (originScroll(deltaY)) return; // Proxy of scroll events
32
+
33
+ if (!isFF) {
34
+ event.preventDefault();
35
+ }
36
+
37
+ nextFrameRef.current = wrapperRaf(function () {
38
+ // Patch a multiple for Firefox to fix wheel number too small
39
+ // ref: https://github.com/ant-design/ant-design/issues/26372#issuecomment-679460266
40
+ var patchMultiple = isMouseScrollRef.current ? 10 : 1;
41
+ onWheelDelta(offsetRef.current * patchMultiple);
42
+ offsetRef.current = 0;
43
+ });
44
+ } // A patch for firefox
45
+
46
+
47
+ function onFireFoxScroll(event) {
48
+ if (!inVirtual) return;
49
+ isMouseScrollRef.current = event.detail === wheelValueRef.current;
50
+ }
51
+
52
+ return [onWheel, onFireFoxScroll];
53
+ }
54
+
55
+ export { useFrameWheel as default };