@gridsheet/core 3.0.0-rc.8
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/README.md +17 -0
- package/dist/constants.d.ts +21 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +28 -0
- package/dist/constants.js.map +1 -0
- package/dist/formula/evaluator.d.ts +134 -0
- package/dist/formula/evaluator.d.ts.map +1 -0
- package/dist/formula/evaluator.js +585 -0
- package/dist/formula/evaluator.js.map +1 -0
- package/dist/formula/formula-error.d.ts +10 -0
- package/dist/formula/formula-error.d.ts.map +1 -0
- package/dist/formula/formula-error.js +15 -0
- package/dist/formula/formula-error.js.map +1 -0
- package/dist/formula/functions/__async.d.ts +67 -0
- package/dist/formula/functions/__async.d.ts.map +1 -0
- package/dist/formula/functions/__async.js +70 -0
- package/dist/formula/functions/__async.js.map +1 -0
- package/dist/formula/functions/__base.d.ts +112 -0
- package/dist/formula/functions/__base.d.ts.map +1 -0
- package/dist/formula/functions/__base.js +265 -0
- package/dist/formula/functions/__base.js.map +1 -0
- package/dist/formula/functions/__utils.d.ts +28 -0
- package/dist/formula/functions/__utils.d.ts.map +1 -0
- package/dist/formula/functions/__utils.js +179 -0
- package/dist/formula/functions/__utils.js.map +1 -0
- package/dist/formula/functions/abs.d.ts +9 -0
- package/dist/formula/functions/abs.d.ts.map +1 -0
- package/dist/formula/functions/abs.js +15 -0
- package/dist/formula/functions/abs.js.map +1 -0
- package/dist/formula/functions/add.d.ts +10 -0
- package/dist/formula/functions/add.d.ts.map +1 -0
- package/dist/formula/functions/add.js +37 -0
- package/dist/formula/functions/add.js.map +1 -0
- package/dist/formula/functions/and.d.ts +9 -0
- package/dist/formula/functions/and.d.ts.map +1 -0
- package/dist/formula/functions/and.js +23 -0
- package/dist/formula/functions/and.js.map +1 -0
- package/dist/formula/functions/arrayformula.d.ts +12 -0
- package/dist/formula/functions/arrayformula.d.ts.map +1 -0
- package/dist/formula/functions/arrayformula.js +24 -0
- package/dist/formula/functions/arrayformula.js.map +1 -0
- package/dist/formula/functions/average.d.ts +9 -0
- package/dist/formula/functions/average.d.ts.map +1 -0
- package/dist/formula/functions/average.js +40 -0
- package/dist/formula/functions/average.js.map +1 -0
- package/dist/formula/functions/concat.d.ts +9 -0
- package/dist/formula/functions/concat.d.ts.map +1 -0
- package/dist/formula/functions/concat.js +27 -0
- package/dist/formula/functions/concat.js.map +1 -0
- package/dist/formula/functions/count.d.ts +9 -0
- package/dist/formula/functions/count.d.ts.map +1 -0
- package/dist/formula/functions/count.js +32 -0
- package/dist/formula/functions/count.js.map +1 -0
- package/dist/formula/functions/counta.d.ts +9 -0
- package/dist/formula/functions/counta.d.ts.map +1 -0
- package/dist/formula/functions/counta.js +32 -0
- package/dist/formula/functions/counta.js.map +1 -0
- package/dist/formula/functions/divide.d.ts +10 -0
- package/dist/formula/functions/divide.d.ts.map +1 -0
- package/dist/formula/functions/divide.js +34 -0
- package/dist/formula/functions/divide.js.map +1 -0
- package/dist/formula/functions/eq.d.ts +9 -0
- package/dist/formula/functions/eq.d.ts.map +1 -0
- package/dist/formula/functions/eq.js +19 -0
- package/dist/formula/functions/eq.js.map +1 -0
- package/dist/formula/functions/gt.d.ts +9 -0
- package/dist/formula/functions/gt.d.ts.map +1 -0
- package/dist/formula/functions/gt.js +19 -0
- package/dist/formula/functions/gt.js.map +1 -0
- package/dist/formula/functions/gte.d.ts +9 -0
- package/dist/formula/functions/gte.d.ts.map +1 -0
- package/dist/formula/functions/gte.js +19 -0
- package/dist/formula/functions/gte.js.map +1 -0
- package/dist/formula/functions/if.d.ts +9 -0
- package/dist/formula/functions/if.d.ts.map +1 -0
- package/dist/formula/functions/if.js +29 -0
- package/dist/formula/functions/if.js.map +1 -0
- package/dist/formula/functions/iferror.d.ts +10 -0
- package/dist/formula/functions/iferror.d.ts.map +1 -0
- package/dist/formula/functions/iferror.js +28 -0
- package/dist/formula/functions/iferror.js.map +1 -0
- package/dist/formula/functions/len.d.ts +9 -0
- package/dist/formula/functions/len.d.ts.map +1 -0
- package/dist/formula/functions/len.js +21 -0
- package/dist/formula/functions/len.js.map +1 -0
- package/dist/formula/functions/lt.d.ts +9 -0
- package/dist/formula/functions/lt.d.ts.map +1 -0
- package/dist/formula/functions/lt.js +19 -0
- package/dist/formula/functions/lt.js.map +1 -0
- package/dist/formula/functions/lte.d.ts +9 -0
- package/dist/formula/functions/lte.d.ts.map +1 -0
- package/dist/formula/functions/lte.js +19 -0
- package/dist/formula/functions/lte.js.map +1 -0
- package/dist/formula/functions/max.d.ts +9 -0
- package/dist/formula/functions/max.d.ts.map +1 -0
- package/dist/formula/functions/max.js +37 -0
- package/dist/formula/functions/max.js.map +1 -0
- package/dist/formula/functions/min.d.ts +9 -0
- package/dist/formula/functions/min.d.ts.map +1 -0
- package/dist/formula/functions/min.js +37 -0
- package/dist/formula/functions/min.js.map +1 -0
- package/dist/formula/functions/minus.d.ts +10 -0
- package/dist/formula/functions/minus.d.ts.map +1 -0
- package/dist/formula/functions/minus.js +41 -0
- package/dist/formula/functions/minus.js.map +1 -0
- package/dist/formula/functions/multiply.d.ts +9 -0
- package/dist/formula/functions/multiply.d.ts.map +1 -0
- package/dist/formula/functions/multiply.js +19 -0
- package/dist/formula/functions/multiply.js.map +1 -0
- package/dist/formula/functions/ne.d.ts +9 -0
- package/dist/formula/functions/ne.d.ts.map +1 -0
- package/dist/formula/functions/ne.js +19 -0
- package/dist/formula/functions/ne.js.map +1 -0
- package/dist/formula/functions/not.d.ts +9 -0
- package/dist/formula/functions/not.d.ts.map +1 -0
- package/dist/formula/functions/not.js +22 -0
- package/dist/formula/functions/not.js.map +1 -0
- package/dist/formula/functions/now.d.ts +9 -0
- package/dist/formula/functions/now.d.ts.map +1 -0
- package/dist/formula/functions/now.js +14 -0
- package/dist/formula/functions/now.js.map +1 -0
- package/dist/formula/functions/or.d.ts +9 -0
- package/dist/formula/functions/or.d.ts.map +1 -0
- package/dist/formula/functions/or.js +23 -0
- package/dist/formula/functions/or.js.map +1 -0
- package/dist/formula/functions/power.d.ts +9 -0
- package/dist/formula/functions/power.d.ts.map +1 -0
- package/dist/formula/functions/power.js +18 -0
- package/dist/formula/functions/power.js.map +1 -0
- package/dist/formula/functions/sum.d.ts +9 -0
- package/dist/formula/functions/sum.d.ts.map +1 -0
- package/dist/formula/functions/sum.js +34 -0
- package/dist/formula/functions/sum.js.map +1 -0
- package/dist/formula/functions/uminus.d.ts +9 -0
- package/dist/formula/functions/uminus.d.ts.map +1 -0
- package/dist/formula/functions/uminus.js +17 -0
- package/dist/formula/functions/uminus.js.map +1 -0
- package/dist/formula/mapping.d.ts +11 -0
- package/dist/formula/mapping.d.ts.map +1 -0
- package/dist/formula/mapping.js +82 -0
- package/dist/formula/mapping.js.map +1 -0
- package/dist/formula/solver.d.ts +39 -0
- package/dist/formula/solver.d.ts.map +1 -0
- package/dist/formula/solver.js +71 -0
- package/dist/formula/solver.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +74 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/autofill.d.ts +22 -0
- package/dist/lib/autofill.d.ts.map +1 -0
- package/dist/lib/autofill.js +276 -0
- package/dist/lib/autofill.js.map +1 -0
- package/dist/lib/book.d.ts +131 -0
- package/dist/lib/book.d.ts.map +1 -0
- package/dist/lib/book.js +53 -0
- package/dist/lib/book.js.map +1 -0
- package/dist/lib/cell.d.ts +17 -0
- package/dist/lib/cell.d.ts.map +1 -0
- package/dist/lib/cell.js +17 -0
- package/dist/lib/cell.js.map +1 -0
- package/dist/lib/coords.d.ts +22 -0
- package/dist/lib/coords.d.ts.map +1 -0
- package/dist/lib/coords.js +73 -0
- package/dist/lib/coords.js.map +1 -0
- package/dist/lib/date.d.ts +2 -0
- package/dist/lib/date.d.ts.map +1 -0
- package/dist/lib/date.js +91 -0
- package/dist/lib/date.js.map +1 -0
- package/dist/lib/dom.d.ts +7 -0
- package/dist/lib/dom.d.ts.map +1 -0
- package/dist/lib/dom.js +28 -0
- package/dist/lib/dom.js.map +1 -0
- package/dist/lib/filter.d.ts +7 -0
- package/dist/lib/filter.d.ts.map +1 -0
- package/dist/lib/filter.js +122 -0
- package/dist/lib/filter.js.map +1 -0
- package/dist/lib/input.d.ts +28 -0
- package/dist/lib/input.d.ts.map +1 -0
- package/dist/lib/input.js +73 -0
- package/dist/lib/input.js.map +1 -0
- package/dist/lib/label.d.ts +4 -0
- package/dist/lib/label.d.ts.map +1 -0
- package/dist/lib/label.js +10 -0
- package/dist/lib/label.js.map +1 -0
- package/dist/lib/operation.d.ts +31 -0
- package/dist/lib/operation.d.ts.map +1 -0
- package/dist/lib/operation.js +36 -0
- package/dist/lib/operation.js.map +1 -0
- package/dist/lib/palette.d.ts +2 -0
- package/dist/lib/palette.d.ts.map +1 -0
- package/dist/lib/palette.js +26 -0
- package/dist/lib/palette.js.map +1 -0
- package/dist/lib/popup.d.ts +24 -0
- package/dist/lib/popup.d.ts.map +1 -0
- package/dist/lib/popup.js +21 -0
- package/dist/lib/popup.js.map +1 -0
- package/dist/lib/reference.d.ts +19 -0
- package/dist/lib/reference.d.ts.map +1 -0
- package/dist/lib/reference.js +40 -0
- package/dist/lib/reference.js.map +1 -0
- package/dist/lib/sheet.d.ts +512 -0
- package/dist/lib/sheet.d.ts.map +1 -0
- package/dist/lib/sheet.js +1530 -0
- package/dist/lib/sheet.js.map +1 -0
- package/dist/lib/sheet_utils.d.ts +55 -0
- package/dist/lib/sheet_utils.d.ts.map +1 -0
- package/dist/lib/sheet_utils.js +125 -0
- package/dist/lib/sheet_utils.js.map +1 -0
- package/dist/lib/spatial.d.ts +79 -0
- package/dist/lib/spatial.d.ts.map +1 -0
- package/dist/lib/spatial.js +227 -0
- package/dist/lib/spatial.js.map +1 -0
- package/dist/lib/time.d.ts +29 -0
- package/dist/lib/time.d.ts.map +1 -0
- package/dist/lib/time.js +113 -0
- package/dist/lib/time.js.map +1 -0
- package/dist/lib/virtualization.d.ts +22 -0
- package/dist/lib/virtualization.d.ts.map +1 -0
- package/dist/lib/virtualization.js +91 -0
- package/dist/lib/virtualization.js.map +1 -0
- package/dist/policy/core.d.ts +161 -0
- package/dist/policy/core.d.ts.map +1 -0
- package/dist/policy/core.js +248 -0
- package/dist/policy/core.js.map +1 -0
- package/dist/policy/thousand_separator.d.ts +4 -0
- package/dist/policy/thousand_separator.d.ts.map +1 -0
- package/dist/policy/thousand_separator.js +13 -0
- package/dist/policy/thousand_separator.js.map +1 -0
- package/dist/sentinels.d.ts +40 -0
- package/dist/sentinels.d.ts.map +1 -0
- package/dist/sentinels.js +41 -0
- package/dist/sentinels.js.map +1 -0
- package/dist/styles/embedder.d.ts +2 -0
- package/dist/styles/embedder.d.ts.map +1 -0
- package/dist/styles/embedder.js +11 -0
- package/dist/styles/embedder.js.map +1 -0
- package/dist/styles/minified.d.ts +3 -0
- package/dist/styles/minified.d.ts.map +1 -0
- package/dist/styles/minified.js +6 -0
- package/dist/styles/minified.js.map +1 -0
- package/dist/types.d.ts +310 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +2 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +5 -0
- package/dist/utils.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,1530 @@
|
|
|
1
|
+
import { getMaxSizesFromCells as wt, expandRange as xt, createMatrix as St, matrixShape as W, areaShape as Rt } from "./spatial.js";
|
|
2
|
+
import { p2a as _, x2c as Z, a2p as A, grantAddressAbsolute as Ct, y2r as It } from "./coords.js";
|
|
3
|
+
import { Lexer as Q } from "../formula/evaluator.js";
|
|
4
|
+
import { FormulaError as z } from "../formula/formula-error.js";
|
|
5
|
+
import { solveFormula as tt, stripSheet as et, solveSheet as Et } from "../formula/solver.js";
|
|
6
|
+
import { ensureSys as k } from "./cell.js";
|
|
7
|
+
import { escapeSheetName as _t, toSheetPrefix as vt } from "./sheet_utils.js";
|
|
8
|
+
import { DEFAULT_WIDTH as $, DEFAULT_HEIGHT as U, HEADER_HEIGHT as st, HEADER_WIDTH as it, DEFAULT_KEY as rt, DEFAULT_COL_KEY as ot, DEFAULT_ROW_KEY as nt } from "../constants.js";
|
|
9
|
+
import { Pending as Mt, SOLVING as at } from "../sentinels.js";
|
|
10
|
+
import { hasOperation as Y, MoveFrom as ht, MoveTo as lt, Copy as bt, Update as X, Write as K, Style as Tt, Resize as Ot, RemoveRows as At, RemoveCols as Dt } from "./operation.js";
|
|
11
|
+
import { createRegistry as Pt } from "./book.js";
|
|
12
|
+
import { nonePolicy as Ft, DEFAULT_POLICY_NAME as B } from "../policy/core.js";
|
|
13
|
+
import { evaluateFilterConfig as Nt } from "./filter.js";
|
|
14
|
+
import { ReferencePreserver as L } from "./reference.js";
|
|
15
|
+
const dt = (ct) => {
|
|
16
|
+
switch (ct) {
|
|
17
|
+
case "INSERT_ROWS":
|
|
18
|
+
case "INSERT_COLS":
|
|
19
|
+
case "REMOVE_ROWS":
|
|
20
|
+
case "REMOVE_COLS":
|
|
21
|
+
case "MOVE":
|
|
22
|
+
case "SORT_ROWS":
|
|
23
|
+
return !0;
|
|
24
|
+
}
|
|
25
|
+
return !1;
|
|
26
|
+
}, Yt = () => !0;
|
|
27
|
+
class V {
|
|
28
|
+
constructor({ limits: t = {}, name: e, registry: s = Pt({}) }) {
|
|
29
|
+
this.__gsType = "Sheet", this.area = { top: 0, left: 0, bottom: 0, right: 0 }, this.id = 0, this.name = "", this.prevName = "", this.status = 0, this.idsToBeIdentified = [], this.totalWidth = 0, this.totalHeight = 0, this.fullHeight = 0, this.defaultColWidth = $, this.defaultRowHeight = U, this.version = 0, this.addressCaches = /* @__PURE__ */ new Map(), this.lastChangedAddresses = [], this.idMatrix = [], this.changedTime = Date.now(), this._limits = {
|
|
30
|
+
minRows: t.minRows ?? 1,
|
|
31
|
+
maxRows: t.maxRows ?? -1,
|
|
32
|
+
minCols: t.minCols ?? 1,
|
|
33
|
+
maxCols: t.maxCols ?? -1
|
|
34
|
+
}, this.name = e || "", this.prevName = this.name, this.registry = s;
|
|
35
|
+
}
|
|
36
|
+
get minNumRows() {
|
|
37
|
+
return this._limits.minRows;
|
|
38
|
+
}
|
|
39
|
+
get maxNumRows() {
|
|
40
|
+
return this._limits.maxRows;
|
|
41
|
+
}
|
|
42
|
+
get minNumCols() {
|
|
43
|
+
return this._limits.minCols;
|
|
44
|
+
}
|
|
45
|
+
get maxNumCols() {
|
|
46
|
+
return this._limits.maxCols;
|
|
47
|
+
}
|
|
48
|
+
static is(t) {
|
|
49
|
+
return (t == null ? void 0 : t.__gsType) === "Sheet";
|
|
50
|
+
}
|
|
51
|
+
toString() {
|
|
52
|
+
return `Sheet(name=${_t(this.name)}, size=${this.numRows}x${this.numCols})`;
|
|
53
|
+
}
|
|
54
|
+
get headerHeight() {
|
|
55
|
+
var t;
|
|
56
|
+
return ((t = this.getCell({ y: 0, x: 0 }, { resolution: "SYSTEM" })) == null ? void 0 : t.height) || st;
|
|
57
|
+
}
|
|
58
|
+
setHeaderHeight(t, e = !0) {
|
|
59
|
+
return this.update({
|
|
60
|
+
diff: { 0: { height: t } },
|
|
61
|
+
partial: !0,
|
|
62
|
+
historicize: e
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
get headerWidth() {
|
|
66
|
+
var t;
|
|
67
|
+
return ((t = this.getCell({ y: 0, x: 0 }, { resolution: "SYSTEM" })) == null ? void 0 : t.width) || it;
|
|
68
|
+
}
|
|
69
|
+
setHeaderWidth(t, e = !0) {
|
|
70
|
+
return this.update({
|
|
71
|
+
diff: { 0: { width: t } },
|
|
72
|
+
partial: !0,
|
|
73
|
+
historicize: e
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the raw (mutable) cell data for a point. Unlike getCell, this returns the actual registry.data reference.
|
|
78
|
+
* @internal
|
|
79
|
+
*/
|
|
80
|
+
_pointToRawCell({ y: t, x: e }) {
|
|
81
|
+
var i;
|
|
82
|
+
const s = (i = this.idMatrix[t]) == null ? void 0 : i[e];
|
|
83
|
+
if (s != null)
|
|
84
|
+
return this.registry.data[s];
|
|
85
|
+
}
|
|
86
|
+
isRowFiltered(t) {
|
|
87
|
+
var e;
|
|
88
|
+
return !!((e = this._pointToRawCell({ y: t, x: 0 })) != null && e.filtered);
|
|
89
|
+
}
|
|
90
|
+
hasActiveFilters() {
|
|
91
|
+
const t = this.numCols;
|
|
92
|
+
for (let e = 1; e <= t; e++) {
|
|
93
|
+
const s = this._pointToRawCell({ y: 0, x: e });
|
|
94
|
+
if (s != null && s.filter && s.filter.conditions.length > 0)
|
|
95
|
+
return !0;
|
|
96
|
+
}
|
|
97
|
+
return !1;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Returns true if any data cell in this sheet currently holds a Pending value
|
|
101
|
+
* (i.e. an async formula that hasn't resolved yet).
|
|
102
|
+
*/
|
|
103
|
+
hasPendingCells() {
|
|
104
|
+
const t = this.numRows, e = this.numCols;
|
|
105
|
+
for (let s = 1; s <= t; s++)
|
|
106
|
+
for (let i = 1; i <= e; i++) {
|
|
107
|
+
const r = this.getCell({ y: s, x: i }, { resolution: "RESOLVED" });
|
|
108
|
+
if (Mt.is(r == null ? void 0 : r.value))
|
|
109
|
+
return !0;
|
|
110
|
+
}
|
|
111
|
+
return !1;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Returns a Promise that resolves when all in-flight async formula computations
|
|
115
|
+
* have completed and no data cells hold Pending values.
|
|
116
|
+
* If nothing is pending, resolves immediately.
|
|
117
|
+
* Useful for waiting before sort/filter so that cell values are fully resolved.
|
|
118
|
+
*/
|
|
119
|
+
waitForPending() {
|
|
120
|
+
const t = this.registry.asyncPending;
|
|
121
|
+
if (t.size > 0) {
|
|
122
|
+
const e = Array.from(t.values()).map((s) => s.promise);
|
|
123
|
+
return Promise.all(e).then(() => this.waitForPending());
|
|
124
|
+
}
|
|
125
|
+
return this.hasPendingCells() ? new Promise((e) => {
|
|
126
|
+
const s = () => {
|
|
127
|
+
if (this.registry.asyncPending.size > 0) {
|
|
128
|
+
const i = Array.from(this.registry.asyncPending.values()).map((r) => r.promise);
|
|
129
|
+
Promise.all(i).then(s);
|
|
130
|
+
} else this.hasPendingCells() ? setTimeout(s, 50) : e();
|
|
131
|
+
};
|
|
132
|
+
s();
|
|
133
|
+
}) : Promise.resolve();
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Returns the addresses that were changed in the most recent `_update()` call.
|
|
137
|
+
* Useful inside `onChange` to know which cells were modified.
|
|
138
|
+
*/
|
|
139
|
+
getLastChangedAddresses() {
|
|
140
|
+
return this.lastChangedAddresses;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Capture the full cell state of all filter-related header cells as a CellsByIdType snapshot.
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
_captureFilterCellStates() {
|
|
147
|
+
var i, r, o, l;
|
|
148
|
+
const t = {}, e = this.numCols, s = this.numRows;
|
|
149
|
+
for (let a = 1; a <= e; a++) {
|
|
150
|
+
const h = (i = this.idMatrix[0]) == null ? void 0 : i[a];
|
|
151
|
+
h != null && (t[h] = { filter: ((r = this.registry.data[h]) == null ? void 0 : r.filter) ?? null });
|
|
152
|
+
}
|
|
153
|
+
for (let a = 1; a <= s; a++) {
|
|
154
|
+
const h = (o = this.idMatrix[a]) == null ? void 0 : o[0];
|
|
155
|
+
h != null && (t[h] = { filtered: ((l = this.registry.data[h]) == null ? void 0 : l.filtered) ?? !1 });
|
|
156
|
+
}
|
|
157
|
+
return t;
|
|
158
|
+
}
|
|
159
|
+
filterRows({
|
|
160
|
+
x: t,
|
|
161
|
+
filter: e
|
|
162
|
+
} = {}) {
|
|
163
|
+
const s = this._captureFilterCellStates();
|
|
164
|
+
if (t == null) {
|
|
165
|
+
const o = this.numCols;
|
|
166
|
+
for (let l = 1; l <= o; l++) {
|
|
167
|
+
const a = this._pointToRawCell({ y: 0, x: l });
|
|
168
|
+
a == null || delete a.filter;
|
|
169
|
+
}
|
|
170
|
+
} else {
|
|
171
|
+
const o = this._pointToRawCell({ y: 0, x: t });
|
|
172
|
+
o && (e ? o.filter = e : delete o.filter);
|
|
173
|
+
}
|
|
174
|
+
this._reapplyFilters();
|
|
175
|
+
const i = this._captureFilterCellStates(), r = Object.keys(s).filter(
|
|
176
|
+
(o) => JSON.stringify(s[o]) !== JSON.stringify(i[o])
|
|
177
|
+
);
|
|
178
|
+
if (r.length > 0) {
|
|
179
|
+
const o = {}, l = {};
|
|
180
|
+
for (const a of r)
|
|
181
|
+
o[a] = s[a], l[a] = i[a];
|
|
182
|
+
this._pushHistory({
|
|
183
|
+
applyed: !0,
|
|
184
|
+
operation: "UPDATE",
|
|
185
|
+
srcSheetId: this.id,
|
|
186
|
+
dstSheetId: this.id,
|
|
187
|
+
diffBefore: o,
|
|
188
|
+
diffAfter: l,
|
|
189
|
+
partial: !0
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
return this.refresh(!1, !0);
|
|
193
|
+
}
|
|
194
|
+
/** @internal */
|
|
195
|
+
_reapplyFilters() {
|
|
196
|
+
const t = this.numCols, e = [], s = [];
|
|
197
|
+
for (let r = 1; r <= t; r++) {
|
|
198
|
+
const o = this._pointToRawCell({ y: 0, x: r });
|
|
199
|
+
o != null && o.filter && o.filter.conditions.length > 0 && e.push({ x: r, filter: o.filter }), s.push(_({ y: 0, x: r }));
|
|
200
|
+
}
|
|
201
|
+
const i = this.numRows;
|
|
202
|
+
for (let r = 1; r <= i; r++) {
|
|
203
|
+
const o = this._pointToRawCell({ y: r, x: 0 });
|
|
204
|
+
if (!o || o.filterFixed)
|
|
205
|
+
continue;
|
|
206
|
+
let l = !1;
|
|
207
|
+
for (const { x: h, filter: u } of e) {
|
|
208
|
+
const n = this.getCell({ y: r, x: h }, { resolution: "RESOLVED" });
|
|
209
|
+
if (!Nt(u, n == null ? void 0 : n.value)) {
|
|
210
|
+
l = !0;
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
const a = !!o.filtered;
|
|
215
|
+
l ? o.filtered = !0 : delete o.filtered, a !== l && s.push(_({ y: r, x: 0 }));
|
|
216
|
+
}
|
|
217
|
+
this.lastChangedAddresses = s;
|
|
218
|
+
}
|
|
219
|
+
sortRows({ x: t, direction: e }) {
|
|
220
|
+
const s = this.numRows;
|
|
221
|
+
if (s <= 1)
|
|
222
|
+
return this;
|
|
223
|
+
const i = /* @__PURE__ */ new Set(), r = [];
|
|
224
|
+
for (let n = 1; n <= s; n++) {
|
|
225
|
+
const f = this._pointToRawCell({ y: n, x: 0 });
|
|
226
|
+
f != null && f.sortFixed ? i.add(n) : r.push(n);
|
|
227
|
+
}
|
|
228
|
+
r.sort((n, f) => {
|
|
229
|
+
const d = this.getCell({ y: n, x: t }, { resolution: "RESOLVED" }), p = this.getCell({ y: f, x: t }, { resolution: "RESOLVED" }), y = d == null ? void 0 : d.value, c = p == null ? void 0 : p.value;
|
|
230
|
+
if (y == null && c == null)
|
|
231
|
+
return 0;
|
|
232
|
+
if (y == null)
|
|
233
|
+
return 1;
|
|
234
|
+
if (c == null)
|
|
235
|
+
return -1;
|
|
236
|
+
let g = 0;
|
|
237
|
+
return typeof y == "number" && typeof c == "number" ? g = y - c : y instanceof Date && c instanceof Date ? g = y.getTime() - c.getTime() : g = String(y).localeCompare(String(c)), e === "asc" ? g : -g;
|
|
238
|
+
});
|
|
239
|
+
const o = [];
|
|
240
|
+
for (let n = 1; n <= s; n++)
|
|
241
|
+
i.has(n) || o.push(n);
|
|
242
|
+
let l = !1;
|
|
243
|
+
for (let n = 0; n < r.length; n++)
|
|
244
|
+
if (r[n] !== o[n]) {
|
|
245
|
+
l = !0;
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
if (!l)
|
|
249
|
+
return this;
|
|
250
|
+
const a = {};
|
|
251
|
+
for (const n of i)
|
|
252
|
+
a[n] = n;
|
|
253
|
+
for (let n = 0; n < r.length; n++)
|
|
254
|
+
a[r[n]] = o[n];
|
|
255
|
+
const h = this.idMatrix.slice();
|
|
256
|
+
for (const [n, f] of Object.entries(a))
|
|
257
|
+
this.idMatrix[Number(f)] = h[Number(n)];
|
|
258
|
+
this.addressCaches.clear();
|
|
259
|
+
const u = new L(this);
|
|
260
|
+
return u.buildMap(h.flat(), this.idMatrix.flat()), u.resolveDependents(), this._pushHistory({
|
|
261
|
+
applyed: !0,
|
|
262
|
+
operation: "SORT_ROWS",
|
|
263
|
+
srcSheetId: this.id,
|
|
264
|
+
dstSheetId: this.id,
|
|
265
|
+
sortedRowMapping: a
|
|
266
|
+
}), this.refresh(!0, !0);
|
|
267
|
+
}
|
|
268
|
+
/** @internal */
|
|
269
|
+
_sortRowMapping(t, e = !1) {
|
|
270
|
+
const s = this.numRows, i = new Array(s);
|
|
271
|
+
if (e)
|
|
272
|
+
for (const [o, l] of Object.entries(t)) {
|
|
273
|
+
const a = Number(o);
|
|
274
|
+
i[a - 1] = l;
|
|
275
|
+
}
|
|
276
|
+
else
|
|
277
|
+
for (const [o, l] of Object.entries(t)) {
|
|
278
|
+
const a = Number(o);
|
|
279
|
+
i[l - 1] = a;
|
|
280
|
+
}
|
|
281
|
+
const r = [];
|
|
282
|
+
for (let o = 0; o < i.length; o++)
|
|
283
|
+
r.push(this.idMatrix[i[o]]);
|
|
284
|
+
for (let o = 0; o < i.length; o++)
|
|
285
|
+
this.idMatrix[o + 1] = r[o];
|
|
286
|
+
this.addressCaches.clear();
|
|
287
|
+
}
|
|
288
|
+
get isInitialized() {
|
|
289
|
+
return this.status === 2;
|
|
290
|
+
}
|
|
291
|
+
get policies() {
|
|
292
|
+
return this.registry.policies;
|
|
293
|
+
}
|
|
294
|
+
/** @internal */
|
|
295
|
+
getSystem(t) {
|
|
296
|
+
const e = this.getId(t);
|
|
297
|
+
if (e != null)
|
|
298
|
+
return this.registry.systems[e];
|
|
299
|
+
}
|
|
300
|
+
/** @internal */
|
|
301
|
+
processFormula(t, { idMap: e, ...s }) {
|
|
302
|
+
if ((typeof t == "string" || t instanceof String) && t.charAt(0) === "=") {
|
|
303
|
+
const i = new Q(t.substring(1));
|
|
304
|
+
return i.tokenize(e), i.identify({ ...s, sheet: this }), i.dependencyIds.forEach((r) => this.addDependency(r, s.dependency)), "=" + i.identifiedFormula;
|
|
305
|
+
}
|
|
306
|
+
return t;
|
|
307
|
+
}
|
|
308
|
+
/** @internal */
|
|
309
|
+
resolveFormulas() {
|
|
310
|
+
this.idsToBeIdentified.forEach((t) => {
|
|
311
|
+
var s;
|
|
312
|
+
const e = this.registry.data[t];
|
|
313
|
+
((s = this.registry.systems[t]) == null ? void 0 : s.sheetId) != null && e != null && (this.clearDependencies(t), e.value = this.processFormula(e == null ? void 0 : e.value, { dependency: t }));
|
|
314
|
+
}), this.idsToBeIdentified = [], this.status = 2;
|
|
315
|
+
}
|
|
316
|
+
/** @internal */
|
|
317
|
+
getSheetBySheetName(t) {
|
|
318
|
+
const e = this.registry.sheetIdsByName[t];
|
|
319
|
+
return this.getSheetBySheetId(e);
|
|
320
|
+
}
|
|
321
|
+
/** @internal */
|
|
322
|
+
getSheetBySheetId(t) {
|
|
323
|
+
var e, s, i;
|
|
324
|
+
return (i = (s = (e = this.registry.contextsBySheetId[t]) == null ? void 0 : e.store) == null ? void 0 : s.sheetReactive) == null ? void 0 : i.current;
|
|
325
|
+
}
|
|
326
|
+
/** @internal */
|
|
327
|
+
static _stack(...t) {
|
|
328
|
+
const e = {};
|
|
329
|
+
return t.forEach((s) => {
|
|
330
|
+
s != null && s.style && (e.style = { ...e.style, ...s.style }), s != null && s.prevention && (e.prevention = (e.prevention || 0) | s.prevention);
|
|
331
|
+
}), e;
|
|
332
|
+
}
|
|
333
|
+
/** @internal */
|
|
334
|
+
initialize(t) {
|
|
335
|
+
var l, a;
|
|
336
|
+
if (this.status > 1)
|
|
337
|
+
return;
|
|
338
|
+
t[0] == null && (t[0] = { width: it, height: st });
|
|
339
|
+
const e = wt(t), s = Date.now();
|
|
340
|
+
this.area = {
|
|
341
|
+
top: 1,
|
|
342
|
+
left: 1,
|
|
343
|
+
bottom: e.numRows,
|
|
344
|
+
right: e.numCols
|
|
345
|
+
};
|
|
346
|
+
for (let h = 0; h < e.numRows + 1; h++) {
|
|
347
|
+
const u = [];
|
|
348
|
+
this.idMatrix.push(u);
|
|
349
|
+
for (let n = 0; n < e.numCols + 1; n++) {
|
|
350
|
+
const f = this._generateId();
|
|
351
|
+
u.push(f);
|
|
352
|
+
const d = _({ y: h, x: n });
|
|
353
|
+
this.addressCaches.set(f, d);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
Object.keys(t).forEach((h) => {
|
|
357
|
+
if (h === rt || h === ot || h === nt)
|
|
358
|
+
return;
|
|
359
|
+
const u = xt(h), n = t[h];
|
|
360
|
+
u.forEach((f) => {
|
|
361
|
+
const d = t[f];
|
|
362
|
+
t[f] = {
|
|
363
|
+
...d,
|
|
364
|
+
...n,
|
|
365
|
+
...V._stack(d, n)
|
|
366
|
+
};
|
|
367
|
+
});
|
|
368
|
+
});
|
|
369
|
+
const i = t == null ? void 0 : t[rt], r = t == null ? void 0 : t[ot], o = t == null ? void 0 : t[nt];
|
|
370
|
+
(r == null ? void 0 : r.width) != null && (this.defaultColWidth = r.width), (o == null ? void 0 : o.height) != null && (this.defaultRowHeight = o.height);
|
|
371
|
+
for (let h = 0; h < e.numRows + 1; h++) {
|
|
372
|
+
const u = It(h);
|
|
373
|
+
for (let n = 0; n < e.numCols + 1; n++) {
|
|
374
|
+
const f = this.getId({ y: h, x: n }), d = Z(n);
|
|
375
|
+
let p;
|
|
376
|
+
if (h === 0 && n > 0) {
|
|
377
|
+
const c = t == null ? void 0 : t[d], { style: g, ...R } = c ?? {}, S = t == null ? void 0 : t[d + "0"];
|
|
378
|
+
p = {
|
|
379
|
+
...r,
|
|
380
|
+
...R,
|
|
381
|
+
...S,
|
|
382
|
+
...V._stack(r, S)
|
|
383
|
+
};
|
|
384
|
+
} else if (n === 0 && h > 0) {
|
|
385
|
+
const c = t == null ? void 0 : t[u], { style: g, ...R } = c ?? {}, S = t == null ? void 0 : t["0" + u];
|
|
386
|
+
p = {
|
|
387
|
+
...o,
|
|
388
|
+
...R,
|
|
389
|
+
...S,
|
|
390
|
+
...V._stack(o, S)
|
|
391
|
+
};
|
|
392
|
+
} else if (h === 0 && n === 0) {
|
|
393
|
+
const c = t == null ? void 0 : t["0"];
|
|
394
|
+
p = { ...c, ...V._stack(c) };
|
|
395
|
+
} else {
|
|
396
|
+
const c = _({ y: h, x: n }), g = t == null ? void 0 : t[u], R = t == null ? void 0 : t[d], S = t == null ? void 0 : t[c];
|
|
397
|
+
p = {
|
|
398
|
+
...i,
|
|
399
|
+
...g,
|
|
400
|
+
...R,
|
|
401
|
+
...S,
|
|
402
|
+
...V._stack(i, g, R, S)
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
(a = (l = p == null ? void 0 : p.value) == null ? void 0 : l.startsWith) != null && a.call(l, "=") && ((p == null ? void 0 : p.formulaEnabled) ?? !0) && this.idsToBeIdentified.push(f), h === 0 ? p.width == null && (p.width = $) : n === 0 ? p.height == null && (p.height = U) : (delete p.height, delete p.width, delete p.label), p = (this.policies[p.policy ?? ""] ?? this.defaultPolicy).deserializeValue(p.value, p) ?? {}, this.registry.systems[f] = { id: f, changedTime: s, sheetId: this.id }, this.registry.data[f] = p;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
this.status = 1, this.registry.sheetIdsByName[this.name] = this.id;
|
|
409
|
+
}
|
|
410
|
+
/** @internal */
|
|
411
|
+
_incrementVersion() {
|
|
412
|
+
this.version++, this.version >= Number.MAX_SAFE_INTEGER && (this.version = 1);
|
|
413
|
+
}
|
|
414
|
+
/** @internal */
|
|
415
|
+
_xsheetDispatch(t) {
|
|
416
|
+
if (t === this)
|
|
417
|
+
return;
|
|
418
|
+
t.refresh(!0);
|
|
419
|
+
const e = this.registry.contextsBySheetId[t.id];
|
|
420
|
+
if (e !== null) {
|
|
421
|
+
const { dispatch: s } = e;
|
|
422
|
+
requestAnimationFrame(() => {
|
|
423
|
+
s(this.registry.updateSheet(t));
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
/** @internal */
|
|
428
|
+
_generateId() {
|
|
429
|
+
return (this.registry.cellHead++).toString();
|
|
430
|
+
}
|
|
431
|
+
getRectSize({ top: t, left: e, bottom: s, right: i }) {
|
|
432
|
+
var d, p, y, c;
|
|
433
|
+
const r = e || 1, o = t || 1, l = ((d = this.registry.systems[this.getId({ y: 0, x: i })]) == null ? void 0 : d.offsetLeft) ?? 0, a = ((p = this.registry.systems[this.getId({ y: 0, x: r })]) == null ? void 0 : p.offsetLeft) ?? 0, h = ((y = this.registry.systems[this.getId({ y: s, x: 0 })]) == null ? void 0 : y.offsetTop) ?? 0, u = ((c = this.registry.systems[this.getId({ y: o, x: 0 })]) == null ? void 0 : c.offsetTop) ?? 0, n = Math.max(0, l - a), f = Math.max(0, h - u);
|
|
434
|
+
return { y: o, x: r, height: f, width: n };
|
|
435
|
+
}
|
|
436
|
+
/** @internal */
|
|
437
|
+
setTotalSize() {
|
|
438
|
+
const t = this.numCols, e = this.numRows, s = this.headerWidth, i = this.headerHeight;
|
|
439
|
+
let r = 0;
|
|
440
|
+
for (let a = 1; a <= t; a++) {
|
|
441
|
+
const h = this.getCell({ y: 0, x: a }, { resolution: "SYSTEM" }), u = (h == null ? void 0 : h.width) || this.defaultColWidth || $, n = this.registry.systems[this.getId({ y: 0, x: a })];
|
|
442
|
+
n != null && (n.offsetLeft = s + r), r += u;
|
|
443
|
+
}
|
|
444
|
+
this.totalWidth = s + r;
|
|
445
|
+
let o = 0, l = 0;
|
|
446
|
+
for (let a = 1; a <= e; a++) {
|
|
447
|
+
const h = this.getCell({ y: a, x: 0 }, { resolution: "SYSTEM" }), u = (h == null ? void 0 : h.height) || this.defaultRowHeight || U, n = this.registry.systems[this.getId({ y: a, x: 0 })];
|
|
448
|
+
n != null && (n.offsetTop = i + o), h != null && h.filtered || (o += u), l += u;
|
|
449
|
+
}
|
|
450
|
+
this.totalHeight = i + o, this.fullHeight = i + l;
|
|
451
|
+
}
|
|
452
|
+
/** @internal */
|
|
453
|
+
refresh(t = !1, e = !1) {
|
|
454
|
+
return this._incrementVersion(), this.lastChangedTime = this.changedTime, this.changedTime = Date.now(), this.clearSolvedCaches(), t && this.addressCaches.clear(), e && this.setTotalSize(), this;
|
|
455
|
+
}
|
|
456
|
+
/** @internal */
|
|
457
|
+
clone(t = !1) {
|
|
458
|
+
return Object.assign(Object.create(Object.getPrototypeOf(this)), this).refresh(t);
|
|
459
|
+
}
|
|
460
|
+
/** @internal */
|
|
461
|
+
getPointById(t, e = 0, s = 0) {
|
|
462
|
+
const i = t.startsWith("$");
|
|
463
|
+
i && (t = t.slice(1), s = 0);
|
|
464
|
+
const r = t.endsWith("$");
|
|
465
|
+
r && (t = t.slice(0, -1), e = 0);
|
|
466
|
+
const o = this.addressCaches.get(t);
|
|
467
|
+
if (o) {
|
|
468
|
+
const l = A(o);
|
|
469
|
+
return { y: l.y + e, x: l.x + s, absCol: i, absRow: r };
|
|
470
|
+
}
|
|
471
|
+
for (let l = 0; l < this.idMatrix.length; l++) {
|
|
472
|
+
const a = this.idMatrix[l];
|
|
473
|
+
for (let h = 0; h < a.length; h++) {
|
|
474
|
+
const u = a[h], n = _({ y: l, x: h });
|
|
475
|
+
if (this.addressCaches.set(u, n), u === t)
|
|
476
|
+
return {
|
|
477
|
+
y: l + e,
|
|
478
|
+
x: h + s,
|
|
479
|
+
absCol: i,
|
|
480
|
+
absRow: r
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
return { y: -1, x: -1, absCol: i, absRow: r };
|
|
485
|
+
}
|
|
486
|
+
/** @internal */
|
|
487
|
+
getAddressById(t, e = 0, s = 0) {
|
|
488
|
+
const { y: i, x: r, absCol: o, absRow: l } = this.getPointById(t, e, s);
|
|
489
|
+
return Ct(_({ y: i, x: r }), o, l);
|
|
490
|
+
}
|
|
491
|
+
/** @internal */
|
|
492
|
+
clearAddressCaches() {
|
|
493
|
+
this.addressCaches.clear();
|
|
494
|
+
}
|
|
495
|
+
/** @internal */
|
|
496
|
+
_warmAddressCaches() {
|
|
497
|
+
for (let t = 0; t < this.idMatrix.length; t++) {
|
|
498
|
+
const e = this.idMatrix[t];
|
|
499
|
+
for (let s = 0; s < e.length; s++)
|
|
500
|
+
this.addressCaches.set(e[s], _({ y: t, x: s }));
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
/** @internal */
|
|
504
|
+
getId(t) {
|
|
505
|
+
var i;
|
|
506
|
+
const { y: e, x: s } = t;
|
|
507
|
+
return (i = this.idMatrix[e]) == null ? void 0 : i[s];
|
|
508
|
+
}
|
|
509
|
+
/** @internal */
|
|
510
|
+
getCell(t, { resolution: e = "RESOLVED", raise: s = !1 } = {}) {
|
|
511
|
+
var h;
|
|
512
|
+
const { y: i, x: r } = t;
|
|
513
|
+
if (i === -1 || r === -1)
|
|
514
|
+
return;
|
|
515
|
+
const o = (h = this.idMatrix[i]) == null ? void 0 : h[r];
|
|
516
|
+
if (o == null)
|
|
517
|
+
return;
|
|
518
|
+
const l = this.registry.data[o];
|
|
519
|
+
if (l == null)
|
|
520
|
+
return;
|
|
521
|
+
let a = l.value;
|
|
522
|
+
return e !== "SYSTEM" && (l.formulaEnabled ?? !0) && (a = tt({ value: a, sheet: this, point: t, raise: s, resolution: e, at: o })), { ...l, value: a };
|
|
523
|
+
}
|
|
524
|
+
/** @internal */
|
|
525
|
+
get numRows() {
|
|
526
|
+
const { top: t, bottom: e } = this.area;
|
|
527
|
+
return 1 + e - t;
|
|
528
|
+
}
|
|
529
|
+
get numCols() {
|
|
530
|
+
const { left: t, right: e } = this.area;
|
|
531
|
+
return 1 + e - t;
|
|
532
|
+
}
|
|
533
|
+
get top() {
|
|
534
|
+
return this.area.top;
|
|
535
|
+
}
|
|
536
|
+
get left() {
|
|
537
|
+
return this.area.left;
|
|
538
|
+
}
|
|
539
|
+
get bottom() {
|
|
540
|
+
return this.area.bottom;
|
|
541
|
+
}
|
|
542
|
+
get right() {
|
|
543
|
+
return this.area.right;
|
|
544
|
+
}
|
|
545
|
+
/** @internal */
|
|
546
|
+
_toValueMatrix({
|
|
547
|
+
area: t,
|
|
548
|
+
at: e,
|
|
549
|
+
resolution: s = "RESOLVED",
|
|
550
|
+
raise: i = !1,
|
|
551
|
+
filter: r = Yt,
|
|
552
|
+
asScalar: o = !1
|
|
553
|
+
} = {}) {
|
|
554
|
+
const { top: l, left: a, bottom: h, right: u } = t ?? this.area, n = St(h - l + 1, u - a + 1);
|
|
555
|
+
for (let f = l; f <= h; f++)
|
|
556
|
+
for (let d = a; d <= u; d++) {
|
|
557
|
+
const p = this.getId({ y: f, x: d });
|
|
558
|
+
if (e === p)
|
|
559
|
+
throw new z("#REF!", "References are circulating.");
|
|
560
|
+
const y = this.getCell({ y: f, x: d }, { resolution: s, raise: i }) ?? {};
|
|
561
|
+
if (r(y)) {
|
|
562
|
+
let c = y.value;
|
|
563
|
+
o && (c = this.getPolicy({ y: f, x: d }).toScalar({ value: y.value, cell: y, sheet: this, point: { y: f, x: d } })), n[f - l][d - a] = c;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
return n;
|
|
567
|
+
}
|
|
568
|
+
/** @internal */
|
|
569
|
+
_pushHistory(t) {
|
|
570
|
+
const e = this.registry;
|
|
571
|
+
if (e.histories.splice(e.historyIndex + 1, e.histories.length).forEach(this._cleanStrayed.bind(this)), e.histories.push(t), e.lastHistory = e.currentHistory = t, e.histories.length > e.historyLimit) {
|
|
572
|
+
const i = e.histories.splice(0, 1)[0];
|
|
573
|
+
this._cleanObsolete(i);
|
|
574
|
+
} else
|
|
575
|
+
e.historyIndex++;
|
|
576
|
+
}
|
|
577
|
+
/** @internal */
|
|
578
|
+
_cleanObsolete(t) {
|
|
579
|
+
(t.operation === "REMOVE_ROWS" || t.operation === "REMOVE_COLS") && t.deleted.forEach((e) => {
|
|
580
|
+
e.forEach((s) => {
|
|
581
|
+
this._deleteOrphanedId(s);
|
|
582
|
+
});
|
|
583
|
+
}), t.operation === "MOVE" && t.moveRelations.forEach((e) => {
|
|
584
|
+
e.new != null && this._deleteOrphanedId(e.new), e.lost != null && this._deleteOrphanedId(e.lost);
|
|
585
|
+
});
|
|
586
|
+
}
|
|
587
|
+
/** @internal */
|
|
588
|
+
_cleanStrayed(t) {
|
|
589
|
+
(t.operation === "INSERT_ROWS" || t.operation === "INSERT_COLS") && t.idMatrix.forEach((e) => {
|
|
590
|
+
e.forEach((s) => {
|
|
591
|
+
this._deleteOrphanedId(s);
|
|
592
|
+
});
|
|
593
|
+
});
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Remove an id from registry.data and registry.dependents entirely.
|
|
597
|
+
* @internal
|
|
598
|
+
*/
|
|
599
|
+
_deleteOrphanedId(t) {
|
|
600
|
+
var s;
|
|
601
|
+
const e = this.registry.systems[t];
|
|
602
|
+
(s = e == null ? void 0 : e.dependencies) == null || s.forEach((i) => {
|
|
603
|
+
var r, o;
|
|
604
|
+
(o = (r = this.registry.systems[i]) == null ? void 0 : r.dependents) == null || o.delete(t);
|
|
605
|
+
}), delete this.registry.data[t], delete this.registry.systems[t];
|
|
606
|
+
}
|
|
607
|
+
/** @internal */
|
|
608
|
+
_copyCellLayout(t) {
|
|
609
|
+
if (t == null)
|
|
610
|
+
return;
|
|
611
|
+
const e = {};
|
|
612
|
+
return t.style != null && (e.style = t.style), t.justifyContent != null && (e.justifyContent = t.justifyContent), t.alignItems != null && (e.alignItems = t.alignItems), t.policy != null && (e.policy = t.policy), t.width != null && (e.width = t.width), t.height != null && (e.height = t.height), e;
|
|
613
|
+
}
|
|
614
|
+
move({
|
|
615
|
+
srcSheet: t = this,
|
|
616
|
+
src: e,
|
|
617
|
+
dst: s,
|
|
618
|
+
historicize: i = !0,
|
|
619
|
+
operator: r = "SYSTEM",
|
|
620
|
+
undoReflection: o,
|
|
621
|
+
redoReflection: l
|
|
622
|
+
}) {
|
|
623
|
+
const a = t.__raw__, h = this._createMoveRelations(a, e, this, s), { diffBefore: u, diffAfter: n } = this._moveCells(a, this, h, !1, r);
|
|
624
|
+
return this._xsheetDispatch(a), i && this._pushHistory({
|
|
625
|
+
applyed: !0,
|
|
626
|
+
operation: "MOVE",
|
|
627
|
+
srcSheetId: a.id,
|
|
628
|
+
dstSheetId: this.id,
|
|
629
|
+
undoReflection: o,
|
|
630
|
+
redoReflection: l,
|
|
631
|
+
diffBefore: u,
|
|
632
|
+
diffAfter: n,
|
|
633
|
+
moveRelations: h
|
|
634
|
+
}), this.refresh(!0);
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Build MoveRelations from src area to dst area, skipping filtered rows.
|
|
638
|
+
*
|
|
639
|
+
* Layout of the returned array (processed in this order by _moveCells):
|
|
640
|
+
* 1. Entries where [0] is a newly-generated ID — these fill the vacated src cells (processed last in forward order)
|
|
641
|
+
* 2. Entries where [0] is a src address and [1] is a dst address — the actual moves (processed first in forward order, descending)
|
|
642
|
+
* Entries whose [1] is an existing ID mean the destination cell is displaced/overflowed and
|
|
643
|
+
* is no longer addressable; on forward pass they are skipped; on reverse pass the ID is written back.
|
|
644
|
+
*/
|
|
645
|
+
/** @internal */
|
|
646
|
+
_createMoveRelations(t, e, s, i) {
|
|
647
|
+
const { top: r, left: o, bottom: l, right: a } = e, { top: h, left: u } = i, n = s.numRows, f = s.numCols, d = [];
|
|
648
|
+
for (let m = r; m <= l; m++)
|
|
649
|
+
t.isRowFiltered(m) || d.push(m);
|
|
650
|
+
const p = a - o + 1, y = d.length, c = [];
|
|
651
|
+
{
|
|
652
|
+
let m = 0, x = h;
|
|
653
|
+
for (; m < y; )
|
|
654
|
+
s.isRowFiltered(x) || (c.push(x), m++), x++;
|
|
655
|
+
}
|
|
656
|
+
const g = /* @__PURE__ */ new Set();
|
|
657
|
+
for (let m = 0; m < y; m++)
|
|
658
|
+
for (let x = 0; x < p; x++)
|
|
659
|
+
g.add(_({ y: d[m], x: o + x }));
|
|
660
|
+
const R = /* @__PURE__ */ new Set();
|
|
661
|
+
for (let m = 0; m < y; m++) {
|
|
662
|
+
const x = c[m];
|
|
663
|
+
for (let C = 0; C < p; C++) {
|
|
664
|
+
const I = u + C;
|
|
665
|
+
x <= n && I <= f && R.add(_({ y: x, x: I }));
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
const S = [];
|
|
669
|
+
for (let m = 0; m < y; m++) {
|
|
670
|
+
const x = d[m], C = c[m];
|
|
671
|
+
for (let I = 0; I < p; I++) {
|
|
672
|
+
const w = o + I, v = u + I, T = _({ y: x, x: w }), b = C <= n && v <= f, D = b ? _({ y: C, x: v }) : void 0;
|
|
673
|
+
let O;
|
|
674
|
+
t === s && R.has(T) || (O = t._generateId());
|
|
675
|
+
let F;
|
|
676
|
+
if (b) {
|
|
677
|
+
if (!(t === s && g.has(D))) {
|
|
678
|
+
const M = s.getId({ y: C, x: v });
|
|
679
|
+
M != null && (F = M);
|
|
680
|
+
}
|
|
681
|
+
} else {
|
|
682
|
+
const M = t.getId({ y: x, x: w });
|
|
683
|
+
M != null && (F = M);
|
|
684
|
+
}
|
|
685
|
+
const N = t.getCell({ y: x, x: w }, { resolution: "SYSTEM" }), E = b ? s.getCell({ y: C, x: v }, { resolution: "SYSTEM" }) : void 0;
|
|
686
|
+
S.push({
|
|
687
|
+
before: N == null ? void 0 : N.policy,
|
|
688
|
+
after: E == null ? void 0 : E.policy,
|
|
689
|
+
src: T,
|
|
690
|
+
dst: D,
|
|
691
|
+
new: O,
|
|
692
|
+
lost: F
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return S;
|
|
697
|
+
}
|
|
698
|
+
get defaultPolicy() {
|
|
699
|
+
return this.policies[B] ?? Ft;
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Apply (or reverse) a MoveRelations list.
|
|
703
|
+
*
|
|
704
|
+
* Forward (reverse=false): process descending — actual ID moves happen bottom-up so
|
|
705
|
+
* earlier entries don't clobber later ones; vacate entries (at front of array) are
|
|
706
|
+
* applied last.
|
|
707
|
+
* Reverse (reverse=true): process ascending — restores IDs in the natural order.
|
|
708
|
+
*
|
|
709
|
+
* On forward pass: applies policy, collects diffBefore, runs ReferencePreserver.
|
|
710
|
+
* On reverse pass: only moves IDs (caller is responsible for applyDiff(diffBefore)).
|
|
711
|
+
*/
|
|
712
|
+
/** @internal */
|
|
713
|
+
_moveCells(t, e, s, i, r = "SYSTEM") {
|
|
714
|
+
const o = {}, l = new L(e), a = {}, h = [], u = [];
|
|
715
|
+
if (i)
|
|
716
|
+
for (const {
|
|
717
|
+
before: y,
|
|
718
|
+
after: c,
|
|
719
|
+
src: g,
|
|
720
|
+
dst: R,
|
|
721
|
+
new: S,
|
|
722
|
+
lost: m
|
|
723
|
+
} of s) {
|
|
724
|
+
if (R != null) {
|
|
725
|
+
const x = A(R), C = e.getId(x);
|
|
726
|
+
if (C != null) {
|
|
727
|
+
const I = A(g);
|
|
728
|
+
h.push({ y: I.y, x: I.x, id: C });
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
if (m != null)
|
|
732
|
+
if (R != null) {
|
|
733
|
+
const x = A(R);
|
|
734
|
+
u.push({ y: x.y, x: x.x, id: m });
|
|
735
|
+
} else {
|
|
736
|
+
const x = A(g);
|
|
737
|
+
h.push({ y: x.y, x: x.x, id: m });
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
else
|
|
741
|
+
for (const {
|
|
742
|
+
before: y,
|
|
743
|
+
after: c,
|
|
744
|
+
src: g,
|
|
745
|
+
dst: R,
|
|
746
|
+
new: S,
|
|
747
|
+
lost: m
|
|
748
|
+
} of s) {
|
|
749
|
+
const x = A(g), C = t.getId(x), I = R != null ? A(R) : void 0, w = I != null ? e.getId(I) : void 0, v = C != null ? t.registry.data[C] : void 0, T = w != null ? e.registry.data[w] : void 0;
|
|
750
|
+
if (!(r === "USER" && (Y(v == null ? void 0 : v.prevention, ht) || Y(T == null ? void 0 : T.prevention, lt)))) {
|
|
751
|
+
if (S != null) {
|
|
752
|
+
const b = y || B, O = (t.policies[b] ?? t.defaultPolicy).select({
|
|
753
|
+
sheet: t,
|
|
754
|
+
point: x,
|
|
755
|
+
next: { value: null },
|
|
756
|
+
current: v,
|
|
757
|
+
operation: ht
|
|
758
|
+
});
|
|
759
|
+
a[S] = {
|
|
760
|
+
...O,
|
|
761
|
+
policy: y
|
|
762
|
+
}, this.registry.systems[S] = { id: S, sheetId: t.id, changedTime: Date.now() }, h.push({ y: x.y, x: x.x, id: S });
|
|
763
|
+
}
|
|
764
|
+
if (w != null && I != null && R != null) {
|
|
765
|
+
const b = c || B, D = y || B, O = e.policies[b] ?? e.defaultPolicy, F = t.policies[D] ?? t.defaultPolicy, N = F.priority > O.priority, M = (N ? F : O).select({
|
|
766
|
+
sheet: e,
|
|
767
|
+
point: I,
|
|
768
|
+
next: v,
|
|
769
|
+
current: T,
|
|
770
|
+
operation: lt
|
|
771
|
+
});
|
|
772
|
+
if (M && (o[C] = v ?? {}, a[C] = {
|
|
773
|
+
...v,
|
|
774
|
+
...M,
|
|
775
|
+
policy: N ? y : c
|
|
776
|
+
}), v != null) {
|
|
777
|
+
const H = this.registry.systems[C];
|
|
778
|
+
H && (H.changedTime = Date.now());
|
|
779
|
+
}
|
|
780
|
+
u.push({ y: I.y, x: I.x, id: C });
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
const n = i ? null : t.idMatrix.flat(), f = !i && t !== e ? e.idMatrix.flat() : null;
|
|
785
|
+
Object.assign(this.registry.data, a);
|
|
786
|
+
for (const { y, x: c, id: g } of h)
|
|
787
|
+
t.idMatrix[y][c] = g;
|
|
788
|
+
for (const { y, x: c, id: g } of u)
|
|
789
|
+
e.idMatrix[y][c] = g;
|
|
790
|
+
const d = s.filter((y) => y.dst != null).map((y) => y.dst), p = s.map((y) => y.src);
|
|
791
|
+
if (t === e ? e.lastChangedAddresses = [.../* @__PURE__ */ new Set([...p, ...d])] : (e.lastChangedAddresses = d, t.lastChangedAddresses = p), !i) {
|
|
792
|
+
l.buildMap(n.flat(), t.idMatrix.flat()), t !== e && l.buildMap(f.flat(), e.idMatrix.flat());
|
|
793
|
+
const y = l.resolveDependents("move");
|
|
794
|
+
Object.assign(o, y);
|
|
795
|
+
}
|
|
796
|
+
return { diffBefore: o, diffAfter: {} };
|
|
797
|
+
}
|
|
798
|
+
copy({
|
|
799
|
+
srcSheet: t = this,
|
|
800
|
+
src: e,
|
|
801
|
+
dst: s,
|
|
802
|
+
onlyValue: i = !1,
|
|
803
|
+
operator: r = "SYSTEM",
|
|
804
|
+
undoReflection: o,
|
|
805
|
+
redoReflection: l
|
|
806
|
+
}) {
|
|
807
|
+
const a = t !== this, { top: h, left: u, bottom: n, right: f } = e, { top: d, left: p, bottom: y, right: c } = s, g = {}, R = Date.now(), S = [];
|
|
808
|
+
for (let w = h; w <= n; w++)
|
|
809
|
+
t.isRowFiltered(w) || S.push(w);
|
|
810
|
+
const m = [];
|
|
811
|
+
for (let w = d; w <= y; w++)
|
|
812
|
+
w > this.numRows || this.isRowFiltered(w) || m.push(w);
|
|
813
|
+
const x = S.length, C = f - u + 1, I = c - p + 1;
|
|
814
|
+
for (let w = 0; w < m.length; w++) {
|
|
815
|
+
const v = m[w], T = S[w % x];
|
|
816
|
+
for (let b = 0; b <= I - 1; b++) {
|
|
817
|
+
const D = p + b;
|
|
818
|
+
if (D > this.numCols)
|
|
819
|
+
continue;
|
|
820
|
+
const O = u + b % C, F = a ? 0 : v - T, N = a ? 0 : D - O, E = {
|
|
821
|
+
...t.getCell({ y: T, x: O }, { resolution: "SYSTEM" })
|
|
822
|
+
}, M = { y: v, x: D }, H = this.getCell(M, { resolution: "SYSTEM" }), ft = this.getPolicy(M), G = { y: T, x: O }, ut = t.getPolicy(G), j = t.getCell(G, { resolution: "SYSTEM" }), yt = ut.priority > ft.priority;
|
|
823
|
+
E.policy = yt ? j == null ? void 0 : j.policy : H == null ? void 0 : H.policy;
|
|
824
|
+
const q = this.getId(M);
|
|
825
|
+
this.clearDependencies(q);
|
|
826
|
+
const pt = (E == null ? void 0 : E.formulaEnabled) ?? !0 ? this.processFormula(E == null ? void 0 : E.value, {
|
|
827
|
+
dependency: q,
|
|
828
|
+
slideY: F,
|
|
829
|
+
slideX: N
|
|
830
|
+
}) : E == null ? void 0 : E.value, gt = this.getId(M), J = this.registry.systems[gt];
|
|
831
|
+
J != null && (J.changedTime = R);
|
|
832
|
+
const mt = _(M);
|
|
833
|
+
if (i) {
|
|
834
|
+
const P = this.getCell(M, { resolution: "SYSTEM" });
|
|
835
|
+
E.style = P == null ? void 0 : P.style, E.justifyContent = P == null ? void 0 : P.justifyContent, E.alignItems = P == null ? void 0 : P.alignItems;
|
|
836
|
+
}
|
|
837
|
+
g[mt] = { ...E, value: pt };
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
return this.update({
|
|
841
|
+
diff: g,
|
|
842
|
+
partial: !1,
|
|
843
|
+
operator: r,
|
|
844
|
+
operation: bt,
|
|
845
|
+
undoReflection: o,
|
|
846
|
+
redoReflection: l
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
getPolicy(t) {
|
|
850
|
+
const e = this.getCell(t, { resolution: "SYSTEM" });
|
|
851
|
+
return (e == null ? void 0 : e.policy) == null ? this.defaultPolicy : this.policies[e.policy] ?? this.defaultPolicy;
|
|
852
|
+
}
|
|
853
|
+
/** @internal */
|
|
854
|
+
_update({
|
|
855
|
+
diff: t,
|
|
856
|
+
partial: e = !0,
|
|
857
|
+
updateChangedTime: s = !0,
|
|
858
|
+
ignoreFields: i = ["label"],
|
|
859
|
+
operator: r = "SYSTEM",
|
|
860
|
+
operation: o = X,
|
|
861
|
+
formulaIdentify: l = !0
|
|
862
|
+
}) {
|
|
863
|
+
const a = {}, h = {}, u = [], n = Date.now();
|
|
864
|
+
let f = !1;
|
|
865
|
+
return Object.keys(t).forEach((d) => {
|
|
866
|
+
var m, x, C, I;
|
|
867
|
+
const p = A(d), y = this.getId(p), c = this.registry.data[y];
|
|
868
|
+
if (r === "USER" && Y(c == null ? void 0 : c.prevention, X))
|
|
869
|
+
return;
|
|
870
|
+
let g = { ...t[d] };
|
|
871
|
+
if (l && (g.formulaEnabled ?? (c == null ? void 0 : c.formulaEnabled) ?? !0) && (this.clearDependencies(y), g.value = this.processFormula(g.value, { dependency: y })), i.forEach((w) => {
|
|
872
|
+
g[w] = c == null ? void 0 : c[w];
|
|
873
|
+
}), r === "USER" && Y(c == null ? void 0 : c.prevention, K) && delete g.value, r === "USER" && Y(c == null ? void 0 : c.prevention, Tt) && ((m = g == null ? void 0 : g.style) == null || delete m.justifyContent, (x = g == null ? void 0 : g.style) == null || delete x.alignItems), r === "USER" && Y(c == null ? void 0 : c.prevention, Ot) && ((C = g == null ? void 0 : g.style) == null || delete C.width, (I = g == null ? void 0 : g.style) == null || delete I.height), (g.width != null || g.height != null) && (f = !0), a[y] = c ?? {}, g = { ...(this.policies[(c == null ? void 0 : c.policy) || B] ?? this.defaultPolicy).select({
|
|
874
|
+
sheet: this,
|
|
875
|
+
point: p,
|
|
876
|
+
next: g,
|
|
877
|
+
current: c,
|
|
878
|
+
operation: o
|
|
879
|
+
}) }, s) {
|
|
880
|
+
const w = this.registry.systems[y];
|
|
881
|
+
w != null && (w.changedTime = n);
|
|
882
|
+
}
|
|
883
|
+
if (e) {
|
|
884
|
+
const w = { ...c, ...g };
|
|
885
|
+
this.registry.data[y] = w, h[y] = w;
|
|
886
|
+
} else
|
|
887
|
+
this.registry.data[y] = g, h[y] = g;
|
|
888
|
+
u.push(d);
|
|
889
|
+
}), this.lastChangedAddresses = u, {
|
|
890
|
+
diffBefore: a,
|
|
891
|
+
diffAfter: h,
|
|
892
|
+
resized: f
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
update({
|
|
896
|
+
diff: t,
|
|
897
|
+
partial: e = !0,
|
|
898
|
+
updateChangedTime: s = !0,
|
|
899
|
+
historicize: i = !0,
|
|
900
|
+
operator: r = "SYSTEM",
|
|
901
|
+
operation: o = X,
|
|
902
|
+
ignoreFields: l,
|
|
903
|
+
undoReflection: a,
|
|
904
|
+
redoReflection: h
|
|
905
|
+
}) {
|
|
906
|
+
const { diffBefore: u, diffAfter: n, resized: f } = this._update({
|
|
907
|
+
diff: t,
|
|
908
|
+
partial: e,
|
|
909
|
+
operator: r,
|
|
910
|
+
operation: o,
|
|
911
|
+
updateChangedTime: s,
|
|
912
|
+
...l != null ? { ignoreFields: l } : {}
|
|
913
|
+
});
|
|
914
|
+
return i && this._pushHistory({
|
|
915
|
+
applyed: !0,
|
|
916
|
+
operation: "UPDATE",
|
|
917
|
+
srcSheetId: this.id,
|
|
918
|
+
dstSheetId: this.id,
|
|
919
|
+
undoReflection: a,
|
|
920
|
+
redoReflection: h,
|
|
921
|
+
diffBefore: u,
|
|
922
|
+
diffAfter: n,
|
|
923
|
+
partial: e
|
|
924
|
+
}), this.refresh(!1, f);
|
|
925
|
+
}
|
|
926
|
+
/** @internal */
|
|
927
|
+
writeRawCellMatrix({
|
|
928
|
+
point: t,
|
|
929
|
+
matrix: e,
|
|
930
|
+
updateChangedTime: s = !0,
|
|
931
|
+
historicize: i = !0,
|
|
932
|
+
onlyValue: r = !1,
|
|
933
|
+
operator: o = "SYSTEM",
|
|
934
|
+
undoReflection: l,
|
|
935
|
+
redoReflection: a
|
|
936
|
+
}) {
|
|
937
|
+
const { y: h, x: u } = t, n = {};
|
|
938
|
+
let f = 0, d = h;
|
|
939
|
+
for (; f < e.length && !(d > this.bottom); ) {
|
|
940
|
+
if (this.isRowFiltered(d)) {
|
|
941
|
+
d++;
|
|
942
|
+
continue;
|
|
943
|
+
}
|
|
944
|
+
e[f].forEach((y, c) => {
|
|
945
|
+
const g = u + c;
|
|
946
|
+
if (g > this.right)
|
|
947
|
+
return;
|
|
948
|
+
const R = { y: d, x: g }, S = this.parse(R, y.value ?? "");
|
|
949
|
+
if (S.style = { ...y.style, ...S.style }, r) {
|
|
950
|
+
const m = this.getCell(R, { resolution: "SYSTEM" });
|
|
951
|
+
S.style = m == null ? void 0 : m.style, S.justifyContent = m == null ? void 0 : m.justifyContent, S.alignItems = m == null ? void 0 : m.alignItems;
|
|
952
|
+
}
|
|
953
|
+
n[_(R)] = S;
|
|
954
|
+
}), f++, d++;
|
|
955
|
+
}
|
|
956
|
+
return this.update({
|
|
957
|
+
diff: n,
|
|
958
|
+
partial: !0,
|
|
959
|
+
updateChangedTime: s,
|
|
960
|
+
historicize: i,
|
|
961
|
+
operator: o,
|
|
962
|
+
operation: K,
|
|
963
|
+
undoReflection: l,
|
|
964
|
+
redoReflection: a
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
writeMatrix(t) {
|
|
968
|
+
const e = t.matrix.map((s) => s.map((i) => ({ value: i })));
|
|
969
|
+
return this.writeRawCellMatrix({ ...t, matrix: e });
|
|
970
|
+
}
|
|
971
|
+
write(t) {
|
|
972
|
+
const { point: e, value: s } = t, i = this.parse(e, s ?? ""), r = this.getCell(e, { resolution: "RAW" });
|
|
973
|
+
if (((r == null ? void 0 : r.value) ?? null) === i.value)
|
|
974
|
+
return this;
|
|
975
|
+
const o = { [_(e)]: i };
|
|
976
|
+
return this.update({
|
|
977
|
+
...t,
|
|
978
|
+
diff: o,
|
|
979
|
+
partial: !0,
|
|
980
|
+
operation: K
|
|
981
|
+
});
|
|
982
|
+
}
|
|
983
|
+
insertRows({
|
|
984
|
+
y: t,
|
|
985
|
+
numRows: e,
|
|
986
|
+
baseY: s,
|
|
987
|
+
diff: i,
|
|
988
|
+
partial: r,
|
|
989
|
+
updateChangedTime: o,
|
|
990
|
+
operator: l = "SYSTEM",
|
|
991
|
+
undoReflection: a,
|
|
992
|
+
redoReflection: h
|
|
993
|
+
}) {
|
|
994
|
+
if (this.maxNumRows !== -1 && this.numRows + e > this.maxNumRows)
|
|
995
|
+
return console.error(`Rows are limited to ${this.maxNumRows}.`), this;
|
|
996
|
+
const u = this.numCols, n = [], f = Date.now();
|
|
997
|
+
for (let d = 0; d < e; d++) {
|
|
998
|
+
const p = [];
|
|
999
|
+
for (let y = 0; y <= u; y++) {
|
|
1000
|
+
const c = this._generateId();
|
|
1001
|
+
p.push(c);
|
|
1002
|
+
const g = this.getCell({ y: s, x: y }, { resolution: "SYSTEM" }), R = this._copyCellLayout(g);
|
|
1003
|
+
this.registry.data[c] = { ...R }, this.registry.systems[c] = { id: c, sheetId: this.id, changedTime: f };
|
|
1004
|
+
}
|
|
1005
|
+
n.push(p);
|
|
1006
|
+
}
|
|
1007
|
+
if (this.idMatrix.splice(t, 0, ...n), this.area.bottom += e, this._pushHistory({
|
|
1008
|
+
applyed: !0,
|
|
1009
|
+
operation: "INSERT_ROWS",
|
|
1010
|
+
srcSheetId: this.id,
|
|
1011
|
+
dstSheetId: this.id,
|
|
1012
|
+
undoReflection: a,
|
|
1013
|
+
redoReflection: h,
|
|
1014
|
+
y: t,
|
|
1015
|
+
numRows: e,
|
|
1016
|
+
idMatrix: n
|
|
1017
|
+
}), i && Object.assign(this.registry.lastHistory, this._update({ diff: i, partial: r, updateChangedTime: o, operator: l }), {
|
|
1018
|
+
partial: r
|
|
1019
|
+
}), this.registry.onInsertRows) {
|
|
1020
|
+
const d = this.clone();
|
|
1021
|
+
d.area = {
|
|
1022
|
+
top: t,
|
|
1023
|
+
bottom: t + e - 1,
|
|
1024
|
+
left: this.area.left,
|
|
1025
|
+
right: this.area.right
|
|
1026
|
+
}, d.addressCaches = /* @__PURE__ */ new Map(), this.registry.onInsertRows({ sheet: d, y: t, numRows: e });
|
|
1027
|
+
}
|
|
1028
|
+
return this.refresh(!0, !0);
|
|
1029
|
+
}
|
|
1030
|
+
removeRows({
|
|
1031
|
+
y: t,
|
|
1032
|
+
numRows: e,
|
|
1033
|
+
operator: s = "SYSTEM",
|
|
1034
|
+
undoReflection: i,
|
|
1035
|
+
redoReflection: r
|
|
1036
|
+
}) {
|
|
1037
|
+
if (this.minNumRows !== -1 && this.numRows - e < this.minNumRows)
|
|
1038
|
+
return console.error(`At least ${this.minNumRows} row(s) are required.`), this;
|
|
1039
|
+
const o = new L(this), l = [], a = this.idMatrix.map((n) => [...n]);
|
|
1040
|
+
for (let n = t; n < t + e; n++) {
|
|
1041
|
+
const f = this.getCell({ y: n, x: 0 }, { resolution: "SYSTEM" });
|
|
1042
|
+
if (s === "USER" && Y(f == null ? void 0 : f.prevention, At))
|
|
1043
|
+
return console.warn(`Cannot delete row ${n}.`), this;
|
|
1044
|
+
for (let d = 1; d <= this.numCols; d++) {
|
|
1045
|
+
const p = this.getId({ y: n, x: d });
|
|
1046
|
+
p != null && (o.collectDependents(p), o.map[p] = this.getId({ y: n + e, x: d }));
|
|
1047
|
+
}
|
|
1048
|
+
l.unshift(n);
|
|
1049
|
+
}
|
|
1050
|
+
const h = [];
|
|
1051
|
+
l.forEach((n) => {
|
|
1052
|
+
const f = this.idMatrix.splice(n, 1);
|
|
1053
|
+
h.unshift(f[0]);
|
|
1054
|
+
}), this.area.bottom -= l.length;
|
|
1055
|
+
const u = o.resolveDependents("removeRows");
|
|
1056
|
+
if (this._pushHistory({
|
|
1057
|
+
applyed: !0,
|
|
1058
|
+
operation: "REMOVE_ROWS",
|
|
1059
|
+
srcSheetId: this.id,
|
|
1060
|
+
dstSheetId: this.id,
|
|
1061
|
+
undoReflection: i,
|
|
1062
|
+
redoReflection: r,
|
|
1063
|
+
ys: l.reverse(),
|
|
1064
|
+
diffBefore: u,
|
|
1065
|
+
deleted: h
|
|
1066
|
+
}), this.registry.onRemoveRows) {
|
|
1067
|
+
const n = this.clone();
|
|
1068
|
+
n.idMatrix = a, n.area = {
|
|
1069
|
+
top: t,
|
|
1070
|
+
bottom: t + e - 1,
|
|
1071
|
+
left: this.area.left,
|
|
1072
|
+
right: this.area.right
|
|
1073
|
+
}, n.addressCaches = /* @__PURE__ */ new Map(), this.registry.onRemoveRows({ sheet: n, ys: l.reverse() });
|
|
1074
|
+
}
|
|
1075
|
+
return this.refresh(!0, !0);
|
|
1076
|
+
}
|
|
1077
|
+
insertCols({
|
|
1078
|
+
x: t,
|
|
1079
|
+
numCols: e,
|
|
1080
|
+
baseX: s,
|
|
1081
|
+
diff: i,
|
|
1082
|
+
partial: r,
|
|
1083
|
+
updateChangedTime: o,
|
|
1084
|
+
operator: l = "SYSTEM",
|
|
1085
|
+
undoReflection: a,
|
|
1086
|
+
redoReflection: h
|
|
1087
|
+
}) {
|
|
1088
|
+
if (this.maxNumCols !== -1 && this.numCols + e > this.maxNumCols)
|
|
1089
|
+
return console.error(`Columns are limited to ${this.maxNumCols}.`), this;
|
|
1090
|
+
const u = this.numRows, n = [], f = Date.now();
|
|
1091
|
+
for (let d = 0; d <= u; d++) {
|
|
1092
|
+
const p = [];
|
|
1093
|
+
for (let y = 0; y < e; y++) {
|
|
1094
|
+
const c = this._generateId();
|
|
1095
|
+
p.push(c);
|
|
1096
|
+
const g = this.getCell({ y: d, x: s }, { resolution: "SYSTEM" }), R = this._copyCellLayout(g);
|
|
1097
|
+
this.idMatrix[d].splice(t, 0, c), this.registry.data[c] = { ...R }, this.registry.systems[c] = { id: c, sheetId: this.id, changedTime: f };
|
|
1098
|
+
}
|
|
1099
|
+
n.push(p);
|
|
1100
|
+
}
|
|
1101
|
+
if (this.area.right += e, this._pushHistory({
|
|
1102
|
+
applyed: !0,
|
|
1103
|
+
operation: "INSERT_COLS",
|
|
1104
|
+
srcSheetId: this.id,
|
|
1105
|
+
dstSheetId: this.id,
|
|
1106
|
+
undoReflection: a,
|
|
1107
|
+
redoReflection: h,
|
|
1108
|
+
x: t,
|
|
1109
|
+
numCols: e,
|
|
1110
|
+
idMatrix: n
|
|
1111
|
+
}), i && Object.assign(this.registry.lastHistory, this._update({ diff: i, partial: r, updateChangedTime: o, operator: l }), {
|
|
1112
|
+
partial: r
|
|
1113
|
+
}), this.registry.onInsertCols) {
|
|
1114
|
+
const d = this.clone();
|
|
1115
|
+
d.area = {
|
|
1116
|
+
top: this.area.top,
|
|
1117
|
+
bottom: this.area.bottom,
|
|
1118
|
+
left: t,
|
|
1119
|
+
right: t + e - 1
|
|
1120
|
+
}, d.addressCaches = /* @__PURE__ */ new Map(), this.registry.onInsertCols({ sheet: d, x: t, numCols: e });
|
|
1121
|
+
}
|
|
1122
|
+
return this.refresh(!0, !0);
|
|
1123
|
+
}
|
|
1124
|
+
removeCols({
|
|
1125
|
+
x: t,
|
|
1126
|
+
numCols: e,
|
|
1127
|
+
operator: s = "SYSTEM",
|
|
1128
|
+
undoReflection: i,
|
|
1129
|
+
redoReflection: r
|
|
1130
|
+
}) {
|
|
1131
|
+
if (this.minNumCols !== -1 && this.numCols - e < this.minNumCols)
|
|
1132
|
+
return console.error(`At least ${this.minNumCols} column(s) are required.`), this;
|
|
1133
|
+
const o = new L(this), l = [], a = this.idMatrix.map((n) => [...n]);
|
|
1134
|
+
for (let n = t; n < t + e; n++) {
|
|
1135
|
+
const f = this.getCell({ y: 0, x: n }, { resolution: "SYSTEM" });
|
|
1136
|
+
if (s === "USER" && Y(f == null ? void 0 : f.prevention, Dt)) {
|
|
1137
|
+
console.warn(`Cannot delete col ${n}.`);
|
|
1138
|
+
continue;
|
|
1139
|
+
}
|
|
1140
|
+
for (let d = 1; d <= this.numRows; d++) {
|
|
1141
|
+
const p = this.getId({ y: d, x: n });
|
|
1142
|
+
p != null && (o.collectDependents(p), o.map[p] = this.getId({ y: d, x: n + e }));
|
|
1143
|
+
}
|
|
1144
|
+
l.unshift(n);
|
|
1145
|
+
}
|
|
1146
|
+
const h = [];
|
|
1147
|
+
this.idMatrix.forEach((n) => {
|
|
1148
|
+
const f = [];
|
|
1149
|
+
h.push(f), l.forEach((d) => {
|
|
1150
|
+
f.unshift(...n.splice(d, 1));
|
|
1151
|
+
});
|
|
1152
|
+
}), this.area.right -= l.length;
|
|
1153
|
+
const u = o.resolveDependents("removeCols");
|
|
1154
|
+
if (this._pushHistory({
|
|
1155
|
+
applyed: !0,
|
|
1156
|
+
operation: "REMOVE_COLS",
|
|
1157
|
+
srcSheetId: this.id,
|
|
1158
|
+
dstSheetId: this.id,
|
|
1159
|
+
undoReflection: i,
|
|
1160
|
+
redoReflection: r,
|
|
1161
|
+
xs: l.reverse(),
|
|
1162
|
+
diffBefore: u,
|
|
1163
|
+
deleted: h
|
|
1164
|
+
}), this.registry.onRemoveCols) {
|
|
1165
|
+
const n = this.clone();
|
|
1166
|
+
n.idMatrix = a, n.area = {
|
|
1167
|
+
top: this.area.top,
|
|
1168
|
+
bottom: this.area.bottom,
|
|
1169
|
+
left: t,
|
|
1170
|
+
right: t + e - 1
|
|
1171
|
+
}, n.addressCaches = /* @__PURE__ */ new Map(), this.registry.onRemoveCols({ sheet: n, xs: l.reverse() });
|
|
1172
|
+
}
|
|
1173
|
+
return this.refresh(!0, !0);
|
|
1174
|
+
}
|
|
1175
|
+
/** @internal */
|
|
1176
|
+
histories() {
|
|
1177
|
+
return [...this.registry.histories];
|
|
1178
|
+
}
|
|
1179
|
+
/** @internal */
|
|
1180
|
+
historyIndex() {
|
|
1181
|
+
return this.registry.historyIndex;
|
|
1182
|
+
}
|
|
1183
|
+
/** @internal */
|
|
1184
|
+
historySize() {
|
|
1185
|
+
return this.registry.histories.length;
|
|
1186
|
+
}
|
|
1187
|
+
/** @internal */
|
|
1188
|
+
getHistoryLimit() {
|
|
1189
|
+
return this.registry.historyLimit;
|
|
1190
|
+
}
|
|
1191
|
+
/** @internal */
|
|
1192
|
+
parse(t, e) {
|
|
1193
|
+
const s = this.getCell(t, { resolution: "SYSTEM" }) ?? {};
|
|
1194
|
+
return this.getPolicy(t).deserializeValue(e, s);
|
|
1195
|
+
}
|
|
1196
|
+
/** @internal */
|
|
1197
|
+
render(t) {
|
|
1198
|
+
const { point: e, apply: s } = t;
|
|
1199
|
+
return this.getId(e), this.getPolicy(e).render({ sheet: this, point: e, apply: s, value: void 0 });
|
|
1200
|
+
}
|
|
1201
|
+
getSerializedValue({
|
|
1202
|
+
point: t,
|
|
1203
|
+
cell: e,
|
|
1204
|
+
resolution: s = "RESOLVED"
|
|
1205
|
+
}) {
|
|
1206
|
+
var o, l;
|
|
1207
|
+
if (e == null) {
|
|
1208
|
+
const a = (o = this.idMatrix[t.y]) == null ? void 0 : o[t.x];
|
|
1209
|
+
e = a != null ? this.registry.data[a] : void 0;
|
|
1210
|
+
}
|
|
1211
|
+
if (e == null)
|
|
1212
|
+
return "";
|
|
1213
|
+
const i = this.getPolicy(t), r = e.value;
|
|
1214
|
+
if (typeof r == "string" && r[0] === "=") {
|
|
1215
|
+
if (s === "SYSTEM")
|
|
1216
|
+
return r;
|
|
1217
|
+
if (s === "RAW") {
|
|
1218
|
+
const a = new Q(r.substring(1));
|
|
1219
|
+
return a.tokenize(), "=" + a.display({ sheet: this });
|
|
1220
|
+
}
|
|
1221
|
+
try {
|
|
1222
|
+
const a = (l = this.idMatrix[t.y]) == null ? void 0 : l[t.x], h = tt({ value: r, sheet: this, point: t, raise: !0, resolution: s, at: a }), u = et({ value: h, raise: !1 });
|
|
1223
|
+
return i.serialize({ value: u, cell: e, sheet: this, point: t });
|
|
1224
|
+
} catch (a) {
|
|
1225
|
+
return i.serialize({ value: a, cell: e, sheet: this, point: t });
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
return i.serialize({ value: r, cell: e, sheet: this, point: t });
|
|
1229
|
+
}
|
|
1230
|
+
/** @internal */
|
|
1231
|
+
trim(t) {
|
|
1232
|
+
const e = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
|
|
1233
|
+
return e.area = t, e;
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* Solve all formulas in this sheet and return a 2D matrix of resolved values.
|
|
1237
|
+
* @internal
|
|
1238
|
+
*/
|
|
1239
|
+
solve({ raise: t = !1, at: e }) {
|
|
1240
|
+
return Et({ sheet: this, raise: t, at: e });
|
|
1241
|
+
}
|
|
1242
|
+
/**
|
|
1243
|
+
* Collapse this sheet to a scalar (top-left cell value).
|
|
1244
|
+
* @internal
|
|
1245
|
+
*/
|
|
1246
|
+
strip({ raise: t = !1, at: e }) {
|
|
1247
|
+
return et({ value: this, raise: t, at: e });
|
|
1248
|
+
}
|
|
1249
|
+
/** @internal */
|
|
1250
|
+
_applyDiff(t = {}, e = !0) {
|
|
1251
|
+
const s = Object.keys(t);
|
|
1252
|
+
s.forEach((r) => {
|
|
1253
|
+
const o = t[r] ?? {};
|
|
1254
|
+
let l;
|
|
1255
|
+
e ? (l = { ...this.registry.data[r] }, Object.keys(o).forEach((h) => {
|
|
1256
|
+
o[h] === void 0 ? delete l[h] : l[h] = o[h];
|
|
1257
|
+
})) : l = { ...o };
|
|
1258
|
+
const a = this.registry.systems[r];
|
|
1259
|
+
a != null && (a.changedTime = Date.now()), this.registry.data[r] = l, this.clearDependencies(r), this.processFormula(l.value, { dependency: r });
|
|
1260
|
+
}), this._warmAddressCaches();
|
|
1261
|
+
const i = [];
|
|
1262
|
+
for (const r of s) {
|
|
1263
|
+
const o = this.getAddressById(r);
|
|
1264
|
+
o && i.push(o);
|
|
1265
|
+
}
|
|
1266
|
+
this.lastChangedAddresses = i;
|
|
1267
|
+
}
|
|
1268
|
+
undo() {
|
|
1269
|
+
if (this.registry.historyIndex < 0)
|
|
1270
|
+
return { history: null, newSheet: this.__raw__ };
|
|
1271
|
+
const t = this.registry.histories[this.registry.historyIndex--];
|
|
1272
|
+
t.applyed = !1, this.registry.currentHistory = this.registry.histories[this.registry.historyIndex];
|
|
1273
|
+
const e = this.getSheetBySheetId(t.srcSheetId), s = this.getSheetBySheetId(t.dstSheetId);
|
|
1274
|
+
if (!s)
|
|
1275
|
+
return { history: null, newSheet: this.__raw__ };
|
|
1276
|
+
switch (t.operation) {
|
|
1277
|
+
case "UPDATE":
|
|
1278
|
+
s._applyDiff(t.diffBefore, t.partial ?? !1);
|
|
1279
|
+
break;
|
|
1280
|
+
case "INSERT_ROWS": {
|
|
1281
|
+
t.diffBefore && s._applyDiff(t.diffBefore, !1);
|
|
1282
|
+
const { rows: i } = W({ matrix: t.idMatrix });
|
|
1283
|
+
s.idMatrix.splice(t.y, i), s.area.bottom -= i;
|
|
1284
|
+
break;
|
|
1285
|
+
}
|
|
1286
|
+
case "INSERT_COLS": {
|
|
1287
|
+
t.diffBefore && s._applyDiff(t.diffBefore, !1);
|
|
1288
|
+
const { cols: i } = W({ matrix: t.idMatrix });
|
|
1289
|
+
s.idMatrix.forEach((r) => {
|
|
1290
|
+
r.splice(t.x, i);
|
|
1291
|
+
}), s.area.right -= i;
|
|
1292
|
+
break;
|
|
1293
|
+
}
|
|
1294
|
+
case "REMOVE_ROWS": {
|
|
1295
|
+
const { ys: i, deleted: r } = t;
|
|
1296
|
+
i.forEach((o, l) => {
|
|
1297
|
+
s.idMatrix.splice(o, 0, r[l]);
|
|
1298
|
+
}), s.area.bottom += i.length, this._applyDiff(t.diffBefore, !1);
|
|
1299
|
+
break;
|
|
1300
|
+
}
|
|
1301
|
+
case "REMOVE_COLS": {
|
|
1302
|
+
const { xs: i, deleted: r } = t;
|
|
1303
|
+
s.idMatrix.forEach((o, l) => {
|
|
1304
|
+
for (let a = 0; a < i.length; a++)
|
|
1305
|
+
o.splice(i[a], 0, r[l][a]);
|
|
1306
|
+
}), s.area.right += i.length, this._applyDiff(t.diffBefore, !1);
|
|
1307
|
+
break;
|
|
1308
|
+
}
|
|
1309
|
+
case "MOVE": {
|
|
1310
|
+
e && this._moveCells(e, s, t.moveRelations, !0);
|
|
1311
|
+
const i = s.lastChangedAddresses;
|
|
1312
|
+
s._applyDiff(t.diffBefore, !1), s.lastChangedAddresses = [.../* @__PURE__ */ new Set([...i, ...s.lastChangedAddresses])];
|
|
1313
|
+
break;
|
|
1314
|
+
}
|
|
1315
|
+
case "SORT_ROWS": {
|
|
1316
|
+
const i = s.idMatrix.flat();
|
|
1317
|
+
s._sortRowMapping(t.sortedRowMapping, !0);
|
|
1318
|
+
const r = new L(s);
|
|
1319
|
+
r.buildMap(i, s.idMatrix.flat()), r.resolveDependents(), s._reapplyFilters();
|
|
1320
|
+
break;
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
return this.refresh(dt(t.operation), !0), s !== this && (s.addressCaches.clear(), s.setTotalSize()), t.operation === "MOVE" && e && e !== s && this._xsheetDispatch(e), {
|
|
1324
|
+
history: t,
|
|
1325
|
+
callback: ({ sheetReactive: i }) => {
|
|
1326
|
+
var r, o;
|
|
1327
|
+
(o = i.current) == null || o.registry.transmit((r = t.undoReflection) == null ? void 0 : r.transmit);
|
|
1328
|
+
}
|
|
1329
|
+
};
|
|
1330
|
+
}
|
|
1331
|
+
redo() {
|
|
1332
|
+
if (this.registry.historyIndex + 1 >= this.registry.histories.length)
|
|
1333
|
+
return { history: null, newSheet: this.__raw__ };
|
|
1334
|
+
const t = this.registry.histories[++this.registry.historyIndex];
|
|
1335
|
+
t.applyed = !0, this.registry.currentHistory = t;
|
|
1336
|
+
const e = this.getSheetBySheetId(t.srcSheetId), s = this.getSheetBySheetId(t.dstSheetId);
|
|
1337
|
+
if (!s)
|
|
1338
|
+
return { history: null, newSheet: this.__raw__ };
|
|
1339
|
+
switch (t.operation) {
|
|
1340
|
+
case "UPDATE":
|
|
1341
|
+
s._applyDiff(t.diffAfter, t.partial ?? !1);
|
|
1342
|
+
break;
|
|
1343
|
+
case "INSERT_ROWS": {
|
|
1344
|
+
t.diffAfter && s._applyDiff(t.diffAfter, !1);
|
|
1345
|
+
const { rows: i } = W({ matrix: t.idMatrix });
|
|
1346
|
+
s.idMatrix.splice(t.y, 0, ...t.idMatrix), s.area.bottom += i;
|
|
1347
|
+
break;
|
|
1348
|
+
}
|
|
1349
|
+
case "INSERT_COLS": {
|
|
1350
|
+
t.diffAfter && s._applyDiff(t.diffAfter, !1);
|
|
1351
|
+
const { cols: i } = W({ matrix: t.idMatrix });
|
|
1352
|
+
s.idMatrix.map((r, o) => {
|
|
1353
|
+
r.splice(t.x, 0, ...t.idMatrix[o]);
|
|
1354
|
+
}), s.area.right += i;
|
|
1355
|
+
break;
|
|
1356
|
+
}
|
|
1357
|
+
case "REMOVE_ROWS": {
|
|
1358
|
+
s.removeRows({
|
|
1359
|
+
y: t.ys[0],
|
|
1360
|
+
numRows: t.ys.length,
|
|
1361
|
+
operator: "SYSTEM",
|
|
1362
|
+
undoReflection: t.undoReflection,
|
|
1363
|
+
redoReflection: t.redoReflection
|
|
1364
|
+
});
|
|
1365
|
+
break;
|
|
1366
|
+
}
|
|
1367
|
+
case "REMOVE_COLS": {
|
|
1368
|
+
s.removeCols({
|
|
1369
|
+
x: t.xs[0],
|
|
1370
|
+
numCols: t.xs.length,
|
|
1371
|
+
operator: "SYSTEM",
|
|
1372
|
+
undoReflection: t.undoReflection,
|
|
1373
|
+
redoReflection: t.redoReflection
|
|
1374
|
+
});
|
|
1375
|
+
break;
|
|
1376
|
+
}
|
|
1377
|
+
case "MOVE": {
|
|
1378
|
+
e && this._moveCells(e, s, t.moveRelations, !1);
|
|
1379
|
+
break;
|
|
1380
|
+
}
|
|
1381
|
+
case "SORT_ROWS": {
|
|
1382
|
+
const i = s.idMatrix.flat();
|
|
1383
|
+
s._sortRowMapping(t.sortedRowMapping, !1);
|
|
1384
|
+
const r = new L(s);
|
|
1385
|
+
r.buildMap(i, s.idMatrix.flat()), r.resolveDependents(), s._reapplyFilters();
|
|
1386
|
+
break;
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
return this.refresh(dt(t.operation), !0), s !== this && (s.addressCaches.clear(), s.setTotalSize()), t.operation === "MOVE" && e && e !== s && this._xsheetDispatch(e), {
|
|
1390
|
+
history: t,
|
|
1391
|
+
callback: ({ sheetReactive: i }) => {
|
|
1392
|
+
var r, o;
|
|
1393
|
+
(o = i.current) == null || o.registry.transmit((r = t.redoReflection) == null ? void 0 : r.transmit);
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
}
|
|
1397
|
+
/** @internal */
|
|
1398
|
+
getFunctionByName(t) {
|
|
1399
|
+
return this.registry.functions[t];
|
|
1400
|
+
}
|
|
1401
|
+
/** @internal */
|
|
1402
|
+
clearDependencies(t) {
|
|
1403
|
+
var s;
|
|
1404
|
+
const e = this.registry.systems[t];
|
|
1405
|
+
(s = e == null ? void 0 : e.dependencies) == null || s.forEach((i) => {
|
|
1406
|
+
var r, o;
|
|
1407
|
+
(o = (r = this.registry.systems[i]) == null ? void 0 : r.dependents) == null || o.delete(t);
|
|
1408
|
+
}), e != null && (e.dependencies = /* @__PURE__ */ new Set());
|
|
1409
|
+
}
|
|
1410
|
+
/** @internal */
|
|
1411
|
+
addDependency(t, e) {
|
|
1412
|
+
const s = k(this.registry, t);
|
|
1413
|
+
s.dependents == null && (s.dependents = /* @__PURE__ */ new Set()), s.dependents.add(e);
|
|
1414
|
+
const i = k(this.registry, e);
|
|
1415
|
+
i.dependencies == null && (i.dependencies = /* @__PURE__ */ new Set()), i.dependencies.add(t);
|
|
1416
|
+
}
|
|
1417
|
+
/** @internal */
|
|
1418
|
+
getSolvedCache(t) {
|
|
1419
|
+
const e = this.getId(t);
|
|
1420
|
+
return [this.registry.solvedCaches.has(e), this.registry.solvedCaches.get(e)];
|
|
1421
|
+
}
|
|
1422
|
+
/** @internal */
|
|
1423
|
+
setSolvingCache(t) {
|
|
1424
|
+
const e = this.getId(t);
|
|
1425
|
+
this.registry.solvedCaches.set(e, at), k(this.registry, e, { tmpAsyncCaches: {} });
|
|
1426
|
+
}
|
|
1427
|
+
/** @internal */
|
|
1428
|
+
finishSolvedCache(t, e) {
|
|
1429
|
+
if (at.is(e))
|
|
1430
|
+
return;
|
|
1431
|
+
const s = this.getId(t);
|
|
1432
|
+
this.registry.solvedCaches.set(s, e);
|
|
1433
|
+
const i = this.registry.data[s];
|
|
1434
|
+
if (i == null)
|
|
1435
|
+
return;
|
|
1436
|
+
const r = this.registry.systems[s], o = r == null ? void 0 : r.tmpAsyncCaches;
|
|
1437
|
+
o != null && (Object.keys(o).length > 0 ? i.asyncCaches = o : delete i.asyncCaches, delete r.tmpAsyncCaches);
|
|
1438
|
+
}
|
|
1439
|
+
/** @internal */
|
|
1440
|
+
clearSolvedCaches() {
|
|
1441
|
+
this.registry.solvedCaches.clear();
|
|
1442
|
+
for (const t of this.registry.lastSpilledTargetIds) {
|
|
1443
|
+
const e = this.registry.systems[t];
|
|
1444
|
+
(e == null ? void 0 : e.spilledFrom) != null && delete e.spilledFrom;
|
|
1445
|
+
}
|
|
1446
|
+
this.registry.lastSpilledTargetIds.clear();
|
|
1447
|
+
}
|
|
1448
|
+
/**
|
|
1449
|
+
* Spill a 2D matrix of values starting from the origin cell.
|
|
1450
|
+
* The origin cell receives matrix[0][0] and adjacent cells receive spill values in solvedCaches.
|
|
1451
|
+
* For a 1×1 matrix, no spill occurs — the single value is cached directly.
|
|
1452
|
+
* Throws FormulaError('#REF!') if the spill range is obstructed.
|
|
1453
|
+
*
|
|
1454
|
+
* @param origin The anchor cell that produced the spill.
|
|
1455
|
+
* @param matrix The 2D array of resolved scalar values.
|
|
1456
|
+
* @returns The top-left value (matrix[0][0]).
|
|
1457
|
+
* @internal
|
|
1458
|
+
*/
|
|
1459
|
+
spill(t, e) {
|
|
1460
|
+
var l;
|
|
1461
|
+
const s = e.length, i = s > 0 ? e[0].length : 0;
|
|
1462
|
+
if (s <= 1 && i <= 1)
|
|
1463
|
+
return (l = e[0]) == null ? void 0 : l[0];
|
|
1464
|
+
for (let a = 0; a < s; a++)
|
|
1465
|
+
for (let h = 0; h < i; h++) {
|
|
1466
|
+
if (a === 0 && h === 0)
|
|
1467
|
+
continue;
|
|
1468
|
+
const u = { y: t.y + a, x: t.x + h }, n = this.getId(u), f = _(u);
|
|
1469
|
+
if (n == null) {
|
|
1470
|
+
console.warn(`Spill target ${f} is out of bounds.`);
|
|
1471
|
+
continue;
|
|
1472
|
+
}
|
|
1473
|
+
const d = this.registry.data[n];
|
|
1474
|
+
if ((d == null ? void 0 : d.value) != null && d.value !== "")
|
|
1475
|
+
throw new z(
|
|
1476
|
+
"#REF!",
|
|
1477
|
+
`Array result was not expanded because it would overwrite data in ${f}.`
|
|
1478
|
+
);
|
|
1479
|
+
if (this.registry.solvedCaches.has(n))
|
|
1480
|
+
throw new z(
|
|
1481
|
+
"#REF!",
|
|
1482
|
+
`Array result was not expanded because ${f} is already occupied by another formula.`
|
|
1483
|
+
);
|
|
1484
|
+
}
|
|
1485
|
+
const r = this.getId(t), o = [];
|
|
1486
|
+
for (let a = 0; a < s; a++)
|
|
1487
|
+
for (let h = 0; h < i; h++) {
|
|
1488
|
+
const u = { y: t.y + a, x: t.x + h }, n = this.getId(u);
|
|
1489
|
+
if (n != null && (this.finishSolvedCache(u, e[a][h]), (a !== 0 || h !== 0) && (o.push(_(u)), r != null && this.registry.data[n] != null))) {
|
|
1490
|
+
const d = k(this.registry, n, {});
|
|
1491
|
+
d.spilledFrom = _(t), this.registry.lastSpilledTargetIds.add(n);
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
return e[0][0];
|
|
1495
|
+
}
|
|
1496
|
+
/** @internal */
|
|
1497
|
+
sheetPrefix(t = !1) {
|
|
1498
|
+
return t ? "" : vt(this.name);
|
|
1499
|
+
}
|
|
1500
|
+
/** @internal */
|
|
1501
|
+
rangeToArea(t) {
|
|
1502
|
+
const e = t.split(":");
|
|
1503
|
+
let [s, i] = e;
|
|
1504
|
+
s.match(/[a-zA-Z]$/) && (s += "1"), s.match(/^[1-9]/) && (s = `A${s}`), i != null && i.match(/[a-zA-Z]$/) && (i += this.bottom), i != null && i.match(/^[1-9]/) && (i = `${Z(this.right)}${i}`);
|
|
1505
|
+
const { y: r, x: o } = A(s), { y: l, x: a } = A(i || s);
|
|
1506
|
+
return {
|
|
1507
|
+
top: Math.abs(r),
|
|
1508
|
+
left: Math.abs(o),
|
|
1509
|
+
bottom: Math.abs(l),
|
|
1510
|
+
right: Math.abs(a)
|
|
1511
|
+
};
|
|
1512
|
+
}
|
|
1513
|
+
get __raw__() {
|
|
1514
|
+
return this;
|
|
1515
|
+
}
|
|
1516
|
+
get shape() {
|
|
1517
|
+
return Rt(this.area);
|
|
1518
|
+
}
|
|
1519
|
+
get hasSingleCell() {
|
|
1520
|
+
const t = this.shape;
|
|
1521
|
+
return t.rows === 1 && t.cols === 1;
|
|
1522
|
+
}
|
|
1523
|
+
get currentVersion() {
|
|
1524
|
+
return this.version;
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
export {
|
|
1528
|
+
V as Sheet
|
|
1529
|
+
};
|
|
1530
|
+
//# sourceMappingURL=sheet.js.map
|