@capillarytech/blaze-ui 0.1.4-alpha.10 → 0.1.4-alpha.11
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/CapTable/CapTable.js +16 -88
- package/dist/esm/CapTable/CapTable.js +19 -55
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/CapTable/CapTable.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CapTable - Migrated to Ant Design v5
|
|
3
3
|
*/
|
|
4
|
-
import React, {
|
|
4
|
+
import React, { useCallback } from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { throttle } from 'lodash';
|
|
7
7
|
import { Table } from 'antd';
|
|
@@ -16,22 +16,6 @@ const StyledTable = styled(Table)`
|
|
|
16
16
|
border: 1px solid ${CAP_G07};
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
&.show-loader {
|
|
21
|
-
.ant-table-body > table > tbody::after {
|
|
22
|
-
content: '${(props) => props.loadMoreData}';
|
|
23
|
-
display: flex;
|
|
24
|
-
justify-content: center;
|
|
25
|
-
position: absolute;
|
|
26
|
-
width: 100%;
|
|
27
|
-
align-items: center;
|
|
28
|
-
height: 60px;
|
|
29
|
-
text-align: center;
|
|
30
|
-
font-size: 16px;
|
|
31
|
-
color: gray;
|
|
32
|
-
border-top: 1px solid ${CAP_G07};
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
19
|
`;
|
|
36
20
|
|
|
37
21
|
const CapTable = ({
|
|
@@ -47,90 +31,34 @@ const CapTable = ({
|
|
|
47
31
|
showLoader,
|
|
48
32
|
...rest
|
|
49
33
|
}) => {
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
throttle((
|
|
53
|
-
|
|
54
|
-
const currentScroll = event.target.scrollTop;
|
|
34
|
+
// Throttled scroll handler using Ant Design's onScroll
|
|
35
|
+
const onScroll = useCallback(
|
|
36
|
+
throttle(({ target }) => {
|
|
37
|
+
if (!infinteScroll || showLoader) return;
|
|
55
38
|
|
|
56
|
-
|
|
39
|
+
const { scrollHeight, scrollTop, clientHeight } = target;
|
|
40
|
+
const maxScroll = scrollHeight - clientHeight;
|
|
41
|
+
|
|
42
|
+
if (scrollTop >= maxScroll - 10) {
|
|
57
43
|
const offsetLimit = { ...offset_limit };
|
|
58
44
|
offsetLimit.offset += offsetLimit.limit;
|
|
59
45
|
setPagination?.(offsetLimit);
|
|
60
46
|
}
|
|
61
47
|
}, 50),
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const addScrollEventListener = useCallback(() => {
|
|
65
|
-
const listTable = document.querySelector(`#${id} div.ant-table-body`);
|
|
66
|
-
if (listTable) {
|
|
67
|
-
listTable.addEventListener('scroll', onScrollThrottle);
|
|
68
|
-
}
|
|
69
|
-
}, [id, onScrollThrottle]);
|
|
70
|
-
|
|
71
|
-
const callSetPaginationIfNotOverflow = useCallback(() => {
|
|
72
|
-
const yscrollheight = scroll?.y || 0;
|
|
73
|
-
const listTable = document.querySelector(`#${id} div.ant-table-body`);
|
|
74
|
-
let isOverflow = false;
|
|
75
|
-
|
|
76
|
-
if (yscrollheight && yscrollheight < listTable?.scrollHeight) {
|
|
77
|
-
isOverflow = true;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (!isOverflow && setPagination && dataSource?.length > 0) {
|
|
81
|
-
setPaginationCalled.current = true;
|
|
82
|
-
const offsetLimit = { ...offset_limit };
|
|
83
|
-
offsetLimit.offset += offsetLimit.limit;
|
|
84
|
-
setPagination(offsetLimit);
|
|
85
|
-
}
|
|
86
|
-
}, [id, scroll?.y, setPagination, dataSource, offset_limit]);
|
|
87
|
-
|
|
88
|
-
useEffect(() => {
|
|
89
|
-
const limit = offset_limit?.limit || 10;
|
|
90
|
-
if (infinteScroll) {
|
|
91
|
-
addScrollEventListener();
|
|
92
|
-
if (dataSource?.length >= limit) {
|
|
93
|
-
callSetPaginationIfNotOverflow();
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return () => {
|
|
98
|
-
const listTable = document.querySelector(`#${id} div.ant-table-body`);
|
|
99
|
-
if (listTable) {
|
|
100
|
-
listTable.removeEventListener('scroll', onScrollThrottle);
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
}, [
|
|
104
|
-
infinteScroll,
|
|
105
|
-
dataSource,
|
|
106
|
-
offset_limit,
|
|
107
|
-
addScrollEventListener,
|
|
108
|
-
callSetPaginationIfNotOverflow,
|
|
109
|
-
id,
|
|
110
|
-
onScrollThrottle,
|
|
111
|
-
]);
|
|
112
|
-
|
|
113
|
-
useEffect(() => {
|
|
114
|
-
const limit = offset_limit?.limit || 10;
|
|
115
|
-
if (
|
|
116
|
-
!setPaginationCalled.current &&
|
|
117
|
-
infinteScroll &&
|
|
118
|
-
dataSource?.length >= limit
|
|
119
|
-
) {
|
|
120
|
-
callSetPaginationIfNotOverflow();
|
|
121
|
-
}
|
|
122
|
-
}, [infinteScroll, dataSource, offset_limit, callSetPaginationIfNotOverflow]);
|
|
48
|
+
[infinteScroll, showLoader, offset_limit, setPagination],
|
|
49
|
+
);
|
|
123
50
|
|
|
124
51
|
return (
|
|
125
52
|
<StyledTable
|
|
126
53
|
{...rest}
|
|
127
54
|
id={id}
|
|
128
55
|
dataSource={dataSource}
|
|
129
|
-
scroll={scroll}
|
|
56
|
+
scroll={{ ...scroll, y: scroll?.y || 400 }}
|
|
130
57
|
pagination={infinteScroll ? false : pagination}
|
|
131
|
-
className={classNames('cap-table-v2', className
|
|
132
|
-
|
|
133
|
-
}
|
|
58
|
+
className={classNames('cap-table-v2', className)}
|
|
59
|
+
loading={showLoader}
|
|
60
|
+
virtual={infinteScroll}
|
|
61
|
+
onScroll={onScroll}
|
|
134
62
|
/>
|
|
135
63
|
);
|
|
136
64
|
};
|
|
@@ -11,7 +11,7 @@ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t =
|
|
|
11
11
|
/**
|
|
12
12
|
* CapTable - Migrated to Ant Design v5
|
|
13
13
|
*/
|
|
14
|
-
import React, {
|
|
14
|
+
import React, { useCallback } from 'react';
|
|
15
15
|
import PropTypes from 'prop-types';
|
|
16
16
|
import { throttle } from 'lodash';
|
|
17
17
|
import { Table } from 'antd';
|
|
@@ -22,9 +22,7 @@ import LocaleHoc from '../LocaleHoc';
|
|
|
22
22
|
var StyledTable = styled(Table).withConfig({
|
|
23
23
|
displayName: "StyledTable",
|
|
24
24
|
componentId: "sc-o01z1q-0"
|
|
25
|
-
})(["&.cap-table-v2{.ant-table{border:1px solid ", ";}}
|
|
26
|
-
return props.loadMoreData;
|
|
27
|
-
}, CAP_G07);
|
|
25
|
+
})(["&.cap-table-v2{.ant-table{border:1px solid ", ";}}"], CAP_G07);
|
|
28
26
|
var CapTable = function CapTable(_ref) {
|
|
29
27
|
var id = _ref.id,
|
|
30
28
|
className = _ref.className,
|
|
@@ -37,65 +35,31 @@ var CapTable = function CapTable(_ref) {
|
|
|
37
35
|
scroll = _ref.scroll,
|
|
38
36
|
showLoader = _ref.showLoader,
|
|
39
37
|
rest = _objectWithoutProperties(_ref, _excluded);
|
|
40
|
-
|
|
41
|
-
var
|
|
42
|
-
var
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
// Throttled scroll handler using Ant Design's onScroll
|
|
39
|
+
var onScroll = useCallback(throttle(function (_ref2) {
|
|
40
|
+
var target = _ref2.target;
|
|
41
|
+
if (!infinteScroll || showLoader) return;
|
|
42
|
+
var scrollHeight = target.scrollHeight,
|
|
43
|
+
scrollTop = target.scrollTop,
|
|
44
|
+
clientHeight = target.clientHeight;
|
|
45
|
+
var maxScroll = scrollHeight - clientHeight;
|
|
46
|
+
if (scrollTop >= maxScroll - 10) {
|
|
45
47
|
var offsetLimit = _objectSpread({}, offset_limit);
|
|
46
48
|
offsetLimit.offset += offsetLimit.limit;
|
|
47
49
|
setPagination === null || setPagination === void 0 ? void 0 : setPagination(offsetLimit);
|
|
48
50
|
}
|
|
49
|
-
}, 50))
|
|
50
|
-
var addScrollEventListener = useCallback(function () {
|
|
51
|
-
var listTable = document.querySelector("#".concat(id, " div.ant-table-body"));
|
|
52
|
-
if (listTable) {
|
|
53
|
-
listTable.addEventListener('scroll', onScrollThrottle);
|
|
54
|
-
}
|
|
55
|
-
}, [id, onScrollThrottle]);
|
|
56
|
-
var callSetPaginationIfNotOverflow = useCallback(function () {
|
|
57
|
-
var yscrollheight = (scroll === null || scroll === void 0 ? void 0 : scroll.y) || 0;
|
|
58
|
-
var listTable = document.querySelector("#".concat(id, " div.ant-table-body"));
|
|
59
|
-
var isOverflow = false;
|
|
60
|
-
if (yscrollheight && yscrollheight < (listTable === null || listTable === void 0 ? void 0 : listTable.scrollHeight)) {
|
|
61
|
-
isOverflow = true;
|
|
62
|
-
}
|
|
63
|
-
if (!isOverflow && setPagination && (dataSource === null || dataSource === void 0 ? void 0 : dataSource.length) > 0) {
|
|
64
|
-
setPaginationCalled.current = true;
|
|
65
|
-
var offsetLimit = _objectSpread({}, offset_limit);
|
|
66
|
-
offsetLimit.offset += offsetLimit.limit;
|
|
67
|
-
setPagination(offsetLimit);
|
|
68
|
-
}
|
|
69
|
-
}, [id, scroll === null || scroll === void 0 ? void 0 : scroll.y, setPagination, dataSource, offset_limit]);
|
|
70
|
-
useEffect(function () {
|
|
71
|
-
var limit = (offset_limit === null || offset_limit === void 0 ? void 0 : offset_limit.limit) || 10;
|
|
72
|
-
if (infinteScroll) {
|
|
73
|
-
addScrollEventListener();
|
|
74
|
-
if ((dataSource === null || dataSource === void 0 ? void 0 : dataSource.length) >= limit) {
|
|
75
|
-
callSetPaginationIfNotOverflow();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return function () {
|
|
79
|
-
var listTable = document.querySelector("#".concat(id, " div.ant-table-body"));
|
|
80
|
-
if (listTable) {
|
|
81
|
-
listTable.removeEventListener('scroll', onScrollThrottle);
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
}, [infinteScroll, dataSource, offset_limit, addScrollEventListener, callSetPaginationIfNotOverflow, id, onScrollThrottle]);
|
|
85
|
-
useEffect(function () {
|
|
86
|
-
var limit = (offset_limit === null || offset_limit === void 0 ? void 0 : offset_limit.limit) || 10;
|
|
87
|
-
if (!setPaginationCalled.current && infinteScroll && (dataSource === null || dataSource === void 0 ? void 0 : dataSource.length) >= limit) {
|
|
88
|
-
callSetPaginationIfNotOverflow();
|
|
89
|
-
}
|
|
90
|
-
}, [infinteScroll, dataSource, offset_limit, callSetPaginationIfNotOverflow]);
|
|
51
|
+
}, 50), [infinteScroll, showLoader, offset_limit, setPagination]);
|
|
91
52
|
return /*#__PURE__*/React.createElement(StyledTable, _extends({}, rest, {
|
|
92
53
|
id: id,
|
|
93
54
|
dataSource: dataSource,
|
|
94
|
-
scroll: scroll,
|
|
55
|
+
scroll: _objectSpread(_objectSpread({}, scroll), {}, {
|
|
56
|
+
y: (scroll === null || scroll === void 0 ? void 0 : scroll.y) || 400
|
|
57
|
+
}),
|
|
95
58
|
pagination: infinteScroll ? false : pagination,
|
|
96
|
-
className: classNames('cap-table-v2', className,
|
|
97
|
-
|
|
98
|
-
|
|
59
|
+
className: classNames('cap-table-v2', className),
|
|
60
|
+
loading: showLoader,
|
|
61
|
+
virtual: infinteScroll,
|
|
62
|
+
onScroll: onScroll
|
|
99
63
|
}));
|
|
100
64
|
};
|
|
101
65
|
CapTable.propTypes = {
|