@gridsheet/react-core 0.12.3 → 0.12.4-rc.1

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.
Files changed (200) hide show
  1. package/dist/components/Cell.d.ts.map +1 -1
  2. package/dist/components/Cell.js +200 -181
  3. package/dist/components/Cell.js.map +1 -1
  4. package/dist/components/ContextMenu.js +211 -194
  5. package/dist/components/ContextMenu.js.map +1 -1
  6. package/dist/components/Editor.js +280 -263
  7. package/dist/components/Editor.js.map +1 -1
  8. package/dist/components/Emitter.js +41 -24
  9. package/dist/components/Emitter.js.map +1 -1
  10. package/dist/components/GridSheet.d.ts.map +1 -1
  11. package/dist/components/GridSheet.js +142 -105
  12. package/dist/components/GridSheet.js.map +1 -1
  13. package/dist/components/HeaderLeftCell.js +76 -60
  14. package/dist/components/HeaderLeftCell.js.map +1 -1
  15. package/dist/components/HeaderTopCell.js +77 -61
  16. package/dist/components/HeaderTopCell.js.map +1 -1
  17. package/dist/components/Resizer.d.ts.map +1 -1
  18. package/dist/components/Resizer.js +94 -75
  19. package/dist/components/Resizer.js.map +1 -1
  20. package/dist/components/SearchBox.d.ts.map +1 -1
  21. package/dist/components/SearchBox.js +68 -49
  22. package/dist/components/SearchBox.js.map +1 -1
  23. package/dist/components/StoreInitializer.js +83 -66
  24. package/dist/components/StoreInitializer.js.map +1 -1
  25. package/dist/components/Tabular.js +98 -80
  26. package/dist/components/Tabular.js.map +1 -1
  27. package/dist/constants.d.ts.map +1 -1
  28. package/dist/constants.js +36 -19
  29. package/dist/constants.js.map +1 -1
  30. package/dist/formula/evaluator.js +500 -474
  31. package/dist/formula/evaluator.js.map +1 -1
  32. package/dist/formula/functions/__base.js +27 -13
  33. package/dist/formula/functions/__base.js.map +1 -1
  34. package/dist/formula/functions/__utils.js +113 -95
  35. package/dist/formula/functions/__utils.js.map +1 -1
  36. package/dist/formula/functions/abs.js +31 -17
  37. package/dist/formula/functions/abs.js.map +1 -1
  38. package/dist/formula/functions/abs.spec.js +35 -23
  39. package/dist/formula/functions/abs.spec.js.map +1 -1
  40. package/dist/formula/functions/acos.js +38 -24
  41. package/dist/formula/functions/acos.js.map +1 -1
  42. package/dist/formula/functions/add.js +57 -43
  43. package/dist/formula/functions/add.js.map +1 -1
  44. package/dist/formula/functions/and.js +38 -24
  45. package/dist/formula/functions/and.js.map +1 -1
  46. package/dist/formula/functions/asin.js +38 -24
  47. package/dist/formula/functions/asin.js.map +1 -1
  48. package/dist/formula/functions/atan.js +36 -22
  49. package/dist/formula/functions/atan.js.map +1 -1
  50. package/dist/formula/functions/atan2.js +42 -28
  51. package/dist/formula/functions/atan2.js.map +1 -1
  52. package/dist/formula/functions/average.js +50 -36
  53. package/dist/formula/functions/average.js.map +1 -1
  54. package/dist/formula/functions/col.js +38 -24
  55. package/dist/formula/functions/col.js.map +1 -1
  56. package/dist/formula/functions/concat.js +37 -23
  57. package/dist/formula/functions/concat.js.map +1 -1
  58. package/dist/formula/functions/concatenate.js +35 -21
  59. package/dist/formula/functions/concatenate.js.map +1 -1
  60. package/dist/formula/functions/cos.js +36 -22
  61. package/dist/formula/functions/cos.js.map +1 -1
  62. package/dist/formula/functions/count.js +45 -31
  63. package/dist/formula/functions/count.js.map +1 -1
  64. package/dist/formula/functions/counta.js +45 -31
  65. package/dist/formula/functions/counta.js.map +1 -1
  66. package/dist/formula/functions/countif.js +40 -26
  67. package/dist/formula/functions/countif.js.map +1 -1
  68. package/dist/formula/functions/divide.js +42 -28
  69. package/dist/formula/functions/divide.js.map +1 -1
  70. package/dist/formula/functions/eq.js +35 -21
  71. package/dist/formula/functions/eq.js.map +1 -1
  72. package/dist/formula/functions/exp.js +38 -24
  73. package/dist/formula/functions/exp.js.map +1 -1
  74. package/dist/formula/functions/gt.js +37 -23
  75. package/dist/formula/functions/gt.js.map +1 -1
  76. package/dist/formula/functions/gte.js +37 -23
  77. package/dist/formula/functions/gte.js.map +1 -1
  78. package/dist/formula/functions/hlookup.js +77 -63
  79. package/dist/formula/functions/hlookup.js.map +1 -1
  80. package/dist/formula/functions/if.js +46 -32
  81. package/dist/formula/functions/if.js.map +1 -1
  82. package/dist/formula/functions/iferror.js +48 -34
  83. package/dist/formula/functions/iferror.js.map +1 -1
  84. package/dist/formula/functions/iferror.spec.js +63 -51
  85. package/dist/formula/functions/iferror.spec.js.map +1 -1
  86. package/dist/formula/functions/len.js +36 -22
  87. package/dist/formula/functions/len.js.map +1 -1
  88. package/dist/formula/functions/lenb.js +36 -22
  89. package/dist/formula/functions/lenb.js.map +1 -1
  90. package/dist/formula/functions/ln.js +38 -24
  91. package/dist/formula/functions/ln.js.map +1 -1
  92. package/dist/formula/functions/log.js +43 -29
  93. package/dist/formula/functions/log.js.map +1 -1
  94. package/dist/formula/functions/log10.js +38 -24
  95. package/dist/formula/functions/log10.js.map +1 -1
  96. package/dist/formula/functions/lt.js +37 -23
  97. package/dist/formula/functions/lt.js.map +1 -1
  98. package/dist/formula/functions/lte.js +37 -23
  99. package/dist/formula/functions/lte.js.map +1 -1
  100. package/dist/formula/functions/max.js +52 -38
  101. package/dist/formula/functions/max.js.map +1 -1
  102. package/dist/formula/functions/min.js +52 -38
  103. package/dist/formula/functions/min.js.map +1 -1
  104. package/dist/formula/functions/minus.js +57 -43
  105. package/dist/formula/functions/minus.js.map +1 -1
  106. package/dist/formula/functions/mod.js +40 -26
  107. package/dist/formula/functions/mod.js.map +1 -1
  108. package/dist/formula/functions/mod.spec.js +58 -46
  109. package/dist/formula/functions/mod.spec.js.map +1 -1
  110. package/dist/formula/functions/multiply.js +37 -23
  111. package/dist/formula/functions/multiply.js.map +1 -1
  112. package/dist/formula/functions/ne.js +35 -21
  113. package/dist/formula/functions/ne.js.map +1 -1
  114. package/dist/formula/functions/not.js +40 -26
  115. package/dist/formula/functions/not.js.map +1 -1
  116. package/dist/formula/functions/now.js +31 -17
  117. package/dist/formula/functions/now.js.map +1 -1
  118. package/dist/formula/functions/or.js +38 -24
  119. package/dist/formula/functions/or.js.map +1 -1
  120. package/dist/formula/functions/pi.js +29 -15
  121. package/dist/formula/functions/pi.js.map +1 -1
  122. package/dist/formula/functions/power.js +34 -20
  123. package/dist/formula/functions/power.js.map +1 -1
  124. package/dist/formula/functions/product.js +47 -33
  125. package/dist/formula/functions/product.js.map +1 -1
  126. package/dist/formula/functions/radians.js +36 -22
  127. package/dist/formula/functions/radians.js.map +1 -1
  128. package/dist/formula/functions/rand.js +29 -15
  129. package/dist/formula/functions/rand.js.map +1 -1
  130. package/dist/formula/functions/round.js +44 -30
  131. package/dist/formula/functions/round.js.map +1 -1
  132. package/dist/formula/functions/rounddown.js +44 -30
  133. package/dist/formula/functions/rounddown.js.map +1 -1
  134. package/dist/formula/functions/roundup.js +44 -30
  135. package/dist/formula/functions/roundup.js.map +1 -1
  136. package/dist/formula/functions/row.js +38 -24
  137. package/dist/formula/functions/row.js.map +1 -1
  138. package/dist/formula/functions/sin.js +36 -22
  139. package/dist/formula/functions/sin.js.map +1 -1
  140. package/dist/formula/functions/sqrt.js +38 -24
  141. package/dist/formula/functions/sqrt.js.map +1 -1
  142. package/dist/formula/functions/sum.js +52 -38
  143. package/dist/formula/functions/sum.js.map +1 -1
  144. package/dist/formula/functions/sum.spec.js +45 -33
  145. package/dist/formula/functions/sum.spec.js.map +1 -1
  146. package/dist/formula/functions/sumif.js +66 -52
  147. package/dist/formula/functions/sumif.js.map +1 -1
  148. package/dist/formula/functions/tan.js +36 -22
  149. package/dist/formula/functions/tan.js.map +1 -1
  150. package/dist/formula/functions/uminus.js +33 -19
  151. package/dist/formula/functions/uminus.js.map +1 -1
  152. package/dist/formula/functions/vlookup.js +77 -63
  153. package/dist/formula/functions/vlookup.js.map +1 -1
  154. package/dist/formula/mapping.js +126 -113
  155. package/dist/formula/mapping.js.map +1 -1
  156. package/dist/formula/solver.js +71 -56
  157. package/dist/formula/solver.js.map +1 -1
  158. package/dist/index.js +41 -10
  159. package/dist/index.js.map +1 -1
  160. package/dist/lib/autofill.js +344 -330
  161. package/dist/lib/autofill.js.map +1 -1
  162. package/dist/lib/clipboard.js +55 -41
  163. package/dist/lib/clipboard.js.map +1 -1
  164. package/dist/lib/converters.js +140 -119
  165. package/dist/lib/converters.js.map +1 -1
  166. package/dist/lib/structs.js +266 -228
  167. package/dist/lib/structs.js.map +1 -1
  168. package/dist/lib/table.js +915 -900
  169. package/dist/lib/table.js.map +1 -1
  170. package/dist/lib/time.js +69 -55
  171. package/dist/lib/time.js.map +1 -1
  172. package/dist/lib/virtualization.d.ts +10 -1
  173. package/dist/lib/virtualization.d.ts.map +1 -1
  174. package/dist/lib/virtualization.js +126 -103
  175. package/dist/lib/virtualization.js.map +1 -1
  176. package/dist/parsers/core.js +119 -105
  177. package/dist/parsers/core.js.map +1 -1
  178. package/dist/renderers/checkbox.js +24 -8
  179. package/dist/renderers/checkbox.js.map +1 -1
  180. package/dist/renderers/core.js +139 -125
  181. package/dist/renderers/core.js.map +1 -1
  182. package/dist/renderers/thousand_separator.js +25 -12
  183. package/dist/renderers/thousand_separator.js.map +1 -1
  184. package/dist/store/actions.d.ts.map +1 -1
  185. package/dist/store/actions.js +498 -479
  186. package/dist/store/actions.js.map +1 -1
  187. package/dist/store/helpers.js +88 -72
  188. package/dist/store/helpers.js.map +1 -1
  189. package/dist/store/index.js +38 -2
  190. package/dist/store/index.js.map +1 -1
  191. package/dist/styles/embedder.js +27 -13
  192. package/dist/styles/embedder.js.map +1 -1
  193. package/dist/styles/minified.js +16 -3
  194. package/dist/styles/minified.js.map +1 -1
  195. package/dist/types.d.ts +4 -4
  196. package/dist/types.d.ts.map +1 -1
  197. package/dist/types.js +12 -1
  198. package/dist/utils.js +19 -5
  199. package/dist/utils.js.map +1 -1
  200. package/package.json +1 -1
