@kdcloudjs/table 1.1.6 → 1.2.0-canary.10
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/dist/@kdcloudjs/table.css +1 -1
- package/dist/@kdcloudjs/table.js +835 -187
- package/dist/@kdcloudjs/table.js.map +1 -1
- package/dist/@kdcloudjs/table.min.css +1 -1
- package/dist/@kdcloudjs/table.min.js +8 -8
- package/dist/@kdcloudjs/table.min.js.map +1 -1
- package/es/locale/locale.d.ts +8 -4
- package/es/locale/zh-CN.d.ts +8 -4
- package/es/locale/zh-CN.js +10 -4
- package/es/table/base/helpers/TableDOMUtils.js +17 -14
- package/es/table/base/styles.d.ts +10 -0
- package/es/table/base/styles.js +12 -2
- package/es/table/base/table.js +38 -7
- package/es/table/common-views.js +3 -1
- package/es/table/interfaces.d.ts +5 -0
- package/es/table/pipeline/features/autoFill.js +7 -3
- package/es/table/pipeline/features/columnFilter.js +17 -5
- package/es/table/pipeline/features/columnResizeWidth.js +3 -1
- package/es/table/pipeline/features/filter/DefaultFilterContent.d.ts +1 -1
- package/es/table/pipeline/features/filter/DefaultFilterContent.js +11 -5
- package/es/table/pipeline/features/filter/Filter.d.ts +4 -1
- package/es/table/pipeline/features/filter/Filter.js +4 -2
- package/es/table/pipeline/features/index.d.ts +1 -0
- package/es/table/pipeline/features/index.js +2 -1
- package/es/table/pipeline/features/multiSelect.js +31 -12
- package/es/table/pipeline/features/rangeSelection.d.ts +22 -1
- package/es/table/pipeline/features/rangeSelection.js +274 -100
- package/es/table/pipeline/features/rowDrag.d.ts +28 -0
- package/es/table/pipeline/features/rowDrag.js +325 -0
- package/es/table/pipeline/features/sort.js +22 -3
- package/lib/locale/locale.d.ts +8 -4
- package/lib/locale/zh-CN.d.ts +8 -4
- package/lib/locale/zh-CN.js +10 -4
- package/lib/table/base/helpers/TableDOMUtils.js +17 -14
- package/lib/table/base/styles.d.ts +10 -0
- package/lib/table/base/styles.js +12 -2
- package/lib/table/base/table.js +38 -7
- package/lib/table/common-views.js +3 -1
- package/lib/table/interfaces.d.ts +5 -0
- package/lib/table/pipeline/features/autoFill.js +7 -3
- package/lib/table/pipeline/features/columnFilter.js +18 -6
- package/lib/table/pipeline/features/columnResizeWidth.js +3 -1
- package/lib/table/pipeline/features/filter/DefaultFilterContent.d.ts +1 -1
- package/lib/table/pipeline/features/filter/DefaultFilterContent.js +11 -5
- package/lib/table/pipeline/features/filter/Filter.d.ts +4 -1
- package/lib/table/pipeline/features/filter/Filter.js +4 -2
- package/lib/table/pipeline/features/index.d.ts +1 -0
- package/lib/table/pipeline/features/index.js +9 -1
- package/lib/table/pipeline/features/multiSelect.js +33 -12
- package/lib/table/pipeline/features/rangeSelection.d.ts +22 -1
- package/lib/table/pipeline/features/rangeSelection.js +282 -104
- package/lib/table/pipeline/features/rowDrag.d.ts +28 -0
- package/lib/table/pipeline/features/rowDrag.js +347 -0
- package/lib/table/pipeline/features/sort.js +22 -3
- package/package.json +3 -3
|
@@ -6,6 +6,9 @@ import React from 'react';
|
|
|
6
6
|
import { internals } from '../../internals';
|
|
7
7
|
import { always, arrayUtils } from '../../utils/others';
|
|
8
8
|
import { collectNodes, mergeCellProps } from '../../utils';
|
|
9
|
+
var fullRowsSetKey = 'fullRowsSetKey';
|
|
10
|
+
var allEnableKeys = 'allEnableKeys';
|
|
11
|
+
var selectValueSetKey = 'selectValueSetKey';
|
|
9
12
|
export function multiSelect() {
|
|
10
13
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
11
14
|
return function multiSelectStep(pipeline) {
|
|
@@ -36,10 +39,9 @@ export function multiSelect() {
|
|
|
36
39
|
action: action
|
|
37
40
|
});
|
|
38
41
|
};
|
|
39
|
-
|
|
40
|
-
var dataSource = pipeline.getDataSource();
|
|
41
42
|
/** dataSource 中包含的所有 keys */
|
|
42
43
|
|
|
44
|
+
|
|
43
45
|
var fullKeySet = new _Set();
|
|
44
46
|
/** 所有有效的 keys(disable 状态为 false) */
|
|
45
47
|
|
|
@@ -48,7 +50,7 @@ export function multiSelect() {
|
|
|
48
50
|
var isAllChecked = set.size !== 0; // 当前不存在选中则默认为false
|
|
49
51
|
|
|
50
52
|
var isAnyChecked = false;
|
|
51
|
-
var flatDataSource = collectNodes(
|
|
53
|
+
var flatDataSource = collectNodes(pipeline.getDataSource());
|
|
52
54
|
flatDataSource.forEach(function (row, rowIndex) {
|
|
53
55
|
var rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
54
56
|
fullKeySet.add(rowKey); // 在 allKeys 中排除被禁用的 key
|
|
@@ -76,6 +78,8 @@ export function multiSelect() {
|
|
|
76
78
|
checked: isAllChecked,
|
|
77
79
|
indeterminate: !isAllChecked && isAnyChecked,
|
|
78
80
|
onChange: function onChange(_) {
|
|
81
|
+
var allKeys = pipeline.getFeatureOptions(allEnableKeys);
|
|
82
|
+
|
|
79
83
|
if (isAllChecked) {
|
|
80
84
|
_onChange(arrayUtils.diff(value, allKeys), '', allKeys, 'uncheck-all');
|
|
81
85
|
} else {
|
|
@@ -96,9 +100,11 @@ export function multiSelect() {
|
|
|
96
100
|
var rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
97
101
|
var checkboxCellProps = {};
|
|
98
102
|
var preCellProps = (_b = (_a = opts.checkboxColumn) === null || _a === void 0 ? void 0 : _a.getCellProps) === null || _b === void 0 ? void 0 : _b.call(_a, value, row, rowIndex);
|
|
103
|
+
var fullRowsSet = pipeline.getFeatureOptions(fullRowsSetKey) || new _Set();
|
|
104
|
+
var selectValueSet = pipeline.getFeatureOptions(selectValueSetKey) || new _Set();
|
|
99
105
|
|
|
100
|
-
if (
|
|
101
|
-
var prevChecked =
|
|
106
|
+
if (fullRowsSet.has(rowKey) && clickArea === 'cell') {
|
|
107
|
+
var prevChecked = selectValueSet.has(rowKey);
|
|
102
108
|
var disabled = isDisabled(row, rowIndex);
|
|
103
109
|
checkboxCellProps = {
|
|
104
110
|
style: {
|
|
@@ -122,7 +128,8 @@ export function multiSelect() {
|
|
|
122
128
|
}
|
|
123
129
|
|
|
124
130
|
var key = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
125
|
-
var
|
|
131
|
+
var selectValueSet = pipeline.getFeatureOptions(selectValueSetKey) || new _Set();
|
|
132
|
+
var checked = selectValueSet.has(key);
|
|
126
133
|
return /*#__PURE__*/React.createElement(Checkbox, {
|
|
127
134
|
checked: checked,
|
|
128
135
|
disabled: isDisabled(row, rowIndex),
|
|
@@ -161,8 +168,9 @@ export function multiSelect() {
|
|
|
161
168
|
|
|
162
169
|
pipeline.appendRowPropsGetter(function (row, rowIndex) {
|
|
163
170
|
var rowKey = internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
171
|
+
var fullRowsSet = pipeline.getFeatureOptions(fullRowsSetKey) || new _Set();
|
|
164
172
|
|
|
165
|
-
if (!
|
|
173
|
+
if (!fullRowsSet.has(rowKey)) {
|
|
166
174
|
// rowKey 不在 fullKeySet 中说明这一行是在 multiSelect 之后才生成的,multiSelect 不对之后生成的行进行处理
|
|
167
175
|
return;
|
|
168
176
|
}
|
|
@@ -170,7 +178,8 @@ export function multiSelect() {
|
|
|
170
178
|
var style = {};
|
|
171
179
|
var className;
|
|
172
180
|
var onClick;
|
|
173
|
-
var
|
|
181
|
+
var selectValueSet = pipeline.getFeatureOptions(selectValueSetKey) || new _Set();
|
|
182
|
+
var checked = selectValueSet.has(rowKey);
|
|
174
183
|
|
|
175
184
|
if (opts.highlightRowWhenSelected && checked) {
|
|
176
185
|
className = 'highlight';
|
|
@@ -197,22 +206,32 @@ export function multiSelect() {
|
|
|
197
206
|
style: style,
|
|
198
207
|
onClick: onClick
|
|
199
208
|
};
|
|
200
|
-
});
|
|
209
|
+
}); // 只保留一份到pipeline, 避免行数据过多时内容被握住
|
|
210
|
+
|
|
211
|
+
pipeline.setFeatureOptions(fullRowsSetKey, fullKeySet);
|
|
212
|
+
pipeline.setFeatureOptions(allEnableKeys, allKeys);
|
|
213
|
+
pipeline.setFeatureOptions(selectValueSetKey, set);
|
|
214
|
+
fullKeySet = null;
|
|
215
|
+
allKeys = null;
|
|
216
|
+
set = null;
|
|
201
217
|
return pipeline;
|
|
202
218
|
|
|
203
219
|
function onCheckboxChange(prevChecked, key, batch) {
|
|
204
220
|
var batchKeys = [key];
|
|
205
221
|
|
|
206
222
|
if (batch && lastKey) {
|
|
207
|
-
var
|
|
208
|
-
|
|
223
|
+
var _allKeys = pipeline.getFeatureOptions(allEnableKeys);
|
|
224
|
+
|
|
225
|
+
var lastIdx = _allKeys.indexOf(lastKey);
|
|
226
|
+
|
|
227
|
+
var cntIdx = _allKeys.indexOf(key);
|
|
209
228
|
|
|
210
229
|
var _ref = lastIdx < cntIdx ? [lastIdx, cntIdx] : [cntIdx, lastIdx],
|
|
211
230
|
_ref2 = _slicedToArray(_ref, 2),
|
|
212
231
|
start = _ref2[0],
|
|
213
232
|
end = _ref2[1];
|
|
214
233
|
|
|
215
|
-
batchKeys = _sliceInstanceProperty(
|
|
234
|
+
batchKeys = _sliceInstanceProperty(_allKeys).call(_allKeys, start, end + 1);
|
|
216
235
|
}
|
|
217
236
|
|
|
218
237
|
if (prevChecked) {
|
|
@@ -1,10 +1,31 @@
|
|
|
1
1
|
import { TablePipeline } from '../pipeline';
|
|
2
|
+
import { ArtColumn } from '../../interfaces';
|
|
2
3
|
export interface RangeSelectionFeatureOptions {
|
|
3
4
|
/** 范围选中回调函数 */
|
|
4
|
-
rangeSelectedChange?(
|
|
5
|
+
rangeSelectedChange?(cellRanges: CellRange[], isFinished: boolean): void;
|
|
5
6
|
/** 是否阻止keydown的默认行为 */
|
|
6
7
|
preventkDefaultOfKeyDownEvent?: boolean;
|
|
8
|
+
/** 是否禁止多范围框选 */
|
|
9
|
+
suppressMultiRangeSelection?: boolean;
|
|
10
|
+
}
|
|
11
|
+
interface FooterRowRange {
|
|
12
|
+
startRow: number;
|
|
13
|
+
endRow: number;
|
|
14
|
+
}
|
|
15
|
+
interface CellRange {
|
|
16
|
+
startRow: number;
|
|
17
|
+
endRow: number;
|
|
18
|
+
columns: ArtColumn[];
|
|
19
|
+
startColumn: ArtColumn;
|
|
20
|
+
footerRowRange: FooterRowRange | null;
|
|
7
21
|
}
|
|
8
22
|
export declare const rangeSelectionKey = "rangeSelection";
|
|
9
23
|
export declare const lastClickCellKey = "lastClickCell";
|
|
10
24
|
export declare function rangeSelection(opts: RangeSelectionFeatureOptions): (pipeline: TablePipeline) => TablePipeline;
|
|
25
|
+
/**
|
|
26
|
+
* 获取框选范围唯一标识
|
|
27
|
+
* @param {*} cellRange
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
export declare function getCellRangeId(cellRange: CellRange): string;
|
|
31
|
+
export {};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime-corejs3/helpers/typeof";
|
|
2
1
|
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
|
|
2
|
+
import _typeof from "@babel/runtime-corejs3/helpers/typeof";
|
|
3
3
|
import _extends from "@babel/runtime-corejs3/helpers/extends";
|
|
4
|
+
import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
|
|
5
|
+
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
4
6
|
import _findIndexInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find-index";
|
|
5
7
|
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
|
6
8
|
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
@@ -12,9 +14,10 @@ import { Classes } from '../../base/styles';
|
|
|
12
14
|
import cx from 'classnames';
|
|
13
15
|
export var rangeSelectionKey = 'rangeSelection';
|
|
14
16
|
export var lastClickCellKey = 'lastClickCell';
|
|
17
|
+
var startSelectedCellRangesKey = 'startSelectedCellRanges';
|
|
18
|
+
var SCROLL_OFFSET = 30;
|
|
15
19
|
export function rangeSelection(opts) {
|
|
16
20
|
return function step(pipeline) {
|
|
17
|
-
var SCROLL_SIZE = 30;
|
|
18
21
|
var tableBody = pipeline.ref.current.domHelper && pipeline.ref.current.domHelper.tableBody;
|
|
19
22
|
var tableFooter = pipeline.ref.current.domHelper && pipeline.ref.current.domHelper.tableFooter;
|
|
20
23
|
var artTable = pipeline.ref.current.domHelper && pipeline.ref.current.domHelper.artTable;
|
|
@@ -26,14 +29,18 @@ export function rangeSelection(opts) {
|
|
|
26
29
|
var columns = pipeline.getColumns();
|
|
27
30
|
var dataSource = pipeline.getDataSource();
|
|
28
31
|
|
|
29
|
-
var rangeSelectedChange = function rangeSelectedChange(rangeSelection) {
|
|
32
|
+
var rangeSelectedChange = function rangeSelectedChange(rangeSelection, isFinished) {
|
|
30
33
|
var _a;
|
|
31
34
|
|
|
35
|
+
if (isFinished) {
|
|
36
|
+
pipeline.setFeatureOptions(startSelectedCellRangesKey, rangeSelection);
|
|
37
|
+
}
|
|
38
|
+
|
|
32
39
|
pipeline.setStateAtKey(rangeSelectionKey, rangeSelection);
|
|
33
|
-
(_a = opts === null || opts === void 0 ? void 0 : opts.rangeSelectedChange) === null || _a === void 0 ? void 0 : _a.call(opts, rangeSelection);
|
|
40
|
+
(_a = opts === null || opts === void 0 ? void 0 : opts.rangeSelectedChange) === null || _a === void 0 ? void 0 : _a.call(opts, rangeSelection, isFinished);
|
|
34
41
|
};
|
|
35
42
|
|
|
36
|
-
var setRangeSelection = function setRangeSelection(startDragCell, draggingCell) {
|
|
43
|
+
var setRangeSelection = function setRangeSelection(startDragCell, draggingCell, isFinished) {
|
|
37
44
|
if (!startDragCell || !draggingCell) return;
|
|
38
45
|
var rangeColumns = getRangeColumns(startDragCell, draggingCell, columns);
|
|
39
46
|
|
|
@@ -42,21 +49,31 @@ export function rangeSelection(opts) {
|
|
|
42
49
|
endRow = _getRangeSelectionRow.endRow,
|
|
43
50
|
footerRowRange = _getRangeSelectionRow.footerRowRange;
|
|
44
51
|
|
|
45
|
-
var
|
|
52
|
+
var cellRange = {
|
|
46
53
|
startRow: startRow,
|
|
47
54
|
endRow: endRow,
|
|
48
55
|
columns: rangeColumns,
|
|
49
56
|
startColumn: startDragCell.column,
|
|
50
57
|
footerRowRange: footerRowRange
|
|
51
58
|
};
|
|
59
|
+
var cellRanges = pipeline.getFeatureOptions(startSelectedCellRangesKey) ? _toConsumableArray(pipeline.getFeatureOptions(startSelectedCellRangesKey)) : [];
|
|
60
|
+
|
|
61
|
+
if (isCellRangeSingleCell([cellRange])) {
|
|
62
|
+
var singleCellRangeId = getCellRangeId(cellRange);
|
|
63
|
+
cellRanges = _filterInstanceProperty(cellRanges).call(cellRanges, function (item) {
|
|
64
|
+
return getCellRangeId(item) !== singleCellRangeId;
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
cellRanges.push(cellRange);
|
|
52
69
|
|
|
53
|
-
if (isCellRangeSingleCell(
|
|
70
|
+
if (isCellRangeSingleCell(cellRanges)) {
|
|
54
71
|
artTable.classList.remove(cx(Classes.rangeSelection));
|
|
55
72
|
} else {
|
|
56
73
|
artTable.classList.add(cx(Classes.rangeSelection));
|
|
57
74
|
}
|
|
58
75
|
|
|
59
|
-
rangeSelectedChange(
|
|
76
|
+
rangeSelectedChange(cellRanges, isFinished);
|
|
60
77
|
};
|
|
61
78
|
|
|
62
79
|
var shiftKeySelect = function shiftKeySelect(event) {
|
|
@@ -64,76 +81,110 @@ export function rangeSelection(opts) {
|
|
|
64
81
|
var clickCell = getTargetCell(target, columns);
|
|
65
82
|
|
|
66
83
|
if (clickCell) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
setRangeSelection(_lastClickCell, clickCell);
|
|
72
|
-
} else {
|
|
73
|
-
// 第一次进来就按住shift键,这时候要记住点击的单元格
|
|
74
|
-
pipeline.setFeatureOptions(lastClickCellKey, clickCell);
|
|
75
|
-
}
|
|
84
|
+
var _lastClickCell = pipeline.getFeatureOptions(lastClickCellKey);
|
|
85
|
+
|
|
86
|
+
if (_lastClickCell) {
|
|
87
|
+
setRangeSelection(_lastClickCell, clickCell, true);
|
|
76
88
|
} else {
|
|
89
|
+
// 第一次进来就按住shift键,这时候要记住点击的单元格
|
|
77
90
|
pipeline.setFeatureOptions(lastClickCellKey, clickCell);
|
|
78
|
-
setRangeSelection(clickCell, clickCell);
|
|
79
91
|
}
|
|
80
92
|
}
|
|
81
93
|
};
|
|
82
94
|
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
shiftKeySelect(mouseDownEvent);
|
|
88
|
-
if (mouseDownEvent.shiftKey) return;
|
|
89
|
-
var target = mouseDownEvent.target;
|
|
90
|
-
var startDragCell = getTargetCell(target, columns);
|
|
91
|
-
var mousemove$ = fromEvent(window, 'mousemove');
|
|
92
|
-
var mouseup$ = fromEvent(window, 'mouseup');
|
|
95
|
+
var updateScrollPosition = function updateScrollPosition(client) {
|
|
96
|
+
var clientX = client.clientX,
|
|
97
|
+
clientY = client.clientY;
|
|
93
98
|
var tableBodyClientRect = tableBody.getBoundingClientRect();
|
|
99
|
+
var left = tableBodyClientRect.left,
|
|
100
|
+
top = tableBodyClientRect.top,
|
|
101
|
+
height = tableBodyClientRect.height,
|
|
102
|
+
width = tableBodyClientRect.width;
|
|
94
103
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
var left = tableBodyClientRect.left,
|
|
99
|
-
top = tableBodyClientRect.top,
|
|
100
|
-
height = tableBodyClientRect.height,
|
|
101
|
-
width = tableBodyClientRect.width;
|
|
104
|
+
if (clientX + SCROLL_OFFSET >= left + width) {
|
|
105
|
+
pipeline.ref.current.domHelper.virtual.scrollLeft += SCROLL_OFFSET;
|
|
106
|
+
}
|
|
102
107
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
108
|
+
if (clientX - SCROLL_OFFSET <= left) {
|
|
109
|
+
pipeline.ref.current.domHelper.virtual.scrollLeft -= SCROLL_OFFSET;
|
|
110
|
+
}
|
|
106
111
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
112
|
+
if (clientY + SCROLL_OFFSET >= top + height) {
|
|
113
|
+
pipeline.ref.current.domHelper.tableBody.scrollTop += SCROLL_OFFSET;
|
|
114
|
+
}
|
|
110
115
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
116
|
+
if (clientY + SCROLL_OFFSET <= top) {
|
|
117
|
+
pipeline.ref.current.domHelper.tableBody.scrollTop -= SCROLL_OFFSET;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
114
120
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
121
|
+
var setStartSelectedCellRanges = function setStartSelectedCellRanges(isCtrlKey, isShiftKey) {
|
|
122
|
+
if (opts === null || opts === void 0 ? void 0 : opts.suppressMultiRangeSelection) {
|
|
123
|
+
pipeline.setFeatureOptions(startSelectedCellRangesKey, []);
|
|
124
|
+
return;
|
|
125
|
+
} // ctrl 和shift 同时按时,优先生效shift
|
|
126
|
+
// 没有点击ctrl 或者shift时,每次点击开始时都清空选中范围
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
if (!isCtrlKey && !isShiftKey) {
|
|
130
|
+
pipeline.setFeatureOptions(startSelectedCellRangesKey, []);
|
|
131
|
+
} // shift 点击框选,要保留之前的选中结果。最新的框选范围覆盖最后一次的框选范围
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
if (isShiftKey) {
|
|
135
|
+
var _startDragCellRanges = pipeline.getFeatureOptions(startSelectedCellRangesKey) ? _toConsumableArray(pipeline.getFeatureOptions(startSelectedCellRangesKey)) : [];
|
|
119
136
|
|
|
137
|
+
_startDragCellRanges.pop();
|
|
138
|
+
|
|
139
|
+
pipeline.setFeatureOptions(startSelectedCellRangesKey, _startDragCellRanges);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
var onMouseDown = function onMouseDown(mouseDownEvent) {
|
|
144
|
+
if (mouseDownEvent.button !== 0 || !(isElementInEventPath(tableBody, mouseDownEvent.nativeEvent) || isElementInEventPath(tableFooter, mouseDownEvent.nativeEvent))) return; // mouseDownEvent.preventDefault()
|
|
145
|
+
|
|
146
|
+
var isCtrlKey = mouseDownEvent.ctrlKey || mouseDownEvent.metaKey;
|
|
147
|
+
var isShiftKey = mouseDownEvent.shiftKey;
|
|
148
|
+
var target = mouseDownEvent.target; // 每次点击时先确认初始生效的框选范围
|
|
149
|
+
|
|
150
|
+
setStartSelectedCellRanges(isCtrlKey, isShiftKey);
|
|
151
|
+
|
|
152
|
+
if (isShiftKey) {
|
|
153
|
+
shiftKeySelect(mouseDownEvent);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
var startDragCell = getTargetCell(target, columns);
|
|
158
|
+
pipeline.setFeatureOptions(lastClickCellKey, startDragCell);
|
|
159
|
+
var draggingCell = startDragCell;
|
|
160
|
+
var mousemove$ = fromEvent(window, 'mousemove');
|
|
161
|
+
var mouseup$ = fromEvent(window, 'mouseup');
|
|
120
162
|
var rangeSelected$ = mousemove$.pipe(map(function (mouseMoveEvent) {
|
|
121
163
|
var target = mouseMoveEvent.target || mouseMoveEvent.srcElement;
|
|
122
|
-
|
|
164
|
+
draggingCell = getTargetCell(target, columns);
|
|
123
165
|
var client = {
|
|
124
166
|
clientX: mouseMoveEvent.clientX,
|
|
125
167
|
clientY: mouseMoveEvent.clientY
|
|
126
168
|
};
|
|
127
|
-
|
|
169
|
+
|
|
170
|
+
if (!(draggingCell === null || draggingCell === void 0 ? void 0 : draggingCell.isFooterCell)) {
|
|
171
|
+
updateScrollPosition(client);
|
|
172
|
+
}
|
|
173
|
+
|
|
128
174
|
return {
|
|
129
175
|
startDragCell: startDragCell,
|
|
130
176
|
draggingCell: draggingCell
|
|
131
177
|
};
|
|
132
178
|
}), takeUntil(mouseup$));
|
|
133
|
-
rangeSelected$.subscribe(
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
179
|
+
rangeSelected$.subscribe({
|
|
180
|
+
next: function next(_ref) {
|
|
181
|
+
var startDragCell = _ref.startDragCell,
|
|
182
|
+
draggingCell = _ref.draggingCell;
|
|
183
|
+
setRangeSelection(startDragCell, draggingCell, false);
|
|
184
|
+
},
|
|
185
|
+
complete: function complete() {
|
|
186
|
+
setRangeSelection(startDragCell, draggingCell, true);
|
|
187
|
+
}
|
|
137
188
|
});
|
|
138
189
|
};
|
|
139
190
|
|
|
@@ -147,7 +198,7 @@ export function rangeSelection(opts) {
|
|
|
147
198
|
if (columns.length && rowLen && !getElementEditable(e.target)) {
|
|
148
199
|
opts.preventkDefaultOfKeyDownEvent !== false && e.preventDefault();
|
|
149
200
|
artTable.classList.add(cx(Classes.rangeSelection));
|
|
150
|
-
rangeSelectedChange({
|
|
201
|
+
rangeSelectedChange([{
|
|
151
202
|
startRow: 0,
|
|
152
203
|
endRow: rowLen - 1,
|
|
153
204
|
columns: collectNodes(columns, 'leaf-only'),
|
|
@@ -156,7 +207,7 @@ export function rangeSelection(opts) {
|
|
|
156
207
|
startRow: 0,
|
|
157
208
|
endRow: footerDataSource.length - 1
|
|
158
209
|
} : null
|
|
159
|
-
});
|
|
210
|
+
}], true);
|
|
160
211
|
}
|
|
161
212
|
}
|
|
162
213
|
};
|
|
@@ -169,41 +220,21 @@ export function rangeSelection(opts) {
|
|
|
169
220
|
}); // todo: 后面可以把mousedown放到一个流里面
|
|
170
221
|
|
|
171
222
|
return pipeline.mapColumns(makeRecursiveMapper(function (col) {
|
|
172
|
-
var
|
|
173
|
-
|
|
174
|
-
var rangeSelection = pipeline.getStateAtKey(rangeSelectionKey);
|
|
175
|
-
if (!rangeSelection || _findIndexInstanceProperty(_context = rangeSelection.columns).call(_context, function (selectedCol) {
|
|
176
|
-
return selectedCol.code === col.code;
|
|
177
|
-
}) === -1) return col;
|
|
223
|
+
var cellRanges = pipeline.getStateAtKey(rangeSelectionKey) || [];
|
|
178
224
|
var prevGetCellProps = col.getCellProps;
|
|
179
225
|
return _extends(_extends({}, col), {
|
|
180
226
|
getCellProps: function getCellProps(value, record, rowIndex) {
|
|
181
|
-
var _cx;
|
|
182
|
-
|
|
183
227
|
var prevCellProps = prevGetCellProps === null || prevGetCellProps === void 0 ? void 0 : prevGetCellProps(value, record, rowIndex);
|
|
184
|
-
var
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
var _getFooterRowIndex = getFooterRowIndex(footerRowRange),
|
|
195
|
-
footerStartRowIndex = _getFooterRowIndex.startRowIndex,
|
|
196
|
-
footerEndRowIndex = _getFooterRowIndex.endRowIndex;
|
|
197
|
-
|
|
198
|
-
var startCol = columns[0];
|
|
199
|
-
var endCol = columns[columns.length - 1];
|
|
200
|
-
var bodyMatch = !isInFooter && rowIndex >= startRowIndex && rowIndex <= endRowIndex;
|
|
201
|
-
var footerMatch = isInFooter && footerRowRange && rowIndex >= footerStartRowIndex && rowIndex <= footerEndRowIndex;
|
|
202
|
-
var match = footerMatch || bodyMatch;
|
|
203
|
-
var matchSingleCell = match && isCellRangeSingleCell(rangeSelection); // 单个范围选中单元格不显示样式
|
|
204
|
-
|
|
205
|
-
var showCellRangeStyle = match && !matchSingleCell;
|
|
206
|
-
var className = cx((_cx = {}, _defineProperty(_cx, Classes.tableCellRangeSingleCell, matchSingleCell), _defineProperty(_cx, Classes.tableCellRangeSelected, showCellRangeStyle), _defineProperty(_cx, Classes.tableCellRangeTop, showCellRangeStyle && (isInFooter ? startRowIndex !== -1 ? false : rowIndex === footerStartRowIndex : rowIndex === startRowIndex)), _defineProperty(_cx, Classes.tableCellRangeLeft, showCellRangeStyle && col.code === startCol.code), _defineProperty(_cx, Classes.tableCellRangeBottom, showCellRangeStyle && (isInFooter ? rowIndex === footerEndRowIndex : footerRowRange ? false : rowIndex === endRowIndex)), _defineProperty(_cx, Classes.tableCellRangeRight, showCellRangeStyle && col.code === endCol.code), _cx));
|
|
228
|
+
var isFooterCell = record[pipeline.getFeatureOptions('footerRowMetaKey')];
|
|
229
|
+
if (!cellRanges.some(function (cellRange) {
|
|
230
|
+
return isCellInRange(cellRange, rowIndex, col, isFooterCell);
|
|
231
|
+
})) return prevCellProps;
|
|
232
|
+
var className = getCellRangesClassName(cellRanges, {
|
|
233
|
+
isFooterCell: isFooterCell,
|
|
234
|
+
rowIndex: rowIndex,
|
|
235
|
+
col: col,
|
|
236
|
+
record: record
|
|
237
|
+
});
|
|
207
238
|
return mergeCellProps(prevCellProps, {
|
|
208
239
|
className: className
|
|
209
240
|
});
|
|
@@ -230,7 +261,7 @@ function getTargetCell(target, columns) {
|
|
|
230
261
|
rowSpan: parseInt(target.getAttribute('rowspan') || 1),
|
|
231
262
|
code: columnCode,
|
|
232
263
|
column: column,
|
|
233
|
-
|
|
264
|
+
isFooterCell: isEleInFooter(target)
|
|
234
265
|
}
|
|
235
266
|
};
|
|
236
267
|
}();
|
|
@@ -245,7 +276,7 @@ function getTargetCell(target, columns) {
|
|
|
245
276
|
}
|
|
246
277
|
|
|
247
278
|
function isSameCell(cell1, cell2) {
|
|
248
|
-
return cell1.rowIndex === cell2.rowIndex && cell1.code === cell2.code && cell1.
|
|
279
|
+
return cell1.rowIndex === cell2.rowIndex && cell1.code === cell2.code && cell1.isFooterCell === cell2.isFooterCell;
|
|
249
280
|
}
|
|
250
281
|
|
|
251
282
|
function isEleInFooter(target) {
|
|
@@ -288,10 +319,10 @@ function getRangeSelectionRowInfo(startCell, endCell, dataSource) {
|
|
|
288
319
|
_endRow = _getCellRangeRow.endRow; // 两个单元格都在表体
|
|
289
320
|
|
|
290
321
|
|
|
291
|
-
if (!startCell.
|
|
322
|
+
if (!startCell.isFooterCell && !endCell.isFooterCell) {
|
|
292
323
|
startRow = _startRow;
|
|
293
324
|
endRow = _endRow;
|
|
294
|
-
} else if (startCell.
|
|
325
|
+
} else if (startCell.isFooterCell && endCell.isFooterCell) {
|
|
295
326
|
// 两个单元格都在表底
|
|
296
327
|
footerRowRange = {
|
|
297
328
|
startRow: _startRow,
|
|
@@ -299,7 +330,7 @@ function getRangeSelectionRowInfo(startCell, endCell, dataSource) {
|
|
|
299
330
|
};
|
|
300
331
|
} else {
|
|
301
332
|
// 一个单元格在表体,一个在表底
|
|
302
|
-
if (startCell.
|
|
333
|
+
if (startCell.isFooterCell) {
|
|
303
334
|
startRow = dataSource.length - 1;
|
|
304
335
|
endRow = endCell.rowIndex;
|
|
305
336
|
footerRowRange = {
|
|
@@ -322,6 +353,13 @@ function getRangeSelectionRowInfo(startCell, endCell, dataSource) {
|
|
|
322
353
|
footerRowRange: footerRowRange
|
|
323
354
|
};
|
|
324
355
|
}
|
|
356
|
+
/**
|
|
357
|
+
* 获取框选范围的起始结束行
|
|
358
|
+
* @param startCell 起始单元格
|
|
359
|
+
* @param endCell 结束单元格
|
|
360
|
+
* @returns
|
|
361
|
+
*/
|
|
362
|
+
|
|
325
363
|
|
|
326
364
|
function getCellRangeRow(startCell, endCell) {
|
|
327
365
|
if (isSameCell(startCell, endCell)) {
|
|
@@ -339,12 +377,20 @@ function getCellRangeRow(startCell, endCell) {
|
|
|
339
377
|
endRow: endRow
|
|
340
378
|
};
|
|
341
379
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
380
|
+
/**
|
|
381
|
+
* 框选范围是否只包含单个单元格
|
|
382
|
+
* @param cellRanges
|
|
383
|
+
* @returns
|
|
384
|
+
*/
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
function isCellRangeSingleCell(cellRanges) {
|
|
388
|
+
if (cellRanges.length !== 1) return false;
|
|
389
|
+
var _cellRanges$ = cellRanges[0],
|
|
390
|
+
startRow = _cellRanges$.startRow,
|
|
391
|
+
endRow = _cellRanges$.endRow,
|
|
392
|
+
columns = _cellRanges$.columns,
|
|
393
|
+
footerRowRange = _cellRanges$.footerRowRange;
|
|
348
394
|
var isBodySingleCell = !footerRowRange && startRow === endRow && columns.length === 1;
|
|
349
395
|
var isFooterSingleCell = startRow === -1 && footerRowRange.startRow === footerRowRange.endRow && columns.length === 1;
|
|
350
396
|
return isBodySingleCell || isFooterSingleCell;
|
|
@@ -372,12 +418,140 @@ function getFooterRowIndex(footerRowRange) {
|
|
|
372
418
|
}
|
|
373
419
|
|
|
374
420
|
function getElementEditable(target) {
|
|
375
|
-
var
|
|
421
|
+
var _context;
|
|
376
422
|
|
|
377
423
|
if (!target) return;
|
|
378
424
|
|
|
379
|
-
if (_includesInstanceProperty(
|
|
425
|
+
if (_includesInstanceProperty(_context = ['input', 'textarea']).call(_context, target.tagName.toLowerCase())) {
|
|
380
426
|
if (target.type === 'checkbox') return;
|
|
381
427
|
return !target.disabled && !target.readOnly;
|
|
382
428
|
}
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* 判断单元格是否在框选范围内
|
|
432
|
+
* @param cellRange
|
|
433
|
+
* @param rowIndex
|
|
434
|
+
* @param col
|
|
435
|
+
* @param isFooterCell
|
|
436
|
+
* @returns
|
|
437
|
+
*/
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
function isCellInRange(cellRange, rowIndex, col, isFooterCell) {
|
|
441
|
+
var startRow = cellRange.startRow,
|
|
442
|
+
endRow = cellRange.endRow,
|
|
443
|
+
columns = cellRange.columns,
|
|
444
|
+
footerRowRange = cellRange.footerRowRange;
|
|
445
|
+
var isColInRanges = _findIndexInstanceProperty(columns).call(columns, function (item) {
|
|
446
|
+
return item.code === col.code;
|
|
447
|
+
}) !== -1;
|
|
448
|
+
if (!isColInRanges) return false;
|
|
449
|
+
|
|
450
|
+
var _getRowIndex = getRowIndex(startRow, endRow),
|
|
451
|
+
startRowIndex = _getRowIndex.startRowIndex,
|
|
452
|
+
endRowIndex = _getRowIndex.endRowIndex;
|
|
453
|
+
|
|
454
|
+
var _getFooterRowIndex = getFooterRowIndex(footerRowRange),
|
|
455
|
+
footerStartRowIndex = _getFooterRowIndex.startRowIndex,
|
|
456
|
+
footerEndRowIndex = _getFooterRowIndex.endRowIndex;
|
|
457
|
+
|
|
458
|
+
var bodyMatch = !isFooterCell && rowIndex >= startRowIndex && rowIndex <= endRowIndex;
|
|
459
|
+
var footerMatch = isFooterCell && footerRowRange && rowIndex >= footerStartRowIndex && rowIndex <= footerEndRowIndex;
|
|
460
|
+
var isRowInRange = footerMatch || bodyMatch;
|
|
461
|
+
return isRowInRange;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* 获取框选范围唯一标识
|
|
465
|
+
* @param {*} cellRange
|
|
466
|
+
* @returns
|
|
467
|
+
*/
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
export function getCellRangeId(cellRange) {
|
|
471
|
+
var startRow = cellRange.startRow,
|
|
472
|
+
endRow = cellRange.endRow,
|
|
473
|
+
footerRowRange = cellRange.footerRowRange,
|
|
474
|
+
columns = cellRange.columns;
|
|
475
|
+
|
|
476
|
+
var _getRowIndex2 = getRowIndex(startRow, endRow),
|
|
477
|
+
startRowIndex = _getRowIndex2.startRowIndex,
|
|
478
|
+
endRowIndex = _getRowIndex2.endRowIndex;
|
|
479
|
+
|
|
480
|
+
var _getFooterRowIndex2 = getFooterRowIndex(footerRowRange),
|
|
481
|
+
footerStartRowIndex = _getFooterRowIndex2.startRowIndex,
|
|
482
|
+
footerEndRowIndex = _getFooterRowIndex2.endRowIndex;
|
|
483
|
+
|
|
484
|
+
var firstColId = columns[0].code;
|
|
485
|
+
var endColId = columns[columns.length - 1].code;
|
|
486
|
+
return startRowIndex + '_' + endRowIndex + '_' + footerStartRowIndex + '_' + footerEndRowIndex + '_' + firstColId + '_' + endColId;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* 获取框选范围中单元格的样式
|
|
490
|
+
* @param cellRanges
|
|
491
|
+
* @param param1
|
|
492
|
+
* @returns
|
|
493
|
+
*/
|
|
494
|
+
|
|
495
|
+
function getCellRangesClassName(cellRanges, _ref2) {
|
|
496
|
+
var _cx;
|
|
497
|
+
|
|
498
|
+
var isFooterCell = _ref2.isFooterCell,
|
|
499
|
+
rowIndex = _ref2.rowIndex,
|
|
500
|
+
col = _ref2.col,
|
|
501
|
+
record = _ref2.record;
|
|
502
|
+
|
|
503
|
+
var _getMatchBorderStyle = getMatchBorderStyle(cellRanges, {
|
|
504
|
+
isFooterCell: isFooterCell,
|
|
505
|
+
rowIndex: rowIndex,
|
|
506
|
+
col: col,
|
|
507
|
+
record: record
|
|
508
|
+
}),
|
|
509
|
+
matchCellRangeTop = _getMatchBorderStyle.matchCellRangeTop,
|
|
510
|
+
matchCellRangeLeft = _getMatchBorderStyle.matchCellRangeLeft,
|
|
511
|
+
matchCellRangeBottom = _getMatchBorderStyle.matchCellRangeBottom,
|
|
512
|
+
matchCellRangeRight = _getMatchBorderStyle.matchCellRangeRight;
|
|
513
|
+
|
|
514
|
+
var isSingleCell = isCellRangeSingleCell(cellRanges);
|
|
515
|
+
var className = cx((_cx = {}, _defineProperty(_cx, Classes.tableCellRangeSingleCell, isSingleCell), _defineProperty(_cx, Classes.tableCellRangeSelected, !isSingleCell), _defineProperty(_cx, Classes.tableCellRangeTop, !isSingleCell && matchCellRangeTop), _defineProperty(_cx, Classes.tableCellRangeLeft, !isSingleCell && matchCellRangeLeft), _defineProperty(_cx, Classes.tableCellRangeBottom, !isSingleCell && matchCellRangeBottom), _defineProperty(_cx, Classes.tableCellRangeRight, !isSingleCell && matchCellRangeRight), _cx));
|
|
516
|
+
return className;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function getMatchBorderStyle(cellRanges, _ref3) {
|
|
520
|
+
var isFooterCell = _ref3.isFooterCell,
|
|
521
|
+
rowIndex = _ref3.rowIndex,
|
|
522
|
+
col = _ref3.col,
|
|
523
|
+
record = _ref3.record;
|
|
524
|
+
return cellRanges.reduce(function (obj, cellRange) {
|
|
525
|
+
if (!isCellInRange(cellRange, rowIndex, col, isFooterCell)) return obj;
|
|
526
|
+
var startRow = cellRange.startRow,
|
|
527
|
+
endRow = cellRange.endRow,
|
|
528
|
+
columns = cellRange.columns,
|
|
529
|
+
footerRowRange = cellRange.footerRowRange;
|
|
530
|
+
|
|
531
|
+
var _getRowIndex3 = getRowIndex(startRow, endRow),
|
|
532
|
+
startRowIndex = _getRowIndex3.startRowIndex,
|
|
533
|
+
endRowIndex = _getRowIndex3.endRowIndex;
|
|
534
|
+
|
|
535
|
+
var _getFooterRowIndex3 = getFooterRowIndex(footerRowRange),
|
|
536
|
+
footerStartRowIndex = _getFooterRowIndex3.startRowIndex,
|
|
537
|
+
footerEndRowIndex = _getFooterRowIndex3.endRowIndex;
|
|
538
|
+
|
|
539
|
+
var startCol = columns[0];
|
|
540
|
+
var endCol = columns[columns.length - 1];
|
|
541
|
+
var matchCellRangeTop = isFooterCell ? startRowIndex !== -1 ? false : rowIndex === footerStartRowIndex : rowIndex === startRowIndex;
|
|
542
|
+
var matchCellRangeLeft = col.code === startCol.code;
|
|
543
|
+
var matchCellRangeBottom = isFooterCell ? rowIndex === footerEndRowIndex : footerRowRange ? false : rowIndex === endRowIndex;
|
|
544
|
+
var matchCellRangeRight = col.code === endCol.code; // 如果样式已经匹配上了,就不需要再取计算的样式
|
|
545
|
+
|
|
546
|
+
obj.matchCellRangeTop = obj.matchCellRangeTop || matchCellRangeTop;
|
|
547
|
+
obj.matchCellRangeLeft = obj.matchCellRangeLeft || matchCellRangeLeft;
|
|
548
|
+
obj.matchCellRangeBottom = obj.matchCellRangeBottom || matchCellRangeBottom;
|
|
549
|
+
obj.matchCellRangeRight = obj.matchCellRangeRight || matchCellRangeRight;
|
|
550
|
+
return obj;
|
|
551
|
+
}, {
|
|
552
|
+
matchCellRangeTop: false,
|
|
553
|
+
matchCellRangeLeft: false,
|
|
554
|
+
matchCellRangeBottom: false,
|
|
555
|
+
matchCellRangeRight: false
|
|
556
|
+
});
|
|
383
557
|
}
|