@fileverse-dev/fortune-react 1.0.81 → 1.0.82

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,129 @@ 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
+ 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, ed_index_1;
552
+ if (e.code === 'KeyR') {
553
+ _a = getSelection()[0].row, st_index_1 = _a[0], ed_index_1 = _a[1];
554
+ var range_2 = context.luckysheet_select_save;
555
+ setContextWithProduce(function (draftCtx) {
556
+ deleteRowCol(draftCtx, {
557
+ type: "row",
558
+ start: st_index_1,
559
+ end: ed_index_1,
560
+ id: context.currentSheetId
561
+ });
562
+ draftCtx.luckysheet_select_save = range_2;
563
+ });
564
+ } else {
565
+ _b = getSelection()[0].column, st_index_1 = _b[0], ed_index_1 = _b[1];
566
+ var range_3 = context.luckysheet_select_save;
567
+ setContextWithProduce(function (draftCtx) {
568
+ deleteRowCol(draftCtx, {
569
+ type: "column",
570
+ start: st_index_1,
571
+ end: ed_index_1,
572
+ id: context.currentSheetId
573
+ });
574
+ draftCtx.luckysheet_select_save = range_3;
575
+ });
576
+ }
577
+ waitingForDelRow = false;
578
+ clearTimeout(resetDeleteRowTimer);
579
+ e.preventDefault();
580
+ return;
581
+ }
582
+ if (e.shiftKey && e.code === 'Space') {
583
+ e.stopPropagation();
584
+ e.preventDefault();
585
+ var selection = getSelection();
586
+ var selectedCol = selection === null || selection === void 0 ? void 0 : selection[0].column;
587
+ var totalRow = getSheet().data.length;
588
+ setSelection([{
589
+ row: [0, totalRow - 1],
590
+ column: selectedCol
591
+ }]);
592
+ }
593
+ if (e.ctrlKey && e.code === 'Space') {
594
+ e.stopPropagation();
595
+ e.preventDefault();
596
+ var selection = getSelection();
597
+ var selectedRow = selection === null || selection === void 0 ? void 0 : selection[0].row;
598
+ var totalCol = getSheet().data[0].length;
599
+ setSelection([{
600
+ row: selectedRow,
601
+ column: [0, totalCol - 1]
602
+ }]);
603
+ }
482
604
  var nativeEvent = e.nativeEvent;
483
605
  if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ") {
