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