sheet-happens 0.0.43 → 0.0.44

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 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;
@@ -1327,9 +1376,11 @@ var useMouse = function useMouse(hitmapRef, selection, knobArea, editMode, editD
1327
1376
  for (var _i = 0, _autosized = autosized; _i < _autosized.length; _i++) {
1328
1377
  var column = _autosized[_i];
1329
1378
  onInvalidateColumn === null || onInvalidateColumn === void 0 ? void 0 : onInvalidateColumn(column - 1);
1330
- onCellWidthChange([column], getAutoSizeWidth(column));
1331
1379
  }
1332
1380
 
1381
+ onCellWidthChange(autosized, autosized.map(function (column) {
1382
+ return getAutoSizeWidth(column);
1383
+ }));
1333
1384
  if (autosized.length) return;
1334
1385
  }
1335
1386
 
@@ -1497,6 +1548,162 @@ var parseKnobOperation = function parseKnobOperation(knobArea, selection, source
1497
1548
  return changes;
1498
1549
  };
1499
1550
 
1551
+ var useKeyboard = function useKeyboard(arrowKeyCommitMode, overlayRef, cellReadOnly, displayData, editCell, editMode, focused, rawSelection, selection, onEdit, onCommit, onCancel, onSelectionChange, onFocusChange, onClipboardCopy, onChange) {
1552
+ var onInputKeyDown = function onInputKeyDown(e) {
1553
+ if (e.key === 'Escape') {
1554
+ onCancel === null || onCancel === void 0 ? void 0 : onCancel();
1555
+ return;
1556
+ }
1557
+
1558
+ var direction = e.key === 'Enter' ? 'down' : e.key === 'Tab' ? 'right' : arrowKeyCommitMode ? ARROW_KEYS[e.key] : null;
1559
+
1560
+ if (direction) {
1561
+ e.preventDefault();
1562
+ var step = getDirectionStep(direction);
1563
+ var head = maxXY(addXY(editCell, step), ORIGIN);
1564
+ onCommit === null || onCommit === void 0 ? void 0 : onCommit();
1565
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([head, head]);
1566
+ }
1567
+ };
1568
+
1569
+ var onGridKeyDown = function onGridKeyDown(e) {
1570
+ if (editMode && arrowKeyCommitMode && e.key in ARROW_KEYS) {
1571
+ onCommit === null || onCommit === void 0 ? void 0 : onCommit();
1572
+ return;
1573
+ }
1574
+
1575
+ if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'v') {
1576
+ return;
1577
+ }
1578
+
1579
+ if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'c') {
1580
+ onClipboardCopy === null || onClipboardCopy === void 0 ? void 0 : onClipboardCopy(false);
1581
+ return;
1582
+ }
1583
+
1584
+ if ((e.metaKey || e.ctrlKey) && String.fromCharCode(e.which).toLowerCase() === 'x') {
1585
+ onClipboardCopy === null || onClipboardCopy === void 0 ? void 0 : onClipboardCopy(true);
1586
+ return;
1587
+ }
1588
+
1589
+ if (e.key === 'Backspace' || e.key === 'Delete') {
1590
+ var _normalizeSelection = normalizeSelection(selection),
1591
+ _normalizeSelection$ = _normalizeSelection[0],
1592
+ x1 = _normalizeSelection$[0],
1593
+ y1 = _normalizeSelection$[1],
1594
+ _normalizeSelection$2 = _normalizeSelection[1],
1595
+ x2 = _normalizeSelection$2[0],
1596
+ y2 = _normalizeSelection$2[1];
1597
+
1598
+ if (isRowSelection(selection)) {
1599
+ x1 = 0;
1600
+ x2 = MAX_SEARCHABLE_INDEX;
1601
+ }
1602
+
1603
+ if (isColumnSelection(selection)) {
1604
+ y1 = 0;
1605
+ y2 = MAX_SEARCHABLE_INDEX;
1606
+ }
1607
+
1608
+ var changes = [];
1609
+
1610
+ for (var y = y1; y <= y2; y++) {
1611
+ for (var x = x1; x <= x2; x++) {
1612
+ if (!cellReadOnly(x, y)) {
1613
+ changes.push({
1614
+ x: x,
1615
+ y: y,
1616
+ value: null
1617
+ });
1618
+ }
1619
+ }
1620
+ }
1621
+
1622
+ onChange === null || onChange === void 0 ? void 0 : onChange(changes);
1623
+ return;
1624
+ }
1625
+
1626
+ if (isEmptySelection(selection)) {
1627
+ return;
1628
+ }
1629
+
1630
+ 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 === ',') {
1631
+ var cell = selection[0];
1632
+ var cellX = cell[0],
1633
+ cellY = cell[1];
1634
+
1635
+ if (cellReadOnly(cellX, cellY)) {
1636
+ return;
1637
+ }
1638
+
1639
+ onEdit === null || onEdit === void 0 ? void 0 : onEdit(cell, e.key !== 'Enter');
1640
+ return;
1641
+ }
1642
+
1643
+ e.preventDefault();
1644
+
1645
+ if (e.key in ARROW_KEYS) {
1646
+ var anchor = rawSelection[0],
1647
+ head = rawSelection[1];
1648
+ var direction = ARROW_KEYS[e.key];
1649
+ var step = getDirectionStep(direction);
1650
+ var shift = e.shiftKey;
1651
+
1652
+ if (e.metaKey || e.ctrlKey) {
1653
+ head = findInDisplayData(displayData, head, direction);
1654
+ } else {
1655
+ var limit = shift ? isRowSelection(selection) ? [-1, 0] : isColumnSelection(selection) ? [0, -1] : NEG_NEG : ORIGIN;
1656
+ head = maxXY(addXY(head, step), limit);
1657
+ }
1658
+
1659
+ if (!shift) {
1660
+ anchor = head;
1661
+ }
1662
+
1663
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange([anchor, head], true, true);
1664
+ return;
1665
+ }
1666
+ };
1667
+
1668
+ var onGridFocus = function onGridFocus() {
1669
+ onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(true);
1670
+ };
1671
+
1672
+ var onGridBlur = function onGridBlur() {
1673
+ onFocusChange === null || onFocusChange === void 0 ? void 0 : onFocusChange(false);
1674
+ };
1675
+
1676
+ React.useLayoutEffect(function () {
1677
+ var overlay = overlayRef.current;
1678
+
1679
+ if (!overlay) {
1680
+ return;
1681
+ }
1682
+
1683
+ if (editMode || !focused) {
1684
+ return;
1685
+ }
1686
+
1687
+ if (document.activeElement === overlay) {
1688
+ return;
1689
+ }
1690
+
1691
+ var activeTagName = document.activeElement.tagName.toLowerCase();
1692
+
1693
+ if (!(activeTagName === 'div' && document.activeElement.contentEditable === 'true' || activeTagName === 'input' || activeTagName === 'textarea' || activeTagName === 'select')) {
1694
+ overlay.focus({
1695
+ preventScroll: true
1696
+ });
1697
+ }
1698
+ }, [editMode, focused]);
1699
+ return {
1700
+ onInputKeyDown: onInputKeyDown,
1701
+ onGridFocus: onGridFocus,
1702
+ onGridBlur: onGridBlur,
1703
+ onGridKeyDown: onGridKeyDown
1704
+ };
1705
+ };
1706
+
1500
1707
  var useScroll = function useScroll(offset, maxScroll, cellLayout, onOffsetChange, onMaxScrollChange) {
1501
1708
  return React.useCallback(function (e) {
1502
1709
  if (!e.target || !(e.target instanceof Element)) {
@@ -1654,42 +1861,6 @@ var scrollToCell = function scrollToCell(element, cell, view, freeze, offset, ma
1654
1861
  }
1655
1862
  };
1656
1863
 
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
1864
  var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth) {
1694
1865
  var context = React.useMemo(function () {
1695
1866
  return document.createElement('canvas').getContext('2d');
@@ -1698,9 +1869,8 @@ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle,
1698
1869
  if (!context) return 0;
1699
1870
 
1700
1871
  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;
1872
+ context.font = style.weight + ' ' + style.fontSize + 'px ' + style.fontFamily;
1873
+ var inlineMargin = style.marginLeft + style.marginRight;
1704
1874
 
1705
1875
  if (typeof cellContent === 'string' || typeof cellContent === 'number') {
1706
1876
  var _context$measureText = context.measureText(cellContent.toString()),
@@ -1725,7 +1895,7 @@ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle,
1725
1895
  }
1726
1896
 
1727
1897
  if (obj.horizontalAlign === 'right') {
1728
- extraWidth += _width;
1898
+ extraWidth += style.textAlign === 'right' ? _width * 2 : _width;
1729
1899
  } else {
1730
1900
  _maxWidth = Math.max(_maxWidth, _width);
1731
1901
  }
@@ -1738,19 +1908,23 @@ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle,
1738
1908
  };
1739
1909
 
1740
1910
  var maxWidth = SIZES.minimumWidth;
1741
- var headerContent = columnHeaders(x);
1911
+
1912
+ var headerStyle = _extends({}, DEFAULT_COLUMN_HEADER_STYLE, columnHeaderStyle(x));
1913
+
1914
+ var headerContent = columnHeaders(x, headerStyle);
1742
1915
 
1743
1916
  if (headerContent) {
1744
- var headerStyle = columnHeaderStyle(x);
1745
1917
  maxWidth = Math.max(maxWidth, getWidth(headerContent, headerStyle));
1746
1918
  }
1747
1919
 
1748
1920
  for (var _iterator2 = _createForOfIteratorHelperLoose(rows), _step2; !(_step2 = _iterator2()).done;) {
1749
1921
  var y = _step2.value;
1750
- var cellContent = displayData(x, y);
1922
+
1923
+ var style = _extends({}, DEFAULT_CELL_STYLE, cellStyle(x, y));
1924
+
1925
+ var cellContent = displayData(x, y, style);
1751
1926
 
1752
1927
  if (cellContent != null) {
1753
- var style = cellStyle(x, y);
1754
1928
  maxWidth = Math.max(maxWidth, getWidth(cellContent, style));
1755
1929
  }
1756
1930
  }
@@ -1760,90 +1934,349 @@ var useAutoSizeColumn = function useAutoSizeColumn(rows, displayData, cellStyle,
1760
1934
  return getAutoSizeWidth;
1761
1935
  };
1762
1936
 
1763
- var useClipboardCopy = function useClipboardCopy(textAreaRef, selection, editMode, editData) {
1937
+ // A type of promise-like that resolves synchronously and supports only one observer
1938
+
1939
+ const _iteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator"))) : "@@iterator";
1940
+
1941
+ const _asyncIteratorSymbol = /*#__PURE__*/ typeof Symbol !== "undefined" ? (Symbol.asyncIterator || (Symbol.asyncIterator = Symbol("Symbol.asyncIterator"))) : "@@asyncIterator";
1942
+
1943
+ // Asynchronously call a function and send errors to recovery continuation
1944
+ function _catch(body, recover) {
1945
+ try {
1946
+ var result = body();
1947
+ } catch(e) {
1948
+ return recover(e);
1949
+ }
1950
+ if (result && result.then) {
1951
+ return result.then(void 0, recover);
1952
+ }
1953
+ return result;
1954
+ }
1955
+
1956
+ var EMPTY_TABLE = {
1957
+ rows: []
1958
+ };
1959
+ var useClipboardTable = function useClipboardTable() {
1960
+ var _useState = React.useState(),
1961
+ peek = _useState[0],
1962
+ setPeek = _useState[1];
1963
+
1764
1964
  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);
1965
+ var softRefresh = function softRefresh() {
1966
+ return Promise.resolve(_catch(function () {
1967
+ return Promise.resolve(navigator.permissions.query({
1968
+ name: 'clipboard-read'
1969
+ })).then(function (status) {
1970
+ if (status.state !== 'granted') return;
1971
+ hardRefresh();
1972
+ });
1973
+ }, function () {}));
1974
+ };
1975
+
1976
+ var hardRefresh = function hardRefresh() {
1977
+ try {
1978
+ var _temp3 = _catch(function () {
1979
+ return Promise.resolve(navigator.clipboard.read()).then(function (items) {
1980
+ var item = items[0];
1981
+
1982
+ var _temp = function () {
1983
+ if (item) {
1984
+ return Promise.resolve(parseClipboardTable(item)).then(function (peek) {
1985
+ setPeek(peek);
1986
+ });
1987
+ } else {
1988
+ setPeek(EMPTY_TABLE);
1989
+ }
1990
+ }();
1991
+
1992
+ if (_temp && _temp.then) return _temp.then(function () {});
1993
+ });
1994
+ }, function () {});
1995
+
1996
+ return Promise.resolve(_temp3 && _temp3.then ? _temp3.then(function () {}) : void 0);
1997
+ } catch (e) {
1998
+ return Promise.reject(e);
1999
+ }
2000
+ };
2001
+
2002
+ var delayedRefresh = function delayedRefresh() {
2003
+ return setTimeout(hardRefresh);
2004
+ };
2005
+
2006
+ window.document.addEventListener('cut', delayedRefresh);
2007
+ window.document.addEventListener('copy', delayedRefresh);
2008
+ window.document.addEventListener('focus', softRefresh);
2009
+ softRefresh();
2010
+ return function () {
2011
+ window.document.removeEventListener('cut', delayedRefresh);
2012
+ window.document.removeEventListener('copy', delayedRefresh);
2013
+ window.document.removeEventListener('focus', softRefresh);
2014
+ };
2015
+ }, []);
2016
+ var canPaste = React.useCallback(function () {
2017
+ var _peek$rows;
1770
2018
 
1771
- if (v.match(/^[\t\n]*$/)) {
1772
- v = ' ' + v;
2019
+ return !!(peek == null || (_peek$rows = peek.rows) !== null && _peek$rows !== void 0 && _peek$rows.length);
2020
+ }, [peek]);
2021
+ return {
2022
+ peek: peek,
2023
+ canPaste: canPaste,
2024
+ copyTable: copyClipboardTable,
2025
+ pasteTable: pasteClipboardTable
2026
+ };
2027
+ };
2028
+ var useClipboardAPI = function useClipboardAPI(selection, editData, cellReadOnly, addListener, onSelectionChange, onChange, onCopy, onPaste) {
2029
+ var _useClipboardTable = useClipboardTable(),
2030
+ canPaste = _useClipboardTable.canPaste,
2031
+ copyTable = _useClipboardTable.copyTable,
2032
+ pasteTable = _useClipboardTable.pasteTable;
2033
+
2034
+ var pasteIntoSelection = React.useCallback(function (selection, table) {
2035
+ try {
2036
+ var rows = table.rows,
2037
+ payload = table.payload;
2038
+
2039
+ var _normalizeSelection = normalizeSelection(selection),
2040
+ min = _normalizeSelection[0];
2041
+
2042
+ var minX = min[0],
2043
+ minY = min[1];
2044
+ var left = Math.max(0, minX);
2045
+ var top = Math.max(0, minY);
2046
+ var width = rows.reduce(function (a, b) {
2047
+ return Math.max(a, b.length);
2048
+ }, 0);
2049
+ var height = rows.length;
2050
+ var newSelection = [min, addXY(min, [width - 1, height - 1])];
2051
+ return Promise.resolve(onPaste === null || onPaste === void 0 ? void 0 : onPaste(newSelection, rows, payload)).then(function (shouldPaste) {
2052
+ if (shouldPaste !== false) {
2053
+ var changes = rows.flatMap(function (row, j) {
2054
+ return row.map(function (value, i) {
2055
+ var x = left + i;
2056
+ var y = top + j;
2057
+ return !(cellReadOnly !== null && cellReadOnly !== void 0 && cellReadOnly(x, y)) ? {
2058
+ x: x,
2059
+ y: y,
2060
+ value: value
2061
+ } : null;
2062
+ });
2063
+ }).filter(function (change) {
2064
+ return !!change;
2065
+ });
2066
+ onChange === null || onChange === void 0 ? void 0 : onChange(changes);
2067
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(newSelection);
2068
+ }
2069
+ });
2070
+ } catch (e) {
2071
+ return Promise.reject(e);
2072
+ }
2073
+ }, [onChange, onSelectionChange, cellReadOnly]);
2074
+ var copySelection = React.useCallback(function (selection, cut) {
2075
+ if (cut === void 0) {
2076
+ cut = false;
1773
2077
  }
1774
2078
 
1775
- textArea.value = v;
1776
- }, [selection, editMode, editData, textAreaRef]);
1777
- React.useLayoutEffect(function () {
1778
- var textArea = textAreaRef.current;
1779
- if (!textArea) return;
2079
+ try {
2080
+ var _payload$cut;
1780
2081
 
1781
- var focus = function focus() {
1782
- textArea.focus({
1783
- preventScroll: true
2082
+ var rows = formatSelectionAsRows(selection, editData);
2083
+ var payload = onCopy === null || onCopy === void 0 ? void 0 : onCopy(selection, rows, cut);
2084
+ copyTable(rows, payload);
2085
+
2086
+ if ((_payload$cut = payload === null || payload === void 0 ? void 0 : payload.cut) != null ? _payload$cut : cut) {
2087
+ var changes = [];
2088
+ forSelectionRows(selection)(function (y) {
2089
+ forSelectionColumns(selection)(function (x) {
2090
+ if (!(cellReadOnly !== null && cellReadOnly !== void 0 && cellReadOnly(x, y))) {
2091
+ var change = {
2092
+ x: x,
2093
+ y: y,
2094
+ value: ''
2095
+ };
2096
+ changes.push(change);
2097
+ }
2098
+ });
2099
+ });
2100
+ onChange === null || onChange === void 0 ? void 0 : onChange(changes);
2101
+ }
2102
+
2103
+ return Promise.resolve();
2104
+ } catch (e) {
2105
+ return Promise.reject(e);
2106
+ }
2107
+ }, [onCopy, onChange, cellReadOnly]);
2108
+ var pasteSelection = React.useCallback(function (selection) {
2109
+ try {
2110
+ return Promise.resolve(pasteTable()).then(function (table) {
2111
+ if (table) pasteIntoSelection(selection, table);
1784
2112
  });
1785
- textArea.select();
1786
- };
2113
+ } catch (e) {
2114
+ return Promise.reject(e);
2115
+ }
2116
+ }, [pasteIntoSelection]);
1787
2117
 
1788
- if (editMode) return;
1789
- if (document.activeElement === textArea) return;
1790
- var activeTagName = document.activeElement.tagName.toLowerCase();
2118
+ var onClipboardCopy = function onClipboardCopy(cut) {
2119
+ if (isEmptySelection(selection)) return;
2120
+ return copySelection(selection, cut);
2121
+ };
1791
2122
 
1792
- if (!(activeTagName === 'div' && document.activeElement.contentEditable === 'true' || activeTagName === 'input' || activeTagName === 'textarea' || activeTagName === 'select')) {
1793
- focus();
2123
+ var onClipboardPaste = function onClipboardPaste(e) {
2124
+ try {
2125
+ e.preventDefault();
2126
+ var clipboardData = e.clipboardData || window.clipboardData;
2127
+ return Promise.resolve(parseClipboardTable(clipboardData)).then(function (table) {
2128
+ if (table) pasteIntoSelection(selection, table);
2129
+ });
2130
+ } catch (e) {
2131
+ return Promise.reject(e);
1794
2132
  }
2133
+ };
2134
+
2135
+ React.useLayoutEffect(function () {
2136
+ if (!addListener) return;
2137
+ window.document.addEventListener('paste', onClipboardPaste);
2138
+ return function () {
2139
+ window.document.removeEventListener('paste', onClipboardPaste);
2140
+ };
1795
2141
  });
2142
+ var clipboardApi = React.useMemo(function () {
2143
+ return {
2144
+ copySelection: copySelection,
2145
+ pasteSelection: pasteSelection,
2146
+ canPasteSelection: canPaste
2147
+ };
2148
+ }, [copySelection, pasteSelection, canPaste]);
2149
+ return {
2150
+ clipboardApi: clipboardApi,
2151
+ onClipboardCopy: onClipboardCopy,
2152
+ onClipboardPaste: onClipboardPaste
2153
+ };
2154
+ };
2155
+
2156
+ var copyClipboardTable = function copyClipboardTable(rows, payload) {
2157
+ try {
2158
+ var text = formatRowsAsTSV(rows);
2159
+ var html = formatRowsAsHTML(rows, payload != null ? payload : undefined);
2160
+ return Promise.resolve(navigator.clipboard.write([new ClipboardItem({
2161
+ 'text/html': new Blob([html], {
2162
+ type: 'text/html'
2163
+ }),
2164
+ 'text/plain': new Blob([text], {
2165
+ type: 'text/plain'
2166
+ })
2167
+ })])).then(function () {
2168
+ var event = new Event('copy');
2169
+ document.dispatchEvent(event);
2170
+ });
2171
+ } catch (e) {
2172
+ return Promise.reject(e);
2173
+ }
1796
2174
  };
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
2175
 
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);
2176
+ var pasteClipboardTable = function pasteClipboardTable() {
2177
+ try {
2178
+ return Promise.resolve(navigator.clipboard.read()).then(function (items) {
2179
+ var item = items[0];
2180
+ if (!item) return;
2181
+ return parseClipboardTable(item);
2182
+ });
2183
+ } catch (e) {
2184
+ return Promise.reject(e);
2185
+ }
2186
+ };
2187
+
2188
+ var parseClipboardTable = function parseClipboardTable(item) {
2189
+ try {
2190
+ var _temp7 = function _temp7() {
2191
+ return rows ? {
2192
+ rows: rows,
2193
+ payload: payload
2194
+ } : {
2195
+ rows: []
2196
+ };
1822
2197
  };
1823
2198
 
1824
- window.document.addEventListener('paste', onPaste);
1825
- return function () {
1826
- window.document.removeEventListener('paste', onPaste);
2199
+ var has = function has(type) {
2200
+ return item.types.includes(type);
2201
+ };
2202
+
2203
+ var get = function get(type) {
2204
+ if ('getData' in item) return item.getData(type);else if ('getType' in item) return item.getType(type).then(function (blob) {
2205
+ return blob.text();
2206
+ });
2207
+ return '';
1827
2208
  };
1828
- }, [textAreaRef, selection]);
2209
+
2210
+ var rows, payload;
2211
+
2212
+ var _temp8 = function () {
2213
+ if (has('text/html')) {
2214
+ return Promise.resolve(get('text/html')).then(function (pastedHtml) {
2215
+ var _parsePastedHtml = parsePastedHtml(pastedHtml);
2216
+
2217
+ rows = _parsePastedHtml.rows;
2218
+ payload = _parsePastedHtml.payload;
2219
+ });
2220
+ } else {
2221
+ var _temp9 = function () {
2222
+ if (has('text/plain')) {
2223
+ return Promise.resolve(get('text/plain')).then(function (text) {
2224
+ rows = parsePastedText(text);
2225
+ });
2226
+ }
2227
+ }();
2228
+
2229
+ if (_temp9 && _temp9.then) return _temp9.then(function () {});
2230
+ }
2231
+ }();
2232
+
2233
+ return Promise.resolve(_temp8 && _temp8.then ? _temp8.then(_temp7) : _temp7(_temp8));
2234
+ } catch (e) {
2235
+ return Promise.reject(e);
2236
+ }
1829
2237
  };
1830
2238
 
1831
- var formatTSV = function formatTSV(rows) {
2239
+ var formatRowsAsTSV = function formatRowsAsTSV(rows) {
1832
2240
  return rows.map(function (row) {
1833
2241
  return row.join('\t');
1834
2242
  }).join('\n');
1835
2243
  };
1836
2244
 
1837
- var formatSelectionAsTSV = function formatSelectionAsTSV(selection, editData) {
1838
- if (isEmptySelection(selection)) return '';
2245
+ var formatRowsAsHTML = function formatRowsAsHTML(rows, payload) {
2246
+ var trs = rows.map(function (row) {
2247
+ var tds = row.map(formatTextAsHTML).map(function (cell) {
2248
+ return "<td>" + cell + "</td>";
2249
+ });
2250
+ return tds.join('');
2251
+ }).map(function (row) {
2252
+ return "<tr>" + row + "</tr>";
2253
+ }).join('\n');
2254
+ var table = "<table>" + trs + "</table>";
1839
2255
 
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];
2256
+ if (payload) {
2257
+ var extra = "<SheetHappens payload=\"" + formatTextAsHTML(JSON.stringify(payload)) + "\"></SheetHappens>";
2258
+ return extra + table;
2259
+ }
2260
+
2261
+ return table;
2262
+ };
2263
+
2264
+ var formatTextAsHTML = function formatTextAsHTML(s) {
2265
+ return s.replace(/[&"'<>]/g, function (i) {
2266
+ return "&#" + i.charCodeAt(0) + ";";
2267
+ });
2268
+ };
2269
+
2270
+ var formatSelectionAsRows = function formatSelectionAsRows(selection, editData) {
2271
+ if (isEmptySelection(selection)) return [];
2272
+
2273
+ var _normalizeSelection2 = normalizeSelection(selection),
2274
+ _normalizeSelection2$ = _normalizeSelection2[0],
2275
+ minX = _normalizeSelection2$[0],
2276
+ minY = _normalizeSelection2$[1],
2277
+ _normalizeSelection2$2 = _normalizeSelection2[1],
2278
+ maxX = _normalizeSelection2$2[0],
2279
+ maxY = _normalizeSelection2$2[1];
1847
2280
 
1848
2281
  if (isMaybeRowSelection(selection)) {
1849
2282
  var _findApproxMaxEditDat = findApproxMaxEditDataIndex(editData),
@@ -1877,132 +2310,94 @@ var formatSelectionAsTSV = function formatSelectionAsTSV(selection, editData) {
1877
2310
  rows.push(row);
1878
2311
  }
1879
2312
 
1880
- return formatTSV(rows);
2313
+ return rows;
1881
2314
  };
1882
2315
 
1883
- var findTable = function findTable(element) {
2316
+ var findTag = function findTag(element, tagName) {
1884
2317
  for (var _iterator = _createForOfIteratorHelperLoose(element.children), _step; !(_step = _iterator()).done;) {
1885
2318
  var child = _step.value;
1886
2319
 
1887
- if (child.nodeName === 'TABLE') {
2320
+ if (child.nodeName === tagName) {
1888
2321
  return child;
1889
2322
  }
1890
2323
 
1891
- var maybeTable = findTable(child);
2324
+ var maybeTag = findTag(child, tagName);
1892
2325
 
1893
- if (maybeTable) {
1894
- return maybeTable;
2326
+ if (maybeTag) {
2327
+ return maybeTag;
1895
2328
  }
1896
2329
  }
1897
2330
  };
1898
2331
 
1899
- var parsePastedHtml = function parsePastedHtml(selection, html, isReadOnly) {
2332
+ var parsePastedHtml = function parsePastedHtml(html) {
1900
2333
  var div = document.createElement('div');
1901
2334
  div.innerHTML = html.trim();
2335
+ var rows = [];
2336
+ var payload = undefined;
2337
+ var sheetNode = findTag(div, 'SHEETHAPPENS');
1902
2338
 
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);
2339
+ if (sheetNode) {
2340
+ var json = sheetNode.getAttribute('payload');
1912
2341
 
1913
- if (!tableNode) {
1914
- return null;
2342
+ try {
2343
+ payload = JSON.parse(json);
2344
+ } catch (e) {}
1915
2345
  }
1916
2346
 
1917
- var right = left;
1918
- var bottom = top;
1919
- var y = top;
2347
+ var tableNode = findTag(div, 'TABLE');
1920
2348
 
1921
- for (var _iterator2 = _createForOfIteratorHelperLoose(tableNode.children), _step2; !(_step2 = _iterator2()).done;) {
1922
- var tableChild = _step2.value;
2349
+ if (tableNode) {
2350
+ for (var _iterator2 = _createForOfIteratorHelperLoose(tableNode.children), _step2; !(_step2 = _iterator2()).done;) {
2351
+ var tableChild = _step2.value;
1923
2352
 
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;
2353
+ if (tableChild.nodeName === 'TBODY') {
2354
+ for (var _iterator3 = _createForOfIteratorHelperLoose(tableChild.children), _step3; !(_step3 = _iterator3()).done;) {
2355
+ var tr = _step3.value;
1928
2356
 
1929
- if (tr.nodeName === 'TR') {
1930
- for (var _iterator4 = _createForOfIteratorHelperLoose(tr.children), _step4; !(_step4 = _iterator4()).done;) {
1931
- var td = _step4.value;
2357
+ if (tr.nodeName === 'TR') {
2358
+ var row = [];
1932
2359
 
1933
- if (td.nodeName === 'TD') {
1934
- var str = '';
2360
+ for (var _iterator4 = _createForOfIteratorHelperLoose(tr.children), _step4; !(_step4 = _iterator4()).done;) {
2361
+ var td = _step4.value;
1935
2362
 
1936
- if (td.children.length !== 0 && td.children[0].nodeName === 'P') {
1937
- var p = td.children[0];
2363
+ if (td.nodeName === 'TD') {
2364
+ var str = '';
1938
2365
 
1939
- if (p.children.length !== 0 && p.children[0].nodeName === 'FONT') {
1940
- str = p.children[0].textContent.trim();
2366
+ if (td.children.length !== 0 && td.children[0].nodeName === 'P') {
2367
+ var p = td.children[0];
2368
+
2369
+ if (p.children.length !== 0 && p.children[0].nodeName === 'FONT') {
2370
+ str = p.children[0].textContent.trim();
2371
+ } else {
2372
+ str = p.textContent.trim();
2373
+ }
1941
2374
  } else {
1942
- str = p.textContent.trim();
2375
+ str = td.textContent.trim();
1943
2376
  }
1944
- } else {
1945
- str = td.textContent.trim();
1946
- }
1947
2377
 
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++;
2378
+ str = str.replaceAll('\n', '');
2379
+ str = str.replaceAll(/\s\s+/g, ' ');
2380
+ row.push(str);
2381
+ }
1956
2382
  }
1957
- }
1958
2383
 
1959
- y++;
2384
+ rows.push(row);
2385
+ }
1960
2386
  }
1961
-
1962
- right = Math.max(right, x - 1);
1963
2387
  }
1964
2388
  }
1965
2389
  }
1966
2390
 
1967
- bottom = Math.max(top, y - 1);
1968
2391
  return {
1969
- selection: [[left, top], [right, bottom]],
1970
- changes: changes
2392
+ rows: rows,
2393
+ payload: payload
1971
2394
  };
1972
2395
  };
1973
2396
 
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
- };
2397
+ var parsePastedText = function parsePastedText(text) {
2398
+ return text.split(/\r?\n/).map(function (line) {
2399
+ return line.split('\t');
2400
+ });
2006
2401
  };
2007
2402
 
2008
2403
  var INITIAL_SIZE = 256;
@@ -2385,7 +2780,40 @@ var makeIntMap = function makeIntMap(initialSize) {
2385
2780
  };
2386
2781
  };
2387
2782
 
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) {
2783
+ var resolveSheetStyle = function resolveSheetStyle(sheetStyle) {
2784
+ var _sheetStyle$shadowBlu, _sheetStyle$shadowOpa, _sheetStyle$shadowCol;
2785
+
2786
+ return {
2787
+ freezeColumns: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeColumns) || 0,
2788
+ freezeRows: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.freezeRows) || 0,
2789
+ hideColumnHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideColumnHeaders) || false,
2790
+ hideRowHeaders: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideRowHeaders) || false,
2791
+ hideGridlines: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideGridlines) || false,
2792
+ hideScrollBars: (sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.hideScrollBars) || false,
2793
+ columnHeaderHeight: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideColumnHeaders ? 1 : SIZES.headerHeight,
2794
+ rowHeaderWidth: sheetStyle !== null && sheetStyle !== void 0 && sheetStyle.hideRowHeaders ? 1 : SIZES.headerWidth,
2795
+ shadowBlur: (_sheetStyle$shadowBlu = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowBlur) != null ? _sheetStyle$shadowBlu : SIZES.shadowBlur,
2796
+ shadowOpacity: (_sheetStyle$shadowOpa = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowOpacity) != null ? _sheetStyle$shadowOpa : SIZES.shadowOpacity,
2797
+ shadowColor: (_sheetStyle$shadowCol = sheetStyle === null || sheetStyle === void 0 ? void 0 : sheetStyle.shadowColor) != null ? _sheetStyle$shadowCol : COLORS.shadowColor
2798
+ };
2799
+ };
2800
+ var applyAlignment = function applyAlignment(start, cellSize, style, imageWidth, alignment) {
2801
+ if (alignment === void 0) {
2802
+ alignment = style.textAlign;
2803
+ }
2804
+
2805
+ if (alignment === 'left') {
2806
+ return start + style.marginLeft;
2807
+ } else if (alignment === 'center') {
2808
+ return start + cellSize * 0.5 - imageWidth / 2;
2809
+ } else if (alignment === 'right') {
2810
+ return start + (cellSize - style.marginRight - imageWidth);
2811
+ }
2812
+
2813
+ return start;
2814
+ };
2815
+
2816
+ 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
2817
  var canvas = context.canvas;
2390
2818
  var width = canvas.width,
2391
2819
  height = canvas.height;
@@ -2547,11 +2975,13 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2547
2975
  var isGroupSelected = rowSelectionActive && isInRowGroup;
2548
2976
  var style = isSelfSelected ? HEADER_SELECTED_STYLE : isGroupSelected ? HEADER_GROUP_SELECTED_STYLE : isActive ? HEADER_ACTIVE_STYLE : NO_STYLE;
2549
2977
 
2978
+ var resolvedStyle = _extends({}, DEFAULT_COLUMN_HEADER_STYLE, style);
2979
+
2550
2980
  var _top2 = rowToPixel(row);
2551
2981
 
2552
2982
  var _bottom2 = rowToPixel(row, 1);
2553
2983
 
2554
- clickables.push.apply(clickables, renderCell(context, content, style, DEFAULT_COLUMN_HEADER_STYLE, 0, _top2, rowHeaderWidth, _bottom2 - _top2));
2984
+ clickables.push.apply(clickables, renderCell(context, content, resolvedStyle, 0, _top2, rowHeaderWidth, _bottom2 - _top2));
2555
2985
  }
2556
2986
  }
2557
2987
 
@@ -2564,8 +2994,6 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2564
2994
 
2565
2995
  var column = _step5.value;
2566
2996
 
2567
- var _content = (_columnHeaders = columnHeaders(column)) != null ? _columnHeaders : excelHeaderString(column + 1);
2568
-
2569
2997
  var _isActive = isInRange(column, minX, maxX);
2570
2998
 
2571
2999
  var _groupKey = columnGroupKeys(column);
@@ -2575,19 +3003,22 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2575
3003
  var selectedStyle = isSelected ? HEADER_SELECTED_STYLE : NO_STYLE;
2576
3004
  var activeStyle = _isActive ? HEADER_ACTIVE_STYLE : NO_STYLE;
2577
3005
 
2578
- var _style = _extends({}, columnHeaderStyle(column), activeStyle, selectedStyle);
3006
+ var _style = _extends({}, DEFAULT_COLUMN_HEADER_STYLE, columnHeaderStyle(column), activeStyle, selectedStyle);
2579
3007
 
2580
3008
  var _left2 = columnToPixel(column);
2581
3009
 
2582
3010
  var _right2 = columnToPixel(column, 1);
2583
3011
 
2584
- clickables.push.apply(clickables, renderCell(context, _content, _style, DEFAULT_COLUMN_HEADER_STYLE, _left2, 0, _right2 - _left2, columnHeaderHeight));
3012
+ var _content = (_columnHeaders = columnHeaders(column, _style)) != null ? _columnHeaders : excelHeaderString(column + 1);
3013
+
3014
+ clickables.push.apply(clickables, renderCell(context, _content, _style, _left2, 0, _right2 - _left2, columnHeaderHeight));
2585
3015
  }
2586
3016
  }
2587
3017
 
2588
3018
  if (selectionActive) {
2589
3019
  context.strokeStyle = COLORS.selectionBorder;
2590
3020
  context.lineWidth = 2;
3021
+ context.globalAlpha = isFocused ? 1 : 0.5;
2591
3022
  var _selected$7 = selected[0],
2592
3023
  _left3 = _selected$7[0],
2593
3024
  _top3 = _selected$7[1],
@@ -2595,6 +3026,7 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2595
3026
  _right3 = _selected$8[0],
2596
3027
  _bottom3 = _selected$8[1];
2597
3028
  context.strokeRect(_left3, _top3, _right3 - _left3 - 1, _bottom3 - _top3 - 1);
3029
+ context.globalAlpha = 1;
2598
3030
  }
2599
3031
 
2600
3032
  for (var _iterator6 = _createForOfIteratorHelperLoose(secondarySelections), _step6; !(_step6 = _iterator6()).done;) {
@@ -2744,43 +3176,42 @@ var renderSheet = function renderSheet(context, cellLayout, visibleCells, sheetS
2744
3176
 
2745
3177
  var _bottom10 = rowToPixel(_y, 1);
2746
3178
 
2747
- var cellContent = displayData(_x, _y);
3179
+ var _style2 = _extends({}, DEFAULT_CELL_STYLE, cellStyle(_x, _y));
2748
3180
 
2749
- if (cellContent !== null && cellContent !== undefined) {
2750
- var _style2 = cellStyle(_x, _y);
3181
+ var cellContent = displayData(_x, _y, _style2);
2751
3182
 
2752
- clickables.push.apply(clickables, renderCell(context, cellContent, _style2, DEFAULT_CELL_STYLE, _left9, _top9, _right10 - _left9, _bottom10 - _top9));
3183
+ if (cellContent !== null && cellContent !== undefined) {
3184
+ clickables.push.apply(clickables, renderCell(context, cellContent, _style2, _left9, _top9, _right10 - _left9, _bottom10 - _top9));
2753
3185
  }
2754
3186
  }
2755
3187
  }
2756
3188
 
2757
3189
  return clickables;
2758
3190
  };
2759
- var renderCell = function renderCell(context, cellContent, style, defaultCellStyle, xCoord, yCoord, cellWidth, cellHeight) {
3191
+ var renderCell = function renderCell(context, cellContent, style, xCoord, yCoord, cellWidth, cellHeight) {
2760
3192
  var clickables = [];
2761
3193
 
2762
3194
  if (cellContent === null) {
2763
3195
  return clickables;
2764
3196
  }
2765
3197
 
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;
3198
+ context.fillStyle = style.color;
3199
+ context.font = style.weight + ' ' + style.fontSize + 'px ' + style.fontFamily;
3200
+ context.textAlign = style.textAlign;
2770
3201
  var yy = Math.floor(yCoord + cellHeight * 0.5);
2771
3202
  context.save();
2772
3203
  context.beginPath();
2773
3204
  context.rect(xCoord, yCoord, cellWidth, cellHeight);
2774
3205
  context.clip();
2775
3206
 
2776
- if (finalStyle.backgroundColor !== '') {
2777
- context.fillStyle = finalStyle.backgroundColor;
3207
+ if (style.backgroundColor !== '') {
3208
+ context.fillStyle = style.backgroundColor;
2778
3209
  context.fillRect(xCoord, yCoord, cellWidth, cellHeight);
2779
- context.fillStyle = finalStyle.color;
3210
+ context.fillStyle = style.color;
2780
3211
  }
2781
3212
 
2782
3213
  if (typeof cellContent === 'string' || typeof cellContent === 'number') {
2783
- var xx = applyAlignment(xCoord, cellWidth, finalStyle, 0);
3214
+ var xx = applyAlignment(xCoord, cellWidth, style, 0);
2784
3215
  var text = '' + cellContent;
2785
3216
  context.fillText(text, xx, yy);
2786
3217
  } else if (typeof cellContent === 'object') {
@@ -2794,7 +3225,7 @@ var renderCell = function renderCell(context, cellContent, style, defaultCellSty
2794
3225
  if (obj.content instanceof HTMLImageElement) {
2795
3226
  w = obj.width || cellWidth;
2796
3227
  h = obj.height || cellHeight;
2797
- var finalX = applyAlignment(xCoord, cellWidth, finalStyle, w, obj.horizontalAlign);
3228
+ var finalX = applyAlignment(xCoord, cellWidth, style, w, obj.horizontalAlign);
2798
3229
  x = finalX + obj.x;
2799
3230
  y = yy + obj.y;
2800
3231
  context.drawImage(obj.content, x, y, w, h);
@@ -2803,7 +3234,7 @@ var renderCell = function renderCell(context, cellContent, style, defaultCellSty
2803
3234
  context.textAlign = obj.horizontalAlign;
2804
3235
  }
2805
3236
 
2806
- var _finalX = applyAlignment(xCoord, cellWidth, finalStyle, 0, obj.horizontalAlign);
3237
+ var _finalX = applyAlignment(xCoord, cellWidth, style, 0, obj.horizontalAlign);
2807
3238
 
2808
3239
  var _text = '' + obj.content;
2809
3240
 
@@ -3029,8 +3460,8 @@ var Sheet = React.forwardRef(function (props, ref) {
3029
3460
  var selectionProp = (_props$selection = props.selection) != null ? _props$selection : NO_SELECTION;
3030
3461
 
3031
3462
  var _useState3 = React.useState(selectionProp),
3032
- selection = _useState3[0],
3033
- setSelection = _useState3[1];
3463
+ rawSelection = _useState3[0],
3464
+ setRawSelection = _useState3[1];
3034
3465
 
3035
3466
  var _useState4 = React.useState(null),
3036
3467
  knobArea = _useState4[0],
@@ -3052,22 +3483,26 @@ var Sheet = React.forwardRef(function (props, ref) {
3052
3483
  editCell = _useState8[0],
3053
3484
  setEditCell = _useState8[1];
3054
3485
 
3055
- var _useState9 = React.useState(selectionProp),
3056
- lastSelectionProp = _useState9[0],
3057
- setLastSelectionProp = _useState9[1];
3486
+ var _useState9 = React.useState(!!props.autoFocus),
3487
+ focused = _useState9[0],
3488
+ setFocused = _useState9[1];
3489
+
3490
+ var _useState10 = React.useState(selectionProp),
3491
+ lastSelectionProp = _useState10[0],
3492
+ setLastSelectionProp = _useState10[1];
3058
3493
 
3059
3494
  if (lastSelectionProp !== selectionProp) {
3060
3495
  setLastSelectionProp(selectionProp);
3061
- setSelection(selectionProp);
3496
+ setRawSelection(selectionProp);
3062
3497
  }
3063
3498
 
3064
- var _useState10 = React.useState(''),
3065
- editValue = _useState10[0],
3066
- setEditValue = _useState10[1];
3499
+ var _useState11 = React.useState(''),
3500
+ editValue = _useState11[0],
3501
+ setEditValue = _useState11[1];
3067
3502
 
3068
- var _useState11 = React.useState(false),
3069
- arrowKeyCommitMode = _useState11[0],
3070
- setArrowKeyCommitMode = _useState11[1];
3503
+ var _useState12 = React.useState(false),
3504
+ arrowKeyCommitMode = _useState12[0],
3505
+ setArrowKeyCommitMode = _useState12[1];
3071
3506
 
3072
3507
  var _useResizeObserver = useResizeObserver({
3073
3508
  ref: overlayRef
@@ -3084,7 +3519,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3084
3519
  return createRowOrColumnProp(props.cellHeight, 22);
3085
3520
  }, [props.cellHeight]);
3086
3521
  var columnHeaders = React.useMemo(function () {
3087
- return createRowOrColumnProp(props.columnHeaders, null);
3522
+ return createRowOrColumnStyledProp(props.columnHeaders, null);
3088
3523
  }, [props.columnHeaders]);
3089
3524
  var columnHeaderStyle = React.useMemo(function () {
3090
3525
  return createRowOrColumnProp(props.columnHeaderStyle, {});
@@ -3114,7 +3549,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3114
3549
  return createCellProp(props.sourceData, null);
3115
3550
  }, [props.sourceData]);
3116
3551
  var displayData = React.useMemo(function () {
3117
- return createCellProp(props.displayData, '');
3552
+ return createCellStyledProp(props.displayData, '');
3118
3553
  }, [props.displayData]);
3119
3554
  var editData = React.useMemo(function () {
3120
3555
  return createCellProp(props.editData, '');
@@ -3129,6 +3564,9 @@ var Sheet = React.forwardRef(function (props, ref) {
3129
3564
  return resolveSheetStyle(props.sheetStyle);
3130
3565
  }, [props.sheetStyle]);
3131
3566
  var secondarySelections = (_props$secondarySelec = props.secondarySelections) != null ? _props$secondarySelec : NO_SELECTIONS;
3567
+ var selection = React.useMemo(function () {
3568
+ return validateSelection(rawSelection);
3569
+ }, [rawSelection]);
3132
3570
  var selectedColumnGroups = React.useMemo(function () {
3133
3571
  return props.columnGroupKeys ? new Set(mapSelectionColumns(selection)(function (x) {
3134
3572
  return columnGroupKeys(x);
@@ -3207,7 +3645,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3207
3645
  }
3208
3646
 
3209
3647
  if (!isSameSelection(selection, newSelection)) {
3210
- setSelection(validateSelection(newSelection));
3648
+ setRawSelection(newSelection);
3211
3649
  }
3212
3650
 
3213
3651
  var overlay = overlayRef.current;
@@ -3218,7 +3656,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3218
3656
  }
3219
3657
 
3220
3658
  if (props.onSelectionChanged) {
3221
- var _normalizeSelection = normalizeSelection(newSelection),
3659
+ var _normalizeSelection = normalizeSelection(validateSelection(newSelection)),
3222
3660
  _normalizeSelection$ = _normalizeSelection[0],
3223
3661
  minX = _normalizeSelection$[0],
3224
3662
  minY = _normalizeSelection$[1],
@@ -3230,6 +3668,11 @@ var Sheet = React.forwardRef(function (props, ref) {
3230
3668
  }
3231
3669
  };
3232
3670
 
3671
+ var cancelEditingCell = function cancelEditingCell() {
3672
+ setEditCell(NO_CELL);
3673
+ setFocused(true);
3674
+ };
3675
+
3233
3676
  var commitEditingCell = function commitEditingCell(value) {
3234
3677
  if (props.onChange) {
3235
3678
  var cellX = editCell[0],
@@ -3242,6 +3685,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3242
3685
  }
3243
3686
 
3244
3687
  setEditCell(NO_CELL);
3688
+ setFocused(true);
3245
3689
  };
3246
3690
 
3247
3691
  var startEditingCell = function startEditingCell(editCell, arrowKeyCommitMode) {
@@ -3279,16 +3723,25 @@ var Sheet = React.forwardRef(function (props, ref) {
3279
3723
  setDataOffset(clipDataOffset(view, dataOffset, freeze, [maxColumns, maxRows], cellLayout));
3280
3724
  }, [maxRows, maxColumns]);
3281
3725
  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);
3726
+ var isFocused = focused || editMode;
3727
+
3728
+ var _useClipboardAPI = useClipboardAPI(selection, editData, cellReadOnly, isFocused, changeSelection, props.onChange, props.onCopy, props.onPaste),
3729
+ clipboardApi = _useClipboardAPI.clipboardApi,
3730
+ onClipboardCopy = _useClipboardAPI.onClipboardCopy;
3731
+
3285
3732
  var onScroll = useScroll(dataOffset, maxScroll, cellLayout, setDataOffset, setMaxScroll);
3286
3733
  var getAutoSizeWidth = useAutoSizeColumn(visibleCells.rows, displayData, cellStyle, columnHeaders, columnHeaderStyle, canvasWidth);
3287
3734
 
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),
3735
+ 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
3736
  mouseHandlers = _useMouse.mouseHandlers,
3290
3737
  knobPosition = _useMouse.knobPosition;
3291
3738
 
3739
+ var _useKeyboard = useKeyboard(arrowKeyCommitMode, overlayRef, cellReadOnly, displayData, editCell, editMode, focused, rawSelection, selection, startEditingCell, commitEditingCell, cancelEditingCell, changeSelection, setFocused, onClipboardCopy, props.onChange),
3740
+ onInputKeyDown = _useKeyboard.onInputKeyDown,
3741
+ onGridKeyDown = _useKeyboard.onGridKeyDown,
3742
+ onGridFocus = _useKeyboard.onGridFocus,
3743
+ onGridBlur = _useKeyboard.onGridBlur;
3744
+
3292
3745
  React.useLayoutEffect(function () {
3293
3746
  var canvas = canvasRef.current;
3294
3747
 
@@ -3303,130 +3756,16 @@ var Sheet = React.forwardRef(function (props, ref) {
3303
3756
  }
3304
3757
 
3305
3758
  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);
3759
+ 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
3760
  });
3308
3761
  return function () {
3309
3762
  window.cancelAnimationFrame(animationFrameId);
3310
3763
  };
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
- }
3764
+ }, [cellLayout, visibleCells, sheetStyle, cellStyle, selection, secondarySelections, isFocused, knobPosition, knobArea, dragOffset, dropTarget, columnHeaders, columnHeaderStyle, displayData, columnGroupKeys, rowGroupKeys, selectedColumnGroups, selectedRowGroups, dataOffset]);
3339
3765
 
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
- }
3419
-
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];
3766
+ var _useState13 = React.useState(''),
3767
+ lastEditKey = _useState13[0],
3768
+ setLastEditKey = _useState13[1];
3430
3769
 
3431
3770
  var editTextPosition = ORIGIN;
3432
3771
  var editTextWidth = 0;
@@ -3454,7 +3793,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3454
3793
  var inputProps = {
3455
3794
  value: editValue,
3456
3795
  autoFocus: true,
3457
- onKeyDown: onKeyDown,
3796
+ onKeyDown: onInputKeyDown,
3458
3797
  style: {
3459
3798
  position: 'absolute',
3460
3799
  left: textX,
@@ -3481,6 +3820,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3481
3820
  top: 0,
3482
3821
  left: 0,
3483
3822
  overflow: 'scroll',
3823
+ outline: 0,
3484
3824
  borderBottom: '1px solid #ddd'
3485
3825
  };
3486
3826
  var canvasStyles = {
@@ -3516,10 +3856,10 @@ var Sheet = React.forwardRef(function (props, ref) {
3516
3856
  });
3517
3857
  }, [props.renderOutside, visibleCells, cellLayout, selection, editMode]);
3518
3858
  React.useImperativeHandle(ref, function () {
3519
- return _extends({}, cellLayout, {
3859
+ return _extends({}, cellLayout, clipboardApi, {
3520
3860
  startEditingCell: startEditingCell
3521
3861
  });
3522
- }, [cellLayout, startEditingCell]);
3862
+ }, [cellLayout, clipboardApi, startEditingCell]);
3523
3863
  return React__default.createElement("div", {
3524
3864
  style: {
3525
3865
  position: 'relative',
@@ -3532,6 +3872,10 @@ var Sheet = React.forwardRef(function (props, ref) {
3532
3872
  }), React__default.createElement("div", Object.assign({
3533
3873
  ref: overlayRef
3534
3874
  }, mouseHandlers, {
3875
+ onKeyDown: onGridKeyDown,
3876
+ onFocus: onGridFocus,
3877
+ onBlur: onGridBlur,
3878
+ tabIndex: 0,
3535
3879
  onScroll: onScroll,
3536
3880
  className: overlayDivClassName,
3537
3881
  style: overlayDivStyles
@@ -3568,26 +3912,7 @@ var Sheet = React.forwardRef(function (props, ref) {
3568
3912
  height: '100%',
3569
3913
  pointerEvents: 'none'
3570
3914
  }
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, {
3915
+ }, renderedOutside) : null, editMode && (input !== undefined ? input : React__default.createElement("input", Object.assign({}, inputProps, {
3591
3916
  type: "text",
3592
3917
  onFocus: function onFocus(e) {
3593
3918
  return e.target.select();
@@ -3598,5 +3923,6 @@ var Sheet = React.forwardRef(function (props, ref) {
3598
3923
  }))));
3599
3924
  });
3600
3925
 
3601
- module.exports = Sheet;
3926
+ exports.default = Sheet;
3927
+ exports.useClipboardTable = useClipboardTable;
3602
3928
  //# sourceMappingURL=index.js.map