sheet-happens 0.0.6 → 0.0.10
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.d.ts +11 -2
- package/dist/index.js +227 -112
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +227 -112
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import { MouseEvent } from 'react';
|
|
1
|
+
import React, { MouseEvent, CSSProperties, ReactElement } from 'react';
|
|
2
2
|
declare type PropTypes = string | number | boolean | Style | CellContentType;
|
|
3
3
|
declare type RowOrColumnProperty<T extends PropTypes> = T | Array<T> | ((index: number) => T);
|
|
4
4
|
declare type CellProperty<T extends PropTypes> = T | Array<Array<T>> | ((x: number, y: number) => T);
|
|
5
5
|
declare type CellContentType = null | number | string | CellContent;
|
|
6
|
+
declare type InputStyle = Pick<CSSProperties, 'position' | 'top' | 'left' | 'width' | 'height' | 'outline' | 'border' | 'textAlign' | 'color' | 'fontSize' | 'fontFamily'>;
|
|
7
|
+
export interface SheetInputProps {
|
|
8
|
+
value: string;
|
|
9
|
+
autoFocus: boolean;
|
|
10
|
+
onKeyDown: React.KeyboardEventHandler<HTMLElement>;
|
|
11
|
+
onChange: (valiue: string) => void;
|
|
12
|
+
style: InputStyle;
|
|
13
|
+
}
|
|
6
14
|
export interface Change {
|
|
7
15
|
x: number;
|
|
8
16
|
y: number;
|
|
@@ -15,7 +23,7 @@ export interface CellContentItem {
|
|
|
15
23
|
width?: number;
|
|
16
24
|
height?: number;
|
|
17
25
|
horiozntalAlign?: 'left' | 'right' | 'center';
|
|
18
|
-
onClick?: () => void;
|
|
26
|
+
onClick?: (e: MouseEvent) => void;
|
|
19
27
|
}
|
|
20
28
|
export interface CellContent {
|
|
21
29
|
items: Array<CellContentItem>;
|
|
@@ -36,6 +44,7 @@ export interface SheetProps {
|
|
|
36
44
|
sourceData?: CellProperty<string | number | null>;
|
|
37
45
|
displayData?: CellProperty<CellContentType>;
|
|
38
46
|
editData?: CellProperty<string>;
|
|
47
|
+
inputComponent?: (x: number, y: number, props: SheetInputProps, commitEditingCell?: () => void) => ReactElement | undefined;
|
|
39
48
|
onSelectionChanged?: (x1: number, y1: number, x2: number, y2: number) => void;
|
|
40
49
|
onRightClick?: (e: SheetMouseEvent) => void;
|
|
41
50
|
onChange?: (changes: Array<Change>) => void;
|
package/dist/index.js
CHANGED
|
@@ -592,6 +592,8 @@ function renderOnCanvas(context, rowSizes, columnSizes, cellStyle, cellWidth, ce
|
|
|
592
592
|
}
|
|
593
593
|
|
|
594
594
|
function Sheet(props) {
|
|
595
|
+
var _props$inputComponent;
|
|
596
|
+
|
|
595
597
|
var canvasRef = React.useRef(null);
|
|
596
598
|
var overlayRef = React.useRef(null);
|
|
597
599
|
var copyPasteTextAreaRef = React.useRef(null);
|
|
@@ -834,74 +836,138 @@ function Sheet(props) {
|
|
|
834
836
|
|
|
835
837
|
resizeCanvas(canvas);
|
|
836
838
|
var yCoord = columnHeaderHeight;
|
|
839
|
+
var xCoord = rowHeaderWidth;
|
|
840
|
+
|
|
841
|
+
for (var _iterator10 = _createForOfIteratorHelperLoose(columnSizes.index), _step10; !(_step10 = _iterator10()).done;) {
|
|
842
|
+
var x = _step10.value;
|
|
843
|
+
var ch = columnHeaders(x);
|
|
844
|
+
var cellW = cellWidth(x);
|
|
845
|
+
|
|
846
|
+
if (ch && typeof ch === 'object' && ch.items) {
|
|
847
|
+
var finalStyle = void 0;
|
|
848
|
+
|
|
849
|
+
for (var _iterator12 = _createForOfIteratorHelperLoose(ch.items), _step12; !(_step12 = _iterator12()).done;) {
|
|
850
|
+
var obj = _step12.value;
|
|
851
|
+
|
|
852
|
+
if (obj.onClick) {
|
|
853
|
+
if (!finalStyle) {
|
|
854
|
+
finalStyle = createStyleObject(columnHeaderStyle(x), defaultCellStyle);
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
var w = obj.content instanceof HTMLImageElement ? obj.width || cellW : 0;
|
|
858
|
+
var absX1 = applyAlignment(xCoord, cellW, finalStyle, w, obj.horiozntalAlign) + obj.x;
|
|
859
|
+
var absY1 = columnHeaderHeight * 0.5 + obj.y;
|
|
860
|
+
var absX2 = absX1 + (obj.width || 0);
|
|
861
|
+
var absY2 = absY1 + (obj.height || 0);
|
|
862
|
+
var hitTarget = {
|
|
863
|
+
x: absX1,
|
|
864
|
+
y: absY1,
|
|
865
|
+
w: obj.width,
|
|
866
|
+
h: obj.height,
|
|
867
|
+
onClick: obj.onClick
|
|
868
|
+
};
|
|
869
|
+
var x1key = Math.floor(absX1 / xBinSize);
|
|
870
|
+
var x2key = Math.floor(absX2 / xBinSize);
|
|
871
|
+
var y1key = Math.floor(absY1 / yBinSize);
|
|
872
|
+
var y2key = Math.floor(absY2 / yBinSize);
|
|
873
|
+
|
|
874
|
+
for (var xkey = x1key; xkey <= x2key; xkey++) {
|
|
875
|
+
if (!hitM[xkey]) {
|
|
876
|
+
hitM[xkey] = {};
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
var xbin = hitM[xkey];
|
|
880
|
+
|
|
881
|
+
for (var ykey = y1key; ykey <= y2key; ykey++) {
|
|
882
|
+
if (!xbin[ykey]) {
|
|
883
|
+
xbin[ykey] = [];
|
|
884
|
+
}
|
|
837
885
|
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
886
|
+
xbin[ykey].push(hitTarget);
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
xCoord += cellW;
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
for (var _iterator11 = _createForOfIteratorHelperLoose(rowSizes.index), _step11; !(_step11 = _iterator11()).done;) {
|
|
897
|
+
var y = _step11.value;
|
|
898
|
+
xCoord = rowHeaderWidth;
|
|
899
|
+
|
|
900
|
+
for (var _iterator13 = _createForOfIteratorHelperLoose(columnSizes.index), _step13; !(_step13 = _iterator13()).done;) {
|
|
901
|
+
var _x2 = _step13.value;
|
|
902
|
+
var cellContent = displayData(_x2, y);
|
|
841
903
|
|
|
842
|
-
|
|
843
|
-
var x = _step11.value;
|
|
844
|
-
var cellContent = displayData(x, y);
|
|
845
|
-
var cellW = cellWidth(x);
|
|
904
|
+
var _cellW = cellWidth(_x2);
|
|
846
905
|
|
|
847
906
|
if (cellContent === null || cellContent === undefined) {
|
|
848
|
-
xCoord +=
|
|
907
|
+
xCoord += _cellW;
|
|
849
908
|
continue;
|
|
850
909
|
}
|
|
851
910
|
|
|
852
911
|
var xx = xCoord;
|
|
853
912
|
var yy = yCoord + cellHeight(y) * 0.5;
|
|
854
913
|
|
|
855
|
-
if (typeof cellContent === 'object') {
|
|
856
|
-
var
|
|
914
|
+
if (typeof cellContent === 'object' && cellContent.items) {
|
|
915
|
+
var _finalStyle = void 0;
|
|
857
916
|
|
|
858
|
-
for (var
|
|
859
|
-
var
|
|
917
|
+
for (var _iterator14 = _createForOfIteratorHelperLoose(cellContent.items), _step14; !(_step14 = _iterator14()).done;) {
|
|
918
|
+
var _obj = _step14.value;
|
|
860
919
|
|
|
861
|
-
if (
|
|
862
|
-
if (!
|
|
863
|
-
|
|
920
|
+
if (_obj.onClick) {
|
|
921
|
+
if (!_finalStyle) {
|
|
922
|
+
_finalStyle = createStyleObject(cellStyle(_x2, y), defaultCellStyle);
|
|
864
923
|
}
|
|
865
924
|
|
|
866
|
-
var
|
|
867
|
-
|
|
868
|
-
var
|
|
869
|
-
|
|
870
|
-
var
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
925
|
+
var _w = _obj.content instanceof HTMLImageElement ? _obj.width || _cellW : 0;
|
|
926
|
+
|
|
927
|
+
var _absX = applyAlignment(xx, _cellW, _finalStyle, _w, _obj.horiozntalAlign) + _obj.x;
|
|
928
|
+
|
|
929
|
+
var _absY = yy + _obj.y;
|
|
930
|
+
|
|
931
|
+
var _absX2 = _absX + (_obj.width || 0);
|
|
932
|
+
|
|
933
|
+
var _absY2 = _absY + (_obj.height || 0);
|
|
934
|
+
|
|
935
|
+
var _hitTarget = {
|
|
936
|
+
x: _absX,
|
|
937
|
+
y: _absY,
|
|
938
|
+
w: _obj.width,
|
|
939
|
+
h: _obj.height,
|
|
940
|
+
onClick: _obj.onClick
|
|
879
941
|
};
|
|
880
|
-
|
|
881
|
-
var
|
|
882
|
-
|
|
883
|
-
var
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
942
|
+
|
|
943
|
+
var _x1key = Math.floor(_absX / xBinSize);
|
|
944
|
+
|
|
945
|
+
var _x2key = Math.floor(_absX2 / xBinSize);
|
|
946
|
+
|
|
947
|
+
var _y1key = Math.floor(_absY / yBinSize);
|
|
948
|
+
|
|
949
|
+
var _y2key = Math.floor(_absY2 / yBinSize);
|
|
950
|
+
|
|
951
|
+
for (var _xkey = _x1key; _xkey <= _x2key; _xkey++) {
|
|
952
|
+
if (!hitM[_xkey]) {
|
|
953
|
+
hitM[_xkey] = {};
|
|
888
954
|
}
|
|
889
955
|
|
|
890
|
-
var
|
|
956
|
+
var _xbin = hitM[_xkey];
|
|
891
957
|
|
|
892
|
-
for (var
|
|
893
|
-
if (!
|
|
894
|
-
|
|
958
|
+
for (var _ykey = _y1key; _ykey <= _y2key; _ykey++) {
|
|
959
|
+
if (!_xbin[_ykey]) {
|
|
960
|
+
_xbin[_ykey] = [];
|
|
895
961
|
}
|
|
896
962
|
|
|
897
|
-
|
|
963
|
+
_xbin[_ykey].push(_hitTarget);
|
|
898
964
|
}
|
|
899
965
|
}
|
|
900
966
|
}
|
|
901
967
|
}
|
|
902
968
|
}
|
|
903
969
|
|
|
904
|
-
xCoord +=
|
|
970
|
+
xCoord += _cellW;
|
|
905
971
|
}
|
|
906
972
|
|
|
907
973
|
yCoord += cellHeight(y);
|
|
@@ -985,8 +1051,8 @@ function Sheet(props) {
|
|
|
985
1051
|
});
|
|
986
1052
|
|
|
987
1053
|
var findTable = function findTable(element) {
|
|
988
|
-
for (var
|
|
989
|
-
var child =
|
|
1054
|
+
for (var _iterator15 = _createForOfIteratorHelperLoose(element.children), _step15; !(_step15 = _iterator15()).done;) {
|
|
1055
|
+
var child = _step15.value;
|
|
990
1056
|
|
|
991
1057
|
if (child.nodeName === 'TABLE') {
|
|
992
1058
|
return child;
|
|
@@ -1035,23 +1101,39 @@ function Sheet(props) {
|
|
|
1035
1101
|
return;
|
|
1036
1102
|
}
|
|
1037
1103
|
|
|
1038
|
-
for (var
|
|
1039
|
-
var tableChild =
|
|
1104
|
+
for (var _iterator16 = _createForOfIteratorHelperLoose(tableNode.children), _step16; !(_step16 = _iterator16()).done;) {
|
|
1105
|
+
var tableChild = _step16.value;
|
|
1040
1106
|
|
|
1041
1107
|
if (tableChild.nodeName === 'TBODY') {
|
|
1042
|
-
for (var
|
|
1043
|
-
var tr =
|
|
1108
|
+
for (var _iterator17 = _createForOfIteratorHelperLoose(tableChild.children), _step17; !(_step17 = _iterator17()).done;) {
|
|
1109
|
+
var tr = _step17.value;
|
|
1044
1110
|
x = pasteLocX;
|
|
1045
1111
|
|
|
1046
1112
|
if (tr.nodeName === 'TR') {
|
|
1047
|
-
for (var
|
|
1048
|
-
var td =
|
|
1113
|
+
for (var _iterator18 = _createForOfIteratorHelperLoose(tr.children), _step18; !(_step18 = _iterator18()).done;) {
|
|
1114
|
+
var td = _step18.value;
|
|
1049
1115
|
|
|
1050
1116
|
if (td.nodeName === 'TD') {
|
|
1117
|
+
var str = '';
|
|
1118
|
+
|
|
1119
|
+
if (td.children.length !== 0 && td.children[0].nodeName === 'P') {
|
|
1120
|
+
var p = td.children[0];
|
|
1121
|
+
|
|
1122
|
+
if (p.children.length !== 0 && p.children[0].nodeName === 'FONT') {
|
|
1123
|
+
str = p.children[0].innerHTML;
|
|
1124
|
+
} else {
|
|
1125
|
+
str = p.innerHTML;
|
|
1126
|
+
}
|
|
1127
|
+
} else {
|
|
1128
|
+
str = td.innerHTML;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
str = str.replaceAll('\n', '');
|
|
1132
|
+
str = str.replaceAll(/\s\s+/g, ' ');
|
|
1051
1133
|
changes.push({
|
|
1052
1134
|
y: y,
|
|
1053
1135
|
x: x,
|
|
1054
|
-
value:
|
|
1136
|
+
value: str
|
|
1055
1137
|
});
|
|
1056
1138
|
x++;
|
|
1057
1139
|
}
|
|
@@ -1170,12 +1252,12 @@ function Sheet(props) {
|
|
|
1170
1252
|
}
|
|
1171
1253
|
};
|
|
1172
1254
|
|
|
1173
|
-
var commitEditingCell = function commitEditingCell() {
|
|
1255
|
+
var commitEditingCell = function commitEditingCell(value) {
|
|
1174
1256
|
if (props.onChange) {
|
|
1175
1257
|
props.onChange([{
|
|
1176
1258
|
x: editCell.x,
|
|
1177
1259
|
y: editCell.y,
|
|
1178
|
-
value: editValue
|
|
1260
|
+
value: value != null ? value : editValue
|
|
1179
1261
|
}]);
|
|
1180
1262
|
}
|
|
1181
1263
|
|
|
@@ -1246,6 +1328,7 @@ function Sheet(props) {
|
|
|
1246
1328
|
return;
|
|
1247
1329
|
}
|
|
1248
1330
|
|
|
1331
|
+
setSelectionInProgress(false);
|
|
1249
1332
|
var rect = e.target.getBoundingClientRect();
|
|
1250
1333
|
var x = e.clientX - rect.left;
|
|
1251
1334
|
var y = e.clientY - rect.top;
|
|
@@ -1258,8 +1341,8 @@ function Sheet(props) {
|
|
|
1258
1341
|
var hitTargetKeyY = Math.floor(y / yBinSize);
|
|
1259
1342
|
|
|
1260
1343
|
if (hitMap[hitTargetKeyX] && hitMap[hitTargetKeyX][hitTargetKeyY]) {
|
|
1261
|
-
for (var
|
|
1262
|
-
var hitTarget =
|
|
1344
|
+
for (var _iterator19 = _createForOfIteratorHelperLoose(hitMap[hitTargetKeyX][hitTargetKeyY]), _step19; !(_step19 = _iterator19()).done;) {
|
|
1345
|
+
var hitTarget = _step19.value;
|
|
1263
1346
|
|
|
1264
1347
|
if (hitTarget.x <= x && x <= hitTarget.x + hitTarget.w && hitTarget.y <= y && y <= hitTarget.y + hitTarget.h) {
|
|
1265
1348
|
setButtonClickMouseDownCoordinates({
|
|
@@ -1273,42 +1356,38 @@ function Sheet(props) {
|
|
|
1273
1356
|
}
|
|
1274
1357
|
|
|
1275
1358
|
if (y < columnHeaderHeight) {
|
|
1276
|
-
var
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
var
|
|
1359
|
+
for (var colIdx = 0; colIdx < columnSizes.index.length; colIdx++) {
|
|
1360
|
+
var start = columnSizes.start[colIdx];
|
|
1361
|
+
var end = columnSizes.end[colIdx];
|
|
1362
|
+
var index = columnSizes.index[colIdx];
|
|
1280
1363
|
|
|
1281
|
-
if (Math.abs(
|
|
1364
|
+
if (Math.abs(start - x) < resizeColumnRowMouseThreshold || Math.abs(end - x) < resizeColumnRowMouseThreshold) {
|
|
1282
1365
|
window.document.body.style.cursor = 'col-resize';
|
|
1283
1366
|
setColumnResize({
|
|
1284
|
-
startX:
|
|
1285
|
-
oldWidth: cellWidth(
|
|
1286
|
-
colIdx:
|
|
1367
|
+
startX: end,
|
|
1368
|
+
oldWidth: cellWidth(index),
|
|
1369
|
+
colIdx: index
|
|
1287
1370
|
});
|
|
1288
1371
|
return;
|
|
1289
1372
|
}
|
|
1290
|
-
|
|
1291
|
-
xx += cellWidth(col);
|
|
1292
1373
|
}
|
|
1293
1374
|
}
|
|
1294
1375
|
|
|
1295
1376
|
if (x < rowHeaderWidth) {
|
|
1296
|
-
var
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
var
|
|
1377
|
+
for (var rowIdx = 0; rowIdx < rowSizes.index.length; rowIdx++) {
|
|
1378
|
+
var _start = rowSizes.start[rowIdx];
|
|
1379
|
+
var _end = rowSizes.end[rowIdx];
|
|
1380
|
+
var _index = rowSizes.index[rowIdx];
|
|
1300
1381
|
|
|
1301
|
-
if (Math.abs(
|
|
1382
|
+
if (Math.abs(_start - y) < resizeColumnRowMouseThreshold || Math.abs(_end - y) < resizeColumnRowMouseThreshold) {
|
|
1302
1383
|
window.document.body.style.cursor = 'row-resize';
|
|
1303
1384
|
setRowResize({
|
|
1304
|
-
startY:
|
|
1305
|
-
oldHeight: cellHeight(
|
|
1306
|
-
rowIdx:
|
|
1385
|
+
startY: _end,
|
|
1386
|
+
oldHeight: cellHeight(_index),
|
|
1387
|
+
rowIdx: _index
|
|
1307
1388
|
});
|
|
1308
1389
|
return;
|
|
1309
1390
|
}
|
|
1310
|
-
|
|
1311
|
-
yy += cellHeight(row);
|
|
1312
1391
|
}
|
|
1313
1392
|
}
|
|
1314
1393
|
|
|
@@ -1336,7 +1415,7 @@ function Sheet(props) {
|
|
|
1336
1415
|
var scrollToP2 = true;
|
|
1337
1416
|
|
|
1338
1417
|
if (x < rowHeaderWidth) {
|
|
1339
|
-
sel2.x = 100;
|
|
1418
|
+
sel2.x = dataOffset.x + 100;
|
|
1340
1419
|
scrollToP2 = false;
|
|
1341
1420
|
setRowSelectionInProgress(true);
|
|
1342
1421
|
} else {
|
|
@@ -1344,7 +1423,7 @@ function Sheet(props) {
|
|
|
1344
1423
|
}
|
|
1345
1424
|
|
|
1346
1425
|
if (y < columnHeaderHeight) {
|
|
1347
|
-
sel2.y = 100;
|
|
1426
|
+
sel2.y = dataOffset.y + 100;
|
|
1348
1427
|
scrollToP2 = false;
|
|
1349
1428
|
setColumnSelectionInProgress(true);
|
|
1350
1429
|
} else {
|
|
@@ -1433,12 +1512,12 @@ function Sheet(props) {
|
|
|
1433
1512
|
|
|
1434
1513
|
var srcX = sx1;
|
|
1435
1514
|
|
|
1436
|
-
for (var
|
|
1515
|
+
for (var _x3 = fx1; _x3 <= fx2; _x3++) {
|
|
1437
1516
|
for (var _y2 = fy1; _y2 <= fy2; _y2++) {
|
|
1438
1517
|
var _value = sourceData(srcX, _y2);
|
|
1439
1518
|
|
|
1440
1519
|
changes.push({
|
|
1441
|
-
x:
|
|
1520
|
+
x: _x3,
|
|
1442
1521
|
y: _y2,
|
|
1443
1522
|
value: _value
|
|
1444
1523
|
});
|
|
@@ -1473,14 +1552,14 @@ function Sheet(props) {
|
|
|
1473
1552
|
|
|
1474
1553
|
var rect = e.target.getBoundingClientRect();
|
|
1475
1554
|
|
|
1476
|
-
var
|
|
1555
|
+
var _x4 = e.clientX - rect.left;
|
|
1477
1556
|
|
|
1478
1557
|
var _y3 = e.clientY - rect.top;
|
|
1479
1558
|
|
|
1480
1559
|
var hitTarget = buttonClickMouseDownCoordinates.hitTarget;
|
|
1481
1560
|
|
|
1482
|
-
if (hitTarget.x <=
|
|
1483
|
-
hitTarget.onClick();
|
|
1561
|
+
if (hitTarget.x <= _x4 && _x4 <= hitTarget.x + hitTarget.w && hitTarget.y <= _y3 && _y3 <= hitTarget.y + hitTarget.h) {
|
|
1562
|
+
hitTarget.onClick(e);
|
|
1484
1563
|
}
|
|
1485
1564
|
|
|
1486
1565
|
setButtonClickMouseDownCoordinates({
|
|
@@ -1602,7 +1681,14 @@ function Sheet(props) {
|
|
|
1602
1681
|
y2 = selection.y1;
|
|
1603
1682
|
}
|
|
1604
1683
|
|
|
1605
|
-
|
|
1684
|
+
var xCellDiff = 0;
|
|
1685
|
+
if (cell.x < x1) xCellDiff = cell.x - x1;
|
|
1686
|
+
if (cell.x > x2) xCellDiff = x2 - cell.x;
|
|
1687
|
+
var yCellDiff = 0;
|
|
1688
|
+
if (cell.y < y1) yCellDiff = cell.y - y1;
|
|
1689
|
+
if (cell.y > y2) yCellDiff = y2 - cell.y;
|
|
1690
|
+
|
|
1691
|
+
if (xCellDiff > yCellDiff) {
|
|
1606
1692
|
if (cell.y < y1) {
|
|
1607
1693
|
y1 = cell.y;
|
|
1608
1694
|
} else {
|
|
@@ -1626,7 +1712,9 @@ function Sheet(props) {
|
|
|
1626
1712
|
};
|
|
1627
1713
|
|
|
1628
1714
|
var onDoubleClick = function onDoubleClick(e) {
|
|
1629
|
-
|
|
1715
|
+
e.preventDefault();
|
|
1716
|
+
|
|
1717
|
+
if (!e.target || !(e.target instanceof Element) || shiftKeyDown) {
|
|
1630
1718
|
return;
|
|
1631
1719
|
}
|
|
1632
1720
|
|
|
@@ -1813,9 +1901,7 @@ function Sheet(props) {
|
|
|
1813
1901
|
};
|
|
1814
1902
|
|
|
1815
1903
|
var onContextMenu = function onContextMenu(e) {
|
|
1816
|
-
|
|
1817
|
-
return;
|
|
1818
|
-
}
|
|
1904
|
+
var _props$onRightClick;
|
|
1819
1905
|
|
|
1820
1906
|
if (!e.target || !(e.target instanceof Element)) {
|
|
1821
1907
|
return;
|
|
@@ -1825,17 +1911,41 @@ function Sheet(props) {
|
|
|
1825
1911
|
var x = e.clientX - rect.left;
|
|
1826
1912
|
var y = e.clientY - rect.top;
|
|
1827
1913
|
var cell = absCoordianteToCell(x, y, rowSizes, columnSizes);
|
|
1914
|
+
var cellX = cell.x;
|
|
1915
|
+
var cellY = cell.y;
|
|
1916
|
+
var x1 = selection.x1,
|
|
1917
|
+
x2 = selection.x2,
|
|
1918
|
+
y1 = selection.y1,
|
|
1919
|
+
y2 = selection.y2;
|
|
1920
|
+
|
|
1921
|
+
if (x1 > x2) {
|
|
1922
|
+
var _ref = [x2, x1];
|
|
1923
|
+
x1 = _ref[0];
|
|
1924
|
+
x2 = _ref[1];
|
|
1925
|
+
}
|
|
1828
1926
|
|
|
1829
|
-
if (
|
|
1830
|
-
|
|
1927
|
+
if (y1 > y2) {
|
|
1928
|
+
var _ref2 = [y2, y1];
|
|
1929
|
+
y1 = _ref2[0];
|
|
1930
|
+
y2 = _ref2[1];
|
|
1931
|
+
}
|
|
1831
1932
|
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
});
|
|
1933
|
+
if (!(y > columnHeaderHeight && x > rowHeaderWidth)) {
|
|
1934
|
+
return;
|
|
1935
|
+
}
|
|
1836
1936
|
|
|
1837
|
-
|
|
1937
|
+
if (!(cellX >= x1 && cellX <= x2) || !(cellY >= y1 && cellY <= y2)) {
|
|
1938
|
+
changeSelection(cellX, cellY, cellX, cellY);
|
|
1838
1939
|
}
|
|
1940
|
+
|
|
1941
|
+
onMouseMove(e);
|
|
1942
|
+
|
|
1943
|
+
var ev = _extends({}, e, {
|
|
1944
|
+
cellX: cellX,
|
|
1945
|
+
cellY: cellY
|
|
1946
|
+
});
|
|
1947
|
+
|
|
1948
|
+
(_props$onRightClick = props.onRightClick) === null || _props$onRightClick === void 0 ? void 0 : _props$onRightClick.call(props, ev);
|
|
1839
1949
|
};
|
|
1840
1950
|
|
|
1841
1951
|
var editMode = editCell.x !== -1 && editCell.y !== -1;
|
|
@@ -1857,6 +1967,27 @@ function Sheet(props) {
|
|
|
1857
1967
|
editTextTextAlign = style.textAlign || defaultCellStyle.textAlign || 'left';
|
|
1858
1968
|
}
|
|
1859
1969
|
|
|
1970
|
+
var inputProps = {
|
|
1971
|
+
value: editValue,
|
|
1972
|
+
autoFocus: true,
|
|
1973
|
+
onKeyDown: onKeyDown,
|
|
1974
|
+
style: {
|
|
1975
|
+
position: 'absolute',
|
|
1976
|
+
top: editTextPosition.y,
|
|
1977
|
+
left: editTextPosition.x,
|
|
1978
|
+
width: editTextWidth,
|
|
1979
|
+
height: editTextHeight,
|
|
1980
|
+
outline: 'none',
|
|
1981
|
+
border: 'none',
|
|
1982
|
+
textAlign: editTextTextAlign,
|
|
1983
|
+
color: 'black',
|
|
1984
|
+
fontSize: defaultCellStyle.fontSize,
|
|
1985
|
+
fontFamily: 'sans-serif'
|
|
1986
|
+
}
|
|
1987
|
+
};
|
|
1988
|
+
var input = (_props$inputComponent = props.inputComponent) === null || _props$inputComponent === void 0 ? void 0 : _props$inputComponent.call(props, editCell.x, editCell.y, _extends({}, inputProps, {
|
|
1989
|
+
onChange: setEditValue
|
|
1990
|
+
}), commitEditingCell);
|
|
1860
1991
|
return React__default.createElement("div", {
|
|
1861
1992
|
style: {
|
|
1862
1993
|
position: 'relative',
|
|
@@ -1921,31 +2052,15 @@ function Sheet(props) {
|
|
|
1921
2052
|
tabIndex: 0,
|
|
1922
2053
|
onKeyDown: onGridKeyDown,
|
|
1923
2054
|
onKeyUp: onGridKeyUp
|
|
1924
|
-
}), editMode && React__default.createElement("input", {
|
|
2055
|
+
}), editMode && (input != null ? input : React__default.createElement("input", Object.assign({}, inputProps, {
|
|
1925
2056
|
type: "text",
|
|
1926
2057
|
onFocus: function onFocus(e) {
|
|
1927
2058
|
return e.target.select();
|
|
1928
2059
|
},
|
|
1929
|
-
autoFocus: true,
|
|
1930
|
-
onKeyDown: onKeyDown,
|
|
1931
|
-
value: editValue,
|
|
1932
2060
|
onChange: function onChange(e) {
|
|
1933
2061
|
return setEditValue(e.target.value);
|
|
1934
|
-
},
|
|
1935
|
-
style: {
|
|
1936
|
-
position: 'absolute',
|
|
1937
|
-
top: editTextPosition.y,
|
|
1938
|
-
left: editTextPosition.x,
|
|
1939
|
-
width: editTextWidth,
|
|
1940
|
-
height: editTextHeight,
|
|
1941
|
-
outline: 'none',
|
|
1942
|
-
border: 'none',
|
|
1943
|
-
textAlign: editTextTextAlign,
|
|
1944
|
-
color: 'black',
|
|
1945
|
-
fontSize: defaultCellStyle.fontSize,
|
|
1946
|
-
fontFamily: 'sans-serif'
|
|
1947
2062
|
}
|
|
1948
|
-
}));
|
|
2063
|
+
}))));
|
|
1949
2064
|
}
|
|
1950
2065
|
|
|
1951
2066
|
module.exports = Sheet;
|