@gridsheet/react-core 0.12.13 → 0.13.0-alpha.0

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.
Files changed (67) hide show
  1. package/README.md +4 -0
  2. package/dist/components/Cell.d.ts.map +1 -1
  3. package/dist/components/Cell.js +3 -3
  4. package/dist/components/Cell.js.map +1 -1
  5. package/dist/components/ContextMenu.d.ts.map +1 -1
  6. package/dist/components/ContextMenu.js +74 -29
  7. package/dist/components/ContextMenu.js.map +1 -1
  8. package/dist/components/Editor.d.ts.map +1 -1
  9. package/dist/components/Editor.js +32 -0
  10. package/dist/components/Editor.js.map +1 -1
  11. package/dist/components/GridSheet.js +2 -2
  12. package/dist/components/GridSheet.js.map +1 -1
  13. package/dist/components/HorizontalHeaderCell.d.ts +7 -0
  14. package/dist/components/HorizontalHeaderCell.d.ts.map +1 -0
  15. package/dist/components/{HeaderTopCell.js → HorizontalHeaderCell.js} +30 -6
  16. package/dist/components/HorizontalHeaderCell.js.map +1 -0
  17. package/dist/components/Resizer.d.ts.map +1 -1
  18. package/dist/components/Resizer.js +4 -3
  19. package/dist/components/Resizer.js.map +1 -1
  20. package/dist/components/Tabular.js +4 -4
  21. package/dist/components/Tabular.js.map +1 -1
  22. package/dist/components/VerticalHeaderCell.d.ts +7 -0
  23. package/dist/components/VerticalHeaderCell.d.ts.map +1 -0
  24. package/dist/components/{HeaderLeftCell.js → VerticalHeaderCell.js} +30 -6
  25. package/dist/components/VerticalHeaderCell.js.map +1 -0
  26. package/dist/index.d.ts +5 -3
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js.map +1 -1
  29. package/dist/lib/autofill.d.ts +1 -1
  30. package/dist/lib/autofill.d.ts.map +1 -1
  31. package/dist/lib/autofill.js +5 -3
  32. package/dist/lib/autofill.js.map +1 -1
  33. package/dist/lib/clipboard.d.ts +1 -1
  34. package/dist/lib/clipboard.d.ts.map +1 -1
  35. package/dist/lib/converters.d.ts +1 -1
  36. package/dist/lib/converters.d.ts.map +1 -1
  37. package/dist/lib/prevention.d.ts +24 -0
  38. package/dist/lib/prevention.d.ts.map +1 -0
  39. package/dist/lib/prevention.js +77 -0
  40. package/dist/lib/prevention.js.map +1 -0
  41. package/dist/lib/structs.d.ts +3 -2
  42. package/dist/lib/structs.d.ts.map +1 -1
  43. package/dist/lib/structs.js +43 -6
  44. package/dist/lib/structs.js.map +1 -1
  45. package/dist/lib/table.d.ts +24 -12
  46. package/dist/lib/table.d.ts.map +1 -1
  47. package/dist/lib/table.js +203 -103
  48. package/dist/lib/table.js.map +1 -1
  49. package/dist/lib/virtualization.d.ts +1 -1
  50. package/dist/lib/virtualization.d.ts.map +1 -1
  51. package/dist/store/actions.d.ts.map +1 -1
  52. package/dist/store/actions.js +46 -5
  53. package/dist/store/actions.js.map +1 -1
  54. package/dist/store/helpers.js +2 -2
  55. package/dist/styles/minified.d.ts +2 -2
  56. package/dist/styles/minified.d.ts.map +1 -1
  57. package/dist/styles/minified.js +2 -2
  58. package/dist/styles/minified.js.map +1 -1
  59. package/dist/types.d.ts +16 -15
  60. package/dist/types.d.ts.map +1 -1
  61. package/package.json +1 -1
  62. package/dist/components/HeaderLeftCell.d.ts +0 -7
  63. package/dist/components/HeaderLeftCell.d.ts.map +0 -1
  64. package/dist/components/HeaderLeftCell.js.map +0 -1
  65. package/dist/components/HeaderTopCell.d.ts +0 -7
  66. package/dist/components/HeaderTopCell.d.ts.map +0 -1
  67. package/dist/components/HeaderTopCell.js.map +0 -1
