sheet-happens 0.0.43 → 0.0.45

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
@@ -69,13 +69,13 @@ var styles = {"sheetscroll":"_PxIi8"};
69
69
  var INITIAL_MAX_SCROLL = [2000, 1000];
70
70
  var ORIGIN = [0, 0];
71
71
  var ONE_ONE = [1, 1];
72
+ var NEG_NEG = [-1, -1];
72
73
  var NO_CELL = [-1, -1];
73
74
  var NO_SELECTION = [NO_CELL, NO_CELL];
74
75
  var NO_SELECTIONS = [];
75
76
  var NO_CLICKABLES = [];
76
77
  var NO_STYLE = {};
77
- var MAX_SEARCHABLE_INDEX = 65536;
78
- var MAX_XY = [MAX_SEARCHABLE_INDEX, MAX_SEARCHABLE_INDEX];
78
+ var MAX_SEARCHABLE_INDEX = 100000;
79
79
  var COLORS = {
80
80
  selectionBorder: '#1a66ff',
81
81
  selectionBackground: '#d8e6ff80',
@@ -145,9 +145,6 @@ var ARROW_KEYS = {
145
145
  ArrowDown: 'down'
146
146
  };
147
147
 
148
- var clamp = function clamp(x, min, max) {
149
- return Math.max(Math.min(max, x), min);
150
- };
151
148
  var seq = function seq(n, s, d) {
152
149
  if (s === void 0) {
153
150
  s = 0;
@@ -188,13 +185,6 @@ var maxXY = function maxXY(a, b) {
188
185
  var minXY = function minXY(a, b) {
189
186
  return [Math.min(a[0], b[0]), Math.min(a[1], b[1])];
190
187
  };
191
- var clampXY = function clampXY(p, min, max) {
192
- if (max === void 0) {
193
- max = [Infinity, Infinity];
194
- }
195
-
196
- return [clamp(p[0], min[0], max[0]), clamp(p[1], min[1], max[1])];
197
- };
198
188
  var getDirectionStep = function getDirectionStep(direction) {
199
189
  if (direction === 'left') return [-1, 0];
200
190
  if (direction === 'right') return [1, 0];
@@ -435,6 +425,52 @@ var createCellProp = function createCellProp(cellProp, defaultValue) {
435
425
  };
436
426
  }
437
427
  };
428
+ var createRowOrColumnStyledProp = function createRowOrColumnStyledProp(rowColProp, defaultValue) {
429
+ if (Array.isArray(rowColProp)) {
430
+ return function (rowOrColIndex) {
431
+ if (rowOrColIndex >= 0 && rowOrColIndex < rowColProp.length) {
432
+ return rowColProp[rowOrColIndex];
433
+ } else {
434
+ return defaultValue;
435
+ }
436
+ };
437
+ } else if (typeof rowColProp === 'function') {
438
+ return rowColProp;
439
+ } else if (rowColProp !== null && rowColProp !== undefined) {
440
+ return function () {
441
+ return rowColProp;
442
+ };
443
+ } else {
444
+ return function () {
445
+ return defaultValue;
446
+ };
447
+ }
448
+ };
449
+ var createCellStyledProp = function createCellStyledProp(cellProp, defaultValue) {
450
+ if (Array.isArray(cellProp)) {
451
+ return function (x, y) {
452
+ if (y >= 0 && y < cellProp.length) {
453
+ if (x >= 0 && x < cellProp[y].length) {
454
+ return cellProp[y][x];
455
+ } else {
456
+ return defaultValue;
457
+ }
458
+ } else {
459
+ return defaultValue;
460
+ }
461
+ };
462
+ } else if (typeof cellProp === 'function') {
463
+ return cellProp;
464
+ } else if (cellProp !== null && cellProp !== undefined) {
465
+ return function () {
466
+ return cellProp;
467
+ };
468
+ } else {
469
+ return function () {
470
+ return defaultValue;
471
+ };
472
+ }
473
+ };
438
474
  var findApproxMaxEditDataIndex = function findApproxMaxEditDataIndex(editData) {
439
475
  var x = 0;
440
476
  var y = 0;
@@ -500,8 +536,13 @@ var findApproxMaxEditDataIndex = function findApproxMaxEditDataIndex(editData) {
500
536
  };
501
537
  var findInDisplayData = function findInDisplayData(displayData, start, direction) {
502
538
  var step = getDirectionStep(direction);
503
- var cell = clampXY(start, ORIGIN, MAX_XY);
504
- var first = displayData.apply(void 0, addXY(cell, step));
539
+ var cell = maxXY(start, ORIGIN);
540
+
541
+ var _addXY = addXY(cell, step),
542
+ x = _addXY[0],
543
+ y = _addXY[1];
544
+
545
+ var first = displayData(x, y, DEFAULT_CELL_STYLE);
505
546
  var firstFilled = first !== '' && first !== null && first !== undefined;
506
547
 
507
548
  if (!firstFilled) {
@@ -511,9 +552,11 @@ var findInDisplayData = function findInDisplayData(displayData, start, direction
511
552
  var _cell = cell,
512
553
  cellX = _cell[0],
513
554
  cellY = _cell[1];
555
+ var maxX = cellX + MAX_SEARCHABLE_INDEX - 1;
556
+ var maxY = cellY + MAX_SEARCHABLE_INDEX - 1;
514
557
 
515
- while (cellX <= MAX_SEARCHABLE_INDEX && cellY <= MAX_SEARCHABLE_INDEX && cellX >= 0 && cellY >= 0) {
516
- var data = displayData(cellX, cellY);
558
+ while (cellX < maxX && cellY < maxY && cellX >= 0 && cellY >= 0) {
559
+ var data = displayData(cellX, cellY, DEFAULT_CELL_STYLE);
517
560
 
518
561
  if (firstFilled && (data === '' || data === null || data === undefined)) {
519
562
  return subXY(cell, step);
@@ -532,7 +575,7 @@ var findInDisplayData = function findInDisplayData(displayData, start, direction
532
575
  return maxXY(cell, [0, 0]);
533
576
  };
534
577
 
535
- var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, onEdit, onCommit, onKnobAreaChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onInvalidateColumn, onInvalidateRow, onChange, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onRightClick, dontCommitEditOnSelectionChange, dontChangeSelectionOnOrderChange) {
578
+ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, onEdit, onCommit, onKnobAreaChange, onDragIndicesChange, onDragOffsetChange, onDropTargetChange, onSelectionChange, onFocusChange, onInvalidateColumn, onInvalidateRow, onChange, onColumnOrderChange, onRowOrderChange, onCellWidthChange, onCellHeightChange, onRightClick, dontCommitEditOnSelectionChange, dontChangeSelectionOnOrderChange) {
536
579
  var _useState = React.useState(null),
537
580
  hitTarget = _useState[0],
538
581
  setHitTarget = _useState[1];
@@ -673,6 +716,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
673
716
  columns = _ref$current$visibleC.columns,
674
717
  rows = _ref$current$visibleC.rows,
675
718
  knobPosition = _ref$current.knobPosition;
719
+ onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(true);
676
720
  if (e.button !== 0) return;
677
721
  (_e$target2 = e.target) === null || _e$target2 === void 0 ? void 0 : (_e$target2$setPointer = _e$target2.setPointerCapture) === null || _e$target2$setPointer === void 0 ? void 0 : _e$target2$setPointer.call(_e$target2, e.pointerId);
678
722
  var xy = getMousePosition(e);
@@ -939,6 +983,7 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
939
983
  pixelToRow = _ref$current2$cellLay.pixelToRow,
940
984
  getIndentX = _ref$current2$cellLay.getIndentX,
941
985
  getIndentY = _ref$current2$cellLay.getIndentY;
986
+ onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(true);
942
987
 
943
988
  if (knobArea && draggingKnob) {
944
989
  var changes = parseKnobOperation(knobArea, selection, sourceData, editData, cellReadOnly);
@@ -1174,7 +1219,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1174
1219
 
1175
1220
  var newWidth = Math.max(size + x - anchor + scroll - currentScroll, SIZES.minimumWidth * indices.length);
1176
1221
  onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(indices[0] - 1);
1177
- onCellWidthChange(indices, newWidth / indices.length);
1222
+ onCellWidthChange(indices, indices.map(function (_) {
1223
+ return Math.round(newWidth / indices.length);
1224
+ }));
1178
1225
  }
1179
1226
 
1180
1227
  return;
@@ -1192,7 +1239,9 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1192
1239
 
1193
1240
  var newHeight = Math.max(_size4 + y - _anchor + _scroll4 - _currentScroll, SIZES.minimumHeight * _indices5.length);
1194
1241
  onInvalidateRow === null || onInvalidateRow === void 0 ? void 0 : onInvalidateRow(_indices5[0] - 1);
1195
- onCellHeightChange(_indices5, newHeight / _indices5.length);
1242
+ onCellHeightChange(_indices5, _indices5.map(function (_) {
1243
+ return newHeight / _indices5.length;
1244
+ }));
1196
1245
  }
1197
1246
 
1198
1247
  return;
@@ -1295,15 +1344,18 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1295
1344
  selection = _ref$current4.selection,
1296
1345
  _ref$current4$cellLay = _ref$current4.cellLayout,
1297
1346
  pixelToCell = _ref$current4$cellLay.pixelToCell,
1298
- columnToPixel = _ref$current4$cellLay.columnToPixel;
1347
+ columnToPixel = _ref$current4$cellLay.columnToPixel,
1348
+ getIndentY = _ref$current4$cellLay.getIndentY;
1299
1349
  e.preventDefault();
1300
1350
  if (e.shiftKey) return;
1301
1351
  var xy = getMousePosition(e);
1302
1352
  if (!xy) return;
1303
- var x = xy[0];
1353
+ var x = xy[0],
1354
+ y = xy[1];
1355
+ var indentY = getIndentY();
1304
1356
  var columns = visibleCells.columns;
1305
1357
 
1306
- if (onCellWidthChange) {
1358
+ if (onCellWidthChange && y < indentY) {
1307
1359
  var autosized = [];
1308
1360
 
1309
1361
  for (var _iterator10 = _createForOfIteratorHelperLoose(columns), _step10; !(_step10 = _iterator10()).done;) {
@@ -1327,9 +1379,11 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1327
1379
  for (var _i = 0, _autosized = autosized; _i < _autosized.length; _i++) {
1328
1380
  var column = _autosized[_i];
1329
1381
  onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(column - 1);
1330
- onCellWidthChange([column], getAutoSizeWidth(column));
1331
1382
  }
1332
1383
 
1384
+ onCellWidthChange(autosized, autosized.map(function (column) {
1385
+ return getAutoSizeWidth(column);
1386
+ }));
1333
1387
  if (autosized.length) return;
1334
1388
  }
1335
1389
 
@@ -1497,6 +1551,162 @@ var parseKnobOperation = function parseKnobOperation(knobArea, selection, source
1497
1551
  return changes;
1498
1552
  };
1499
1553
 
1554
+ var useKeyboard = function useKeyboard(arrowKeyCommitMode, overlayRef, cellReadOnly, displayData, editCell, editMode, focused, rawSelection, selection, onEdit, onCommit, onCancel, onSelectionChange, onFocusChange, onClipboardCopy, onChange) {
1555
+ var onInputKeyDown = function onInputKeyDown(e) {
1556
+ if (e.key === 'Escape') {
1557
+ onCancel === null || onCancel === void 0 ? void 0 : onCancel();
1558
+ return;
1559
+ }
1560
+
1561
+ var direction = e.key === 'Enter' ? 'down' : e.key === 'Tab' ? 'right' : arrowKeyCommitMode ? ARROW_KEYS[e.key] : null;
1562
+
1563
+ if (direction) {
1564
+ e.preventDefault();
1565
+ var step = getDirectionStep(direction);
1566
+ var head = maxXY(addXY(editCell, step), ORIGIN);
1567
+ onCommit === null || onCommit === void 0 ? void 0 : onCommit();
1568
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([head, head]);
1569
+ }
1570
+ };
1571
+
1572
+ var onGridKeyDown = function onGridKeyDown(e) {
1573
+ if (editMode && arrowKeyCommitMode && e.key in ARROW_KEYS) {
1574
+ onCommit === null || onCommit === void 0 ? void 0 : onCommit();
1575
+ return;
1576
+ }
1577
+
1578
+ if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'v') {
1579
+ return;
1580
+ }
1581
+
1582
+ if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'c') {
1583
+ onClipboardCopy === null || onClipboardCopy === void 0 ? void 0 : onClipboardCopy(false);
1584
+ return;
1585
+ }
1586
+
1587
+ if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'x') {
1588
+ onClipboardCopy === null || onClipboardCopy === void 0 ? void 0 : onClipboardCopy(true);
1589
+ return;
1590
+ }
1591
+
1592
+ if (e.key === 'Backspace' || e.key === 'Delete') {
1593
+ var _normalizeSelection = normalizeSelection(selection),
1594
+ _normalizeSelection$ = _normalizeSelection[0],
1595
+ x1 = _normalizeSelection$[0],
1596
+ y1 = _normalizeSelection$[1],
1597
+ _normalizeSelection$2 = _normalizeSelection[1],
1598
+ x2 = _normalizeSelection$2[0],
1599
+ y2 = _normalizeSelection$2[1];
1600
+
1601
+ if (isRowSelection(selection)) {
1602
+ x1 = 0;
1603
+ x2 = MAX_SEARCHABLE_INDEX;
1604
+ }
1605
+
1606
+ if (isColumnSelection(selection)) {
1607
+ y1 = 0;
1608
+ y2 = MAX_SEARCHABLE_INDEX;
1609
+ }
1610
+
1611
+ var changes = [];
1612
+
1613
+ for (var y = y1; y <= y2; y++) {
1614
+ for (var x = x1; x <= x2; x++) {
1615
+ if (!cellReadOnly(x, y)) {
1616
+ changes.push({
1617
+ x: x,
1618
+ y: y,
1619
+ value: null
1620
+ });
1621
+ }
1622
+ }
1623
+ }
1624
+
1625
+ onChange === null || onChange === void 0 ? void 0 : onChange(changes);
1626
+ return;
1627
+ }
1628
+
1629
+ if (isEmptySelection(selection)) {
1630
+ return;
1631
+ }
1632
+
1633
+ if (e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode >= 96 && e.keyCode <= 105 || e.keyCode >= 65 && e.keyCode <= 90 || e.key === 'Enter' || e.key === '-' || e.key === '.' || e.key === ',') {
1634
+ var cell = selection[0];
1635
+ var cellX = cell[0],
1636
+ cellY = cell[1];
1637
+
1638
+ if (cellReadOnly(cellX, cellY)) {
1639
+ return;
1640
+ }
1641
+
1642
+ onEdit === null || onEdit === void 0 ? void 0 : onEdit(cell, e.key !== 'Enter');
1643
+ return;
1644
+ }
1645
+
1646
+ e.preventDefault();
1647
+
1648
+ if (e.key in ARROW_KEYS) {
1649
+ var anchor = rawSelection[0],
1650
+ head = rawSelection[1];
1651
+ var direction = ARROW_KEYS[e.key];
1652
+ var step = getDirectionStep(direction);
1653
+ var shift = e.shiftKey;
1654
+
1655
+ if (e.metaKey || e.ctrlKey) {
1656
+ head = findInDisplayData(displayData, head, direction);
1657
+ } else {
1658
+ var limit = shift ? isRowSelection(selection) ? [-1, 0] : isColumnSelection(selection) ? [0, -1] : NEG_NEG : ORIGIN;
1659
+ head = maxXY(addXY(head, step), limit);
1660
+ }
1661
+
1662
+ if (!shift) {
1663
+ anchor = head;
1664
+ }
1665
+
1666
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([anchor, head], true, true);
1667
+ return;
1668
+ }
1669
+ };
1670
+
1671
+ var onGridFocus = function onGridFocus() {
1672
+ onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(true);
1673
+ };
1674
+
1675
+ var onGridBlur = function onGridBlur() {
1676
+ onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(false);
1677
+ };
1678
+
1679
+ React.useLayoutEffect(function () {
1680
+ var overlay = overlayRef.current;
1681
+
1682
+ if (!overlay) {
1683
+ return;
1684
+ }
1685
+
1686
+ if (editMode || !focused) {
1687
+ return;
1688
+ }
1689
+
1690
+ if (document.activeElement === overlay) {
1691
+ return;
1692
+ }
1693
+
1694
+ var activeTagName = document.activeElement.tagName.toLowerCase();
1695
+
1696
+ if (!(activeTagName === 'div' && document.activeElement.contentEditable === 'true' || activeTagName === 'input' || activeTagName === 'textarea' || activeTagName === 'select')) {
1697
+ overlay.focus({
1698
+ preventScroll: true
1699
+ });
1700
+ }
1701
+ }, [editMode, focused]);
1702
+ return {
1703
+ onInputKeyDown: onInputKeyDown,
1704
+ onGridFocus: onGridFocus,
1705
+ onGridBlur: onGridBlur,
1706
+ onGridKeyDown: onGridKeyDown
1707
+ };
1708
+ };
1709
+
1500
1710
  var useScroll = function useScroll(offset, maxScroll, cellLayout, onOffsetChange, onMaxScrollChange) {
1501
1711
  return React.useCallback(function (e) {
1502
1712
  if (!e.target || !(e.target instanceof Element)) {
@@ -1654,42 +1864,6 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
1654
1864
  }
1655
1865
  };
1656
1866
 
1657
- var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
1658
- var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
1659
-
1660
- return {
1661
- freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
1662
- freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
1663
- hideColumnHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideColumnHeaders) || false,
1664
- hideRowHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideRowHeaders) || false,
1665
- hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
1666
- hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
1667
- columnHeaderHeight: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideColumnHeaders ? 1 : SIZES.headerHeight,
1668
- rowHeaderWidth: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideRowHeaders ? 1 : SIZES.headerWidth,
1669
- shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
1670
- shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
1671
- shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
1672
- };
1673
- };
1674
- var resolveCellStyle = function resolveCellStyle(optionalStyle, defaultStyle) {
1675
- return _extends({}, defaultStyle, optionalStyle);
1676
- };
1677
- var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth, alignment) {
1678
- if (alignment === void 0) {
1679
- alignment = style.textAlign;
1680
- }
1681
-
1682
- if (alignment === 'left') {
1683
- return start + style.marginLeft;
1684
- } else if (alignment === 'center') {
1685
- return start + cellSize * 0.5 - imageWidth / 2;
1686
- } else if (alignment === 'right') {
1687
- return start + (cellSize - style.marginRight - imageWidth);
1688
- }
1689
-
1690
- return start;
1691
- };
1692
-
1693
1867
  var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth) {
1694
1868
  var context = React.useMemo(function () {
1695
1869
  return document.createElement('canvas').getContext('2d');
@@ -1698,9 +1872,8 @@ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle,
1698
1872
  if (!context) return 0;
1699
1873
 
1700
1874
  var getWidth = function getWidth(cellContent, style) {
1701
- var finalStyle = resolveCellStyle(style, DEFAULT_CELL_STYLE);
1702
- context.font = finalStyle.weight + ' ' + finalStyle.fontSize + 'px ' + finalStyle.fontFamily;
1703
- var inlineMargin = finalStyle.marginLeft + finalStyle.marginRight;
1875
+ context.font = style.weight + ' ' + style.fontSize + 'px ' + style.fontFamily;
1876
+ var inlineMargin = style.marginLeft + style.marginRight;
1704
1877
 
1705
1878
  if (typeof cellContent === 'string' || typeof cellContent === 'number') {
1706
1879
  var _context$measureText = context.measureText(cellContent.toString()),
@@ -1725,7 +1898,7 @@ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle,
1725
1898
  }
1726
1899
 
1727
1900
  if (obj.horizontalAlign === 'right') {
1728
- extraWidth += _width;
1901
+ extraWidth += style.textAlign === 'right' ? _width * 2 : _width;
1729
1902
  } else {
1730
1903
  _maxWidth = Math.max(_maxWidth, _width);
1731
1904
  }
@@ -1738,19 +1911,23 @@ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle,
1738
1911
  };
1739
1912
 
1740
1913
  var maxWidth = SIZES.minimumWidth;
1741
- var headerContent = columnHeaders(x);
1914
+
1915
+ var headerStyle = _extends({}, DEFAULT_COLUMN_HEADER_STYLE, columnHeaderStyle(x));
1916
+
1917
+ var headerContent = columnHeaders(x, headerStyle);
1742
1918
 
1743
1919
  if (headerContent) {
1744
- var headerStyle = columnHeaderStyle(x);
1745
1920
  maxWidth = Math.max(maxWidth, getWidth(headerContent, headerStyle));
1746
1921
  }
1747
1922
 
1748
1923
  for (var _iterator2 = _createForOfIteratorHelperLoose(rows), _step2; !(_step2 = _iterator2()).done;) {
1749
1924
  var y = _step2.value;
1750
- var cellContent = displayData(x, y);
1925
+
1926
+ var style = _extends({}, DEFAULT_CELL_STYLE, cellStyle(x, y));
1927
+
1928
+ var cellContent = displayData(x, y, style);
1751
1929
 
1752
1930
  if (cellContent != null) {
1753
- var style = cellStyle(x, y);
1754
1931
  maxWidth = Math.max(maxWidth, getWidth(cellContent, style));
1755
1932
  }
1756
1933
  }
@@ -1760,90 +1937,349 @@ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle,
1760
1937
  return getAutoSizeWidth;
1761
1938
  };
1762
1939
 
1763
- var useClipboardCopy = function useClipboardCopy(textAreaRef, selection, editMode, editData) {
1940
+ // A type of promise-like that resolves synchronously and supports only one observer
1941
+
1942
+ const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
1943
+
1944
+ const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
1945
+
1946
+ // Asynchronously call a function and send errors to recovery continuation
1947
+ function _catch(body, recover) {
1948
+ try {
1949
+ var result = body();
1950
+ } catch(e) {
1951
+ return recover(e);
1952
+ }
1953
+ if (result && result.then) {
1954
+ return result.then(void 0, recover);
1955
+ }
1956
+ return result;
1957
+ }
1958
+
1959
+ var EMPTY_TABLE = {
1960
+ rows: []
1961
+ };
1962
+ var useClipboardTable = function useClipboardTable() {
1963
+ var _useState = React.useState(),
1964
+ peek = _useState[0],
1965
+ setPeek = _useState[1];
1966
+
1764
1967
  React.useLayoutEffect(function () {
1765
- var textArea = textAreaRef.current;
1766
- if (!textArea) return;
1767
- if (editMode) return;
1768
- if (isEmptySelection(selection)) return;
1769
- var v = formatSelectionAsTSV(selection, editData);
1968
+ var softRefresh = function softRefresh() {
1969
+ return Promise.resolve(_catch(function () {
1970
+ return Promise.resolve(navigator.permissions.query({
1971
+ name: 'clipboard-read'
1972
+ })).then(function (status) {
1973
+ if (status.state !== 'granted') return;
1974
+ hardRefresh();
1975
+ });
1976
+ }, function () {}));
1977
+ };
1978
+
1979
+ var hardRefresh = function hardRefresh() {
1980
+ try {
1981
+ var _temp3 = _catch(function () {
1982
+ return Promise.resolve(navigator.clipboard.read()).then(function (items) {
1983
+ var item = items[0];
1984
+
1985
+ var _temp = function () {
1986
+ if (item) {
1987
+ return Promise.resolve(parseClipboardTable(item)).then(function (peek) {
1988
+ setPeek(peek);
1989
+ });
1990
+ } else {
1991
+ setPeek(EMPTY_TABLE);
1992
+ }
1993
+ }();
1994
+
1995
+ if (_temp && _temp.then) return _temp.then(function () {});
1996
+ });
1997
+ }, function () {});
1770
1998
 
1771
- if (v.match(/^[\t\n]*$/)) {
1772
- v = ' ' + v;
1999
+ return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(function () {}) : void 0);
2000
+ } catch (e) {
2001
+ return Promise.reject(e);
2002
+ }
2003
+ };
2004
+
2005
+ var delayedRefresh = function delayedRefresh() {
2006
+ return setTimeout(hardRefresh);
2007
+ };
2008
+
2009
+ window.document.addEventListener('cut', delayedRefresh);
2010
+ window.document.addEventListener('copy', delayedRefresh);
2011
+ window.document.addEventListener('focus', softRefresh);
2012
+ softRefresh();
2013
+ return function () {
2014
+ window.document.removeEventListener('cut', delayedRefresh);
2015
+ window.document.removeEventListener('copy', delayedRefresh);
2016
+ window.document.removeEventListener('focus', softRefresh);
2017
+ };
2018
+ }, []);
2019
+ var canPaste = React.useCallback(function () {
2020
+ var _peek$rows;
2021
+
2022
+ return !!(peek == null || (_peek$rows = peek.rows) !== null && _peek$rows !== void 0 && _peek$rows.length);
2023
+ }, [peek]);
2024
+ return {
2025
+ peek: peek,
2026
+ canPaste: canPaste,
2027
+ copyTable: copyClipboardTable,
2028
+ pasteTable: pasteClipboardTable
2029
+ };
2030
+ };
2031
+ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly, addListener, onSelectionChange, onChange, onCopy, onPaste) {
2032
+ var _useClipboardTable = useClipboardTable(),
2033
+ canPaste = _useClipboardTable.canPaste,
2034
+ copyTable = _useClipboardTable.copyTable,
2035
+ pasteTable = _useClipboardTable.pasteTable;
2036
+
2037
+ var pasteIntoSelection = React.useCallback(function (selection, table) {
2038
+ try {
2039
+ var rows = table.rows,
2040
+ payload = table.payload;
2041
+
2042
+ var _normalizeSelection = normalizeSelection(selection),
2043
+ min = _normalizeSelection[0];
2044
+
2045
+ var minX = min[0],
2046
+ minY = min[1];
2047
+ var left = Math.max(0, minX);
2048
+ var top = Math.max(0, minY);
2049
+ var width = rows.reduce(function (a, b) {
2050
+ return Math.max(a, b.length);
2051
+ }, 0);
2052
+ var height = rows.length;
2053
+ var newSelection = [min, addXY(min, [width - 1, height - 1])];
2054
+ return Promise.resolve(onPaste === null || onPaste === void 0 ? void 0 : onPaste(newSelection, rows, payload)).then(function (shouldPaste) {
2055
+ if (shouldPaste !== false) {
2056
+ var changes = rows.flatMap(function (row, j) {
2057
+ return row.map(function (value, i) {
2058
+ var x = left + i;
2059
+ var y = top + j;
2060
+ return !(cellReadOnly !== null && cellReadOnly !== void 0 && cellReadOnly(x, y)) ? {
2061
+ x: x,
2062
+ y: y,
2063
+ value: value
2064
+ } : null;
2065
+ });
2066
+ }).filter(function (change) {
2067
+ return !!change;
2068
+ });
2069
+ onChange === null || onChange === void 0 ? void 0 : onChange(changes);
2070
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(newSelection);
2071
+ }
2072
+ });
2073
+ } catch (e) {
2074
+ return Promise.reject(e);
2075
+ }
2076
+ }, [onChange, onSelectionChange, cellReadOnly]);
2077
+ var copySelection = React.useCallback(function (selection, cut) {
2078
+ if (cut === void 0) {
2079
+ cut = false;
1773
2080
  }
1774
2081
 
1775
- textArea.value = v;
1776
- }, [selection, editMode, editData, textAreaRef]);
1777
- React.useLayoutEffect(function () {
1778
- var textArea = textAreaRef.current;
1779
- if (!textArea) return;
2082
+ try {
2083
+ var _payload$cut;
1780
2084
 
1781
- var focus = function focus() {
1782
- textArea.focus({
1783
- preventScroll: true
2085
+ var rows = formatSelectionAsRows(selection, editData);
2086
+ var payload = onCopy === null || onCopy === void 0 ? void 0 : onCopy(selection, rows, cut);
2087
+ copyTable(rows, payload);
2088
+
2089
+ if ((_payload$cut = payload === null || payload === void 0 ? void 0 : payload.cut) != null ? _payload$cut : cut) {
2090
+ var changes = [];
2091
+ forSelectionRows(selection)(function (y) {
2092
+ forSelectionColumns(selection)(function (x) {
2093
+ if (!(cellReadOnly !== null && cellReadOnly !== void 0 && cellReadOnly(x, y))) {
2094
+ var change = {
2095
+ x: x,
2096
+ y: y,
2097
+ value: ''
2098
+ };
2099
+ changes.push(change);
2100
+ }
2101
+ });
2102
+ });
2103
+ onChange === null || onChange === void 0 ? void 0 : onChange(changes);
2104
+ }
2105
+
2106
+ return Promise.resolve();
2107
+ } catch (e) {
2108
+ return Promise.reject(e);
2109
+ }
2110
+ }, [onCopy, onChange, cellReadOnly]);
2111
+ var pasteSelection = React.useCallback(function (selection) {
2112
+ try {
2113
+ return Promise.resolve(pasteTable()).then(function (table) {
2114
+ if (table) pasteIntoSelection(selection, table);
1784
2115
  });
1785
- textArea.select();
1786
- };
2116
+ } catch (e) {
2117
+ return Promise.reject(e);
2118
+ }
2119
+ }, [pasteIntoSelection]);
1787
2120
 
1788
- if (editMode) return;
1789
- if (document.activeElement === textArea) return;
1790
- var activeTagName = document.activeElement.tagName.toLowerCase();
2121
+ var onClipboardCopy = function onClipboardCopy(cut) {
2122
+ if (isEmptySelection(selection)) return;
2123
+ return copySelection(selection, cut);
2124
+ };
1791
2125
 
1792
- if (!(activeTagName === 'div' && document.activeElement.contentEditable === 'true' || activeTagName === 'input' || activeTagName === 'textarea' || activeTagName === 'select')) {
1793
- focus();
2126
+ var onClipboardPaste = function onClipboardPaste(e) {
2127
+ try {
2128
+ e.preventDefault();
2129
+ var clipboardData = e.clipboardData || window.clipboardData;
2130
+ return Promise.resolve(parseClipboardTable(clipboardData)).then(function (table) {
2131
+ if (table) pasteIntoSelection(selection, table);
2132
+ });
2133
+ } catch (e) {
2134
+ return Promise.reject(e);
1794
2135
  }
2136
+ };
2137
+
2138
+ React.useLayoutEffect(function () {
2139
+ if (!addListener) return;
2140
+ window.document.addEventListener('paste', onClipboardPaste);
2141
+ return function () {
2142
+ window.document.removeEventListener('paste', onClipboardPaste);
2143
+ };
1795
2144
  });
2145
+ var clipboardApi = React.useMemo(function () {
2146
+ return {
2147
+ copySelection: copySelection,
2148
+ pasteSelection: pasteSelection,
2149
+ canPasteSelection: canPaste
2150
+ };
2151
+ }, [copySelection, pasteSelection, canPaste]);
2152
+ return {
2153
+ clipboardApi: clipboardApi,
2154
+ onClipboardCopy: onClipboardCopy,
2155
+ onClipboardPaste: onClipboardPaste
2156
+ };
2157
+ };
2158
+
2159
+ var copyClipboardTable = function copyClipboardTable(rows, payload) {
2160
+ try {
2161
+ var text = formatRowsAsTSV(rows);
2162
+ var html = formatRowsAsHTML(rows, payload != null ? payload : undefined);
2163
+ return Promise.resolve(navigator.clipboard.write([new ClipboardItem({
2164
+ 'text/html': new Blob([html], {
2165
+ type: 'text/html'
2166
+ }),
2167
+ 'text/plain': new Blob([text], {
2168
+ type: 'text/plain'
2169
+ })
2170
+ })])).then(function () {
2171
+ var event = new Event('copy');
2172
+ document.dispatchEvent(event);
2173
+ });
2174
+ } catch (e) {
2175
+ return Promise.reject(e);
2176
+ }
1796
2177
  };
1797
- var useClipboardPaste = function useClipboardPaste(textAreaRef, selection, onSelectionChange, onChange, isReadOnly) {
1798
- React.useEffect(function () {
1799
- var onPaste = function onPaste(e) {
1800
- var textArea = textAreaRef.current;
1801
- if (!textArea) return;
1802
- if (e.target !== textArea) return;
1803
- e.preventDefault();
1804
- var clipboardData = e.clipboardData || window.clipboardData;
1805
- var types = clipboardData.types;
1806
- var parsed;
1807
-
1808
- if (types.includes('text/html')) {
1809
- var pastedHtml = clipboardData.getData('text/html');
1810
- parsed = parsePastedHtml(selection, pastedHtml, isReadOnly);
1811
- } else if (types.includes('text/plain')) {
1812
- var text = clipboardData.getData('text/plain');
1813
- parsed = parsePastedText(selection, text, isReadOnly);
1814
- }
1815
2178
 
1816
- if (!parsed) return;
1817
- var _parsed = parsed,
1818
- s = _parsed.selection,
1819
- changes = _parsed.changes;
1820
- onChange === null || onChange === void 0 ? void 0 : onChange(changes);
1821
- onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(s);
2179
+ var pasteClipboardTable = function pasteClipboardTable() {
2180
+ try {
2181
+ return Promise.resolve(navigator.clipboard.read()).then(function (items) {
2182
+ var item = items[0];
2183
+ if (!item) return;
2184
+ return parseClipboardTable(item);
2185
+ });
2186
+ } catch (e) {
2187
+ return Promise.reject(e);
2188
+ }
2189
+ };
2190
+
2191
+ var parseClipboardTable = function parseClipboardTable(item) {
2192
+ try {
2193
+ var _temp7 = function _temp7() {
2194
+ return rows ? {
2195
+ rows: rows,
2196
+ payload: payload
2197
+ } : {
2198
+ rows: []
2199
+ };
1822
2200
  };
1823
2201
 
1824
- window.document.addEventListener('paste', onPaste);
1825
- return function () {
1826
- window.document.removeEventListener('paste', onPaste);
2202
+ var has = function has(type) {
2203
+ return item.types.includes(type);
2204
+ };
2205
+
2206
+ var get = function get(type) {
2207
+ if ('getData' in item) return item.getData(type);else if ('getType' in item) return item.getType(type).then(function (blob) {
2208
+ return blob.text();
2209
+ });
2210
+ return '';
1827
2211
  };
1828
- }, [textAreaRef, selection]);
2212
+
2213
+ var rows, payload;
2214
+
2215
+ var _temp8 = function () {
2216
+ if (has('text/html')) {
2217
+ return Promise.resolve(get('text/html')).then(function (pastedHtml) {
2218
+ var _parsePastedHtml = parsePastedHtml(pastedHtml);
2219
+
2220
+ rows = _parsePastedHtml.rows;
2221
+ payload = _parsePastedHtml.payload;
2222
+ });
2223
+ } else {
2224
+ var _temp9 = function () {
2225
+ if (has('text/plain')) {
2226
+ return Promise.resolve(get('text/plain')).then(function (text) {
2227
+ rows = parsePastedText(text);
2228
+ });
2229
+ }
2230
+ }();
2231
+
2232
+ if (_temp9 && _temp9.then) return _temp9.then(function () {});
2233
+ }
2234
+ }();
2235
+
2236
+ return Promise.resolve(_temp8 && _temp8.then ? _temp8.then(_temp7) : _temp7(_temp8));
2237
+ } catch (e) {
2238
+ return Promise.reject(e);
2239
+ }
1829
2240
  };
1830
2241
 
1831
- var formatTSV = function formatTSV(rows) {
2242
+ var formatRowsAsTSV = function formatRowsAsTSV(rows) {
1832
2243
  return rows.map(function (row) {
1833
2244
  return row.join('\t');
1834
2245
  }).join('\n');
1835
2246
  };
1836
2247
 
1837
- var formatSelectionAsTSV = function formatSelectionAsTSV(selection, editData) {
1838
- if (isEmptySelection(selection)) return '';
2248
+ var formatRowsAsHTML = function formatRowsAsHTML(rows, payload) {
2249
+ var trs = rows.map(function (row) {
2250
+ var tds = row.map(formatTextAsHTML).map(function (cell) {
2251
+ return "<td>" + cell + "</td>";
2252
+ });
2253
+ return tds.join('');
2254
+ }).map(function (row) {
2255
+ return "<tr>" + row + "</tr>";
2256
+ }).join('\n');
2257
+ var table = "<table>" + trs + "</table>";
1839
2258
 
1840
- var _normalizeSelection = normalizeSelection(selection),
1841
- _normalizeSelection$ = _normalizeSelection[0],
1842
- minX = _normalizeSelection$[0],
1843
- minY = _normalizeSelection$[1],
1844
- _normalizeSelection$2 = _normalizeSelection[1],
1845
- maxX = _normalizeSelection$2[0],
1846
- maxY = _normalizeSelection$2[1];
2259
+ if (payload) {
2260
+ var extra = "<SheetHappens payload=\"" + formatTextAsHTML(JSON.stringify(payload)) + "\"></SheetHappens>";
2261
+ return extra + table;
2262
+ }
2263
+
2264
+ return table;
2265
+ };
2266
+
2267
+ var formatTextAsHTML = function formatTextAsHTML(s) {
2268
+ return s.replace(/[&"'<>]/g, function (i) {
2269
+ return "&#" + i.charCodeAt(0) + ";";
2270
+ });
2271
+ };
2272
+
2273
+ var formatSelectionAsRows = function formatSelectionAsRows(selection, editData) {
2274
+ if (isEmptySelection(selection)) return [];
2275
+
2276
+ var _normalizeSelection2 = normalizeSelection(selection),
2277
+ _normalizeSelection2$ = _normalizeSelection2[0],
2278
+ minX = _normalizeSelection2$[0],
2279
+ minY = _normalizeSelection2$[1],
2280
+ _normalizeSelection2$2 = _normalizeSelection2[1],
2281
+ maxX = _normalizeSelection2$2[0],
2282
+ maxY = _normalizeSelection2$2[1];
1847
2283
 
1848
2284
  if (isMaybeRowSelection(selection)) {
1849
2285
  var _findApproxMaxEditDat = findApproxMaxEditDataIndex(editData),
@@ -1877,132 +2313,94 @@ var formatSelectionAsTSV = function formatSelectionAsTSV(selection, editData) {
1877
2313
  rows.push(row);
1878
2314
  }
1879
2315
 
1880
- return formatTSV(rows);
2316
+ return rows;
1881
2317
  };
1882
2318
 
1883
- var findTable = function findTable(element) {
2319
+ var findTag = function findTag(element, tagName) {
1884
2320
  for (var _iterator = _createForOfIteratorHelperLoose(element.children), _step; !(_step = _iterator()).done;) {
1885
2321
  var child = _step.value;
1886
2322
 
1887
- if (child.nodeName === 'TABLE') {
2323
+ if (child.nodeName === tagName) {
1888
2324
  return child;
1889
2325
  }
1890
2326
 
1891
- var maybeTable = findTable(child);
2327
+ var maybeTag = findTag(child, tagName);
1892
2328
 
1893
- if (maybeTable) {
1894
- return maybeTable;
2329
+ if (maybeTag) {
2330
+ return maybeTag;
1895
2331
  }
1896
2332
  }
1897
2333
  };
1898
2334
 
1899
- var parsePastedHtml = function parsePastedHtml(selection, html, isReadOnly) {
2335
+ var parsePastedHtml = function parsePastedHtml(html) {
1900
2336
  var div = document.createElement('div');
1901
2337
  div.innerHTML = html.trim();
2338
+ var rows = [];
2339
+ var payload = undefined;
2340
+ var sheetNode = findTag(div, 'SHEETHAPPENS');
1902
2341
 
1903
- var _normalizeSelection2 = normalizeSelection(selection),
1904
- _normalizeSelection2$ = _normalizeSelection2[0],
1905
- minX = _normalizeSelection2$[0],
1906
- minY = _normalizeSelection2$[1];
1907
-
1908
- var left = isMaybeRowSelection(selection) ? 0 : minX;
1909
- var top = isMaybeColumnSelection(selection) ? 0 : minY;
1910
- var changes = [];
1911
- var tableNode = findTable(div);
2342
+ if (sheetNode) {
2343
+ var json = sheetNode.getAttribute('payload');
1912
2344
 
1913
- if (!tableNode) {
1914
- return null;
2345
+ try {
2346
+ payload = JSON.parse(json);
2347
+ } catch (e) {}
1915
2348
  }
1916
2349
 
1917
- var right = left;
1918
- var bottom = top;
1919
- var y = top;
2350
+ var tableNode = findTag(div, 'TABLE');
2351
+
2352
+ if (tableNode) {
2353
+ for (var _iterator2 = _createForOfIteratorHelperLoose(tableNode.children), _step2; !(_step2 = _iterator2()).done;) {
2354
+ var tableChild = _step2.value;
1920
2355
 
1921
- for (var _iterator2 = _createForOfIteratorHelperLoose(tableNode.children), _step2; !(_step2 = _iterator2()).done;) {
1922
- var tableChild = _step2.value;
2356
+ if (tableChild.nodeName === 'TBODY') {
2357
+ for (var _iterator3 = _createForOfIteratorHelperLoose(tableChild.children), _step3; !(_step3 = _iterator3()).done;) {
2358
+ var tr = _step3.value;
1923
2359
 
1924
- if (tableChild.nodeName === 'TBODY') {
1925
- for (var _iterator3 = _createForOfIteratorHelperLoose(tableChild.children), _step3; !(_step3 = _iterator3()).done;) {
1926
- var tr = _step3.value;
1927
- var x = left;
2360
+ if (tr.nodeName === 'TR') {
2361
+ var row = [];
1928
2362
 
1929
- if (tr.nodeName === 'TR') {
1930
- for (var _iterator4 = _createForOfIteratorHelperLoose(tr.children), _step4; !(_step4 = _iterator4()).done;) {
1931
- var td = _step4.value;
2363
+ for (var _iterator4 = _createForOfIteratorHelperLoose(tr.children), _step4; !(_step4 = _iterator4()).done;) {
2364
+ var td = _step4.value;
1932
2365
 
1933
- if (td.nodeName === 'TD') {
1934
- var str = '';
2366
+ if (td.nodeName === 'TD') {
2367
+ var str = '';
1935
2368
 
1936
- if (td.children.length !== 0 && td.children[0].nodeName === 'P') {
1937
- var p = td.children[0];
2369
+ if (td.children.length !== 0 && td.children[0].nodeName === 'P') {
2370
+ var p = td.children[0];
1938
2371
 
1939
- if (p.children.length !== 0 && p.children[0].nodeName === 'FONT') {
1940
- str = p.children[0].textContent.trim();
2372
+ if (p.children.length !== 0 && p.children[0].nodeName === 'FONT') {
2373
+ str = p.children[0].textContent.trim();
2374
+ } else {
2375
+ str = p.textContent.trim();
2376
+ }
1941
2377
  } else {
1942
- str = p.textContent.trim();
2378
+ str = td.textContent.trim();
1943
2379
  }
1944
- } else {
1945
- str = td.textContent.trim();
1946
- }
1947
2380
 
1948
- str = str.replaceAll('\n', '');
1949
- str = str.replaceAll(/\s\s+/g, ' ');
1950
- if (!(isReadOnly !== null && isReadOnly !== void 0 && isReadOnly(x, y))) changes.push({
1951
- x: x,
1952
- y: y,
1953
- value: str
1954
- });
1955
- x++;
2381
+ str = str.replaceAll('\n', '');
2382
+ str = str.replaceAll(/\s\s+/g, ' ');
2383
+ row.push(str);
2384
+ }
1956
2385
  }
1957
- }
1958
2386
 
1959
- y++;
2387
+ rows.push(row);
2388
+ }
1960
2389
  }
1961
-
1962
- right = Math.max(right, x - 1);
1963
2390
  }
1964
2391
  }
1965
2392
  }
1966
2393
 
1967
- bottom = Math.max(top, y - 1);
1968
2394
  return {
1969
- selection: [[left, top], [right, bottom]],
1970
- changes: changes
2395
+ rows: rows,
2396
+ payload: payload
1971
2397
  };
1972
2398
  };
1973
2399
 
1974
- var parsePastedText = function parsePastedText(selection, text, isReadOnly) {
1975
- var _normalizeSelection3 = normalizeSelection(selection),
1976
- _normalizeSelection3$ = _normalizeSelection3[0],
1977
- minX = _normalizeSelection3$[0],
1978
- minY = _normalizeSelection3$[1];
1979
-
1980
- var left = isMaybeRowSelection(selection) ? 0 : minX;
1981
- var top = isMaybeColumnSelection(selection) ? 0 : minY;
1982
- var rows = text.split(/\r?\n/);
1983
- var right = left;
1984
- var bottom = top + rows.length - 1;
1985
- var changes = [];
1986
-
1987
- for (var y = 0; y < rows.length; y++) {
1988
- var cols = rows[y].split('\t');
1989
- right = Math.max(right, left + cols.length - 1);
1990
-
1991
- for (var x = 0; x < cols.length; x++) {
1992
- var X = left + x;
1993
- var Y = top + y;
1994
- if (!(isReadOnly !== null && isReadOnly !== void 0 && isReadOnly(X, Y))) changes.push({
1995
- x: X,
1996
- y: Y,
1997
- value: cols[x]
1998
- });
1999
- }
2000
- }
2001
-
2002
- return {
2003
- selection: [[left, top], [right, bottom]],
2004
- changes: changes
2005
- };
2400
+ var parsePastedText = function parsePastedText(text) {
2401
+ return text.split(/\r?\n/).map(function (line) {
2402
+ return line.split('\t');
2403
+ });
2006
2404
  };
2007
2405
 
2008
2406
  var INITIAL_SIZE = 256;
@@ -2385,7 +2783,40 @@ var makeIntMap = function makeIntMap(initialSize) {
2385
2783
  };
2386
2784
  };
2387
2785
 
2388
- var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset) {
2786
+ var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
2787
+ var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
2788
+
2789
+ return {
2790
+ freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
2791
+ freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
2792
+ hideColumnHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideColumnHeaders) || false,
2793
+ hideRowHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideRowHeaders) || false,
2794
+ hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
2795
+ hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
2796
+ columnHeaderHeight: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideColumnHeaders ? 1 : SIZES.headerHeight,
2797
+ rowHeaderWidth: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideRowHeaders ? 1 : SIZES.headerWidth,
2798
+ shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
2799
+ shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
2800
+ shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
2801
+ };
2802
+ };
2803
+ var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth, alignment) {
2804
+ if (alignment === void 0) {
2805
+ alignment = style.textAlign;
2806
+ }
2807
+
2808
+ if (alignment === 'left') {
2809
+ return start + style.marginLeft;
2810
+ } else if (alignment === 'center') {
2811
+ return start + cellSize * 0.5 - imageWidth / 2;
2812
+ } else if (alignment === 'right') {
2813
+ return start + (cellSize - style.marginRight - imageWidth);
2814
+ }
2815
+
2816
+ return start;
2817
+ };
2818
+
2819
+ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset) {
2389
2820
  var canvas = context.canvas;
2390
2821
  var width = canvas.width,
2391
2822
  height = canvas.height;
@@ -2547,11 +2978,13 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2547
2978
  var isGroupSelected = rowSelectionActive && isInRowGroup;
2548
2979
  var style = isSelfSelected ? HEADER_SELECTED_STYLE : isGroupSelected ? HEADER_GROUP_SELECTED_STYLE : isActive ? HEADER_ACTIVE_STYLE : NO_STYLE;
2549
2980
 
2981
+ var resolvedStyle = _extends({}, DEFAULT_COLUMN_HEADER_STYLE, style);
2982
+
2550
2983
  var _top2 = rowToPixel(row);
2551
2984
 
2552
2985
  var _bottom2 = rowToPixel(row, 1);
2553
2986
 
2554
- clickables.push.apply(clickables, renderCell(context, content, style, DEFAULT_COLUMN_HEADER_STYLE, 0, _top2, rowHeaderWidth, _bottom2 - _top2));
2987
+ clickables.push.apply(clickables, renderCell(context, content, resolvedStyle, 0, _top2, rowHeaderWidth, _bottom2 - _top2));
2555
2988
  }
2556
2989
  }
2557
2990
 
@@ -2564,8 +2997,6 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2564
2997
 
2565
2998
  var column = _step5.value;
2566
2999
 
2567
- var _content = (_columnHeaders = columnHeaders(column)) != null ? _columnHeaders : excelHeaderString(column + 1);
2568
-
2569
3000
  var _isActive = isInRange(column, minX, maxX);
2570
3001
 
2571
3002
  var _groupKey = columnGroupKeys(column);
@@ -2575,19 +3006,22 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2575
3006
  var selectedStyle = isSelected ? HEADER_SELECTED_STYLE : NO_STYLE;
2576
3007
  var activeStyle = _isActive ? HEADER_ACTIVE_STYLE : NO_STYLE;
2577
3008
 
2578
- var _style = _extends({}, columnHeaderStyle(column), activeStyle, selectedStyle);
3009
+ var _style = _extends({}, DEFAULT_COLUMN_HEADER_STYLE, columnHeaderStyle(column), activeStyle, selectedStyle);
2579
3010
 
2580
3011
  var _left2 = columnToPixel(column);
2581
3012
 
2582
3013
  var _right2 = columnToPixel(column, 1);
2583
3014
 
2584
- clickables.push.apply(clickables, renderCell(context, _content, _style, DEFAULT_COLUMN_HEADER_STYLE, _left2, 0, _right2 - _left2, columnHeaderHeight));
3015
+ var _content = (_columnHeaders = columnHeaders(column, _style)) != null ? _columnHeaders : excelHeaderString(column + 1);
3016
+
3017
+ clickables.push.apply(clickables, renderCell(context, _content, _style, _left2, 0, _right2 - _left2, columnHeaderHeight));
2585
3018
  }
2586
3019
  }
2587
3020
 
2588
3021
  if (selectionActive) {
2589
3022
  context.strokeStyle = COLORS.selectionBorder;
2590
3023
  context.lineWidth = 2;
3024
+ context.globalAlpha = isFocused ? 1 : 0.5;
2591
3025
  var _selected$7 = selected[0],
2592
3026
  _left3 = _selected$7[0],
2593
3027
  _top3 = _selected$7[1],
@@ -2595,6 +3029,7 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2595
3029
  _right3 = _selected$8[0],
2596
3030
  _bottom3 = _selected$8[1];
2597
3031
  context.strokeRect(_left3, _top3, _right3 - _left3 - 1, _bottom3 - _top3 - 1);
3032
+ context.globalAlpha = 1;
2598
3033
  }
2599
3034
 
2600
3035
  for (var _iterator6 = _createForOfIteratorHelperLoose(secondarySelections), _step6; !(_step6 = _iterator6()).done;) {
@@ -2744,43 +3179,42 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2744
3179
 
2745
3180
  var _bottom10 = rowToPixel(_y, 1);
2746
3181
 
2747
- var cellContent = displayData(_x, _y);
3182
+ var _style2 = _extends({}, DEFAULT_CELL_STYLE, cellStyle(_x, _y));
2748
3183
 
2749
- if (cellContent !== null && cellContent !== undefined) {
2750
- var _style2 = cellStyle(_x, _y);
3184
+ var cellContent = displayData(_x, _y, _style2);
2751
3185
 
2752
- clickables.push.apply(clickables, renderCell(context, cellContent, _style2, DEFAULT_CELL_STYLE, _left9, _top9, _right10 - _left9, _bottom10 - _top9));
3186
+ if (cellContent !== null && cellContent !== undefined) {
3187
+ clickables.push.apply(clickables, renderCell(context, cellContent, _style2, _left9, _top9, _right10 - _left9, _bottom10 - _top9));
2753
3188
  }
2754
3189
  }
2755
3190
  }
2756
3191
 
2757
3192
  return clickables;
2758
3193
  };
2759
- var renderCell = function renderCell(context, cellContent, style, defaultCellStyle, xCoord, yCoord, cellWidth, cellHeight) {
3194
+ var renderCell = function renderCell(context, cellContent, style, xCoord, yCoord, cellWidth, cellHeight) {
2760
3195
  var clickables = [];
2761
3196
 
2762
3197
  if (cellContent === null) {
2763
3198
  return clickables;
2764
3199
  }
2765
3200
 
2766
- var finalStyle = resolveCellStyle(style, defaultCellStyle);
2767
- context.fillStyle = finalStyle.color;
2768
- context.font = finalStyle.weight + ' ' + finalStyle.fontSize + 'px ' + finalStyle.fontFamily;
2769
- context.textAlign = finalStyle.textAlign;
3201
+ context.fillStyle = style.color;
3202
+ context.font = style.weight + ' ' + style.fontSize + 'px ' + style.fontFamily;
3203
+ context.textAlign = style.textAlign;
2770
3204
  var yy = Math.floor(yCoord + cellHeight * 0.5);
2771
3205
  context.save();
2772
3206
  context.beginPath();
2773
3207
  context.rect(xCoord, yCoord, cellWidth, cellHeight);
2774
3208
  context.clip();
2775
3209
 
2776
- if (finalStyle.backgroundColor !== '') {
2777
- context.fillStyle = finalStyle.backgroundColor;
3210
+ if (style.backgroundColor !== '') {
3211
+ context.fillStyle = style.backgroundColor;
2778
3212
  context.fillRect(xCoord, yCoord, cellWidth, cellHeight);
2779
- context.fillStyle = finalStyle.color;
3213
+ context.fillStyle = style.color;
2780
3214
  }
2781
3215
 
2782
3216
  if (typeof cellContent === 'string' || typeof cellContent === 'number') {
2783
- var xx = applyAlignment(xCoord, cellWidth, finalStyle, 0);
3217
+ var xx = applyAlignment(xCoord, cellWidth, style, 0);
2784
3218
  var text = '' + cellContent;
2785
3219
  context.fillText(text, xx, yy);
2786
3220
  } else if (typeof cellContent === 'object') {
@@ -2794,7 +3228,7 @@ var renderCell = function renderCell(context, cellContent, style, defaultCellSty
2794
3228
  if (obj.content instanceof HTMLImageElement) {
2795
3229
  w = obj.width || cellWidth;
2796
3230
  h = obj.height || cellHeight;
2797
- var finalX = applyAlignment(xCoord, cellWidth, finalStyle, w, obj.horizontalAlign);
3231
+ var finalX = applyAlignment(xCoord, cellWidth, style, w, obj.horizontalAlign);
2798
3232
  x = finalX + obj.x;
2799
3233
  y = yy + obj.y;
2800
3234
  context.drawImage(obj.content, x, y, w, h);
@@ -2803,7 +3237,7 @@ var renderCell = function renderCell(context, cellContent, style, defaultCellSty
2803
3237
  context.textAlign = obj.horizontalAlign;
2804
3238
  }
2805
3239
 
2806
- var _finalX = applyAlignment(xCoord, cellWidth, finalStyle, 0, obj.horizontalAlign);
3240
+ var _finalX = applyAlignment(xCoord, cellWidth, style, 0, obj.horizontalAlign);
2807
3241
 
2808
3242
  var _text = '' + obj.content;
2809
3243
 
@@ -3029,8 +3463,8 @@ var Sheet = React.forwardRef(function (props, ref) {
3029
3463
  var selectionProp = (_props$selection = props.selection) != null ? _props$selection : NO_SELECTION;
3030
3464
 
3031
3465
  var _useState3 = React.useState(selectionProp),
3032
- selection = _useState3[0],
3033
- setSelection = _useState3[1];
3466
+ rawSelection = _useState3[0],
3467
+ setRawSelection = _useState3[1];
3034
3468
 
3035
3469
  var _useState4 = React.useState(null),
3036
3470
  knobArea = _useState4[0],
@@ -3052,22 +3486,26 @@ var Sheet = React.forwardRef(function (props, ref) {
3052
3486
  editCell = _useState8[0],
3053
3487
  setEditCell = _useState8[1];
3054
3488
 
3055
- var _useState9 = React.useState(selectionProp),
3056
- lastSelectionProp = _useState9[0],
3057
- setLastSelectionProp = _useState9[1];
3489
+ var _useState9 = React.useState(!!props.autoFocus),
3490
+ focused = _useState9[0],
3491
+ setFocused = _useState9[1];
3492
+
3493
+ var _useState10 = React.useState(selectionProp),
3494
+ lastSelectionProp = _useState10[0],
3495
+ setLastSelectionProp = _useState10[1];
3058
3496
 
3059
3497
  if (lastSelectionProp !== selectionProp) {
3060
3498
  setLastSelectionProp(selectionProp);
3061
- setSelection(selectionProp);
3499
+ setRawSelection(selectionProp);
3062
3500
  }
3063
3501
 
3064
- var _useState10 = React.useState(''),
3065
- editValue = _useState10[0],
3066
- setEditValue = _useState10[1];
3502
+ var _useState11 = React.useState(''),
3503
+ editValue = _useState11[0],
3504
+ setEditValue = _useState11[1];
3067
3505
 
3068
- var _useState11 = React.useState(false),
3069
- arrowKeyCommitMode = _useState11[0],
3070
- setArrowKeyCommitMode = _useState11[1];
3506
+ var _useState12 = React.useState(false),
3507
+ arrowKeyCommitMode = _useState12[0],
3508
+ setArrowKeyCommitMode = _useState12[1];
3071
3509
 
3072
3510
  var _useResizeObserver = useResizeObserver({
3073
3511
  ref: overlayRef
@@ -3084,7 +3522,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3084
3522
  return createRowOrColumnProp(props.cellHeight, 22);
3085
3523
  }, [props.cellHeight]);
3086
3524
  var columnHeaders = React.useMemo(function () {
3087
- return createRowOrColumnProp(props.columnHeaders, null);
3525
+ return createRowOrColumnStyledProp(props.columnHeaders, null);
3088
3526
  }, [props.columnHeaders]);
3089
3527
  var columnHeaderStyle = React.useMemo(function () {
3090
3528
  return createRowOrColumnProp(props.columnHeaderStyle, {});
@@ -3114,7 +3552,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3114
3552
  return createCellProp(props.sourceData, null);
3115
3553
  }, [props.sourceData]);
3116
3554
  var displayData = React.useMemo(function () {
3117
- return createCellProp(props.displayData, '');
3555
+ return createCellStyledProp(props.displayData, '');
3118
3556
  }, [props.displayData]);
3119
3557
  var editData = React.useMemo(function () {
3120
3558
  return createCellProp(props.editData, '');
@@ -3129,6 +3567,9 @@ var Sheet = React.forwardRef(function (props, ref) {
3129
3567
  return resolveSheetStyle(props.sheetStyle);
3130
3568
  }, [props.sheetStyle]);
3131
3569
  var secondarySelections = (_props$secondarySelec = props.secondarySelections) != null ? _props$secondarySelec : NO_SELECTIONS;
3570
+ var selection = React.useMemo(function () {
3571
+ return validateSelection(rawSelection);
3572
+ }, [rawSelection]);
3132
3573
  var selectedColumnGroups = React.useMemo(function () {
3133
3574
  return props.columnGroupKeys ? new Set(mapSelectionColumns(selection)(function (x) {
3134
3575
  return columnGroupKeys(x);
@@ -3207,7 +3648,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3207
3648
  }
3208
3649
 
3209
3650
  if (!isSameSelection(selection, newSelection)) {
3210
- setSelection(validateSelection(newSelection));
3651
+ setRawSelection(newSelection);
3211
3652
  }
3212
3653
 
3213
3654
  var overlay = overlayRef.current;
@@ -3218,7 +3659,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3218
3659
  }
3219
3660
 
3220
3661
  if (props.onSelectionChanged) {
3221
- var _normalizeSelection = normalizeSelection(newSelection),
3662
+ var _normalizeSelection = normalizeSelection(validateSelection(newSelection)),
3222
3663
  _normalizeSelection$ = _normalizeSelection[0],
3223
3664
  minX = _normalizeSelection$[0],
3224
3665
  minY = _normalizeSelection$[1],
@@ -3230,6 +3671,11 @@ var Sheet = React.forwardRef(function (props, ref) {
3230
3671
  }
3231
3672
  };
3232
3673
 
3674
+ var cancelEditingCell = function cancelEditingCell() {
3675
+ setEditCell(NO_CELL);
3676
+ setFocused(true);
3677
+ };
3678
+
3233
3679
  var commitEditingCell = function commitEditingCell(value) {
3234
3680
  if (props.onChange) {
3235
3681
  var cellX = editCell[0],
@@ -3242,6 +3688,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3242
3688
  }
3243
3689
 
3244
3690
  setEditCell(NO_CELL);
3691
+ setFocused(true);
3245
3692
  };
3246
3693
 
3247
3694
  var startEditingCell = function startEditingCell(editCell, arrowKeyCommitMode) {
@@ -3279,16 +3726,25 @@ var Sheet = React.forwardRef(function (props, ref) {
3279
3726
  setDataOffset(clipDataOffset(view, dataOffset, freeze, [maxColumns, maxRows], cellLayout));
3280
3727
  }, [maxRows, maxColumns]);
3281
3728
  var hitmapRef = React.useRef(NO_CLICKABLES);
3282
- var textAreaRef = React.useRef(null);
3283
- useClipboardCopy(textAreaRef, selection, editMode, editData);
3284
- useClipboardPaste(textAreaRef, selection, changeSelection, props.onChange, cellReadOnly);
3729
+ var isFocused = focused || editMode;
3730
+
3731
+ var _useClipboardAPI = useClipboardAPI(selection, editData, cellReadOnly, isFocused && !editMode, changeSelection, props.onChange, props.onCopy, props.onPaste),
3732
+ clipboardApi = _useClipboardAPI.clipboardApi,
3733
+ onClipboardCopy = _useClipboardAPI.onClipboardCopy;
3734
+
3285
3735
  var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
3286
3736
  var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth);
3287
3737
 
3288
- var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, 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),
3738
+ var _useMouse = useMouse(hitmapRef, selection, knobArea, editMode, editData, sourceData, cellReadOnly, canSizeColumn, canSizeRow, canOrderColumn, canOrderRow, cellLayout, visibleCells, sheetStyle, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, getAutoSizeWidth, startEditingCell, commitEditingCell, setKnobArea, setDragIndices, setDragOffset, setDropTarget, changeSelection, setFocused, 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),
3289
3739
  mouseHandlers = _useMouse.mouseHandlers,
3290
3740
  knobPosition = _useMouse.knobPosition;
3291
3741
 
3742
+ var _useKeyboard = useKeyboard(arrowKeyCommitMode, overlayRef, cellReadOnly, displayData, editCell, editMode, focused, rawSelection, selection, startEditingCell, commitEditingCell, cancelEditingCell, changeSelection, setFocused, onClipboardCopy, props.onChange),
3743
+ onInputKeyDown = _useKeyboard.onInputKeyDown,
3744
+ onGridKeyDown = _useKeyboard.onGridKeyDown,
3745
+ onGridFocus = _useKeyboard.onGridFocus,
3746
+ onGridBlur = _useKeyboard.onGridBlur;
3747
+
3292
3748
  React.useLayoutEffect(function () {
3293
3749
  var canvas = canvasRef.current;
3294
3750
 
@@ -3303,130 +3759,16 @@ var Sheet = React.forwardRef(function (props, ref) {
3303
3759
  }
3304
3760
 
3305
3761
  var animationFrameId = window.requestAnimationFrame(function () {
3306
- hitmapRef.current = renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset);
3762
+ hitmapRef.current = renderSheet(context, cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragIndices, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset);
3307
3763
  });
3308
3764
  return function () {
3309
3765
  window.cancelAnimationFrame(animationFrameId);
3310
3766
  };
3311
- }, [cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, knobPosition, knobArea, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset]);
3312
-
3313
- var onKeyDown = function onKeyDown(e) {
3314
- if (e.key === 'Escape') {
3315
- setEditCell(NO_CELL);
3316
- return;
3317
- }
3318
-
3319
- var direction = e.key === 'Enter' ? 'down' : e.key === 'Tab' ? 'right' : arrowKeyCommitMode ? ARROW_KEYS[e.key] : null;
3320
-
3321
- if (direction) {
3322
- e.preventDefault();
3323
- var step = getDirectionStep(direction);
3324
- var head = maxXY(addXY(editCell, step), ORIGIN);
3325
- commitEditingCell();
3326
- changeSelection([head, head]);
3327
- }
3328
- };
3329
-
3330
- var onGridKeyDown = function onGridKeyDown(e) {
3331
- if (editMode && arrowKeyCommitMode && e.key in ARROW_KEYS) {
3332
- commitEditingCell();
3333
- return;
3334
- }
3335
-
3336
- if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'v') {
3337
- return;
3338
- }
3339
-
3340
- if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'c') {
3341
- var textArea = textAreaRef.current;
3342
- textArea === null || textArea === void 0 ? void 0 : textArea.select();
3343
- return;
3344
- }
3345
-
3346
- if (e.key === 'Backspace' || e.key === 'Delete') {
3347
- var _normalizeSelection2 = normalizeSelection(selection),
3348
- _normalizeSelection2$ = _normalizeSelection2[0],
3349
- x1 = _normalizeSelection2$[0],
3350
- y1 = _normalizeSelection2$[1],
3351
- _normalizeSelection2$2 = _normalizeSelection2[1],
3352
- x2 = _normalizeSelection2$2[0],
3353
- y2 = _normalizeSelection2$2[1];
3354
-
3355
- if (isRowSelection(selection)) {
3356
- x1 = 0;
3357
- x2 = MAX_SEARCHABLE_INDEX;
3358
- }
3359
-
3360
- if (isColumnSelection(selection)) {
3361
- y1 = 0;
3362
- y2 = MAX_SEARCHABLE_INDEX;
3363
- }
3364
-
3365
- var changes = [];
3366
-
3367
- for (var y = y1; y <= y2; y++) {
3368
- for (var x = x1; x <= x2; x++) {
3369
- if (!cellReadOnly(x, y)) {
3370
- changes.push({
3371
- x: x,
3372
- y: y,
3373
- value: null
3374
- });
3375
- }
3376
- }
3377
- }
3378
-
3379
- if (props.onChange) {
3380
- props.onChange(changes);
3381
- }
3382
-
3383
- return;
3384
- }
3385
-
3386
- if (isEmptySelection(selection)) {
3387
- return;
3388
- }
3389
-
3390
- if (e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode >= 96 && e.keyCode <= 105 || e.keyCode >= 65 && e.keyCode <= 90 || e.key === 'Enter' || e.key === '-' || e.key === '.' || e.key === ',') {
3391
- var cell = selection[0];
3392
- var cellX = cell[0],
3393
- cellY = cell[1];
3394
-
3395
- if (cellReadOnly(cellX, cellY)) {
3396
- e.preventDefault();
3397
- return;
3398
- }
3399
-
3400
- startEditingCell(cell, e.key !== 'Enter');
3401
- return;
3402
- }
3403
-
3404
- if (e.key in ARROW_KEYS) {
3405
- var anchor = selection[0],
3406
- head = selection[1];
3407
- var direction = ARROW_KEYS[e.key];
3408
- var step = getDirectionStep(direction);
3409
-
3410
- if (e.metaKey || e.ctrlKey) {
3411
- head = findInDisplayData(displayData, head, direction);
3412
- } else {
3413
- head = maxXY(addXY(head, step), ORIGIN);
3414
- }
3415
-
3416
- if (!e.shiftKey) {
3417
- anchor = head;
3418
- }
3767
+ }, [cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset]);
3419
3768
 
3420
- changeSelection([anchor, head], true, true);
3421
- return;
3422
- }
3423
-
3424
- e.preventDefault();
3425
- };
3426
-
3427
- var _useState12 = React.useState(''),
3428
- lastEditKey = _useState12[0],
3429
- setLastEditKey = _useState12[1];
3769
+ var _useState13 = React.useState(''),
3770
+ lastEditKey = _useState13[0],
3771
+ setLastEditKey = _useState13[1];
3430
3772
 
3431
3773
  var editTextPosition = ORIGIN;
3432
3774
  var editTextWidth = 0;
@@ -3454,7 +3796,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3454
3796
  var inputProps = {
3455
3797
  value: editValue,
3456
3798
  autoFocus: true,
3457
- onKeyDown: onKeyDown,
3799
+ onKeyDown: onInputKeyDown,
3458
3800
  style: {
3459
3801
  position: 'absolute',
3460
3802
  left: textX,
@@ -3481,6 +3823,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3481
3823
  top: 0,
3482
3824
  left: 0,
3483
3825
  overflow: 'scroll',
3826
+ outline: 0,
3484
3827
  borderBottom: '1px solid #ddd'
3485
3828
  };
3486
3829
  var canvasStyles = {
@@ -3516,10 +3859,10 @@ var Sheet = React.forwardRef(function (props, ref) {
3516
3859
  });
3517
3860
  }, [props.renderOutside, visibleCells, cellLayout, selection, editMode]);
3518
3861
  React.useImperativeHandle(ref, function () {
3519
- return _extends({}, cellLayout, {
3862
+ return _extends({}, cellLayout, clipboardApi, {
3520
3863
  startEditingCell: startEditingCell
3521
3864
  });
3522
- }, [cellLayout, startEditingCell]);
3865
+ }, [cellLayout, clipboardApi, startEditingCell]);
3523
3866
  return React__default.createElement("div", {
3524
3867
  style: {
3525
3868
  position: 'relative',
@@ -3532,6 +3875,10 @@ var Sheet = React.forwardRef(function (props, ref) {
3532
3875
  }), React__default.createElement("div", Object.assign({
3533
3876
  ref: overlayRef
3534
3877
  }, mouseHandlers, {
3878
+ onKeyDown: onGridKeyDown,
3879
+ onFocus: onGridFocus,
3880
+ onBlur: onGridBlur,
3881
+ tabIndex: 0,
3535
3882
  onScroll: onScroll,
3536
3883
  className: overlayDivClassName,
3537
3884
  style: overlayDivStyles
@@ -3568,26 +3915,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3568
3915
  height: '100%',
3569
3916
  pointerEvents: 'none'
3570
3917
  }
3571
- }, renderedOutside) : null, React__default.createElement("textarea", {
3572
- style: {
3573
- position: 'absolute',
3574
- top: 0,
3575
- left: 0,
3576
- width: 1,
3577
- height: 1,
3578
- opacity: 0.01
3579
- },
3580
- ref: textAreaRef,
3581
- autoComplete: "off",
3582
- autoCorrect: "off",
3583
- autoCapitalize: "off",
3584
- spellCheck: "false",
3585
- onFocus: function onFocus(e) {
3586
- return e.target.select();
3587
- },
3588
- tabIndex: 0,
3589
- onKeyDown: onGridKeyDown
3590
- }), editMode && (input !== undefined ? input : React__default.createElement("input", Object.assign({}, inputProps, {
3918
+ }, renderedOutside) : null, editMode && (input !== undefined ? input : React__default.createElement("input", Object.assign({}, inputProps, {
3591
3919
  type: "text",
3592
3920
  onFocus: function onFocus(e) {
3593
3921
  return e.target.select();
@@ -3598,5 +3926,6 @@ var Sheet = React.forwardRef(function (props, ref) {
3598
3926
  }))));
3599
3927
  });
3600
3928
 
3601
- module.exports = Sheet;
3929
+ exports.default = Sheet;
3930
+ exports.useClipboardTable = useClipboardTable;
3602
3931
  //# sourceMappingURL=index.js.map