@kdcloudjs/table 1.1.6-canary.4 → 1.2.0-canary.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.
@@ -1,10 +1,31 @@
1
1
  import { TablePipeline } from '../pipeline';
2
+ import { ArtColumn } from '../../interfaces';
2
3
  export interface RangeSelectionFeatureOptions {
3
4
  /** 范围选中回调函数 */
4
- rangeSelectedChange?(params: any): void;
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 rangeSelection = {
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(rangeSelection)) {
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(rangeSelection);
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
- if (event.shiftKey) {
68
- var _lastClickCell = pipeline.getFeatureOptions(lastClickCellKey);
69
-
70
- if (_lastClickCell) {
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 onMouseDown = function onMouseDown(mouseDownEvent) {
84
- if (mouseDownEvent.button !== 0 || !(isElementInEventPath(tableBody, mouseDownEvent.nativeEvent) || isElementInEventPath(tableFooter, mouseDownEvent.nativeEvent))) return; // mouseDownEvent.preventDefault()
85
- // shift + 点击选中
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
- var updateScrollPosition = function updateScrollPosition(client) {
96
- var clientX = client.clientX,
97
- clientY = client.clientY;
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
- if (clientX + SCROLL_SIZE >= left + width) {
104
- pipeline.ref.current.domHelper.virtual.scrollLeft += SCROLL_SIZE;
105
- }
108
+ if (clientX - SCROLL_OFFSET <= left) {
109
+ pipeline.ref.current.domHelper.virtual.scrollLeft -= SCROLL_OFFSET;
110
+ }
106
111
 
107
- if (clientX - SCROLL_SIZE <= left) {
108
- pipeline.ref.current.domHelper.virtual.scrollLeft -= SCROLL_SIZE;
109
- }
112
+ if (clientY + SCROLL_OFFSET >= top + height) {
113
+ pipeline.ref.current.domHelper.tableBody.scrollTop += SCROLL_OFFSET;
114
+ }
110
115
 
111
- if (clientY + SCROLL_SIZE >= top + height) {
112
- pipeline.ref.current.domHelper.tableBody.scrollTop += SCROLL_SIZE;
113
- }
116
+ if (clientY + SCROLL_OFFSET <= top) {
117
+ pipeline.ref.current.domHelper.tableBody.scrollTop -= SCROLL_OFFSET;
118
+ }
119
+ };
114
120
 
115
- if (clientY + SCROLL_SIZE <= top) {
116
- pipeline.ref.current.domHelper.tableBody.scrollTop -= SCROLL_SIZE;
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
- var draggingCell = getTargetCell(target, columns);
164
+ draggingCell = getTargetCell(target, columns);
123
165
  var client = {
124
166
  clientX: mouseMoveEvent.clientX,
125
167
  clientY: mouseMoveEvent.clientY
126
168
  };
127
- updateScrollPosition(client);
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(function (_ref) {
134
- var startDragCell = _ref.startDragCell,
135
- draggingCell = _ref.draggingCell;
136
- setRangeSelection(startDragCell, draggingCell);
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 _context;
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 isInFooter = record[pipeline.getFeatureOptions('footerRowMetaKey')];
185
- var startRow = rangeSelection.startRow,
186
- endRow = rangeSelection.endRow,
187
- columns = rangeSelection.columns,
188
- footerRowRange = rangeSelection.footerRowRange;
189
-
190
- var _getRowIndex = getRowIndex(startRow, endRow),
191
- startRowIndex = _getRowIndex.startRowIndex,
192
- endRowIndex = _getRowIndex.endRowIndex;
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
- isInFooter: isEleInFooter(target)
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.isInFooter === cell2.isInFooter;
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.isInFooter && !endCell.isInFooter) {
322
+ if (!startCell.isFooterCell && !endCell.isFooterCell) {
292
323
  startRow = _startRow;
293
324
  endRow = _endRow;
294
- } else if (startCell.isInFooter && endCell.isInFooter) {
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.isInFooter) {
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
- function isCellRangeSingleCell(rangeSelection) {
344
- var startRow = rangeSelection.startRow,
345
- endRow = rangeSelection.endRow,
346
- columns = rangeSelection.columns,
347
- footerRowRange = rangeSelection.footerRowRange;
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 _context2;
421
+ var _context;
376
422
 
377
423
  if (!target) return;
378
424
 
379
- if (_includesInstanceProperty(_context2 = ['input', 'textarea']).call(_context2, target.tagName.toLowerCase())) {
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
  }
@@ -1,10 +1,31 @@
1
1
  import { TablePipeline } from '../pipeline';
2
+ import { ArtColumn } from '../../interfaces';
2
3
  export interface RangeSelectionFeatureOptions {
3
4
  /** 范围选中回调函数 */
4
- rangeSelectedChange?(params: any): void;
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 {};