package/dist/lib/table.js CHANGED
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.Table = void 0;
4
27
  const core_1 = require("../parsers/core");
@@ -10,6 +33,7 @@ const evaluator_1 = require("../formula/evaluator");
10
33
  const solver_1 = require("../formula/solver");
11
34
  const constants_1 = require("../constants");
12
35
  const helpers_1 = require("../store/helpers");
36
+ const prevention = __importStar(require("./prevention"));
13
37
  const cellFilter = (cell) => true;
14
38
  class Table {
15
39
  constructor({ numRows = 0, numCols = 0, cells = {}, parsers = {}, renderers = {}, labelers = {}, useBigInt = false, historyLimit: historyLimit, minNumRows = 1, maxNumRows = -1, minNumCols = 1, maxNumCols = -1, headerWidth = -1, headerHeight = -1, functions = mapping_1.functions, }) {
@@ -38,7 +62,6 @@ class Table {
38
62
  this.headerHeight = headerHeight || 0;
39
63
  this.headerWidth = headerWidth || 0;
40
64
  this.functions = functions;
41
- const common = cells === null || cells === void 0 ? void 0 : cells['default'];
42
65
  // make idMatrix beforehand
43
66
  for (let y = 0; y < numRows + 1; y++) {
44
67
  const ids = [];
@@ -50,6 +73,15 @@ class Table {
50
73
  this.addressesById[id] = address;
51
74
  }
52
75
  }
76
+ Object.keys(cells).forEach((address) => {
77
+ const range = (0, structs_1.expandRange)(address);
78
+ const data = cells[address];
79
+ range.forEach((address) => {
80
+ const origin = cells[address];
81
+ cells[address] = Object.assign(Object.assign(Object.assign({}, origin), data), { style: Object.assign(Object.assign({}, origin === null || origin === void 0 ? void 0 : origin.style), data === null || data === void 0 ? void 0 : data.style), prevention: ((origin === null || origin === void 0 ? void 0 : origin.prevention) || 0) | ((data === null || data === void 0 ? void 0 : data.prevention) || 0) });
82
+ });
83
+ });
84
+ const common = cells === null || cells === void 0 ? void 0 : cells['default'];
53
85
  for (let y = 0; y < numRows + 1; y++) {
54
86
  const rowId = (0, converters_1.y2r)(y);
55
87
  const rowDefault = cells === null || cells === void 0 ? void 0 : cells[rowId];
@@ -59,7 +91,7 @@ class Table {
59
91
  const colId = (0, converters_1.x2c)(x);
60
92
  const colDefault = cells === null || cells === void 0 ? void 0 : cells[colId];
61
93
  const cell = cells === null || cells === void 0 ? void 0 : cells[address];
62
- const stacked = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, common), rowDefault), colDefault), cell), { style: Object.assign(Object.assign(Object.assign(Object.assign({}, common === null || common === void 0 ? void 0 : common.style), rowDefault === null || rowDefault === void 0 ? void 0 : rowDefault.style), colDefault === null || colDefault === void 0 ? void 0 : colDefault.style), cell === null || cell === void 0 ? void 0 : cell.style) });
94
+ const stacked = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, common), rowDefault), colDefault), cell), { style: Object.assign(Object.assign(Object.assign(Object.assign({}, common === null || common === void 0 ? void 0 : common.style), rowDefault === null || rowDefault === void 0 ? void 0 : rowDefault.style), colDefault === null || colDefault === void 0 ? void 0 : colDefault.style), cell === null || cell === void 0 ? void 0 : cell.style), prevention: ((common === null || common === void 0 ? void 0 : common.prevention) || 0) | ((rowDefault === null || rowDefault === void 0 ? void 0 : rowDefault.prevention) || 0) | ((colDefault === null || colDefault === void 0 ? void 0 : colDefault.prevention) || 0) | ((cell === null || cell === void 0 ? void 0 : cell.prevention) || 0) });
63
95
  stacked.value = (0, evaluator_1.convertFormulaAbsolute)({
64
96
  value: stacked === null || stacked === void 0 ? void 0 : stacked.value,
65
97
  table: this,
@@ -407,9 +439,9 @@ class Table {
407
439
  }
408
440
  }
409
441
  cleanObsolete(history) {
410
- if (history.operation === "REMOVE_ROWS" ||
411
- history.operation === "REMOVE_COLS") {
412
- history.idMatrix.forEach((ids) => {
442
+ if (history.operation === "DELETE_ROWS" ||
443
+ history.operation === "DELETE_COLS") {
444
+ history.deleted.forEach((ids) => {
413
445
  ids.forEach((id) => {
414
446
  delete this.data[id];
415
447
  });
@@ -419,7 +451,9 @@ class Table {
419
451
  Object.keys(history.lostRows).forEach((address) => {
420
452
  const idMatrix = history.lostRows[address];
421
453
  idMatrix.map((ids) => ids.forEach((id) => {
422
- delete this.data[id];
454
+ if (id != null) {
455
+ delete this.data[id];
456
+ }
423
457
  }));
424
458
  });
425
459
  }
@@ -454,9 +488,10 @@ class Table {
454
488
  matrix.push(ids);
455
489
  for (let x = left; x <= right; x++) {
456
490
  const id = (_a = this.idMatrix[y]) === null || _a === void 0 ? void 0 : _a[x];
457
- if (id) {
458
- ids.push(id);
491
+ if (id == null) {
492
+ continue;
459
493
  }
494
+ ids.push(id);
460
495
  }
461
496
  }
462
497
  return matrix;
@@ -499,33 +534,45 @@ class Table {
499
534
  }
500
535
  return newCell;
501
536
  }
502
- move({ src, dst, reflection = {}, }) {
503
- const changedAt = new Date();
537
+ move({ src, dst, historicize = true, operator = "SYSTEM", reflection = {}, }) {
538
+ const matrixNew = this.getNewIdMatrix(src);
504
539
  const matrixFrom = this.getIdMatrixFromArea(src);
505
540
  const matrixTo = this.getIdMatrixFromArea(dst);
506
- const matrixNew = this.getNewIdMatrix(src);
507
- (0, structs_1.putMatrix)(this.idMatrix, matrixNew, src);
508
- matrixFrom.forEach((ids) => {
509
- ids
510
- .map(this.getById.bind(this))
511
- .filter((c) => c)
512
- .forEach((cell) => this.setChangedAt(cell, changedAt));
541
+ (0, structs_1.putMatrix)(this.idMatrix, matrixNew, src, (_, id) => {
542
+ const cell = this.data[id];
543
+ if (operator === 'USER' && prevention.isPrevented(cell === null || cell === void 0 ? void 0 : cell.prevention, prevention.MoveFrom)) {
544
+ return false;
545
+ }
546
+ return true;
513
547
  });
514
- const lostRows = (0, structs_1.putMatrix)(this.idMatrix, matrixFrom, dst);
515
- this.pushHistory({
516
- applyed: true,
517
- operation: "MOVE",
518
- reflection,
519
- matrixFrom,
520
- matrixTo,
521
- matrixNew,
522
- pointFrom: { y: src.top, x: src.left },
523
- pointTo: { y: dst.top, x: dst.left },
524
- lostRows,
548
+ const lostRows = (0, structs_1.putMatrix)(this.idMatrix, matrixFrom, dst, (srcId, dstId) => {
549
+ const srcCell = this.data[srcId];
550
+ const dstCell = this.data[dstId];
551
+ if (operator === 'USER' && (prevention.isPrevented(srcCell === null || srcCell === void 0 ? void 0 : srcCell.prevention, prevention.MoveFrom) ||
552
+ prevention.isPrevented(dstCell === null || dstCell === void 0 ? void 0 : dstCell.prevention, prevention.MoveTo))) {
553
+ return false;
554
+ }
555
+ if (srcCell != null) {
556
+ this.setChangedAt(srcCell, new Date());
557
+ }
558
+ return true;
525
559
  });
560
+ if (historicize) {
561
+ this.pushHistory({
562
+ applyed: true,
563
+ operation: "MOVE",
564
+ reflection,
565
+ src,
566
+ dst,
567
+ matrixFrom,
568
+ matrixTo,
569
+ matrixNew,
570
+ lostRows,
571
+ });
572
+ }
526
573
  return this.shallowCopy({ copyCache: false });
527
574
  }
528
- copy({ src, dst, reflection = {}, }) {
575
+ copy({ src, dst, operator = "SYSTEM", reflection = {}, }) {
529
576
  const { height: maxHeight, width: maxWidth } = (0, structs_1.areaShape)(Object.assign(Object.assign({}, src), { base: 1 }));
530
577
  const { top: topFrom, left: leftFrom } = src;
531
578
  const { top: topTo, left: leftTo, bottom: bottomTo, right: rightTo } = dst;
@@ -545,10 +592,10 @@ class Table {
545
592
  const fromX = leftFrom + (j % maxWidth);
546
593
  const slideY = toY - fromY;
547
594
  const slideX = toX - fromX;
548
- const cell = Object.assign({}, this.getByPoint({
595
+ const cell = Object.assign(Object.assign({}, this.getByPoint({
549
596
  y: topFrom + (i % maxHeight),
550
597
  x: leftFrom + (j % maxWidth),
551
- }));
598
+ })), { prevention: 0 });
552
599
  const value = (0, evaluator_1.convertFormulaAbsolute)({
553
600
  value: cell === null || cell === void 0 ? void 0 : cell.value,
554
601
  table: this,
@@ -559,16 +606,21 @@ class Table {
559
606
  diff[(0, converters_1.p2a)({ y: toY, x: toX })] = Object.assign(Object.assign({}, cell), { style: Object.assign({}, cell === null || cell === void 0 ? void 0 : cell.style), value });
560
607
  }
561
608
  }
562
- return this.update({ diff, partial: false, reflection });
609
+ return this.update({
610
+ diff,
611
+ partial: false,
612
+ operator,
613
+ reflection,
614
+ });
563
615
  }
564
- _update({ diff, partial = true, updateChangedAt = true, }) {
616
+ _update({ diff, partial = true, updateChangedAt = true, ignoreFields = ['labeler', 'prevention'], operator = 'SYSTEM', }) {
565
617
  const diffBefore = {};
566
618
  const diffAfter = {};
567
619
  const changedAt = new Date();
568
620
  Object.keys(diff).forEach((address) => {
569
621
  const cell = Object.assign({}, diff[address]);
570
- if (updateChangedAt) {
571
- this.setChangedAt(cell, changedAt);
622
+ if (operator === 'USER' && prevention.isPrevented(cell === null || cell === void 0 ? void 0 : cell.prevention, prevention.Update)) {
623
+ return;
572
624
  }
573
625
  cell.value = (0, evaluator_1.convertFormulaAbsolute)({
574
626
  value: cell.value,
@@ -576,11 +628,36 @@ class Table {
576
628
  });
577
629
  const point = (0, converters_1.a2p)(address);
578
630
  const id = this.getId(point);
631
+ const current = this.data[id];
632
+ ignoreFields.forEach((key) => {
633
+ cell[key] = current === null || current === void 0 ? void 0 : current[key];
634
+ });
635
+ if (operator === 'USER' && prevention.isPrevented(current === null || current === void 0 ? void 0 : current.prevention, prevention.Write)) {
636
+ cell.value = current === null || current === void 0 ? void 0 : current.value;
637
+ }
638
+ if (operator === 'USER' && prevention.isPrevented(current === null || current === void 0 ? void 0 : current.prevention, prevention.Style)) {
639
+ cell.style = current === null || current === void 0 ? void 0 : current.style;
640
+ cell.justifyContent = current === null || current === void 0 ? void 0 : current.justifyContent;
641
+ cell.alignItems = current === null || current === void 0 ? void 0 : current.alignItems;
642
+ }
643
+ if (operator === 'USER' && prevention.isPrevented(current === null || current === void 0 ? void 0 : current.prevention, prevention.Resize)) {
644
+ cell.width = current === null || current === void 0 ? void 0 : current.width;
645
+ cell.height = current === null || current === void 0 ? void 0 : current.height;
646
+ }
647
+ if (operator === 'USER' && prevention.isPrevented(current === null || current === void 0 ? void 0 : current.prevention, prevention.SetRenderer)) {
648
+ cell.renderer = current === null || current === void 0 ? void 0 : current.renderer;
649
+ }
650
+ if (operator === 'USER' && prevention.isPrevented(current === null || current === void 0 ? void 0 : current.prevention, prevention.SetParser)) {
651
+ cell.parser = current === null || current === void 0 ? void 0 : current.parser;
652
+ }
653
+ if (updateChangedAt) {
654
+ this.setChangedAt(cell, changedAt);
655
+ }
579
656
  // must not partial
580
657
  diffBefore[id] = this.getByPoint(point);
581
658
  diffAfter[id] = cell;
582
659
  if (partial) {
583
- this.data[id] = Object.assign(Object.assign({}, this.data[id]), cell);
660
+ this.data[id] = Object.assign(Object.assign({}, current), cell);
584
661
  }
585
662
  else {
586
663
  this.data[id] = cell;
@@ -592,23 +669,26 @@ class Table {
592
669
  diffAfter,
593
670
  };
594
671
  }
595
- update({ diff, partial = true, updateChangedAt = true, reflection = {}, }) {
672
+ update({ diff, partial = true, updateChangedAt = true, historicize = true, operator = "SYSTEM", reflection = {}, }) {
596
673
  const { diffBefore, diffAfter } = this._update({
597
674
  diff,
598
675
  partial,
676
+ operator,
599
677
  updateChangedAt,
600
678
  });
601
- this.pushHistory({
602
- applyed: true,
603
- operation: "UPDATE",
604
- reflection,
605
- diffBefore,
606
- diffAfter,
607
- partial,
608
- });
679
+ if (historicize) {
680
+ this.pushHistory({
681
+ applyed: true,
682
+ operation: "UPDATE",
683
+ reflection,
684
+ diffBefore,
685
+ diffAfter,
686
+ partial,
687
+ });
688
+ }
609
689
  return this.shallowCopy({ copyCache: true });
610
690
  }
611
- writeMatrix({ point, matrix, updateChangedAt = true, reflection = {}, }) {
691
+ writeMatrix({ point, matrix, updateChangedAt = true, historicize = true, operator = "SYSTEM", reflection = {}, }) {
612
692
  const { y: baseY, x: baseX } = point;
613
693
  const diff = {};
614
694
  matrix.forEach((cols, i) => {
@@ -629,28 +709,32 @@ class Table {
629
709
  diff,
630
710
  partial: true,
631
711
  updateChangedAt,
712
+ historicize,
713
+ operator,
632
714
  reflection,
633
715
  });
634
716
  }
635
- write({ point, value, updateChangedAt = true, reflection = {}, }) {
717
+ write({ point, value, updateChangedAt = true, historicize = true, operator = "SYSTEM", reflection = {}, }) {
636
718
  return this.writeMatrix({
637
719
  point,
638
720
  matrix: [[value]],
639
721
  updateChangedAt,
722
+ historicize,
723
+ operator,
640
724
  reflection,
641
725
  });
642
726
  }
643
- addRowsAndUpdate({ y, numRows, baseY, diff, partial, updateChangedAt, reflection = {}, }) {
727
+ addRowsAndUpdate({ y, numRows, baseY, diff, partial, updateChangedAt, operator = "SYSTEM", reflection = {}, }) {
644
728
  const returned = this.addRows({
645
729
  y,
646
730
  numRows,
647
731
  baseY,
648
732
  reflection,
649
733
  });
650
- Object.assign(this.lastHistory, this._update({ diff, partial, updateChangedAt }), { partial });
734
+ Object.assign(this.lastHistory, this._update({ diff, partial, updateChangedAt, operator }), { partial });
651
735
  return returned;
652
736
  }
653
- addRows({ y, numRows, baseY, reflection = {}, }) {
737
+ addRows({ y, numRows, baseY, operator = "SYSTEM", reflection = {}, }) {
654
738
  if (this.maxNumRows !== -1 &&
655
739
  this.getNumRows() + numRows > this.maxNumRows) {
656
740
  console.error(`Rows are limited to ${this.maxNumRows}.`);
@@ -682,21 +766,33 @@ class Table {
682
766
  });
683
767
  return this.shallowCopy({ copyCache: false });
684
768
  }
685
- removeRows({ y, numRows, reflection = {}, }) {
769
+ deleteRows({ y, numRows, operator = "SYSTEM", reflection = {}, }) {
686
770
  if (this.minNumRows !== -1 &&
687
771
  this.getNumRows() - numRows < this.minNumRows) {
688
772
  console.error(`At least ${this.minNumRows} row(s) are required.`);
689
773
  return this;
690
774
  }
691
- const rows = this.idMatrix.splice(y, numRows);
692
- this.area.bottom -= numRows;
775
+ const ys = [];
776
+ for (let i = y; i < y + numRows; i++) {
777
+ const cell = this.getByPoint({ y: i, x: 0 });
778
+ if (operator === "USER" && prevention.isPrevented(cell === null || cell === void 0 ? void 0 : cell.prevention, prevention.DeleteRow)) {
779
+ console.warn(`Cannot delete row ${i}.`);
780
+ return this;
781
+ }
782
+ ys.unshift(i);
783
+ }
784
+ const deleted = [];
785
+ ys.forEach((y) => {
786
+ const row = this.idMatrix.splice(y, 1);
787
+ deleted.unshift(row[0]);
788
+ });
789
+ this.area.bottom -= ys.length;
693
790
  this.pushHistory({
694
791
  applyed: true,
695
- operation: "REMOVE_ROWS",
792
+ operation: "DELETE_ROWS",
696
793
  reflection,
697
- y,
698
- numRows,
699
- idMatrix: rows,
794
+ ys: ys.reverse(),
795
+ deleted,
700
796
  });
701
797
  return this.shallowCopy({ copyCache: false });
702
798
  }
@@ -742,25 +838,37 @@ class Table {
742
838
  });
743
839
  return this.shallowCopy({ copyCache: false });
744
840
  }
745
- removeCols({ x, numCols, reflection = {}, }) {
841
+ deleteCols({ x, numCols, operator = "SYSTEM", reflection = {}, }) {
746
842
  if (this.minNumCols !== -1 &&
747
843
  this.getNumCols() - numCols < this.minNumCols) {
748
844
  console.error(`At least ${this.minNumCols} column(s) are required.`);
749
845
  return this;
750
846
  }
751
- const rows = [];
847
+ const xs = [];
848
+ for (let i = x; i < x + numCols; i++) {
849
+ const cell = this.getByPoint({ y: 0, x: i });
850
+ if (operator === "USER" && prevention.isPrevented(cell === null || cell === void 0 ? void 0 : cell.prevention, prevention.DeleteCol)) {
851
+ console.warn(`Cannot delete col ${i}.`);
852
+ continue;
853
+ }
854
+ xs.unshift(i);
855
+ }
856
+ const deleted = [];
752
857
  this.idMatrix.forEach((row) => {
753
- const deleted = row.splice(x, numCols);
754
- rows.push(deleted);
858
+ const deleting = [];
859
+ deleted.push(deleting);
860
+ // reverse and delete
861
+ xs.forEach((x) => {
862
+ deleting.unshift(...row.splice(x, 1));
863
+ });
755
864
  });
756
- this.area.right -= numCols;
865
+ this.area.right -= xs.length;
757
866
  this.pushHistory({
758
867
  applyed: true,
759
- operation: "REMOVE_COLS",
868
+ operation: "DELETE_COLS",
760
869
  reflection,
761
- x,
762
- numCols,
763
- idMatrix: rows,
870
+ xs: xs.reverse(),
871
+ deleted,
764
872
  });
765
873
  return this.shallowCopy({ copyCache: false });
766
874
  }
@@ -868,23 +976,27 @@ class Table {
868
976
  this.area.right -= width;
869
977
  break;
870
978
  }
871
- case "REMOVE_ROWS": {
872
- const { height } = (0, structs_1.matrixShape)({ matrix: history.idMatrix });
873
- this.idMatrix.splice(history.y, 0, ...history.idMatrix);
874
- this.area.bottom += height;
979
+ case "DELETE_ROWS": {
980
+ const { ys, deleted } = history;
981
+ ys.forEach((y, i) => {
982
+ this.idMatrix.splice(y, 0, deleted[i]);
983
+ });
984
+ this.area.bottom += ys.length;
875
985
  break;
876
986
  }
877
- case "REMOVE_COLS": {
878
- const { width } = (0, structs_1.matrixShape)({ matrix: history.idMatrix });
987
+ case "DELETE_COLS": {
988
+ const { xs, deleted } = history;
879
989
  this.idMatrix.forEach((row, i) => {
880
- row.splice(history.x, 0, ...history.idMatrix[i]);
990
+ for (let j = 0; j < xs.length; j++) {
991
+ row.splice(xs[j], 0, deleted[i][j]);
992
+ }
881
993
  });
882
- this.area.right += width;
994
+ this.area.right += xs.length;
883
995
  break;
884
996
  }
885
997
  case "MOVE": {
886
- const { y: yFrom, x: xFrom } = history.pointFrom;
887
- const { y: yTo, x: xTo } = history.pointTo;
998
+ const { top: yFrom, left: xFrom } = history.src;
999
+ const { top: yTo, left: xTo } = history.dst;
888
1000
  const { height: rows, width: cols } = (0, structs_1.matrixShape)({
889
1001
  matrix: history.matrixFrom,
890
1002
  base: -1,
@@ -942,39 +1054,27 @@ class Table {
942
1054
  this.area.right += width;
943
1055
  break;
944
1056
  }
945
- case "REMOVE_ROWS": {
946
- const { height } = (0, structs_1.matrixShape)({ matrix: history.idMatrix });
947
- this.idMatrix.splice(history.y, height);
948
- this.area.bottom -= height;
1057
+ case "DELETE_ROWS": {
1058
+ const { ys } = history;
1059
+ [...ys].reverse().forEach((y) => {
1060
+ this.idMatrix.splice(y, 1);
1061
+ });
1062
+ this.area.bottom -= ys.length;
949
1063
  break;
950
1064
  }
951
- case "REMOVE_COLS": {
952
- const { width } = (0, structs_1.matrixShape)({ matrix: history.idMatrix });
953
- this.idMatrix.forEach((row) => {
954
- row.splice(history.x, width);
1065
+ case "DELETE_COLS": {
1066
+ const { xs } = history;
1067
+ [...xs].reverse().forEach((x) => {
1068
+ this.idMatrix.forEach((row) => {
1069
+ row.splice(x, 1);
1070
+ });
955
1071
  });
956
- this.area.right -= width;
1072
+ this.area.right -= xs.length;
957
1073
  break;
958
1074
  }
959
1075
  case "MOVE": {
960
- const { y: yFrom, x: xFrom } = history.pointFrom;
961
- const { y: yTo, x: xTo } = history.pointTo;
962
- const { height: rows, width: cols } = (0, structs_1.matrixShape)({
963
- matrix: history.matrixFrom,
964
- base: -1,
965
- });
966
- (0, structs_1.putMatrix)(this.idMatrix, history.matrixNew, {
967
- top: yFrom,
968
- left: xFrom,
969
- bottom: yFrom + rows,
970
- right: xFrom + cols,
971
- });
972
- (0, structs_1.putMatrix)(this.idMatrix, history.matrixFrom, {
973
- top: yTo,
974
- left: xTo,
975
- bottom: yTo + rows,
976
- right: xTo + cols,
977
- });
1076
+ const { src, dst } = history;
1077
+ this.move({ src, dst, operator: "USER", historicize: false });
978
1078
  }
979
1079
  }
980
1080
  return {