@gridsheet/react-core 0.12.2 → 0.12.4-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/README.md +1 -1
  2. package/dist/components/Cell.d.ts.map +1 -1
  3. package/dist/components/Emitter.d.ts.map +1 -1
  4. package/dist/components/GridSheet.d.ts.map +1 -1
  5. package/dist/components/HeaderLeftCell.d.ts.map +1 -1
  6. package/dist/components/HeaderTopCell.d.ts.map +1 -1
  7. package/dist/components/Resizer.d.ts.map +1 -1
  8. package/dist/components/SearchBox.d.ts.map +1 -1
  9. package/dist/components/Tabular.d.ts.map +1 -1
  10. package/dist/constants.d.ts.map +1 -1
  11. package/dist/formula/evaluator.d.ts.map +1 -1
  12. package/dist/formula/functions/__base.d.ts.map +1 -1
  13. package/dist/formula/solver.d.ts.map +1 -1
  14. package/dist/index.d.ts +1824 -1
  15. package/dist/index.js +5205 -11
  16. package/dist/lib/structs.d.ts.map +1 -1
  17. package/dist/lib/table.d.ts.map +1 -1
  18. package/dist/lib/time.d.ts.map +1 -1
  19. package/dist/lib/virtualization.d.ts.map +1 -1
  20. package/dist/parsers/core.d.ts.map +1 -1
  21. package/dist/renderers/core.d.ts.map +1 -1
  22. package/dist/store/actions.d.ts.map +1 -1
  23. package/dist/store/index.d.ts.map +1 -1
  24. package/dist/styles/minified.d.ts.map +1 -1
  25. package/dist/types.d.ts.map +1 -1
  26. package/package.json +13 -3
  27. package/dist/components/Cell.d.ts +0 -8
  28. package/dist/components/Cell.js +0 -199
  29. package/dist/components/Cell.js.map +0 -1
  30. package/dist/components/ContextMenu.d.ts +0 -3
  31. package/dist/components/ContextMenu.js +0 -207
  32. package/dist/components/ContextMenu.js.map +0 -1
  33. package/dist/components/Editor.d.ts +0 -3
  34. package/dist/components/Editor.js +0 -304
  35. package/dist/components/Editor.js.map +0 -1
  36. package/dist/components/Emitter.d.ts +0 -9
  37. package/dist/components/Emitter.js +0 -26
  38. package/dist/components/Emitter.js.map +0 -1
  39. package/dist/components/GridSheet.d.ts +0 -4
  40. package/dist/components/GridSheet.js +0 -110
  41. package/dist/components/GridSheet.js.map +0 -1
  42. package/dist/components/HeaderLeftCell.d.ts +0 -7
  43. package/dist/components/HeaderLeftCell.js +0 -67
  44. package/dist/components/HeaderLeftCell.js.map +0 -1
  45. package/dist/components/HeaderTopCell.d.ts +0 -7
  46. package/dist/components/HeaderTopCell.js +0 -68
  47. package/dist/components/HeaderTopCell.js.map +0 -1
  48. package/dist/components/Resizer.d.ts +0 -3
  49. package/dist/components/Resizer.js +0 -83
  50. package/dist/components/Resizer.js.map +0 -1
  51. package/dist/components/SearchBox.d.ts +0 -3
  52. package/dist/components/SearchBox.js +0 -52
  53. package/dist/components/SearchBox.js.map +0 -1
  54. package/dist/components/StoreInitializer.d.ts +0 -4
  55. package/dist/components/StoreInitializer.js +0 -68
  56. package/dist/components/StoreInitializer.js.map +0 -1
  57. package/dist/components/Tabular.d.ts +0 -9
  58. package/dist/components/Tabular.js +0 -84
  59. package/dist/components/Tabular.js.map +0 -1
  60. package/dist/constants.d.ts +0 -18
  61. package/dist/constants.js +0 -21
  62. package/dist/constants.js.map +0 -1
  63. package/dist/formula/evaluator.d.ts +0 -91
  64. package/dist/formula/evaluator.js +0 -541
  65. package/dist/formula/evaluator.js.map +0 -1
  66. package/dist/formula/functions/__base.d.ts +0 -23
  67. package/dist/formula/functions/__base.js +0 -16
  68. package/dist/formula/functions/__base.js.map +0 -1
  69. package/dist/formula/functions/__utils.d.ts +0 -6
  70. package/dist/formula/functions/__utils.js +0 -102
  71. package/dist/formula/functions/__utils.js.map +0 -1
  72. package/dist/formula/functions/abs.d.ts +0 -12
  73. package/dist/formula/functions/abs.js +0 -21
  74. package/dist/formula/functions/abs.js.map +0 -1
  75. package/dist/formula/functions/abs.spec.d.ts +0 -2
  76. package/dist/formula/functions/abs.spec.js +0 -29
  77. package/dist/formula/functions/abs.spec.js.map +0 -1
  78. package/dist/formula/functions/acos.d.ts +0 -12
  79. package/dist/formula/functions/acos.js +0 -29
  80. package/dist/formula/functions/acos.js.map +0 -1
  81. package/dist/formula/functions/add.d.ts +0 -13
  82. package/dist/formula/functions/add.js +0 -50
  83. package/dist/formula/functions/add.js.map +0 -1
  84. package/dist/formula/functions/and.d.ts +0 -19
  85. package/dist/formula/functions/and.js +0 -28
  86. package/dist/formula/functions/and.js.map +0 -1
  87. package/dist/formula/functions/asin.d.ts +0 -12
  88. package/dist/formula/functions/asin.js +0 -29
  89. package/dist/formula/functions/asin.js.map +0 -1
  90. package/dist/formula/functions/atan.d.ts +0 -12
  91. package/dist/formula/functions/atan.js +0 -26
  92. package/dist/formula/functions/atan.js.map +0 -1
  93. package/dist/formula/functions/atan2.d.ts +0 -12
  94. package/dist/formula/functions/atan2.js +0 -32
  95. package/dist/formula/functions/atan2.js.map +0 -1
  96. package/dist/formula/functions/average.d.ts +0 -19
  97. package/dist/formula/functions/average.js +0 -41
  98. package/dist/formula/functions/average.js.map +0 -1
  99. package/dist/formula/functions/col.d.ts +0 -14
  100. package/dist/formula/functions/col.js +0 -30
  101. package/dist/formula/functions/col.js.map +0 -1
  102. package/dist/formula/functions/concat.d.ts +0 -12
  103. package/dist/formula/functions/concat.js +0 -27
  104. package/dist/formula/functions/concat.js.map +0 -1
  105. package/dist/formula/functions/concatenate.d.ts +0 -19
  106. package/dist/formula/functions/concatenate.js +0 -25
  107. package/dist/formula/functions/concatenate.js.map +0 -1
  108. package/dist/formula/functions/cos.d.ts +0 -12
  109. package/dist/formula/functions/cos.js +0 -26
  110. package/dist/formula/functions/cos.js.map +0 -1
  111. package/dist/formula/functions/count.d.ts +0 -19
  112. package/dist/formula/functions/count.js +0 -35
  113. package/dist/formula/functions/count.js.map +0 -1
  114. package/dist/formula/functions/counta.d.ts +0 -19
  115. package/dist/formula/functions/counta.js +0 -35
  116. package/dist/formula/functions/counta.js.map +0 -1
  117. package/dist/formula/functions/countif.d.ts +0 -13
  118. package/dist/formula/functions/countif.js +0 -30
  119. package/dist/formula/functions/countif.js.map +0 -1
  120. package/dist/formula/functions/divide.d.ts +0 -12
  121. package/dist/formula/functions/divide.js +0 -33
  122. package/dist/formula/functions/divide.js.map +0 -1
  123. package/dist/formula/functions/eq.d.ts +0 -12
  124. package/dist/formula/functions/eq.js +0 -25
  125. package/dist/formula/functions/eq.js.map +0 -1
  126. package/dist/formula/functions/exp.d.ts +0 -12
  127. package/dist/formula/functions/exp.js +0 -28
  128. package/dist/formula/functions/exp.js.map +0 -1
  129. package/dist/formula/functions/gt.d.ts +0 -12
  130. package/dist/formula/functions/gt.js +0 -27
  131. package/dist/formula/functions/gt.js.map +0 -1
  132. package/dist/formula/functions/gte.d.ts +0 -12
  133. package/dist/formula/functions/gte.js +0 -27
  134. package/dist/formula/functions/gte.js.map +0 -1
  135. package/dist/formula/functions/hlookup.d.ts +0 -18
  136. package/dist/formula/functions/hlookup.js +0 -74
  137. package/dist/formula/functions/hlookup.js.map +0 -1
  138. package/dist/formula/functions/if.d.ts +0 -17
  139. package/dist/formula/functions/if.js +0 -36
  140. package/dist/formula/functions/if.js.map +0 -1
  141. package/dist/formula/functions/iferror.d.ts +0 -20
  142. package/dist/formula/functions/iferror.js +0 -41
  143. package/dist/formula/functions/iferror.js.map +0 -1
  144. package/dist/formula/functions/iferror.spec.d.ts +0 -2
  145. package/dist/formula/functions/iferror.spec.js +0 -61
  146. package/dist/formula/functions/iferror.spec.js.map +0 -1
  147. package/dist/formula/functions/len.d.ts +0 -12
  148. package/dist/formula/functions/len.js +0 -26
  149. package/dist/formula/functions/len.js.map +0 -1
  150. package/dist/formula/functions/lenb.d.ts +0 -12
  151. package/dist/formula/functions/lenb.js +0 -26
  152. package/dist/formula/functions/lenb.js.map +0 -1
  153. package/dist/formula/functions/ln.d.ts +0 -12
  154. package/dist/formula/functions/ln.js +0 -29
  155. package/dist/formula/functions/ln.js.map +0 -1
  156. package/dist/formula/functions/log.d.ts +0 -12
  157. package/dist/formula/functions/log.js +0 -35
  158. package/dist/formula/functions/log.js.map +0 -1
  159. package/dist/formula/functions/log10.d.ts +0 -12
  160. package/dist/formula/functions/log10.js +0 -29
  161. package/dist/formula/functions/log10.js.map +0 -1
  162. package/dist/formula/functions/lt.d.ts +0 -12
  163. package/dist/formula/functions/lt.js +0 -27
  164. package/dist/formula/functions/lt.js.map +0 -1
  165. package/dist/formula/functions/lte.d.ts +0 -12
  166. package/dist/formula/functions/lte.js +0 -27
  167. package/dist/formula/functions/lte.js.map +0 -1
  168. package/dist/formula/functions/max.d.ts +0 -19
  169. package/dist/formula/functions/max.js +0 -44
  170. package/dist/formula/functions/max.js.map +0 -1
  171. package/dist/formula/functions/min.d.ts +0 -19
  172. package/dist/formula/functions/min.js +0 -44
  173. package/dist/formula/functions/min.js.map +0 -1
  174. package/dist/formula/functions/minus.d.ts +0 -13
  175. package/dist/formula/functions/minus.js +0 -50
  176. package/dist/formula/functions/minus.js.map +0 -1
  177. package/dist/formula/functions/mod.d.ts +0 -12
  178. package/dist/formula/functions/mod.js +0 -31
  179. package/dist/formula/functions/mod.js.map +0 -1
  180. package/dist/formula/functions/mod.spec.d.ts +0 -2
  181. package/dist/formula/functions/mod.spec.js +0 -52
  182. package/dist/formula/functions/mod.spec.js.map +0 -1
  183. package/dist/formula/functions/multiply.d.ts +0 -12
  184. package/dist/formula/functions/multiply.js +0 -27
  185. package/dist/formula/functions/multiply.js.map +0 -1
  186. package/dist/formula/functions/ne.d.ts +0 -12
  187. package/dist/formula/functions/ne.js +0 -25
  188. package/dist/formula/functions/ne.js.map +0 -1
  189. package/dist/formula/functions/not.d.ts +0 -12
  190. package/dist/formula/functions/not.js +0 -30
  191. package/dist/formula/functions/not.js.map +0 -1
  192. package/dist/formula/functions/now.d.ts +0 -9
  193. package/dist/formula/functions/now.js +0 -21
  194. package/dist/formula/functions/now.js.map +0 -1
  195. package/dist/formula/functions/or.d.ts +0 -19
  196. package/dist/formula/functions/or.js +0 -28
  197. package/dist/formula/functions/or.js.map +0 -1
  198. package/dist/formula/functions/pi.d.ts +0 -9
  199. package/dist/formula/functions/pi.js +0 -19
  200. package/dist/formula/functions/pi.js.map +0 -1
  201. package/dist/formula/functions/power.d.ts +0 -12
  202. package/dist/formula/functions/power.js +0 -24
  203. package/dist/formula/functions/power.js.map +0 -1
  204. package/dist/formula/functions/product.d.ts +0 -19
  205. package/dist/formula/functions/product.js +0 -37
  206. package/dist/formula/functions/product.js.map +0 -1
  207. package/dist/formula/functions/radians.d.ts +0 -12
  208. package/dist/formula/functions/radians.js +0 -26
  209. package/dist/formula/functions/radians.js.map +0 -1
  210. package/dist/formula/functions/rand.d.ts +0 -9
  211. package/dist/formula/functions/rand.js +0 -19
  212. package/dist/formula/functions/rand.js.map +0 -1
  213. package/dist/formula/functions/round.d.ts +0 -17
  214. package/dist/formula/functions/round.js +0 -34
  215. package/dist/formula/functions/round.js.map +0 -1
  216. package/dist/formula/functions/rounddown.d.ts +0 -17
  217. package/dist/formula/functions/rounddown.js +0 -34
  218. package/dist/formula/functions/rounddown.js.map +0 -1
  219. package/dist/formula/functions/roundup.d.ts +0 -17
  220. package/dist/formula/functions/roundup.js +0 -34
  221. package/dist/formula/functions/roundup.js.map +0 -1
  222. package/dist/formula/functions/row.d.ts +0 -14
  223. package/dist/formula/functions/row.js +0 -30
  224. package/dist/formula/functions/row.js.map +0 -1
  225. package/dist/formula/functions/sin.d.ts +0 -12
  226. package/dist/formula/functions/sin.js +0 -26
  227. package/dist/formula/functions/sin.js.map +0 -1
  228. package/dist/formula/functions/sqrt.d.ts +0 -12
  229. package/dist/formula/functions/sqrt.js +0 -29
  230. package/dist/formula/functions/sqrt.js.map +0 -1
  231. package/dist/formula/functions/sum.d.ts +0 -19
  232. package/dist/formula/functions/sum.js +0 -44
  233. package/dist/formula/functions/sum.js.map +0 -1
  234. package/dist/formula/functions/sum.spec.d.ts +0 -2
  235. package/dist/formula/functions/sum.spec.js +0 -40
  236. package/dist/formula/functions/sum.spec.js.map +0 -1
  237. package/dist/formula/functions/sumif.d.ts +0 -18
  238. package/dist/formula/functions/sumif.js +0 -59
  239. package/dist/formula/functions/sumif.js.map +0 -1
  240. package/dist/formula/functions/tan.d.ts +0 -12
  241. package/dist/formula/functions/tan.js +0 -26
  242. package/dist/formula/functions/tan.js.map +0 -1
  243. package/dist/formula/functions/uminus.d.ts +0 -12
  244. package/dist/formula/functions/uminus.js +0 -23
  245. package/dist/formula/functions/uminus.js.map +0 -1
  246. package/dist/formula/functions/vlookup.d.ts +0 -18
  247. package/dist/formula/functions/vlookup.js +0 -74
  248. package/dist/formula/functions/vlookup.js.map +0 -1
  249. package/dist/formula/mapping.d.ts +0 -114
  250. package/dist/formula/mapping.js +0 -114
  251. package/dist/formula/mapping.js.map +0 -1
  252. package/dist/formula/solver.d.ts +0 -12
  253. package/dist/formula/solver.js +0 -64
  254. package/dist/formula/solver.js.map +0 -1
  255. package/dist/index.js.map +0 -1
  256. package/dist/lib/autofill.d.ts +0 -17
  257. package/dist/lib/autofill.js +0 -389
  258. package/dist/lib/autofill.js.map +0 -1
  259. package/dist/lib/clipboard.d.ts +0 -3
  260. package/dist/lib/clipboard.js +0 -45
  261. package/dist/lib/clipboard.js.map +0 -1
  262. package/dist/lib/converters.d.ts +0 -10
  263. package/dist/lib/converters.js +0 -127
  264. package/dist/lib/converters.js.map +0 -1
  265. package/dist/lib/structs.d.ts +0 -60
  266. package/dist/lib/structs.js +0 -251
  267. package/dist/lib/structs.js.map +0 -1
  268. package/dist/lib/table.d.ts +0 -299
  269. package/dist/lib/table.js +0 -989
  270. package/dist/lib/table.js.map +0 -1
  271. package/dist/lib/time.d.ts +0 -14
  272. package/dist/lib/time.js +0 -60
  273. package/dist/lib/time.js.map +0 -1
  274. package/dist/lib/virtualization.d.ts +0 -30
  275. package/dist/lib/virtualization.js +0 -114
  276. package/dist/lib/virtualization.js.map +0 -1
  277. package/dist/parsers/core.d.ts +0 -36
  278. package/dist/parsers/core.js +0 -123
  279. package/dist/parsers/core.js.map +0 -1
  280. package/dist/renderers/checkbox.d.ts +0 -5
  281. package/dist/renderers/checkbox.js +0 -10
  282. package/dist/renderers/checkbox.js.map +0 -1
  283. package/dist/renderers/core.d.ts +0 -48
  284. package/dist/renderers/core.js +0 -143
  285. package/dist/renderers/core.js.map +0 -1
  286. package/dist/renderers/thousand_separator.d.ts +0 -5
  287. package/dist/renderers/thousand_separator.js +0 -14
  288. package/dist/renderers/thousand_separator.js.map +0 -1
  289. package/dist/store/actions.d.ts +0 -198
  290. package/dist/store/actions.js +0 -519
  291. package/dist/store/actions.js.map +0 -1
  292. package/dist/store/helpers.d.ts +0 -28
  293. package/dist/store/helpers.js +0 -78
  294. package/dist/store/helpers.js.map +0 -1
  295. package/dist/store/index.d.ts +0 -11
  296. package/dist/store/index.js +0 -3
  297. package/dist/store/index.js.map +0 -1
  298. package/dist/styles/embedder.d.ts +0 -2
  299. package/dist/styles/embedder.js +0 -16
  300. package/dist/styles/embedder.js.map +0 -1
  301. package/dist/styles/minified.d.ts +0 -3
  302. package/dist/styles/minified.js +0 -4
  303. package/dist/styles/minified.js.map +0 -1
  304. package/dist/types.d.ts +0 -213
  305. package/dist/types.js +0 -2
  306. package/dist/types.js.map +0 -1
  307. package/dist/utils.d.ts +0 -2
  308. package/dist/utils.js +0 -7
  309. package/dist/utils.js.map +0 -1