484
606
  if (e.shiftKey) {
@@ -512,9 +634,9 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
512
634
  var trList = ele.querySelectorAll("table tr");
513
635
  var maxRow = trList.length + context.luckysheet_select_save[0].row[0];
514
636
  var rowToBeAdded = maxRow - context.luckysheetfile[getSheetIndex(context, context.currentSheetId)].data.length;
515
- var range_1 = context.luckysheet_select_save;
637
+ var range_4 = context.luckysheet_select_save;
516
638
  if (rowToBeAdded > 0) {
517
- var insertRowColOp_1 = {
639
+ var insertRowColOp_2 = {
518
640
  type: "row",
519
641
  index: context.luckysheetfile[getSheetIndex(context, context.currentSheetId)].data.length - 1,
520
642
  count: rowToBeAdded,
@@ -522,10 +644,10 @@ var Workbook = /*#__PURE__*/React.forwardRef(function (_a, ref) {
522
644
  id: context.currentSheetId
523
645
  };
524
646
  setContextWithProduce(function (draftCtx) {
525
- insertRowCol(draftCtx, insertRowColOp_1);
526
- draftCtx.luckysheet_select_save = range_1;
647
+ insertRowCol(draftCtx, insertRowColOp_2);
648
+ draftCtx.luckysheet_select_save = range_4;
527
649
  }, {
528
- insertRowColOp: insertRowColOp_1
650
+ insertRowColOp: insertRowColOp_2
529
651
  });
530
652
  }
531
653
  setContextWithProduce(function (draftCtx) {
@@ -487,7 +487,129 @@ 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
+ 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, ed_index_1;
561
+ if (e.code === 'KeyR') {
562
+ _a = getSelection()[0].row, st_index_1 = _a[0], ed_index_1 = _a[1];
563
+ var range_2 = context.luckysheet_select_save;
564
+ setContextWithProduce(function (draftCtx) {
565
+ (0, _fortuneCore.deleteRowCol)(draftCtx, {
566
+ type: "row",
567
+ start: st_index_1,
568
+ end: ed_index_1,
569
+ id: context.currentSheetId
570
+ });
571
+ draftCtx.luckysheet_select_save = range_2;
572
+ });
573
+ } else {
574
+ _b = getSelection()[0].column, st_index_1 = _b[0], ed_index_1 = _b[1];
575
+ var range_3 = context.luckysheet_select_save;
576
+ setContextWithProduce(function (draftCtx) {
577
+ (0, _fortuneCore.deleteRowCol)(draftCtx, {
578
+ type: "column",
579
+ start: st_index_1,
580
+ end: ed_index_1,
581
+ id: context.currentSheetId
582
+ });
583
+ draftCtx.luckysheet_select_save = range_3;
584
+ });
585
+ }
586
+ waitingForDelRow = false;
587
+ clearTimeout(resetDeleteRowTimer);
588
+ e.preventDefault();
589
+ return;
590
+ }
591
+ if (e.shiftKey && e.code === 'Space') {
592
+ e.stopPropagation();
593
+ e.preventDefault();
594
+ var selection = getSelection();
595
+ var selectedCol = selection === null || selection === void 0 ? void 0 : selection[0].column;
596
+ var totalRow = getSheet().data.length;
597
+ setSelection([{
598
+ row: [0, totalRow - 1],
599
+ column: selectedCol
600
+ }]);
601
+ }
602
+ if (e.ctrlKey && e.code === 'Space') {
603
+ e.stopPropagation();
604
+ e.preventDefault();
605
+ var selection = getSelection();
606
+ var selectedRow = selection === null || selection === void 0 ? void 0 : selection[0].row;
607
+ var totalCol = getSheet().data[0].length;
608
+ setSelection([{
609
+ row: selectedRow,
610
+ column: [0, totalCol - 1]
611
+ }]);
612
+ }
491
613
  var nativeEvent = e.nativeEvent;
492
614
  if ((e.ctrlKey || e.metaKey) && e.code === "KeyZ") {
493
615
  if (e.shiftKey) {
@@ -521,9 +643,9 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
521
643
  var trList = ele.querySelectorAll("table tr");
522
644
  var maxRow = trList.length + context.luckysheet_select_save[0].row[0];
523
645
  var rowToBeAdded = maxRow - context.luckysheetfile[(0, _fortuneCore.getSheetIndex)(context, context.currentSheetId)].data.length;
524
- var range_1 = context.luckysheet_select_save;
646
+ var range_4 = context.luckysheet_select_save;
525
647
  if (rowToBeAdded > 0) {
526
- var insertRowColOp_1 = {
648
+ var insertRowColOp_2 = {
527
649
  type: "row",
528
650
  index: context.luckysheetfile[(0, _fortuneCore.getSheetIndex)(context, context.currentSheetId)].data.length - 1,
529
651
  count: rowToBeAdded,
@@ -531,10 +653,10 @@ var Workbook = /*#__PURE__*/_react.default.forwardRef(function (_a, ref) {
531
653
  id: context.currentSheetId
532
654
  };
533
655
  setContextWithProduce(function (draftCtx) {
534
- (0, _fortuneCore.insertRowCol)(draftCtx, insertRowColOp_1);
535
- draftCtx.luckysheet_select_save = range_1;
656
+ (0, _fortuneCore.insertRowCol)(draftCtx, insertRowColOp_2);
657
+ draftCtx.luckysheet_select_save = range_4;
536
658
  }, {
537
- insertRowColOp: insertRowColOp_1
659
+ insertRowColOp: insertRowColOp_2
538
660
  });
539
661
  }
540
662
  setContextWithProduce(function (draftCtx) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fileverse-dev/fortune-react",
3
- "version": "1.0.81",
3
+ "version": "1.0.82",
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.81",
19
+ "@fileverse-dev/fortune-core": "1.0.82",
20
20
  "@fileverse/ui": "^4.1.7-patch-21",
21
21
  "@tippyjs/react": "^4.2.6",
22
22
  "@types/regenerator-runtime": "^0.13.6",