sheet-happens 0.0.36 → 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
@@ -78,7 +78,7 @@ var MAX_SEARCHABLE_INDEX = 65536;
78
78
  var MAX_XY = [MAX_SEARCHABLE_INDEX, MAX_SEARCHABLE_INDEX];
79
79
  var COLORS = {
80
80
  selectionBorder: '#1a66ff',
81
- selectionBackground: '#e8f0ff',
81
+ selectionBackground: '#d8e6ff80',
82
82
  gridLine: '#0000001f',
83
83
  dragGhost: '#1a66ff30',
84
84
  dropTarget: '#1a66ff',
@@ -88,7 +88,10 @@ var COLORS = {
88
88
  headerActive: '#e8f0ff',
89
89
  headerActiveText: '#1a66ff',
90
90
  headerSelected: '#1a66ff',
91
- headerSelectedText: '#ffffff'
91
+ headerSelectedGroup: '#1a66ff70',
92
+ headerSelectedText: '#ffffff',
93
+ headerSelectedGroupText: '#ffffff',
94
+ shadowColor: '#000000'
92
95
  };
93
96
  var SIZES = {
94
97
  knobArea: 6,
@@ -98,7 +101,9 @@ var SIZES = {
98
101
  minimumHeight: 22,
99
102
  resizeZone: 4,
100
103
  scrollZone: 50,
101
- scrollSpeed: 30
104
+ scrollSpeed: 30,
105
+ shadowBlur: 12,
106
+ shadowOpacity: 0.05
102
107
  };
103
108
  var DEFAULT_CELL_STYLE = {
104
109
  textAlign: 'left',
@@ -129,11 +134,15 @@ var HEADER_SELECTED_STYLE = {
129
134
  backgroundColor: COLORS.headerSelected,
130
135
  color: COLORS.headerSelectedText
131
136
  };
137
+ var HEADER_GROUP_SELECTED_STYLE = {
138
+ backgroundColor: COLORS.headerSelectedGroup,
139
+ color: COLORS.headerSelectedGroupText
140
+ };
132
141
  var ARROW_KEYS = {
133
- 'ArrowRight': 'right',
134
- 'ArrowLeft': 'left',
135
- 'ArrowUp': 'up',
136
- 'ArrowDown': 'down'
142
+ ArrowRight: 'right',
143
+ ArrowLeft: 'left',
144
+ ArrowUp: 'up',
145
+ ArrowDown: 'down'
137
146
  };
138
147
 
139
148
  var clamp = function clamp(x, min, max) {
@@ -176,6 +185,9 @@ var mulXY = function mulXY(a, b) {
176
185
  var maxXY = function maxXY(a, b) {
177
186
  return [Math.max(a[0], b[0]), Math.max(a[1], b[1])];
178
187
  };
188
+ var minXY = function minXY(a, b) {
189
+ return [Math.min(a[0], b[0]), Math.min(a[1], b[1])];
190
+ };
179
191
  var clampXY = function clampXY(p, min, max) {
180
192
  if (max === void 0) {
181
193
  max = [Infinity, Infinity];
@@ -200,6 +212,50 @@ var isSameSelection = function isSameSelection(a, b) {
200
212
  b2 = b[1];
201
213
  return isSameXY(a1, b1) && isSameXY(a2, b2);
202
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
+ };
203
259
  var isMaybeRowSelection = function isMaybeRowSelection(selection) {
204
260
  var _selection$ = selection[0],
205
261
  left = _selection$[0],
@@ -251,39 +307,86 @@ var isEmptySelection = function isEmptySelection(selection) {
251
307
  return left === -1 && right === -1 && top === -1 && bottom === -1;
252
308
  };
253
309
  var isPointInsideSelection = function isPointInsideSelection(selection, point) {
254
- var _normalizeSelection = normalizeSelection(selection),
255
- _normalizeSelection$ = _normalizeSelection[0],
256
- left = _normalizeSelection$[0],
257
- top = _normalizeSelection$[1],
258
- _normalizeSelection$2 = _normalizeSelection[1],
259
- right = _normalizeSelection$2[0],
260
- 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];
261
317
 
262
318
  var x = point[0],
263
319
  y = point[1];
264
320
  return x >= left && x <= right && y >= top && y <= bottom;
265
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
+ };
266
332
  var normalizeSelection = function normalizeSelection(selection) {
267
- var _selection$13 = selection[0],
268
- left = _selection$13[0],
269
- top = _selection$13[1],
270
- _selection$14 = selection[1],
271
- right = _selection$14[0],
272
- bottom = _selection$14[1];
333
+ var anchor = selection[0],
334
+ head = selection[1];
335
+ return [minXY(anchor, head), maxXY(anchor, head)];
336
+ };
337
+ var orientSelection = function orientSelection(normalized, to) {
338
+ var _normalized$ = normalized[0],
339
+ left = _normalized$[0],
340
+ top = _normalized$[1],
341
+ _normalized$2 = normalized[1],
342
+ right = _normalized$2[0],
343
+ bottom = _normalized$2[1];
344
+ var anchor = to[0],
345
+ head = to[1];
346
+ var ax = anchor[0],
347
+ ay = anchor[1];
348
+ var hx = head[0],
349
+ hy = head[1];
350
+ var swapX = (ax - hx || 1) * (right - left || 1) < 0;
351
+ var swapY = (ay - hy || 1) * (bottom - top || 1) < 0;
352
+ return [[swapX ? right : left, swapY ? bottom : top], [swapX ? left : right, swapY ? top : bottom]];
353
+ };
273
354
 
274
- if (left > right) {
275
- var _ref = [right, left];
276
- left = _ref[0];
277
- right = _ref[1];
278
- }
355
+ var LIMIT = 1000;
356
+
357
+ var scanGroup = function scanGroup(keys, index, direction, matchKeys) {
358
+ var i = 1;
359
+ var limit = direction > 0 ? LIMIT : Math.min(LIMIT, index + 1);
279
360
 
280
- if (top > bottom) {
281
- var _ref2 = [bottom, top];
282
- top = _ref2[0];
283
- bottom = _ref2[1];
361
+ for (; i < limit; i++) {
362
+ var key = keys(index + i * direction);
363
+ if (key == null || !matchKeys.has(key)) break;
284
364
  }
285
365
 
286
- return [[left, top], [right, bottom]];
366
+ return index + (i - 1) * direction;
367
+ };
368
+
369
+ var expandSelectionToRowOrColumnGroups = function expandSelectionToRowOrColumnGroups(selection, groupKeys, matchKeys, coordinate) {
370
+ if (!matchKeys) return selection;
371
+
372
+ var _normalizeSelection = normalizeSelection(selection),
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;
383
+ var oriented = orientSelection(expanded, selection);
384
+ return oriented;
385
+ };
386
+ var isBoundaryInsideGroup = function isBoundaryInsideGroup(index, groupKeys) {
387
+ var before = groupKeys(index - 1);
388
+ var after = groupKeys(index);
389
+ return before != null && after != null && before === after;
287
390
  };
288
391
 
289
392
  var createRowOrColumnProp = function createRowOrColumnProp(rowColProp, defaultValue) {
@@ -429,7 +532,7 @@ var findInDisplayData = function findInDisplayData(displayData, start, direction
429
532
  return maxXY(cell, [0, 0]);
430
533
  };
431
534
 
432
- var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, 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) {
433
536
  var _useState = React.useState(null),
434
537
  hitTarget = _useState[0],
435
538
  setHitTarget = _useState[1];
@@ -579,31 +682,26 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
579
682
  return;
580
683
  }
581
684
 
582
- var _normalizeSelection2 = normalizeSelection(selection),
583
- _normalizeSelection2$ = _normalizeSelection2[0],
584
- minX = _normalizeSelection2$[0],
585
- minY = _normalizeSelection2$[1],
586
- _normalizeSelection2$2 = _normalizeSelection2[1],
587
- maxX = _normalizeSelection2$2[0],
588
- maxY = _normalizeSelection2$2[1];
589
-
590
- var selectedColumns = [];
591
- var selectedRows = [];
592
-
593
- for (var i = minX; i <= maxX; i++) {
594
- selectedColumns.push(i);
595
- }
596
-
597
- for (var _i = minY; _i <= maxY; _i++) {
598
- selectedRows.push(_i);
599
- }
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
+ });
600
698
 
601
699
  if (!hideColumnHeaders && y < getIndentY()) {
602
700
  if (onColumnOrderChange) {
603
701
  var start = columnToPixel(minX) + SIZES.resizeZone;
604
702
  var end = columnToPixel(maxX, 1) - SIZES.resizeZone;
605
703
 
606
- if (isInRange(x, start, end)) {
704
+ if (isInRange(x, start, end) || selectedColumnGroups) {
607
705
  for (var _iterator2 = _createForOfIteratorHelperLoose(columns), _step2; !(_step2 = _iterator2()).done;) {
608
706
  var index = _step2.value;
609
707
 
@@ -611,9 +709,31 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
611
709
 
612
710
  var _end = columnToPixel(index, 1);
613
711
 
614
- 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)) {
615
713
  window.document.body.style.cursor = 'grabbing';
616
- 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
+
617
737
  var size = columnToPixel(maxX, 1) - columnToPixel(minX);
618
738
 
619
739
  var _getScrollPosition = getScrollPosition(e),
@@ -626,6 +746,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
626
746
  indices: indices
627
747
  });
628
748
  onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([0, 0]);
749
+ onDragIndicesChange === null || onDragIndicesChange === void 0 ? void 0 : onDragIndicesChange([dragIndices, null]);
629
750
  return;
630
751
  }
631
752
  }
@@ -667,7 +788,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
667
788
 
668
789
  var _end2 = rowToPixel(maxY, 1) - SIZES.resizeZone;
669
790
 
670
- if (isInRange(y, _start2, _end2)) {
791
+ if (isInRange(y, _start2, _end2) || selectedRowGroups) {
671
792
  for (var _iterator4 = _createForOfIteratorHelperLoose(rows), _step4; !(_step4 = _iterator4()).done;) {
672
793
  var _index2 = _step4.value;
673
794
 
@@ -675,9 +796,38 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
675
796
 
676
797
  var _end3 = rowToPixel(_index2, 1);
677
798
 
678
- 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)) {
679
800
  window.document.body.style.cursor = 'grabbing';
680
- 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
+ }
681
831
 
682
832
  var _size2 = rowToPixel(maxY, 1) - rowToPixel(minY);
683
833
 
@@ -691,6 +841,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
691
841
  indices: _indices2
692
842
  });
693
843
  onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([0, 0]);
844
+ onDragIndicesChange === null || onDragIndicesChange === void 0 ? void 0 : onDragIndicesChange([null, _dragIndices]);
694
845
  return;
695
846
  }
696
847
  }
@@ -765,7 +916,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
765
916
 
766
917
  setDraggingSelection(true);
767
918
  onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([anchor, head], scrollTo, true);
768
- }, [getMousePosition, getScrollPosition, getMouseHit, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onKnobAreaChange, onSelectionChange, onCommit, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow]);
919
+ }, [getMousePosition, getScrollPosition, getMouseHit, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onKnobAreaChange, onSelectionChange, onCommit, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, dontCommitEditOnSelectionChange, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups]);
769
920
  var onPointerUp = React.useCallback(function (e) {
770
921
  var _getMouseHit;
771
922
 
@@ -795,18 +946,19 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
795
946
 
796
947
  if (xy && (columnDrag || rowDrag)) {
797
948
  window.document.body.style.cursor = 'auto';
949
+ onDragIndicesChange === null || onDragIndicesChange === void 0 ? void 0 : onDragIndicesChange([null, null]);
798
950
  onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange(null);
799
951
  onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(null);
800
952
  var x = xy[0],
801
953
  y = xy[1];
802
954
 
803
- var _normalizeSelection3 = normalizeSelection(selection),
804
- _normalizeSelection3$ = _normalizeSelection3[0],
805
- minX = _normalizeSelection3$[0],
806
- minY = _normalizeSelection3$[1],
807
- _normalizeSelection3$2 = _normalizeSelection3[1],
808
- maxX = _normalizeSelection3$2[0],
809
- 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];
810
962
 
811
963
  var cellX = pixelToColumn(Math.max(x, getIndentX()), 0.5);
812
964
  var cellY = pixelToRow(Math.max(y, getIndentY()), 0.5);
@@ -814,10 +966,14 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
814
966
  if (columnDrag) {
815
967
  var indices = columnDrag.indices;
816
968
  var insideSelection = cellX >= minX && cellX <= maxX + 1;
969
+ var insideGroup = selectedColumnGroups === null || selectedColumnGroups === void 0 ? void 0 : selectedColumnGroups.has(columnGroupKeys(x));
817
970
 
818
- if (!insideSelection) {
819
- var order = cellX > minX ? cellX - indices.length : cellX;
820
- onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([[order, minY], [order + maxX - minX, maxY]]);
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]]));
821
977
  onColumnOrderChange === null || onColumnOrderChange === void 0 ? void 0 : onColumnOrderChange(indices, order);
