sheet-happens 0.0.37 → 0.0.38

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/index.js CHANGED
@@ -88,7 +88,9 @@ var COLORS = {
88
88
  headerActive: '#e8f0ff',
89
89
  headerActiveText: '#1a66ff',
90
90
  headerSelected: '#1a66ff',
91
+ headerSelectedGroup: '#1a66ff70',
91
92
  headerSelectedText: '#ffffff',
93
+ headerSelectedGroupText: '#ffffff',
92
94
  shadowColor: '#000000'
93
95
  };
94
96
  var SIZES = {
@@ -132,6 +134,10 @@ var HEADER_SELECTED_STYLE = {
132
134
  backgroundColor: COLORS.headerSelected,
133
135
  color: COLORS.headerSelectedText
134
136
  };
137
+ var HEADER_GROUP_SELECTED_STYLE = {
138
+ backgroundColor: COLORS.headerSelectedGroup,
139
+ color: COLORS.headerSelectedGroupText
140
+ };
135
141
  var ARROW_KEYS = {
136
142
  ArrowRight: 'right',
137
143
  ArrowLeft: 'left',
@@ -179,6 +185,9 @@ var mulXY = function mulXY(a, b) {
179
185
  var maxXY = function maxXY(a, b) {
180
186
  return [Math.max(a[0], b[0]), Math.max(a[1], b[1])];
181
187
  };
188
+ var minXY = function minXY(a, b) {
189
+ return [Math.min(a[0], b[0]), Math.min(a[1], b[1])];
190
+ };
182
191
  var clampXY = function clampXY(p, min, max) {
183
192
  if (max === void 0) {
184
193
  max = [Infinity, Infinity];
@@ -203,6 +212,50 @@ var isSameSelection = function isSameSelection(a, b) {
203
212
  b2 = b[1];
204
213
  return isSameXY(a1, b1) && isSameXY(a2, b2);
205
214
  };
215
+ var forRange = function forRange(min, max, callback) {
216
+ for (var i = min; i <= max; ++i) {
217
+ callback(i);
218
+ }
219
+ };
220
+ var forSelectionColumns = function forSelectionColumns(selection) {
221
+ return function (callback) {
222
+ var _normalizeSelection = normalizeSelection(selection),
223
+ _normalizeSelection$ = _normalizeSelection[0],
224
+ left = _normalizeSelection$[0],
225
+ _normalizeSelection$2 = _normalizeSelection[1],
226
+ right = _normalizeSelection$2[0];
227
+
228
+ forRange(left, right, callback);
229
+ };
230
+ };
231
+ var forSelectionRows = function forSelectionRows(selection) {
232
+ return function (callback) {
233
+ var _normalizeSelection2 = normalizeSelection(selection),
234
+ _normalizeSelection2$ = _normalizeSelection2[0],
235
+ top = _normalizeSelection2$[1],
236
+ _normalizeSelection2$2 = _normalizeSelection2[1],
237
+ bottom = _normalizeSelection2$2[1];
238
+
239
+ forRange(top, bottom, callback);
240
+ };
241
+ };
242
+
243
+ var forToMap = function forToMap(forLoop) {
244
+ return function (map) {
245
+ var out = [];
246
+ forLoop(function () {
247
+ return out.push(map.apply(void 0, arguments));
248
+ });
249
+ return out;
250
+ };
251
+ };
252
+
253
+ var mapSelectionColumns = function mapSelectionColumns(selection) {
254
+ return forToMap(forSelectionColumns(selection));
255
+ };
256
+ var mapSelectionRows = function mapSelectionRows(selection) {
257
+ return forToMap(forSelectionRows(selection));
258
+ };
206
259
  var isMaybeRowSelection = function isMaybeRowSelection(selection) {
207
260
  var _selection$ = selection[0],
208
261
  left = _selection$[0],
@@ -254,30 +307,32 @@ var isEmptySelection = function isEmptySelection(selection) {
254
307
  return left === -1 && right === -1 && top === -1 && bottom === -1;
255
308
  };
256
309
  var isPointInsideSelection = function isPointInsideSelection(selection, point) {
257
- var _normalizeSelection = normalizeSelection(selection),
258
- _normalizeSelection$ = _normalizeSelection[0],
259
- left = _normalizeSelection$[0],
260
- top = _normalizeSelection$[1],
261
- _normalizeSelection$2 = _normalizeSelection[1],
262
- right = _normalizeSelection$2[0],
263
- bottom = _normalizeSelection$2[1];
310
+ var _normalizeSelection3 = normalizeSelection(selection),
311
+ _normalizeSelection3$ = _normalizeSelection3[0],
312
+ left = _normalizeSelection3$[0],
313
+ top = _normalizeSelection3$[1],
314
+ _normalizeSelection3$2 = _normalizeSelection3[1],
315
+ right = _normalizeSelection3$2[0],
316
+ bottom = _normalizeSelection3$2[1];
264
317
 
265
318
  var x = point[0],
266
319
  y = point[1];
267
320
  return x >= left && x <= right && y >= top && y <= bottom;
268
321
  };
322
+ var validateSelection = function validateSelection(selection) {
323
+ var anchor = selection[0],
324
+ head = selection[1];
325
+ anchor = anchor.slice();
326
+ head = head.slice();
327
+ var min = minXY(anchor, head);
328
+ if (min[0] === -1) anchor[0] = head[0] = -1;
329
+ if (min[1] === -1) anchor[1] = head[1] = -1;
330
+ return [anchor, head];
331
+ };
269
332
  var normalizeSelection = function normalizeSelection(selection) {
270
333
  var anchor = selection[0],
271
334
  head = selection[1];
272
- var ax = anchor[0],
273
- ay = anchor[1];
274
- var hx = head[0],
275
- hy = head[1];
276
- var left = Math.min(ax, hx);
277
- var right = Math.max(ax, hx);
278
- var top = Math.min(ay, hy);
279
- var bottom = Math.max(ay, hy);
280
- return [[left, top], [right, bottom]];
335
+ return [minXY(anchor, head), maxXY(anchor, head)];
281
336
  };
282
337
  var orientSelection = function orientSelection(normalized, to) {
283
338
  var _normalized$ = normalized[0],
@@ -292,62 +347,45 @@ var orientSelection = function orientSelection(normalized, to) {
292
347
  ay = anchor[1];
293
348
  var hx = head[0],
294
349
  hy = head[1];
295
- var swapX = (ax - hx || 1) * (left - right || 1) < 0;
296
- var swapY = (ay - hy || 1) * (top - bottom || 1) < 0;
350
+ var swapX = (ax - hx || 1) * (right - left || 1) < 0;
351
+ var swapY = (ay - hy || 1) * (bottom - top || 1) < 0;
297
352
  return [[swapX ? right : left, swapY ? bottom : top], [swapX ? left : right, swapY ? top : bottom]];
298
353
  };
299
354
 
300
355
  var LIMIT = 1000;
301
356
 
302
- var scanGroup = function scanGroup(keys, index, direction, match) {
303
- if (match == null) return index;
304
- var i = 0;
357
+ var scanGroup = function scanGroup(keys, index, direction, matchKeys) {
358
+ var i = 1;
305
359
  var limit = direction > 0 ? LIMIT : Math.min(LIMIT, index + 1);
306
360
 
307
361
  for (; i < limit; i++) {
308
- if (keys(index + i * direction) !== match) break;
362
+ var key = keys(index + i * direction);
363
+ if (key == null || !matchKeys.has(key)) break;
309
364
  }
310
365
 
311
366
  return index + (i - 1) * direction;
312
367
  };
313
368
 
314
- var expandSelectionToColumnGroups = function expandSelectionToColumnGroups(selection, columnGroupKeys) {
369
+ var expandSelectionToRowOrColumnGroups = function expandSelectionToRowOrColumnGroups(selection, groupKeys, matchKeys, coordinate) {
370
+ if (!matchKeys) return selection;
371
+
315
372
  var _normalizeSelection = normalizeSelection(selection),
316
- _normalizeSelection$ = _normalizeSelection[0],
317
- left = _normalizeSelection$[0],
318
- top = _normalizeSelection$[1],
319
- _normalizeSelection$2 = _normalizeSelection[1],
320
- right = _normalizeSelection$2[0],
321
- bottom = _normalizeSelection$2[1];
322
-
323
- var leftKey = columnGroupKeys(left);
324
- var rightKey = columnGroupKeys(right);
325
- var startColumn = scanGroup(columnGroupKeys, left, -1, leftKey);
326
- var endColumn = scanGroup(columnGroupKeys, right, 1, rightKey);
327
- var expanded = [[startColumn, top], [endColumn, bottom]];
328
- var oriented = orientSelection(expanded, selection);
329
- return oriented;
330
- };
331
- var expandSelectionToRowGroups = function expandSelectionToRowGroups(selection, rowGroupKeys) {
332
- var _normalizeSelection2 = normalizeSelection(selection),
333
- _normalizeSelection2$ = _normalizeSelection2[0],
334
- left = _normalizeSelection2$[0],
335
- top = _normalizeSelection2$[1],
336
- _normalizeSelection2$2 = _normalizeSelection2[1],
337
- right = _normalizeSelection2$2[0],
338
- bottom = _normalizeSelection2$2[1];
339
-
340
- var topKey = rowGroupKeys(top);
341
- var bottomKey = rowGroupKeys(bottom);
342
- var startRow = scanGroup(rowGroupKeys, top, -1, topKey);
343
- var endRow = scanGroup(rowGroupKeys, bottom, 1, bottomKey);
344
- var expanded = [[left, startRow], [right, endRow]];
373
+ first = _normalizeSelection[0],
374
+ second = _normalizeSelection[1];
375
+
376
+ var start = first[coordinate];
377
+ var end = second[coordinate];
378
+ var startIndex = scanGroup(groupKeys, start, -1, matchKeys);
379
+ var endIndex = scanGroup(groupKeys, end, 1, matchKeys);
380
+ var expanded = [first.slice(), second.slice()];
381
+ expanded[0][coordinate] = startIndex;
382
+ expanded[1][coordinate] = endIndex;
345
383
  var oriented = orientSelection(expanded, selection);
346
384
  return oriented;
347
385
  };
348
- var isBoundaryInsideGroup = function isBoundaryInsideGroup(index, rowOrColumnGroupKeys) {
349
- var before = rowOrColumnGroupKeys(index - 1);
350
- var after = rowOrColumnGroupKeys(index);
386
+ var isBoundaryInsideGroup = function isBoundaryInsideGroup(index, groupKeys) {
387
+ var before = groupKeys(index - 1);
388
+ var after = groupKeys(index);
351
389
  return before != null && after != null && before === after;
352
390
  };
353
391
 
@@ -494,7 +532,7 @@ var findInDisplayData = function findInDisplayData(displayData, start, direction
494
532
  return maxXY(cell, [0, 0]);
495
533
  };
496
534
 
497
- var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, onEdit, onCommit, onKnobAreaChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onInvalidateColumn, onInvalidateRow, onChange, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onRightClick, dontCommitEditOnSelectionChange) {
535
+ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, onEdit, onCommit, onKnobAreaChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onInvalidateColumn, onInvalidateRow, onChange, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onRightClick, dontCommitEditOnSelectionChange, dontChangeSelectionOnOrderChange) {
498
536
  var _useState = React.useState(null),
499
537
  hitTarget = _useState[0],
500
538
  setHitTarget = _useState[1];
@@ -644,31 +682,26 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
644
682
  return;
645
683
  }
646
684
 
647
- var _normalizeSelection2 = normalizeSelection(selection),
648
- _normalizeSelection2$ = _normalizeSelection2[0],
649
- minX = _normalizeSelection2$[0],
650
- minY = _normalizeSelection2$[1],
651
- _normalizeSelection2$2 = _normalizeSelection2[1],
652
- maxX = _normalizeSelection2$2[0],
653
- maxY = _normalizeSelection2$2[1];
654
-
655
- var selectedColumns = [];
656
- var selectedRows = [];
657
-
658
- for (var i = minX; i <= maxX; i++) {
659
- selectedColumns.push(i);
660
- }
661
-
662
- for (var _i = minY; _i <= maxY; _i++) {
663
- selectedRows.push(_i);
664
- }
685
+ var normalized = normalizeSelection(selection);
686
+ var _normalized$ = normalized[0],
687
+ minX = _normalized$[0],
688
+ minY = _normalized$[1],
689
+ _normalized$2 = normalized[1],
690
+ maxX = _normalized$2[0],
691
+ maxY = _normalized$2[1];
692
+ var selectedColumns = mapSelectionColumns(selection)(function (i) {
693
+ return i;
694
+ });
695
+ var selectedRows = mapSelectionRows(selection)(function (i) {
696
+ return i;
697
+ });
665
698
 
666
699
  if (!hideColumnHeaders && y < getIndentY()) {
667
700
  if (onColumnOrderChange) {
668
701
  var start = columnToPixel(minX) + SIZES.resizeZone;
669
702
  var end = columnToPixel(maxX, 1) - SIZES.resizeZone;
670
703
 
671
- if (isInRange(x, start, end)) {
704
+ if (isInRange(x, start, end) || selectedColumnGroups) {
672
705
  for (var _iterator2 = _createForOfIteratorHelperLoose(columns), _step2; !(_step2 = _iterator2()).done;) {
673
706
  var index = _step2.value;
674
707
 
@@ -676,9 +709,31 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
676
709
 
677
710
  var _end = columnToPixel(index, 1);
678
711
 
679
- if (isColumnSelection(selection) && isInRange(x, _start, _end) && isInRange(index, minX, maxX) && canOrderColumn(index)) {
712
+ if (isColumnSelection(selection) && isInRange(x, _start, _end) && (isInRange(index, minX, maxX) || selectedColumnGroups !== null && selectedColumnGroups !== void 0 && selectedColumnGroups.has(columnGroupKeys(index))) && canOrderColumn(index)) {
680
713
  window.document.body.style.cursor = 'grabbing';
681
- var indices = selectedColumns;
714
+ var indices = [].concat(new Set([].concat(selectedColumns, selectedColumnGroups ? columns.filter(function (index) {
715
+ return selectedColumnGroups.has(columnGroupKeys(index));
716
+ }) : [])).values());
717
+ indices.sort(function (a, b) {
718
+ return a - b;
719
+ });
720
+ var dragIndices = indices;
721
+
722
+ if (selectedColumnGroups) {
723
+ var clickSelection = [[index, -1], [index, -1]];
724
+
725
+ var _expandSelectionToRow = expandSelectionToRowOrColumnGroups(clickSelection, columnGroupKeys, selectedColumnGroups, 0),
726
+ _expandSelectionToRow2 = _expandSelectionToRow[0],
727
+ left = _expandSelectionToRow2[0],
728
+ _expandSelectionToRow3 = _expandSelectionToRow[1],
729
+ right = _expandSelectionToRow3[0];
730
+
731
+ var connected = !(minX > right || maxX < left);
732
+ var dragStart = connected ? Math.min(minX, left) : left;
733
+ var dragEnd = connected ? Math.max(maxX, right) : right;
734
+ dragIndices = seq(dragEnd - dragStart + 1, dragStart);
735
+ }
736
+
682
737
  var size = columnToPixel(maxX, 1) - columnToPixel(minX);
683
738
 
684
739
  var _getScrollPosition = getScrollPosition(e),
@@ -691,6 +746,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
691
746
  indices: indices
692
747
  });
693
748
  onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([0, 0]);
749
+ onDragIndicesChange === null || onDragIndicesChange === void 0 ? void 0 : onDragIndicesChange([dragIndices, null]);
694
750
  return;
695
751
  }
696
752
  }
@@ -732,7 +788,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
732
788
 
733
789
  var _end2 = rowToPixel(maxY, 1) - SIZES.resizeZone;
734
790
 
735
- if (isInRange(y, _start2, _end2)) {
791
+ if (isInRange(y, _start2, _end2) || selectedRowGroups) {
736
792
  for (var _iterator4 = _createForOfIteratorHelperLoose(rows), _step4; !(_step4 = _iterator4()).done;) {
737
793
  var _index2 = _step4.value;
738
794
 
@@ -740,9 +796,38 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
740
796
 
741
797
  var _end3 = rowToPixel(_index2, 1);
742
798
 
743
- if (isRowSelection(selection) && isInRange(y, _start3, _end3) && isInRange(_index2, minY, maxY) && canOrderRow(_index2)) {
799
+ if (isRowSelection(selection) && isInRange(y, _start3, _end3) && (isInRange(_index2, minY, maxY) || selectedRowGroups !== null && selectedRowGroups !== void 0 && selectedRowGroups.has(rowGroupKeys(_index2))) && canOrderRow(_index2)) {
744
800
  window.document.body.style.cursor = 'grabbing';
745
- var _indices2 = selectedRows;
801
+
802
+ var _indices2 = [].concat(new Set([].concat(selectedRows, selectedRowGroups ? rows.map(function (_, i) {
803
+ return i;
804
+ }).filter(function (index) {
805
+ return selectedRowGroups.has(rowGroupKeys(index));
806
+ }) : [])).values());
807
+
808
+ _indices2.sort(function (a, b) {
809
+ return a - b;
810
+ });
811
+
812
+ var _dragIndices = _indices2;
813
+
814
+ if (selectedRowGroups) {
815
+ var _clickSelection = [[-1, _index2], [-1, _index2]];
816
+
817
+ var _expandSelectionToRow4 = expandSelectionToRowOrColumnGroups(_clickSelection, rowGroupKeys, selectedRowGroups, 1),
818
+ _expandSelectionToRow5 = _expandSelectionToRow4[0],
819
+ top = _expandSelectionToRow5[1],
820
+ _expandSelectionToRow6 = _expandSelectionToRow4[1],
821
+ bottom = _expandSelectionToRow6[1];
822
+
823
+ var _connected = !(minY > bottom || maxY < top);
824
+
825
+ var _dragStart = _connected ? Math.min(minY, top) : top;
826
+
827
+ var _dragEnd = _connected ? Math.max(maxY, bottom) : bottom;
828
+
829
+ _dragIndices = seq(_dragEnd - _dragStart + 1, _dragStart);
830
+ }
746
831
 
747
832
  var _size2 = rowToPixel(maxY, 1) - rowToPixel(minY);
748
833
 
@@ -756,6 +841,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
756
841
  indices: _indices2
757
842
  });
758
843
  onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([0, 0]);
844
+ onDragIndicesChange === null || onDragIndicesChange === void 0 ? void 0 : onDragIndicesChange([null, _dragIndices]);
759
845
  return;
760
846
  }
761
847
  }
@@ -830,7 +916,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
830
916
 
831
917
  setDraggingSelection(true);
832
918
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([anchor, head], scrollTo, true);
833
- }, [getMousePosition, getScrollPosition, getMouseHit, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onKnobAreaChange, onSelectionChange, onCommit, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, dontCommitEditOnSelectionChange]);
919
+ }, [getMousePosition, getScrollPosition, getMouseHit, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onKnobAreaChange, onSelectionChange, onCommit, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, dontCommitEditOnSelectionChange, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups]);
834
920
  var onPointerUp = React.useCallback(function (e) {
835
921
  var _getMouseHit;
836
922
 
@@ -860,18 +946,19 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
860
946
 
861
947
  if (xy && (columnDrag || rowDrag)) {
862
948
  window.document.body.style.cursor = 'auto';
949
+ onDragIndicesChange === null || onDragIndicesChange === void 0 ? void 0 : onDragIndicesChange([null, null]);
863
950
  onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange(null);
864
951
  onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(null);
865
952
  var x = xy[0],
866
953
  y = xy[1];
867
954
 
868
- var _normalizeSelection3 = normalizeSelection(selection),
869
- _normalizeSelection3$ = _normalizeSelection3[0],
870
- minX = _normalizeSelection3$[0],
871
- minY = _normalizeSelection3$[1],
872
- _normalizeSelection3$2 = _normalizeSelection3[1],
873
- maxX = _normalizeSelection3$2[0],
874
- maxY = _normalizeSelection3$2[1];
955
+ var _normalizeSelection2 = normalizeSelection(selection),
956
+ _normalizeSelection2$ = _normalizeSelection2[0],
957
+ minX = _normalizeSelection2$[0],
958
+ minY = _normalizeSelection2$[1],
959
+ _normalizeSelection2$2 = _normalizeSelection2[1],
960
+ maxX = _normalizeSelection2$2[0],
961
+ maxY = _normalizeSelection2$2[1];
875
962
 
876
963
  var cellX = pixelToColumn(Math.max(x, getIndentX()), 0.5);
877
964
  var cellY = pixelToRow(Math.max(y, getIndentY()), 0.5);
@@ -879,10 +966,14 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
879
966
  if (columnDrag) {
880
967
  var indices = columnDrag.indices;
881
968
  var insideSelection = cellX >= minX && cellX <= maxX + 1;
969
+ var insideGroup = selectedColumnGroups === null || selectedColumnGroups === void 0 ? void 0 : selectedColumnGroups.has(columnGroupKeys(x));
882
970
 
883
- if (!insideSelection) {
884
- var order = cellX > minX ? cellX - indices.length : cellX;
885
- onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([[order, minY], [order + maxX - minX, maxY]], false, false, true);
971
+ if (!insideSelection && !insideGroup) {
972
+ var preceding = indices.filter(function (i) {
973
+ return i < cellX;
974
+ });
975
+ var order = cellX - preceding.length;
976
+ dontChangeSelectionOnOrderChange || (onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([[order, minY], [order + indices.length - 1, maxY]]));
886
977
  onColumnOrderChange === null || onColumnOrderChange === void 0 ? void 0 : onColumnOrderChange(indices, order);
887
978
  onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(Math.min(minX, order));
888
979
  }
@@ -893,10 +984,16 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
893
984
 
894
985
  var _insideSelection = cellY >= minY && cellY <= maxY + 1;
895
986
 
896
- if (!_insideSelection) {
897
- var _order = cellY > minY ? cellY - _indices4.length : cellY;
987
+ var _insideGroup = selectedRowGroups === null || selectedRowGroups === void 0 ? void 0 : selectedRowGroups.has(rowGroupKeys(y));
898
988
 
899
- onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([[minX, _order], [maxX, _order + maxY - minY]], false, false, true);
989
+ if (!_insideSelection && !_insideGroup) {
990
+ var _preceding = _indices4.filter(function (i) {
991
+ return i < cellY;
992
+ });
993
+
994
+ var _order = cellY - _preceding.length;
995
+
996
+ dontChangeSelectionOnOrderChange || (onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([[minX, _order], [maxX, _order + _indices4.length - 1]]));
900
997
  onRowOrderChange === null || onRowOrderChange === void 0 ? void 0 : onRowOrderChange(_indices4, _order);
901
998
  onInvalidateRow === null || onInvalidateRow === void 0 ? void 0 : onInvalidateRow(Math.min(minY, _order));
902
999
  }
@@ -922,7 +1019,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
922
1019
  var obj = hitTarget.obj;
923
1020
  (_obj$onClick = obj.onClick) === null || _obj$onClick === void 0 ? void 0 : _obj$onClick.call(obj, e);
924
1021
  }
925
- }, [getMousePosition, getMouseHit, onChange, onSelectionChange, onKnobAreaChange, onDropTargetChange, onColumnOrderChange, onRowOrderChange]);
1022
+ }, [getMousePosition, getMouseHit, onChange, onSelectionChange, onKnobAreaChange, onDropTargetChange, onColumnOrderChange, onRowOrderChange, dontChangeSelectionOnOrderChange]);
926
1023
  var onPointerMove = React.useCallback(function (e) {
927
1024
  var _ref$current3 = ref.current,
928
1025
  selection = _ref$current3.selection,
@@ -968,13 +1065,13 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
968
1065
  var x = xy[0],
969
1066
  y = xy[1];
970
1067
 
971
- var _normalizeSelection4 = normalizeSelection(selection),
972
- _normalizeSelection4$ = _normalizeSelection4[0],
973
- minX = _normalizeSelection4$[0],
974
- minY = _normalizeSelection4$[1],
975
- _normalizeSelection4$2 = _normalizeSelection4[1],
976
- maxX = _normalizeSelection4$2[0],
977
- maxY = _normalizeSelection4$2[1];
1068
+ var _normalizeSelection3 = normalizeSelection(selection),
1069
+ _normalizeSelection3$ = _normalizeSelection3[0],
1070
+ minX = _normalizeSelection3$[0],
1071
+ minY = _normalizeSelection3$[1],
1072
+ _normalizeSelection3$2 = _normalizeSelection3[1],
1073
+ maxX = _normalizeSelection3$2[0],
1074
+ maxY = _normalizeSelection3$2[1];
978
1075
 
979
1076
  var isDragging = columnResize || columnDrag || rowResize || rowDrag || draggingRowSelection || draggingColumnSelection;
980
1077
 
@@ -984,7 +1081,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
984
1081
  var start = columnToPixel(minX) + SIZES.resizeZone;
985
1082
  var end = columnToPixel(maxX, 1) - SIZES.resizeZone;
986
1083
 
987
- if (isInRange(x, start, end)) {
1084
+ if (isInRange(x, start, end) || selectedColumnGroups) {
988
1085
  for (var _iterator6 = _createForOfIteratorHelperLoose(columns), _step6; !(_step6 = _iterator6()).done;) {
989
1086
  var index = _step6.value;
990
1087
 
@@ -992,7 +1089,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
992
1089
 
993
1090
  var _end4 = columnToPixel(index, 1);
994
1091
 
995
- if (!draggingColumnSelection && isColumnSelection(selection) && isInRange(x, _start4, _end4) && isInRange(index, minX, maxX) && canOrderColumn(index)) {
1092
+ if (!draggingColumnSelection && isColumnSelection(selection) && isInRange(x, _start4, _end4) && (isInRange(index, minX, maxX) || selectedColumnGroups !== null && selectedColumnGroups !== void 0 && selectedColumnGroups.has(columnGroupKeys(index))) && canOrderColumn(index)) {
996
1093
  window.document.body.style.cursor = 'grab';
997
1094
  return;
998
1095
  }
@@ -1019,7 +1116,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1019
1116
 
1020
1117
  var _end5 = rowToPixel(maxY, 1) - SIZES.resizeZone;
1021
1118
 
1022
- if (isInRange(y, _start5, _end5)) {
1119
+ if (isInRange(y, _start5, _end5) || selectedRowGroups) {
1023
1120
  for (var _iterator8 = _createForOfIteratorHelperLoose(rows), _step8; !(_step8 = _iterator8()).done;) {
1024
1121
  var _index5 = _step8.value;
1025
1122
 
@@ -1027,7 +1124,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1027
1124
 
1028
1125
  var _end6 = rowToPixel(_index5, 1);
1029
1126
 
1030
- if (!draggingRowSelection && isRowSelection(selection) && isInRange(y, _start6, _end6) && isInRange(_index5, minY, maxY) && canOrderRow(_index5)) {
1127
+ if (!draggingRowSelection && isRowSelection(selection) && isInRange(y, _start6, _end6) && (isInRange(_index5, minY, maxY) || selectedRowGroups !== null && selectedRowGroups !== void 0 && selectedRowGroups.has(rowGroupKeys(_index5))) && canOrderRow(_index5)) {
1031
1128
  window.document.body.style.cursor = 'grab';
1032
1129
  return;
1033
1130
  }
@@ -1120,13 +1217,13 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1120
1217
  cellX = _pixelToCell[0],
1121
1218
  cellY = _pixelToCell[1];
1122
1219
 
1123
- var _normalizeSelection5 = normalizeSelection(selection),
1124
- _normalizeSelection5$ = _normalizeSelection5[0],
1125
- _minX = _normalizeSelection5$[0],
1126
- _minY = _normalizeSelection5$[1],
1127
- _normalizeSelection5$2 = _normalizeSelection5[1],
1128
- _maxX = _normalizeSelection5$2[0],
1129
- _maxY = _normalizeSelection5$2[1];
1220
+ var _normalizeSelection4 = normalizeSelection(selection),
1221
+ _normalizeSelection4$ = _normalizeSelection4[0],
1222
+ _minX = _normalizeSelection4$[0],
1223
+ _minY = _normalizeSelection4$[1],
1224
+ _normalizeSelection4$2 = _normalizeSelection4[1],
1225
+ _maxX = _normalizeSelection4$2[0],
1226
+ _maxY = _normalizeSelection4$2[1];
1130
1227
 
1131
1228
  var xCellDiff = Math.min(cellX - _minX, _maxX - cellX, 0);
1132
1229
  var yCellDiff = Math.min(cellY - _minY, _maxY - cellY, 0);
@@ -1173,7 +1270,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1173
1270
 
1174
1271
  var _insideSelection2 = _cellY >= minY && _cellY <= maxY + 1;
1175
1272
 
1176
- var _insideGroup = isBoundaryInsideGroup(_cellY, rowGroupKeys);
1273
+ var _insideGroup2 = isBoundaryInsideGroup(_cellY, rowGroupKeys);
1177
1274
 
1178
1275
  var _anchor4 = rowDrag.anchor,
1179
1276
  _scroll6 = rowDrag.scroll;
@@ -1184,10 +1281,10 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1184
1281
  _currentScroll3 = _getScrollPosition8[1];
1185
1282
 
1186
1283
  onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([0, _shift + _currentScroll3 - _scroll6]);
1187
- onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(_insideSelection2 || _insideGroup ? null : [[-1, _cellY], [-1, _cellY]]);
1284
+ onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(_insideSelection2 || _insideGroup2 ? null : [[-1, _cellY], [-1, _cellY]]);
1188
1285
  }
1189
1286
  }
1190
- }, [getMousePosition, getScrollPosition, getMouseHit, onCellWidthChange, onCellHeightChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onKnobAreaChange, onInvalidateRow, onInvalidateColumn]);
1287
+ }, [getMousePosition, getScrollPosition, getMouseHit, onCellWidthChange, onCellHeightChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onKnobAreaChange, onInvalidateRow, onInvalidateColumn, columnGroupKeys, rowGroupKeys]);
1191
1288
  var onDoubleClick = React.useCallback(function (e) {
1192
1289
  var pixelToCell = ref.current.cellLayout.pixelToCell;
1193
1290
  e.preventDefault();
@@ -1251,21 +1348,21 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1251
1348
  };
1252
1349
 
1253
1350
  var parseKnobOperation = function parseKnobOperation(knobArea, selection, sourceData, editData, cellReadOnly) {
1254
- var _normalizeSelection6 = normalizeSelection(knobArea),
1351
+ var _normalizeSelection5 = normalizeSelection(knobArea),
1352
+ _normalizeSelection5$ = _normalizeSelection5[0],
1353
+ kx1 = _normalizeSelection5$[0],
1354
+ ky1 = _normalizeSelection5$[1],
1355
+ _normalizeSelection5$2 = _normalizeSelection5[1],
1356
+ kx2 = _normalizeSelection5$2[0],
1357
+ ky2 = _normalizeSelection5$2[1];
1358
+
1359
+ var _normalizeSelection6 = normalizeSelection(selection),
1255
1360
  _normalizeSelection6$ = _normalizeSelection6[0],
1256
- kx1 = _normalizeSelection6$[0],
1257
- ky1 = _normalizeSelection6$[1],
1361
+ sx1 = _normalizeSelection6$[0],
1362
+ sy1 = _normalizeSelection6$[1],
1258
1363
  _normalizeSelection6$2 = _normalizeSelection6[1],
1259
- kx2 = _normalizeSelection6$2[0],
1260
- ky2 = _normalizeSelection6$2[1];
1261
-
1262
- var _normalizeSelection7 = normalizeSelection(selection),
1263
- _normalizeSelection7$ = _normalizeSelection7[0],
1264
- sx1 = _normalizeSelection7$[0],
1265
- sy1 = _normalizeSelection7$[1],
1266
- _normalizeSelection7$2 = _normalizeSelection7[1],
1267
- sx2 = _normalizeSelection7$2[0],
1268
- sy2 = _normalizeSelection7$2[1];
1364
+ sx2 = _normalizeSelection6$2[0],
1365
+ sy2 = _normalizeSelection6$2[1];
1269
1366
 
1270
1367
  var fx1 = kx1;
1271
1368
  var fy1 = ky1;
@@ -2114,7 +2211,7 @@ var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth,
2114
2211
  return start;
2115
2212
  };
2116
2213
 
2117
- var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, knobPosition, knobArea, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, dataOffset) {
2214
+ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset) {
2118
2215
  var canvas = context.canvas;
2119
2216
  var width = canvas.width,
2120
2217
  height = canvas.height;
@@ -2146,8 +2243,8 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2146
2243
  for (var _iterator = _createForOfIteratorHelperLoose(rows), _step; !(_step = _iterator()).done;) {
2147
2244
  var y = _step.value;
2148
2245
 
2149
- for (var _iterator8 = _createForOfIteratorHelperLoose(columns), _step8; !(_step8 = _iterator8()).done;) {
2150
- var x = _step8.value;
2246
+ for (var _iterator10 = _createForOfIteratorHelperLoose(columns), _step10; !(_step10 = _iterator10()).done;) {
2247
+ var x = _step10.value;
2151
2248
 
2152
2249
  var _left7 = columnToPixel(x);
2153
2250
 
@@ -2237,17 +2334,17 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2237
2334
  drawGridLineY(columnHeaderHeight, context.canvas.width);
2238
2335
 
2239
2336
  for (var _iterator2 = _createForOfIteratorHelperLoose(columns), _step2; !(_step2 = _iterator2()).done;) {
2240
- var _column = _step2.value;
2337
+ var _column2 = _step2.value;
2241
2338
 
2242
- var _right8 = columnToPixel(_column, 1);
2339
+ var _right8 = columnToPixel(_column2, 1);
2243
2340
 
2244
2341
  drawGridLineX(_right8, gridBottom);
2245
2342
  }
2246
2343
 
2247
2344
  for (var _iterator3 = _createForOfIteratorHelperLoose(rows), _step3; !(_step3 = _iterator3()).done;) {
2248
- var _row = _step3.value;
2345
+ var _row2 = _step3.value;
2249
2346
 
2250
- var _bottom8 = rowToPixel(_row, 1);
2347
+ var _bottom8 = rowToPixel(_row2, 1);
2251
2348
 
2252
2349
  drawGridLineY(_bottom8, gridRight);
2253
2350
  }
@@ -2270,8 +2367,11 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2270
2367
  var row = _step4.value;
2271
2368
  var content = "" + (row + 1);
2272
2369
  var isActive = isInRange(row, minY, maxY);
2273
- var isSelected = rowSelectionActive && !columnSelectionActive && isActive;
2274
- var style = isSelected ? HEADER_SELECTED_STYLE : isActive ? HEADER_ACTIVE_STYLE : NO_STYLE;
2370
+ var groupKey = rowGroupKeys(row);
2371
+ var isInRowGroup = groupKey != null && (selectedRowGroups === null || selectedRowGroups === void 0 ? void 0 : selectedRowGroups.has(groupKey));
2372
+ var isSelfSelected = rowSelectionActive && isActive;
2373
+ var isGroupSelected = rowSelectionActive && isInRowGroup;
2374
+ var style = isSelfSelected ? HEADER_SELECTED_STYLE : isGroupSelected ? HEADER_GROUP_SELECTED_STYLE : isActive ? HEADER_ACTIVE_STYLE : NO_STYLE;
2275
2375
 
2276
2376
  var _top2 = rowToPixel(row);
2277
2377
 
@@ -2294,7 +2394,11 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2294
2394
 
2295
2395
  var _isActive = isInRange(column, minX, maxX);
2296
2396
 
2297
- var selectedStyle = columnSelectionActive && !rowSelectionActive && _isActive ? HEADER_SELECTED_STYLE : NO_STYLE;
2397
+ var _groupKey = columnGroupKeys(column);
2398
+
2399
+ var isInColumnGroup = _groupKey != null && (selectedColumnGroups === null || selectedColumnGroups === void 0 ? void 0 : selectedColumnGroups.has(_groupKey));
2400
+ var isSelected = columnSelectionActive && !rowSelectionActive && (_isActive || isInColumnGroup);
2401
+ var selectedStyle = isSelected ? HEADER_SELECTED_STYLE : NO_STYLE;
2298
2402
  var activeStyle = _isActive ? HEADER_ACTIVE_STYLE : NO_STYLE;
2299
2403
 
2300
2404
  var _style = _extends({}, columnHeaderStyle(column), activeStyle, selectedStyle);
@@ -2373,30 +2477,46 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2373
2477
  if (dragOffset) {
2374
2478
  var shiftX = dragOffset[0],
2375
2479
  shiftY = dragOffset[1];
2480
+ var dragColumns = dragIndices[0],
2481
+ dragRows = dragIndices[1];
2482
+ context.fillStyle = COLORS.dragGhost;
2376
2483
 
2377
- var _resolveSelection = resolveSelection(selection, cellLayout),
2378
- _resolveSelection$ = _resolveSelection[0],
2379
- _left5 = _resolveSelection$[0],
2380
- _top5 = _resolveSelection$[1],
2381
- _resolveSelection$2 = _resolveSelection[1],
2382
- _right5 = _resolveSelection$2[0],
2383
- _bottom5 = _resolveSelection$2[1];
2484
+ if (dragColumns) {
2485
+ for (var _iterator7 = _createForOfIteratorHelperLoose(dragColumns), _step7; !(_step7 = _iterator7()).done;) {
2486
+ var _column = _step7.value;
2384
2487
 
2385
- context.fillStyle = COLORS.dragGhost;
2386
- context.fillRect(_left5 + shiftX, _top5 + shiftY, _right5 - _left5, _bottom5 - _top5);
2488
+ var _left5 = columnToPixel(_column);
2489
+
2490
+ var _right5 = columnToPixel(_column, 1);
2491
+
2492
+ context.fillRect(_left5 + shiftX, 0, _right5 - _left5, height);
2493
+ }
2494
+ }
2495
+
2496
+ if (dragRows) {
2497
+ for (var _iterator8 = _createForOfIteratorHelperLoose(dragRows), _step8; !(_step8 = _iterator8()).done;) {
2498
+ var _row = _step8.value;
2499
+
2500
+ var _top5 = rowToPixel(_row);
2501
+
2502
+ var _bottom5 = rowToPixel(_row, 1);
2503
+
2504
+ context.fillRect(0, _top5 + shiftY, width, _bottom5 - _top5);
2505
+ }
2506
+ }
2387
2507
  }
2388
2508
 
2389
2509
  if (dropTarget) {
2390
- var _resolveSelection2 = resolveSelection(dropTarget, cellLayout),
2391
- _resolveSelection2$ = _resolveSelection2[0],
2392
- _left6 = _resolveSelection2$[0],
2393
- _top6 = _resolveSelection2$[1],
2394
- _resolveSelection2$2 = _resolveSelection2[1],
2395
- _right6 = _resolveSelection2$2[0],
2396
- _bottom6 = _resolveSelection2$2[1];
2510
+ var _resolveSelection = resolveSelection(dropTarget, cellLayout),
2511
+ _resolveSelection$ = _resolveSelection[0],
2512
+ _left6 = _resolveSelection$[0],
2513
+ _top6 = _resolveSelection$[1],
2514
+ _resolveSelection$2 = _resolveSelection[1],
2515
+ _right6 = _resolveSelection$2[0],
2516
+ _bottom6 = _resolveSelection$2[1];
2397
2517
 
2398
2518
  context.strokeStyle = COLORS.dropTarget;
2399
- context.lineWidth = 2;
2519
+ context.lineWidth = 4;
2400
2520
 
2401
2521
  if (isColumnSelection(dropTarget)) {
2402
2522
  _right6 = _left6;
@@ -2436,11 +2556,11 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2436
2556
 
2437
2557
  context.textBaseline = 'middle';
2438
2558
 
2439
- for (var _iterator7 = _createForOfIteratorHelperLoose(rows), _step7; !(_step7 = _iterator7()).done;) {
2440
- var _y = _step7.value;
2559
+ for (var _iterator9 = _createForOfIteratorHelperLoose(rows), _step9; !(_step9 = _iterator9()).done;) {
2560
+ var _y = _step9.value;
2441
2561
 
2442
- for (var _iterator9 = _createForOfIteratorHelperLoose(columns), _step9; !(_step9 = _iterator9()).done;) {
2443
- var _x = _step9.value;
2562
+ for (var _iterator11 = _createForOfIteratorHelperLoose(columns), _step11; !(_step11 = _iterator11()).done;) {
2563
+ var _x = _step11.value;
2444
2564
 
2445
2565
  var _left9 = columnToPixel(_x);
2446
2566
 
@@ -2490,8 +2610,8 @@ var renderCell = function renderCell(context, cellContent, style, defaultCellSty
2490
2610
  var text = '' + cellContent;
2491
2611
  context.fillText(text, xx, yy);
2492
2612
  } else if (typeof cellContent === 'object') {
2493
- for (var _iterator10 = _createForOfIteratorHelperLoose(cellContent.items), _step10; !(_step10 = _iterator10()).done;) {
2494
- var obj = _step10.value;
2613
+ for (var _iterator12 = _createForOfIteratorHelperLoose(cellContent.items), _step12; !(_step12 = _iterator12()).done;) {
2614
+ var obj = _step12.value;
2495
2615
  var x = 0;
2496
2616
  var y = 0;
2497
2617
  var w = 0;
@@ -2746,33 +2866,37 @@ var Sheet = React.forwardRef(function (props, ref) {
2746
2866
  dragOffset = _useState5[0],
2747
2867
  setDragOffset = _useState5[1];
2748
2868
 
2749
- var _useState6 = React.useState(null),
2750
- dropTarget = _useState6[0],
2751
- setDropTarget = _useState6[1];
2869
+ var _useState6 = React.useState([null, null]),
2870
+ dragIndices = _useState6[0],
2871
+ setDragIndices = _useState6[1];
2872
+
2873
+ var _useState7 = React.useState(null),
2874
+ dropTarget = _useState7[0],
2875
+ setDropTarget = _useState7[1];
2752
2876
 
2753
- var _useState7 = React.useState(NO_CELL),
2754
- editCell = _useState7[0],
2755
- setEditCell = _useState7[1];
2877
+ var _useState8 = React.useState(NO_CELL),
2878
+ editCell = _useState8[0],
2879
+ setEditCell = _useState8[1];
2756
2880
 
2757
- var _useState8 = React.useState(selectionProp),
2758
- lastSelectionProp = _useState8[0],
2759
- setLastSelectionProp = _useState8[1];
2881
+ var _useState9 = React.useState(selectionProp),
2882
+ lastSelectionProp = _useState9[0],
2883
+ setLastSelectionProp = _useState9[1];
2760
2884
 
2761
2885
  if (lastSelectionProp !== selectionProp) {
2762
2886
  setLastSelectionProp(selectionProp);
2763
2887
  setSelection(selectionProp);
2764
2888
  }
2765
2889
 
2766
- var _useState9 = React.useState(''),
2767
- editValue = _useState9[0],
2768
- setEditValue = _useState9[1];
2890
+ var _useState10 = React.useState(''),
2891
+ editValue = _useState10[0],
2892
+ setEditValue = _useState10[1];
2769
2893
 
2770
- var _useState10 = React.useState(false),
2771
- arrowKeyCommitMode = _useState10[0],
2772
- setArrowKeyCommitMode = _useState10[1];
2894
+ var _useState11 = React.useState(false),
2895
+ arrowKeyCommitMode = _useState11[0],
2896
+ setArrowKeyCommitMode = _useState11[1];
2773
2897
 
2774
2898
  var _useResizeObserver = useResizeObserver({
2775
- ref: canvasRef
2899
+ ref: overlayRef
2776
2900
  }),
2777
2901
  _useResizeObserver$wi = _useResizeObserver.width,
2778
2902
  canvasWidth = _useResizeObserver$wi === void 0 ? 3000 : _useResizeObserver$wi,
@@ -2831,6 +2955,20 @@ var Sheet = React.forwardRef(function (props, ref) {
2831
2955
  return resolveSheetStyle(props.sheetStyle);
2832
2956
  }, [props.sheetStyle]);
2833
2957
  var secondarySelections = (_props$secondarySelec = props.secondarySelections) != null ? _props$secondarySelec : NO_SELECTIONS;
2958
+ var selectedColumnGroups = React.useMemo(function () {
2959
+ return props.columnGroupKeys ? new Set(mapSelectionColumns(selection)(function (x) {
2960
+ return columnGroupKeys(x);
2961
+ }).filter(function (x) {
2962
+ return x != null;
2963
+ })) : null;
2964
+ }, [props.columnGroupKeys, columnGroupKeys, selection]);
2965
+ var selectedRowGroups = React.useMemo(function () {
2966
+ return props.rowGroupKeys ? new Set(mapSelectionRows(selection)(function (y) {
2967
+ return rowGroupKeys(y);
2968
+ }).filter(function (x) {
2969
+ return x != null;
2970
+ })) : null;
2971
+ }, [props.rowGroupKeys, rowGroupKeys, selection]);
2834
2972
  var maxScrollX = maxScroll[0],
2835
2973
  maxScrollY = maxScroll[1];
2836
2974
  var editCellX = editCell[0],
@@ -2868,7 +3006,7 @@ var Sheet = React.forwardRef(function (props, ref) {
2868
3006
  }
2869
3007
  }, [visibleCells, props.onScrollChange]);
2870
3008
 
2871
- var changeSelection = function changeSelection(newSelection, scrollTo, toHead, dragOperation) {
3009
+ var changeSelection = function changeSelection(newSelection, scrollTo, toHead) {
2872
3010
  if (scrollTo === void 0) {
2873
3011
  scrollTo = true;
2874
3012
  }
@@ -2877,31 +3015,16 @@ var Sheet = React.forwardRef(function (props, ref) {
2877
3015
  toHead = false;
2878
3016
  }
2879
3017
 
2880
- if (dragOperation === void 0) {
2881
- dragOperation = false;
2882
- }
2883
-
2884
- if (!dragOperation) {
2885
- if (isColumnSelection(newSelection) && columnGroupKeys) {
2886
- newSelection = expandSelectionToColumnGroups(newSelection, columnGroupKeys);
2887
- }
2888
-
2889
- if (isRowSelection(newSelection) && rowGroupKeys) {
2890
- newSelection = expandSelectionToRowGroups(newSelection, rowGroupKeys);
2891
- }
2892
- }
2893
-
2894
3018
  if (!isSameSelection(selection, newSelection)) {
2895
- setSelection(newSelection);
3019
+ setSelection(validateSelection(newSelection));
2896
3020
  }
2897
3021
 
2898
3022
  var overlay = overlayRef.current;
2899
3023
  if (!overlay) return;
2900
3024
 
2901
3025
  if (scrollTo) {
2902
- var _newSelection = newSelection,
2903
- anchor = _newSelection[0],
2904
- head = _newSelection[1];
3026
+ var anchor = newSelection[0],
3027
+ head = newSelection[1];
2905
3028
  scrollToCell(overlay, toHead ? head : anchor, [canvasWidth, canvasHeight], [freezeColumns, freezeRows], dataOffset, maxScroll, cellLayout, function (dataOffset, maxScroll) {
2906
3029
  setDataOffset(dataOffset);
2907
3030
  setMaxScroll(maxScroll);
@@ -2966,7 +3089,7 @@ var Sheet = React.forwardRef(function (props, ref) {
2966
3089
  useClipboardPaste(textAreaRef, selection, changeSelection, props.onChange, cellReadOnly);
2967
3090
  var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
2968
3091
 
2969
- var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, startEditingCell, commitEditingCell, setKnobArea, setDragOffset, setDropTarget, changeSelection, props.cacheLayout ? columnLayout.clearAfter : undefined, props.cacheLayout ? rowLayout.clearAfter : undefined, props.onChange, props.onColumnOrderChange, props.onRowOrderChange, props.onCellWidthChange, props.onCellHeightChange, props.onRightClick, props.dontCommitEditOnSelectionChange),
3092
+ var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, startEditingCell, commitEditingCell, setKnobArea, setDragIndices, setDragOffset, setDropTarget, changeSelection, props.cacheLayout ? columnLayout.clearAfter : undefined, props.cacheLayout ? rowLayout.clearAfter : undefined, props.onChange, props.onColumnOrderChange, props.onRowOrderChange, props.onCellWidthChange, props.onCellHeightChange, props.onRightClick, props.dontCommitEditOnSelectionChange, props.dontChangeSelectionOnOrderChange),
2970
3093
  mouseHandlers = _useMouse.mouseHandlers,
2971
3094
  knobPosition = _useMouse.knobPosition;
2972
3095
 
@@ -2984,12 +3107,12 @@ var Sheet = React.forwardRef(function (props, ref) {
2984
3107
  }
2985
3108
 
2986
3109
  var animationFrameId = window.requestAnimationFrame(function () {
2987
- hitmapRef.current = renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, knobPosition, knobArea, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, dataOffset);
3110
+ hitmapRef.current = renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset);
2988
3111
  });
2989
3112
  return function () {
2990
3113
  window.cancelAnimationFrame(animationFrameId);
2991
3114
  };
2992
- }, [cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, knobPosition, knobArea, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, dataOffset]);
3115
+ }, [cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, knobPosition, knobArea, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset]);
2993
3116
 
2994
3117
  var onKeyDown = function onKeyDown(e) {
2995
3118
  if (e.key === 'Escape') {
@@ -3105,9 +3228,9 @@ var Sheet = React.forwardRef(function (props, ref) {
3105
3228
  e.preventDefault();
3106
3229
  };
3107
3230
 
3108
- var _useState11 = React.useState(''),
3109
- lastEditKey = _useState11[0],
3110
- setLastEditKey = _useState11[1];
3231
+ var _useState12 = React.useState(''),
3232
+ lastEditKey = _useState12[0],
3233
+ setLastEditKey = _useState12[1];
3111
3234
 
3112
3235
  var editTextPosition = ORIGIN;
3113
3236
  var editTextWidth = 0;