@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,37 +1,44 @@
|
|
|
1
|
-
import { selectionFromActiveCell } from "@rowsncolumns/utils";
|
|
2
1
|
import { produceWithPatches } from "immer";
|
|
3
|
-
import { processSideEffectDependentCells } from "../api/dependency";
|
|
2
|
+
import { collectUniqueDependentsForRange, processSideEffectDependentCells, } from "../api/dependency";
|
|
3
|
+
import { createSheetCellIdentifier, expandRangesInFormula } from "../api/formula";
|
|
4
4
|
import { cloneCellWithFormatting, createSheetDraft } from "../api/immer-utils";
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import { shiftMergesInBand } from "../api/merges";
|
|
6
|
+
import { isRangeInsideBand, resolveShiftSelection, shiftBand, } from "../api/structural-guards";
|
|
7
|
+
import { SheetCell } from "../sheet-cell";
|
|
8
|
+
/**
|
|
9
|
+
* Insert cells ▸ Shift cells down (SHF-01, SHF-06, SHF-07, SHF-08, FMT-03). Only the selection's
|
|
10
|
+
* columns move: every cell at or below the selection's first row slides down by the selection's
|
|
11
|
+
* height. References that target a shifted cell follow it; a range that lies entirely inside the
|
|
12
|
+
* shifted columns and straddles the insertion row grows by the inserted height (SHF-08); a wider
|
|
13
|
+
* range keeps its address (SHF-07). The vacated cells take the formatting of the cell above the
|
|
14
|
+
* insertion (FMT-03). Refusals (torn merge/table/array, off-sheet push) are decided by the hook via
|
|
15
|
+
* `getShiftCellsRefusal` before this runs.
|
|
16
|
+
*/
|
|
17
|
+
export const insertCellsShiftDown = ({ rowCount, columnCount, locale, cellXfsRegistry, sharedStringRegistry, getActiveCell, getSelections, getDependents, getSheetName, createHistory, enqueueGraphOperation, enqueueCalculation, enqueueStructureChange, onChangeSheetData, onChangeSheets, onChangeTables, onChangeCitations, }) => {
|
|
7
18
|
return (sheetId, activeCell, selections) => {
|
|
8
19
|
const saveHistory = createHistory();
|
|
9
20
|
// We need to track this for history. Precedent cells
|
|
10
21
|
const recalcCells = new Map();
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const selection = finalSelections[finalSelections.length - 1];
|
|
17
|
-
const count = selection.range.endRowIndex - selection.range.startRowIndex + 1;
|
|
22
|
+
const selection = resolveShiftSelection(activeCell, selections);
|
|
23
|
+
const { startRowIndex: r1, endRowIndex: r2, startColumnIndex: c1, endColumnIndex: c2, } = selection.range;
|
|
24
|
+
const count = r2 - r1 + 1;
|
|
25
|
+
const band = shiftBand("down", selection.range);
|
|
26
|
+
const sheetName = getSheetName?.(sheetId) ?? "";
|
|
18
27
|
enqueueStructureChange?.({
|
|
19
28
|
kind: "insert-cells-shift-down",
|
|
20
29
|
sheetId,
|
|
21
|
-
startRowIndex:
|
|
22
|
-
endRowIndex:
|
|
23
|
-
startColumnIndex:
|
|
24
|
-
endColumnIndex:
|
|
30
|
+
startRowIndex: r1,
|
|
31
|
+
endRowIndex: r2,
|
|
32
|
+
startColumnIndex: c1,
|
|
33
|
+
endColumnIndex: c2,
|
|
25
34
|
rowCount,
|
|
26
35
|
});
|
|
27
|
-
// Update sheets
|
|
36
|
+
// Update sheets — merges wholly inside the shifted columns ride down with their cells.
|
|
28
37
|
onChangeSheets?.((prevSheets) => {
|
|
29
38
|
const [nextState, patches, inversePatches] = produceWithPatches(prevSheets, (draft) => {
|
|
30
39
|
const sheet = draft.find((sheet) => sheet.sheetId === sheetId);
|
|
31
|
-
if (sheet) {
|
|
32
|
-
|
|
33
|
-
sheet.merges = moveMergedCells(sheet.merges, "row-insert", rowIndex);
|
|
34
|
-
}
|
|
40
|
+
if (sheet?.merges) {
|
|
41
|
+
sheet.merges = shiftMergesInBand(sheet.merges, "row", r1, count, true, c1, c2);
|
|
35
42
|
}
|
|
36
43
|
});
|
|
37
44
|
// Save history
|
|
@@ -40,27 +47,37 @@ export const insertCellsShiftDown = ({ rowCount, columnCount, locale, cellXfsReg
|
|
|
40
47
|
});
|
|
41
48
|
return nextState;
|
|
42
49
|
});
|
|
50
|
+
// Tables whose columns the band covers entirely move with it (a partial cover was refused).
|
|
51
|
+
onChangeTables?.((prevTables) => {
|
|
52
|
+
const [nextState, patches, inversePatches] = produceWithPatches(prevTables, (draft) => {
|
|
53
|
+
for (const table of draft) {
|
|
54
|
+
if (table.sheetId !== sheetId ||
|
|
55
|
+
!isRangeInsideBand(table.range, band)) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
table.range.startRowIndex += count;
|
|
59
|
+
table.range.endRowIndex += count;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
saveHistory({ tables: { patches, inversePatches } });
|
|
63
|
+
return nextState;
|
|
64
|
+
});
|
|
43
65
|
// Update citations - shift if in affected columns and after insertion row
|
|
44
66
|
onChangeCitations?.((prevCitations) => {
|
|
45
67
|
const [nextState, patches, inversePatches] = produceWithPatches(prevCitations, (draft) => {
|
|
46
|
-
const affectedColStart = selection.range.startColumnIndex;
|
|
47
|
-
const affectedColEnd = selection.range.endColumnIndex;
|
|
48
|
-
const insertRowStart = selection.range.startRowIndex;
|
|
49
|
-
const shiftAmount = selection.range.endRowIndex - selection.range.startRowIndex + 1;
|
|
50
68
|
for (const citation of draft) {
|
|
51
69
|
// Skip citations on other sheets
|
|
52
70
|
if (citation.range.sheetId !== sheetId) {
|
|
53
71
|
continue;
|
|
54
72
|
}
|
|
55
73
|
// Check if citation overlaps with affected columns
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
const colsOverlap = !(citationColEnd < affectedColStart || citationColStart > affectedColEnd);
|
|
74
|
+
const colsOverlap = !(citation.range.endColumnIndex < c1 ||
|
|
75
|
+
citation.range.startColumnIndex > c2);
|
|
59
76
|
if (colsOverlap) {
|
|
60
77
|
// If citation starts at or after the insertion row, shift it down
|
|
61
|
-
if (citation.range.startRowIndex >=
|
|
62
|
-
citation.range.startRowIndex +=
|
|
63
|
-
citation.range.endRowIndex +=
|
|
78
|
+
if (citation.range.startRowIndex >= r1) {
|
|
79
|
+
citation.range.startRowIndex += count;
|
|
80
|
+
citation.range.endRowIndex += count;
|
|
64
81
|
}
|
|
65
82
|
}
|
|
66
83
|
}
|
|
@@ -74,16 +91,31 @@ export const insertCellsShiftDown = ({ rowCount, columnCount, locale, cellXfsReg
|
|
|
74
91
|
onChangeSheetData?.((prevSheetData) => {
|
|
75
92
|
const [nextState, patches, inversePatches] = produceWithPatches(prevSheetData, (draft) => {
|
|
76
93
|
const movedKeys = new Set();
|
|
77
|
-
const totalRows = draft[sheetId]?.length ??
|
|
78
|
-
|
|
94
|
+
const totalRows = Math.max(draft[sheetId]?.length ?? 0, r2 + 1);
|
|
95
|
+
// Everything at or below the insertion row in the band's columns moves down by `count`.
|
|
96
|
+
const sourceRange = {
|
|
97
|
+
startRowIndex: r1,
|
|
98
|
+
endRowIndex: totalRows + count,
|
|
99
|
+
startColumnIndex: c1,
|
|
100
|
+
endColumnIndex: c2,
|
|
101
|
+
};
|
|
102
|
+
// Formulas that read a moving cell — captured before the graph goes stale.
|
|
103
|
+
const dependents = collectUniqueDependentsForRange({
|
|
104
|
+
draft,
|
|
105
|
+
sheetId,
|
|
106
|
+
sourceRange: {
|
|
107
|
+
startRowIndex: r1,
|
|
108
|
+
endRowIndex: totalRows,
|
|
109
|
+
startColumnIndex: c1,
|
|
110
|
+
endColumnIndex: c2,
|
|
111
|
+
},
|
|
112
|
+
getDependents,
|
|
113
|
+
});
|
|
114
|
+
for (let rowIndex = totalRows; rowIndex >= r1; rowIndex--) {
|
|
79
115
|
// We have a for loop
|
|
80
116
|
// to cater for table expansion
|
|
81
117
|
// which will push multiple columns down
|
|
82
|
-
for (let columnIndex =
|
|
83
|
-
const sourceRange = {
|
|
84
|
-
...selection.range,
|
|
85
|
-
endRowIndex: selection.range.endRowIndex + count,
|
|
86
|
-
};
|
|
118
|
+
for (let columnIndex = c1; columnIndex <= c2; columnIndex++) {
|
|
87
119
|
// Process dependents
|
|
88
120
|
processSideEffectDependentCells({
|
|
89
121
|
draft,
|
|
@@ -94,6 +126,7 @@ export const insertCellsShiftDown = ({ rowCount, columnCount, locale, cellXfsReg
|
|
|
94
126
|
enqueueGraphOperation,
|
|
95
127
|
enqueueCalculation,
|
|
96
128
|
getDependents,
|
|
129
|
+
getSheetName,
|
|
97
130
|
recalcCells,
|
|
98
131
|
rowDelta: count,
|
|
99
132
|
sourceRange,
|
|
@@ -104,26 +137,62 @@ export const insertCellsShiftDown = ({ rowCount, columnCount, locale, cellXfsReg
|
|
|
104
137
|
cellXfsRegistry,
|
|
105
138
|
sharedStringRegistry,
|
|
106
139
|
});
|
|
107
|
-
// Skip unaffected cells
|
|
108
|
-
if (rowIndex < selection.range.startRowIndex) {
|
|
109
|
-
continue;
|
|
110
|
-
}
|
|
111
140
|
}
|
|
112
141
|
}
|
|
142
|
+
// SHF-08: a range living entirely inside the band's columns that straddles the insertion
|
|
143
|
+
// row grows by the inserted height (Excel's "insert inside a range expands it"). Runs on
|
|
144
|
+
// the pre-shift positions; the value shift below carries in-band dependents down.
|
|
145
|
+
const sheetCell = new SheetCell();
|
|
146
|
+
for (const pos of dependents.values()) {
|
|
147
|
+
if (pos.sheetId !== sheetId)
|
|
148
|
+
continue;
|
|
149
|
+
const currentSheet = createSheetDraft(draft, sheetId, pos.rowIndex);
|
|
150
|
+
const cellData = currentSheet[pos.rowIndex]?.values?.[pos.columnIndex];
|
|
151
|
+
sheetCell.assign(sheetId, { rowIndex: pos.rowIndex, columnIndex: pos.columnIndex }, cellData, { locale, cellXfsRegistry, sharedStringRegistry });
|
|
152
|
+
const formulaValue = sheetCell.formula;
|
|
153
|
+
if (!formulaValue)
|
|
154
|
+
continue;
|
|
155
|
+
const expanded = expandRangesInFormula(formulaValue, r1, count, "row", sheetName, { bandSpan: { startIndex: c1, endIndex: c2 } });
|
|
156
|
+
if (!expanded || expanded === formulaValue)
|
|
157
|
+
continue;
|
|
158
|
+
sheetCell.setFormulaValue(expanded, false);
|
|
159
|
+
currentSheet[pos.rowIndex].values[pos.columnIndex] =
|
|
160
|
+
sheetCell.getCellData();
|
|
161
|
+
const movesWithBand = pos.rowIndex >= r1 && pos.columnIndex >= c1 && pos.columnIndex <= c2;
|
|
162
|
+
const finalPosition = {
|
|
163
|
+
sheetId,
|
|
164
|
+
rowIndex: movesWithBand ? pos.rowIndex + count : pos.rowIndex,
|
|
165
|
+
columnIndex: pos.columnIndex,
|
|
166
|
+
};
|
|
167
|
+
const enqueueOperation = sheetCell.ephemeral()
|
|
168
|
+
? enqueueCalculation
|
|
169
|
+
: enqueueGraphOperation;
|
|
170
|
+
enqueueOperation?.({ type: "add", position: finalPosition });
|
|
171
|
+
enqueueCalculation?.({
|
|
172
|
+
type: "dirty",
|
|
173
|
+
position: finalPosition,
|
|
174
|
+
force: true,
|
|
175
|
+
});
|
|
176
|
+
recalcCells.set(createSheetCellIdentifier(sheetId, finalPosition.rowIndex, finalPosition.columnIndex), finalPosition);
|
|
177
|
+
}
|
|
113
178
|
// Update values
|
|
114
|
-
for (let rowIndex = totalRows + count; rowIndex >
|
|
179
|
+
for (let rowIndex = totalRows + count; rowIndex > r1; rowIndex--) {
|
|
115
180
|
const currentSheet = createSheetDraft(draft, sheetId, rowIndex);
|
|
116
|
-
for (let columnIndex =
|
|
181
|
+
for (let columnIndex = c2; columnIndex >= c1; columnIndex--) {
|
|
117
182
|
const previousValue = currentSheet[rowIndex - count]?.values?.[columnIndex];
|
|
118
183
|
currentSheet[rowIndex].values[columnIndex] = previousValue;
|
|
119
184
|
}
|
|
120
185
|
}
|
|
121
|
-
//
|
|
122
|
-
|
|
186
|
+
// FMT-03: the inserted cells take the formatting of the cell directly ABOVE the
|
|
187
|
+
// insertion; at row 1 there is none, so they keep the displaced cell's formatting.
|
|
188
|
+
for (let rowIndex = r1; rowIndex <= r2; rowIndex++) {
|
|
123
189
|
const currentSheet = createSheetDraft(draft, sheetId, rowIndex);
|
|
124
|
-
for (let columnIndex =
|
|
190
|
+
for (let columnIndex = c2; columnIndex >= c1; columnIndex--) {
|
|
191
|
+
const formatSource = r1 > 1
|
|
192
|
+
? currentSheet[r1 - 1]?.values?.[columnIndex]
|
|
193
|
+
: currentSheet[rowIndex].values[columnIndex];
|
|
125
194
|
currentSheet[rowIndex].values[columnIndex] =
|
|
126
|
-
cloneCellWithFormatting(
|
|
195
|
+
cloneCellWithFormatting(formatSource);
|
|
127
196
|
}
|
|
128
197
|
}
|
|
129
198
|
});
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import type { CellData, CellInterface, SelectionArea } from "@rowsncolumns/common-types";
|
|
2
2
|
import type { SelectionAttributes, Sheet } from "@rowsncolumns/spreadsheet";
|
|
3
3
|
import type { UseOnInsertCellsShiftRight } from "../hooks/use-on-insert-cells-shift-right";
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Insert cells ▸ Shift cells right (SHF-02, FMT-04) — the horizontal twin of
|
|
6
|
+
* `insertCellsShiftDown`: only the selection's rows move, every cell at or right of the selection's
|
|
7
|
+
* first column slides right by the selection's width. References follow shifted cells; a range
|
|
8
|
+
* entirely inside the shifted rows that straddles the insertion column widens (SHF-08 analog);
|
|
9
|
+
* the vacated cells take the formatting of the cell to the LEFT of the insertion (FMT-04). Refusals
|
|
10
|
+
* (torn merge/table/array, a non-blank cell pushed past `columnCount` — SHF-10) are decided by the
|
|
11
|
+
* hook before this runs.
|
|
12
|
+
*/
|
|
13
|
+
export declare const insertCellsShiftRight: <T extends CellData, S extends Sheet>({ rowCount, columnCount, locale, cellXfsRegistry, sharedStringRegistry, getActiveCell, getSelections, getDependents, getSheetName, createHistory, enqueueGraphOperation, enqueueCalculation, enqueueStructureChange, onChangeSheetData, onChangeSheets, onChangeTables, onChangeCitations, }: UseOnInsertCellsShiftRight<T, S>) => (sheetId: number, activeCell: CellInterface, selections: SelectionArea<SelectionAttributes>[]) => void;
|
|
5
14
|
//# sourceMappingURL=insert-cells-shift-right.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insert-cells-shift-right.d.ts","sourceRoot":"","sources":["../../../interface/insert-cells-shift-right.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,aAAa,EAEb,aAAa,EACd,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"insert-cells-shift-right.d.ts","sourceRoot":"","sources":["../../../interface/insert-cells-shift-right.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,aAAa,EAEb,aAAa,EACd,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAgB5E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AAI3F;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,GAAI,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,KAAK,EAAE,8RAkBxE,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAC,MAE/B,SAAS,MAAM,EACf,YAAY,aAAa,EACzB,YAAY,aAAa,CAAC,mBAAmB,CAAC,EAAE,SAqQnD,CAAC"}
|
|
@@ -1,39 +1,45 @@
|
|
|
1
|
-
import { createArrayRange
|
|
1
|
+
import { createArrayRange } from "@rowsncolumns/utils";
|
|
2
2
|
import { produceWithPatches } from "immer";
|
|
3
|
-
import { processSideEffectDependentCells } from "../api/dependency";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
3
|
+
import { collectUniqueDependentsForRange, processSideEffectDependentCells, } from "../api/dependency";
|
|
4
|
+
import { createSheetCellIdentifier, expandRangesInFormula } from "../api/formula";
|
|
5
|
+
import { cloneCellWithFormatting, createSheetDraft } from "../api/immer-utils";
|
|
6
|
+
import { shiftMergesInBand } from "../api/merges";
|
|
7
|
+
import { isRangeInsideBand, resolveShiftSelection, shiftBand, } from "../api/structural-guards";
|
|
8
|
+
import { SheetCell } from "../sheet-cell";
|
|
9
|
+
/**
|
|
10
|
+
* Insert cells ▸ Shift cells right (SHF-02, FMT-04) — the horizontal twin of
|
|
11
|
+
* `insertCellsShiftDown`: only the selection's rows move, every cell at or right of the selection's
|
|
12
|
+
* first column slides right by the selection's width. References follow shifted cells; a range
|
|
13
|
+
* entirely inside the shifted rows that straddles the insertion column widens (SHF-08 analog);
|
|
14
|
+
* the vacated cells take the formatting of the cell to the LEFT of the insertion (FMT-04). Refusals
|
|
15
|
+
* (torn merge/table/array, a non-blank cell pushed past `columnCount` — SHF-10) are decided by the
|
|
16
|
+
* hook before this runs.
|
|
17
|
+
*/
|
|
18
|
+
export const insertCellsShiftRight = ({ rowCount, columnCount, locale, cellXfsRegistry, sharedStringRegistry, getActiveCell, getSelections, getDependents, getSheetName, createHistory, enqueueGraphOperation, enqueueCalculation, enqueueStructureChange, onChangeSheetData, onChangeSheets, onChangeTables, onChangeCitations, }) => {
|
|
7
19
|
return (sheetId, activeCell, selections) => {
|
|
8
20
|
const saveHistory = createHistory();
|
|
9
21
|
// We need to track this for history. Precedent cells
|
|
10
22
|
const recalcCells = new Map();
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const selection = finalSelections[finalSelections.length - 1];
|
|
17
|
-
const count = selection.range.endRowIndex - selection.range.startRowIndex + 1;
|
|
23
|
+
const selection = resolveShiftSelection(activeCell, selections);
|
|
24
|
+
const { startRowIndex: r1, endRowIndex: r2, startColumnIndex: c1, endColumnIndex: c2, } = selection.range;
|
|
25
|
+
const count = c2 - c1 + 1;
|
|
26
|
+
const band = shiftBand("right", selection.range);
|
|
27
|
+
const sheetName = getSheetName?.(sheetId) ?? "";
|
|
18
28
|
enqueueStructureChange?.({
|
|
19
29
|
kind: "insert-cells-shift-right",
|
|
20
30
|
sheetId,
|
|
21
|
-
startRowIndex:
|
|
22
|
-
endRowIndex:
|
|
23
|
-
startColumnIndex:
|
|
24
|
-
endColumnIndex:
|
|
31
|
+
startRowIndex: r1,
|
|
32
|
+
endRowIndex: r2,
|
|
33
|
+
startColumnIndex: c1,
|
|
34
|
+
endColumnIndex: c2,
|
|
25
35
|
columnCount,
|
|
26
36
|
});
|
|
27
|
-
// Update sheets
|
|
37
|
+
// Update sheets — merges wholly inside the shifted rows ride right with their cells.
|
|
28
38
|
onChangeSheets?.((prevSheets) => {
|
|
29
39
|
const [nextState, patches, inversePatches] = produceWithPatches(prevSheets, (draft) => {
|
|
30
40
|
const sheet = draft.find((sheet) => sheet.sheetId === sheetId);
|
|
31
|
-
if (sheet) {
|
|
32
|
-
|
|
33
|
-
if (sheet.merges) {
|
|
34
|
-
sheet.merges = moveMergedCells(sheet.merges, "column-insert", columnIndex);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
41
|
+
if (sheet?.merges) {
|
|
42
|
+
sheet.merges = shiftMergesInBand(sheet.merges, "column", c1, count, true, r1, r2);
|
|
37
43
|
}
|
|
38
44
|
});
|
|
39
45
|
// Save history
|
|
@@ -42,30 +48,37 @@ export const insertCellsShiftRight = ({ rowCount, columnCount, locale, cellXfsRe
|
|
|
42
48
|
});
|
|
43
49
|
return nextState;
|
|
44
50
|
});
|
|
51
|
+
// Tables whose rows the band covers entirely move with it (a partial cover was refused).
|
|
52
|
+
onChangeTables?.((prevTables) => {
|
|
53
|
+
const [nextState, patches, inversePatches] = produceWithPatches(prevTables, (draft) => {
|
|
54
|
+
for (const table of draft) {
|
|
55
|
+
if (table.sheetId !== sheetId ||
|
|
56
|
+
!isRangeInsideBand(table.range, band)) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
table.range.startColumnIndex += count;
|
|
60
|
+
table.range.endColumnIndex += count;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
saveHistory({ tables: { patches, inversePatches } });
|
|
64
|
+
return nextState;
|
|
65
|
+
});
|
|
45
66
|
// Update citations - shift if in affected rows and after insertion column
|
|
46
67
|
onChangeCitations?.((prevCitations) => {
|
|
47
68
|
const [nextState, patches, inversePatches] = produceWithPatches(prevCitations, (draft) => {
|
|
48
|
-
const affectedRowStart = selection.range.startRowIndex;
|
|
49
|
-
const affectedRowEnd = selection.range.endRowIndex;
|
|
50
|
-
const insertColumnStart = selection.range.startColumnIndex;
|
|
51
|
-
const shiftAmount = selection.range.endColumnIndex -
|
|
52
|
-
selection.range.startColumnIndex +
|
|
53
|
-
1;
|
|
54
69
|
for (const citation of draft) {
|
|
55
70
|
// Skip citations on other sheets
|
|
56
71
|
if (citation.range.sheetId !== sheetId) {
|
|
57
72
|
continue;
|
|
58
73
|
}
|
|
59
74
|
// Check if citation overlaps with affected rows
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
const rowsOverlap = !(citationRowEnd < affectedRowStart ||
|
|
63
|
-
citationRowStart > affectedRowEnd);
|
|
75
|
+
const rowsOverlap = !(citation.range.endRowIndex < r1 ||
|
|
76
|
+
citation.range.startRowIndex > r2);
|
|
64
77
|
if (rowsOverlap) {
|
|
65
78
|
// If citation starts at or after the insertion column, shift it right
|
|
66
|
-
if (citation.range.startColumnIndex >=
|
|
67
|
-
citation.range.startColumnIndex +=
|
|
68
|
-
citation.range.endColumnIndex +=
|
|
79
|
+
if (citation.range.startColumnIndex >= c1) {
|
|
80
|
+
citation.range.startColumnIndex += count;
|
|
81
|
+
citation.range.endColumnIndex += count;
|
|
69
82
|
}
|
|
70
83
|
}
|
|
71
84
|
}
|
|
@@ -79,13 +92,31 @@ export const insertCellsShiftRight = ({ rowCount, columnCount, locale, cellXfsRe
|
|
|
79
92
|
onChangeSheetData?.((prevSheetData) => {
|
|
80
93
|
const [nextState, patches, inversePatches] = produceWithPatches(prevSheetData, (draft) => {
|
|
81
94
|
const movedKeys = new Set();
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
95
|
+
let totalColumns = Math.max(columnCount, c2 + 1);
|
|
96
|
+
for (let rowIndex = r1; rowIndex <= r2; rowIndex++) {
|
|
97
|
+
totalColumns = Math.max(totalColumns, draft[sheetId]?.[rowIndex]?.values?.length ?? 0);
|
|
98
|
+
}
|
|
99
|
+
// Everything at or right of the insertion column in the band's rows moves by `count`.
|
|
100
|
+
const sourceRange = {
|
|
101
|
+
startRowIndex: r1,
|
|
102
|
+
endRowIndex: r2,
|
|
103
|
+
startColumnIndex: c1,
|
|
104
|
+
endColumnIndex: totalColumns + count,
|
|
105
|
+
};
|
|
106
|
+
// Formulas that read a moving cell — captured before the graph goes stale.
|
|
107
|
+
const dependents = collectUniqueDependentsForRange({
|
|
108
|
+
draft,
|
|
109
|
+
sheetId,
|
|
110
|
+
sourceRange: {
|
|
111
|
+
startRowIndex: r1,
|
|
112
|
+
endRowIndex: r2,
|
|
113
|
+
startColumnIndex: c1,
|
|
114
|
+
endColumnIndex: totalColumns,
|
|
115
|
+
},
|
|
116
|
+
getDependents,
|
|
117
|
+
});
|
|
118
|
+
for (let rowIndex = r1; rowIndex <= r2; rowIndex++) {
|
|
119
|
+
for (let columnIndex = totalColumns; columnIndex >= c1; columnIndex--) {
|
|
89
120
|
// Process dependents
|
|
90
121
|
processSideEffectDependentCells({
|
|
91
122
|
draft,
|
|
@@ -96,6 +127,7 @@ export const insertCellsShiftRight = ({ rowCount, columnCount, locale, cellXfsRe
|
|
|
96
127
|
enqueueGraphOperation,
|
|
97
128
|
enqueueCalculation,
|
|
98
129
|
getDependents,
|
|
130
|
+
getSheetName,
|
|
99
131
|
recalcCells,
|
|
100
132
|
rowDelta: 0,
|
|
101
133
|
sourceRange,
|
|
@@ -108,14 +140,51 @@ export const insertCellsShiftRight = ({ rowCount, columnCount, locale, cellXfsRe
|
|
|
108
140
|
});
|
|
109
141
|
}
|
|
110
142
|
}
|
|
111
|
-
//
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
143
|
+
// SHF-08 analog: a range living entirely inside the band's rows that straddles the
|
|
144
|
+
// insertion column widens by the inserted width. Runs on the pre-shift positions; the
|
|
145
|
+
// splice below carries in-band dependents right.
|
|
146
|
+
const sheetCell = new SheetCell();
|
|
147
|
+
for (const pos of dependents.values()) {
|
|
148
|
+
if (pos.sheetId !== sheetId)
|
|
149
|
+
continue;
|
|
150
|
+
const currentSheet = createSheetDraft(draft, sheetId, pos.rowIndex);
|
|
151
|
+
const cellData = currentSheet[pos.rowIndex]?.values?.[pos.columnIndex];
|
|
152
|
+
sheetCell.assign(sheetId, { rowIndex: pos.rowIndex, columnIndex: pos.columnIndex }, cellData, { locale, cellXfsRegistry, sharedStringRegistry });
|
|
153
|
+
const formulaValue = sheetCell.formula;
|
|
154
|
+
if (!formulaValue)
|
|
155
|
+
continue;
|
|
156
|
+
const expanded = expandRangesInFormula(formulaValue, c1, count, "column", sheetName, { bandSpan: { startIndex: r1, endIndex: r2 } });
|
|
157
|
+
if (!expanded || expanded === formulaValue)
|
|
158
|
+
continue;
|
|
159
|
+
sheetCell.setFormulaValue(expanded, false);
|
|
160
|
+
currentSheet[pos.rowIndex].values[pos.columnIndex] =
|
|
161
|
+
sheetCell.getCellData();
|
|
162
|
+
const movesWithBand = pos.columnIndex >= c1 && pos.rowIndex >= r1 && pos.rowIndex <= r2;
|
|
163
|
+
const finalPosition = {
|
|
164
|
+
sheetId,
|
|
165
|
+
rowIndex: pos.rowIndex,
|
|
166
|
+
columnIndex: movesWithBand
|
|
167
|
+
? pos.columnIndex + count
|
|
168
|
+
: pos.columnIndex,
|
|
169
|
+
};
|
|
170
|
+
const enqueueOperation = sheetCell.ephemeral()
|
|
171
|
+
? enqueueCalculation
|
|
172
|
+
: enqueueGraphOperation;
|
|
173
|
+
enqueueOperation?.({ type: "add", position: finalPosition });
|
|
174
|
+
enqueueCalculation?.({
|
|
175
|
+
type: "dirty",
|
|
176
|
+
position: finalPosition,
|
|
177
|
+
force: true,
|
|
178
|
+
});
|
|
179
|
+
recalcCells.set(createSheetCellIdentifier(sheetId, finalPosition.rowIndex, finalPosition.columnIndex), finalPosition);
|
|
180
|
+
}
|
|
181
|
+
// Splice the inserted cells in. FMT-04: they take the formatting of the cell directly
|
|
182
|
+
// LEFT of the insertion; at column 1 there is none, so they keep the displaced cell's.
|
|
183
|
+
for (let rowIndex = r1; rowIndex <= r2; rowIndex++) {
|
|
184
|
+
const values = draft[sheetId]?.[rowIndex]?.values;
|
|
185
|
+
if (!values)
|
|
186
|
+
continue;
|
|
187
|
+
values.splice(c1, 0, ...createArrayRange(c1, c2).map((columnIndex) => cloneCellWithFormatting(c1 > 1 ? values[c1 - 1] : values[columnIndex])));
|
|
119
188
|
}
|
|
120
189
|
});
|
|
121
190
|
// Save history
|
|
@@ -2,6 +2,6 @@ import { Direction } from "@rowsncolumns/common-types";
|
|
|
2
2
|
import type { CellData, Sheet, TableView } from "@rowsncolumns/spreadsheet";
|
|
3
3
|
import type { UseOnInsertColumnProps } from "../hooks/use-on-insert-column";
|
|
4
4
|
import type { UseOnTableProps } from "../hooks/use-on-table";
|
|
5
|
-
export declare const insertColumn: <T extends CellData, S extends Sheet>({ rowCount, columnCount, locale, tables, cellXfsRegistry, sharedStringRegistry, getSheetName, getDependents, getGraphNodes, getGraphNodesInSheet, getActiveCell, getSelections, createHistory, enqueueGraphOperation, enqueueCalculation, enqueueStructureChange, onChangeSheetData, onChangeSheets, onChangeTables, onChangeDataValidations, onChangeConditionalFormats, onChangeCitations, onChangePivotTables, generatedNames, }: UseOnInsertColumnProps<T, S>) => (sheetId: number, referenceColumnIndex: number, numColumns?: number) => void;
|
|
5
|
+
export declare const insertColumn: <T extends CellData, S extends Sheet>({ rowCount, columnCount, locale, maxColumnCount, tables, cellXfsRegistry, sharedStringRegistry, getSheetName, getDependents, getGraphNodes, getGraphNodesInSheet, getActiveCell, getSelections, createHistory, enqueueGraphOperation, enqueueCalculation, enqueueStructureChange, onChangeSheetData, onChangeSheets, onChangeTables, onChangeDataValidations, onChangeConditionalFormats, onChangeCitations, onChangePivotTables, onChangeNamedRanges, onChangeEmbeds, onChangeCharts, onChangeProtectedRanges, generatedNames, }: UseOnInsertColumnProps<T, S>) => (sheetId: number, referenceColumnIndex: number, numColumns?: number) => void;
|
|
6
6
|
export declare const insertTableColumn: <T extends CellData, S extends Sheet>({ tables, columnCount, rowCount, locale, cellXfsRegistry, sharedStringRegistry, getSheetName, createHistory, onChangeTables, onChangeSheets, onChangeSheetData, enqueueCalculation, enqueueStructureChange, enqueueGraphOperation, getDependents, generatedNames, }: Pick<UseOnTableProps<T, S>, "tables" | "columnCount" | "rowCount" | "locale" | "cellXfsRegistry" | "sharedStringRegistry" | "createHistory" | "onChangeTables" | "onChangeSheets" | "onChangeSheetData" | "enqueueCalculation" | "enqueueStructureChange" | "enqueueGraphOperation" | "getDependents" | "getSheetName" | "generatedNames">) => (tableView: TableView, dimensionIndex: number, direction: Direction.Left | Direction.Right) => void;
|
|
7
7
|
//# sourceMappingURL=insert-column.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insert-column.d.ts","sourceRoot":"","sources":["../../../interface/insert-column.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"insert-column.d.ts","sourceRoot":"","sources":["../../../interface/insert-column.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAkC5E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAI7D,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,KAAK,EAAE,mgBA8B/D,sBAAsB,CAAC,CAAC,EAAE,CAAC,CAAC,MACrB,SAAS,MAAM,EAAE,sBAAsB,MAAM,EAAE,mBAAc,SAoatE,CAAC;AAMF,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,KAAK,EAAE,qQAiBpE,IAAI,CACL,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EACnB,QAAQ,GACR,aAAa,GACb,UAAU,GACV,QAAQ,GACR,iBAAiB,GACjB,sBAAsB,GACtB,eAAe,GACf,gBAAgB,GAChB,gBAAgB,GAChB,mBAAmB,GACnB,oBAAoB,GACpB,wBAAwB,GACxB,uBAAuB,GACvB,eAAe,GACf,cAAc,GACd,gBAAgB,CACnB,MAEG,WAAW,SAAS,EACpB,gBAAgB,MAAM,EACtB,WAAW,SAAS,CAAC,IAAI,GAAG,SAAS,CAAC,KAAK,SA2V9C,CAAC"}
|