822
978
  onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(Math.min(minX, order));
823
979
  }
@@ -828,10 +984,16 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
828
984
 
829
985
  var _insideSelection = cellY >= minY && cellY <= maxY + 1;
830
986
 
831
- if (!_insideSelection) {
832
- var _order = cellY > minY ? cellY - _indices4.length : cellY;
987
+ var _insideGroup = selectedRowGroups === null || selectedRowGroups === void 0 ? void 0 : selectedRowGroups.has(rowGroupKeys(y));
988
+
989
+ if (!_insideSelection && !_insideGroup) {
990
+ var _preceding = _indices4.filter(function (i) {
991
+ return i < cellY;
992
+ });
833
993
 
834
- onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([[minX, _order], [maxX, _order + maxY - minY]]);
994
+ var _order = cellY - _preceding.length;
995
+
996
+ dontChangeSelectionOnOrderChange || (onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([[minX, _order], [maxX, _order + _indices4.length - 1]]));
835
997
  onRowOrderChange === null || onRowOrderChange === void 0 ? void 0 : onRowOrderChange(_indices4, _order);
836
998
  onInvalidateRow === null || onInvalidateRow === void 0 ? void 0 : onInvalidateRow(Math.min(minY, _order));
837
999
  }
@@ -857,7 +1019,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
857
1019
  var obj = hitTarget.obj;
858
1020
  (_obj$onClick = obj.onClick) === null || _obj$onClick === void 0 ? void 0 : _obj$onClick.call(obj, e);
859
1021
  }