package/dist/lib/table.js CHANGED
@@ -1,299 +1,251 @@
1
- import { defaultParser } from "../parsers/core";
2
- import { defaultRenderer } from "../renderers/core";
3
- import { areaShape, createMatrix, matrixShape, putMatrix } from "./structs";
4
- import { a2p, x2c, p2a, y2r, grantAddressAbsolute } from "./converters";
5
- import { functions as functionsDefault } from "../formula/mapping";
6
- import { convertFormulaAbsolute, Lexer } from "../formula/evaluator";
7
- import { solveFormula } from "../formula/solver";
8
- import { DEFAULT_HEIGHT, DEFAULT_WIDTH, HISTORY_LIMIT } from "../constants";
9
- import { shouldTracking } from "../store/helpers";
10
- const cellFilter = (cell) => true;
11
- export class Table {
12
- constructor({ numRows = 0, numCols = 0, cells = {}, parsers = {}, renderers = {}, labelers = {}, useBigInt = false, historyLimit: historyLimit = HISTORY_LIMIT, minNumRows = 1, maxNumRows = -1, minNumCols = 1, maxNumCols = -1, headerWidth = -1, headerHeight = -1, functions = functionsDefault, }) {
13
- this.totalWidth = 0;
14
- this.totalHeight = 0;
15
- this.headerWidth = 0;
16
- this.headerHeight = 0;
17
- this.functions = {};
18
- this.head = useBigInt ? BigInt(0) : 0;
19
- this.data = {};
20
- this.area = { top: 0, left: 0, bottom: numRows, right: numCols };
21
- this.parsers = parsers;
22
- this.renderers = renderers;
23
- this.labelers = labelers;
24
- this.idMatrix = [];
25
- this.histories = [];
26
- this.historyIndex = -1;
27
- this.addressesById = {};
28
- this.historyLimit = historyLimit;
29
- this.changedAt = new Date();
30
- this.minNumRows = minNumRows;
31
- this.maxNumRows = maxNumRows;
32
- this.minNumCols = minNumCols;
33
- this.maxNumCols = maxNumCols;
34
- this.solvedCaches = {};
35
- this.headerHeight = headerHeight;
36
- this.headerWidth = headerWidth;
37
- this.functions = functions;
38
- const common = cells.default;
39
- // make idMatrix beforehand
40
- for (let y = 0; y < numRows + 1; y++) {
41
- const ids = [];
42
- this.idMatrix.push(ids);
43
- for (let x = 0; x < numCols + 1; x++) {
44
- const id = this.generateId();
45
- ids.push(id);
46
- const address = p2a({ y, x });
47
- this.addressesById[id] = address;
48
- }
49
- }
50
- for (let y = 0; y < numRows + 1; y++) {
51
- const rowId = y2r(y);
52
- const rowDefault = cells[rowId];
53
- for (let x = 0; x < numCols + 1; x++) {
54
- const id = this.getId({ y, x });
55
- const address = p2a({ y, x });
56
- const colId = x2c(x);
57
- const colDefault = cells[colId];
58
- const cell = cells[address];
59
- const stacked = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, common), rowDefault), colDefault), cell), { style: Object.assign(Object.assign(Object.assign(Object.assign({}, common === null || common === void 0 ? void 0 : common.style), rowDefault === null || rowDefault === void 0 ? void 0 : rowDefault.style), colDefault === null || colDefault === void 0 ? void 0 : colDefault.style), cell === null || cell === void 0 ? void 0 : cell.style) });
60
- stacked.value = convertFormulaAbsolute({
61
- value: stacked === null || stacked === void 0 ? void 0 : stacked.value,
62
- table: this,
63
- });
64
- if (y === 0) {
65
- if (stacked.width == null) {
66
- stacked.width = DEFAULT_WIDTH;
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports", "../parsers/core", "../renderers/core", "./structs", "./converters", "../formula/mapping", "../formula/evaluator", "../formula/solver", "../constants", "../store/helpers"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ReadonlyTable = exports.Table = void 0;
13
+ const core_1 = require("../parsers/core");
14
+ const core_2 = require("../renderers/core");
15
+ const structs_1 = require("./structs");
16
+ const converters_1 = require("./converters");
17
+ const mapping_1 = require("../formula/mapping");
18
+ const evaluator_1 = require("../formula/evaluator");
19
+ const solver_1 = require("../formula/solver");
20
+ const constants_1 = require("../constants");
21
+ const helpers_1 = require("../store/helpers");
22
+ const cellFilter = (cell) => true;
23
+ class Table {
24
+ constructor({ numRows = 0, numCols = 0, cells = {}, parsers = {}, renderers = {}, labelers = {}, useBigInt = false, historyLimit: historyLimit = constants_1.HISTORY_LIMIT, minNumRows = 1, maxNumRows = -1, minNumCols = 1, maxNumCols = -1, headerWidth = -1, headerHeight = -1, functions = mapping_1.functions, }) {
25
+ this.totalWidth = 0;
26
+ this.totalHeight = 0;
27
+ this.headerWidth = 0;
28
+ this.headerHeight = 0;
29
+ this.functions = {};
30
+ this.head = useBigInt ? BigInt(0) : 0;
31
+ this.data = {};
32
+ this.area = { top: 0, left: 0, bottom: numRows, right: numCols };
33
+ this.parsers = parsers;
34
+ this.renderers = renderers;
35
+ this.labelers = labelers;
36
+ this.idMatrix = [];
37
+ this.histories = [];
38
+ this.historyIndex = -1;
39
+ this.addressesById = {};
40
+ this.historyLimit = historyLimit;
41
+ this.changedAt = new Date();
42
+ this.minNumRows = minNumRows;
43
+ this.maxNumRows = maxNumRows;
44
+ this.minNumCols = minNumCols;
45
+ this.maxNumCols = maxNumCols;
46
+ this.solvedCaches = {};
47
+ this.headerHeight = headerHeight;
48
+ this.headerWidth = headerWidth;
49
+ this.functions = functions;
50
+ const common = cells.default;
51
+ // make idMatrix beforehand
52
+ for (let y = 0; y < numRows + 1; y++) {
53
+ const ids = [];
54
+ this.idMatrix.push(ids);
55
+ for (let x = 0; x < numCols + 1; x++) {
56
+ const id = this.generateId();
57
+ ids.push(id);
58
+ const address = (0, converters_1.p2a)({ y, x });
59
+ this.addressesById[id] = address;
60
+ }
61
+ }
62
+ for (let y = 0; y < numRows + 1; y++) {
63
+ const rowId = (0, converters_1.y2r)(y);
64
+ const rowDefault = cells[rowId];
65
+ for (let x = 0; x < numCols + 1; x++) {
66
+ const id = this.getId({ y, x });
67
+ const address = (0, converters_1.p2a)({ y, x });
68
+ const colId = (0, converters_1.x2c)(x);
69
+ const colDefault = cells[colId];
70
+ const cell = cells[address];
71
+ const stacked = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, common), rowDefault), colDefault), cell), { style: Object.assign(Object.assign(Object.assign(Object.assign({}, common === null || common === void 0 ? void 0 : common.style), rowDefault === null || rowDefault === void 0 ? void 0 : rowDefault.style), colDefault === null || colDefault === void 0 ? void 0 : colDefault.style), cell === null || cell === void 0 ? void 0 : cell.style) });
72
+ stacked.value = (0, evaluator_1.convertFormulaAbsolute)({
73
+ value: stacked === null || stacked === void 0 ? void 0 : stacked.value,
74
+ table: this,
75
+ });
76
+ if (y === 0) {
77
+ if (stacked.width == null) {
78
+ stacked.width = constants_1.DEFAULT_WIDTH;
79
+ }
80
+ }
81
+ else if (x === 0) {
82
+ if (stacked.height == null) {
83
+ stacked.height = constants_1.DEFAULT_HEIGHT;
84
+ }
67
85
  }
86
+ else {
87
+ delete stacked.height;
88
+ delete stacked.width;
89
+ delete stacked.labeler;
90
+ }
91
+ this.data[id] = stacked;
68
92
  }
