@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,60 +1,88 @@
|
|
|
1
|
-
import { selectionFromActiveCell } from "@rowsncolumns/utils";
|
|
2
1
|
import { produceWithPatches } from "immer";
|
|
3
2
|
import { collectUniqueDependentsForRange, moveFormulaAtPosition, } from "../api/dependency";
|
|
4
|
-
import {
|
|
5
|
-
|
|
3
|
+
import { contractRangesInFormula } from "../api/formula";
|
|
4
|
+
import { createSheetDraft } from "../api/immer-utils";
|
|
5
|
+
import { shiftMergesInBand } from "../api/merges";
|
|
6
|
+
import { isRangeInsideBand, isRangeInsideBlock, resolveShiftSelection, shiftBand, } from "../api/structural-guards";
|
|
7
|
+
import { SheetCell } from "../sheet-cell";
|
|
8
|
+
/**
|
|
9
|
+
* Delete cells ▸ Shift cells left (SHF-04) — the horizontal twin of `deleteCellsShiftUp`: only the
|
|
10
|
+
* selection's rows move, the selected block is removed and every cell to its right slides left by
|
|
11
|
+
* the block's width. A reference to a deleted cell becomes `#REF!`; one to a cell that slid left
|
|
12
|
+
* follows it; a range entirely inside the block's rows that the block partially covers contracts.
|
|
13
|
+
* Refusals (torn merge/table/array) are decided by the hook before this runs.
|
|
14
|
+
*/
|
|
15
|
+
export const deleteCellsShiftLeft = ({ rowCount, columnCount, locale, cellXfsRegistry, sharedStringRegistry, getActiveCell, getSelections, getDependents, getSheetName, createHistory, enqueueGraphOperation, enqueueCalculation, enqueueStructureChange, onChangeSheetData, onChangeSheets, onChangeTables, onChangeCitations, }) => {
|
|
6
16
|
return (sheetId, activeCell, selections) => {
|
|
7
17
|
const saveHistory = createHistory();
|
|
8
18
|
const recalcCells = new Map();
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
19
|
+
const selection = resolveShiftSelection(activeCell, selections);
|
|
20
|
+
const { startRowIndex: r1, endRowIndex: r2, startColumnIndex: c1, endColumnIndex: c2, } = selection.range;
|
|
21
|
+
const count = c2 - c1 + 1;
|
|
22
|
+
const band = shiftBand("left", selection.range);
|
|
23
|
+
const deletedRange = { ...selection.range };
|
|
24
|
+
const sheetName = getSheetName?.(sheetId) ?? "";
|
|
15
25
|
enqueueStructureChange?.({
|
|
16
26
|
kind: "delete-cells-shift-left",
|
|
17
27
|
sheetId,
|
|
18
|
-
startRowIndex:
|
|
19
|
-
endRowIndex:
|
|
20
|
-
startColumnIndex:
|
|
21
|
-
endColumnIndex:
|
|
28
|
+
startRowIndex: r1,
|
|
29
|
+
endRowIndex: r2,
|
|
30
|
+
startColumnIndex: c1,
|
|
31
|
+
endColumnIndex: c2,
|
|
22
32
|
columnCount,
|
|
23
33
|
});
|
|
24
|
-
// Update merges on sheet
|
|
34
|
+
// Update merges on sheet — merges wholly inside the deleted block go with it; merges wholly
|
|
35
|
+
// inside the shifted rows right of it ride left.
|
|
25
36
|
onChangeSheets?.((prevSheets) => {
|
|
26
37
|
const [nextState, patches, inversePatches] = produceWithPatches(prevSheets, (draft) => {
|
|
27
38
|
const sheet = draft.find((s) => s.sheetId === sheetId);
|
|
28
39
|
if (sheet?.merges) {
|
|
29
|
-
|
|
30
|
-
sheet.merges = moveMergedCells(sheet.merges, "column-remove", columnIndex);
|
|
31
|
-
}
|
|
40
|
+
sheet.merges = shiftMergesInBand(sheet.merges, "column", c1, count, false, r1, r2);
|
|
32
41
|
}
|
|
33
42
|
});
|
|
34
43
|
saveHistory({ sheets: { patches, inversePatches } });
|
|
35
44
|
return nextState;
|
|
36
45
|
});
|
|
46
|
+
// Tables: one wholly inside the deleted block is deleted with it; one wholly inside the
|
|
47
|
+
// shifted rows right of the block rides left. A partial cover was refused by the hook.
|
|
48
|
+
onChangeTables?.((prevTables) => {
|
|
49
|
+
const [nextState, patches, inversePatches] = produceWithPatches(prevTables, (draft) => {
|
|
50
|
+
for (let idx = draft.length - 1; idx >= 0; idx--) {
|
|
51
|
+
const table = draft[idx];
|
|
52
|
+
if (table.sheetId !== sheetId)
|
|
53
|
+
continue;
|
|
54
|
+
if (isRangeInsideBlock(deletedRange, table.range)) {
|
|
55
|
+
draft.splice(idx, 1);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (isRangeInsideBand(table.range, band) &&
|
|
59
|
+
table.range.startColumnIndex > c2) {
|
|
60
|
+
table.range.startColumnIndex -= count;
|
|
61
|
+
table.range.endColumnIndex -= count;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
saveHistory({ tables: { patches, inversePatches } });
|
|
66
|
+
return nextState;
|
|
67
|
+
});
|
|
37
68
|
// Update citations - delete if overlapping, shift back if after
|
|
38
69
|
onChangeCitations?.((prevCitations) => {
|
|
39
70
|
const [nextState, patches, inversePatches] = produceWithPatches(prevCitations, (draft) => {
|
|
40
|
-
const deleteRowStart = selection.range.startRowIndex;
|
|
41
|
-
const deleteRowEnd = selection.range.endRowIndex;
|
|
42
|
-
const deleteColStart = selection.range.startColumnIndex;
|
|
43
|
-
const deleteColEnd = selection.range.endColumnIndex;
|
|
44
|
-
const shiftAmount = deleteColEnd - deleteColStart + 1;
|
|
45
71
|
for (let idx = draft.length - 1; idx >= 0; idx--) {
|
|
46
72
|
const citation = draft[idx];
|
|
47
73
|
if (citation.range.sheetId !== sheetId)
|
|
48
74
|
continue;
|
|
49
|
-
const rowsOverlap = !(citation.range.endRowIndex <
|
|
75
|
+
const rowsOverlap = !(citation.range.endRowIndex < r1 ||
|
|
76
|
+
citation.range.startRowIndex > r2);
|
|
50
77
|
if (rowsOverlap) {
|
|
51
|
-
const colsOverlap = !(citation.range.endColumnIndex <
|
|
78
|
+
const colsOverlap = !(citation.range.endColumnIndex < c1 ||
|
|
79
|
+
citation.range.startColumnIndex > c2);
|
|
52
80
|
if (colsOverlap) {
|
|
53
81
|
draft.splice(idx, 1);
|
|
54
82
|
}
|
|
55
|
-
else if (citation.range.startColumnIndex >
|
|
56
|
-
citation.range.startColumnIndex -=
|
|
57
|
-
citation.range.endColumnIndex -=
|
|
83
|
+
else if (citation.range.startColumnIndex > c2) {
|
|
84
|
+
citation.range.startColumnIndex -= count;
|
|
85
|
+
citation.range.endColumnIndex -= count;
|
|
58
86
|
}
|
|
59
87
|
}
|
|
60
88
|
}
|
|
@@ -66,65 +94,113 @@ export const deleteCellsShiftLeft = ({ rowCount, columnCount, locale, cellXfsReg
|
|
|
66
94
|
onChangeSheetData?.((prevSheetData) => {
|
|
67
95
|
const [nextState, patches, inversePatches] = produceWithPatches(prevSheetData, (draft) => {
|
|
68
96
|
const movedKeys = new Set();
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
97
|
+
let totalColumns = Math.max(columnCount, c2 + 1);
|
|
98
|
+
for (let rowIndex = r1; rowIndex <= r2; rowIndex++) {
|
|
99
|
+
totalColumns = Math.max(totalColumns, draft[sheetId]?.[rowIndex]?.values?.length ?? 0);
|
|
100
|
+
}
|
|
101
|
+
// The cells that actually move: everything RIGHT of the deleted block in its rows.
|
|
102
|
+
const movingRange = {
|
|
103
|
+
startRowIndex: r1,
|
|
104
|
+
endRowIndex: r2,
|
|
105
|
+
startColumnIndex: c2 + 1,
|
|
106
|
+
endColumnIndex: totalColumns,
|
|
75
107
|
};
|
|
76
|
-
//
|
|
108
|
+
// Dependents of the deleted block AND of the moving cells, each processed once.
|
|
77
109
|
const dependents = collectUniqueDependentsForRange({
|
|
78
110
|
draft,
|
|
79
111
|
sheetId,
|
|
80
|
-
sourceRange
|
|
112
|
+
sourceRange: {
|
|
113
|
+
startRowIndex: r1,
|
|
114
|
+
endRowIndex: r2,
|
|
115
|
+
startColumnIndex: c1,
|
|
116
|
+
endColumnIndex: totalColumns,
|
|
117
|
+
},
|
|
81
118
|
getDependents,
|
|
82
119
|
});
|
|
83
|
-
|
|
84
|
-
|
|
120
|
+
const sheetCell = new SheetCell();
|
|
121
|
+
const contractAt = (pos) => {
|
|
122
|
+
if (pos.sheetId !== sheetId)
|
|
123
|
+
return;
|
|
124
|
+
const currentSheet = createSheetDraft(draft, sheetId, pos.rowIndex);
|
|
125
|
+
const cellData = currentSheet[pos.rowIndex]?.values?.[pos.columnIndex];
|
|
126
|
+
sheetCell.assign(sheetId, { rowIndex: pos.rowIndex, columnIndex: pos.columnIndex }, cellData, { locale, cellXfsRegistry, sharedStringRegistry });
|
|
127
|
+
const formulaValue = sheetCell.formula;
|
|
128
|
+
if (!formulaValue)
|
|
129
|
+
return;
|
|
130
|
+
const contracted = contractRangesInFormula(formulaValue, c1, count, "column", sheetName, { bandSpan: { startIndex: r1, endIndex: r2 } });
|
|
131
|
+
if (!contracted || contracted === formulaValue)
|
|
132
|
+
return;
|
|
133
|
+
sheetCell.setFormulaValue(contracted, false);
|
|
134
|
+
currentSheet[pos.rowIndex].values[pos.columnIndex] =
|
|
135
|
+
sheetCell.getCellData();
|
|
136
|
+
};
|
|
137
|
+
const rebaseAt = (pos) => {
|
|
138
|
+
const insideBlock = pos.sheetId === sheetId &&
|
|
139
|
+
pos.rowIndex >= r1 &&
|
|
140
|
+
pos.rowIndex <= r2 &&
|
|
141
|
+
pos.columnIndex >= c1 &&
|
|
142
|
+
pos.columnIndex <= c2;
|
|
143
|
+
if (insideBlock)
|
|
144
|
+
return;
|
|
145
|
+
const moves = pos.sheetId === sheetId &&
|
|
146
|
+
pos.columnIndex > c2 &&
|
|
147
|
+
pos.rowIndex >= r1 &&
|
|
148
|
+
pos.rowIndex <= r2;
|
|
149
|
+
contractAt(pos);
|
|
85
150
|
moveFormulaAtPosition({
|
|
86
151
|
draft,
|
|
87
152
|
position: pos,
|
|
153
|
+
activeSheetName: getSheetName?.(pos.sheetId),
|
|
88
154
|
enqueueCalculation,
|
|
89
155
|
enqueueGraphOperation,
|
|
90
156
|
recalcCells,
|
|
91
157
|
movedKeys,
|
|
92
158
|
rowDelta: 0,
|
|
93
159
|
columnDelta: -count,
|
|
94
|
-
|
|
160
|
+
destinationPosition: {
|
|
161
|
+
rowIndex: pos.rowIndex,
|
|
162
|
+
columnIndex: moves ? pos.columnIndex - count : pos.columnIndex,
|
|
163
|
+
},
|
|
164
|
+
sourceRange: movingRange,
|
|
165
|
+
deletedRange,
|
|
95
166
|
locale,
|
|
96
167
|
rowCount,
|
|
97
168
|
columnCount,
|
|
98
169
|
cellXfsRegistry,
|
|
99
170
|
sharedStringRegistry,
|
|
100
171
|
});
|
|
172
|
+
};
|
|
173
|
+
for (const pos of dependents.values()) {
|
|
174
|
+
rebaseAt(pos);
|
|
101
175
|
}
|
|
102
|
-
//
|
|
103
|
-
for (let rowIndex =
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
moveFormulaAtPosition({
|
|
108
|
-
draft,
|
|
109
|
-
position: { sheetId, rowIndex, columnIndex },
|
|
110
|
-
enqueueCalculation,
|
|
111
|
-
enqueueGraphOperation,
|
|
112
|
-
recalcCells,
|
|
113
|
-
movedKeys,
|
|
114
|
-
rowDelta: 0,
|
|
115
|
-
columnDelta: -count,
|
|
116
|
-
sourceRange,
|
|
176
|
+
// Formulas inside the deleted block leave the graph with their cells.
|
|
177
|
+
for (let rowIndex = r1; rowIndex <= r2; rowIndex++) {
|
|
178
|
+
for (let columnIndex = c1; columnIndex <= c2; columnIndex++) {
|
|
179
|
+
const cellData = draft[sheetId]?.[rowIndex]?.values?.[columnIndex];
|
|
180
|
+
sheetCell.assign(sheetId, { rowIndex, columnIndex }, cellData, {
|
|
117
181
|
locale,
|
|
118
|
-
rowCount,
|
|
119
|
-
columnCount,
|
|
120
|
-
cellXfsRegistry,
|
|
121
|
-
sharedStringRegistry,
|
|
122
182
|
});
|
|
183
|
+
if (!sheetCell.isFormula())
|
|
184
|
+
continue;
|
|
185
|
+
const enqueueOperation = sheetCell.ephemeral()
|
|
186
|
+
? enqueueCalculation
|
|
187
|
+
: enqueueGraphOperation;
|
|
188
|
+
enqueueOperation?.({
|
|
189
|
+
type: "remove",
|
|
190
|
+
position: { sheetId, rowIndex, columnIndex },
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Re-base the moving formulas themselves
|
|
195
|
+
for (let rowIndex = r1; rowIndex <= r2; rowIndex++) {
|
|
196
|
+
const dataColumnCount = draft[sheetId]?.[rowIndex]?.values?.length ?? 0;
|
|
197
|
+
for (let columnIndex = c2 + 1; columnIndex < dataColumnCount; columnIndex++) {
|
|
198
|
+
rebaseAt({ sheetId, rowIndex, columnIndex });
|
|
123
199
|
}
|
|
124
200
|
}
|
|
125
201
|
// Finally delete the selected cells by splicing from right to left
|
|
126
|
-
for (let rowIndex =
|
|
127
|
-
for (let columnIndex =
|
|
202
|
+
for (let rowIndex = r1; rowIndex <= r2; rowIndex++) {
|
|
203
|
+
for (let columnIndex = c2; columnIndex >= c1; columnIndex--) {
|
|
128
204
|
if (draft[sheetId]?.[rowIndex]?.values) {
|
|
129
205
|
draft[sheetId][rowIndex]?.values?.splice(columnIndex, 1);
|
|
130
206
|
}
|
|
@@ -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,60 +1,89 @@
|
|
|
1
|
-
import { selectionFromActiveCell } from "@rowsncolumns/utils";
|
|
2
1
|
import { produceWithPatches } from "immer";
|
|
3
2
|
import { collectUniqueDependentsForRange, moveFormulaAtPosition, } from "../api/dependency";
|
|
3
|
+
import { contractRangesInFormula } from "../api/formula";
|
|
4
4
|
import { createSheetDraft } from "../api/immer-utils";
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import { shiftMergesInBand } from "../api/merges";
|
|
6
|
+
import { isRangeInsideBand, isRangeInsideBlock, resolveShiftSelection, shiftBand, } from "../api/structural-guards";
|
|
7
|
+
import { SheetCell } from "../sheet-cell";
|
|
8
|
+
/**
|
|
9
|
+
* Delete cells ▸ Shift cells up (SHF-03, SHF-09). Only the selection's columns move: the selected
|
|
10
|
+
* block is removed and every cell below it slides up by the block's height. A reference to a
|
|
11
|
+
* deleted cell (or to a range the block covers entirely) becomes `#REF!` (SHF-09); a reference to a
|
|
12
|
+
* cell that slid up follows it (SHF-03); a range entirely inside the block's columns that the block
|
|
13
|
+
* partially covers contracts by the overlap. Refusals (torn merge/table/array) are decided by the
|
|
14
|
+
* hook via `getShiftCellsRefusal` before this runs.
|
|
15
|
+
*/
|
|
16
|
+
export const deleteCellsShiftUp = ({ rowCount, columnCount, locale, cellXfsRegistry, sharedStringRegistry, getActiveCell, getSelections, getDependents, getSheetName, createHistory, enqueueGraphOperation, enqueueCalculation, enqueueStructureChange, onChangeSheetData, onChangeSheets, onChangeTables, onChangeCitations, }) => {
|
|
7
17
|
return (sheetId, activeCell, selections) => {
|
|
8
18
|
const saveHistory = createHistory();
|
|
9
19
|
const recalcCells = new Map();
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
20
|
+
const selection = resolveShiftSelection(activeCell, selections);
|
|
21
|
+
const { startRowIndex: r1, endRowIndex: r2, startColumnIndex: c1, endColumnIndex: c2, } = selection.range;
|
|
22
|
+
const count = r2 - r1 + 1;
|
|
23
|
+
const band = shiftBand("up", selection.range);
|
|
24
|
+
const deletedRange = { ...selection.range };
|
|
25
|
+
const sheetName = getSheetName?.(sheetId) ?? "";
|
|
15
26
|
enqueueStructureChange?.({
|
|
16
27
|
kind: "delete-cells-shift-up",
|
|
17
28
|
sheetId,
|
|
18
|
-
startRowIndex:
|
|
19
|
-
endRowIndex:
|
|
20
|
-
startColumnIndex:
|
|
21
|
-
endColumnIndex:
|
|
29
|
+
startRowIndex: r1,
|
|
30
|
+
endRowIndex: r2,
|
|
31
|
+
startColumnIndex: c1,
|
|
32
|
+
endColumnIndex: c2,
|
|
22
33
|
rowCount,
|
|
23
34
|
});
|
|
24
|
-
// Update merges on sheet rows
|
|
35
|
+
// Update merges on sheet rows — merges wholly inside the deleted block go with it; merges
|
|
36
|
+
// wholly inside the shifted columns below it ride up.
|
|
25
37
|
onChangeSheets?.((prevSheets) => {
|
|
26
38
|
const [nextState, patches, inversePatches] = produceWithPatches(prevSheets, (draft) => {
|
|
27
39
|
const sheet = draft.find((s) => s.sheetId === sheetId);
|
|
28
40
|
if (sheet?.merges) {
|
|
29
|
-
|
|
30
|
-
sheet.merges = moveMergedCells(sheet.merges, "row-remove", rowIndex);
|
|
31
|
-
}
|
|
41
|
+
sheet.merges = shiftMergesInBand(sheet.merges, "row", r1, count, false, c1, c2);
|
|
32
42
|
}
|
|
33
43
|
});
|
|
34
44
|
saveHistory({ sheets: { patches, inversePatches } });
|
|
35
45
|
return nextState;
|
|
36
46
|
});
|
|
47
|
+
// Tables: one wholly inside the deleted block is deleted with it (TBL-06); one wholly inside
|
|
48
|
+
// the shifted columns below the block rides up. A partial cover was refused by the hook.
|
|
49
|
+
onChangeTables?.((prevTables) => {
|
|
50
|
+
const [nextState, patches, inversePatches] = produceWithPatches(prevTables, (draft) => {
|
|
51
|
+
for (let idx = draft.length - 1; idx >= 0; idx--) {
|
|
52
|
+
const table = draft[idx];
|
|
53
|
+
if (table.sheetId !== sheetId)
|
|
54
|
+
continue;
|
|
55
|
+
if (isRangeInsideBlock(deletedRange, table.range)) {
|
|
56
|
+
draft.splice(idx, 1);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (isRangeInsideBand(table.range, band) &&
|
|
60
|
+
table.range.startRowIndex > r2) {
|
|
61
|
+
table.range.startRowIndex -= count;
|
|
62
|
+
table.range.endRowIndex -= count;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
saveHistory({ tables: { patches, inversePatches } });
|
|
67
|
+
return nextState;
|
|
68
|
+
});
|
|
37
69
|
// Update citations - delete if overlapping, shift back if after
|
|
38
70
|
onChangeCitations?.((prevCitations) => {
|
|
39
71
|
const [nextState, patches, inversePatches] = produceWithPatches(prevCitations, (draft) => {
|
|
40
|
-
const deleteRowStart = selection.range.startRowIndex;
|
|
41
|
-
const deleteRowEnd = selection.range.endRowIndex;
|
|
42
|
-
const deleteColStart = selection.range.startColumnIndex;
|
|
43
|
-
const deleteColEnd = selection.range.endColumnIndex;
|
|
44
|
-
const shiftAmount = deleteRowEnd - deleteRowStart + 1;
|
|
45
72
|
for (let idx = draft.length - 1; idx >= 0; idx--) {
|
|
46
73
|
const citation = draft[idx];
|
|
47
74
|
if (citation.range.sheetId !== sheetId)
|
|
48
75
|
continue;
|
|
49
|
-
const colsOverlap = !(citation.range.endColumnIndex <
|
|
76
|
+
const colsOverlap = !(citation.range.endColumnIndex < c1 ||
|
|
77
|
+
citation.range.startColumnIndex > c2);
|
|
50
78
|
if (colsOverlap) {
|
|
51
|
-
const rowsOverlap = !(citation.range.endRowIndex <
|
|
79
|
+
const rowsOverlap = !(citation.range.endRowIndex < r1 ||
|
|
80
|
+
citation.range.startRowIndex > r2);
|
|
52
81
|
if (rowsOverlap) {
|
|
53
82
|
draft.splice(idx, 1);
|
|
54
83
|
}
|
|
55
|
-
else if (citation.range.startRowIndex >
|
|
56
|
-
citation.range.startRowIndex -=
|
|
57
|
-
citation.range.endRowIndex -=
|
|
84
|
+
else if (citation.range.startRowIndex > r2) {
|
|
85
|
+
citation.range.startRowIndex -= count;
|
|
86
|
+
citation.range.endRowIndex -= count;
|
|
58
87
|
}
|
|
59
88
|
}
|
|
60
89
|
}
|
|
@@ -67,57 +96,108 @@ export const deleteCellsShiftUp = ({ rowCount, columnCount, locale, cellXfsRegis
|
|
|
67
96
|
const [nextState, patches, inversePatches] = produceWithPatches(prevSheetData, (draft) => {
|
|
68
97
|
const movedKeys = new Set();
|
|
69
98
|
const totalRows = draft[sheetId]?.length ?? 0;
|
|
70
|
-
//
|
|
71
|
-
const
|
|
72
|
-
startRowIndex:
|
|
73
|
-
endRowIndex: totalRows,
|
|
74
|
-
startColumnIndex:
|
|
75
|
-
endColumnIndex:
|
|
99
|
+
// The cells that actually move: everything BELOW the deleted block in its columns.
|
|
100
|
+
const movingRange = {
|
|
101
|
+
startRowIndex: r2 + 1,
|
|
102
|
+
endRowIndex: Math.max(totalRows, r2 + 1),
|
|
103
|
+
startColumnIndex: c1,
|
|
104
|
+
endColumnIndex: c2,
|
|
76
105
|
};
|
|
106
|
+
// Dependents of the deleted block AND of the moving cells, each processed once.
|
|
77
107
|
const dependents = collectUniqueDependentsForRange({
|
|
78
108
|
draft,
|
|
79
109
|
sheetId,
|
|
80
|
-
sourceRange
|
|
110
|
+
sourceRange: {
|
|
111
|
+
startRowIndex: r1,
|
|
112
|
+
endRowIndex: Math.max(totalRows, r2),
|
|
113
|
+
startColumnIndex: c1,
|
|
114
|
+
endColumnIndex: c2,
|
|
115
|
+
},
|
|
81
116
|
getDependents,
|
|
82
117
|
});
|
|
83
|
-
|
|
118
|
+
// Contract ranges the block partially covers, then re-base: a range wholly inside the
|
|
119
|
+
// block is left to `moveFormulaAtPosition`, which turns it into `#REF!`.
|
|
120
|
+
const sheetCell = new SheetCell();
|
|
121
|
+
const contractAt = (pos) => {
|
|
122
|
+
if (pos.sheetId !== sheetId)
|
|
123
|
+
return;
|
|
124
|
+
const currentSheet = createSheetDraft(draft, sheetId, pos.rowIndex);
|
|
125
|
+
const cellData = currentSheet[pos.rowIndex]?.values?.[pos.columnIndex];
|
|
126
|
+
sheetCell.assign(sheetId, { rowIndex: pos.rowIndex, columnIndex: pos.columnIndex }, cellData, { locale, cellXfsRegistry, sharedStringRegistry });
|
|
127
|
+
const formulaValue = sheetCell.formula;
|
|
128
|
+
if (!formulaValue)
|
|
129
|
+
return;
|
|
130
|
+
const contracted = contractRangesInFormula(formulaValue, r1, count, "row", sheetName, { bandSpan: { startIndex: c1, endIndex: c2 } });
|
|
131
|
+
if (!contracted || contracted === formulaValue)
|
|
132
|
+
return;
|
|
133
|
+
sheetCell.setFormulaValue(contracted, false);
|
|
134
|
+
currentSheet[pos.rowIndex].values[pos.columnIndex] =
|
|
135
|
+
sheetCell.getCellData();
|
|
136
|
+
};
|
|
137
|
+
const rebaseAt = (pos) => {
|
|
138
|
+
const insideBlock = pos.sheetId === sheetId &&
|
|
139
|
+
pos.rowIndex >= r1 &&
|
|
140
|
+
pos.rowIndex <= r2 &&
|
|
141
|
+
pos.columnIndex >= c1 &&
|
|
142
|
+
pos.columnIndex <= c2;
|
|
143
|
+
if (insideBlock)
|
|
144
|
+
return;
|
|
145
|
+
const moves = pos.sheetId === sheetId &&
|
|
146
|
+
pos.rowIndex > r2 &&
|
|
147
|
+
pos.columnIndex >= c1 &&
|
|
148
|
+
pos.columnIndex <= c2;
|
|
149
|
+
contractAt(pos);
|
|
84
150
|
moveFormulaAtPosition({
|
|
85
151
|
draft,
|
|
86
152
|
position: pos,
|
|
153
|
+
activeSheetName: getSheetName?.(pos.sheetId),
|
|
87
154
|
enqueueCalculation,
|
|
88
155
|
enqueueGraphOperation,
|
|
89
156
|
recalcCells,
|
|
90
157
|
movedKeys,
|
|
91
158
|
rowDelta: -count,
|
|
92
159
|
columnDelta: 0,
|
|
93
|
-
|
|
160
|
+
destinationPosition: {
|
|
161
|
+
rowIndex: moves ? pos.rowIndex - count : pos.rowIndex,
|
|
162
|
+
columnIndex: pos.columnIndex,
|
|
163
|
+
},
|
|
164
|
+
sourceRange: movingRange,
|
|
165
|
+
deletedRange,
|
|
94
166
|
locale,
|
|
95
167
|
rowCount,
|
|
96
168
|
columnCount,
|
|
97
169
|
cellXfsRegistry,
|
|
98
170
|
sharedStringRegistry,
|
|
99
171
|
});
|
|
172
|
+
};
|
|
173
|
+
for (const pos of dependents.values()) {
|
|
174
|
+
rebaseAt(pos);
|
|
100
175
|
}
|
|
101
|
-
//
|
|
102
|
-
for (let rowIndex =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
draft,
|
|
107
|
-
position: { sheetId, rowIndex, columnIndex },
|
|
108
|
-
enqueueCalculation,
|
|
109
|
-
enqueueGraphOperation,
|
|
110
|
-
recalcCells,
|
|
111
|
-
movedKeys,
|
|
112
|
-
rowDelta: -count,
|
|
113
|
-
columnDelta: 0,
|
|
114
|
-
sourceRange,
|
|
176
|
+
// Formulas inside the deleted block leave the graph with their cells.
|
|
177
|
+
for (let rowIndex = r1; rowIndex <= r2; rowIndex++) {
|
|
178
|
+
for (let columnIndex = c1; columnIndex <= c2; columnIndex++) {
|
|
179
|
+
const cellData = draft[sheetId]?.[rowIndex]?.values?.[columnIndex];
|
|
180
|
+
sheetCell.assign(sheetId, { rowIndex, columnIndex }, cellData, {
|
|
115
181
|
locale,
|
|
116
|
-
rowCount,
|
|
117
|
-
columnCount,
|
|
118
|
-
cellXfsRegistry,
|
|
119
|
-
sharedStringRegistry,
|
|
120
182
|
});
|
|
183
|
+
if (!sheetCell.isFormula())
|
|
184
|
+
continue;
|
|
185
|
+
const enqueueOperation = sheetCell.ephemeral()
|
|
186
|
+
? enqueueCalculation
|
|
187
|
+
: enqueueGraphOperation;
|
|
188
|
+
enqueueOperation?.({
|
|
189
|
+
type: "remove",
|
|
190
|
+
position: { sheetId, rowIndex, columnIndex },
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// Re-base the moving formulas themselves, then shift values up
|
|
195
|
+
for (let rowIndex = r1; rowIndex < totalRows; rowIndex++) {
|
|
196
|
+
const currentSheet = createSheetDraft(draft, sheetId, rowIndex);
|
|
197
|
+
for (let columnIndex = c1; columnIndex <= c2; columnIndex++) {
|
|
198
|
+
if (rowIndex > r2) {
|
|
199
|
+
rebaseAt({ sheetId, rowIndex, columnIndex });
|
|
200
|
+
}
|
|
121
201
|
currentSheet[rowIndex].values[columnIndex] =
|
|
122
202
|
currentSheet[rowIndex + count]?.values?.[columnIndex];
|
|
123
203
|
}
|
|
@@ -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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delete-column.d.ts","sourceRoot":"","sources":["../../../interface/delete-column.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"delete-column.d.ts","sourceRoot":"","sources":["../../../interface/delete-column.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAsBjE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAG5E,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,KAAK,EAAE,0hBA+B/D,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,MACrB,SAAS,MAAM,EAAE,eAAe,MAAM,EAAE,SA8bjD,CAAC"}
|