@gridsheet/react-core 1.4.0-alpha.2 → 1.4.0-alpha.3

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 (235) hide show
  1. package/dist/_virtual/_commonjsHelpers.js +7 -0
  2. package/dist/_virtual/_commonjsHelpers.js.map +1 -0
  3. package/dist/_virtual/dayjs.min.js +8 -0
  4. package/dist/_virtual/dayjs.min.js.map +1 -0
  5. package/dist/_virtual/dayjs.min2.js +5 -0
  6. package/dist/_virtual/dayjs.min2.js.map +1 -0
  7. package/dist/_virtual/jsx-runtime.js +6 -0
  8. package/dist/_virtual/jsx-runtime.js.map +1 -0
  9. package/dist/_virtual/jsx-runtime2.js +5 -0
  10. package/dist/_virtual/jsx-runtime2.js.map +1 -0
  11. package/dist/_virtual/react-jsx-runtime.development.js +5 -0
  12. package/dist/_virtual/react-jsx-runtime.development.js.map +1 -0
  13. package/dist/_virtual/react-jsx-runtime.production.js +5 -0
  14. package/dist/_virtual/react-jsx-runtime.production.js.map +1 -0
  15. package/dist/_virtual/timezone.js +8 -0
  16. package/dist/_virtual/timezone.js.map +1 -0
  17. package/dist/_virtual/timezone2.js +5 -0
  18. package/dist/_virtual/timezone2.js.map +1 -0
  19. package/dist/_virtual/utc.js +8 -0
  20. package/dist/_virtual/utc.js.map +1 -0
  21. package/dist/_virtual/utc2.js +5 -0
  22. package/dist/_virtual/utc2.js.map +1 -0
  23. package/dist/components/Cell.js +232 -0
  24. package/dist/components/Cell.js.map +1 -0
  25. package/dist/components/ContextMenu.js +297 -0
  26. package/dist/components/ContextMenu.js.map +1 -0
  27. package/dist/components/Editor.js +455 -0
  28. package/dist/components/Editor.js.map +1 -0
  29. package/dist/components/Emitter.js +26 -0
  30. package/dist/components/Emitter.js.map +1 -0
  31. package/dist/components/Fixed.js +17 -0
  32. package/dist/components/Fixed.js.map +1 -0
  33. package/dist/components/FormulaBar.js +149 -0
  34. package/dist/components/FormulaBar.js.map +1 -0
  35. package/dist/components/GridSheet.js +246 -0
  36. package/dist/components/GridSheet.js.map +1 -0
  37. package/dist/components/HeaderCellLeft.js +131 -0
  38. package/dist/components/HeaderCellLeft.js.map +1 -0
  39. package/dist/components/HeaderCellTop.js +132 -0
  40. package/dist/components/HeaderCellTop.js.map +1 -0
  41. package/dist/components/PluginBase.js +35 -0
  42. package/dist/components/PluginBase.js.map +1 -0
  43. package/dist/components/Resizer.js +98 -0
  44. package/dist/components/Resizer.js.map +1 -0
  45. package/dist/components/SearchBar.js +108 -0
  46. package/dist/components/SearchBar.js.map +1 -0
  47. package/dist/components/SheetProvider.js +56 -0
  48. package/dist/components/SheetProvider.js.map +1 -0
  49. package/dist/components/StoreInitializer.js +84 -0
  50. package/dist/components/StoreInitializer.js.map +1 -0
  51. package/dist/components/Tabular.js +308 -0
  52. package/dist/components/Tabular.js.map +1 -0
  53. package/dist/components/hooks.js +15 -0
  54. package/dist/components/hooks.js.map +1 -0
  55. package/dist/components/svg/Base.js +24 -0
  56. package/dist/components/svg/Base.js.map +1 -0
  57. package/dist/components/svg/CloseIcon.js +13 -0
  58. package/dist/components/svg/CloseIcon.js.map +1 -0
  59. package/dist/components/svg/SearchIcon.js +13 -0
  60. package/dist/components/svg/SearchIcon.js.map +1 -0
  61. package/dist/constants.js +43 -0
  62. package/dist/constants.js.map +1 -0
  63. package/dist/formula/evaluator.js +674 -0
  64. package/dist/formula/evaluator.js.map +1 -0
  65. package/dist/formula/functions/__base.js +19 -0
  66. package/dist/formula/functions/__base.js.map +1 -0
  67. package/dist/formula/functions/__utils.js +145 -0
  68. package/dist/formula/functions/__utils.js.map +1 -0
  69. package/dist/formula/functions/abs.js +24 -0
  70. package/dist/formula/functions/abs.js.map +1 -0
  71. package/dist/formula/functions/acos.js +32 -0
  72. package/dist/formula/functions/acos.js.map +1 -0
  73. package/dist/formula/functions/add.js +57 -0
  74. package/dist/formula/functions/add.js.map +1 -0
  75. package/dist/formula/functions/and.js +28 -0
  76. package/dist/formula/functions/and.js.map +1 -0
  77. package/dist/formula/functions/asin.js +32 -0
  78. package/dist/formula/functions/asin.js.map +1 -0
  79. package/dist/formula/functions/atan.js +29 -0
  80. package/dist/formula/functions/atan.js.map +1 -0
  81. package/dist/formula/functions/atan2.js +35 -0
  82. package/dist/formula/functions/atan2.js.map +1 -0
  83. package/dist/formula/functions/average.js +44 -0
  84. package/dist/formula/functions/average.js.map +1 -0
  85. package/dist/formula/functions/col.js +31 -0
  86. package/dist/formula/functions/col.js.map +1 -0
  87. package/dist/formula/functions/concat.js +27 -0
  88. package/dist/formula/functions/concat.js.map +1 -0
  89. package/dist/formula/functions/concatenate.js +28 -0
  90. package/dist/formula/functions/concatenate.js.map +1 -0
  91. package/dist/formula/functions/cos.js +29 -0
  92. package/dist/formula/functions/cos.js.map +1 -0
  93. package/dist/formula/functions/count.js +38 -0
  94. package/dist/formula/functions/count.js.map +1 -0
  95. package/dist/formula/functions/counta.js +38 -0
  96. package/dist/formula/functions/counta.js.map +1 -0
  97. package/dist/formula/functions/countif.js +32 -0
  98. package/dist/formula/functions/countif.js.map +1 -0
  99. package/dist/formula/functions/divide.js +33 -0
  100. package/dist/formula/functions/divide.js.map +1 -0
  101. package/dist/formula/functions/eq.js +29 -0
  102. package/dist/formula/functions/eq.js.map +1 -0
  103. package/dist/formula/functions/exp.js +29 -0
  104. package/dist/formula/functions/exp.js.map +1 -0
  105. package/dist/formula/functions/gt.js +29 -0
  106. package/dist/formula/functions/gt.js.map +1 -0
  107. package/dist/formula/functions/gte.js +29 -0
  108. package/dist/formula/functions/gte.js.map +1 -0
  109. package/dist/formula/functions/hlookup.js +75 -0
  110. package/dist/formula/functions/hlookup.js.map +1 -0
  111. package/dist/formula/functions/if.js +39 -0
  112. package/dist/formula/functions/if.js.map +1 -0
  113. package/dist/formula/functions/iferror.js +45 -0
  114. package/dist/formula/functions/iferror.js.map +1 -0
  115. package/dist/formula/functions/len.js +29 -0
  116. package/dist/formula/functions/len.js.map +1 -0
  117. package/dist/formula/functions/lenb.js +29 -0
  118. package/dist/formula/functions/lenb.js.map +1 -0
  119. package/dist/formula/functions/ln.js +32 -0
  120. package/dist/formula/functions/ln.js.map +1 -0
  121. package/dist/formula/functions/log.js +36 -0
  122. package/dist/formula/functions/log.js.map +1 -0
  123. package/dist/formula/functions/log10.js +32 -0
  124. package/dist/formula/functions/log10.js.map +1 -0
  125. package/dist/formula/functions/lt.js +29 -0
  126. package/dist/formula/functions/lt.js.map +1 -0
  127. package/dist/formula/functions/lte.js +29 -0
  128. package/dist/formula/functions/lte.js.map +1 -0
  129. package/dist/formula/functions/max.js +47 -0
  130. package/dist/formula/functions/max.js.map +1 -0
  131. package/dist/formula/functions/min.js +47 -0
  132. package/dist/formula/functions/min.js.map +1 -0
  133. package/dist/formula/functions/minus.js +57 -0
  134. package/dist/formula/functions/minus.js.map +1 -0
  135. package/dist/formula/functions/mod.js +33 -0
  136. package/dist/formula/functions/mod.js.map +1 -0
  137. package/dist/formula/functions/multiply.js +27 -0
  138. package/dist/formula/functions/multiply.js.map +1 -0
  139. package/dist/formula/functions/ne.js +29 -0
  140. package/dist/formula/functions/ne.js.map +1 -0
  141. package/dist/formula/functions/not.js +30 -0
  142. package/dist/formula/functions/not.js.map +1 -0
  143. package/dist/formula/functions/now.js +22 -0
  144. package/dist/formula/functions/now.js.map +1 -0
  145. package/dist/formula/functions/or.js +28 -0
  146. package/dist/formula/functions/or.js.map +1 -0
  147. package/dist/formula/functions/pi.js +22 -0
  148. package/dist/formula/functions/pi.js.map +1 -0
  149. package/dist/formula/functions/power.js +27 -0
  150. package/dist/formula/functions/power.js.map +1 -0
  151. package/dist/formula/functions/product.js +40 -0
  152. package/dist/formula/functions/product.js.map +1 -0
  153. package/dist/formula/functions/radians.js +29 -0
  154. package/dist/formula/functions/radians.js.map +1 -0
  155. package/dist/formula/functions/rand.js +22 -0
  156. package/dist/formula/functions/rand.js.map +1 -0
  157. package/dist/formula/functions/round.js +35 -0
  158. package/dist/formula/functions/round.js.map +1 -0
  159. package/dist/formula/functions/rounddown.js +35 -0
  160. package/dist/formula/functions/rounddown.js.map +1 -0
  161. package/dist/formula/functions/roundup.js +35 -0
  162. package/dist/formula/functions/roundup.js.map +1 -0
  163. package/dist/formula/functions/row.js +31 -0
  164. package/dist/formula/functions/row.js.map +1 -0
  165. package/dist/formula/functions/sin.js +29 -0
  166. package/dist/formula/functions/sin.js.map +1 -0
  167. package/dist/formula/functions/sqrt.js +32 -0
  168. package/dist/formula/functions/sqrt.js.map +1 -0
  169. package/dist/formula/functions/sum.js +47 -0
  170. package/dist/formula/functions/sum.js.map +1 -0
  171. package/dist/formula/functions/sumif.js +65 -0
  172. package/dist/formula/functions/sumif.js.map +1 -0
  173. package/dist/formula/functions/tan.js +29 -0
  174. package/dist/formula/functions/tan.js.map +1 -0
  175. package/dist/formula/functions/uminus.js +24 -0
  176. package/dist/formula/functions/uminus.js.map +1 -0
  177. package/dist/formula/functions/vlookup.js +75 -0
  178. package/dist/formula/functions/vlookup.js.map +1 -0
  179. package/dist/formula/mapping.js +118 -0
  180. package/dist/formula/mapping.js.map +1 -0
  181. package/dist/formula/solver.js +70 -0
  182. package/dist/formula/solver.js.map +1 -0
  183. package/dist/index.js +16 -9113
  184. package/dist/index.js.map +1 -1
  185. package/dist/lib/autofill.js +391 -0
  186. package/dist/lib/autofill.js.map +1 -0
  187. package/dist/lib/clipboard.js +46 -0
  188. package/dist/lib/clipboard.js.map +1 -0
  189. package/dist/lib/converters.js +141 -0
  190. package/dist/lib/converters.js.map +1 -0
  191. package/dist/lib/input.js +52 -0
  192. package/dist/lib/input.js.map +1 -0
  193. package/dist/lib/palette.js +24 -0
  194. package/dist/lib/palette.js.map +1 -0
  195. package/dist/lib/prevention.js +82 -0
  196. package/dist/lib/prevention.js.map +1 -0
  197. package/dist/lib/structs.js +276 -0
  198. package/dist/lib/structs.js.map +1 -0
  199. package/dist/lib/table.js +1248 -0
  200. package/dist/lib/table.js.map +1 -0
  201. package/dist/lib/time.js +79 -0
  202. package/dist/lib/time.js.map +1 -0
  203. package/dist/lib/virtualization.js +129 -0
  204. package/dist/lib/virtualization.js.map +1 -0
  205. package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/dayjs.min.js +287 -0
  206. package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/dayjs.min.js.map +1 -0
  207. package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/plugin/timezone.js +72 -0
  208. package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/plugin/timezone.js.map +1 -0
  209. package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/plugin/utc.js +85 -0
  210. package/dist/node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/plugin/utc.js.map +1 -0
  211. package/dist/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.development.js +454 -0
  212. package/dist/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.development.js.map +1 -0
  213. package/dist/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.production.js +42 -0
  214. package/dist/node_modules/.pnpm/react@19.0.0/node_modules/react/cjs/react-jsx-runtime.production.js.map +1 -0
  215. package/dist/node_modules/.pnpm/react@19.0.0/node_modules/react/jsx-runtime.js +18 -0
  216. package/dist/node_modules/.pnpm/react@19.0.0/node_modules/react/jsx-runtime.js.map +1 -0
  217. package/dist/parsers/core.js +139 -0
  218. package/dist/parsers/core.js.map +1 -0
  219. package/dist/renderers/checkbox.js +20 -0
  220. package/dist/renderers/checkbox.js.map +1 -0
  221. package/dist/renderers/core.js +147 -0
  222. package/dist/renderers/core.js.map +1 -0
  223. package/dist/renderers/thousand_separator.js +17 -0
  224. package/dist/renderers/thousand_separator.js.map +1 -0
  225. package/dist/store/actions.js +762 -0
  226. package/dist/store/actions.js.map +1 -0
  227. package/dist/store/helpers.js +88 -0
  228. package/dist/store/helpers.js.map +1 -0
  229. package/dist/store/index.js +8 -0
  230. package/dist/store/index.js.map +1 -0
  231. package/dist/styles/embedder.js +19 -0
  232. package/dist/styles/embedder.js.map +1 -0
  233. package/dist/styles/minified.js +7 -0
  234. package/dist/styles/minified.js.map +1 -0
  235. package/package.json +1 -7
