@gridsheet/react-core 0.12.4-rc.0 → 0.12.4

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