@fileverse-dev/fortune-react 1.0.81 → 1.0.83
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.
|
@@ -15,7 +15,7 @@ var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
|
|
|
15
15
|
}
|
|
16
16
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
17
17
|
};
|
|
18
|
-
import { defaultContext, defaultSettings, initSheetIndex, handleGlobalKeyDown, getSheetIndex, handlePaste, filterPatch, patchToOp, inverseRowColOptions, ensureSheetIndex, insertRowCol, locale, calcSelectionInfo, groupValuesRefresh, insertDuneChart, getFlowdata, api } from "@fileverse-dev/fortune-core";
|
|
18
|
+
import { defaultContext, defaultSettings, initSheetIndex, handleGlobalKeyDown, getSheetIndex, handlePaste, filterPatch, patchToOp, inverseRowColOptions, ensureSheetIndex, insertRowCol, deleteRowCol, locale, calcSelectionInfo, groupValuesRefresh, insertDuneChart, getFlowdata, api } from "@fileverse-dev/fortune-core";
|
|
19
19
|
import React, { useMemo, useState, useCallback, useEffect, useRef, useImperativeHandle } from "react";
|
|
20
20
|
import "./index.css";
|
|
21
21
|
import produce, { applyPatches, enablePatches, produceWithPatches } from "immer";
|
|
@@ -478,7 +478,130 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
478
478
|
noHistory: true
|
|
479
479
|
});
|
|
480
480
|
}, [context.currentSheetId, context.luckysheetfile.length, originalData, mergedSettings.defaultRowHeight, mergedSettings.defaultColWidth, mergedSettings.column, mergedSettings.row, mergedSettings.defaultFontSize, mergedSettings.devicePixelRatio, mergedSettings.lang, mergedSettings.allowEdit, mergedSettings.hooks, mergedSettings.generateSheetId, setContextWithProduce, initSheetData, mergedSettings.rowHeaderWidth, mergedSettings.columnHeaderHeight, mergedSettings.addRows, mergedSettings.currency]);
|
|
481
|
+
var isMac = navigator.platform.toUpperCase().includes("MAC");
|
|
482
|
+
var waitingForRInsertRow = false;
|
|
483
|
+
var resetInsertRowTimer;
|
|
484
|
+
var waitingForDelRow = false;
|
|
485
|
+
var resetDeleteRowTimer;
|
|
481
486
|
var onKeyDown = useCallback(function (e) {
|
|
487
|
+
var _a, _b;
|
|
488
|
+
var _c = ref.current,
|
|
489
|
+
getSelection = _c.getSelection,
|
|
490
|
+
getSheet = _c.getSheet,
|
|
491
|
+
setSelection = _c.setSelection;
|
|
492
|
+
var isMacShortcutInsertRow = isMac && e.ctrlKey && e.altKey;
|
|
493
|
+
var isWindowsShortcutInsertRow = !isMac && e.altKey;
|
|
494
|
+
if ((isMacShortcutInsertRow || isWindowsShortcutInsertRow) && e.code === "KeyI") {
|
|
495
|
+
waitingForRInsertRow = true;
|
|
496
|
+
clearTimeout(resetInsertRowTimer);
|
|
497
|
+
resetInsertRowTimer = setTimeout(function () {
|
|
498
|
+
waitingForRInsertRow = false;
|
|
499
|
+
}, 3000);
|
|
500
|
+
e.preventDefault();
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
if (waitingForRInsertRow && (e.code === "KeyR" || e.code === "KeyC")) {
|
|
504
|
+
var direction = "rightbottom";
|
|
505
|
+
var position = void 0;
|
|
506
|
+
var insertRowColOp_1;
|
|
507
|
+
if (e.code === "KeyR") {
|
|
508
|
+
position = getSelection()[0].row[1];
|
|
509
|
+
insertRowColOp_1 = {
|
|
510
|
+
type: "row",
|
|
511
|
+
index: position,
|
|
512
|
+
count: 1,
|
|
513
|
+
direction: direction,
|
|
514
|
+
id: context.currentSheetId
|
|
515
|
+
};
|
|
516
|
+
} else {
|
|
517
|
+
position = getSelection()[0].column[1];
|
|
518
|
+
insertRowColOp_1 = {
|
|
519
|
+
type: "column",
|
|
520
|
+
index: position,
|
|
521
|
+
count: 1,
|
|
522
|
+
direction: direction,
|
|
523
|
+
id: context.currentSheetId
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
if (!position) return;
|
|
527
|
+
var range_1 = context.luckysheet_select_save;
|
|
528
|
+
setContextWithProduce(function (draftCtx) {
|
|
529
|
+
if (insertRowColOp_1) insertRowCol(draftCtx, insertRowColOp_1);
|
|
530
|
+
draftCtx.luckysheet_select_save = range_1;
|
|
531
|
+
}, {
|
|
532
|
+
insertRowColOp: insertRowColOp_1
|
|
533
|
+
});
|
|
534
|
+
waitingForRInsertRow = false;
|
|
535
|
+
clearTimeout(resetInsertRowTimer);
|
|
536
|
+
e.preventDefault();
|
|
537
|
+
}
|
|
538
|
+
var isDashKey = e.key === "-" || e.code === "Minus";
|
|
539
|
+
var isSecondShortcut = isMac ? e.metaKey && e.altKey && isDashKey : e.ctrlKey && e.altKey && isDashKey;
|
|
540
|
+
if (isSecondShortcut) {
|
|
541
|
+
waitingForDelRow = true;
|
|
542
|
+
clearTimeout(resetDeleteRowTimer);
|
|
543
|
+
resetDeleteRowTimer = setTimeout(function () {
|
|
544
|
+
waitingForDelRow = false;
|
|
545
|
+
console.log("Timeout: No second key (R or C) pressed in time.");
|
|
546
|
+
}, 3000);
|
|
547
|
+
e.preventDefault();
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
if (waitingForDelRow && (e.code === "KeyR" || e.code === "KeyC")) {
|
|
551
|
+
var st_index_1;
|
|
552
|
+
var ed_index_1;
|
|
553
|
+
if (e.code === "KeyR") {
|
|
554
|
+
_a = getSelection()[0].row, st_index_1 = _a[0], ed_index_1 = _a[1];
|
|
555
|
+
var range_2 = context.luckysheet_select_save;
|
|
556
|
+
setContextWithProduce(function (draftCtx) {
|
|
557
|
+
deleteRowCol(draftCtx, {
|
|
558
|
+
type: "row",
|
|
559
|
+
start: st_index_1,
|
|
560
|
+
end: ed_index_1,
|
|
561
|
+
id: context.currentSheetId
|
|
562
|
+
});
|
|
563
|
+
draftCtx.luckysheet_select_save = range_2;
|
|
564
|
+
});
|
|
565
|
+
} else {
|
|
566
|
+
_b = getSelection()[0].column, st_index_1 = _b[0], ed_index_1 = _b[1];
|
|
567
|
+
var range_3 = context.luckysheet_select_save;
|
|
568
|
+
setContextWithProduce(function (draftCtx) {
|
|
569
|
+
deleteRowCol(draftCtx, {
|
|
570
|
+
type: "column",
|
|
571
|
+
start: st_index_1,
|
|
572
|
+
end: ed_index_1,
|
|
573
|
+
id: context.currentSheetId
|
|
574
|
+
});
|
|
575
|
+
draftCtx.luckysheet_select_save = range_3;
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
waitingForDelRow = false;
|
|
579
|
+
clearTimeout(resetDeleteRowTimer);
|
|
580
|
+
e.preventDefault();
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
if (e.shiftKey && e.code === "Space") {
|
|
584
|
+
e.stopPropagation();
|
|
585
|
+
e.preventDefault();
|
|
586
|
+
var selection = getSelection();
|
|
587
|
+
var selectedCol = selection === null || selection === void 0 ? void 0 : selection[0].column;
|
|
588
|
+
var totalRow = getSheet().data.length;
|
|
589
|
+
setSelection([{
|
|
590
|
+
row: [0, totalRow - 1],
|
|
591
|
+
column: selectedCol
|
|
592
|
+
}]);
|
|
593
|
+
}
|
|
594
|
+
if (e.ctrlKey && e.code === "Space") {
|
|
595
|
+
e.stopPropagation();
|
|
596
|
+
e.preventDefault();
|
|
597
|
+
var selection = getSelection();
|
|
598
|
+
var selectedRow = selection === null || selection === void 0 ? void 0 : selection[0].row;
|
|
599
|
+
var totalCol = getSheet().data[0].length;
|
|
600
|
+
setSelection([{
|
|
601
|
+
row: selectedRow,
|
|
602
|
+
column: [0, totalCol - 1]
|
|
603
|
+
}]);
|
|
604
|
+
}
|
|
482
605
|
var nativeEvent = e.nativeEvent;
|
|
483
606
|
if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ") {
|
|
484
607
|
if (e.shiftKey) {
|
|
@@ -512,9 +635,9 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
512
635
|
var trList = ele.querySelectorAll("table tr");
|
|
513
636
|
var maxRow = trList.length + context.luckysheet_select_save[0].row[0];
|
|
514
637
|
var rowToBeAdded = maxRow - context.luckysheetfile[getSheetIndex(context, context.currentSheetId)].data.length;
|
|
515
|
-
var
|
|
638
|
+
var range_4 = context.luckysheet_select_save;
|
|
516
639
|
if (rowToBeAdded > 0) {
|
|
517
|
-
var
|
|
640
|
+
var insertRowColOp_2 = {
|
|
518
641
|
type: "row",
|
|
519
642
|
index: context.luckysheetfile[getSheetIndex(context, context.currentSheetId)].data.length - 1,
|
|
520
643
|
count: rowToBeAdded,
|
|
@@ -522,10 +645,10 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
|
522
645
|
id: context.currentSheetId
|
|
523
646
|
};
|
|
524
647
|
setContextWithProduce(function (draftCtx) {
|
|
525
|
-
insertRowCol(draftCtx,
|
|
526
|
-
draftCtx.luckysheet_select_save =
|
|
648
|
+
insertRowCol(draftCtx, insertRowColOp_2);
|
|
649
|
+
draftCtx.luckysheet_select_save = range_4;
|
|
527
650
|
}, {
|
|
528
|
-
insertRowColOp:
|
|
651
|
+
insertRowColOp: insertRowColOp_2
|
|
529
652
|
});
|
|
530
653
|
}
|
|
531
654
|
setContextWithProduce(function (draftCtx) {
|
|
@@ -487,7 +487,130 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
|
|
|
487
487
|
noHistory: true
|
|
488
488
|
});
|
|
489
489
|
}, [context.currentSheetId, context.luckysheetfile.length, originalData, mergedSettings.defaultRowHeight, mergedSettings.defaultColWidth, mergedSettings.column, mergedSettings.row, mergedSettings.defaultFontSize, mergedSettings.devicePixelRatio, mergedSettings.lang, mergedSettings.allowEdit, mergedSettings.hooks, mergedSettings.generateSheetId, setContextWithProduce, initSheetData, mergedSettings.rowHeaderWidth, mergedSettings.columnHeaderHeight, mergedSettings.addRows, mergedSettings.currency]);
|
|
490
|
+
var isMac = navigator.platform.toUpperCase().includes("MAC");
|
|
491
|
+
var waitingForRInsertRow = false;
|
|
492
|
+
var resetInsertRowTimer;
|
|
493
|
+
var waitingForDelRow = false;
|
|
494
|
+
var resetDeleteRowTimer;
|
|
490
495
|
var onKeyDown = (0, _react.useCallback)(function (e) {
|
|
496
|
+
var _a, _b;
|
|
497
|
+
var _c = ref.current,
|
|
498
|
+
getSelection = _c.getSelection,
|
|
499
|
+
getSheet = _c.getSheet,
|
|
500
|
+
setSelection = _c.setSelection;
|
|
501
|
+
var isMacShortcutInsertRow = isMac && e.ctrlKey && e.altKey;
|
|
502
|
+
var isWindowsShortcutInsertRow = !isMac && e.altKey;
|
|
503
|
+
if ((isMacShortcutInsertRow || isWindowsShortcutInsertRow) && e.code === "KeyI") {
|
|
504
|
+
waitingForRInsertRow = true;
|
|
505
|
+
clearTimeout(resetInsertRowTimer);
|
|
506
|
+
resetInsertRowTimer = setTimeout(function () {
|
|
507
|
+
waitingForRInsertRow = false;
|
|
508
|
+
}, 3000);
|
|
509
|
+
e.preventDefault();
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
if (waitingForRInsertRow && (e.code === "KeyR" || e.code === "KeyC")) {
|
|
513
|
+
var direction = "rightbottom";
|
|
514
|
+
var position = void 0;
|
|
515
|
+
var insertRowColOp_1;
|
|
516
|
+
if (e.code === "KeyR") {
|
|
517
|
+
position = getSelection()[0].row[1];
|
|
518
|
+
insertRowColOp_1 = {
|
|
519
|
+
type: "row",
|
|
520
|
+
index: position,
|
|
521
|
+
count: 1,
|
|
522
|
+
direction: direction,
|
|
523
|
+
id: context.currentSheetId
|
|
524
|
+
};
|
|
525
|
+
} else {
|
|
526
|
+
position = getSelection()[0].column[1];
|
|
527
|
+
insertRowColOp_1 = {
|
|
528
|
+
type: "column",
|
|
529
|
+
index: position,
|
|
530
|
+
count: 1,
|
|
531
|
+
direction: direction,
|
|
532
|
+
id: context.currentSheetId
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
if (!position) return;
|
|
536
|
+
var range_1 = context.luckysheet_select_save;
|
|
537
|
+
setContextWithProduce(function (draftCtx) {
|
|
538
|
+
if (insertRowColOp_1) (0, _fortuneCore.insertRowCol)(draftCtx, insertRowColOp_1);
|
|
539
|
+
draftCtx.luckysheet_select_save = range_1;
|
|
540
|
+
}, {
|
|
541
|
+
insertRowColOp: insertRowColOp_1
|
|
542
|
+
});
|
|
543
|
+
waitingForRInsertRow = false;
|
|
544
|
+
clearTimeout(resetInsertRowTimer);
|
|
545
|
+
e.preventDefault();
|
|
546
|
+
}
|
|
547
|
+
var isDashKey = e.key === "-" || e.code === "Minus";
|
|
548
|
+
var isSecondShortcut = isMac ? e.metaKey && e.altKey && isDashKey : e.ctrlKey && e.altKey && isDashKey;
|
|
549
|
+
if (isSecondShortcut) {
|
|
550
|
+
waitingForDelRow = true;
|
|
551
|
+
clearTimeout(resetDeleteRowTimer);
|
|
552
|
+
resetDeleteRowTimer = setTimeout(function () {
|
|
553
|
+
waitingForDelRow = false;
|
|
554
|
+
console.log("Timeout: No second key (R or C) pressed in time.");
|
|
555
|
+
}, 3000);
|
|
556
|
+
e.preventDefault();
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
if (waitingForDelRow && (e.code === "KeyR" || e.code === "KeyC")) {
|
|
560
|
+
var st_index_1;
|
|
561
|
+
var ed_index_1;
|
|
562
|
+
if (e.code === "KeyR") {
|
|
563
|
+
_a = getSelection()[0].row, st_index_1 = _a[0], ed_index_1 = _a[1];
|
|
564
|
+
var range_2 = context.luckysheet_select_save;
|
|
565
|
+
setContextWithProduce(function (draftCtx) {
|
|
566
|
+
(0, _fortuneCore.deleteRowCol)(draftCtx, {
|
|
567
|
+
type: "row",
|
|
568
|
+
start: st_index_1,
|
|
569
|
+
end: ed_index_1,
|
|
570
|
+
id: context.currentSheetId
|
|
571
|
+
});
|
|
572
|
+
draftCtx.luckysheet_select_save = range_2;
|
|
573
|
+
});
|
|
574
|
+
} else {
|
|
575
|
+
_b = getSelection()[0].column, st_index_1 = _b[0], ed_index_1 = _b[1];
|
|
576
|
+
var range_3 = context.luckysheet_select_save;
|
|
577
|
+
setContextWithProduce(function (draftCtx) {
|
|
578
|
+
(0, _fortuneCore.deleteRowCol)(draftCtx, {
|
|
579
|
+
type: "column",
|
|
580
|
+
start: st_index_1,
|
|
581
|
+
end: ed_index_1,
|
|
582
|
+
id: context.currentSheetId
|
|
583
|
+
});
|
|
584
|
+
draftCtx.luckysheet_select_save = range_3;
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
waitingForDelRow = false;
|
|
588
|
+
clearTimeout(resetDeleteRowTimer);
|
|
589
|
+
e.preventDefault();
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
if (e.shiftKey && e.code === "Space") {
|
|
593
|
+
e.stopPropagation();
|
|
594
|
+
e.preventDefault();
|
|
595
|
+
var selection = getSelection();
|
|
596
|
+
var selectedCol = selection === null || selection === void 0 ? void 0 : selection[0].column;
|
|
597
|
+
var totalRow = getSheet().data.length;
|
|
598
|
+
setSelection([{
|
|
599
|
+
row: [0, totalRow - 1],
|
|
600
|
+
column: selectedCol
|
|
601
|
+
}]);
|
|
602
|
+
}
|
|
603
|
+
if (e.ctrlKey && e.code === "Space") {
|
|
604
|
+
e.stopPropagation();
|
|
605
|
+
e.preventDefault();
|
|
606
|
+
var selection = getSelection();
|
|
607
|
+
var selectedRow = selection === null || selection === void 0 ? void 0 : selection[0].row;
|
|
608
|
+
var totalCol = getSheet().data[0].length;
|
|
609
|
+
setSelection([{
|
|
610
|
+
row: selectedRow,
|
|
611
|
+
column: [0, totalCol - 1]
|
|
612
|
+
}]);
|
|
613
|
+
}
|
|
491
614
|
var nativeEvent = e.nativeEvent;
|
|
492
615
|
if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ") {
|
|
493
616
|
if (e.shiftKey) {
|
|
@@ -521,9 +644,9 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
|
|
|
521
644
|
var trList = ele.querySelectorAll("table tr");
|
|
522
645
|
var maxRow = trList.length + context.luckysheet_select_save[0].row[0];
|
|
523
646
|
var rowToBeAdded = maxRow - context.luckysheetfile[(0, _fortuneCore.getSheetIndex)(context, context.currentSheetId)].data.length;
|
|
524
|
-
var
|
|
647
|
+
var range_4 = context.luckysheet_select_save;
|
|
525
648
|
if (rowToBeAdded > 0) {
|
|
526
|
-
var
|
|
649
|
+
var insertRowColOp_2 = {
|
|
527
650
|
type: "row",
|
|
528
651
|
index: context.luckysheetfile[(0, _fortuneCore.getSheetIndex)(context, context.currentSheetId)].data.length - 1,
|
|
529
652
|
count: rowToBeAdded,
|
|
@@ -531,10 +654,10 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
|
|
|
531
654
|
id: context.currentSheetId
|
|
532
655
|
};
|
|
533
656
|
setContextWithProduce(function (draftCtx) {
|
|
534
|
-
(0, _fortuneCore.insertRowCol)(draftCtx,
|
|
535
|
-
draftCtx.luckysheet_select_save =
|
|
657
|
+
(0, _fortuneCore.insertRowCol)(draftCtx, insertRowColOp_2);
|
|
658
|
+
draftCtx.luckysheet_select_save = range_4;
|
|
536
659
|
}, {
|
|
537
|
-
insertRowColOp:
|
|
660
|
+
insertRowColOp: insertRowColOp_2
|
|
538
661
|
});
|
|
539
662
|
}
|
|
540
663
|
setContextWithProduce(function (draftCtx) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fileverse-dev/fortune-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.83",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"tsc": "tsc"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@fileverse-dev/fortune-core": "1.0.
|
|
19
|
+
"@fileverse-dev/fortune-core": "1.0.83",
|
|
20
20
|
"@fileverse/ui": "^4.1.7-patch-21",
|
|
21
21
|
"@tippyjs/react": "^4.2.6",
|
|
22
22
|
"@types/regenerator-runtime": "^0.13.6",
|