860
- }, [getMousePosition, getMouseHit, onChange, onSelectionChange, onKnobAreaChange, onDropTargetChange, onColumnOrderChange, onRowOrderChange]);
1022
+ }, [getMousePosition, getMouseHit, onChange, onSelectionChange, onKnobAreaChange, onDropTargetChange, onColumnOrderChange, onRowOrderChange, dontChangeSelectionOnOrderChange]);
861
1023
  var onPointerMove = React.useCallback(function (e) {
862
1024
  var _ref$current3 = ref.current,
863
1025
  selection = _ref$current3.selection,
@@ -903,13 +1065,13 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
903
1065
  var x = xy[0],
904
1066
  y = xy[1];
905
1067
 
906
- var _normalizeSelection4 = normalizeSelection(selection),
907
- _normalizeSelection4$ = _normalizeSelection4[0],
908
- minX = _normalizeSelection4$[0],
909
- minY = _normalizeSelection4$[1],
910
- _normalizeSelection4$2 = _normalizeSelection4[1],
911
- maxX = _normalizeSelection4$2[0],
912
- 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];
913
1075
 
914
1076
  var isDragging = columnResize || columnDrag || rowResize || rowDrag || draggingRowSelection || draggingColumnSelection;
915
1077
 
@@ -919,7 +1081,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
919
1081
  var start = columnToPixel(minX) + SIZES.resizeZone;
920
1082
  var end = columnToPixel(maxX, 1) - SIZES.resizeZone;
921
1083
 
922
- if (isInRange(x, start, end)) {
1084
+ if (isInRange(x, start, end) || selectedColumnGroups) {
923
1085
  for (var _iterator6 = _createForOfIteratorHelperLoose(columns), _step6; !(_step6 = _iterator6()).done;) {
924
1086
  var index = _step6.value;
925
1087
 
@@ -927,7 +1089,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
927
1089
 
928
1090
  var _end4 = columnToPixel(index, 1);
929
1091
 
930
- 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)) {
931
1093
  window.document.body.style.cursor = 'grab';
932
1094
  return;
933
1095
  }
@@ -954,7 +1116,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
954
1116
 
955
1117
  var _end5 = rowToPixel(maxY, 1) - SIZES.resizeZone;
956
1118
 
957
- if (isInRange(y, _start5, _end5)) {
1119
+ if (isInRange(y, _start5, _end5) || selectedRowGroups) {
958
1120
  for (var _iterator8 = _createForOfIteratorHelperLoose(rows), _step8; !(_step8 = _iterator8()).done;) {
959
1121
  var _index5 = _step8.value;
960
1122
 
@@ -962,7 +1124,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
962
1124
 
963
1125
  var _end6 = rowToPixel(_index5, 1);
964
1126
 
965
- 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)) {
966
1128
  window.document.body.style.cursor = 'grab';
967
1129
  return;
968
1130
  }
@@ -1055,13 +1217,13 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1055
1217
  cellX = _pixelToCell[0],
1056
1218
  cellY = _pixelToCell[1];
1057
1219
 
1058
- var _normalizeSelection5 = normalizeSelection(selection),
1059
- _normalizeSelection5$ = _normalizeSelection5[0],
1060
- _minX = _normalizeSelection5$[0],
1061
- _minY = _normalizeSelection5$[1],
1062
- _normalizeSelection5$2 = _normalizeSelection5[1],
1063
- _maxX = _normalizeSelection5$2[0],
1064
- _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];
1065
1227
 
1066
1228
  var xCellDiff = Math.min(cellX - _minX, _maxX - cellX, 0);
1067
1229
  var yCellDiff = Math.min(cellY - _minY, _maxY - cellY, 0);
@@ -1091,6 +1253,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1091
1253
  var _cellX = pixelToColumn(Math.max(_x, getIndentX()), 0.5);
1092
1254
 
1093
1255
  var insideSelection = _cellX >= minX && _cellX <= maxX + 1;
1256
+ var insideGroup = isBoundaryInsideGroup(_cellX, columnGroupKeys);
1094
1257
  var _anchor3 = columnDrag.anchor,
1095
1258
  _scroll5 = columnDrag.scroll;
1096
1259
  var shift = _x - _anchor3;
@@ -1099,7 +1262,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1099
1262
  _currentScroll2 = _getScrollPosition7[0];
1100
1263
 
1101
1264
  onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([shift + _currentScroll2 - _scroll5, 0]);
1102
- onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(insideSelection ? null : [[_cellX, -1], [_cellX, -1]]);
1265
+ onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(insideSelection || insideGroup ? null : [[_cellX, -1], [_cellX, -1]]);
1103
1266
  }
1104
1267
 
1105
1268
  if (rowDrag) {
@@ -1107,6 +1270,8 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1107
1270
 
1108
1271
  var _insideSelection2 = _cellY >= minY && _cellY <= maxY + 1;
1109
1272
 
1273
+ var _insideGroup2 = isBoundaryInsideGroup(_cellY, rowGroupKeys);
1274
+
1110
1275
  var _anchor4 = rowDrag.anchor,
1111
1276
  _scroll6 = rowDrag.scroll;
1112
1277
 
@@ -1116,10 +1281,10 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1116
1281
  _currentScroll3 = _getScrollPosition8[1];
1117
1282
 
1118
1283
  onDragOffsetChange === null || onDragOffsetChange === void 0 ? void 0 : onDragOffsetChange([0, _shift + _currentScroll3 - _scroll6]);
1119
- onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(_insideSelection2 ? null : [[-1, _cellY], [-1, _cellY]]);
1284
+ onDropTargetChange === null || onDropTargetChange === void 0 ? void 0 : onDropTargetChange(_insideSelection2 || _insideGroup2 ? null : [[-1, _cellY], [-1, _cellY]]);
1120
1285
  }
1121
1286
  }
