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