@lemon-fe/components 0.0.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.
- package/README.md +11 -0
- package/es/Actions/index.d.ts +25 -0
- package/es/Actions/index.js +164 -0
- package/es/Actions/index.less +82 -0
- package/es/BaseTable/BaseTableContext.d.ts +6 -0
- package/es/BaseTable/BaseTableContext.js +6 -0
- package/es/BaseTable/ResizeHeaderCell.d.ts +8 -0
- package/es/BaseTable/ResizeHeaderCell.js +115 -0
- package/es/BaseTable/Sort.d.ts +10 -0
- package/es/BaseTable/Sort.js +122 -0
- package/es/BaseTable/VirtualBody.d.ts +8 -0
- package/es/BaseTable/VirtualBody.js +165 -0
- package/es/BaseTable/index.d.ts +7 -0
- package/es/BaseTable/index.js +371 -0
- package/es/BaseTable/index.less +103 -0
- package/es/BaseTable/typings.d.ts +32 -0
- package/es/BaseTable/utils.d.ts +4 -0
- package/es/BaseTable/utils.js +26 -0
- package/es/DurationPicker/index.d.ts +26 -0
- package/es/DurationPicker/index.js +234 -0
- package/es/DurationPicker/index.less +63 -0
- package/es/EditableTable/EditableCell.d.ts +11 -0
- package/es/EditableTable/EditableCell.js +37 -0
- package/es/EditableTable/EditableTableFormItem.d.ts +6 -0
- package/es/EditableTable/EditableTableFormItem.js +49 -0
- package/es/EditableTable/Table.d.ts +7 -0
- package/es/EditableTable/Table.js +363 -0
- package/es/EditableTable/index.d.ts +9 -0
- package/es/EditableTable/index.js +8 -0
- package/es/EditableTable/index.less +19 -0
- package/es/EditableTable/typings.d.ts +86 -0
- package/es/EditableTable/util.d.ts +25 -0
- package/es/EditableTable/util.js +387 -0
- package/es/Filter/index.d.ts +7 -0
- package/es/Filter/index.js +469 -0
- package/es/Filter/index.less +77 -0
- package/es/Filter/typings.d.ts +27 -0
- package/es/FormLayout/index.d.ts +32 -0
- package/es/FormLayout/index.js +41 -0
- package/es/FormLayout/index.less +89 -0
- package/es/Icons/DarkSearch.d.ts +5 -0
- package/es/Icons/DarkSearch.js +38 -0
- package/es/Icons/Down.d.ts +5 -0
- package/es/Icons/Down.js +30 -0
- package/es/Icons/Empty.d.ts +2 -0
- package/es/Icons/Empty.js +267 -0
- package/es/Icons/Search.d.ts +5 -0
- package/es/Icons/Search.js +39 -0
- package/es/Icons/Tip.d.ts +6 -0
- package/es/Icons/Tip.js +169 -0
- package/es/Icons/index.d.ts +12 -0
- package/es/Icons/index.js +13 -0
- package/es/InputMaxLength/index.d.ts +14 -0
- package/es/InputMaxLength/index.js +92 -0
- package/es/InputMaxLength/index.less +8 -0
- package/es/Layout/index.d.ts +21 -0
- package/es/Layout/index.js +35 -0
- package/es/Layout/index.less +92 -0
- package/es/PageLoading/index.d.ts +5 -0
- package/es/PageLoading/index.js +15 -0
- package/es/PageLoading/index.less +10 -0
- package/es/Popup/index.d.ts +27 -0
- package/es/Popup/index.js +191 -0
- package/es/Popup/index.less +14 -0
- package/es/Section/index.d.ts +54 -0
- package/es/Section/index.js +111 -0
- package/es/Section/index.less +177 -0
- package/es/SiderTree/TreeNodeTitle.d.ts +9 -0
- package/es/SiderTree/TreeNodeTitle.js +124 -0
- package/es/SiderTree/index.d.ts +35 -0
- package/es/SiderTree/index.js +237 -0
- package/es/SiderTree/index.less +170 -0
- package/es/SiderTree/typings.d.ts +19 -0
- package/es/Table/index.d.ts +3 -0
- package/es/Table/index.js +224 -0
- package/es/Table/index.less +1 -0
- package/es/Table/typings.d.ts +26 -0
- package/es/Table/utils.d.ts +2 -0
- package/es/Table/utils.js +3 -0
- package/es/TipMark/index.d.ts +10 -0
- package/es/TipMark/index.js +45 -0
- package/es/TipMark/index.less +8 -0
- package/es/constants.d.ts +1 -0
- package/es/constants.js +1 -0
- package/es/index.d.ts +21 -0
- package/es/index.js +17 -0
- package/es/index.less +50 -0
- package/es/init.d.ts +3 -0
- package/es/init.js +100 -0
- package/es/theme.less +13 -0
- package/package.json +43 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
var _excluded = ["children"];
|
|
2
|
+
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
+
|
|
7
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
+
|
|
9
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
|
+
|
|
11
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
+
|
|
13
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
14
|
+
|
|
15
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
16
|
+
|
|
17
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
18
|
+
|
|
19
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
20
|
+
|
|
21
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
22
|
+
|
|
23
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
24
|
+
|
|
25
|
+
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
26
|
+
import { useThrottle } from '@lemon-fe/hooks';
|
|
27
|
+
import { get } from 'lodash';
|
|
28
|
+
import BaseTableContext from './BaseTableContext';
|
|
29
|
+
import { PREFIX_CLS } from '../constants';
|
|
30
|
+
export default function VirtualList(props) {
|
|
31
|
+
var children = props.children,
|
|
32
|
+
restProps = _objectWithoutProperties(props, _excluded);
|
|
33
|
+
|
|
34
|
+
var ref = useRef(null);
|
|
35
|
+
|
|
36
|
+
var _useContext = useContext(BaseTableContext),
|
|
37
|
+
scrollY = _useContext.scrollY,
|
|
38
|
+
_useContext$rowHeight = _useContext.rowHeight,
|
|
39
|
+
rowHeight = _useContext$rowHeight === void 0 ? 37 : _useContext$rowHeight;
|
|
40
|
+
|
|
41
|
+
var _useState = useState(null),
|
|
42
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
43
|
+
range = _useState2[0],
|
|
44
|
+
setRange = _useState2[1];
|
|
45
|
+
|
|
46
|
+
var getRange = function getRange() {
|
|
47
|
+
var height = Number(scrollY);
|
|
48
|
+
|
|
49
|
+
if (isNaN(height)) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
var body = ref.current;
|
|
54
|
+
|
|
55
|
+
if (body === null) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var scroller = body.closest('.ant-table-body');
|
|
60
|
+
|
|
61
|
+
if (scroller === null) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
var pageSize = Math.ceil(height / rowHeight);
|
|
66
|
+
var offset = Math.round(scroller.scrollTop / rowHeight);
|
|
67
|
+
var start = offset - Math.floor(pageSize / 2);
|
|
68
|
+
|
|
69
|
+
if (start < 0) {
|
|
70
|
+
start = 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
var end = offset + pageSize + Math.ceil(pageSize / 2) - 1;
|
|
74
|
+
var bufferSpace = height * 0.3;
|
|
75
|
+
return {
|
|
76
|
+
start: start,
|
|
77
|
+
end: end,
|
|
78
|
+
isTop: scroller.scrollTop - body.offsetTop <= bufferSpace,
|
|
79
|
+
isBottom: body.offsetHeight + body.offsetTop - (scroller.scrollTop + height) <= bufferSpace
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
var handleScroll = useThrottle(function () {
|
|
84
|
+
var mRange = getRange();
|
|
85
|
+
|
|
86
|
+
if (mRange === null) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
var isTop = mRange.isTop,
|
|
91
|
+
isBottom = mRange.isBottom;
|
|
92
|
+
|
|
93
|
+
if (!isTop && !isBottom) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
setRange(mRange);
|
|
98
|
+
}, 300, {
|
|
99
|
+
trailing: true
|
|
100
|
+
});
|
|
101
|
+
useEffect(function () {
|
|
102
|
+
setRange(getRange());
|
|
103
|
+
}, [get(children, ['1', 'length']), rowHeight, scrollY]);
|
|
104
|
+
var render = useMemo(function () {
|
|
105
|
+
var _children = _slicedToArray(children, 2),
|
|
106
|
+
measureRow = _children[0],
|
|
107
|
+
rows = _children[1];
|
|
108
|
+
|
|
109
|
+
if (!Array.isArray(rows)) {
|
|
110
|
+
return [children, 0, 0];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (range === null) {
|
|
114
|
+
return [measureRow, 0, 0];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
var list = [];
|
|
118
|
+
var max = rows.length - 1;
|
|
119
|
+
var start = range.start,
|
|
120
|
+
end = range.end;
|
|
121
|
+
|
|
122
|
+
if (end > max) {
|
|
123
|
+
end = max;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
for (var i = start; i <= end; i += 1) {
|
|
127
|
+
list.push(rows[i]);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return [[measureRow, list], start * rowHeight, (max - end) * rowHeight];
|
|
131
|
+
}, [children, range]);
|
|
132
|
+
useEffect(function () {
|
|
133
|
+
var _ref$current;
|
|
134
|
+
|
|
135
|
+
if (ref.current === null) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
var tableBody = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.closest('.ant-table-body');
|
|
140
|
+
|
|
141
|
+
if (tableBody === null) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
tableBody.addEventListener('scroll', handleScroll);
|
|
146
|
+
return function () {
|
|
147
|
+
tableBody.removeEventListener('scroll', handleScroll);
|
|
148
|
+
};
|
|
149
|
+
}, []);
|
|
150
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("tbody", {
|
|
151
|
+
className: "".concat(PREFIX_CLS, "-table-append-before"),
|
|
152
|
+
style: {
|
|
153
|
+
display: 'block',
|
|
154
|
+
height: render[1]
|
|
155
|
+
}
|
|
156
|
+
}), /*#__PURE__*/React.createElement("tbody", _objectSpread(_objectSpread({}, restProps), {}, {
|
|
157
|
+
ref: ref
|
|
158
|
+
}), render[0]), /*#__PURE__*/React.createElement("tbody", {
|
|
159
|
+
className: "".concat(PREFIX_CLS, "-table-append-after"),
|
|
160
|
+
style: {
|
|
161
|
+
display: 'block',
|
|
162
|
+
height: render[2]
|
|
163
|
+
}
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { BaseTableProps as Props } from './typings';
|
|
3
|
+
declare function BaseTable<T extends Record<string, any>>(props: Props<T>): JSX.Element;
|
|
4
|
+
declare namespace BaseTable {
|
|
5
|
+
var Summary: typeof import("rc-table/lib/Footer/Summary").default;
|
|
6
|
+
}
|
|
7
|
+
export default BaseTable;
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
var _excluded = ["onWidthChange", "width", "fullTableRef"],
|
|
2
|
+
_excluded2 = ["id", "columns", "defaultColumnProps", "rowKey", "children", "summaryTitle", "summaryRecord", "dataSource", "onSortChange", "sort", "scroll", "virtual", "components", "pagination", "onChange", "rowHeight", "tableLayout"];
|
|
3
|
+
|
|
4
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
5
|
+
|
|
6
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
7
|
+
|
|
8
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
9
|
+
|
|
10
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
11
|
+
|
|
12
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
13
|
+
|
|
14
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
15
|
+
|
|
16
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
17
|
+
|
|
18
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
19
|
+
|
|
20
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
21
|
+
|
|
22
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
23
|
+
|
|
24
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
25
|
+
|
|
26
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
27
|
+
|
|
28
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
29
|
+
|
|
30
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
31
|
+
|
|
32
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
33
|
+
|
|
34
|
+
import React, { useMemo, useState, useEffect, useRef } from 'react';
|
|
35
|
+
import { Table as AntdTable } from 'antd';
|
|
36
|
+
import { get } from 'lodash';
|
|
37
|
+
import { useThrottle } from '@lemon-fe/hooks';
|
|
38
|
+
import { isColumnType, getColumnKey, randomStr } from './utils';
|
|
39
|
+
import ResizeHeaderCell from './ResizeHeaderCell';
|
|
40
|
+
import { PREFIX_CLS } from '../constants';
|
|
41
|
+
import VirtualList from './VirtualBody';
|
|
42
|
+
import BaseTableContext from './BaseTableContext';
|
|
43
|
+
|
|
44
|
+
function formatSummary(summary) {
|
|
45
|
+
if (!summary) {
|
|
46
|
+
return summary;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
var obj = _objectSpread({}, summary);
|
|
50
|
+
|
|
51
|
+
var pretty = new Intl.NumberFormat('en-US', {
|
|
52
|
+
minimumFractionDigits: 2,
|
|
53
|
+
maximumFractionDigits: 2
|
|
54
|
+
});
|
|
55
|
+
Object.keys(obj).forEach(function (key) {
|
|
56
|
+
if (obj.hasOwnProperty(key) && typeof obj[key] === 'number') {
|
|
57
|
+
obj[key] = pretty.format(obj[key]);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return obj;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function Th(props) {
|
|
64
|
+
var onWidthChange = props.onWidthChange,
|
|
65
|
+
width = props.width,
|
|
66
|
+
fullTableRef = props.fullTableRef,
|
|
67
|
+
restProps = _objectWithoutProperties(props, _excluded);
|
|
68
|
+
|
|
69
|
+
if (!width || !onWidthChange) {
|
|
70
|
+
return /*#__PURE__*/React.createElement("th", _objectSpread({}, restProps));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return /*#__PURE__*/React.createElement(ResizeHeaderCell, {
|
|
74
|
+
width: width,
|
|
75
|
+
onChange: onWidthChange,
|
|
76
|
+
fullTableRef: fullTableRef,
|
|
77
|
+
prefixCls: "".concat(PREFIX_CLS, "-table")
|
|
78
|
+
}, /*#__PURE__*/React.createElement("th", _objectSpread({}, restProps)));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function BaseTable(props) {
|
|
82
|
+
var id = props.id,
|
|
83
|
+
columns = props.columns,
|
|
84
|
+
defaultColumnProps = props.defaultColumnProps,
|
|
85
|
+
rowKey = props.rowKey,
|
|
86
|
+
children = props.children,
|
|
87
|
+
summaryTitle = props.summaryTitle,
|
|
88
|
+
summaryRecord = props.summaryRecord,
|
|
89
|
+
_props$dataSource = props.dataSource,
|
|
90
|
+
dataSource = _props$dataSource === void 0 ? [] : _props$dataSource,
|
|
91
|
+
onSortChange = props.onSortChange,
|
|
92
|
+
defaultSort = props.sort,
|
|
93
|
+
scroll = props.scroll,
|
|
94
|
+
virtual = props.virtual,
|
|
95
|
+
componentsProp = props.components,
|
|
96
|
+
paginationProp = props.pagination,
|
|
97
|
+
onChangeProp = props.onChange,
|
|
98
|
+
rowHeight = props.rowHeight,
|
|
99
|
+
_props$tableLayout = props.tableLayout,
|
|
100
|
+
tableLayout = _props$tableLayout === void 0 ? 'fixed' : _props$tableLayout,
|
|
101
|
+
restProps = _objectWithoutProperties(props, _excluded2);
|
|
102
|
+
|
|
103
|
+
var fullTableRef = useRef(null);
|
|
104
|
+
var tableID = useMemo(function () {
|
|
105
|
+
return id || randomStr();
|
|
106
|
+
}, [id]);
|
|
107
|
+
|
|
108
|
+
var _useState = useState(0),
|
|
109
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
110
|
+
scrollY = _useState2[0],
|
|
111
|
+
setScrollY = _useState2[1];
|
|
112
|
+
|
|
113
|
+
var _useState3 = useState(new Map()),
|
|
114
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
115
|
+
colsState = _useState4[0],
|
|
116
|
+
setColsState = _useState4[1];
|
|
117
|
+
|
|
118
|
+
useEffect(function () {
|
|
119
|
+
fullTableRef.current = document.getElementById(tableID);
|
|
120
|
+
}, [tableID]);
|
|
121
|
+
/** auto scroll y */
|
|
122
|
+
|
|
123
|
+
var calcScrollY = function calcScrollY() {
|
|
124
|
+
var table = fullTableRef.current;
|
|
125
|
+
|
|
126
|
+
if (table === null) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
var wrapper = table.closest('.ant-table-wrapper');
|
|
131
|
+
var tableBody = table.querySelector('.ant-table-body');
|
|
132
|
+
|
|
133
|
+
if (tableBody === null || wrapper === null) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
var parent = wrapper.parentElement;
|
|
138
|
+
|
|
139
|
+
if (parent === null) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
var style = getComputedStyle(parent);
|
|
144
|
+
var contentHeight = parent.offsetHeight - (parseFloat(style.getPropertyValue('padding-top')) || 0) - (parseFloat(style.getPropertyValue('padding-bottom')) || 0);
|
|
145
|
+
var nodes = [];
|
|
146
|
+
|
|
147
|
+
if (tableBody.previousElementSibling !== null) {
|
|
148
|
+
nodes.push(tableBody.previousElementSibling);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (tableBody.nextElementSibling !== null) {
|
|
152
|
+
nodes.push(tableBody.nextElementSibling);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (table.nextElementSibling !== null) {
|
|
156
|
+
nodes.push(table.nextElementSibling);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
contentHeight -= nodes.reduce(function (prev, dom) {
|
|
160
|
+
var cpStyle = window.getComputedStyle(dom);
|
|
161
|
+
var height = dom.offsetHeight + (parseFloat(cpStyle.getPropertyValue('margin-top')) || 0) + (parseFloat(cpStyle.getPropertyValue('margin-bottom')) || 0);
|
|
162
|
+
return prev + height;
|
|
163
|
+
}, 0);
|
|
164
|
+
return contentHeight;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
var changeScrollY = useThrottle(function () {
|
|
168
|
+
if ((scroll === null || scroll === void 0 ? void 0 : scroll.y) === true) {
|
|
169
|
+
var y = calcScrollY();
|
|
170
|
+
setScrollY(y || undefined);
|
|
171
|
+
} else {
|
|
172
|
+
setScrollY(scroll === null || scroll === void 0 ? void 0 : scroll.y);
|
|
173
|
+
}
|
|
174
|
+
}, 80, {
|
|
175
|
+
trailing: true
|
|
176
|
+
});
|
|
177
|
+
useEffect(function () {
|
|
178
|
+
changeScrollY();
|
|
179
|
+
}, [scroll === null || scroll === void 0 ? void 0 : scroll.y, dataSource]);
|
|
180
|
+
useEffect(function () {
|
|
181
|
+
window.addEventListener('resize', changeScrollY);
|
|
182
|
+
return function () {
|
|
183
|
+
window.removeEventListener('resize', changeScrollY);
|
|
184
|
+
};
|
|
185
|
+
}, []);
|
|
186
|
+
|
|
187
|
+
var handleChange = function handleChange() {
|
|
188
|
+
changeScrollY();
|
|
189
|
+
|
|
190
|
+
if (onChangeProp) {
|
|
191
|
+
onChangeProp.apply(void 0, arguments);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
/** resizable column */
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
var _useMemo = useMemo(function () {
|
|
198
|
+
var flattenCols = [];
|
|
199
|
+
var isFixedLayout = tableLayout === 'fixed';
|
|
200
|
+
var hasAutoWidthCol = false;
|
|
201
|
+
|
|
202
|
+
var traverse = function traverse(cols) {
|
|
203
|
+
var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
204
|
+
return cols.map(function (col, index) {
|
|
205
|
+
var currPath = [].concat(_toConsumableArray(path), [index]);
|
|
206
|
+
|
|
207
|
+
if (isColumnType(col)) {
|
|
208
|
+
var colKey = getColumnKey(col);
|
|
209
|
+
|
|
210
|
+
var nextCol = _objectSpread(_objectSpread({}, defaultColumnProps), col);
|
|
211
|
+
|
|
212
|
+
var colState = colsState.get(colKey);
|
|
213
|
+
|
|
214
|
+
if (colState && colState.width !== undefined) {
|
|
215
|
+
nextCol.width = colState.width;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (isFixedLayout && !!nextCol.title) {
|
|
219
|
+
if (nextCol.width === undefined) {
|
|
220
|
+
nextCol.width = 160;
|
|
221
|
+
} else if (nextCol.width === 'auto') {
|
|
222
|
+
nextCol.width = undefined;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
if (!nextCol.width) {
|
|
227
|
+
hasAutoWidthCol = true;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
if (nextCol.width && !nextCol.fixed) {
|
|
231
|
+
if (nextCol.ellipsis === undefined) {
|
|
232
|
+
nextCol.ellipsis = true;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
nextCol.onHeaderCell = function () {
|
|
236
|
+
return {
|
|
237
|
+
width: nextCol.width,
|
|
238
|
+
fullTableRef: fullTableRef,
|
|
239
|
+
onWidthChange: function onWidthChange(size) {
|
|
240
|
+
setColsState(function (prev) {
|
|
241
|
+
var prevItem = prev.get(colKey);
|
|
242
|
+
|
|
243
|
+
if (prevItem !== undefined && prevItem.width === size) {
|
|
244
|
+
return prev;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
prevItem = _objectSpread(_objectSpread({}, prevItem), {}, {
|
|
248
|
+
width: size
|
|
249
|
+
});
|
|
250
|
+
var next = new Map(prev);
|
|
251
|
+
next.set(colKey, prevItem);
|
|
252
|
+
return next;
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
flattenCols.push(nextCol);
|
|
260
|
+
return nextCol;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return _objectSpread(_objectSpread(_objectSpread({}, defaultColumnProps), col), {}, {
|
|
264
|
+
children: traverse(col.children, currPath)
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
var newColumns = traverse(columns);
|
|
270
|
+
|
|
271
|
+
if (isFixedLayout && !hasAutoWidthCol) {
|
|
272
|
+
newColumns.push({
|
|
273
|
+
title: ''
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return [newColumns, flattenCols];
|
|
278
|
+
}, [columns, colsState, tableLayout]),
|
|
279
|
+
_useMemo2 = _slicedToArray(_useMemo, 2),
|
|
280
|
+
formatedColumns = _useMemo2[0],
|
|
281
|
+
flattenColumns = _useMemo2[1];
|
|
282
|
+
/** virtualize scroll */
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
var _useMemo3 = useMemo(function () {
|
|
286
|
+
return {
|
|
287
|
+
components: _objectSpread({
|
|
288
|
+
header: {
|
|
289
|
+
cell: Th
|
|
290
|
+
},
|
|
291
|
+
body: virtual ? {
|
|
292
|
+
wrapper: VirtualList
|
|
293
|
+
} : undefined
|
|
294
|
+
}, componentsProp)
|
|
295
|
+
};
|
|
296
|
+
}, [virtual]),
|
|
297
|
+
components = _useMemo3.components;
|
|
298
|
+
/** summary row */
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
var summary = useMemo(function () {
|
|
302
|
+
var Summary = AntdTable.Summary;
|
|
303
|
+
|
|
304
|
+
if (!summaryRecord) {
|
|
305
|
+
return undefined;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
return function () {
|
|
309
|
+
var _props$rowSelection;
|
|
310
|
+
|
|
311
|
+
var data = formatSummary(summaryRecord);
|
|
312
|
+
var offset = 0;
|
|
313
|
+
return /*#__PURE__*/React.createElement(Summary, {
|
|
314
|
+
fixed: true
|
|
315
|
+
}, /*#__PURE__*/React.createElement(Summary.Row, null, ((_props$rowSelection = props.rowSelection) === null || _props$rowSelection === void 0 ? void 0 : _props$rowSelection.type) !== undefined && /*#__PURE__*/React.createElement(Summary.Cell, {
|
|
316
|
+
index: offset++
|
|
317
|
+
}), flattenColumns.map(function (item, index) {
|
|
318
|
+
var value;
|
|
319
|
+
|
|
320
|
+
if (index === 0) {
|
|
321
|
+
value = summaryTitle;
|
|
322
|
+
} else if (item.dataIndex) {
|
|
323
|
+
value = get(data, item.dataIndex);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return /*#__PURE__*/React.createElement(Summary.Cell, {
|
|
327
|
+
index: index + offset,
|
|
328
|
+
key: getColumnKey(item) || index,
|
|
329
|
+
align: item.align
|
|
330
|
+
}, value);
|
|
331
|
+
})));
|
|
332
|
+
};
|
|
333
|
+
}, [flattenColumns, summaryRecord, summaryTitle]);
|
|
334
|
+
var ctx = useMemo(function () {
|
|
335
|
+
return {
|
|
336
|
+
scrollY: scrollY,
|
|
337
|
+
rowHeight: rowHeight
|
|
338
|
+
};
|
|
339
|
+
}, [scrollY, rowHeight]);
|
|
340
|
+
return /*#__PURE__*/React.createElement(BaseTableContext.Provider, {
|
|
341
|
+
value: ctx
|
|
342
|
+
}, /*#__PURE__*/React.createElement(AntdTable, _objectSpread(_objectSpread({
|
|
343
|
+
size: "small",
|
|
344
|
+
id: tableID,
|
|
345
|
+
columns: formatedColumns,
|
|
346
|
+
dataSource: dataSource,
|
|
347
|
+
rowKey: rowKey,
|
|
348
|
+
summary: summary,
|
|
349
|
+
scroll: {
|
|
350
|
+
x: (scroll === null || scroll === void 0 ? void 0 : scroll.x) || '100%',
|
|
351
|
+
y: scrollY
|
|
352
|
+
},
|
|
353
|
+
components: components,
|
|
354
|
+
onChange: handleChange,
|
|
355
|
+
tableLayout: tableLayout
|
|
356
|
+
}, restProps), {}, {
|
|
357
|
+
pagination: paginationProp !== false ? _objectSpread({
|
|
358
|
+
size: 'small',
|
|
359
|
+
pageSizeOptions: ['10', '20', '50', '100'],
|
|
360
|
+
showSizeChanger: true,
|
|
361
|
+
showQuickJumper: true,
|
|
362
|
+
showTotal: function showTotal(val) {
|
|
363
|
+
return "\u5171".concat(val, "\u6761");
|
|
364
|
+
},
|
|
365
|
+
defaultPageSize: 20
|
|
366
|
+
}, paginationProp) : false
|
|
367
|
+
})));
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
BaseTable.Summary = AntdTable.Summary;
|
|
371
|
+
export default BaseTable;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
@tablePrefixCls: lemon-table;
|
|
2
|
+
@font-size-base: 14px;
|
|
3
|
+
@resize-indicator-color: #333;
|
|
4
|
+
|
|
5
|
+
.ant-table-thead > tr > th {
|
|
6
|
+
border-bottom: none;
|
|
7
|
+
|
|
8
|
+
&::before {
|
|
9
|
+
display: none;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.ant-table-body {
|
|
14
|
+
scrollbar-width: thin;
|
|
15
|
+
|
|
16
|
+
&::-webkit-scrollbar {
|
|
17
|
+
width: 8px;
|
|
18
|
+
height: 8px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
&::-webkit-scrollbar-thumb {
|
|
22
|
+
background-color: #ddd;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&::-webkit-scrollbar-track {
|
|
26
|
+
background-color: #fff;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.ant-table-cell {
|
|
31
|
+
.ant-checkbox-checked .ant-checkbox-inner::after {
|
|
32
|
+
transition: none !important;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.ant-checkbox-inner {
|
|
36
|
+
transition: none !important;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.ant-checkbox-checked::after {
|
|
40
|
+
animation: none !important;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.ant-table-pagination.ant-pagination {
|
|
45
|
+
margin-bottom: 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.@{tablePrefixCls} {
|
|
49
|
+
position: relative;
|
|
50
|
+
box-sizing: border-box;
|
|
51
|
+
color: @text-color;
|
|
52
|
+
font-size: @font-size-base;
|
|
53
|
+
|
|
54
|
+
&-resizable-handle {
|
|
55
|
+
position: absolute;
|
|
56
|
+
top: 50%;
|
|
57
|
+
right: -5px;
|
|
58
|
+
z-index: 1;
|
|
59
|
+
box-sizing: border-box;
|
|
60
|
+
width: 11px;
|
|
61
|
+
height: 12px;
|
|
62
|
+
margin-top: -6px;
|
|
63
|
+
cursor: col-resize;
|
|
64
|
+
|
|
65
|
+
& > div {
|
|
66
|
+
width: 1px;
|
|
67
|
+
height: 100%;
|
|
68
|
+
margin: 0 auto;
|
|
69
|
+
background-color: #bbb;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
&-resizable-indicator {
|
|
74
|
+
position: absolute;
|
|
75
|
+
top: 0;
|
|
76
|
+
z-index: 20;
|
|
77
|
+
width: 1px;
|
|
78
|
+
background-color: @resize-indicator-color;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
&-resizing-col thead th {
|
|
82
|
+
user-select: none;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
&-sort {
|
|
86
|
+
display: flex;
|
|
87
|
+
align-items: center;
|
|
88
|
+
cursor: pointer;
|
|
89
|
+
|
|
90
|
+
&-title {
|
|
91
|
+
margin-right: 10px;
|
|
92
|
+
overflow: hidden;
|
|
93
|
+
text-overflow: ellipsis;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
&-number {
|
|
97
|
+
margin-left: 4px;
|
|
98
|
+
color: #999;
|
|
99
|
+
font-weight: normal;
|
|
100
|
+
font-size: 12px;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ReactText } from 'react';
|
|
2
|
+
import { TableProps, TableColumnType, TableColumnGroupType, TableColumnsType } from 'antd';
|
|
3
|
+
|
|
4
|
+
export type ColumnType<T> = TableColumnType<T>;
|
|
5
|
+
|
|
6
|
+
export type ColumnGroupType<T> = TableColumnGroupType<T>;
|
|
7
|
+
|
|
8
|
+
export type ColumnsType<T> = TableColumnsType<T>;
|
|
9
|
+
|
|
10
|
+
export interface BaseTableProps<T> extends Omit<TableProps<T>, 'columns' | 'scroll'> {
|
|
11
|
+
defaultColumnProps?: Partial<ColumnType<T>>;
|
|
12
|
+
/**
|
|
13
|
+
* @description 当width为auto时为自适应列宽,默认为160
|
|
14
|
+
*/
|
|
15
|
+
columns: ColumnsType<T>;
|
|
16
|
+
summaryRecord?: any;
|
|
17
|
+
summaryTitle?: string;
|
|
18
|
+
sort?: [ReactText, string][];
|
|
19
|
+
onSortChange?: (sort: [ReactText, string][]) => void;
|
|
20
|
+
/**
|
|
21
|
+
* @description 行高 默认为37,如果表格行有边界,需要包含边界
|
|
22
|
+
*/
|
|
23
|
+
rowHeight?: number;
|
|
24
|
+
/**
|
|
25
|
+
* @description 虚拟列表 行高必须一致 并且需要指定rowHeight
|
|
26
|
+
*/
|
|
27
|
+
virtual?: boolean;
|
|
28
|
+
scroll?: {
|
|
29
|
+
x?: number | string | true;
|
|
30
|
+
y?: number | string | true;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ColumnType, ColumnGroupType } from './typings';
|
|
2
|
+
export declare function isColumnType<T>(col: ColumnGroupType<T> | ColumnType<T>): col is ColumnType<T>;
|
|
3
|
+
export declare function getColumnKey(col: ColumnType<any>): string | number;
|
|
4
|
+
export declare function randomStr(): string;
|