1122
- }, [getMousePosition, getScrollPosition, getMouseHit, onCellWidthChange, onCellHeightChange]);
1287
+ }, [getMousePosition, getScrollPosition, getMouseHit, onCellWidthChange, onCellHeightChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onKnobAreaChange, onInvalidateRow, onInvalidateColumn, columnGroupKeys, rowGroupKeys]);
1123
1288
  var onDoubleClick = React.useCallback(function (e) {
1124
1289
  var pixelToCell = ref.current.cellLayout.pixelToCell;
1125
1290
  e.preventDefault();
@@ -1183,21 +1348,21 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1183
1348
  };
1184
1349
 
1185
1350
  var parseKnobOperation = function parseKnobOperation(knobArea, selection, sourceData, editData, cellReadOnly) {
1186
- 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),
1187
1360
  _normalizeSelection6$ = _normalizeSelection6[0],
1188
- kx1 = _normalizeSelection6$[0],
1189
- ky1 = _normalizeSelection6$[1],
1361
+ sx1 = _normalizeSelection6$[0],
1362
+ sy1 = _normalizeSelection6$[1],
1190
1363
  _normalizeSelection6$2 = _normalizeSelection6[1],
1191
- kx2 = _normalizeSelection6$2[0],
1192
- ky2 = _normalizeSelection6$2[1];
1193
-
1194
- var _normalizeSelection7 = normalizeSelection(selection),
1195
- _normalizeSelection7$ = _normalizeSelection7[0],
1196
- sx1 = _normalizeSelection7$[0],
1197
- sy1 = _normalizeSelection7$[1],
1198
- _normalizeSelection7$2 = _normalizeSelection7[1],
1199
- sx2 = _normalizeSelection7$2[0],
1200
- sy2 = _normalizeSelection7$2[1];
1364
+ sx2 = _normalizeSelection6$2[0],
1365
+ sy2 = _normalizeSelection6$2[1];
1201
1366
 
1202
1367
  var fx1 = kx1;
1203
1368
  var fy1 = ky1;
@@ -2011,6 +2176,8 @@ var makeIntMap = function makeIntMap(initialSize) {
2011
2176
  };
2012
2177
 
2013
2178
  var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
2179
+ var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
2180
+
2014
2181
  return {
2015
2182
  freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
2016
2183
  freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
@@ -2019,7 +2186,10 @@ var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
2019
2186
  hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
2020
2187
  hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
2021
2188
  columnHeaderHeight: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideColumnHeaders ? 1 : SIZES.headerHeight,
2022
- rowHeaderWidth: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideRowHeaders ? 1 : SIZES.headerWidth
2189
+ rowHeaderWidth: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideRowHeaders ? 1 : SIZES.headerWidth,
2190
+ shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
2191
+ shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
2192
+ shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
2023
2193
  };
2024
2194
  };
