@gridsheet/react-core 0.12.4-alpha.2 → 0.12.4-beta.1

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