@gridsheet/react-core 1.3.1 → 1.4.0-alpha.0

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