2025
2195
  var resolveCellStyle = function resolveCellStyle(optionalStyle, defaultStyle) {
@@ -2041,7 +2211,7 @@ var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth,
2041
2211
  return start;
2042
2212
  };
2043
2213
 
2044
- 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) {
2045
2215
  var canvas = context.canvas;
2046
2216
  var width = canvas.width,
2047
2217
  height = canvas.height;
@@ -2051,11 +2221,16 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2051
2221
  rowHeaderWidth = sheetStyle.rowHeaderWidth,
2052
2222
  columnHeaderHeight = sheetStyle.columnHeaderHeight,
2053
2223
  freezeColumns = sheetStyle.freezeColumns,
2054
- freezeRows = sheetStyle.freezeRows;
2224
+ freezeRows = sheetStyle.freezeRows,
2225
+ shadowBlur = sheetStyle.shadowBlur,
2226
+ shadowColor = sheetStyle.shadowColor,
2227
+ shadowOpacity = sheetStyle.shadowOpacity;
2055
2228
  var columns = visibleCells.columns,
2056
2229
  rows = visibleCells.rows;
2057
2230
  var columnToPixel = cellLayout.columnToPixel,
2058
- rowToPixel = cellLayout.rowToPixel;
2231
+ rowToPixel = cellLayout.rowToPixel,
2232
+ columnToAbsolute = cellLayout.columnToAbsolute,
2233
+ rowToAbsolute = cellLayout.rowToAbsolute;
2059
2234
  var clickables = [];
2060
2235
  var freeze = [freezeColumns, freezeRows];
2061
2236
  var indent = [rowHeaderWidth, columnHeaderHeight];
@@ -2063,12 +2238,13 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2063
2238
  context.clearRect(0, 0, width, height);
2064
2239
  context.fillStyle = 'white';
2065
2240
  context.fillRect(0, 0, width, height);
2241
+ context.shadowColor = '#00000080';
2066
2242
 
2067
2243
  for (var _iterator = _createForOfIteratorHelperLoose(rows), _step; !(_step = _iterator()).done;) {
2068
2244
  var y = _step.value;
2069
2245
 
2070
- for (var _iterator8 = _createForOfIteratorHelperLoose(columns), _step8; !(_step8 = _iterator8()).done;) {
2071
- var x = _step8.value;
2246
+ for (var _iterator10 = _createForOfIteratorHelperLoose(columns), _step10; !(_step10 = _iterator10()).done;) {
2247
+ var x = _step10.value;
2072
2248
 
2073
2249
  var _left7 = columnToPixel(x);
2074
2250
 
@@ -2142,15 +2318,15 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2142
2318
 
2143
2319
  var drawGridLineX = function drawGridLineX(x, height) {
2144
2320
  context.beginPath();
2145
- context.moveTo(x - .5, 0);
2146
- context.lineTo(x - .5, height);
2321
+ context.moveTo(x - 0.5, 0);
2322
+ context.lineTo(x - 0.5, height);
2147
2323
  context.stroke();
2148
2324
  };
2149
2325
 
2150
2326
  var drawGridLineY = function drawGridLineY(y, width) {
2151
2327
  context.beginPath();
2152
- context.moveTo(0, y - .5);
2153
- context.lineTo(width, y - .5);
2328
+ context.moveTo(0, y - 0.5);
2329
+ context.lineTo(width, y - 0.5);
2154
2330
  context.stroke();
2155
2331
  };
2156
2332
 
@@ -2158,17 +2334,17 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2158
2334
  drawGridLineY(columnHeaderHeight, context.canvas.width);
2159
2335
 
2160
2336
  for (var _iterator2 = _createForOfIteratorHelperLoose(columns), _step2; !(_step2 = _iterator2()).done;) {
2161
- var _column = _step2.value;
2337
+ var _column2 = _step2.value;
2162
2338
 
2163
- var _right8 = columnToPixel(_column, 1);
2339
+ var _right8 = columnToPixel(_column2, 1);
2164
2340
 
2165
2341
  drawGridLineX(_right8, gridBottom);
2166
2342
  }
2167
2343
 
2168
2344
  for (var _iterator3 = _createForOfIteratorHelperLoose(rows), _step3; !(_step3 = _iterator3()).done;) {
2169
- var _row = _step3.value;
2345
+ var _row2 = _step3.value;
2170
2346
 
2171
- var _bottom8 = rowToPixel(_row, 1);
2347
+ var _bottom8 = rowToPixel(_row2, 1);
2172
2348
 
2173
2349
  drawGridLineY(_bottom8, gridRight);
2174
2350
  }
@@ -2191,8 +2367,11 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2191
2367
  var row = _step4.value;
2192
2368
  var content = "" + (row + 1);
2193
2369
  var isActive = isInRange(row, minY, maxY);
2194
- var isSelected = rowSelectionActive && !columnSelectionActive && isActive;
2195
- 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;
2196
2375
 
2197
2376
  var _top2 = rowToPixel(row);
2198
2377
 
@@ -2215,7 +2394,11 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2215
2394
 
2216
2395
  var _isActive = isInRange(column, minX, maxX);
2217
2396
 
2218
- 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;
2219
2402
  var activeStyle = _isActive ? HEADER_ACTIVE_STYLE : NO_STYLE;
2220
2403
 
2221
2404
  var _style = _extends({}, columnHeaderStyle(column), activeStyle, selectedStyle);
@@ -2294,30 +2477,46 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2294
2477
  if (dragOffset) {
2295
2478
  var shiftX = dragOffset[0],
2296
2479
  shiftY = dragOffset[1];
2480
+ var dragColumns = dragIndices[0],
2481
+ dragRows = dragIndices[1];
2482
+ context.fillStyle = COLORS.dragGhost;
2297
2483
 
2298
- var _resolveSelection = resolveSelection(selection, cellLayout),
2299
- _resolveSelection$ = _resolveSelection[0],
2300
- _left5 = _resolveSelection$[0],
2301
- _top5 = _resolveSelection$[1],
2302
- _resolveSelection$2 = _resolveSelection[1],
2303
- _right5 = _resolveSelection$2[0],
2304
- _bottom5 = _resolveSelection$2[1];
2484
+ if (dragColumns) {
2485
+ for (var _iterator7 = _createForOfIteratorHelperLoose(dragColumns), _step7; !(_step7 = _iterator7()).done;) {
2486
+ var _column = _step7.value;
2305
2487
 
2306
- context.fillStyle = COLORS.dragGhost;
2307
- 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
+ }
2308
2507
  }
2309
2508
 
2310
2509
  if (dropTarget) {
2311
- var _resolveSelection2 = resolveSelection(dropTarget, cellLayout),
2312
- _resolveSelection2$ = _resolveSelection2[0],
2313
- _left6 = _resolveSelection2$[0],
2314
- _top6 = _resolveSelection2$[1],
2315
- _resolveSelection2$2 = _resolveSelection2[1],
2316
- _right6 = _resolveSelection2$2[0],
2317
- _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];
2318
2517
 
2319
2518
  context.strokeStyle = COLORS.dropTarget;
2320
- context.lineWidth = 2;
2519
+ context.lineWidth = 4;
2321
2520
 
2322
2521
  if (isColumnSelection(dropTarget)) {
2323
2522
  _right6 = _left6;
@@ -2330,13 +2529,38 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2330
2529
  context.strokeRect(_left6 - 1, _top6 - 1, _right6 - _left6, _bottom6 - _top6);
2331
2530
  }
2332
2531
 
2532
+ var scrollX = dataOffset[0],
2533
+ scrollY = dataOffset[1];
2534
+ var hasRowShadow = freezeRows > 0 && scrollY > 0;
2535
+ var hasColumnShadow = freezeColumns > 0 && scrollX > 0;
2536
+
2537
+ if (hasRowShadow || hasColumnShadow) {
2538
+ if (hasRowShadow) {
2539
+ var h = columnHeaderHeight + rowToAbsolute(freezeRows);
2540
+ var gradient = context.createLinearGradient(0, h, 0, h + shadowBlur);
2541
+ halfShadowGradient(gradient, shadowColor, shadowOpacity);
2542
+ context.fillStyle = gradient;
2543
+ context.fillRect(0, h, width, shadowBlur);
2544
+ }
2545
+
2546
+ if (hasColumnShadow) {
2547
+ var w = rowHeaderWidth + columnToAbsolute(freezeColumns);
2548
+
2549
+ var _gradient = context.createLinearGradient(w, 0, w + shadowBlur, 0);
2550
+
2551
+ halfShadowGradient(_gradient, shadowColor, shadowOpacity);
2552
+ context.fillStyle = _gradient;
2553
+ context.fillRect(w, 0, shadowBlur, height);
2554
+ }
2555
+ }
2556
+
2333
2557
  context.textBaseline = 'middle';
2334
2558
 
2335
- for (var _iterator7 = _createForOfIteratorHelperLoose(rows), _step7; !(_step7 = _iterator7()).done;) {
2336
- var _y = _step7.value;
2559
+ for (var _iterator9 = _createForOfIteratorHelperLoose(rows), _step9; !(_step9 = _iterator9()).done;) {
2560
+ var _y = _step9.value;
2337
2561
 
2338
- for (var _iterator9 = _createForOfIteratorHelperLoose(columns), _step9; !(_step9 = _iterator9()).done;) {
2339
- var _x = _step9.value;
2562
+ for (var _iterator11 = _createForOfIteratorHelperLoose(columns), _step11; !(_step11 = _iterator11()).done;) {
2563
+ var _x = _step11.value;
2340
2564
 
2341
2565
  var _left9 = columnToPixel(_x);
2342
2566
 
@@ -2386,8 +2610,8 @@ var renderCell = function renderCell(context, cellContent, style, defaultCellSty
2386
2610
  var text = '' + cellContent;
2387
2611
  context.fillText(text, xx, yy);
2388
2612
  } else if (typeof cellContent === 'object') {
2389
- for (var _iterator10 = _createForOfIteratorHelperLoose(cellContent.items), _step10; !(_step10 = _iterator10()).done;) {
2390
- var obj = _step10.value;
2613
+ for (var _iterator12 = _createForOfIteratorHelperLoose(cellContent.items), _step12; !(_step12 = _iterator12()).done;) {
2614
+ var obj = _step12.value;
2391
2615
  var x = 0;
2392
2616
  var y = 0;
2393
2617
  var w = 0;
@@ -2595,8 +2819,27 @@ var excelHeaderString = function excelHeaderString(num) {
2595
2819
  return s || '';
2596
2820
  };
2597
2821
 
2822
+ var halfShadowGradient = function halfShadowGradient(gradient, rgb, opacity) {
2823
+ var hex = function hex(x) {
2824
+ return ('0' + Math.round(x).toString(16)).slice(-2);
2825
+ };
2826
+
2827
+ var ease = function ease(x) {
2828
+ return 1.0 - Math.sin(x * Math.PI / 2);
2829
+ };
2830
+
2831
+ var adjust = function adjust(x) {
2832
+ return 1.0 - Math.pow(1.0 - x, 2.2);
2833
+ };
2834
+
2835
+ for (var i = 0; i <= 16; ++i) {
2836
+ var f = i / 16;
2837
+ gradient.addColorStop(f, rgb + hex(adjust(opacity * ease(f) * 0.5) * 255));
2838
+ }
2839
+ };
2840
+
2598
2841
  var Sheet = React.forwardRef(function (props, ref) {
2599
- var _props$selection, _props$secondarySelec, _props$inputComponent;
2842
+ var _props$selection, _props$secondarySelec, _props$cacheLayout, _props$inputComponent;
2600
2843
 
2601
2844
  var canvasRef = React.useRef(null);
2602
2845
  var overlayRef = React.useRef(null);
@@ -2623,33 +2866,37 @@ var Sheet = React.forwardRef(function (props, ref) {
2623
2866
  dragOffset = _useState5[0],
2624
2867
  setDragOffset = _useState5[1];
2625
2868
 
2626
- var _useState6 = React.useState(null),
2627
- dropTarget = _useState6[0],
2628
- setDropTarget = _useState6[1];
2869
+ var _useState6 = React.useState([null, null]),
2870
+ dragIndices = _useState6[0],
2871
+ setDragIndices = _useState6[1];
2629
2872
 
2630
- var _useState7 = React.useState(NO_CELL),
2631
- editCell = _useState7[0],
2632
- setEditCell = _useState7[1];
2873
+ var _useState7 = React.useState(null),
2874
+ dropTarget = _useState7[0],
2875
+ setDropTarget = _useState7[1];
2633
2876
 
2634
- var _useState8 = React.useState(selectionProp),
2635
- lastSelectionProp = _useState8[0],
2636
- setLastSelectionProp = _useState8[1];
2877
+ var _useState8 = React.useState(NO_CELL),
2878
+ editCell = _useState8[0],
2879
+ setEditCell = _useState8[1];
2880
+
2881
+ var _useState9 = React.useState(selectionProp),
2882
+ lastSelectionProp = _useState9[0],
2883
+ setLastSelectionProp = _useState9[1];
2637
2884
 
2638
2885
  if (lastSelectionProp !== selectionProp) {
2639
2886
  setLastSelectionProp(selectionProp);
2640
2887
  setSelection(selectionProp);
2641
2888
  }
2642
2889
 
2643
- var _useState9 = React.useState(''),
2644
- editValue = _useState9[0],
2645
- setEditValue = _useState9[1];
2890
+ var _useState10 = React.useState(''),
2891
+ editValue = _useState10[0],
2892
+ setEditValue = _useState10[1];
2646
2893
 
2647
- var _useState10 = React.useState(false),
2648
- arrowKeyCommitMode = _useState10[0],
2649
- setArrowKeyCommitMode = _useState10[1];
2894
+ var _useState11 = React.useState(false),
2895
+ arrowKeyCommitMode = _useState11[0],
2896
+ setArrowKeyCommitMode = _useState11[1];
2650
2897
 
2651
2898
  var _useResizeObserver = useResizeObserver({
2652
- ref: canvasRef
2899
+ ref: overlayRef
2653
2900
  }),
2654
2901
  _useResizeObserver$wi = _useResizeObserver.width,
2655
2902
  canvasWidth = _useResizeObserver$wi === void 0 ? 3000 : _useResizeObserver$wi,
@@ -2680,6 +2927,12 @@ var Sheet = React.forwardRef(function (props, ref) {
2680
2927
  var canOrderRow = React.useMemo(function () {
2681
2928
  return createRowOrColumnProp(props.canOrderRow, true);
2682
2929
  }, [props.canOrderRow]);
2930
+ var rowGroupKeys = React.useMemo(function () {
2931
+ return createRowOrColumnProp(props.rowGroupKeys, null);
2932
+ }, [props.rowGroupKeys]);
2933
+ var columnGroupKeys = React.useMemo(function () {
2934
+ return createRowOrColumnProp(props.columnGroupKeys, null);
2935
+ }, [props.columnGroupKeys]);
2683
2936
  var cellReadOnly = React.useMemo(function () {
2684
2937
  return createCellProp(props.readOnly, false);
2685
2938
  }, [props.readOnly]);
@@ -2702,22 +2955,38 @@ var Sheet = React.forwardRef(function (props, ref) {
2702
2955
  return resolveSheetStyle(props.sheetStyle);
2703
2956
  }, [props.sheetStyle]);
2704
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]);
2705
2972
  var maxScrollX = maxScroll[0],
2706
2973
  maxScrollY = maxScroll[1];
2707
2974
  var editCellX = editCell[0],
2708
2975
  editCellY = editCell[1];
2709
2976
  var editMode = editCellX !== -1 && editCellY !== -1;
2977
+ var shouldCacheLayout = ((_props$cacheLayout = props.cacheLayout) != null ? _props$cacheLayout : false) !== false;
2978
+ var layoutVersion = typeof props.cacheLayout === 'number' ? props.cacheLayout : 0;
2710
2979
  var columnLayout = React.useMemo(function () {
2711
2980
  return makeLayoutCache(cellWidth);
2712
- }, [props.cacheLayout ? null : cellWidth]);
2981
+ }, [shouldCacheLayout ? layoutVersion : cellWidth]);
2713
2982
  var rowLayout = React.useMemo(function () {
2714
2983
  return makeLayoutCache(cellHeight);
2715
- }, [props.cacheLayout ? null : cellHeight]);
2984
+ }, [shouldCacheLayout ? layoutVersion : cellHeight]);
2716
2985
  React.useMemo(function () {
2717
- if (!props.cacheLayout) return;
2986
+ if (!shouldCacheLayout) return;
2718
2987
  columnLayout.setSizer(cellWidth);
2719
2988
  rowLayout.setSizer(cellHeight);
2720
- }, [props.cacheLayout, cellWidth, cellHeight]);
2989
+ }, [shouldCacheLayout, layoutVersion, cellWidth, cellHeight]);
2721
2990
  var freezeColumns = sheetStyle.freezeColumns,
2722
2991
  freezeRows = sheetStyle.freezeRows,
2723
2992
  rowHeaderWidth = sheetStyle.rowHeaderWidth,
@@ -2747,7 +3016,7 @@ var Sheet = React.forwardRef(function (props, ref) {
2747
3016
  }
2748
3017
 
2749
3018
  if (!isSameSelection(selection, newSelection)) {
2750
- setSelection(newSelection);
3019
+ setSelection(validateSelection(newSelection));
2751
3020
  }
2752
3021
 
2753
3022
  var overlay = overlayRef.current;
@@ -2820,7 +3089,7 @@ var Sheet = React.forwardRef(function (props, ref) {
2820
3089
  useClipboardPaste(textAreaRef, selection, changeSelection, props.onChange, cellReadOnly);
2821
3090
  var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
2822
3091
 
2823
- var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, 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),
2824
3093
  mouseHandlers = _useMouse.mouseHandlers,
2825
3094
  knobPosition = _useMouse.knobPosition;
2826
3095
 
@@ -2838,12 +3107,12 @@ var Sheet = React.forwardRef(function (props, ref) {
2838
3107
  }
2839
3108
 
2840
3109
  var animationFrameId = window.requestAnimationFrame(function () {
2841
- 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);
2842
3111
  });
2843
3112
  return function () {
2844
3113
  window.cancelAnimationFrame(animationFrameId);
2845
3114
  };
2846
- }, [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]);
2847
3116
 
2848
3117
  var onKeyDown = function onKeyDown(e) {
2849
3118
  if (e.key === 'Escape') {
@@ -2959,9 +3228,9 @@ var Sheet = React.forwardRef(function (props, ref) {
2959
3228
  e.preventDefault();
2960
3229
  };
2961
3230
 
2962
- var _useState11 = React.useState(''),
2963
- lastEditKey = _useState11[0],
2964
- setLastEditKey = _useState11[1];
3231
+ var _useState12 = React.useState(''),
3232
+ lastEditKey = _useState12[0],
3233
+ setLastEditKey = _useState12[1];
2965
3234
 
2966
3235
  var editTextPosition = ORIGIN;
2967
3236
  var editTextWidth = 0;
@@ -3019,8 +3288,8 @@ var Sheet = React.forwardRef(function (props, ref) {
3019
3288
  borderBottom: '1px solid #ddd'
3020
3289
  };
3021
3290
  var canvasStyles = {
3022
- width: 'calc(100% - 14px)',
3023
- height: 'calc(100% - 15px)',
3291
+ width: canvasWidth,
3292
+ height: canvasHeight,
3024
3293
  outline: '1px solid #ddd'
3025
3294
  };
3026
3295
 
@@ -3028,7 +3297,6 @@ var Sheet = React.forwardRef(function (props, ref) {
3028
3297
  delete canvasStyles['outline'];
3029
3298
  delete overlayDivStyles['borderBottom'];
3030
3299
  overlayDivClassName = '';
3031
- canvasStyles.width = 'calc(100%)';
3032
3300
  }
3033
3301
 
3034
3302
  var renderedInside = React.useMemo(function () {