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