@@ -0,0 +1,1248 @@
1
+ import { defaultParser } from "../parsers/core.js";
2
+ import { defaultRenderer } from "../renderers/core.js";
3
+ import { getMaxSizesFromCells, expandRange, createMatrix, putMatrix, areaShape, matrixShape } from "./structs.js";
4
+ import { p2a, x2c, grantAddressAbsolute, a2p, y2r } from "./converters.js";
5
+ import { functions } from "../formula/mapping.js";
6
+ import { absolutizeFormula, Lexer, stripSheetName } from "../formula/evaluator.js";
7
+ import { solveFormula } from "../formula/solver.js";
8
+ import { HISTORY_LIMIT, HEADER_HEIGHT, HEADER_WIDTH, DEFAULT_WIDTH, DEFAULT_HEIGHT } from "../constants.js";
9
+ import { shouldTracking } from "../store/helpers.js";
10
+ import { isPrevented, MoveFrom, MoveTo, Update, Write, Style, Resize, SetRenderer, SetParser, DeleteRow, DeleteCol } from "./prevention.js";
11
+ const noFilter = () => true;
12
+ class Table {
13
+ constructor({
14
+ parsers = {},
15
+ renderers = {},
16
+ labelers = {},
17
+ useBigInt = false,
18
+ historyLimit,
19
+ minNumRows = 1,
20
+ maxNumRows = -1,
21
+ minNumCols = 1,
22
+ maxNumCols = -1,
23
+ headerWidth = HEADER_WIDTH,
24
+ headerHeight = HEADER_HEIGHT,
25
+ functions: functions$1 = functions
26
+ }) {
27
+ this.totalWidth = 0;
28
+ this.totalHeight = 0;
29
+ this.headerWidth = 0;
30
+ this.headerHeight = 0;
31
+ this.sheetId = 0;
32
+ this.sheetName = "";
33
+ this.sheets = {};
34
+ this.tables = {};
35
+ this.data = {};
36
+ this.area = { top: 0, left: 0, bottom: 0, right: 0 };
37
+ this.functions = {};
38
+ this.head = useBigInt ? BigInt(0) : 0;
39
+ this.parsers = parsers || {};
40
+ this.renderers = renderers || {};
41
+ this.labelers = labelers || {};
42
+ this.idMatrix = [];
43
+ this.histories = [];
44
+ this.historyIndex = -1;
45
+ this.addressesById = {};
46
+ this.historyLimit = historyLimit || HISTORY_LIMIT;
47
+ this.changedAt = /* @__PURE__ */ new Date();
48
+ this.minNumRows = minNumRows || 0;
49
+ this.maxNumRows = maxNumRows || 0;
50
+ this.minNumCols = minNumCols || 0;
51
+ this.maxNumCols = maxNumCols || 0;
52
+ this.solvedCaches = {};
53
+ this.headerHeight = headerHeight;
54
+ this.headerWidth = headerWidth;
55
+ this.functions = functions$1;
56
+ this.idsToBeAbsoluted = [];
57
+ }
58
+ getTableBySheetName(sheetName) {
59
+ const sheetId = this.sheets[sheetName];
60
+ return this.tables[sheetId];
61
+ }
62
+ initialize(cells) {
63
+ var _a, _b;
64
+ const auto = getMaxSizesFromCells(cells);
65
+ this.area = {
66
+ top: 0,
67
+ left: 0,
68
+ bottom: auto.numRows || 0,
69
+ right: auto.numCols || 0
70
+ };
71
+ for (let y = 0; y < auto.numRows + 1; y++) {
72
+ const ids = [];
73
+ this.idMatrix.push(ids);
74
+ for (let x = 0; x < auto.numCols + 1; x++) {
75
+ const id = this.generateId();
76
+ ids.push(id);
77
+ const address = p2a({ y, x });
78
+ this.addressesById[id] = address;
79
+ }
80
+ }
81
+ Object.keys(cells).forEach((address) => {
82
+ const range = expandRange(address);
83
+ const data = cells[address];
84
+ range.forEach((address2) => {
85
+ const origin = cells[address2];
86
+ cells[address2] = {
87
+ ...origin,
88
+ ...data,
89
+ style: {
90
+ ...origin == null ? void 0 : origin.style,
91
+ ...data == null ? void 0 : data.style
92
+ },
93
+ prevention: ((origin == null ? void 0 : origin.prevention) || 0) | ((data == null ? void 0 : data.prevention) || 0)
94
+ };
95
+ });
96
+ });
97
+ const common = cells == null ? void 0 : cells["default"];
98
+ for (let y = 0; y < auto.numRows + 1; y++) {
99
+ const rowId = y2r(y);
100
+ const rowDefault = cells == null ? void 0 : cells[rowId];
101
+ for (let x = 0; x < auto.numCols + 1; x++) {
102
+ const id = this.getId({ y, x });
103
+ const address = p2a({ y, x });
104
+ const colId = x2c(x);
105
+ const colDefault = cells == null ? void 0 : cells[colId];
106
+ const cell = cells == null ? void 0 : cells[address];
107
+ const stacked = {
108
+ ...common,
109
+ ...rowDefault,
110
+ ...colDefault,
111
+ ...cell,
112
+ style: {
113
+ ...common == null ? void 0 : common.style,
114
+ ...rowDefault == null ? void 0 : rowDefault.style,
115
+ ...colDefault == null ? void 0 : colDefault.style,
116
+ ...cell == null ? void 0 : cell.style
117
+ },
118
+ prevention: ((common == null ? void 0 : common.prevention) || 0) | ((rowDefault == null ? void 0 : rowDefault.prevention) || 0) | ((colDefault == null ? void 0 : colDefault.prevention) || 0) | ((cell == null ? void 0 : cell.prevention) || 0)
119
+ };
120
+ if ((_b = (_a = stacked == null ? void 0 : stacked.value) == null ? void 0 : _a.startsWith) == null ? void 0 : _b.call(_a, "=")) {
121
+ this.idsToBeAbsoluted.push(id);
122
+ }
123
+ if (y === 0) {
124
+ if (stacked.width == null) {
125
+ stacked.width = DEFAULT_WIDTH;
126
+ }
127
+ } else if (x === 0) {
128
+ if (stacked.height == null) {
129
+ stacked.height = DEFAULT_HEIGHT;
130
+ }
131
+ } else {
132
+ delete stacked.height;
133
+ delete stacked.width;
134
+ delete stacked.labeler;
135
+ }
136
+ this.data[id] = stacked;
137
+ }
138
+ }
139
+ this.setTotalSize();
140
+ }
141
+ absolutizeFormula() {
142
+ this.idsToBeAbsoluted.forEach((id) => {
143
+ const cell = this.data[id];
144
+ if (cell == null) {
145
+ return;
146
+ }
147
+ cell.value = absolutizeFormula({
148
+ value: cell == null ? void 0 : cell.value,
149
+ table: this
150
+ });
151
+ });
152
+ }
153
+ generateId() {
154
+ return (this.head++).toString(36);
155
+ }
156
+ getRectSize({ top, left, bottom, right }) {
157
+ var _a, _b;
158
+ let width = 0, height = 0;
159
+ for (let x = left || 1; x < right; x++) {
160
+ width += ((_a = this.getByPoint({ y: 0, x })) == null ? void 0 : _a.width) || DEFAULT_WIDTH;
161
+ }
162
+ for (let y = top || 1; y < bottom; y++) {
163
+ height += ((_b = this.getByPoint({ y, x: 0 })) == null ? void 0 : _b.height) || DEFAULT_HEIGHT;
164
+ }
165
+ return { width, height };
166
+ }
167
+ setTotalSize() {
168
+ const { bottom, right } = this.area;
169
+ const { width, height } = this.getRectSize({
170
+ top: 1,
171
+ left: 1,
172
+ bottom: bottom + 1,
173
+ right: right + 1
174
+ });
175
+ this.totalWidth = width + this.headerWidth;
176
+ this.totalHeight = height + this.headerHeight;
177
+ }
178
+ shallowCopy({ copyCache = true } = {}) {
179
+ const copied = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
180
+ copied.changedAt = /* @__PURE__ */ new Date();
181
+ copied.lastChangedAt = this.changedAt;
182
+ copied.setTotalSize();
183
+ copied.idsToBeAbsoluted = [];
184
+ copied.solvedCaches = {};
185
+ if (!copyCache) {
186
+ this.addressesById = {};
187
+ }
188
+ return copied;
189
+ }
190
+ getAddressById(id, slideY = 0, slideX = 0) {
191
+ const absCol = id.startsWith("$");
192
+ if (absCol) {
193
+ id = id.slice(1);
194
+ slideX = 0;
195
+ }
196
+ const absRow = id.endsWith("$");
197
+ if (absRow) {
198
+ id = id.slice(0, -1);
199
+ slideY = 0;
200
+ }
201
+ for (let y = 0; y < this.idMatrix.length; y++) {
202
+ const ids = this.idMatrix[y];
203
+ for (let x = 0; x < ids.length; x++) {
204
+ const existing = ids[x];
205
+ const address = p2a({ y, x });
206
+ this.addressesById[existing] = address;
207
+ if (existing === id) {
208
+ const slidedAddress = p2a({
209
+ y: y + slideY,
210
+ x: x + slideX
211
+ });
212
+ return grantAddressAbsolute(slidedAddress, absCol, absRow);
213
+ }
214
+ }
215
+ }
216
+ }
217
+ getAddressesByIds(ids) {
218
+ const addresses = {};
219
+ Object.keys(ids).forEach((id) => {
220
+ const cell = ids[id];
221
+ const address = this.getAddressById(id);
222
+ if (cell && address) {
223
+ addresses[address] = cell;
224
+ }
225
+ });
226
+ return addresses;
227
+ }
228
+ getPointById(id) {
229
+ const address = this.getAddressById(id);
230
+ if (address) {
231
+ return a2p(address);
232
+ }
233
+ return { y: 0, x: 0 };
234
+ }
235
+ getId(point) {
236
+ var _a;
237
+ const { y, x } = point;
238
+ return (_a = this.idMatrix[Math.abs(y)]) == null ? void 0 : _a[Math.abs(x)];
239
+ }
240
+ getByPoint(point) {
241
+ var _a;
242
+ const { y, x } = point;
243
+ if (y === -1 || x === -1) {
244
+ return void 0;
245
+ }
246
+ const id = (_a = this.idMatrix[y]) == null ? void 0 : _a[x];
247
+ if (id == null) {
248
+ return void 0;
249
+ }
250
+ const value = this.data[id];
251
+ return value;
252
+ }
253
+ getById(id) {
254
+ return this.data[id];
255
+ }
256
+ getNumRows(base = 0) {
257
+ const { top, bottom } = this.area;
258
+ return base + bottom - top;
259
+ }
260
+ getNumCols(base = 0) {
261
+ const { left, right } = this.area;
262
+ return base + right - left;
263
+ }
264
+ get top() {
265
+ return this.area.top;
266
+ }
267
+ get left() {
268
+ return this.area.left;
269
+ }
270
+ get bottom() {
271
+ return this.area.bottom;
272
+ }
273
+ get right() {
274
+ return this.area.right;
275
+ }
276
+ getMatrixFlatten({
277
+ area,
278
+ key = "value",
279
+ evaluates = true,
280
+ raise = false,
281
+ filter = noFilter
282
+ } = {}) {
283
+ const { top, left, bottom, right } = area || {
284
+ top: 1,
285
+ left: 1,
286
+ bottom: this.area.bottom,
287
+ right: this.area.right
288
+ };
289
+ const matrix = createMatrix(bottom - top + 1, right - left + 1);
290
+ for (let y = top; y <= bottom; y++) {
291
+ for (let x = left; x <= right; x++) {
292
+ const cell = this.getByPoint({ y, x }) || {};
293
+ if (!filter(cell)) {
294
+ continue;
295
+ }
296
+ matrix[y - top][x - left] = solveFormula({
297
+ value: cell[key],
298
+ table: this,
299
+ raise,
300
+ evaluates
301
+ });
302
+ }
303
+ }
304
+ return matrix;
305
+ }
306
+ getObjectFlatten({ key = "value", evaluates = true, raise = false, filter = noFilter } = {}) {
307
+ const result = {};
308
+ const { top, left, bottom, right } = this.area;
309
+ for (let y = top; y <= bottom; y++) {
310
+ for (let x = left; x <= right; x++) {
311
+ const cell = this.getByPoint({ y: y - top, x: x - left });
312
+ if (cell != null && filter(cell)) {
313
+ result[p2a({ y, x })] = solveFormula({
314
+ value: cell[key],
315
+ table: this,
316
+ raise,
317
+ evaluates
318
+ });
319
+ }
320
+ }
321
+ }
322
+ return result;
323
+ }
324
+ getRowsFlatten({ key = "value", evaluates = true, raise = false, filter = noFilter } = {}) {
325
+ const result = [];
326
+ const { top, left, bottom, right } = this.area;
327
+ for (let y = top; y <= bottom; y++) {
328
+ const row = {};
329
+ result.push(row);
330
+ for (let x = left; x <= right; x++) {
331
+ const cell = this.getByPoint({ y: y - top, x: x - left });
332
+ if (cell != null && filter(cell)) {
333
+ row[x2c(x) || y2r(y)] = solveFormula({
334
+ value: cell[key],
335
+ table: this,
336
+ raise,
337
+ evaluates
338
+ });
339
+ }
340
+ }
341
+ }
342
+ return result;
343
+ }
344
+ getColsFlatten({ key = "value", evaluates = true, raise = false, filter = noFilter } = {}) {
345
+ const result = [];
346
+ const { top, left, bottom, right } = this.area;
347
+ for (let x = left; x <= right; x++) {
348
+ const col = {};
349
+ result.push(col);
350
+ for (let y = top; y <= bottom; y++) {
351
+ const cell = this.getByPoint({ y: y - top, x: x - left });
352
+ if (cell != null && filter(cell)) {
353
+ col[y2r(y) || x2c(x)] = solveFormula({
354
+ value: cell[key],
355
+ table: this,
356
+ raise,
357
+ evaluates
358
+ });
359
+ }
360
+ }
361
+ }
362
+ return result;
363
+ }
364
+ getMatrix({
365
+ area,
366
+ evaluates = true,
367
+ raise = false,
368
+ filter = noFilter
369
+ } = {}) {
370
+ const { top, left, bottom, right } = area || {
371
+ top: 1,
372
+ left: 1,
373
+ bottom: this.area.bottom,
374
+ right: this.area.right
375
+ };
376
+ const matrix = createMatrix(bottom - top + 1, right - left + 1);
377
+ for (let y = top; y <= bottom; y++) {
378
+ for (let x = left; x <= right; x++) {
379
+ const cell = this.getByPoint({ y, x });
380
+ if (cell != null && filter(cell)) {
381
+ matrix[y - top][x - left] = {
382
+ ...cell,
383
+ value: solveFormula({
384
+ value: cell == null ? void 0 : cell.value,
385
+ table: this,
386
+ raise,
387
+ evaluates
388
+ })
389
+ };
390
+ }
391
+ }
392
+ }
393
+ return matrix;
394
+ }
395
+ getObject({ evaluates = true, raise = false, filter = noFilter } = {}) {
396
+ const result = {};
397
+ const { top, left, bottom, right } = this.area;
398
+ for (let y = top; y <= bottom; y++) {
399
+ for (let x = left; x <= right; x++) {
400
+ const cell = this.getByPoint({ y: y - top, x: x - left });
401
+ if (cell != null && filter(cell)) {
402
+ result[p2a({ y, x })] = {
403
+ ...cell,
404
+ value: solveFormula({
405
+ value: cell == null ? void 0 : cell.value,
406
+ table: this,
407
+ raise,
408
+ evaluates
409
+ })
410
+ };
411
+ }
412
+ }
413
+ }
414
+ return result;
415
+ }
416
+ getRows({ evaluates = true, raise = false, filter = noFilter } = {}) {
417
+ const result = [];
418
+ const { top, left, bottom, right } = this.area;
419
+ for (let y = top; y <= bottom; y++) {
420
+ const row = {};
421
+ result.push(row);
422
+ for (let x = left; x <= right; x++) {
423
+ const cell = this.getByPoint({ y: y - top, x: x - left });
424
+ if (cell != null && filter(cell)) {
425
+ row[x2c(x) || y2r(y)] = {
426
+ ...cell,
427
+ value: solveFormula({
428
+ value: cell == null ? void 0 : cell.value,
429
+ table: this,
430
+ raise,
431
+ evaluates
432
+ })
433
+ };
434
+ }
435
+ }
436
+ }
437
+ return result;
438
+ }
439
+ getCols({ evaluates = true, raise = false, filter = noFilter } = {}) {
440
+ const result = [];
441
+ const { top, left, bottom, right } = this.area;
442
+ for (let x = left; x <= right; x++) {
443
+ const col = {};
444
+ result.push(col);
445
+ for (let y = top; y <= bottom; y++) {
446
+ const cell = this.getByPoint({ y: y - top, x: x - left });
447
+ if (cell != null && filter(cell)) {
448
+ col[y2r(y) || x2c(x)] = {
449
+ ...cell,
450
+ value: solveFormula({
451
+ value: cell == null ? void 0 : cell.value,
452
+ table: this,
453
+ raise,
454
+ evaluates
455
+ })
456
+ };
457
+ }
458
+ }
459
+ }
460
+ return result;
461
+ }
462
+ pushHistory(history) {
463
+ const strayedHistories = this.histories.splice(this.historyIndex + 1, this.histories.length);
464
+ strayedHistories.forEach(this.cleanStrayed.bind(this));
465
+ this.histories.push(history);
466
+ this.lastHistory = this.currentHistory = history;
467
+ if (this.histories.length > this.historyLimit) {
468
+ const kickedOut = this.histories.splice(0, 1)[0];
469
+ this.cleanObsolete(kickedOut);
470
+ } else {
471
+ this.historyIndex++;
472
+ }
473
+ }
474
+ cleanObsolete(history) {
475
+ if (history.operation === "DELETE_ROWS" || history.operation === "DELETE_COLS") {
476
+ history.deleted.forEach((ids) => {
477
+ ids.forEach((id) => {
478
+ delete this.data[id];
479
+ });
480
+ });
481
+ }
482
+ if (history.operation === "MOVE") {
483
+ Object.keys(history.lostRows).forEach((address) => {
484
+ const idMatrix = history.lostRows[address];
485
+ idMatrix.map(
486
+ (ids) => ids.forEach((id) => {
487
+ if (id != null) {
488
+ delete this.data[id];
489
+ }
490
+ })
491
+ );
492
+ });
493
+ }
494
+ }
495
+ cleanStrayed(history) {
496
+ if (history.operation === "ADD_ROWS" || history.operation === "ADD_COLS") {
497
+ history.idMatrix.forEach((ids) => {
498
+ ids.forEach((id) => {
499
+ delete this.data[id];
500
+ });
501
+ });
502
+ }
503
+ }
504
+ getNewIdMatrix(area) {
505
+ const matrix = [];
506
+ const { top, left, bottom, right } = area;
507
+ for (let y = top; y <= bottom; y++) {
508
+ const ids = [];
509
+ matrix.push(ids);
510
+ for (let x = left; x <= right; x++) {
511
+ ids.push(this.generateId());
512
+ }
513
+ }
514
+ return matrix;
515
+ }
516
+ getIdMatrixFromArea(area) {
517
+ var _a;
518
+ const matrix = [];
519
+ const { top, left, bottom, right } = area;
520
+ for (let y = top; y <= bottom; y++) {
521
+ const ids = [];
522
+ matrix.push(ids);
523
+ for (let x = left; x <= right; x++) {
524
+ const id = (_a = this.idMatrix[y]) == null ? void 0 : _a[x];
525
+ if (id == null) {
526
+ continue;
527
+ }
528
+ ids.push(id);
529
+ }
530
+ }
531
+ return matrix;
532
+ }
533
+ setChangedAt(cell, changedAt) {
534
+ if (cell == null) {
535
+ return null;
536
+ }
537
+ cell.changedAt = changedAt || /* @__PURE__ */ new Date();
538
+ return cell;
539
+ }
540
+ copyCellLayout(cell) {
541
+ if (cell == null) {
542
+ return void 0;
543
+ }
544
+ const newCell = {};
545
+ if (cell.style != null) {
546
+ newCell.style = cell.style;
547
+ }
548
+ if (cell.justifyContent != null) {
549
+ newCell.justifyContent = cell.justifyContent;
550
+ }
551
+ if (cell.alignItems != null) {
552
+ newCell.alignItems = cell.alignItems;
553
+ }
554
+ if (cell.renderer != null) {
555
+ newCell.renderer = cell.renderer;
556
+ }
557
+ if (cell.parser != null) {
558
+ newCell.parser = cell.parser;
559
+ }
560
+ if (cell.width != null) {
561
+ newCell.width = cell.width;
562
+ }
563
+ if (cell.height != null) {
564
+ newCell.height = cell.height;
565
+ }
566
+ if (cell.labeler != null) {
567
+ newCell.labeler = cell.labeler;
568
+ }
569
+ return newCell;
570
+ }
571
+ move({ src, dst, historicize = true, operator = "SYSTEM", reflection = {} }) {
572
+ const matrixNew = this.getNewIdMatrix(src);
573
+ const matrixFrom = this.getIdMatrixFromArea(src);
574
+ const matrixTo = this.getIdMatrixFromArea(dst);
575
+ putMatrix(this.idMatrix, matrixNew, src, (_, id) => {
576
+ const cell = this.data[id];
577
+ if (operator === "USER" && isPrevented(cell == null ? void 0 : cell.prevention, MoveFrom)) {
578
+ return false;
579
+ }
580
+ return true;
581
+ });
582
+ const lostRows = putMatrix(this.idMatrix, matrixFrom, dst, (srcId, dstId) => {
583
+ const srcCell = this.data[srcId];
584
+ const dstCell = this.data[dstId];
585
+ if (operator === "USER" && (isPrevented(srcCell == null ? void 0 : srcCell.prevention, MoveFrom) || isPrevented(dstCell == null ? void 0 : dstCell.prevention, MoveTo))) {
586
+ return false;
587
+ }
588
+ if (srcCell != null) {
589
+ this.setChangedAt(srcCell, /* @__PURE__ */ new Date());
590
+ }
591
+ return true;
592
+ });
593
+ if (historicize) {
594
+ this.pushHistory({
595
+ applyed: true,
596
+ operation: "MOVE",
597
+ reflection,
598
+ src,
599
+ dst,
600
+ matrixFrom,
601
+ matrixTo,
602
+ matrixNew,
603
+ lostRows
604
+ });
605
+ }
606
+ return this.shallowCopy({ copyCache: false });
607
+ }
608
+ copy({ src, dst, operator = "SYSTEM", reflection = {} }) {
609
+ const { height: maxHeight, width: maxWidth } = areaShape({
610
+ ...src,
611
+ base: 1
612
+ });
613
+ const { top: topFrom, left: leftFrom } = src;
614
+ const { top: topTo, left: leftTo, bottom: bottomTo, right: rightTo } = dst;
615
+ const diff = {};
616
+ const changedAt = /* @__PURE__ */ new Date();
617
+ for (let i = 0; i <= bottomTo - topTo; i++) {
618
+ const toY = topTo + i;
619
+ if (toY > this.getNumRows()) {
620
+ continue;
621
+ }
622
+ for (let j = 0; j <= rightTo - leftTo; j++) {
623
+ const toX = leftTo + j;
624
+ if (toX > this.getNumCols()) {
625
+ continue;
626
+ }
627
+ const fromY = topFrom + i % maxHeight;
628
+ const fromX = leftFrom + j % maxWidth;
629
+ const slideY = toY - fromY;
630
+ const slideX = toX - fromX;
631
+ const cell = {
632
+ ...this.getByPoint({
633
+ y: topFrom + i % maxHeight,
634
+ x: leftFrom + j % maxWidth
635
+ }),
636
+ prevention: 0
637
+ // Is this okay?
638
+ };
639
+ const value = absolutizeFormula({
640
+ value: cell == null ? void 0 : cell.value,
641
+ table: this,
642
+ slideY,
643
+ slideX
644
+ });
645
+ this.setChangedAt(cell, changedAt);
646
+ diff[p2a({ y: toY, x: toX })] = {
647
+ ...cell,
648
+ style: { ...cell == null ? void 0 : cell.style },
649
+ value
650
+ };
651
+ }
652
+ }
653
+ return this.update({
654
+ diff,
655
+ partial: false,
656
+ operator,
657
+ reflection
658
+ });
659
+ }
660
+ _update({
661
+ diff,
662
+ partial = true,
663
+ updateChangedAt = true,
664
+ ignoreFields = ["labeler", "prevention"],
665
+ operator = "SYSTEM"
666
+ }) {
667
+ const diffBefore = {};
668
+ const diffAfter = {};
669
+ const changedAt = /* @__PURE__ */ new Date();
670
+ Object.keys(diff).forEach((address) => {
671
+ const cell = { ...diff[address] };
672
+ if (operator === "USER" && isPrevented(cell == null ? void 0 : cell.prevention, Update)) {
673
+ return;
674
+ }
675
+ cell.value = absolutizeFormula({
676
+ value: cell.value,
677
+ table: this
678
+ });
679
+ const point = a2p(address);
680
+ const id = this.getId(point);
681
+ const current = this.data[id];
682
+ ignoreFields.forEach((key) => {
683
+ cell[key] = current == null ? void 0 : current[key];
684
+ });
685
+ if (operator === "USER" && isPrevented(current == null ? void 0 : current.prevention, Write)) {
686
+ cell.value = current == null ? void 0 : current.value;
687
+ }
688
+ if (operator === "USER" && isPrevented(current == null ? void 0 : current.prevention, Style)) {
689
+ cell.style = current == null ? void 0 : current.style;
690
+ cell.justifyContent = current == null ? void 0 : current.justifyContent;
691
+ cell.alignItems = current == null ? void 0 : current.alignItems;
692
+ }
693
+ if (operator === "USER" && isPrevented(current == null ? void 0 : current.prevention, Resize)) {
694
+ cell.width = current == null ? void 0 : current.width;
695
+ cell.height = current == null ? void 0 : current.height;
696
+ }
697
+ if (operator === "USER" && isPrevented(current == null ? void 0 : current.prevention, SetRenderer)) {
698
+ cell.renderer = current == null ? void 0 : current.renderer;
699
+ }
700
+ if (operator === "USER" && isPrevented(current == null ? void 0 : current.prevention, SetParser)) {
701
+ cell.parser = current == null ? void 0 : current.parser;
702
+ }
703
+ if (updateChangedAt) {
704
+ this.setChangedAt(cell, changedAt);
705
+ }
706
+ diffBefore[id] = this.getByPoint(point);
707
+ diffAfter[id] = cell;
708
+ if (partial) {
709
+ this.data[id] = { ...current, ...cell };
710
+ } else {
711
+ this.data[id] = cell;
712
+ }
713
+ });
714
+ this.solvedCaches = {};
715
+ return {
716
+ diffBefore,
717
+ diffAfter
718
+ };
719
+ }
720
+ update({
721
+ diff,
722
+ partial = true,
723
+ updateChangedAt = true,
724
+ historicize = true,
725
+ operator = "SYSTEM",
726
+ reflection = {}
727
+ }) {
728
+ const { diffBefore, diffAfter } = this._update({
729
+ diff,
730
+ partial,
731
+ operator,
732
+ updateChangedAt
733
+ });
734
+ if (historicize) {
735
+ this.pushHistory({
736
+ applyed: true,
737
+ operation: "UPDATE",
738
+ reflection,
739
+ diffBefore,
740
+ diffAfter,
741
+ partial
742
+ });
743
+ }
744
+ return this.shallowCopy({ copyCache: true });
745
+ }
746
+ writeMatrix({
747
+ point,
748
+ matrix,
749
+ updateChangedAt = true,
750
+ historicize = true,
751
+ operator = "SYSTEM",
752
+ reflection = {}
753
+ }) {
754
+ const { y: baseY, x: baseX } = point;
755
+ const diff = {};
756
+ matrix.forEach((cols, i) => {
757
+ const y = baseY + i;
758
+ if (y > this.bottom) {
759
+ return;
760
+ }
761
+ cols.forEach((value, j) => {
762
+ const x = baseX + j;
763
+ if (x > this.right) {
764
+ return;
765
+ }
766
+ const cell = this.parse({ y, x }, value);
767
+ diff[p2a({ y, x })] = cell;
768
+ });
769
+ });
770
+ return this.update({
771
+ diff,
772
+ partial: true,
773
+ updateChangedAt,
774
+ historicize,
775
+ operator,
776
+ reflection
777
+ });
778
+ }
779
+ write({
780
+ point,
781
+ value,
782
+ updateChangedAt = true,
783
+ historicize = true,
784
+ operator = "SYSTEM",
785
+ reflection = {}
786
+ }) {
787
+ return this.writeMatrix({
788
+ point,
789
+ matrix: [[value]],
790
+ updateChangedAt,
791
+ historicize,
792
+ operator,
793
+ reflection
794
+ });
795
+ }
796
+ addRowsAndUpdate({
797
+ y,
798
+ numRows,
799
+ baseY,
800
+ diff,
801
+ partial,
802
+ updateChangedAt,
803
+ operator = "SYSTEM",
804
+ reflection = {}
805
+ }) {
806
+ const returned = this.addRows({
807
+ y,
808
+ numRows,
809
+ baseY,
810
+ reflection
811
+ });
812
+ Object.assign(this.lastHistory, this._update({ diff, partial, updateChangedAt, operator }), { partial });
813
+ return returned;
814
+ }
815
+ addRows({
816
+ y,
817
+ numRows,
818
+ baseY,
819
+ // operator = 'SYSTEM',
820
+ reflection = {}
821
+ }) {
822
+ if (this.maxNumRows !== -1 && this.getNumRows() + numRows > this.maxNumRows) {
823
+ console.error(`Rows are limited to ${this.maxNumRows}.`);
824
+ return this;
825
+ }
826
+ const numCols = this.getNumCols(1);
827
+ const rows = [];
828
+ const changedAt = /* @__PURE__ */ new Date();
829
+ for (let i = 0; i < numRows; i++) {
830
+ const row = [];
831
+ for (let j = 0; j < numCols; j++) {
832
+ const id = this.generateId();
833
+ row.push(id);
834
+ const cell = this.getByPoint({ y: baseY, x: j });
835
+ const copied = this.copyCellLayout(cell);
836
+ this.data[id] = { ...copied, changedAt };
837
+ }
838
+ rows.push(row);
839
+ }
840
+ this.idMatrix.splice(y, 0, ...rows);
841
+ this.area.bottom += numRows;
842
+ this.pushHistory({
843
+ applyed: true,
844
+ operation: "ADD_ROWS",
845
+ reflection,
846
+ y,
847
+ numRows,
848
+ idMatrix: rows
849
+ });
850
+ return this.shallowCopy({ copyCache: false });
851
+ }
852
+ deleteRows({
853
+ y,
854
+ numRows,
855
+ operator = "SYSTEM",
856
+ reflection = {}
857
+ }) {
858
+ if (this.minNumRows !== -1 && this.getNumRows() - numRows < this.minNumRows) {
859
+ console.error(`At least ${this.minNumRows} row(s) are required.`);
860
+ return this;
861
+ }
862
+ const ys = [];
863
+ for (let i = y; i < y + numRows; i++) {
864
+ const cell = this.getByPoint({ y: i, x: 0 });
865
+ if (operator === "USER" && isPrevented(cell == null ? void 0 : cell.prevention, DeleteRow)) {
866
+ console.warn(`Cannot delete row ${i}.`);
867
+ return this;
868
+ }
869
+ ys.unshift(i);
870
+ }
871
+ const deleted = [];
872
+ ys.forEach((y2) => {
873
+ const row = this.idMatrix.splice(y2, 1);
874
+ deleted.unshift(row[0]);
875
+ });
876
+ this.area.bottom -= ys.length;
877
+ this.pushHistory({
878
+ applyed: true,
879
+ operation: "DELETE_ROWS",
880
+ reflection,
881
+ ys: ys.reverse(),
882
+ deleted
883
+ });
884
+ return this.shallowCopy({ copyCache: false });
885
+ }
886
+ addColsAndUpdate({
887
+ x,
888
+ numCols,
889
+ baseX,
890
+ diff,
891
+ partial,
892
+ updateChangedAt,
893
+ reflection = {}
894
+ }) {
895
+ const returned = this.addCols({
896
+ x,
897
+ numCols,
898
+ baseX,
899
+ reflection
900
+ });
901
+ Object.assign(this.lastHistory, this._update({ diff, partial, updateChangedAt }), { partial });
902
+ return returned;
903
+ }
904
+ addCols({
905
+ x,
906
+ numCols,
907
+ baseX,
908
+ reflection = {}
909
+ }) {
910
+ if (this.maxNumCols !== -1 && this.getNumCols() + numCols > this.maxNumCols) {
911
+ console.error(`Columns are limited to ${this.maxNumCols}.`);
912
+ return this;
913
+ }
914
+ const numRows = this.getNumRows(1);
915
+ const rows = [];
916
+ const changedAt = /* @__PURE__ */ new Date();
917
+ for (let i = 0; i < numRows; i++) {
918
+ const row = [];
919
+ for (let j = 0; j < numCols; j++) {
920
+ const id = this.generateId();
921
+ row.push(id);
922
+ const cell = this.getByPoint({ y: i, x: baseX });
923
+ const copied = this.copyCellLayout(cell);
924
+ this.idMatrix[i].splice(x, 0, id);
925
+ this.data[id] = { ...copied, changedAt };
926
+ }
927
+ rows.push(row);
928
+ }
929
+ this.area.right += numCols;
930
+ this.pushHistory({
931
+ applyed: true,
932
+ operation: "ADD_COLS",
933
+ reflection,
934
+ x,
935
+ numCols,
936
+ idMatrix: rows
937
+ });
938
+ return this.shallowCopy({ copyCache: false });
939
+ }
940
+ deleteCols({
941
+ x,
942
+ numCols,
943
+ operator = "SYSTEM",
944
+ reflection = {}
945
+ }) {
946
+ if (this.minNumCols !== -1 && this.getNumCols() - numCols < this.minNumCols) {
947
+ console.error(`At least ${this.minNumCols} column(s) are required.`);
948
+ return this;
949
+ }
950
+ const xs = [];
951
+ for (let i = x; i < x + numCols; i++) {
952
+ const cell = this.getByPoint({ y: 0, x: i });
953
+ if (operator === "USER" && isPrevented(cell == null ? void 0 : cell.prevention, DeleteCol)) {
954
+ console.warn(`Cannot delete col ${i}.`);
955
+ continue;
956
+ }
957
+ xs.unshift(i);
958
+ }
959
+ const deleted = [];
960
+ this.idMatrix.forEach((row) => {
961
+ const deleting = [];
962
+ deleted.push(deleting);
963
+ xs.forEach((x2) => {
964
+ deleting.unshift(...row.splice(x2, 1));
965
+ });
966
+ });
967
+ this.area.right -= xs.length;
968
+ this.pushHistory({
969
+ applyed: true,
970
+ operation: "DELETE_COLS",
971
+ reflection,
972
+ xs: xs.reverse(),
973
+ deleted
974
+ });
975
+ return this.shallowCopy({ copyCache: false });
976
+ }
977
+ getHistories() {
978
+ return [...this.histories];
979
+ }
980
+ getHistoryIndex() {
981
+ return this.historyIndex;
982
+ }
983
+ getHistorySize() {
984
+ return this.histories.length;
985
+ }
986
+ getHistoryLimit() {
987
+ return this.historyLimit;
988
+ }
989
+ setFunctions(additionalFunctions) {
990
+ this.functions = { ...functions, ...additionalFunctions };
991
+ }
992
+ getArea() {
993
+ return { ...this.area };
994
+ }
995
+ parse(point, value) {
996
+ const cell = this.getByPoint(point) || {};
997
+ const parser = this.parsers[cell.parser || ""] || defaultParser;
998
+ return parser.call(value, cell);
999
+ }
1000
+ render(point, writer) {
1001
+ const cell = this.getByPoint(point) || {};
1002
+ const renderer = this.renderers[cell.renderer || ""] || defaultRenderer;
1003
+ return renderer.call(this, point, writer);
1004
+ }
1005
+ stringify(point, value, evaluates = false) {
1006
+ const cell = this.getByPoint(point);
1007
+ const renderer = this.renderers[(cell == null ? void 0 : cell.renderer) || ""] || defaultRenderer;
1008
+ const s = renderer.stringify(typeof value === "undefined" ? { ...cell } : { ...cell, value });
1009
+ if (s[0] === "=") {
1010
+ if (evaluates) {
1011
+ return String(solveFormula({ value: s, table: this, raise: false, evaluates }));
1012
+ }
1013
+ const lexer = new Lexer(s.substring(1));
1014
+ lexer.tokenize();
1015
+ return "=" + lexer.stringifyToRef(this);
1016
+ }
1017
+ return s;
1018
+ }
1019
+ trim(area) {
1020
+ const copied = Object.assign(Object.create(Object.getPrototypeOf(this)), this);
1021
+ copied.area = area;
1022
+ return copied;
1023
+ }
1024
+ getIdByAddress(address) {
1025
+ let table = this;
1026
+ if (address.indexOf("!") !== -1) {
1027
+ const [sheetName, addr] = address.split("!");
1028
+ const sheetId = this.sheets[stripSheetName(sheetName)];
1029
+ table = this.tables[sheetId];
1030
+ address = addr;
1031
+ }
1032
+ const { y, x } = a2p(address);
1033
+ const id = table.getId({ y, x });
1034
+ if (id) {
1035
+ const prefix = table === this ? "" : `#${table.sheetId}!`;
1036
+ return `${prefix}#${x < 0 ? "$" : ""}${id}${y < 0 ? "$" : ""}`;
1037
+ }
1038
+ }
1039
+ applyDiff(diff, partial = true) {
1040
+ if (!partial) {
1041
+ Object.assign(this.data, diff);
1042
+ return;
1043
+ }
1044
+ Object.keys(diff).map((id) => {
1045
+ const cell = diff[id];
1046
+ this.data[id] = { ...this.getById(id), ...cell };
1047
+ });
1048
+ }
1049
+ undo() {
1050
+ if (this.historyIndex < 0) {
1051
+ return { history: null, newTable: this };
1052
+ }
1053
+ const history = this.histories[this.historyIndex--];
1054
+ history.applyed = false;
1055
+ this.currentHistory = history;
1056
+ switch (history.operation) {
1057
+ case "UPDATE":
1058
+ this.applyDiff(history.diffBefore, false);
1059
+ break;
1060
+ case "ADD_ROWS": {
1061
+ if (history.diffBefore) {
1062
+ this.applyDiff(history.diffBefore, false);
1063
+ }
1064
+ const { height } = matrixShape({ matrix: history.idMatrix });
1065
+ this.idMatrix.splice(history.y, height);
1066
+ this.area.bottom -= height;
1067
+ break;
1068
+ }
1069
+ case "ADD_COLS": {
1070
+ if (history.diffBefore) {
1071
+ this.applyDiff(history.diffBefore, false);
1072
+ }
1073
+ const { width } = matrixShape({ matrix: history.idMatrix });
1074
+ this.idMatrix.forEach((row) => {
1075
+ row.splice(history.x, width);
1076
+ });
1077
+ this.area.right -= width;
1078
+ break;
1079
+ }
1080
+ case "DELETE_ROWS": {
1081
+ const { ys, deleted } = history;
1082
+ ys.forEach((y, i) => {
1083
+ this.idMatrix.splice(y, 0, deleted[i]);
1084
+ });
1085
+ this.area.bottom += ys.length;
1086
+ break;
1087
+ }
1088
+ case "DELETE_COLS": {
1089
+ const { xs, deleted } = history;
1090
+ this.idMatrix.forEach((row, i) => {
1091
+ for (let j = 0; j < xs.length; j++) {
1092
+ row.splice(xs[j], 0, deleted[i][j]);
1093
+ }
1094
+ });
1095
+ this.area.right += xs.length;
1096
+ break;
1097
+ }
1098
+ case "MOVE": {
1099
+ const { top: yFrom, left: xFrom } = history.src;
1100
+ const { top: yTo, left: xTo } = history.dst;
1101
+ const { height: rows, width: cols } = matrixShape({
1102
+ matrix: history.matrixFrom,
1103
+ base: -1
1104
+ });
1105
+ putMatrix(this.idMatrix, history.matrixFrom, {
1106
+ top: yFrom,
1107
+ left: xFrom,
1108
+ bottom: yFrom + rows,
1109
+ right: xFrom + cols
1110
+ });
1111
+ putMatrix(this.idMatrix, history.matrixTo, {
1112
+ top: yTo,
1113
+ left: xTo,
1114
+ bottom: yTo + rows,
1115
+ right: xTo + cols
1116
+ });
1117
+ break;
1118
+ }
1119
+ }
1120
+ return {
1121
+ history,
1122
+ newTable: this.shallowCopy({
1123
+ copyCache: !shouldTracking(history.operation)
1124
+ })
1125
+ };
1126
+ }
1127
+ redo() {
1128
+ if (this.historyIndex + 1 >= this.histories.length) {
1129
+ return { history: null, newTable: this };
1130
+ }
1131
+ const history = this.histories[++this.historyIndex];
1132
+ history.applyed = true;
1133
+ this.currentHistory = history;
1134
+ switch (history.operation) {
1135
+ case "UPDATE":
1136
+ this.applyDiff(history.diffAfter, history.partial);
1137
+ break;
1138
+ case "ADD_ROWS": {
1139
+ if (history.diffAfter) {
1140
+ this.applyDiff(history.diffAfter, history.partial);
1141
+ }
1142
+ const { height } = matrixShape({ matrix: history.idMatrix });
1143
+ this.idMatrix.splice(history.y, 0, ...history.idMatrix);
1144
+ this.area.bottom += height;
1145
+ break;
1146
+ }
1147
+ case "ADD_COLS": {
1148
+ if (history.diffAfter) {
1149
+ this.applyDiff(history.diffAfter, history.partial);
1150
+ }
1151
+ const { width } = matrixShape({ matrix: history.idMatrix });
1152
+ this.idMatrix.map((row, i) => {
1153
+ row.splice(history.x, 0, ...history.idMatrix[i]);
1154
+ });
1155
+ this.area.right += width;
1156
+ break;
1157
+ }
1158
+ case "DELETE_ROWS": {
1159
+ const { ys } = history;
1160
+ [...ys].reverse().forEach((y) => {
1161
+ this.idMatrix.splice(y, 1);
1162
+ });
1163
+ this.area.bottom -= ys.length;
1164
+ break;
1165
+ }
1166
+ case "DELETE_COLS": {
1167
+ const { xs } = history;
1168
+ [...xs].reverse().forEach((x) => {
1169
+ this.idMatrix.forEach((row) => {
1170
+ row.splice(x, 1);
1171
+ });
1172
+ });
1173
+ this.area.right -= xs.length;
1174
+ break;
1175
+ }
1176
+ case "MOVE": {
1177
+ const { src, dst } = history;
1178
+ this.move({ src, dst, operator: "USER", historicize: false });
1179
+ }
1180
+ }
1181
+ return {
1182
+ history,
1183
+ newTable: this.shallowCopy({
1184
+ copyCache: !shouldTracking(history.operation)
1185
+ })
1186
+ };
1187
+ }
1188
+ getFunction(name) {
1189
+ return this.functions[name];
1190
+ }
1191
+ getLabel(key, n) {
1192
+ const labeler = this.labelers[key];
1193
+ return labeler == null ? void 0 : labeler(n);
1194
+ }
1195
+ getBase() {
1196
+ return this;
1197
+ }
1198
+ getSolvedCache(key) {
1199
+ return this.solvedCaches[key];
1200
+ }
1201
+ setSolvedCache(key, value) {
1202
+ this.solvedCaches[key] = value;
1203
+ }
1204
+ wrappedSheetName() {
1205
+ const sheetName = this.sheetName;
1206
+ if (sheetName.indexOf(" ") !== -1) {
1207
+ return `'${sheetName}'`;
1208
+ }
1209
+ return sheetName;
1210
+ }
1211
+ sheetPrefix(omit = false) {
1212
+ if (omit) {
1213
+ return "";
1214
+ }
1215
+ if (this.sheetName) {
1216
+ return `${this.wrappedSheetName()}!`;
1217
+ }
1218
+ return "";
1219
+ }
1220
+ rangeToArea(range) {
1221
+ const cells = range.split(":");
1222
+ let [start, end] = cells;
1223
+ if (start.match(/[a-zA-Z]$/)) {
1224
+ start += "1";
1225
+ }
1226
+ if (start.match(/^[1-9]/)) {
1227
+ start = `A${start}`;
1228
+ }
1229
+ if (end == null ? void 0 : end.match(/[a-zA-Z]$/)) {
1230
+ end += this.bottom;
1231
+ }
1232
+ if (end == null ? void 0 : end.match(/^[1-9]/)) {
1233
+ end = `${x2c(this.right)}${end}`;
1234
+ }
1235
+ const { y: top, x: left } = a2p(start);
1236
+ const { y: bottom, x: right } = a2p(end || start);
1237
+ return {
1238
+ top: Math.abs(top),
1239
+ left: Math.abs(left),
1240
+ bottom: Math.abs(bottom),
1241
+ right: Math.abs(right)
1242
+ };
1243
+ }
1244
+ }
1245
+ export {
1246
+ Table
1247
+ };
1248
+ //# sourceMappingURL=table.js.map