package/dist/lib/table.js DELETED
@@ -1,989 +0,0 @@
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;
67
- }
68
- }
69
- else if (x === 0) {
70
- if (stacked.height == null) {
71
- stacked.height = DEFAULT_HEIGHT;
72
- }
73
- }
74
- else {
75
- delete stacked.height;
76
- delete stacked.width;
77
- delete stacked.labeler;
78
- }
79
- this.data[id] = stacked;
80
- }
81
- }
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;
92
- }
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;
95
- }
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;
128
- }
129
- else {
130
- // force reset
131
- this.addressesById = {};
132
- }
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
- }
160
- }
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);
177
- }
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
- }
243
- }
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
- }
262
- }
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
- }
283
- }
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);
292
- 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({
297
- value: cell[key],
298
- table: this,
299
- raise,
300
- })
301
- : cell[key];
302
- }
303
- }
304
- }
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,
322
- table: this,
323
- raise,
324
- })
325
- : cell === null || cell === void 0 ? void 0 : cell.value });
326
- }
327
- }
328
- }
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,
341
- table: this,
342
- raise,
343
- })
344
- : cell === null || cell === void 0 ? void 0 : cell.value });
345
- }
346
- }
347
- }
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);
356
- 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,
362
- table: this,
363
- raise,
364
- })
365
- : cell === null || cell === void 0 ? void 0 : cell.value });
366
- }
367
- }
368
- }
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);
377
- 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 });
387
- }
388
- }
389
- }
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
- });
430
- }
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());
440
- }
441
- }
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);
451
- 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);
455
- }
456
- }
457
- }
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;
477
- }
478
- if (cell.alignItems != null) {
479
- newCell.alignItems = cell.alignItems;
480
- }
481
- if (cell.renderer != null) {
482
- newCell.renderer = cell.renderer;
483
- }
484
- if (cell.parser != null) {
485
- newCell.parser = cell.parser;
486
- }
487
- if (cell.width != null) {
488
- newCell.width = cell.width;
489
- }
490
- if (cell.height != null) {
491
- newCell.height = cell.height;
492
- }
493
- if (cell.labeler != null) {
494
- newCell.labeler = cell.labeler;
495
- }
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()) {
537
- continue;
538
- }
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 });
555
- }
556
- }
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
- });
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) {
616
- return;
617
- }
618
- const cell = this.parse({ y, x }, value);
619
- diff[p2a({ y, x })] = cell;
620
- });
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
- }
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;
682
- }
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;
708
- }
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;
738
- }
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 ? "$" : ""}`;
813
- }
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);
838
- }
839
- const { height } = matrixShape({ matrix: history.idMatrix });
840
- this.idMatrix.splice(history.y, height);
841
- this.area.bottom -= height;
842
- break;
843
- }
844
- case "ADD_COLS": {
845
- if (history.diffBefore) {
846
- this.applyDiff(history.diffBefore, false);
847
- }
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
- }
890
- }
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;
915
- }
916
- case "ADD_COLS": {
917
- if (history.diffAfter) {
918
- this.applyDiff(history.diffAfter, history.partial);
919
- }
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
- }
961
- }
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
- }
982
- setSolvedCache(key, value) {
983
- this.solvedCaches[key] = value;
984
- }
985
- }
986
- // just using as a type
987
- export class ReadonlyTable extends Table {
988
- }
989
- //# sourceMappingURL=table.js.map