69
- else if (x === 0) {
70
- if (stacked.height == null) {
71
- stacked.height = DEFAULT_HEIGHT;
93
+ }
94
+ this.setTotalSize();
95
+ }
96
+ generateId() {
97
+ return (this.head++).toString(36);
98
+ }
99
+ getRectSize({ top, left, bottom, right }) {
100
+ var _a, _b;
101
+ let width = 0, height = 0;
102
+ for (let x = left || 1; x < right; x++) {
103
+ width += ((_a = this.getByPoint({ y: 0, x })) === null || _a === void 0 ? void 0 : _a.width) || constants_1.DEFAULT_WIDTH;
104
+ }
105
+ for (let y = top || 1; y < bottom; y++) {
106
+ height += ((_b = this.getByPoint({ y, x: 0 })) === null || _b === void 0 ? void 0 : _b.height) || constants_1.DEFAULT_HEIGHT;
107
+ }
108
+ return { width, height };
109
+ }
110
+ setTotalSize() {
111
+ const { bottom, right } = this.area;
112
+ const { width, height } = this.getRectSize({ top: 1, left: 1, bottom: bottom + 1, right: right + 1 });
113
+ this.totalWidth = width + this.headerWidth;
114
+ this.totalHeight = height + this.headerHeight;
115
+ }
116
+ shallowCopy({ copyCache = true } = {}) {
117
+ const copied = new Table({});
118
+ copied.changedAt = new Date();
119
+ copied.lastChangedAt = this.changedAt;
120
+ copied.head = this.head;
121
+ copied.idMatrix = this.idMatrix;
122
+ copied.data = this.data;
123
+ copied.area = this.area;
124
+ copied.parsers = this.parsers;
125
+ copied.renderers = this.renderers;
126
+ copied.labelers = this.labelers;
127
+ copied.functions = this.functions;
128
+ copied.histories = this.histories;
129
+ copied.historyLimit = this.historyLimit;
130
+ copied.historyIndex = this.historyIndex;
131
+ copied.minNumRows = this.minNumRows;
132
+ copied.maxNumRows = this.maxNumRows;
133
+ copied.minNumCols = this.minNumCols;
134
+ copied.maxNumCols = this.maxNumCols;
135
+ copied.headerHeight = this.headerHeight;
136
+ copied.headerWidth = this.headerWidth;
137
+ copied.setTotalSize();
138
+ if (copyCache) {
139
+ copied.addressesById = this.addressesById;
140
+ }
141
+ else {
142
+ // force reset
143
+ this.addressesById = {};
144
+ }
145
+ return copied;
146
+ }
147
+ getAddressById(id, slideY = 0, slideX = 0) {
148
+ const absCol = id.startsWith("$");
149
+ if (absCol) {
150
+ id = id.slice(1);
151
+ slideX = 0;
152
+ }
153
+ const absRow = id.endsWith("$");
154
+ if (absRow) {
155
+ id = id.slice(0, -1);
156
+ slideY = 0;
157
+ }
158
+ for (let y = 0; y < this.idMatrix.length; y++) {
159
+ const ids = this.idMatrix[y];
160
+ for (let x = 0; x < ids.length; x++) {
161
+ const existing = ids[x];
162
+ const address = (0, converters_1.p2a)({ y, x });
163
+ this.addressesById[existing] = address;
164
+ if (existing === id) {
165
+ const slidedAddress = (0, converters_1.p2a)({
166
+ y: y + slideY,
167
+ x: x + slideX,
168
+ });
169
+ return (0, converters_1.grantAddressAbsolute)(slidedAddress, absCol, absRow);
72
170
  }
73
171
  }
74
- else {
75
- delete stacked.height;
76
- delete stacked.width;
77
- delete stacked.labeler;
172
+ }
173
+ }
174
+ getAddressesByIds(ids) {
175
+ const addresses = {};
176
+ Object.keys(ids).forEach((id) => {
177
+ const cell = ids[id];
178
+ const address = this.getAddressById(id);
179
+ if (cell && address) {
180
+ addresses[address] = cell;
78
181
  }
79
- this.data[id] = stacked;
182
+ });
183
+ return addresses;
184
+ }
185
+ getPointById(id) {
186
+ const address = this.getAddressById(id);
187
+ if (address) {
188
+ return (0, converters_1.a2p)(address);
80
189
  }
190
+ return { y: 0, x: 0 };
81
191
  }
82
- this.setTotalSize();
83
- }
84
- generateId() {
85
- return (this.head++).toString(36);
86
- }
87
- getRectSize({ top, left, bottom, right }) {
88
- var _a, _b;
89
- let width = 0, height = 0;
90
- for (let x = left || 1; x < right; x++) {
91
- width += ((_a = this.getByPoint({ y: 0, x })) === null || _a === void 0 ? void 0 : _a.width) || DEFAULT_WIDTH;
192
+ getId(point) {
193
+ var _a;
194
+ const { y, x } = point;
195
+ return (_a = this.idMatrix[y]) === null || _a === void 0 ? void 0 : _a[x];
92
196
  }
93
- for (let y = top || 1; y < bottom; y++) {
94
- height += ((_b = this.getByPoint({ y, x: 0 })) === null || _b === void 0 ? void 0 : _b.height) || DEFAULT_HEIGHT;
197
+ getByPoint(point) {
198
+ var _a;
199
+ const { y, x } = point;
200
+ if (y === -1 || x === -1) {
201
+ return undefined;
202
+ }
203
+ const id = (_a = this.idMatrix[y]) === null || _a === void 0 ? void 0 : _a[x];
204
+ if (id == null) {
205
+ return undefined;
206
+ }
207
+ const value = this.data[id];
208
+ return value;
95
209
  }
96
- return { width, height };
97
- }
98
- setTotalSize() {
99
- const { bottom, right } = this.area;
100
- const { width, height } = this.getRectSize({ top: 1, left: 1, bottom: bottom + 1, right: right + 1 });
101
- this.totalWidth = width + this.headerWidth;
102
- this.totalHeight = height + this.headerHeight;
103
- }
104
- shallowCopy({ copyCache = true } = {}) {
105
- const copied = new Table({});
106
- copied.changedAt = new Date();
107
- copied.lastChangedAt = this.changedAt;
108
- copied.head = this.head;
109
- copied.idMatrix = this.idMatrix;
110
- copied.data = this.data;
111
- copied.area = this.area;
112
- copied.parsers = this.parsers;
113
- copied.renderers = this.renderers;
114
- copied.labelers = this.labelers;
115
- copied.functions = this.functions;
116
- copied.histories = this.histories;
117
- copied.historyLimit = this.historyLimit;
118
- copied.historyIndex = this.historyIndex;
119
- copied.minNumRows = this.minNumRows;
120
- copied.maxNumRows = this.maxNumRows;
121
- copied.minNumCols = this.minNumCols;
122
- copied.maxNumCols = this.maxNumCols;
123
- copied.headerHeight = this.headerHeight;
124
- copied.headerWidth = this.headerWidth;
125
- copied.setTotalSize();
126
- if (copyCache) {
127
- copied.addressesById = this.addressesById;
210
+ getById(id) {
211
+ return this.data[id];
128
212
  }
129
- else {
130
- // force reset
131
- this.addressesById = {};
213
+ getNumRows(base = 0) {
214
+ const { top, left, bottom, right } = this.area;
215
+ return base + bottom - top;
132
216
  }
133
- return copied;
134
- }
135
- getAddressById(id, slideY = 0, slideX = 0) {
136
- const absCol = id.startsWith("$");
137
- if (absCol) {
138
- id = id.slice(1);
139
- slideX = 0;
140
- }
141
- const absRow = id.endsWith("$");
142
- if (absRow) {
143
- id = id.slice(0, -1);
144
- slideY = 0;
145
- }
146
- for (let y = 0; y < this.idMatrix.length; y++) {
147
- const ids = this.idMatrix[y];
148
- for (let x = 0; x < ids.length; x++) {
149
- const existing = ids[x];
150
- const address = p2a({ y, x });
151
- this.addressesById[existing] = address;
152
- if (existing === id) {
153
- const slidedAddress = p2a({
154
- y: y + slideY,
155
- x: x + slideX,
156
- });
157
- return grantAddressAbsolute(slidedAddress, absCol, absRow);
158
- }
159
- }
217
+ getNumCols(base = 0) {
218
+ const { top, left, bottom, right } = this.area;
219
+ return base + right - left;
160
220
  }
161
- }
162
- getAddressesByIds(ids) {
163
- const addresses = {};
164
- Object.keys(ids).forEach((id) => {
165
- const cell = ids[id];
166
- const address = this.getAddressById(id);
167
- if (cell && address) {
168
- addresses[address] = cell;
169
- }
170
- });
171
- return addresses;
172
- }
173
- getPointById(id) {
174
- const address = this.getAddressById(id);
175
- if (address) {
176
- return a2p(address);
221
+ get top() {
222
+ return this.area.top;
177
223
  }
178
- return { y: 0, x: 0 };
179
- }
180
- getId(point) {
181
- var _a;
182
- const { y, x } = point;
183
- return (_a = this.idMatrix[y]) === null || _a === void 0 ? void 0 : _a[x];
184
- }
185
- getByPoint(point) {
186
- var _a;
187
- const { y, x } = point;
188
- if (y === -1 || x === -1) {
189
- return undefined;
190
- }
191
- const id = (_a = this.idMatrix[y]) === null || _a === void 0 ? void 0 : _a[x];
192
- if (id == null) {
193
- return undefined;
194
- }
195
- const value = this.data[id];
196
- return value;
197
- }
198
- getById(id) {
199
- return this.data[id];
200
- }
201
- getNumRows(base = 0) {
202
- const { top, left, bottom, right } = this.area;
203
- return base + bottom - top;
204
- }
205
- getNumCols(base = 0) {
206
- const { top, left, bottom, right } = this.area;
207
- return base + right - left;
208
- }
209
- get top() {
210
- return this.area.top;
211
- }
212
- get left() {
213
- return this.area.left;
214
- }
215
- get bottom() {
216
- return this.area.bottom;
217
- }
218
- get right() {
219
- return this.area.right;
220
- }
221
- getMatrixFlatten({ area, key = "value", evaluates = true, raise = false, filter = cellFilter, } = {}) {
222
- const { top, left, bottom, right } = area || {
223
- top: 1,
224
- left: 1,
225
- bottom: this.area.bottom,
226
- right: this.area.right,
227
- };
228
- const matrix = createMatrix(bottom - top + 1, right - left + 1);
229
- for (let y = top; y <= bottom; y++) {
230
- for (let x = left; x <= right; x++) {
231
- const cell = this.getByPoint({ y, x }) || {};
232
- if (!filter(cell)) {
233
- continue;
234
- }
235
- matrix[y - top][x - left] = evaluates
236
- ? solveFormula({
237
- value: cell[key],
238
- table: this,
239
- raise,
240
- })
241
- : cell[key];
242
- }
224
+ get left() {
225
+ return this.area.left;
243
226
  }
244
- return matrix;
245
- }
246
- getObjectFlatten({ key = "value", evaluates = true, raise = false, filter = cellFilter, } = {}) {
247
- const result = {};
248
- const { top, left, bottom, right } = this.area;
249
- for (let y = top; y <= bottom; y++) {
250
- for (let x = left; x <= right; x++) {
251
- const cell = this.getByPoint({ y: y - top, x: x - left });
252
- if (cell != null && filter(cell)) {
253
- result[p2a({ y, x })] = evaluates
254
- ? solveFormula({
255
- value: cell[key],
256
- table: this,
257
- raise,
258
- })
259
- : cell[key];
260
- }
261
- }
227
+ get bottom() {
228
+ return this.area.bottom;
262
229
  }
263
- return result;
264
- }
265
- getRowsFlatten({ key = "value", evaluates = true, raise = false, filter = cellFilter, } = {}) {
266
- const result = [];
267
- const { top, left, bottom, right } = this.area;
268
- for (let y = top; y <= bottom; y++) {
269
- const row = {};
270
- result.push(row);
271
- for (let x = left; x <= right; x++) {
272
- const cell = this.getByPoint({ y: y - top, x: x - left });
273
- if (cell != null && filter(cell)) {
274
- row[x2c(x) || y2r(y)] = evaluates
275
- ? solveFormula({
276
- value: cell[key],
277
- table: this,
278
- raise,
279
- })
280
- : cell[key];
281
- }
282
- }
230
+ get right() {
231
+ return this.area.right;
283
232
  }
284
- return result;
285
- }
286
- getColsFlatten({ key = "value", evaluates = true, raise = false, filter = cellFilter, } = {}) {
287
- const result = [];
288
- const { top, left, bottom, right } = this.area;
289
- for (let x = left; x <= right; x++) {
290
- const col = {};
291
- result.push(col);
233
+ getMatrixFlatten({ area, key = "value", evaluates = true, raise = false, filter = cellFilter, } = {}) {
234
+ const { top, left, bottom, right } = area || {
235
+ top: 1,
236
+ left: 1,
237
+ bottom: this.area.bottom,
238
+ right: this.area.right,
239
+ };
240
+ const matrix = (0, structs_1.createMatrix)(bottom - top + 1, right - left + 1);
292
241
  for (let y = top; y <= bottom; y++) {
293
- const cell = this.getByPoint({ y: y - top, x: x - left });
294
- if (cell != null && filter(cell)) {
295
- col[y2r(y) || x2c(x)] = evaluates
296
- ? solveFormula({
242
+ for (let x = left; x <= right; x++) {
243
+ const cell = this.getByPoint({ y, x }) || {};
244
+ if (!filter(cell)) {
245
+ continue;
246
+ }
247
+ matrix[y - top][x - left] = evaluates
248
+ ? (0, solver_1.solveFormula)({
297
249
  value: cell[key],
298
250
  table: this,
299
251
  raise,
@@ -301,689 +253,752 @@ export class Table {
301
253
  : cell[key];
302
254
  }
303
255
  }
256
+ return matrix;
304
257
  }
305
- return result;
306
- }
307
- getMatrix({ area, evaluates = true, raise = false, filter = cellFilter, } = {}) {
308
- const { top, left, bottom, right } = area || {
309
- top: 1,
310
- left: 1,
311
- bottom: this.area.bottom,
312
- right: this.area.right,
313
- };
314
- const matrix = createMatrix(bottom - top + 1, right - left + 1);
315
- for (let y = top; y <= bottom; y++) {
316
- for (let x = left; x <= right; x++) {
317
- const cell = this.getByPoint({ y, x });
318
- if (cell != null && filter(cell)) {
319
- matrix[y - top][x - left] = Object.assign(Object.assign({}, cell), { value: evaluates
320
- ? solveFormula({
321
- value: cell === null || cell === void 0 ? void 0 : cell.value,
258
+ getObjectFlatten({ key = "value", evaluates = true, raise = false, filter = cellFilter, } = {}) {
259
+ const result = {};
260
+ const { top, left, bottom, right } = this.area;
261
+ for (let y = top; y <= bottom; y++) {
262
+ for (let x = left; x <= right; x++) {
263
+ const cell = this.getByPoint({ y: y - top, x: x - left });
264
+ if (cell != null && filter(cell)) {
265
+ result[(0, converters_1.p2a)({ y, x })] = evaluates
266
+ ? (0, solver_1.solveFormula)({
267
+ value: cell[key],
322
268
  table: this,
323
269
  raise,
324
270
  })
325
- : cell === null || cell === void 0 ? void 0 : cell.value });
271
+ : cell[key];
272
+ }
326
273
  }
327
274
  }
275
+ return result;
328
276
  }
329
- return matrix;
330
- }
331
- getObject({ evaluates = true, raise = false, filter = cellFilter, } = {}) {
332
- const result = {};
333
- const { top, left, bottom, right } = this.area;
334
- for (let y = top; y <= bottom; y++) {
335
- for (let x = left; x <= right; x++) {
336
- const cell = this.getByPoint({ y: y - top, x: x - left });
337
- if (cell != null && filter(cell)) {
338
- result[p2a({ y, x })] = Object.assign(Object.assign({}, cell), { value: evaluates
339
- ? solveFormula({
340
- value: cell === null || cell === void 0 ? void 0 : cell.value,
277
+ getRowsFlatten({ key = "value", evaluates = true, raise = false, filter = cellFilter, } = {}) {
278
+ const result = [];
279
+ const { top, left, bottom, right } = this.area;
280
+ for (let y = top; y <= bottom; y++) {
281
+ const row = {};
282
+ result.push(row);
283
+ for (let x = left; x <= right; x++) {
284
+ const cell = this.getByPoint({ y: y - top, x: x - left });
285
+ if (cell != null && filter(cell)) {
286
+ row[(0, converters_1.x2c)(x) || (0, converters_1.y2r)(y)] = evaluates
287
+ ? (0, solver_1.solveFormula)({
288
+ value: cell[key],
341
289
  table: this,
342
290
  raise,
343
291
  })
344
- : cell === null || cell === void 0 ? void 0 : cell.value });
292
+ : cell[key];
293
+ }
345
294
  }
346
295
  }
296
+ return result;
347
297
  }
348
- return result;
349
- }
350
- getRows({ evaluates = true, raise = false, filter = cellFilter, } = {}) {
351
- const result = [];
352
- const { top, left, bottom, right } = this.area;
353
- for (let y = top; y <= bottom; y++) {
354
- const row = {};
355
- result.push(row);
298
+ getColsFlatten({ key = "value", evaluates = true, raise = false, filter = cellFilter, } = {}) {
299
+ const result = [];
300
+ const { top, left, bottom, right } = this.area;
356
301
  for (let x = left; x <= right; x++) {
357
- const cell = this.getByPoint({ y: y - top, x: x - left });
358
- if (cell != null && filter(cell)) {
359
- row[x2c(x) || y2r(y)] = Object.assign(Object.assign({}, cell), { value: evaluates
360
- ? solveFormula({
361
- value: cell === null || cell === void 0 ? void 0 : cell.value,
302
+ const col = {};
303
+ result.push(col);
304
+ for (let y = top; y <= bottom; y++) {
305
+ const cell = this.getByPoint({ y: y - top, x: x - left });
306
+ if (cell != null && filter(cell)) {
307
+ col[(0, converters_1.y2r)(y) || (0, converters_1.x2c)(x)] = evaluates
308
+ ? (0, solver_1.solveFormula)({
309
+ value: cell[key],
362
310
  table: this,
363
311
  raise,
364
312
  })
365
- : cell === null || cell === void 0 ? void 0 : cell.value });
313
+ : cell[key];
314
+ }
366
315
  }
367
316
  }
317
+ return result;
368
318
  }
369
- return result;
370
- }
371
- getCols({ evaluates = true, raise = false, filter = cellFilter, } = {}) {
372
- const result = [];
373
- const { top, left, bottom, right } = this.area;
374
- for (let x = left; x <= right; x++) {
375
- const col = {};
376
- result.push(col);
319
+ getMatrix({ area, evaluates = true, raise = false, filter = cellFilter, } = {}) {
320
+ const { top, left, bottom, right } = area || {
321
+ top: 1,
322
+ left: 1,
323
+ bottom: this.area.bottom,
324
+ right: this.area.right,
325
+ };
326
+ const matrix = (0, structs_1.createMatrix)(bottom - top + 1, right - left + 1);
377
327
  for (let y = top; y <= bottom; y++) {
378
- const cell = this.getByPoint({ y: y - top, x: x - left });
379
- if (cell != null && filter(cell)) {
380
- col[y2r(y) || x2c(x)] = Object.assign(Object.assign({}, cell), { value: evaluates
381
- ? solveFormula({
382
- value: cell === null || cell === void 0 ? void 0 : cell.value,
383
- table: this,
384
- raise,
385
- })
386
- : cell === null || cell === void 0 ? void 0 : cell.value });
328
+ for (let x = left; x <= right; x++) {
329
+ const cell = this.getByPoint({ y, x });
330
+ if (cell != null && filter(cell)) {
331
+ matrix[y - top][x - left] = Object.assign(Object.assign({}, cell), { value: evaluates
332
+ ? (0, solver_1.solveFormula)({
333
+ value: cell === null || cell === void 0 ? void 0 : cell.value,
334
+ table: this,
335
+ raise,
336
+ })
337
+ : cell === null || cell === void 0 ? void 0 : cell.value });
338
+ }
387
339
  }
388
340
  }
341
+ return matrix;
389
342
  }
390
- return result;
391
- }
392
- pushHistory(history) {
393
- const strayedHistories = this.histories.splice(this.historyIndex + 1, this.histories.length);
394
- strayedHistories.forEach(this.cleanStrayed.bind(this));
395
- this.histories.push(history);
396
- this.lastHistory = history;
397
- if (this.histories.length > this.historyLimit) {
398
- const kickedOut = this.histories.splice(0, 1)[0];
399
- this.cleanObsolete(kickedOut);
400
- }
401
- else {
402
- this.historyIndex++;
403
- }
404
- }
405
- cleanObsolete(history) {
406
- if (history.operation === "REMOVE_ROWS" ||
407
- history.operation === "REMOVE_COLS") {
408
- history.idMatrix.forEach((ids) => {
409
- ids.forEach((id) => {
410
- delete this.data[id];
411
- });
412
- });
413
- }
414
- if (history.operation === "MOVE") {
415
- Object.keys(history.lostRows).forEach((address) => {
416
- const idMatrix = history.lostRows[address];
417
- idMatrix.map((ids) => ids.forEach((id) => {
418
- delete this.data[id];
419
- }));
420
- });
421
- }
422
- }
423
- cleanStrayed(history) {
424
- if (history.operation === "ADD_ROWS" || history.operation === "ADD_COLS") {
425
- history.idMatrix.forEach((ids) => {
426
- ids.forEach((id) => {
427
- delete this.data[id];
428
- });
429
- });
343
+ getObject({ evaluates = true, raise = false, filter = cellFilter, } = {}) {
344
+ const result = {};
345
+ const { top, left, bottom, right } = this.area;
346
+ for (let y = top; y <= bottom; y++) {
347
+ for (let x = left; x <= right; x++) {
348
+ const cell = this.getByPoint({ y: y - top, x: x - left });
349
+ if (cell != null && filter(cell)) {
350
+ result[(0, converters_1.p2a)({ y, x })] = Object.assign(Object.assign({}, cell), { value: evaluates
351
+ ? (0, solver_1.solveFormula)({
352
+ value: cell === null || cell === void 0 ? void 0 : cell.value,
353
+ table: this,
354
+ raise,
355
+ })
356
+ : cell === null || cell === void 0 ? void 0 : cell.value });
357
+ }
358
+ }
359
+ }
360
+ return result;
430
361
  }
431
- }
432
- getNewIdMatrix(area) {
433
- const matrix = [];
434
- const { top, left, bottom, right } = area;
435
- for (let y = top; y <= bottom; y++) {
436
- const ids = [];
437
- matrix.push(ids);
438
- for (let x = left; x <= right; x++) {
439
- ids.push(this.generateId());
362
+ getRows({ evaluates = true, raise = false, filter = cellFilter, } = {}) {
363
+ const result = [];
364
+ const { top, left, bottom, right } = this.area;
365
+ for (let y = top; y <= bottom; y++) {
366
+ const row = {};
367
+ result.push(row);
368
+ for (let x = left; x <= right; x++) {
369
+ const cell = this.getByPoint({ y: y - top, x: x - left });
370
+ if (cell != null && filter(cell)) {
371
+ row[(0, converters_1.x2c)(x) || (0, converters_1.y2r)(y)] = Object.assign(Object.assign({}, cell), { value: evaluates
372
+ ? (0, solver_1.solveFormula)({
373
+ value: cell === null || cell === void 0 ? void 0 : cell.value,
374
+ table: this,
375
+ raise,
376
+ })
377
+ : cell === null || cell === void 0 ? void 0 : cell.value });
378
+ }
379
+ }
440
380
  }
381
+ return result;
441
382
  }
442
- return matrix;
443
- }
444
- getIdMatrixFromArea(area) {
445
- var _a;
446
- const matrix = [];
447
- const { top, left, bottom, right } = area;
448
- for (let y = top; y <= bottom; y++) {
449
- const ids = [];
450
- matrix.push(ids);
383
+ getCols({ evaluates = true, raise = false, filter = cellFilter, } = {}) {
384
+ const result = [];
385
+ const { top, left, bottom, right } = this.area;
451
386
  for (let x = left; x <= right; x++) {
452
- const id = (_a = this.idMatrix[y]) === null || _a === void 0 ? void 0 : _a[x];
453
- if (id) {
454
- ids.push(id);
387
+ const col = {};
388
+ result.push(col);
389
+ for (let y = top; y <= bottom; y++) {
390
+ const cell = this.getByPoint({ y: y - top, x: x - left });
391
+ if (cell != null && filter(cell)) {
392
+ col[(0, converters_1.y2r)(y) || (0, converters_1.x2c)(x)] = Object.assign(Object.assign({}, cell), { value: evaluates
393
+ ? (0, solver_1.solveFormula)({
394
+ value: cell === null || cell === void 0 ? void 0 : cell.value,
395
+ table: this,
396
+ raise,
397
+ })
398
+ : cell === null || cell === void 0 ? void 0 : cell.value });
399
+ }
455
400
  }
456
401
  }
402
+ return result;
457
403
  }
458
- return matrix;
459
- }
460
- setChangedAt(cell, changedAt) {
461
- if (cell == null) {
462
- return null;
463
- }
464
- cell.changedAt = changedAt || new Date();
465
- return cell;
466
- }
467
- copyCellLayout(cell) {
468
- if (cell == null) {
469
- return undefined;
470
- }
471
- const newCell = {};
472
- if (cell.style != null) {
473
- newCell.style = cell.style;
474
- }
475
- if (cell.justifyContent != null) {
476
- newCell.justifyContent = cell.justifyContent;
404
+ pushHistory(history) {
405
+ const strayedHistories = this.histories.splice(this.historyIndex + 1, this.histories.length);
406
+ strayedHistories.forEach(this.cleanStrayed.bind(this));
407
+ this.histories.push(history);
408
+ this.lastHistory = history;
409
+ if (this.histories.length > this.historyLimit) {
410
+ const kickedOut = this.histories.splice(0, 1)[0];
411
+ this.cleanObsolete(kickedOut);
412
+ }
413
+ else {
414
+ this.historyIndex++;
415
+ }
477
416
  }
478
- if (cell.alignItems != null) {
479
- newCell.alignItems = cell.alignItems;
417
+ cleanObsolete(history) {
418
+ if (history.operation === "REMOVE_ROWS" ||
419
+ history.operation === "REMOVE_COLS") {
420
+ history.idMatrix.forEach((ids) => {
421
+ ids.forEach((id) => {
422
+ delete this.data[id];
423
+ });
424
+ });
425
+ }
426
+ if (history.operation === "MOVE") {
427
+ Object.keys(history.lostRows).forEach((address) => {
428
+ const idMatrix = history.lostRows[address];
429
+ idMatrix.map((ids) => ids.forEach((id) => {
430
+ delete this.data[id];
431
+ }));
432
+ });
433
+ }
480
434
  }
481
- if (cell.renderer != null) {
482
- newCell.renderer = cell.renderer;
435
+ cleanStrayed(history) {
436
+ if (history.operation === "ADD_ROWS" || history.operation === "ADD_COLS") {
437
+ history.idMatrix.forEach((ids) => {
438
+ ids.forEach((id) => {
439
+ delete this.data[id];
440
+ });
441
+ });
442
+ }
483
443
  }
484
- if (cell.parser != null) {
485
- newCell.parser = cell.parser;
444
+ getNewIdMatrix(area) {
445
+ const matrix = [];
446
+ const { top, left, bottom, right } = area;
447
+ for (let y = top; y <= bottom; y++) {
448
+ const ids = [];
449
+ matrix.push(ids);
450
+ for (let x = left; x <= right; x++) {
451
+ ids.push(this.generateId());
452
+ }
453
+ }
454
+ return matrix;
486
455
  }
487
- if (cell.width != null) {
488
- newCell.width = cell.width;
456
+ getIdMatrixFromArea(area) {
457
+ var _a;
458
+ const matrix = [];
459
+ const { top, left, bottom, right } = area;
460
+ for (let y = top; y <= bottom; y++) {
461
+ const ids = [];
462
+ matrix.push(ids);
463
+ for (let x = left; x <= right; x++) {
464
+ const id = (_a = this.idMatrix[y]) === null || _a === void 0 ? void 0 : _a[x];
465
+ if (id) {
466
+ ids.push(id);
467
+ }
468
+ }
469
+ }
470
+ return matrix;
489
471
  }
490
- if (cell.height != null) {
491
- newCell.height = cell.height;
472
+ setChangedAt(cell, changedAt) {
473
+ if (cell == null) {
474
+ return null;
475
+ }
476
+ cell.changedAt = changedAt || new Date();
477
+ return cell;
492
478
  }
493
- if (cell.labeler != null) {
494
- newCell.labeler = cell.labeler;
479
+ copyCellLayout(cell) {
480
+ if (cell == null) {
481
+ return undefined;
482
+ }
483
+ const newCell = {};
484
+ if (cell.style != null) {
485
+ newCell.style = cell.style;
486
+ }
487
+ if (cell.justifyContent != null) {
488
+ newCell.justifyContent = cell.justifyContent;
489
+ }
490
+ if (cell.alignItems != null) {
491
+ newCell.alignItems = cell.alignItems;
492
+ }
493
+ if (cell.renderer != null) {
494
+ newCell.renderer = cell.renderer;
495
+ }
496
+ if (cell.parser != null) {
497
+ newCell.parser = cell.parser;
498
+ }
499
+ if (cell.width != null) {
500
+ newCell.width = cell.width;
501
+ }
502
+ if (cell.height != null) {
503
+ newCell.height = cell.height;
504
+ }
505
+ if (cell.labeler != null) {
506
+ newCell.labeler = cell.labeler;
507
+ }
508
+ return newCell;
495
509
  }
496
- return newCell;
497
- }
498
- move({ src, dst, reflection = {}, }) {
499
- const changedAt = new Date();
500
- const matrixFrom = this.getIdMatrixFromArea(src);
501
- const matrixTo = this.getIdMatrixFromArea(dst);
502
- const matrixNew = this.getNewIdMatrix(src);
503
- putMatrix(this.idMatrix, matrixNew, src);
504
- matrixFrom.forEach((ids) => {
505
- ids
506
- .map(this.getById.bind(this))
507
- .filter((c) => c)
508
- .forEach((cell) => this.setChangedAt(cell, changedAt));
509
- });
510
- const lostRows = putMatrix(this.idMatrix, matrixFrom, dst);
511
- this.pushHistory({
512
- operation: "MOVE",
513
- reflection,
514
- matrixFrom,
515
- matrixTo,
516
- matrixNew,
517
- pointFrom: { y: src.top, x: src.left },
518
- pointTo: { y: dst.top, x: dst.left },
519
- lostRows,
520
- });
521
- return this.shallowCopy({ copyCache: false });
522
- }
523
- copy({ src, dst, reflection = {}, }) {
524
- const { height: maxHeight, width: maxWidth } = areaShape(Object.assign(Object.assign({}, src), { base: 1 }));
525
- const { top: topFrom, left: leftFrom } = src;
526
- const { top: topTo, left: leftTo, bottom: bottomTo, right: rightTo } = dst;
527
- const diff = {};
528
- const changedAt = new Date();
529
- for (let i = 0; i <= bottomTo - topTo; i++) {
530
- const toY = topTo + i;
531
- if (toY > this.getNumRows()) {
532
- continue;
533
- }
534
- for (let j = 0; j <= rightTo - leftTo; j++) {
535
- const toX = leftTo + j;
536
- if (toX > this.getNumCols()) {
510
+ move({ src, dst, reflection = {}, }) {
511
+ const changedAt = new Date();
512
+ const matrixFrom = this.getIdMatrixFromArea(src);
513
+ const matrixTo = this.getIdMatrixFromArea(dst);
514
+ const matrixNew = this.getNewIdMatrix(src);
515
+ (0, structs_1.putMatrix)(this.idMatrix, matrixNew, src);
516
+ matrixFrom.forEach((ids) => {
517
+ ids
518
+ .map(this.getById.bind(this))
519
+ .filter((c) => c)
520
+ .forEach((cell) => this.setChangedAt(cell, changedAt));
521
+ });
522
+ const lostRows = (0, structs_1.putMatrix)(this.idMatrix, matrixFrom, dst);
523
+ this.pushHistory({
524
+ operation: "MOVE",
525
+ reflection,
526
+ matrixFrom,
527
+ matrixTo,
528
+ matrixNew,
529
+ pointFrom: { y: src.top, x: src.left },
530
+ pointTo: { y: dst.top, x: dst.left },
531
+ lostRows,
532
+ });
533
+ return this.shallowCopy({ copyCache: false });
534
+ }
535
+ copy({ src, dst, reflection = {}, }) {
536
+ const { height: maxHeight, width: maxWidth } = (0, structs_1.areaShape)(Object.assign(Object.assign({}, src), { base: 1 }));
537
+ const { top: topFrom, left: leftFrom } = src;
538
+ const { top: topTo, left: leftTo, bottom: bottomTo, right: rightTo } = dst;
539
+ const diff = {};
540
+ const changedAt = new Date();
541
+ for (let i = 0; i <= bottomTo - topTo; i++) {
542
+ const toY = topTo + i;
543
+ if (toY > this.getNumRows()) {
537
544
  continue;
538
545
  }
539
- const fromY = topFrom + (i % maxHeight);
540
- const fromX = leftFrom + (j % maxWidth);
541
- const slideY = toY - fromY;
542
- const slideX = toX - fromX;
543
- const cell = Object.assign({}, this.getByPoint({
544
- y: topFrom + (i % maxHeight),
545
- x: leftFrom + (j % maxWidth),
546
- }));
547
- const value = convertFormulaAbsolute({
548
- value: cell === null || cell === void 0 ? void 0 : cell.value,
549
- table: this,
550
- slideY,
551
- slideX,
552
- });
553
- this.setChangedAt(cell, changedAt);
554
- diff[p2a({ y: toY, x: toX })] = Object.assign(Object.assign({}, cell), { style: Object.assign({}, cell === null || cell === void 0 ? void 0 : cell.style), value });
546
+ for (let j = 0; j <= rightTo - leftTo; j++) {
547
+ const toX = leftTo + j;
548
+ if (toX > this.getNumCols()) {
549
+ continue;
550
+ }
551
+ const fromY = topFrom + (i % maxHeight);
552
+ const fromX = leftFrom + (j % maxWidth);
553
+ const slideY = toY - fromY;
554
+ const slideX = toX - fromX;
555
+ const cell = Object.assign({}, this.getByPoint({
556
+ y: topFrom + (i % maxHeight),
557
+ x: leftFrom + (j % maxWidth),
558
+ }));
559
+ const value = (0, evaluator_1.convertFormulaAbsolute)({
560
+ value: cell === null || cell === void 0 ? void 0 : cell.value,
561
+ table: this,
562
+ slideY,
563
+ slideX,
564
+ });
565
+ this.setChangedAt(cell, changedAt);
566
+ diff[(0, converters_1.p2a)({ y: toY, x: toX })] = Object.assign(Object.assign({}, cell), { style: Object.assign({}, cell === null || cell === void 0 ? void 0 : cell.style), value });
567
+ }
555
568
  }
569
+ return this.update({ diff, partial: false, reflection });
556
570
  }
557
- return this.update({ diff, partial: false, reflection });
558
- }
559
- _update({ diff, partial = true, updateChangedAt = true, }) {
560
- const diffBefore = {};
561
- const diffAfter = {};
562
- const changedAt = new Date();
563
- Object.keys(diff).forEach((address) => {
564
- const cell = Object.assign({}, diff[address]);
565
- if (updateChangedAt) {
566
- this.setChangedAt(cell, changedAt);
567
- }
568
- cell.value = convertFormulaAbsolute({
569
- value: cell.value,
570
- table: this,
571
+ _update({ diff, partial = true, updateChangedAt = true, }) {
572
+ const diffBefore = {};
573
+ const diffAfter = {};
574
+ const changedAt = new Date();
575
+ Object.keys(diff).forEach((address) => {
576
+ const cell = Object.assign({}, diff[address]);
577
+ if (updateChangedAt) {
578
+ this.setChangedAt(cell, changedAt);
579
+ }
580
+ cell.value = (0, evaluator_1.convertFormulaAbsolute)({
581
+ value: cell.value,
582
+ table: this,
583
+ });
584
+ const point = (0, converters_1.a2p)(address);
585
+ const id = this.getId(point);
586
+ // must not partial
587
+ diffBefore[id] = this.getByPoint(point);
588
+ diffAfter[id] = cell;
589
+ if (partial) {
590
+ this.data[id] = Object.assign(Object.assign({}, this.data[id]), cell);
591
+ }
592
+ else {
593
+ this.data[id] = cell;
594
+ }
571
595
  });
572
- const point = a2p(address);
573
- const id = this.getId(point);
574
- // must not partial
575
- diffBefore[id] = this.getByPoint(point);
576
- diffAfter[id] = cell;
577
- if (partial) {
578
- this.data[id] = Object.assign(Object.assign({}, this.data[id]), cell);
579
- }
580
- else {
581
- this.data[id] = cell;
582
- }
583
- });
584
- this.solvedCaches = {};
585
- return {
586
- diffBefore,
587
- diffAfter,
588
- };
589
- }
590
- update({ diff, partial = true, updateChangedAt = true, reflection = {}, }) {
591
- const { diffBefore, diffAfter } = this._update({
592
- diff,
593
- partial,
594
- updateChangedAt,
595
- });
596
- this.pushHistory({
597
- operation: "UPDATE",
598
- reflection,
599
- diffBefore,
600
- diffAfter,
601
- partial,
602
- });
603
- return this.shallowCopy({ copyCache: true });
604
- }
605
- writeMatrix({ point, matrix, updateChangedAt = true, reflection = {}, }) {
606
- const { y: baseY, x: baseX } = point;
607
- const diff = {};
608
- matrix.forEach((cols, i) => {
609
- const y = baseY + i;
610
- if (y > this.bottom) {
611
- return;
612
- }
613
- cols.forEach((value, j) => {
614
- const x = baseX + j;
615
- if (x > this.right) {
596
+ this.solvedCaches = {};
597
+ return {
598
+ diffBefore,
599
+ diffAfter,
600
+ };
601
+ }
602
+ update({ diff, partial = true, updateChangedAt = true, reflection = {}, }) {
603
+ const { diffBefore, diffAfter } = this._update({
604
+ diff,
605
+ partial,
606
+ updateChangedAt,
607
+ });
608
+ this.pushHistory({
609
+ operation: "UPDATE",
610
+ reflection,
611
+ diffBefore,
612
+ diffAfter,
613
+ partial,
614
+ });
615
+ return this.shallowCopy({ copyCache: true });
616
+ }
617
+ writeMatrix({ point, matrix, updateChangedAt = true, reflection = {}, }) {
618
+ const { y: baseY, x: baseX } = point;
619
+ const diff = {};
620
+ matrix.forEach((cols, i) => {
621
+ const y = baseY + i;
622
+ if (y > this.bottom) {
616
623
  return;
617
624
  }
618
- const cell = this.parse({ y, x }, value);
619
- diff[p2a({ y, x })] = cell;
625
+ cols.forEach((value, j) => {
626
+ const x = baseX + j;
627
+ if (x > this.right) {
628
+ return;
629
+ }
630
+ const cell = this.parse({ y, x }, value);
631
+ diff[(0, converters_1.p2a)({ y, x })] = cell;
632
+ });
633
+ });
634
+ return this.update({
635
+ diff,
636
+ partial: true,
637
+ updateChangedAt,
638
+ reflection,
620
639
  });
621
- });
622
- return this.update({
623
- diff,
624
- partial: true,
625
- updateChangedAt,
626
- reflection,
627
- });
628
- }
629
- write({ point, value, updateChangedAt = true, reflection = {}, }) {
630
- return this.writeMatrix({
631
- point,
632
- matrix: [[value]],
633
- updateChangedAt,
634
- reflection,
635
- });
636
- }
637
- addRowsAndUpdate({ y, numRows, baseY, diff, partial, updateChangedAt, reflection = {}, }) {
638
- const returned = this.addRows({
639
- y,
640
- numRows,
641
- baseY,
642
- reflection,
643
- });
644
- Object.assign(this.lastHistory, this._update({ diff, partial, updateChangedAt }), { partial });
645
- return returned;
646
- }
647
- addRows({ y, numRows, baseY, reflection = {}, }) {
648
- if (this.maxNumRows !== -1 &&
649
- this.getNumRows() + numRows > this.maxNumRows) {
650
- console.error(`Rows are limited to ${this.maxNumRows}.`);
651
- return this;
652
640
  }
653
- const numCols = this.getNumCols(1);
654
- const rows = [];
655
- const changedAt = new Date();
656
- for (let i = 0; i < numRows; i++) {
657
- const row = [];
658
- for (let j = 0; j < numCols; j++) {
659
- const id = this.generateId();
660
- row.push(id);
661
- const cell = this.getByPoint({ y: baseY, x: j });
662
- const copied = this.copyCellLayout(cell);
663
- this.data[id] = Object.assign(Object.assign({}, copied), { changedAt });
664
- }
665
- rows.push(row);
666
- }
667
- this.idMatrix.splice(y, 0, ...rows);
668
- this.area.bottom += numRows;
669
- this.pushHistory({
670
- operation: "ADD_ROWS",
671
- reflection,
672
- y,
673
- idMatrix: rows,
674
- });
675
- return this.shallowCopy({ copyCache: false });
676
- }
677
- removeRows({ y, numRows, reflection = {}, }) {
678
- if (this.minNumRows !== -1 &&
679
- this.getNumRows() - numRows < this.minNumRows) {
680
- console.error(`At least ${this.minNumRows} row(s) are required.`);
681
- return this;
641
+ write({ point, value, updateChangedAt = true, reflection = {}, }) {
642
+ return this.writeMatrix({
643
+ point,
644
+ matrix: [[value]],
645
+ updateChangedAt,
646
+ reflection,
647
+ });
682
648
  }
683
- const rows = this.idMatrix.splice(y, numRows);
684
- this.area.bottom -= numRows;
685
- this.pushHistory({
686
- operation: "REMOVE_ROWS",
687
- reflection,
688
- y,
689
- idMatrix: rows,
690
- });
691
- return this.shallowCopy({ copyCache: false });
692
- }
693
- addColsAndUpdate({ x, numCols, baseX, diff, partial, updateChangedAt, reflection = {}, }) {
694
- const returned = this.addCols({
695
- x,
696
- numCols,
697
- baseX,
698
- reflection,
699
- });
700
- Object.assign(this.lastHistory, this._update({ diff, partial, updateChangedAt }), { partial });
701
- return returned;
702
- }
703
- addCols({ x, numCols, baseX, reflection = {}, }) {
704
- if (this.maxNumCols !== -1 &&
705
- this.getNumCols() + numCols > this.maxNumCols) {
706
- console.error(`Columns are limited to ${this.maxNumCols}.`);
707
- return this;
649
+ addRowsAndUpdate({ y, numRows, baseY, diff, partial, updateChangedAt, reflection = {}, }) {
650
+ const returned = this.addRows({
651
+ y,
652
+ numRows,
653
+ baseY,
654
+ reflection,
655
+ });
656
+ Object.assign(this.lastHistory, this._update({ diff, partial, updateChangedAt }), { partial });
657
+ return returned;
658
+ }
659
+ addRows({ y, numRows, baseY, reflection = {}, }) {
660
+ if (this.maxNumRows !== -1 &&
661
+ this.getNumRows() + numRows > this.maxNumRows) {
662
+ console.error(`Rows are limited to ${this.maxNumRows}.`);
663
+ return this;
664
+ }
665
+ const numCols = this.getNumCols(1);
666
+ const rows = [];
667
+ const changedAt = new Date();
668
+ for (let i = 0; i < numRows; i++) {
669
+ const row = [];
670
+ for (let j = 0; j < numCols; j++) {
671
+ const id = this.generateId();
672
+ row.push(id);
673
+ const cell = this.getByPoint({ y: baseY, x: j });
674
+ const copied = this.copyCellLayout(cell);
675
+ this.data[id] = Object.assign(Object.assign({}, copied), { changedAt });
676
+ }
677
+ rows.push(row);
678
+ }
679
+ this.idMatrix.splice(y, 0, ...rows);
680
+ this.area.bottom += numRows;
681
+ this.pushHistory({
682
+ operation: "ADD_ROWS",
683
+ reflection,
684
+ y,
685
+ idMatrix: rows,
686
+ });
687
+ return this.shallowCopy({ copyCache: false });
688
+ }
689
+ removeRows({ y, numRows, reflection = {}, }) {
690
+ if (this.minNumRows !== -1 &&
691
+ this.getNumRows() - numRows < this.minNumRows) {
692
+ console.error(`At least ${this.minNumRows} row(s) are required.`);
693
+ return this;
694
+ }
695
+ const rows = this.idMatrix.splice(y, numRows);
696
+ this.area.bottom -= numRows;
697
+ this.pushHistory({
698
+ operation: "REMOVE_ROWS",
699
+ reflection,
700
+ y,
701
+ idMatrix: rows,
702
+ });
703
+ return this.shallowCopy({ copyCache: false });
704
+ }
705
+ addColsAndUpdate({ x, numCols, baseX, diff, partial, updateChangedAt, reflection = {}, }) {
706
+ const returned = this.addCols({
707
+ x,
708
+ numCols,
709
+ baseX,
710
+ reflection,
711
+ });
712
+ Object.assign(this.lastHistory, this._update({ diff, partial, updateChangedAt }), { partial });
713
+ return returned;
714
+ }
715
+ addCols({ x, numCols, baseX, reflection = {}, }) {
716
+ if (this.maxNumCols !== -1 &&
717
+ this.getNumCols() + numCols > this.maxNumCols) {
718
+ console.error(`Columns are limited to ${this.maxNumCols}.`);
719
+ return this;
720
+ }
721
+ const numRows = this.getNumRows(1);
722
+ const rows = [];
723
+ const changedAt = new Date();
724
+ for (let i = 0; i < numRows; i++) {
725
+ const row = [];
726
+ for (let j = 0; j < numCols; j++) {
727
+ const id = this.generateId();
728
+ row.push(id);
729
+ const cell = this.getByPoint({ y: i, x: baseX });
730
+ const copied = this.copyCellLayout(cell);
731
+ this.idMatrix[i].splice(x, 0, id);
732
+ this.data[id] = Object.assign(Object.assign({}, copied), { changedAt });
733
+ }
734
+ rows.push(row);
735
+ }
736
+ this.area.right += numCols;
737
+ this.pushHistory({
738
+ operation: "ADD_COLS",
739
+ reflection,
740
+ x,
741
+ idMatrix: rows,
742
+ });
743
+ return this.shallowCopy({ copyCache: false });
744
+ }
745
+ removeCols({ x, numCols, reflection = {}, }) {
746
+ if (this.minNumCols !== -1 &&
747
+ this.getNumCols() - numCols < this.minNumCols) {
748
+ console.error(`At least ${this.minNumCols} column(s) are required.`);
749
+ return this;
750
+ }
751
+ const rows = [];
752
+ this.idMatrix.forEach((row) => {
753
+ const deleted = row.splice(x, numCols);
754
+ rows.push(deleted);
755
+ });
756
+ this.area.right -= numCols;
757
+ this.pushHistory({
758
+ operation: "REMOVE_COLS",
759
+ reflection,
760
+ x,
761
+ idMatrix: rows,
762
+ });
763
+ return this.shallowCopy({ copyCache: false });
708
764
  }
709
- const numRows = this.getNumRows(1);
710
- const rows = [];
711
- const changedAt = new Date();
712
- for (let i = 0; i < numRows; i++) {
713
- const row = [];
714
- for (let j = 0; j < numCols; j++) {
715
- const id = this.generateId();
716
- row.push(id);
717
- const cell = this.getByPoint({ y: i, x: baseX });
718
- const copied = this.copyCellLayout(cell);
719
- this.idMatrix[i].splice(x, 0, id);
720
- this.data[id] = Object.assign(Object.assign({}, copied), { changedAt });
721
- }
722
- rows.push(row);
723
- }
724
- this.area.right += numCols;
725
- this.pushHistory({
726
- operation: "ADD_COLS",
727
- reflection,
728
- x,
729
- idMatrix: rows,
730
- });
731
- return this.shallowCopy({ copyCache: false });
732
- }
733
- removeCols({ x, numCols, reflection = {}, }) {
734
- if (this.minNumCols !== -1 &&
735
- this.getNumCols() - numCols < this.minNumCols) {
736
- console.error(`At least ${this.minNumCols} column(s) are required.`);
737
- return this;
765
+ getHistories() {
766
+ return [...this.histories];
738
767
  }
739
- const rows = [];
740
- this.idMatrix.forEach((row) => {
741
- const deleted = row.splice(x, numCols);
742
- rows.push(deleted);
743
- });
744
- this.area.right -= numCols;
745
- this.pushHistory({
746
- operation: "REMOVE_COLS",
747
- reflection,
748
- x,
749
- idMatrix: rows,
750
- });
751
- return this.shallowCopy({ copyCache: false });
752
- }
753
- getHistories() {
754
- return [...this.histories];
755
- }
756
- getHistoryIndex() {
757
- return this.historyIndex;
758
- }
759
- getHistorySize() {
760
- return this.histories.length;
761
- }
762
- getHistoryLimit() {
763
- return this.historyLimit;
764
- }
765
- setFunctions(additionalFunctions) {
766
- this.functions = Object.assign(Object.assign({}, functionsDefault), additionalFunctions);
767
- }
768
- getArea() {
769
- return Object.assign({}, this.area);
770
- }
771
- parse(point, value) {
772
- const cell = this.getByPoint(point) || {};
773
- const parser = this.parsers[cell.parser || ""] || defaultParser;
774
- return parser.call(value, cell);
775
- }
776
- render(point, writer) {
777
- const cell = this.getByPoint(point) || {};
778
- const renderer = this.renderers[cell.renderer || ""] || defaultRenderer;
779
- return renderer.call(this, point, writer);
780
- }
781
- stringify(point, value, evaluates = false) {
782
- const cell = this.getByPoint(point);
783
- const renderer = this.renderers[(cell === null || cell === void 0 ? void 0 : cell.renderer) || ""] || defaultRenderer;
784
- const s = renderer.stringify(typeof value === "undefined" ? Object.assign({}, cell) : Object.assign(Object.assign({}, cell), { value }));
785
- if (s[0] === "=") {
786
- if (evaluates) {
787
- return String(solveFormula({ value: s, table: this, raise: false }));
788
- }
789
- const lexer = new Lexer(s.substring(1));
790
- lexer.tokenize();
791
- return "=" + lexer.stringifyToRef(this);
792
- }
793
- return s;
794
- }
795
- trim(area) {
796
- const copied = new Table({});
797
- copied.area = area;
798
- copied.idMatrix = this.idMatrix;
799
- copied.data = this.data;
800
- copied.parsers = this.parsers;
801
- copied.renderers = this.renderers;
802
- copied.labelers = this.labelers;
803
- copied.functions = this.functions;
804
- copied.addressesById = this.addressesById;
805
- copied.solvedCaches = this.solvedCaches;
806
- return copied;
807
- }
808
- getIdByAddress(address) {
809
- const { y, x } = a2p(address);
810
- const id = this.getId({ y: Math.abs(y), x: Math.abs(x) });
811
- if (id) {
812
- return `#${x < 0 ? "$" : ""}${id}${y < 0 ? "$" : ""}`;
768
+ getHistoryIndex() {
769
+ return this.historyIndex;
813
770
  }
814
- }
815
- applyDiff(diff, partial = true) {
816
- if (!partial) {
817
- Object.assign(this.data, diff);
818
- return;
819
- }
820
- Object.keys(diff).map((id) => {
821
- const cell = diff[id];
822
- this.data[id] = Object.assign(Object.assign({}, this.getById(id)), cell);
823
- });
824
- }
825
- undo() {
826
- if (this.historyIndex < 0) {
827
- return { history: null, newTable: this };
828
- }
829
- const history = this.histories[this.historyIndex--];
830
- switch (history.operation) {
831
- case "UPDATE":
832
- // diffBefore is guaranteed as total of cell (not partial)
833
- this.applyDiff(history.diffBefore, false);
834
- break;
835
- case "ADD_ROWS": {
836
- if (history.diffBefore) {
837
- this.applyDiff(history.diffBefore, false);
771
+ getHistorySize() {
772
+ return this.histories.length;
773
+ }
774
+ getHistoryLimit() {
775
+ return this.historyLimit;
776
+ }
777
+ setFunctions(additionalFunctions) {
778
+ this.functions = Object.assign(Object.assign({}, mapping_1.functions), additionalFunctions);
779
+ }
780
+ getArea() {
781
+ return Object.assign({}, this.area);
782
+ }
783
+ parse(point, value) {
784
+ const cell = this.getByPoint(point) || {};
785
+ const parser = this.parsers[cell.parser || ""] || core_1.defaultParser;
786
+ return parser.call(value, cell);
787
+ }
788
+ render(point, writer) {
789
+ const cell = this.getByPoint(point) || {};
790
+ const renderer = this.renderers[cell.renderer || ""] || core_2.defaultRenderer;
791
+ return renderer.call(this, point, writer);
792
+ }
793
+ stringify(point, value, evaluates = false) {
794
+ const cell = this.getByPoint(point);
795
+ const renderer = this.renderers[(cell === null || cell === void 0 ? void 0 : cell.renderer) || ""] || core_2.defaultRenderer;
796
+ const s = renderer.stringify(typeof value === "undefined" ? Object.assign({}, cell) : Object.assign(Object.assign({}, cell), { value }));
797
+ if (s[0] === "=") {
798
+ if (evaluates) {
799
+ return String((0, solver_1.solveFormula)({ value: s, table: this, raise: false }));
838
800
  }
839
- const { height } = matrixShape({ matrix: history.idMatrix });
840
- this.idMatrix.splice(history.y, height);
841
- this.area.bottom -= height;
842
- break;
801
+ const lexer = new evaluator_1.Lexer(s.substring(1));
802
+ lexer.tokenize();
803
+ return "=" + lexer.stringifyToRef(this);
804
+ }
805
+ return s;
806
+ }
807
+ trim(area) {
808
+ const copied = new Table({});
809
+ copied.area = area;
810
+ copied.idMatrix = this.idMatrix;
811
+ copied.data = this.data;
812
+ copied.parsers = this.parsers;
813
+ copied.renderers = this.renderers;
814
+ copied.labelers = this.labelers;
815
+ copied.functions = this.functions;
816
+ copied.addressesById = this.addressesById;
817
+ copied.solvedCaches = this.solvedCaches;
818
+ return copied;
819
+ }
820
+ getIdByAddress(address) {
821
+ const { y, x } = (0, converters_1.a2p)(address);
822
+ const id = this.getId({ y: Math.abs(y), x: Math.abs(x) });
823
+ if (id) {
824
+ return `#${x < 0 ? "$" : ""}${id}${y < 0 ? "$" : ""}`;
825
+ }
826
+ }
827
+ applyDiff(diff, partial = true) {
828
+ if (!partial) {
829
+ Object.assign(this.data, diff);
830
+ return;
843
831
  }
844
- case "ADD_COLS": {
845
- if (history.diffBefore) {
832
+ Object.keys(diff).map((id) => {
833
+ const cell = diff[id];
834
+ this.data[id] = Object.assign(Object.assign({}, this.getById(id)), cell);
835
+ });
836
+ }
837
+ undo() {
838
+ if (this.historyIndex < 0) {
839
+ return { history: null, newTable: this };
840
+ }
841
+ const history = this.histories[this.historyIndex--];
842
+ switch (history.operation) {
843
+ case "UPDATE":
844
+ // diffBefore is guaranteed as total of cell (not partial)
846
845
  this.applyDiff(history.diffBefore, false);
846
+ break;
847
+ case "ADD_ROWS": {
848
+ if (history.diffBefore) {
849
+ this.applyDiff(history.diffBefore, false);
850
+ }
851
+ const { height } = (0, structs_1.matrixShape)({ matrix: history.idMatrix });
852
+ this.idMatrix.splice(history.y, height);
853
+ this.area.bottom -= height;
854
+ break;
855
+ }
856
+ case "ADD_COLS": {
857
+ if (history.diffBefore) {
858
+ this.applyDiff(history.diffBefore, false);
859
+ }
860
+ const { width } = (0, structs_1.matrixShape)({ matrix: history.idMatrix });
861
+ this.idMatrix.forEach((row) => {
862
+ row.splice(history.x, width);
863
+ });
864
+ this.area.right -= width;
865
+ break;
866
+ }
867
+ case "REMOVE_ROWS": {
868
+ const { height } = (0, structs_1.matrixShape)({ matrix: history.idMatrix });
869
+ this.idMatrix.splice(history.y, 0, ...history.idMatrix);
870
+ this.area.bottom += height;
871
+ break;
872
+ }
873
+ case "REMOVE_COLS": {
874
+ const { width } = (0, structs_1.matrixShape)({ matrix: history.idMatrix });
875
+ this.idMatrix.forEach((row, i) => {
876
+ row.splice(history.x, 0, ...history.idMatrix[i]);
877
+ });
878
+ this.area.right += width;
879
+ break;
880
+ }
881
+ case "MOVE": {
882
+ const { y: yFrom, x: xFrom } = history.pointFrom;
883
+ const { y: yTo, x: xTo } = history.pointTo;
884
+ const { height: rows, width: cols } = (0, structs_1.matrixShape)({
885
+ matrix: history.matrixFrom,
886
+ base: -1,
887
+ });
888
+ (0, structs_1.putMatrix)(this.idMatrix, history.matrixFrom, {
889
+ top: yFrom,
890
+ left: xFrom,
891
+ bottom: yFrom + rows,
892
+ right: xFrom + cols,
893
+ });
894
+ (0, structs_1.putMatrix)(this.idMatrix, history.matrixTo, {
895
+ top: yTo,
896
+ left: xTo,
897
+ bottom: yTo + rows,
898
+ right: xTo + cols,
899
+ });
900
+ break;
847
901
  }
848
- const { width } = matrixShape({ matrix: history.idMatrix });
849
- this.idMatrix.forEach((row) => {
850
- row.splice(history.x, width);
851
- });
852
- this.area.right -= width;
853
- break;
854
- }
855
- case "REMOVE_ROWS": {
856
- const { height } = matrixShape({ matrix: history.idMatrix });
857
- this.idMatrix.splice(history.y, 0, ...history.idMatrix);
858
- this.area.bottom += height;
859
- break;
860
- }
861
- case "REMOVE_COLS": {
862
- const { width } = matrixShape({ matrix: history.idMatrix });
863
- this.idMatrix.forEach((row, i) => {
864
- row.splice(history.x, 0, ...history.idMatrix[i]);
865
- });
866
- this.area.right += width;
867
- break;
868
- }
869
- case "MOVE": {
870
- const { y: yFrom, x: xFrom } = history.pointFrom;
871
- const { y: yTo, x: xTo } = history.pointTo;
872
- const { height: rows, width: cols } = matrixShape({
873
- matrix: history.matrixFrom,
874
- base: -1,
875
- });
876
- putMatrix(this.idMatrix, history.matrixFrom, {
877
- top: yFrom,
878
- left: xFrom,
879
- bottom: yFrom + rows,
880
- right: xFrom + cols,
881
- });
882
- putMatrix(this.idMatrix, history.matrixTo, {
883
- top: yTo,
884
- left: xTo,
885
- bottom: yTo + rows,
886
- right: xTo + cols,
887
- });
888
- break;
889
902
  }
903
+ return {
904
+ history,
905
+ newTable: this.shallowCopy({
906
+ copyCache: !(0, helpers_1.shouldTracking)(history.operation),
907
+ }),
908
+ };
890
909
  }
891
- return {
892
- history,
893
- newTable: this.shallowCopy({
894
- copyCache: !shouldTracking(history.operation),
895
- }),
896
- };
897
- }
898
- redo() {
899
- if (this.historyIndex + 1 >= this.histories.length) {
900
- return { history: null, newTable: this };
901
- }
902
- const history = this.histories[++this.historyIndex];
903
- switch (history.operation) {
904
- case "UPDATE":
905
- this.applyDiff(history.diffAfter, history.partial);
906
- break;
907
- case "ADD_ROWS": {
908
- if (history.diffAfter) {
909
- this.applyDiff(history.diffAfter, history.partial);
910
- }
911
- const { height } = matrixShape({ matrix: history.idMatrix });
912
- this.idMatrix.splice(history.y, 0, ...history.idMatrix);
913
- this.area.bottom += height;
914
- break;
910
+ redo() {
911
+ if (this.historyIndex + 1 >= this.histories.length) {
912
+ return { history: null, newTable: this };
915
913
  }
916
- case "ADD_COLS": {
917
- if (history.diffAfter) {
914
+ const history = this.histories[++this.historyIndex];
915
+ switch (history.operation) {
916
+ case "UPDATE":
918
917
  this.applyDiff(history.diffAfter, history.partial);
918
+ break;
919
+ case "ADD_ROWS": {
920
+ if (history.diffAfter) {
921
+ this.applyDiff(history.diffAfter, history.partial);
922
+ }
923
+ const { height } = (0, structs_1.matrixShape)({ matrix: history.idMatrix });
924
+ this.idMatrix.splice(history.y, 0, ...history.idMatrix);
925
+ this.area.bottom += height;
926
+ break;
927
+ }
928
+ case "ADD_COLS": {
929
+ if (history.diffAfter) {
930
+ this.applyDiff(history.diffAfter, history.partial);
931
+ }
932
+ const { width } = (0, structs_1.matrixShape)({ matrix: history.idMatrix });
933
+ this.idMatrix.map((row, i) => {
934
+ row.splice(history.x, 0, ...history.idMatrix[i]);
935
+ });
936
+ this.area.right += width;
937
+ break;
938
+ }
939
+ case "REMOVE_ROWS": {
940
+ const { height } = (0, structs_1.matrixShape)({ matrix: history.idMatrix });
941
+ this.idMatrix.splice(history.y, height);
942
+ this.area.bottom -= height;
943
+ break;
944
+ }
945
+ case "REMOVE_COLS": {
946
+ const { width } = (0, structs_1.matrixShape)({ matrix: history.idMatrix });
947
+ this.idMatrix.forEach((row) => {
948
+ row.splice(history.x, width);
949
+ });
950
+ this.area.right -= width;
951
+ break;
952
+ }
953
+ case "MOVE": {
954
+ const { y: yFrom, x: xFrom } = history.pointFrom;
955
+ const { y: yTo, x: xTo } = history.pointTo;
956
+ const { height: rows, width: cols } = (0, structs_1.matrixShape)({
957
+ matrix: history.matrixFrom,
958
+ base: -1,
959
+ });
960
+ (0, structs_1.putMatrix)(this.idMatrix, history.matrixNew, {
961
+ top: yFrom,
962
+ left: xFrom,
963
+ bottom: yFrom + rows,
964
+ right: xFrom + cols,
965
+ });
966
+ (0, structs_1.putMatrix)(this.idMatrix, history.matrixFrom, {
967
+ top: yTo,
968
+ left: xTo,
969
+ bottom: yTo + rows,
970
+ right: xTo + cols,
971
+ });
919
972
  }
920
- const { width } = matrixShape({ matrix: history.idMatrix });
921
- this.idMatrix.map((row, i) => {
922
- row.splice(history.x, 0, ...history.idMatrix[i]);
923
- });
924
- this.area.right += width;
925
- break;
926
- }
927
- case "REMOVE_ROWS": {
928
- const { height } = matrixShape({ matrix: history.idMatrix });
929
- this.idMatrix.splice(history.y, height);
930
- this.area.bottom -= height;
931
- break;
932
- }
933
- case "REMOVE_COLS": {
934
- const { width } = matrixShape({ matrix: history.idMatrix });
935
- this.idMatrix.forEach((row) => {
936
- row.splice(history.x, width);
937
- });
938
- this.area.right -= width;
939
- break;
940
- }
941
- case "MOVE": {
942
- const { y: yFrom, x: xFrom } = history.pointFrom;
943
- const { y: yTo, x: xTo } = history.pointTo;
944
- const { height: rows, width: cols } = matrixShape({
945
- matrix: history.matrixFrom,
946
- base: -1,
947
- });
948
- putMatrix(this.idMatrix, history.matrixNew, {
949
- top: yFrom,
950
- left: xFrom,
951
- bottom: yFrom + rows,
952
- right: xFrom + cols,
953
- });
954
- putMatrix(this.idMatrix, history.matrixFrom, {
955
- top: yTo,
956
- left: xTo,
957
- bottom: yTo + rows,
958
- right: xTo + cols,
959
- });
960
973
  }
974
+ return {
975
+ history,
976
+ newTable: this.shallowCopy({
977
+ copyCache: !(0, helpers_1.shouldTracking)(history.operation),
978
+ }),
979
+ };
980
+ }
981
+ getFunction(name) {
982
+ return this.functions[name];
983
+ }
984
+ getLabel(key, n) {
985
+ const labeler = this.labelers[key];
986
+ return labeler === null || labeler === void 0 ? void 0 : labeler(n);
987
+ }
988
+ getBase() {
989
+ return this;
990
+ }
991
+ getSolvedCache(key) {
992
+ return this.solvedCaches[key];
993
+ }
994
+ setSolvedCache(key, value) {
995
+ this.solvedCaches[key] = value;
961
996
  }
962
- return {
963
- history,
964
- newTable: this.shallowCopy({
965
- copyCache: !shouldTracking(history.operation),
966
- }),
967
- };
968
- }
969
- getFunction(name) {
970
- return this.functions[name];
971
- }
972
- getLabel(key, n) {
973
- const labeler = this.labelers[key];
974
- return labeler === null || labeler === void 0 ? void 0 : labeler(n);
975
- }
976
- getBase() {
977
- return this;
978
- }
979
- getSolvedCache(key) {
980
- return this.solvedCaches[key];
981
997
  }
982
- setSolvedCache(key, value) {
983
- this.solvedCaches[key] = value;
998
+ exports.Table = Table;
999
+ // just using as a type
1000
+ class ReadonlyTable extends Table {
984
1001
  }
985
- }
986
- // just using as a type
987
- export class ReadonlyTable extends Table {
988
- }
1002
+ exports.ReadonlyTable = ReadonlyTable;
1003
+ });
989
1004
  //# sourceMappingURL=table.js.map