@rowsncolumns/spreadsheet-state 28.0.75 → 29.0.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.
- package/dist/cjs/api/anchored-objects.d.ts +66 -0
- package/dist/cjs/api/anchored-objects.d.ts.map +1 -0
- package/dist/cjs/api/anchored-objects.js +259 -0
- package/dist/cjs/api/copy-paste.d.ts +8 -1
- package/dist/cjs/api/copy-paste.d.ts.map +1 -1
- package/dist/cjs/api/copy-paste.js +4 -2
- package/dist/cjs/api/dependency.d.ts +13 -2
- package/dist/cjs/api/dependency.d.ts.map +1 -1
- package/dist/cjs/api/dependency.js +11 -5
- package/dist/cjs/api/formula.d.ts +61 -4
- package/dist/cjs/api/formula.d.ts.map +1 -1
- package/dist/cjs/api/formula.js +250 -61
- package/dist/cjs/api/immer-utils.d.ts +11 -1
- package/dist/cjs/api/immer-utils.d.ts.map +1 -1
- package/dist/cjs/api/immer-utils.js +17 -1
- package/dist/cjs/api/insert-cut-cells.d.ts +35 -0
- package/dist/cjs/api/insert-cut-cells.d.ts.map +1 -0
- package/dist/cjs/api/insert-cut-cells.js +60 -0
- package/dist/cjs/api/merges.d.ts +16 -0
- package/dist/cjs/api/merges.d.ts.map +1 -1
- package/dist/cjs/api/merges.js +75 -1
- package/dist/cjs/api/named-range-structural.d.ts +62 -0
- package/dist/cjs/api/named-range-structural.d.ts.map +1 -0
- package/dist/cjs/api/named-range-structural.js +197 -0
- package/dist/cjs/api/range-rule-helpers.d.ts +45 -1
- package/dist/cjs/api/range-rule-helpers.d.ts.map +1 -1
- package/dist/cjs/api/range-rule-helpers.js +159 -6
- package/dist/cjs/api/structural-formula-update.d.ts.map +1 -1
- package/dist/cjs/api/structural-formula-update.js +24 -6
- package/dist/cjs/api/structural-guards.d.ts +78 -0
- package/dist/cjs/api/structural-guards.d.ts.map +1 -0
- package/dist/cjs/api/structural-guards.js +202 -0
- package/dist/cjs/api/structural-table-refs.d.ts +94 -0
- package/dist/cjs/api/structural-table-refs.d.ts.map +1 -0
- package/dist/cjs/api/structural-table-refs.js +313 -0
- package/dist/cjs/api/subtotal.d.ts +20 -13
- package/dist/cjs/api/subtotal.d.ts.map +1 -1
- package/dist/cjs/api/subtotal.js +26 -19
- package/dist/cjs/commands.d.ts +9 -0
- package/dist/cjs/commands.d.ts.map +1 -1
- package/dist/cjs/constants.d.ts +25 -0
- package/dist/cjs/constants.d.ts.map +1 -0
- package/dist/cjs/constants.js +26 -0
- package/dist/cjs/hooks/use-calculation-worker.d.ts.map +1 -1
- package/dist/cjs/hooks/use-calculation-worker.js +64 -6
- package/dist/cjs/hooks/use-calculation.d.ts +7 -0
- package/dist/cjs/hooks/use-calculation.d.ts.map +1 -1
- package/dist/cjs/hooks/use-calculation.js +15 -0
- package/dist/cjs/hooks/use-on-calculation-success.d.ts +7 -0
- package/dist/cjs/hooks/use-on-calculation-success.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-calculation-success.js +7 -1
- package/dist/cjs/hooks/use-on-copy.d.ts +1 -1
- package/dist/cjs/hooks/use-on-copy.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-copy.js +2 -3
- package/dist/cjs/hooks/use-on-delete-cells-shift-left.d.ts +13 -3
- package/dist/cjs/hooks/use-on-delete-cells-shift-left.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-delete-cells-shift-left.js +27 -2
- package/dist/cjs/hooks/use-on-delete-cells-shift-up.d.ts +13 -3
- package/dist/cjs/hooks/use-on-delete-cells-shift-up.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-delete-cells-shift-up.js +27 -2
- package/dist/cjs/hooks/use-on-delete-column.d.ts +13 -4
- package/dist/cjs/hooks/use-on-delete-column.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-delete-column.js +14 -2
- package/dist/cjs/hooks/use-on-delete-row.d.ts +13 -4
- package/dist/cjs/hooks/use-on-delete-row.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-delete-row.js +14 -2
- package/dist/cjs/hooks/use-on-insert-cells-shift-down.d.ts +13 -3
- package/dist/cjs/hooks/use-on-insert-cells-shift-down.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-insert-cells-shift-down.js +27 -2
- package/dist/cjs/hooks/use-on-insert-cells-shift-right.d.ts +13 -3
- package/dist/cjs/hooks/use-on-insert-cells-shift-right.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-insert-cells-shift-right.js +27 -2
- package/dist/cjs/hooks/use-on-insert-column.d.ts +10 -3
- package/dist/cjs/hooks/use-on-insert-column.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-insert-column.js +33 -7
- package/dist/cjs/hooks/use-on-insert-row.d.ts +10 -3
- package/dist/cjs/hooks/use-on-insert-row.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-insert-row.js +32 -7
- package/dist/cjs/hooks/use-on-move-columns.d.ts +2 -1
- package/dist/cjs/hooks/use-on-move-columns.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-move-columns.js +14 -5
- package/dist/cjs/hooks/use-on-move-rows.d.ts +16 -1
- package/dist/cjs/hooks/use-on-move-rows.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-move-rows.js +30 -5
- package/dist/cjs/hooks/use-on-move-selection.d.ts +7 -2
- package/dist/cjs/hooks/use-on-move-selection.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-move-selection.js +14 -1
- package/dist/cjs/hooks/use-on-paste.d.ts +12 -2
- package/dist/cjs/hooks/use-on-paste.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-paste.js +56 -8
- package/dist/cjs/hooks/use-spreadsheet-state.d.ts +16 -5
- package/dist/cjs/hooks/use-spreadsheet-state.d.ts.map +1 -1
- package/dist/cjs/hooks/use-spreadsheet-state.js +141 -18
- package/dist/cjs/hooks/use-structured-reference.d.ts.map +1 -1
- package/dist/cjs/hooks/use-structured-reference.js +10 -6
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +4 -0
- package/dist/cjs/interface/calculation-interface.d.ts +9 -0
- package/dist/cjs/interface/calculation-interface.d.ts.map +1 -1
- package/dist/cjs/interface/calculation-interface.js +31 -2
- package/dist/cjs/interface/delete-cells-shift-left.d.ts +8 -1
- package/dist/cjs/interface/delete-cells-shift-left.d.ts.map +1 -1
- package/dist/cjs/interface/delete-cells-shift-left.js +158 -80
- package/dist/cjs/interface/delete-cells-shift-up.d.ts +9 -1
- package/dist/cjs/interface/delete-cells-shift-up.d.ts.map +1 -1
- package/dist/cjs/interface/delete-cells-shift-up.js +155 -73
- package/dist/cjs/interface/delete-column.d.ts +1 -1
- package/dist/cjs/interface/delete-column.d.ts.map +1 -1
- package/dist/cjs/interface/delete-column.js +109 -50
- package/dist/cjs/interface/delete-row.d.ts +1 -1
- package/dist/cjs/interface/delete-row.d.ts.map +1 -1
- package/dist/cjs/interface/delete-row.js +105 -46
- package/dist/cjs/interface/insert-cells-shift-down.d.ts +10 -1
- package/dist/cjs/interface/insert-cells-shift-down.d.ts.map +1 -1
- package/dist/cjs/interface/insert-cells-shift-down.js +147 -52
- package/dist/cjs/interface/insert-cells-shift-right.d.ts +10 -1
- package/dist/cjs/interface/insert-cells-shift-right.d.ts.map +1 -1
- package/dist/cjs/interface/insert-cells-shift-right.js +154 -58
- package/dist/cjs/interface/insert-column.d.ts +1 -1
- package/dist/cjs/interface/insert-column.d.ts.map +1 -1
- package/dist/cjs/interface/insert-column.js +80 -26
- package/dist/cjs/interface/insert-row.d.ts +1 -1
- package/dist/cjs/interface/insert-row.d.ts.map +1 -1
- package/dist/cjs/interface/insert-row.js +63 -15
- package/dist/cjs/interface/spreadsheet-interface.d.ts.map +1 -1
- package/dist/cjs/interface/spreadsheet-interface.js +33 -0
- package/dist/cjs/sheet-cell.d.ts.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/api/anchored-objects.d.ts +66 -0
- package/dist/esm/api/anchored-objects.d.ts.map +1 -0
- package/dist/esm/api/anchored-objects.js +212 -0
- package/dist/esm/api/copy-paste.d.ts +8 -1
- package/dist/esm/api/copy-paste.d.ts.map +1 -1
- package/dist/esm/api/copy-paste.js +4 -2
- package/dist/esm/api/dependency.d.ts +13 -2
- package/dist/esm/api/dependency.d.ts.map +1 -1
- package/dist/esm/api/dependency.js +10 -4
- package/dist/esm/api/formula.d.ts +61 -4
- package/dist/esm/api/formula.d.ts.map +1 -1
- package/dist/esm/api/formula.js +238 -60
- package/dist/esm/api/immer-utils.d.ts +11 -1
- package/dist/esm/api/immer-utils.d.ts.map +1 -1
- package/dist/esm/api/immer-utils.js +16 -0
- package/dist/esm/api/insert-cut-cells.d.ts +35 -0
- package/dist/esm/api/insert-cut-cells.d.ts.map +1 -0
- package/dist/esm/api/insert-cut-cells.js +67 -0
- package/dist/esm/api/merges.d.ts +16 -0
- package/dist/esm/api/merges.d.ts.map +1 -1
- package/dist/esm/api/merges.js +60 -0
- package/dist/esm/api/named-range-structural.d.ts +62 -0
- package/dist/esm/api/named-range-structural.d.ts.map +1 -0
- package/dist/esm/api/named-range-structural.js +176 -0
- package/dist/esm/api/range-rule-helpers.d.ts +45 -1
- package/dist/esm/api/range-rule-helpers.d.ts.map +1 -1
- package/dist/esm/api/range-rule-helpers.js +153 -1
- package/dist/esm/api/structural-formula-update.d.ts.map +1 -1
- package/dist/esm/api/structural-formula-update.js +24 -6
- package/dist/esm/api/structural-guards.d.ts +78 -0
- package/dist/esm/api/structural-guards.d.ts.map +1 -0
- package/dist/esm/api/structural-guards.js +186 -0
- package/dist/esm/api/structural-table-refs.d.ts +94 -0
- package/dist/esm/api/structural-table-refs.d.ts.map +1 -0
- package/dist/esm/api/structural-table-refs.js +219 -0
- package/dist/esm/api/subtotal.d.ts +20 -13
- package/dist/esm/api/subtotal.d.ts.map +1 -1
- package/dist/esm/api/subtotal.js +15 -8
- package/dist/esm/commands.d.ts +9 -0
- package/dist/esm/commands.d.ts.map +1 -1
- package/dist/esm/constants.d.ts +25 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +26 -0
- package/dist/esm/hooks/use-calculation-worker.d.ts.map +1 -1
- package/dist/esm/hooks/use-calculation-worker.js +45 -0
- package/dist/esm/hooks/use-calculation.d.ts +7 -0
- package/dist/esm/hooks/use-calculation.d.ts.map +1 -1
- package/dist/esm/hooks/use-calculation.js +15 -0
- package/dist/esm/hooks/use-on-calculation-success.d.ts +7 -0
- package/dist/esm/hooks/use-on-calculation-success.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-calculation-success.js +7 -1
- package/dist/esm/hooks/use-on-copy.d.ts +1 -1
- package/dist/esm/hooks/use-on-copy.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-copy.js +2 -3
- package/dist/esm/hooks/use-on-delete-cells-shift-left.d.ts +13 -3
- package/dist/esm/hooks/use-on-delete-cells-shift-left.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-delete-cells-shift-left.js +26 -2
- package/dist/esm/hooks/use-on-delete-cells-shift-up.d.ts +13 -3
- package/dist/esm/hooks/use-on-delete-cells-shift-up.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-delete-cells-shift-up.js +26 -2
- package/dist/esm/hooks/use-on-delete-column.d.ts +13 -4
- package/dist/esm/hooks/use-on-delete-column.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-delete-column.js +14 -2
- package/dist/esm/hooks/use-on-delete-row.d.ts +13 -4
- package/dist/esm/hooks/use-on-delete-row.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-delete-row.js +14 -2
- package/dist/esm/hooks/use-on-insert-cells-shift-down.d.ts +13 -3
- package/dist/esm/hooks/use-on-insert-cells-shift-down.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-insert-cells-shift-down.js +26 -2
- package/dist/esm/hooks/use-on-insert-cells-shift-right.d.ts +13 -3
- package/dist/esm/hooks/use-on-insert-cells-shift-right.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-insert-cells-shift-right.js +26 -2
- package/dist/esm/hooks/use-on-insert-column.d.ts +10 -3
- package/dist/esm/hooks/use-on-insert-column.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-insert-column.js +33 -7
- package/dist/esm/hooks/use-on-insert-row.d.ts +10 -3
- package/dist/esm/hooks/use-on-insert-row.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-insert-row.js +32 -7
- package/dist/esm/hooks/use-on-move-columns.d.ts +2 -1
- package/dist/esm/hooks/use-on-move-columns.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-move-columns.js +14 -5
- package/dist/esm/hooks/use-on-move-rows.d.ts +16 -1
- package/dist/esm/hooks/use-on-move-rows.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-move-rows.js +30 -5
- package/dist/esm/hooks/use-on-move-selection.d.ts +7 -2
- package/dist/esm/hooks/use-on-move-selection.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-move-selection.js +14 -1
- package/dist/esm/hooks/use-on-paste.d.ts +12 -2
- package/dist/esm/hooks/use-on-paste.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-paste.js +41 -2
- package/dist/esm/hooks/use-spreadsheet-state.d.ts +16 -5
- package/dist/esm/hooks/use-spreadsheet-state.d.ts.map +1 -1
- package/dist/esm/hooks/use-spreadsheet-state.js +141 -17
- package/dist/esm/hooks/use-structured-reference.d.ts.map +1 -1
- package/dist/esm/hooks/use-structured-reference.js +10 -6
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +4 -0
- package/dist/esm/interface/calculation-interface.d.ts +9 -0
- package/dist/esm/interface/calculation-interface.d.ts.map +1 -1
- package/dist/esm/interface/calculation-interface.js +33 -2
- package/dist/esm/interface/delete-cells-shift-left.d.ts +8 -1
- package/dist/esm/interface/delete-cells-shift-left.d.ts.map +1 -1
- package/dist/esm/interface/delete-cells-shift-left.js +135 -59
- package/dist/esm/interface/delete-cells-shift-up.d.ts +9 -1
- package/dist/esm/interface/delete-cells-shift-up.d.ts.map +1 -1
- package/dist/esm/interface/delete-cells-shift-up.js +133 -53
- package/dist/esm/interface/delete-column.d.ts +1 -1
- package/dist/esm/interface/delete-column.d.ts.map +1 -1
- package/dist/esm/interface/delete-column.js +96 -38
- package/dist/esm/interface/delete-row.d.ts +1 -1
- package/dist/esm/interface/delete-row.d.ts.map +1 -1
- package/dist/esm/interface/delete-row.js +98 -39
- package/dist/esm/interface/insert-cells-shift-down.d.ts +10 -1
- package/dist/esm/interface/insert-cells-shift-down.d.ts.map +1 -1
- package/dist/esm/interface/insert-cells-shift-down.js +116 -47
- package/dist/esm/interface/insert-cells-shift-right.d.ts +10 -1
- package/dist/esm/interface/insert-cells-shift-right.d.ts.map +1 -1
- package/dist/esm/interface/insert-cells-shift-right.js +120 -51
- package/dist/esm/interface/insert-column.d.ts +1 -1
- package/dist/esm/interface/insert-column.d.ts.map +1 -1
- package/dist/esm/interface/insert-column.js +68 -18
- package/dist/esm/interface/insert-row.d.ts +1 -1
- package/dist/esm/interface/insert-row.d.ts.map +1 -1
- package/dist/esm/interface/insert-row.js +60 -14
- package/dist/esm/interface/spreadsheet-interface.d.ts.map +1 -1
- package/dist/esm/interface/spreadsheet-interface.js +29 -0
- package/dist/esm/sheet-cell.d.ts.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +18 -18
|
@@ -1,62 +1,91 @@
|
|
|
1
|
-
import { __read, __spreadArray, __values } from "tslib";
|
|
2
|
-
import { selectionFromActiveCell } from "@rowsncolumns/utils";
|
|
1
|
+
import { __assign, __read, __spreadArray, __values } from "tslib";
|
|
3
2
|
import { produceWithPatches } from "immer";
|
|
4
3
|
import { collectUniqueDependentsForRange, moveFormulaAtPosition, } from "../api/dependency";
|
|
5
|
-
import {
|
|
4
|
+
import { contractRangesInFormula } from "../api/formula";
|
|
5
|
+
import { createSheetDraft } from "../api/immer-utils";
|
|
6
|
+
import { shiftMergesInBand } from "../api/merges";
|
|
7
|
+
import { isRangeInsideBand, isRangeInsideBlock, resolveShiftSelection, shiftBand, } from "../api/structural-guards";
|
|
8
|
+
import { SheetCell } from "../sheet-cell";
|
|
9
|
+
/**
|
|
10
|
+
* Delete cells ▸ Shift cells left (SHF-04) — the horizontal twin of `deleteCellsShiftUp`: only the
|
|
11
|
+
* selection's rows move, the selected block is removed and every cell to its right slides left by
|
|
12
|
+
* the block's width. A reference to a deleted cell becomes `#REF!`; one to a cell that slid left
|
|
13
|
+
* follows it; a range entirely inside the block's rows that the block partially covers contracts.
|
|
14
|
+
* Refusals (torn merge/table/array) are decided by the hook before this runs.
|
|
15
|
+
*/
|
|
6
16
|
export var deleteCellsShiftLeft = function (_a) {
|
|
7
|
-
var rowCount = _a.rowCount, columnCount = _a.columnCount, locale = _a.locale, cellXfsRegistry = _a.cellXfsRegistry, sharedStringRegistry = _a.sharedStringRegistry, getActiveCell = _a.getActiveCell, getSelections = _a.getSelections, getDependents = _a.getDependents, createHistory = _a.createHistory, enqueueGraphOperation = _a.enqueueGraphOperation, enqueueCalculation = _a.enqueueCalculation, enqueueStructureChange = _a.enqueueStructureChange, onChangeSheetData = _a.onChangeSheetData, onChangeSheets = _a.onChangeSheets, onChangeCitations = _a.onChangeCitations;
|
|
17
|
+
var rowCount = _a.rowCount, columnCount = _a.columnCount, locale = _a.locale, cellXfsRegistry = _a.cellXfsRegistry, sharedStringRegistry = _a.sharedStringRegistry, getActiveCell = _a.getActiveCell, getSelections = _a.getSelections, getDependents = _a.getDependents, getSheetName = _a.getSheetName, createHistory = _a.createHistory, enqueueGraphOperation = _a.enqueueGraphOperation, enqueueCalculation = _a.enqueueCalculation, enqueueStructureChange = _a.enqueueStructureChange, onChangeSheetData = _a.onChangeSheetData, onChangeSheets = _a.onChangeSheets, onChangeTables = _a.onChangeTables, onChangeCitations = _a.onChangeCitations;
|
|
8
18
|
return function (sheetId, activeCell, selections) {
|
|
19
|
+
var _a;
|
|
9
20
|
var saveHistory = createHistory();
|
|
10
21
|
var recalcCells = new Map();
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
var
|
|
22
|
+
var selection = resolveShiftSelection(activeCell, selections);
|
|
23
|
+
var _b = selection.range, r1 = _b.startRowIndex, r2 = _b.endRowIndex, c1 = _b.startColumnIndex, c2 = _b.endColumnIndex;
|
|
24
|
+
var count = c2 - c1 + 1;
|
|
25
|
+
var band = shiftBand("left", selection.range);
|
|
26
|
+
var deletedRange = __assign({}, selection.range);
|
|
27
|
+
var sheetName = (_a = getSheetName === null || getSheetName === void 0 ? void 0 : getSheetName(sheetId)) !== null && _a !== void 0 ? _a : "";
|
|
17
28
|
enqueueStructureChange === null || enqueueStructureChange === void 0 ? void 0 : enqueueStructureChange({
|
|
18
29
|
kind: "delete-cells-shift-left",
|
|
19
30
|
sheetId: sheetId,
|
|
20
|
-
startRowIndex:
|
|
21
|
-
endRowIndex:
|
|
22
|
-
startColumnIndex:
|
|
23
|
-
endColumnIndex:
|
|
31
|
+
startRowIndex: r1,
|
|
32
|
+
endRowIndex: r2,
|
|
33
|
+
startColumnIndex: c1,
|
|
34
|
+
endColumnIndex: c2,
|
|
24
35
|
columnCount: columnCount,
|
|
25
36
|
});
|
|
26
|
-
// Update merges on sheet
|
|
37
|
+
// Update merges on sheet — merges wholly inside the deleted block go with it; merges wholly
|
|
38
|
+
// inside the shifted rows right of it ride left.
|
|
27
39
|
onChangeSheets === null || onChangeSheets === void 0 ? void 0 : onChangeSheets(function (prevSheets) {
|
|
28
40
|
var _a = __read(produceWithPatches(prevSheets, function (draft) {
|
|
29
41
|
var sheet = draft.find(function (s) { return s.sheetId === sheetId; });
|
|
30
42
|
if (sheet === null || sheet === void 0 ? void 0 : sheet.merges) {
|
|
31
|
-
|
|
32
|
-
sheet.merges = moveMergedCells(sheet.merges, "column-remove", columnIndex);
|
|
33
|
-
}
|
|
43
|
+
sheet.merges = shiftMergesInBand(sheet.merges, "column", c1, count, false, r1, r2);
|
|
34
44
|
}
|
|
35
45
|
}), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
|
|
36
46
|
saveHistory({ sheets: { patches: patches, inversePatches: inversePatches } });
|
|
37
47
|
return nextState;
|
|
38
48
|
});
|
|
49
|
+
// Tables: one wholly inside the deleted block is deleted with it; one wholly inside the
|
|
50
|
+
// shifted rows right of the block rides left. A partial cover was refused by the hook.
|
|
51
|
+
onChangeTables === null || onChangeTables === void 0 ? void 0 : onChangeTables(function (prevTables) {
|
|
52
|
+
var _a = __read(produceWithPatches(prevTables, function (draft) {
|
|
53
|
+
for (var idx = draft.length - 1; idx >= 0; idx--) {
|
|
54
|
+
var table = draft[idx];
|
|
55
|
+
if (table.sheetId !== sheetId)
|
|
56
|
+
continue;
|
|
57
|
+
if (isRangeInsideBlock(deletedRange, table.range)) {
|
|
58
|
+
draft.splice(idx, 1);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (isRangeInsideBand(table.range, band) &&
|
|
62
|
+
table.range.startColumnIndex > c2) {
|
|
63
|
+
table.range.startColumnIndex -= count;
|
|
64
|
+
table.range.endColumnIndex -= count;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
|
|
68
|
+
saveHistory({ tables: { patches: patches, inversePatches: inversePatches } });
|
|
69
|
+
return nextState;
|
|
70
|
+
});
|
|
39
71
|
// Update citations - delete if overlapping, shift back if after
|
|
40
72
|
onChangeCitations === null || onChangeCitations === void 0 ? void 0 : onChangeCitations(function (prevCitations) {
|
|
41
73
|
var _a = __read(produceWithPatches(prevCitations, function (draft) {
|
|
42
|
-
var deleteRowStart = selection.range.startRowIndex;
|
|
43
|
-
var deleteRowEnd = selection.range.endRowIndex;
|
|
44
|
-
var deleteColStart = selection.range.startColumnIndex;
|
|
45
|
-
var deleteColEnd = selection.range.endColumnIndex;
|
|
46
|
-
var shiftAmount = deleteColEnd - deleteColStart + 1;
|
|
47
74
|
for (var idx = draft.length - 1; idx >= 0; idx--) {
|
|
48
75
|
var citation = draft[idx];
|
|
49
76
|
if (citation.range.sheetId !== sheetId)
|
|
50
77
|
continue;
|
|
51
|
-
var rowsOverlap = !(citation.range.endRowIndex <
|
|
78
|
+
var rowsOverlap = !(citation.range.endRowIndex < r1 ||
|
|
79
|
+
citation.range.startRowIndex > r2);
|
|
52
80
|
if (rowsOverlap) {
|
|
53
|
-
var colsOverlap = !(citation.range.endColumnIndex <
|
|
81
|
+
var colsOverlap = !(citation.range.endColumnIndex < c1 ||
|
|
82
|
+
citation.range.startColumnIndex > c2);
|
|
54
83
|
if (colsOverlap) {
|
|
55
84
|
draft.splice(idx, 1);
|
|
56
85
|
}
|
|
57
|
-
else if (citation.range.startColumnIndex >
|
|
58
|
-
citation.range.startColumnIndex -=
|
|
59
|
-
citation.range.endColumnIndex -=
|
|
86
|
+
else if (citation.range.startColumnIndex > c2) {
|
|
87
|
+
citation.range.startColumnIndex -= count;
|
|
88
|
+
citation.range.endColumnIndex -= count;
|
|
60
89
|
}
|
|
61
90
|
}
|
|
62
91
|
}
|
|
@@ -68,79 +97,128 @@ export var deleteCellsShiftLeft = function (_a) {
|
|
|
68
97
|
onChangeSheetData === null || onChangeSheetData === void 0 ? void 0 : onChangeSheetData(function (prevSheetData) {
|
|
69
98
|
var _a = __read(produceWithPatches(prevSheetData, function (draft) {
|
|
70
99
|
var e_1, _a;
|
|
71
|
-
var _b, _c, _d, _e, _f, _g, _h, _j;
|
|
100
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
72
101
|
var movedKeys = new Set();
|
|
73
|
-
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
102
|
+
var totalColumns = Math.max(columnCount, c2 + 1);
|
|
103
|
+
for (var rowIndex = r1; rowIndex <= r2; rowIndex++) {
|
|
104
|
+
totalColumns = Math.max(totalColumns, (_e = (_d = (_c = (_b = draft[sheetId]) === null || _b === void 0 ? void 0 : _b[rowIndex]) === null || _c === void 0 ? void 0 : _c.values) === null || _d === void 0 ? void 0 : _d.length) !== null && _e !== void 0 ? _e : 0);
|
|
105
|
+
}
|
|
106
|
+
// The cells that actually move: everything RIGHT of the deleted block in its rows.
|
|
107
|
+
var movingRange = {
|
|
108
|
+
startRowIndex: r1,
|
|
109
|
+
endRowIndex: r2,
|
|
110
|
+
startColumnIndex: c2 + 1,
|
|
111
|
+
endColumnIndex: totalColumns,
|
|
79
112
|
};
|
|
80
|
-
//
|
|
113
|
+
// Dependents of the deleted block AND of the moving cells, each processed once.
|
|
81
114
|
var dependents = collectUniqueDependentsForRange({
|
|
82
115
|
draft: draft,
|
|
83
116
|
sheetId: sheetId,
|
|
84
|
-
sourceRange:
|
|
117
|
+
sourceRange: {
|
|
118
|
+
startRowIndex: r1,
|
|
119
|
+
endRowIndex: r2,
|
|
120
|
+
startColumnIndex: c1,
|
|
121
|
+
endColumnIndex: totalColumns,
|
|
122
|
+
},
|
|
85
123
|
getDependents: getDependents,
|
|
86
124
|
});
|
|
125
|
+
var sheetCell = new SheetCell();
|
|
126
|
+
var contractAt = function (pos) {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
if (pos.sheetId !== sheetId)
|
|
129
|
+
return;
|
|
130
|
+
var currentSheet = createSheetDraft(draft, sheetId, pos.rowIndex);
|
|
131
|
+
var cellData = (_b = (_a = currentSheet[pos.rowIndex]) === null || _a === void 0 ? void 0 : _a.values) === null || _b === void 0 ? void 0 : _b[pos.columnIndex];
|
|
132
|
+
sheetCell.assign(sheetId, { rowIndex: pos.rowIndex, columnIndex: pos.columnIndex }, cellData, { locale: locale, cellXfsRegistry: cellXfsRegistry, sharedStringRegistry: sharedStringRegistry });
|
|
133
|
+
var formulaValue = sheetCell.formula;
|
|
134
|
+
if (!formulaValue)
|
|
135
|
+
return;
|
|
136
|
+
var contracted = contractRangesInFormula(formulaValue, c1, count, "column", sheetName, { bandSpan: { startIndex: r1, endIndex: r2 } });
|
|
137
|
+
if (!contracted || contracted === formulaValue)
|
|
138
|
+
return;
|
|
139
|
+
sheetCell.setFormulaValue(contracted, false);
|
|
140
|
+
currentSheet[pos.rowIndex].values[pos.columnIndex] =
|
|
141
|
+
sheetCell.getCellData();
|
|
142
|
+
};
|
|
143
|
+
var rebaseAt = function (pos) {
|
|
144
|
+
var insideBlock = pos.sheetId === sheetId &&
|
|
145
|
+
pos.rowIndex >= r1 &&
|
|
146
|
+
pos.rowIndex <= r2 &&
|
|
147
|
+
pos.columnIndex >= c1 &&
|
|
148
|
+
pos.columnIndex <= c2;
|
|
149
|
+
if (insideBlock)
|
|
150
|
+
return;
|
|
151
|
+
var moves = pos.sheetId === sheetId &&
|
|
152
|
+
pos.columnIndex > c2 &&
|
|
153
|
+
pos.rowIndex >= r1 &&
|
|
154
|
+
pos.rowIndex <= r2;
|
|
155
|
+
contractAt(pos);
|
|
156
|
+
moveFormulaAtPosition({
|
|
157
|
+
draft: draft,
|
|
158
|
+
position: pos,
|
|
159
|
+
activeSheetName: getSheetName === null || getSheetName === void 0 ? void 0 : getSheetName(pos.sheetId),
|
|
160
|
+
enqueueCalculation: enqueueCalculation,
|
|
161
|
+
enqueueGraphOperation: enqueueGraphOperation,
|
|
162
|
+
recalcCells: recalcCells,
|
|
163
|
+
movedKeys: movedKeys,
|
|
164
|
+
rowDelta: 0,
|
|
165
|
+
columnDelta: -count,
|
|
166
|
+
destinationPosition: {
|
|
167
|
+
rowIndex: pos.rowIndex,
|
|
168
|
+
columnIndex: moves ? pos.columnIndex - count : pos.columnIndex,
|
|
169
|
+
},
|
|
170
|
+
sourceRange: movingRange,
|
|
171
|
+
deletedRange: deletedRange,
|
|
172
|
+
locale: locale,
|
|
173
|
+
rowCount: rowCount,
|
|
174
|
+
columnCount: columnCount,
|
|
175
|
+
cellXfsRegistry: cellXfsRegistry,
|
|
176
|
+
sharedStringRegistry: sharedStringRegistry,
|
|
177
|
+
});
|
|
178
|
+
};
|
|
87
179
|
try {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
moveFormulaAtPosition({
|
|
92
|
-
draft: draft,
|
|
93
|
-
position: pos,
|
|
94
|
-
enqueueCalculation: enqueueCalculation,
|
|
95
|
-
enqueueGraphOperation: enqueueGraphOperation,
|
|
96
|
-
recalcCells: recalcCells,
|
|
97
|
-
movedKeys: movedKeys,
|
|
98
|
-
rowDelta: 0,
|
|
99
|
-
columnDelta: -count,
|
|
100
|
-
sourceRange: sourceRange,
|
|
101
|
-
locale: locale,
|
|
102
|
-
rowCount: rowCount,
|
|
103
|
-
columnCount: columnCount,
|
|
104
|
-
cellXfsRegistry: cellXfsRegistry,
|
|
105
|
-
sharedStringRegistry: sharedStringRegistry,
|
|
106
|
-
});
|
|
180
|
+
for (var _s = __values(dependents.values()), _t = _s.next(); !_t.done; _t = _s.next()) {
|
|
181
|
+
var pos = _t.value;
|
|
182
|
+
rebaseAt(pos);
|
|
107
183
|
}
|
|
108
184
|
}
|
|
109
185
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
110
186
|
finally {
|
|
111
187
|
try {
|
|
112
|
-
if (
|
|
188
|
+
if (_t && !_t.done && (_a = _s.return)) _a.call(_s);
|
|
113
189
|
}
|
|
114
190
|
finally { if (e_1) throw e_1.error; }
|
|
115
191
|
}
|
|
116
|
-
//
|
|
117
|
-
for (var rowIndex =
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
moveFormulaAtPosition({
|
|
122
|
-
draft: draft,
|
|
123
|
-
position: { sheetId: sheetId, rowIndex: rowIndex, columnIndex: columnIndex },
|
|
124
|
-
enqueueCalculation: enqueueCalculation,
|
|
125
|
-
enqueueGraphOperation: enqueueGraphOperation,
|
|
126
|
-
recalcCells: recalcCells,
|
|
127
|
-
movedKeys: movedKeys,
|
|
128
|
-
rowDelta: 0,
|
|
129
|
-
columnDelta: -count,
|
|
130
|
-
sourceRange: sourceRange,
|
|
192
|
+
// Formulas inside the deleted block leave the graph with their cells.
|
|
193
|
+
for (var rowIndex = r1; rowIndex <= r2; rowIndex++) {
|
|
194
|
+
for (var columnIndex = c1; columnIndex <= c2; columnIndex++) {
|
|
195
|
+
var cellData = (_h = (_g = (_f = draft[sheetId]) === null || _f === void 0 ? void 0 : _f[rowIndex]) === null || _g === void 0 ? void 0 : _g.values) === null || _h === void 0 ? void 0 : _h[columnIndex];
|
|
196
|
+
sheetCell.assign(sheetId, { rowIndex: rowIndex, columnIndex: columnIndex }, cellData, {
|
|
131
197
|
locale: locale,
|
|
132
|
-
rowCount: rowCount,
|
|
133
|
-
columnCount: columnCount,
|
|
134
|
-
cellXfsRegistry: cellXfsRegistry,
|
|
135
|
-
sharedStringRegistry: sharedStringRegistry,
|
|
136
198
|
});
|
|
199
|
+
if (!sheetCell.isFormula())
|
|
200
|
+
continue;
|
|
201
|
+
var enqueueOperation = sheetCell.ephemeral()
|
|
202
|
+
? enqueueCalculation
|
|
203
|
+
: enqueueGraphOperation;
|
|
204
|
+
enqueueOperation === null || enqueueOperation === void 0 ? void 0 : enqueueOperation({
|
|
205
|
+
type: "remove",
|
|
206
|
+
position: { sheetId: sheetId, rowIndex: rowIndex, columnIndex: columnIndex },
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// Re-base the moving formulas themselves
|
|
211
|
+
for (var rowIndex = r1; rowIndex <= r2; rowIndex++) {
|
|
212
|
+
var dataColumnCount = (_m = (_l = (_k = (_j = draft[sheetId]) === null || _j === void 0 ? void 0 : _j[rowIndex]) === null || _k === void 0 ? void 0 : _k.values) === null || _l === void 0 ? void 0 : _l.length) !== null && _m !== void 0 ? _m : 0;
|
|
213
|
+
for (var columnIndex = c2 + 1; columnIndex < dataColumnCount; columnIndex++) {
|
|
214
|
+
rebaseAt({ sheetId: sheetId, rowIndex: rowIndex, columnIndex: columnIndex });
|
|
137
215
|
}
|
|
138
216
|
}
|
|
139
217
|
// Finally delete the selected cells by splicing from right to left
|
|
140
|
-
for (var rowIndex =
|
|
141
|
-
for (var columnIndex =
|
|
142
|
-
if ((
|
|
143
|
-
(
|
|
218
|
+
for (var rowIndex = r1; rowIndex <= r2; rowIndex++) {
|
|
219
|
+
for (var columnIndex = c2; columnIndex >= c1; columnIndex--) {
|
|
220
|
+
if ((_p = (_o = draft[sheetId]) === null || _o === void 0 ? void 0 : _o[rowIndex]) === null || _p === void 0 ? void 0 : _p.values) {
|
|
221
|
+
(_r = (_q = draft[sheetId][rowIndex]) === null || _q === void 0 ? void 0 : _q.values) === null || _r === void 0 ? void 0 : _r.splice(columnIndex, 1);
|
|
144
222
|
}
|
|
145
223
|
}
|
|
146
224
|
}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { CellInterface, SelectionArea } from "@rowsncolumns/common-types";
|
|
2
2
|
import type { CellData, SelectionAttributes, Sheet } from "@rowsncolumns/spreadsheet";
|
|
3
3
|
import type { UseOnDeleteCellsShiftUpProps } from "../hooks/use-on-delete-cells-shift-up";
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Delete cells ▸ Shift cells up (SHF-03, SHF-09). Only the selection's columns move: the selected
|
|
6
|
+
* block is removed and every cell below it slides up by the block's height. A reference to a
|
|
7
|
+
* deleted cell (or to a range the block covers entirely) becomes `#REF!` (SHF-09); a reference to a
|
|
8
|
+
* cell that slid up follows it (SHF-03); a range entirely inside the block's columns that the block
|
|
9
|
+
* partially covers contracts by the overlap. Refusals (torn merge/table/array) are decided by the
|
|
10
|
+
* hook via `getShiftCellsRefusal` before this runs.
|
|
11
|
+
*/
|
|
12
|
+
export declare const deleteCellsShiftUp: <T extends CellData, S extends Sheet>({ rowCount, columnCount, locale, cellXfsRegistry, sharedStringRegistry, getActiveCell, getSelections, getDependents, getSheetName, createHistory, enqueueGraphOperation, enqueueCalculation, enqueueStructureChange, onChangeSheetData, onChangeSheets, onChangeTables, onChangeCitations, }: UseOnDeleteCellsShiftUpProps<T, S>) => (sheetId: number, activeCell: CellInterface, selections: SelectionArea<SelectionAttributes>[]) => void;
|
|
5
13
|
//# sourceMappingURL=delete-cells-shift-up.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete-cells-shift-up.d.ts","sourceRoot":"","sources":["../../../interface/delete-cells-shift-up.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAEb,aAAa,EACd,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"delete-cells-shift-up.d.ts","sourceRoot":"","sources":["../../../interface/delete-cells-shift-up.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAEb,aAAa,EACd,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EACV,QAAQ,EACR,mBAAmB,EACnB,KAAK,EACN,MAAM,2BAA2B,CAAC;AAgBnC,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,uCAAuC,CAAC;AAI1F;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,KAAK,EAAE,8RAkBrE,4BAA4B,CAAC,CAAC,EAAE,CAAC,CAAC,MAEjC,SAAS,MAAM,EACf,YAAY,aAAa,EACzB,YAAY,aAAa,CAAC,mBAAmB,CAAC,EAAE,SAmQnD,CAAC"}
|
|
@@ -1,62 +1,92 @@
|
|
|
1
|
-
import { __read, __spreadArray, __values } from "tslib";
|
|
2
|
-
import { selectionFromActiveCell } from "@rowsncolumns/utils";
|
|
1
|
+
import { __assign, __read, __spreadArray, __values } from "tslib";
|
|
3
2
|
import { produceWithPatches } from "immer";
|
|
4
3
|
import { collectUniqueDependentsForRange, moveFormulaAtPosition, } from "../api/dependency";
|
|
4
|
+
import { contractRangesInFormula } from "../api/formula";
|
|
5
5
|
import { createSheetDraft } from "../api/immer-utils";
|
|
6
|
-
import {
|
|
6
|
+
import { shiftMergesInBand } from "../api/merges";
|
|
7
|
+
import { isRangeInsideBand, isRangeInsideBlock, resolveShiftSelection, shiftBand, } from "../api/structural-guards";
|
|
8
|
+
import { SheetCell } from "../sheet-cell";
|
|
9
|
+
/**
|
|
10
|
+
* Delete cells ▸ Shift cells up (SHF-03, SHF-09). Only the selection's columns move: the selected
|
|
11
|
+
* block is removed and every cell below it slides up by the block's height. A reference to a
|
|
12
|
+
* deleted cell (or to a range the block covers entirely) becomes `#REF!` (SHF-09); a reference to a
|
|
13
|
+
* cell that slid up follows it (SHF-03); a range entirely inside the block's columns that the block
|
|
14
|
+
* partially covers contracts by the overlap. Refusals (torn merge/table/array) are decided by the
|
|
15
|
+
* hook via `getShiftCellsRefusal` before this runs.
|
|
16
|
+
*/
|
|
7
17
|
export var deleteCellsShiftUp = function (_a) {
|
|
8
|
-
var rowCount = _a.rowCount, columnCount = _a.columnCount, locale = _a.locale, cellXfsRegistry = _a.cellXfsRegistry, sharedStringRegistry = _a.sharedStringRegistry, getActiveCell = _a.getActiveCell, getSelections = _a.getSelections, getDependents = _a.getDependents, createHistory = _a.createHistory, enqueueGraphOperation = _a.enqueueGraphOperation, enqueueCalculation = _a.enqueueCalculation, enqueueStructureChange = _a.enqueueStructureChange, onChangeSheetData = _a.onChangeSheetData, onChangeSheets = _a.onChangeSheets, onChangeCitations = _a.onChangeCitations;
|
|
18
|
+
var rowCount = _a.rowCount, columnCount = _a.columnCount, locale = _a.locale, cellXfsRegistry = _a.cellXfsRegistry, sharedStringRegistry = _a.sharedStringRegistry, getActiveCell = _a.getActiveCell, getSelections = _a.getSelections, getDependents = _a.getDependents, getSheetName = _a.getSheetName, createHistory = _a.createHistory, enqueueGraphOperation = _a.enqueueGraphOperation, enqueueCalculation = _a.enqueueCalculation, enqueueStructureChange = _a.enqueueStructureChange, onChangeSheetData = _a.onChangeSheetData, onChangeSheets = _a.onChangeSheets, onChangeTables = _a.onChangeTables, onChangeCitations = _a.onChangeCitations;
|
|
9
19
|
return function (sheetId, activeCell, selections) {
|
|
20
|
+
var _a;
|
|
10
21
|
var saveHistory = createHistory();
|
|
11
22
|
var recalcCells = new Map();
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
var
|
|
23
|
+
var selection = resolveShiftSelection(activeCell, selections);
|
|
24
|
+
var _b = selection.range, r1 = _b.startRowIndex, r2 = _b.endRowIndex, c1 = _b.startColumnIndex, c2 = _b.endColumnIndex;
|
|
25
|
+
var count = r2 - r1 + 1;
|
|
26
|
+
var band = shiftBand("up", selection.range);
|
|
27
|
+
var deletedRange = __assign({}, selection.range);
|
|
28
|
+
var sheetName = (_a = getSheetName === null || getSheetName === void 0 ? void 0 : getSheetName(sheetId)) !== null && _a !== void 0 ? _a : "";
|
|
17
29
|
enqueueStructureChange === null || enqueueStructureChange === void 0 ? void 0 : enqueueStructureChange({
|
|
18
30
|
kind: "delete-cells-shift-up",
|
|
19
31
|
sheetId: sheetId,
|
|
20
|
-
startRowIndex:
|
|
21
|
-
endRowIndex:
|
|
22
|
-
startColumnIndex:
|
|
23
|
-
endColumnIndex:
|
|
32
|
+
startRowIndex: r1,
|
|
33
|
+
endRowIndex: r2,
|
|
34
|
+
startColumnIndex: c1,
|
|
35
|
+
endColumnIndex: c2,
|
|
24
36
|
rowCount: rowCount,
|
|
25
37
|
});
|
|
26
|
-
// Update merges on sheet rows
|
|
38
|
+
// Update merges on sheet rows — merges wholly inside the deleted block go with it; merges
|
|
39
|
+
// wholly inside the shifted columns below it ride up.
|
|
27
40
|
onChangeSheets === null || onChangeSheets === void 0 ? void 0 : onChangeSheets(function (prevSheets) {
|
|
28
41
|
var _a = __read(produceWithPatches(prevSheets, function (draft) {
|
|
29
42
|
var sheet = draft.find(function (s) { return s.sheetId === sheetId; });
|
|
30
43
|
if (sheet === null || sheet === void 0 ? void 0 : sheet.merges) {
|
|
31
|
-
|
|
32
|
-
sheet.merges = moveMergedCells(sheet.merges, "row-remove", rowIndex);
|
|
33
|
-
}
|
|
44
|
+
sheet.merges = shiftMergesInBand(sheet.merges, "row", r1, count, false, c1, c2);
|
|
34
45
|
}
|
|
35
46
|
}), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
|
|
36
47
|
saveHistory({ sheets: { patches: patches, inversePatches: inversePatches } });
|
|
37
48
|
return nextState;
|
|
38
49
|
});
|
|
50
|
+
// Tables: one wholly inside the deleted block is deleted with it (TBL-06); one wholly inside
|
|
51
|
+
// the shifted columns below the block rides up. A partial cover was refused by the hook.
|
|
52
|
+
onChangeTables === null || onChangeTables === void 0 ? void 0 : onChangeTables(function (prevTables) {
|
|
53
|
+
var _a = __read(produceWithPatches(prevTables, function (draft) {
|
|
54
|
+
for (var idx = draft.length - 1; idx >= 0; idx--) {
|
|
55
|
+
var table = draft[idx];
|
|
56
|
+
if (table.sheetId !== sheetId)
|
|
57
|
+
continue;
|
|
58
|
+
if (isRangeInsideBlock(deletedRange, table.range)) {
|
|
59
|
+
draft.splice(idx, 1);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (isRangeInsideBand(table.range, band) &&
|
|
63
|
+
table.range.startRowIndex > r2) {
|
|
64
|
+
table.range.startRowIndex -= count;
|
|
65
|
+
table.range.endRowIndex -= count;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
|
|
69
|
+
saveHistory({ tables: { patches: patches, inversePatches: inversePatches } });
|
|
70
|
+
return nextState;
|
|
71
|
+
});
|
|
39
72
|
// Update citations - delete if overlapping, shift back if after
|
|
40
73
|
onChangeCitations === null || onChangeCitations === void 0 ? void 0 : onChangeCitations(function (prevCitations) {
|
|
41
74
|
var _a = __read(produceWithPatches(prevCitations, function (draft) {
|
|
42
|
-
var deleteRowStart = selection.range.startRowIndex;
|
|
43
|
-
var deleteRowEnd = selection.range.endRowIndex;
|
|
44
|
-
var deleteColStart = selection.range.startColumnIndex;
|
|
45
|
-
var deleteColEnd = selection.range.endColumnIndex;
|
|
46
|
-
var shiftAmount = deleteRowEnd - deleteRowStart + 1;
|
|
47
75
|
for (var idx = draft.length - 1; idx >= 0; idx--) {
|
|
48
76
|
var citation = draft[idx];
|
|
49
77
|
if (citation.range.sheetId !== sheetId)
|
|
50
78
|
continue;
|
|
51
|
-
var colsOverlap = !(citation.range.endColumnIndex <
|
|
79
|
+
var colsOverlap = !(citation.range.endColumnIndex < c1 ||
|
|
80
|
+
citation.range.startColumnIndex > c2);
|
|
52
81
|
if (colsOverlap) {
|
|
53
|
-
var rowsOverlap = !(citation.range.endRowIndex <
|
|
82
|
+
var rowsOverlap = !(citation.range.endRowIndex < r1 ||
|
|
83
|
+
citation.range.startRowIndex > r2);
|
|
54
84
|
if (rowsOverlap) {
|
|
55
85
|
draft.splice(idx, 1);
|
|
56
86
|
}
|
|
57
|
-
else if (citation.range.startRowIndex >
|
|
58
|
-
citation.range.startRowIndex -=
|
|
59
|
-
citation.range.endRowIndex -=
|
|
87
|
+
else if (citation.range.startRowIndex > r2) {
|
|
88
|
+
citation.range.startRowIndex -= count;
|
|
89
|
+
citation.range.endRowIndex -= count;
|
|
60
90
|
}
|
|
61
91
|
}
|
|
62
92
|
}
|
|
@@ -68,72 +98,124 @@ export var deleteCellsShiftUp = function (_a) {
|
|
|
68
98
|
onChangeSheetData === null || onChangeSheetData === void 0 ? void 0 : onChangeSheetData(function (prevSheetData) {
|
|
69
99
|
var _a = __read(produceWithPatches(prevSheetData, function (draft) {
|
|
70
100
|
var e_1, _a;
|
|
71
|
-
var _b, _c, _d, _e;
|
|
101
|
+
var _b, _c, _d, _e, _f, _g, _h;
|
|
72
102
|
var movedKeys = new Set();
|
|
73
103
|
var totalRows = (_c = (_b = draft[sheetId]) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
|
|
74
|
-
//
|
|
75
|
-
var
|
|
76
|
-
startRowIndex:
|
|
77
|
-
endRowIndex: totalRows,
|
|
78
|
-
startColumnIndex:
|
|
79
|
-
endColumnIndex:
|
|
104
|
+
// The cells that actually move: everything BELOW the deleted block in its columns.
|
|
105
|
+
var movingRange = {
|
|
106
|
+
startRowIndex: r2 + 1,
|
|
107
|
+
endRowIndex: Math.max(totalRows, r2 + 1),
|
|
108
|
+
startColumnIndex: c1,
|
|
109
|
+
endColumnIndex: c2,
|
|
80
110
|
};
|
|
111
|
+
// Dependents of the deleted block AND of the moving cells, each processed once.
|
|
81
112
|
var dependents = collectUniqueDependentsForRange({
|
|
82
113
|
draft: draft,
|
|
83
114
|
sheetId: sheetId,
|
|
84
|
-
sourceRange:
|
|
115
|
+
sourceRange: {
|
|
116
|
+
startRowIndex: r1,
|
|
117
|
+
endRowIndex: Math.max(totalRows, r2),
|
|
118
|
+
startColumnIndex: c1,
|
|
119
|
+
endColumnIndex: c2,
|
|
120
|
+
},
|
|
85
121
|
getDependents: getDependents,
|
|
86
122
|
});
|
|
123
|
+
// Contract ranges the block partially covers, then re-base: a range wholly inside the
|
|
124
|
+
// block is left to `moveFormulaAtPosition`, which turns it into `#REF!`.
|
|
125
|
+
var sheetCell = new SheetCell();
|
|
126
|
+
var contractAt = function (pos) {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
if (pos.sheetId !== sheetId)
|
|
129
|
+
return;
|
|
130
|
+
var currentSheet = createSheetDraft(draft, sheetId, pos.rowIndex);
|
|
131
|
+
var cellData = (_b = (_a = currentSheet[pos.rowIndex]) === null || _a === void 0 ? void 0 : _a.values) === null || _b === void 0 ? void 0 : _b[pos.columnIndex];
|
|
132
|
+
sheetCell.assign(sheetId, { rowIndex: pos.rowIndex, columnIndex: pos.columnIndex }, cellData, { locale: locale, cellXfsRegistry: cellXfsRegistry, sharedStringRegistry: sharedStringRegistry });
|
|
133
|
+
var formulaValue = sheetCell.formula;
|
|
134
|
+
if (!formulaValue)
|
|
135
|
+
return;
|
|
136
|
+
var contracted = contractRangesInFormula(formulaValue, r1, count, "row", sheetName, { bandSpan: { startIndex: c1, endIndex: c2 } });
|
|
137
|
+
if (!contracted || contracted === formulaValue)
|
|
138
|
+
return;
|
|
139
|
+
sheetCell.setFormulaValue(contracted, false);
|
|
140
|
+
currentSheet[pos.rowIndex].values[pos.columnIndex] =
|
|
141
|
+
sheetCell.getCellData();
|
|
142
|
+
};
|
|
143
|
+
var rebaseAt = function (pos) {
|
|
144
|
+
var insideBlock = pos.sheetId === sheetId &&
|
|
145
|
+
pos.rowIndex >= r1 &&
|
|
146
|
+
pos.rowIndex <= r2 &&
|
|
147
|
+
pos.columnIndex >= c1 &&
|
|
148
|
+
pos.columnIndex <= c2;
|
|
149
|
+
if (insideBlock)
|
|
150
|
+
return;
|
|
151
|
+
var moves = pos.sheetId === sheetId &&
|
|
152
|
+
pos.rowIndex > r2 &&
|
|
153
|
+
pos.columnIndex >= c1 &&
|
|
154
|
+
pos.columnIndex <= c2;
|
|
155
|
+
contractAt(pos);
|
|
156
|
+
moveFormulaAtPosition({
|
|
157
|
+
draft: draft,
|
|
158
|
+
position: pos,
|
|
159
|
+
activeSheetName: getSheetName === null || getSheetName === void 0 ? void 0 : getSheetName(pos.sheetId),
|
|
160
|
+
enqueueCalculation: enqueueCalculation,
|
|
161
|
+
enqueueGraphOperation: enqueueGraphOperation,
|
|
162
|
+
recalcCells: recalcCells,
|
|
163
|
+
movedKeys: movedKeys,
|
|
164
|
+
rowDelta: -count,
|
|
165
|
+
columnDelta: 0,
|
|
166
|
+
destinationPosition: {
|
|
167
|
+
rowIndex: moves ? pos.rowIndex - count : pos.rowIndex,
|
|
168
|
+
columnIndex: pos.columnIndex,
|
|
169
|
+
},
|
|
170
|
+
sourceRange: movingRange,
|
|
171
|
+
deletedRange: deletedRange,
|
|
172
|
+
locale: locale,
|
|
173
|
+
rowCount: rowCount,
|
|
174
|
+
columnCount: columnCount,
|
|
175
|
+
cellXfsRegistry: cellXfsRegistry,
|
|
176
|
+
sharedStringRegistry: sharedStringRegistry,
|
|
177
|
+
});
|
|
178
|
+
};
|
|
87
179
|
try {
|
|
88
|
-
for (var
|
|
89
|
-
var pos =
|
|
90
|
-
|
|
91
|
-
draft: draft,
|
|
92
|
-
position: pos,
|
|
93
|
-
enqueueCalculation: enqueueCalculation,
|
|
94
|
-
enqueueGraphOperation: enqueueGraphOperation,
|
|
95
|
-
recalcCells: recalcCells,
|
|
96
|
-
movedKeys: movedKeys,
|
|
97
|
-
rowDelta: -count,
|
|
98
|
-
columnDelta: 0,
|
|
99
|
-
sourceRange: sourceRange,
|
|
100
|
-
locale: locale,
|
|
101
|
-
rowCount: rowCount,
|
|
102
|
-
columnCount: columnCount,
|
|
103
|
-
cellXfsRegistry: cellXfsRegistry,
|
|
104
|
-
sharedStringRegistry: sharedStringRegistry,
|
|
105
|
-
});
|
|
180
|
+
for (var _j = __values(dependents.values()), _k = _j.next(); !_k.done; _k = _j.next()) {
|
|
181
|
+
var pos = _k.value;
|
|
182
|
+
rebaseAt(pos);
|
|
106
183
|
}
|
|
107
184
|
}
|
|
108
185
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
109
186
|
finally {
|
|
110
187
|
try {
|
|
111
|
-
if (
|
|
188
|
+
if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
|
|
112
189
|
}
|
|
113
190
|
finally { if (e_1) throw e_1.error; }
|
|
114
191
|
}
|
|
115
|
-
//
|
|
116
|
-
for (var rowIndex =
|
|
117
|
-
var
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
draft: draft,
|
|
121
|
-
position: { sheetId: sheetId, rowIndex: rowIndex, columnIndex: columnIndex },
|
|
122
|
-
enqueueCalculation: enqueueCalculation,
|
|
123
|
-
enqueueGraphOperation: enqueueGraphOperation,
|
|
124
|
-
recalcCells: recalcCells,
|
|
125
|
-
movedKeys: movedKeys,
|
|
126
|
-
rowDelta: -count,
|
|
127
|
-
columnDelta: 0,
|
|
128
|
-
sourceRange: sourceRange,
|
|
192
|
+
// Formulas inside the deleted block leave the graph with their cells.
|
|
193
|
+
for (var rowIndex = r1; rowIndex <= r2; rowIndex++) {
|
|
194
|
+
for (var columnIndex = c1; columnIndex <= c2; columnIndex++) {
|
|
195
|
+
var cellData = (_f = (_e = (_d = draft[sheetId]) === null || _d === void 0 ? void 0 : _d[rowIndex]) === null || _e === void 0 ? void 0 : _e.values) === null || _f === void 0 ? void 0 : _f[columnIndex];
|
|
196
|
+
sheetCell.assign(sheetId, { rowIndex: rowIndex, columnIndex: columnIndex }, cellData, {
|
|
129
197
|
locale: locale,
|
|
130
|
-
rowCount: rowCount,
|
|
131
|
-
columnCount: columnCount,
|
|
132
|
-
cellXfsRegistry: cellXfsRegistry,
|
|
133
|
-
sharedStringRegistry: sharedStringRegistry,
|
|
134
198
|
});
|
|
199
|
+
if (!sheetCell.isFormula())
|
|
200
|
+
continue;
|
|
201
|
+
var enqueueOperation = sheetCell.ephemeral()
|
|
202
|
+
? enqueueCalculation
|
|
203
|
+
: enqueueGraphOperation;
|
|
204
|
+
enqueueOperation === null || enqueueOperation === void 0 ? void 0 : enqueueOperation({
|
|
205
|
+
type: "remove",
|
|
206
|
+
position: { sheetId: sheetId, rowIndex: rowIndex, columnIndex: columnIndex },
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// Re-base the moving formulas themselves, then shift values up
|
|
211
|
+
for (var rowIndex = r1; rowIndex < totalRows; rowIndex++) {
|
|
212
|
+
var currentSheet = createSheetDraft(draft, sheetId, rowIndex);
|
|
213
|
+
for (var columnIndex = c1; columnIndex <= c2; columnIndex++) {
|
|
214
|
+
if (rowIndex > r2) {
|
|
215
|
+
rebaseAt({ sheetId: sheetId, rowIndex: rowIndex, columnIndex: columnIndex });
|
|
216
|
+
}
|
|
135
217
|
currentSheet[rowIndex].values[columnIndex] =
|
|
136
|
-
(
|
|
218
|
+
(_h = (_g = currentSheet[rowIndex + count]) === null || _g === void 0 ? void 0 : _g.values) === null || _h === void 0 ? void 0 : _h[columnIndex];
|
|
137
219
|
}
|
|
138
220
|
}
|
|
139
221
|
}), 3), nextState = _a[0], patches = _a[1], inversePatches = _a[2];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { CellData, Sheet } from "@rowsncolumns/spreadsheet";
|
|
2
2
|
import type { UseOnDeleteColumnProps } from "../hooks/use-on-delete-column";
|
|
3
|
-
export declare const deleteColumn: <T extends CellData, S extends Sheet>({ rowCount, columnCount, locale, cellXfsRegistry, sharedStringRegistry, getSheetName, getActiveCell, getSelections, getDependents, getGraphNodes, getGraphNodesInSheet, createHistory, enqueueGraphOperation, enqueueCalculation, enqueueStructureChange, onChangeSheetData, onChangeSheets, onChangeTables, onChangeActiveCell, onChangeSelections, onChangeConditionalFormats, onChangeDataValidations, onChangeCitations, onChangePivotTables, }: UseOnDeleteColumnProps<T, S>) => (sheetId: number, columnIndexes: number[]) => void;
|
|
3
|
+
export declare const deleteColumn: <T extends CellData, S extends Sheet>({ rowCount, columnCount, locale, cellXfsRegistry, sharedStringRegistry, getSheetName, getActiveCell, getSelections, getDependents, getGraphNodes, getGraphNodesInSheet, createHistory, enqueueGraphOperation, enqueueCalculation, enqueueStructureChange, onChangeSheetData, onChangeSheets, onChangeTables, onChangeActiveCell, onChangeSelections, onChangeConditionalFormats, onChangeDataValidations, onChangeCitations, onChangePivotTables, tables, getArrayRange, onChangeNamedRanges, onChangeEmbeds, onChangeCharts, onChangeProtectedRanges, }: UseOnDeleteColumnProps<T, S>) => (sheetId: number, columnIndexes: number[]) => void;
|
|
4
4
|
//# sourceMappingURL=delete-column.d.ts.map
|