@rowsncolumns/spreadsheet-state 29.1.15 → 29.1.17
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/hooks/use-calculation-worker.d.ts.map +1 -1
- package/dist/cjs/hooks/use-calculation-worker.js +26 -2
- package/dist/cjs/hooks/use-calculation.d.ts.map +1 -1
- package/dist/cjs/hooks/use-calculation.js +133 -102
- package/dist/cjs/hooks/use-on-request-create-table.d.ts +3 -3
- package/dist/cjs/hooks/use-on-request-create-table.d.ts.map +1 -1
- package/dist/cjs/hooks/use-on-request-create-table.js +8 -4
- package/dist/cjs/interface/delete-cells.d.ts.map +1 -1
- package/dist/cjs/interface/delete-cells.js +64 -22
- package/dist/cjs/interface/remove-table.d.ts +11 -0
- package/dist/cjs/interface/remove-table.d.ts.map +1 -1
- package/dist/cjs/interface/remove-table.js +71 -40
- package/dist/esm/hooks/use-calculation-worker.d.ts.map +1 -1
- package/dist/esm/hooks/use-calculation-worker.js +26 -2
- package/dist/esm/hooks/use-calculation.d.ts.map +1 -1
- package/dist/esm/hooks/use-calculation.js +30 -5
- package/dist/esm/hooks/use-on-request-create-table.d.ts +3 -3
- package/dist/esm/hooks/use-on-request-create-table.d.ts.map +1 -1
- package/dist/esm/hooks/use-on-request-create-table.js +8 -4
- package/dist/esm/interface/delete-cells.d.ts.map +1 -1
- package/dist/esm/interface/delete-cells.js +31 -6
- package/dist/esm/interface/remove-table.d.ts +11 -0
- package/dist/esm/interface/remove-table.d.ts.map +1 -1
- package/dist/esm/interface/remove-table.js +49 -33
- package/package.json +6 -6
|
@@ -4,6 +4,7 @@ import { produceWithPatches } from "immer";
|
|
|
4
4
|
import { createSheetCellIdentifier } from "../api/formula";
|
|
5
5
|
import { createSheetDraft } from "../api/immer-utils";
|
|
6
6
|
import { SheetCell } from "../sheet-cell";
|
|
7
|
+
import { releaseTableFilterRows } from "./remove-table";
|
|
7
8
|
import { getTableHeaderRefills } from "./table-utils";
|
|
8
9
|
export const deleteCells = ({ locale, rowCount, cellXfsRegistry, sharedStringRegistry, getDataValidationById, getDependents, getDataRowCount, onChangeSheetData, onChangeSheets, onChangeTables, onChangeCitations, onChangeActiveCell, enqueueCalculation, enqueueStructureChange, createHistory, isArrayFormula, getRowHeight, tables, generatedNames, }) => {
|
|
9
10
|
return (sheetId, cell, selections, clearType = "contents") => {
|
|
@@ -14,13 +15,24 @@ export const deleteCells = ({ locale, rowCount, cellXfsRegistry, sharedStringReg
|
|
|
14
15
|
: selectionFromActiveCell(cell);
|
|
15
16
|
const saveHistory = createHistory();
|
|
16
17
|
const maxRowCount = getDataRowCount();
|
|
17
|
-
//
|
|
18
|
-
//
|
|
19
|
-
//
|
|
18
|
+
// Delete / Clear over a selection that covers a whole table deletes the table (Excel's
|
|
19
|
+
// "select the table and press Delete"): the table, its filter and its style go with the
|
|
20
|
+
// cells, and the structured references into it error as they do for any deleted table
|
|
21
|
+
// (Convert to Range is the path that rewrites them to A1).
|
|
22
|
+
const removedTables = shouldClearContents
|
|
23
|
+
? (tables ?? []).filter((table) => table.sheetId === sheetId &&
|
|
24
|
+
finalSelections.some((selection) => areaInsideArea(table.range, selection.range)))
|
|
25
|
+
: [];
|
|
26
|
+
const keptTables = removedTables.length
|
|
27
|
+
? tables?.filter((table) => !removedTables.includes(table))
|
|
28
|
+
: tables;
|
|
29
|
+
// A table survives Delete / Clear over part of it (Excel): only its cells
|
|
30
|
+
// empty out, and cleared header cells are re-named `ColumnN` so the header
|
|
31
|
+
// row and `columns[]` stay in step.
|
|
20
32
|
const headerRefills = shouldClearContents
|
|
21
33
|
? getTableHeaderRefills({
|
|
22
34
|
sheetId,
|
|
23
|
-
tables,
|
|
35
|
+
tables: keptTables,
|
|
24
36
|
selections: finalSelections,
|
|
25
37
|
generatedNames,
|
|
26
38
|
})
|
|
@@ -133,10 +145,16 @@ export const deleteCells = ({ locale, rowCount, cellXfsRegistry, sharedStringReg
|
|
|
133
145
|
});
|
|
134
146
|
return nextState;
|
|
135
147
|
});
|
|
136
|
-
//
|
|
137
|
-
if (headerRefills.length) {
|
|
148
|
+
// Drop the tables the selection covered, and rename the columns whose header cells were cleared
|
|
149
|
+
if (headerRefills.length || removedTables.length) {
|
|
138
150
|
onChangeTables?.((prevTables) => {
|
|
139
151
|
const [nextState, patches, inversePatches] = produceWithPatches(prevTables, (draft) => {
|
|
152
|
+
for (const removed of removedTables) {
|
|
153
|
+
const tableIndex = draft.findIndex((table) => table.id == removed.id);
|
|
154
|
+
if (tableIndex !== -1) {
|
|
155
|
+
draft.splice(tableIndex, 1);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
140
158
|
for (const { tableId, dimensionIndex, name } of headerRefills) {
|
|
141
159
|
const table = draft.find((table) => table.sheetId === sheetId && table.id === tableId);
|
|
142
160
|
if (!table)
|
|
@@ -156,6 +174,13 @@ export const deleteCells = ({ locale, rowCount, cellXfsRegistry, sharedStringReg
|
|
|
156
174
|
});
|
|
157
175
|
return nextState;
|
|
158
176
|
});
|
|
177
|
+
releaseTableFilterRows({
|
|
178
|
+
tables: removedTables,
|
|
179
|
+
onChangeSheets,
|
|
180
|
+
saveHistory,
|
|
181
|
+
getDependents,
|
|
182
|
+
enqueueCalculation,
|
|
183
|
+
});
|
|
159
184
|
}
|
|
160
185
|
// Update citations - retire citations whose cited cells lose their contents.
|
|
161
186
|
// Clearing formats only leaves the cited values in place, so the citations stay.
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import type { CellData, Sheet, TableView } from "@rowsncolumns/spreadsheet";
|
|
2
2
|
import type { UseOnTableProps } from "../hooks/use-on-table";
|
|
3
3
|
export declare const removeTable: <T extends CellData, S extends Sheet>({ locale, cellXfsRegistry, sharedStringRegistry, getSheetName, onChangeTables, onChangeSheets, onChangeSheetData, createHistory, getDependents, getGraphNodes, getBandedCells, enqueueCalculation, enqueueGraphOperation, }: Pick<UseOnTableProps<T, S>, "locale" | "cellXfsRegistry" | "sharedStringRegistry" | "getSheetName" | "onChangeTables" | "onChangeSheets" | "onChangeSheetData" | "getDependents" | "getGraphNodes" | "getBandedCells" | "enqueueCalculation" | "enqueueGraphOperation" | "createHistory">) => (tableView: TableView) => void;
|
|
4
|
+
/**
|
|
5
|
+
* A removed table's filter goes with it: the rows it hid become visible again, in the history step
|
|
6
|
+
* of the removal (`saveHistory`). Their values did not change, so only the formulas that read
|
|
7
|
+
* visibility — `SUBTOTAL(101…111)` / `AGGREGATE` over those rows — are stale; dirtying the
|
|
8
|
+
* un-hidden cells recalculates exactly those dependents. Shared by Convert to Range
|
|
9
|
+
* (`removeTable`) and Delete over a whole table (`deleteCells`).
|
|
10
|
+
*/
|
|
11
|
+
export declare const releaseTableFilterRows: <T extends CellData, S extends Sheet>({ tables, onChangeSheets, saveHistory, getDependents, enqueueCalculation, }: Pick<UseOnTableProps<T, S>, "onChangeSheets" | "getDependents" | "enqueueCalculation"> & {
|
|
12
|
+
tables: TableView[];
|
|
13
|
+
saveHistory: ReturnType<UseOnTableProps<T, S>["createHistory"]>;
|
|
14
|
+
}) => void;
|
|
4
15
|
//# sourceMappingURL=remove-table.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-table.d.ts","sourceRoot":"","sources":["../../../interface/remove-table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAK5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAI7D,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,KAAK,EAAE,6NAc9D,IAAI,CACL,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EACnB,QAAQ,GACR,iBAAiB,GACjB,sBAAsB,GACtB,cAAc,GACd,gBAAgB,GAChB,gBAAgB,GAChB,mBAAmB,GACnB,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,oBAAoB,GACpB,uBAAuB,GACvB,eAAe,CAClB,MACS,WAAW,SAAS,
|
|
1
|
+
{"version":3,"file":"remove-table.d.ts","sourceRoot":"","sources":["../../../interface/remove-table.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAK5E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAI7D,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,KAAK,EAAE,6NAc9D,IAAI,CACL,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EACnB,QAAQ,GACR,iBAAiB,GACjB,sBAAsB,GACtB,cAAc,GACd,gBAAgB,GAChB,gBAAgB,GAChB,mBAAmB,GACnB,eAAe,GACf,eAAe,GACf,gBAAgB,GAChB,oBAAoB,GACpB,uBAAuB,GACvB,eAAe,CAClB,MACS,WAAW,SAAS,SA0E7B,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,GAAI,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,KAAK,EAAE,6EAMzE,IAAI,CACL,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,EACrB,gBAAgB,GAAG,eAAe,GAAG,oBAAoB,CAC1D,GAAG;IACF,MAAM,EAAE,SAAS,EAAE,CAAC;IACpB,WAAW,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC;CACjE,SAoDA,CAAC"}
|
|
@@ -57,42 +57,58 @@ export const removeTable = ({ locale, cellXfsRegistry, sharedStringRegistry, get
|
|
|
57
57
|
});
|
|
58
58
|
return nextState;
|
|
59
59
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
releaseTableFilterRows({
|
|
61
|
+
tables: [tableView],
|
|
62
|
+
onChangeSheets,
|
|
63
|
+
saveHistory,
|
|
64
|
+
getDependents,
|
|
65
|
+
enqueueCalculation,
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* A removed table's filter goes with it: the rows it hid become visible again, in the history step
|
|
71
|
+
* of the removal (`saveHistory`). Their values did not change, so only the formulas that read
|
|
72
|
+
* visibility — `SUBTOTAL(101…111)` / `AGGREGATE` over those rows — are stale; dirtying the
|
|
73
|
+
* un-hidden cells recalculates exactly those dependents. Shared by Convert to Range
|
|
74
|
+
* (`removeTable`) and Delete over a whole table (`deleteCells`).
|
|
75
|
+
*/
|
|
76
|
+
export const releaseTableFilterRows = ({ tables, onChangeSheets, saveHistory, getDependents, enqueueCalculation, }) => {
|
|
77
|
+
if (!tables.length)
|
|
78
|
+
return;
|
|
79
|
+
const unhiddenRecalcCells = new Map();
|
|
80
|
+
onChangeSheets((prevSheets) => {
|
|
81
|
+
const [nextState, patches, inversePatches] = produceWithPatches(prevSheets, (draft) => {
|
|
82
|
+
for (const tableView of tables) {
|
|
67
83
|
const sheet = draft.find((sheet) => sheet.sheetId === tableView.sheetId);
|
|
68
|
-
if (sheet
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
84
|
+
if (!sheet)
|
|
85
|
+
continue;
|
|
86
|
+
if (!sheet.rowMetadata) {
|
|
87
|
+
sheet.rowMetadata = [];
|
|
88
|
+
}
|
|
89
|
+
const { range } = tableView;
|
|
90
|
+
for (let rowIndex = range.startRowIndex; rowIndex <= range.endRowIndex; rowIndex++) {
|
|
91
|
+
if (sheet.rowMetadata[rowIndex]?.hiddenByFilter) {
|
|
92
|
+
sheet.rowMetadata[rowIndex].hiddenByFilter = false;
|
|
93
|
+
for (const [key, position] of markTableAsDirty(tableView.sheetId, { ...range, startRowIndex: rowIndex, endRowIndex: rowIndex }, getDependents, enqueueCalculation)) {
|
|
94
|
+
unhiddenRecalcCells.set(key, position);
|
|
79
95
|
}
|
|
80
96
|
}
|
|
81
97
|
}
|
|
82
|
-
}
|
|
83
|
-
// Save to history
|
|
84
|
-
saveHistory({
|
|
85
|
-
sheets: { patches, inversePatches },
|
|
86
|
-
...(unhiddenRecalcCells.size
|
|
87
|
-
? {
|
|
88
|
-
recalcCells: {
|
|
89
|
-
undo: unhiddenRecalcCells,
|
|
90
|
-
redo: unhiddenRecalcCells,
|
|
91
|
-
},
|
|
92
|
-
}
|
|
93
|
-
: {}),
|
|
94
|
-
});
|
|
95
|
-
return nextState;
|
|
98
|
+
}
|
|
96
99
|
});
|
|
97
|
-
|
|
100
|
+
// Save to history
|
|
101
|
+
saveHistory({
|
|
102
|
+
sheets: { patches, inversePatches },
|
|
103
|
+
...(unhiddenRecalcCells.size
|
|
104
|
+
? {
|
|
105
|
+
recalcCells: {
|
|
106
|
+
undo: unhiddenRecalcCells,
|
|
107
|
+
redo: unhiddenRecalcCells,
|
|
108
|
+
},
|
|
109
|
+
}
|
|
110
|
+
: {}),
|
|
111
|
+
});
|
|
112
|
+
return nextState;
|
|
113
|
+
});
|
|
98
114
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rowsncolumns/spreadsheet-state",
|
|
3
|
-
"version": "29.1.
|
|
3
|
+
"version": "29.1.17",
|
|
4
4
|
"main": "./dist/cjs/index.js",
|
|
5
5
|
"module": "./dist/esm/index.js",
|
|
6
6
|
"types": "./dist/esm/index.d.ts",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@rowsncolumns/calculator": ">=7.3.0",
|
|
58
58
|
"@rowsncolumns/common-types": ">=5.2.33",
|
|
59
59
|
"@rowsncolumns/dag": ">=7.2.30",
|
|
60
|
-
"@rowsncolumns/fast-formula-parser": "6.2.
|
|
60
|
+
"@rowsncolumns/fast-formula-parser": "6.2.45",
|
|
61
61
|
"@rowsncolumns/grid": ">=13.2.33",
|
|
62
62
|
"@rowsncolumns/icons": ">=7.2.32",
|
|
63
63
|
"@rowsncolumns/pivot": ">=11.0.0",
|
|
@@ -72,18 +72,18 @@
|
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@rowsncolumns/calculator": ">=7.3.
|
|
75
|
+
"@rowsncolumns/calculator": ">=7.3.3",
|
|
76
76
|
"@rowsncolumns/common-types": ">=5.3.2",
|
|
77
77
|
"@rowsncolumns/dag": ">=7.2.31",
|
|
78
|
-
"@rowsncolumns/fast-formula-parser": ">=6.2.
|
|
79
|
-
"@rowsncolumns/grid": ">=13.2.
|
|
78
|
+
"@rowsncolumns/fast-formula-parser": ">=6.2.45",
|
|
79
|
+
"@rowsncolumns/grid": ">=13.2.39",
|
|
80
80
|
"@rowsncolumns/icons": ">=7.2.33",
|
|
81
81
|
"@rowsncolumns/spreadsheet": ">=10.5.11",
|
|
82
82
|
"@rowsncolumns/ui": ">=16.1.0",
|
|
83
83
|
"@rowsncolumns/utils": ">=9.5.6"
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@rowsncolumns/calculation-worker": ">=10.0.
|
|
86
|
+
"@rowsncolumns/calculation-worker": ">=10.0.3",
|
|
87
87
|
"@rowsncolumns/date-parser": ">=13.0.4",
|
|
88
88
|
"@rowsncolumns/functions": ">=15.1.0",
|
|
89
89
|
"@rowsncolumns/toolkit": ">=24.5.15",
|