@gridsheet/react-core 1.3.1 → 1.4.0-alpha.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 (367) hide show
  1. package/dist/components/Cell.d.ts +2 -2
  2. package/dist/components/Cell.d.ts.map +1 -1
  3. package/dist/components/ContextMenu.d.ts +1 -1
  4. package/dist/components/ContextMenu.d.ts.map +1 -1
  5. package/dist/components/Editor.d.ts +4 -4
  6. package/dist/components/Editor.d.ts.map +1 -1
  7. package/dist/components/Emitter.d.ts +2 -2
  8. package/dist/components/Emitter.d.ts.map +1 -1
  9. package/dist/components/Fixed.d.ts +2 -2
  10. package/dist/components/Fixed.d.ts.map +1 -1
  11. package/dist/components/FormulaBar.d.ts +1 -1
  12. package/dist/components/FormulaBar.d.ts.map +1 -1
  13. package/dist/components/GridSheet.d.ts +2 -2
  14. package/dist/components/GridSheet.d.ts.map +1 -1
  15. package/dist/components/HeaderCellLeft.d.ts +2 -2
  16. package/dist/components/HeaderCellLeft.d.ts.map +1 -1
  17. package/dist/components/HeaderCellTop.d.ts +2 -2
  18. package/dist/components/HeaderCellTop.d.ts.map +1 -1
  19. package/dist/components/PluginBase.d.ts +3 -3
  20. package/dist/components/PluginBase.d.ts.map +1 -1
  21. package/dist/components/Resizer.d.ts +1 -1
  22. package/dist/components/Resizer.d.ts.map +1 -1
  23. package/dist/components/SearchBar.d.ts +1 -1
  24. package/dist/components/SearchBar.d.ts.map +1 -1
  25. package/dist/components/SheetProvider.d.ts +3 -3
  26. package/dist/components/SheetProvider.d.ts.map +1 -1
  27. package/dist/components/StoreInitializer.d.ts +1 -1
  28. package/dist/components/StoreInitializer.d.ts.map +1 -1
  29. package/dist/components/Tabular.d.ts +2 -2
  30. package/dist/components/Tabular.d.ts.map +1 -1
  31. package/dist/components/Toggle.d.ts +12 -0
  32. package/dist/components/Toggle.d.ts.map +1 -0
  33. package/dist/components/hooks.d.ts.map +1 -1
  34. package/dist/components/svg/AddIcon.d.ts +4 -0
  35. package/dist/components/svg/AddIcon.d.ts.map +1 -0
  36. package/dist/components/svg/Base.d.ts +1 -1
  37. package/dist/components/svg/Base.d.ts.map +1 -1
  38. package/dist/components/svg/CloseIcon.d.ts +2 -2
  39. package/dist/components/svg/CloseIcon.d.ts.map +1 -1
  40. package/dist/components/svg/SearchIcon.d.ts +2 -2
  41. package/dist/components/svg/SearchIcon.d.ts.map +1 -1
  42. package/dist/constants.d.ts.map +1 -1
  43. package/dist/formula/evaluator.d.ts +5 -5
  44. package/dist/formula/evaluator.d.ts.map +1 -1
  45. package/dist/formula/functions/__base.d.ts +2 -2
  46. package/dist/formula/functions/__base.d.ts.map +1 -1
  47. package/dist/formula/functions/__utils.d.ts.map +1 -1
  48. package/dist/formula/functions/abs.d.ts.map +1 -1
  49. package/dist/formula/functions/abs.spec.d.ts.map +1 -1
  50. package/dist/formula/functions/acos.d.ts.map +1 -1
  51. package/dist/formula/functions/add.d.ts.map +1 -1
  52. package/dist/formula/functions/and.d.ts.map +1 -1
  53. package/dist/formula/functions/asin.d.ts.map +1 -1
  54. package/dist/formula/functions/atan.d.ts.map +1 -1
  55. package/dist/formula/functions/atan2.d.ts.map +1 -1
  56. package/dist/formula/functions/average.d.ts.map +1 -1
  57. package/dist/formula/functions/col.d.ts.map +1 -1
  58. package/dist/formula/functions/concat.d.ts.map +1 -1
  59. package/dist/formula/functions/concatenate.d.ts.map +1 -1
  60. package/dist/formula/functions/cos.d.ts.map +1 -1
  61. package/dist/formula/functions/count.d.ts.map +1 -1
  62. package/dist/formula/functions/counta.d.ts.map +1 -1
  63. package/dist/formula/functions/countif.d.ts.map +1 -1
  64. package/dist/formula/functions/countif.spec.d.ts.map +1 -1
  65. package/dist/formula/functions/divide.d.ts.map +1 -1
  66. package/dist/formula/functions/eq.d.ts.map +1 -1
  67. package/dist/formula/functions/eq.spec.d.ts.map +1 -1
  68. package/dist/formula/functions/exp.d.ts.map +1 -1
  69. package/dist/formula/functions/gt.d.ts.map +1 -1
  70. package/dist/formula/functions/gte.d.ts.map +1 -1
  71. package/dist/formula/functions/hlookup.d.ts.map +1 -1
  72. package/dist/formula/functions/if.d.ts.map +1 -1
  73. package/dist/formula/functions/iferror.d.ts.map +1 -1
  74. package/dist/formula/functions/iferror.spec.d.ts.map +1 -1
  75. package/dist/formula/functions/len.d.ts.map +1 -1
  76. package/dist/formula/functions/lenb.d.ts.map +1 -1
  77. package/dist/formula/functions/ln.d.ts.map +1 -1
  78. package/dist/formula/functions/log.d.ts.map +1 -1
  79. package/dist/formula/functions/log10.d.ts.map +1 -1
  80. package/dist/formula/functions/lt.d.ts.map +1 -1
  81. package/dist/formula/functions/lte.d.ts.map +1 -1
  82. package/dist/formula/functions/max.d.ts.map +1 -1
  83. package/dist/formula/functions/min.d.ts.map +1 -1
  84. package/dist/formula/functions/minus.d.ts.map +1 -1
  85. package/dist/formula/functions/mod.d.ts.map +1 -1
  86. package/dist/formula/functions/mod.spec.d.ts.map +1 -1
  87. package/dist/formula/functions/multiply.d.ts.map +1 -1
  88. package/dist/formula/functions/ne.d.ts.map +1 -1
  89. package/dist/formula/functions/not.d.ts.map +1 -1
  90. package/dist/formula/functions/now.d.ts.map +1 -1
  91. package/dist/formula/functions/or.d.ts.map +1 -1
  92. package/dist/formula/functions/pi.d.ts.map +1 -1
  93. package/dist/formula/functions/power.d.ts.map +1 -1
  94. package/dist/formula/functions/product.d.ts.map +1 -1
  95. package/dist/formula/functions/radians.d.ts.map +1 -1
  96. package/dist/formula/functions/rand.d.ts.map +1 -1
  97. package/dist/formula/functions/round.d.ts.map +1 -1
  98. package/dist/formula/functions/rounddown.d.ts.map +1 -1
  99. package/dist/formula/functions/roundup.d.ts.map +1 -1
  100. package/dist/formula/functions/row.d.ts.map +1 -1
  101. package/dist/formula/functions/sin.d.ts.map +1 -1
  102. package/dist/formula/functions/sqrt.d.ts.map +1 -1
  103. package/dist/formula/functions/sum.d.ts.map +1 -1
  104. package/dist/formula/functions/sum.spec.d.ts.map +1 -1
  105. package/dist/formula/functions/sumif.d.ts.map +1 -1
  106. package/dist/formula/functions/tan.d.ts.map +1 -1
  107. package/dist/formula/functions/uminus.d.ts.map +1 -1
  108. package/dist/formula/functions/vlookup.d.ts.map +1 -1
  109. package/dist/formula/mapping.d.ts +1 -1
  110. package/dist/formula/mapping.d.ts.map +1 -1
  111. package/dist/formula/solver.d.ts +3 -3
  112. package/dist/formula/solver.d.ts.map +1 -1
  113. package/dist/index.d.ts +6 -2
  114. package/dist/index.d.ts.map +1 -1
  115. package/dist/index.js +6823 -58
  116. package/dist/lib/autofill.d.ts +3 -3
  117. package/dist/lib/autofill.d.ts.map +1 -1
  118. package/dist/lib/clipboard.d.ts +1 -1
  119. package/dist/lib/clipboard.d.ts.map +1 -1
  120. package/dist/lib/converters.d.ts +1 -1
  121. package/dist/lib/converters.d.ts.map +1 -1
  122. package/dist/lib/input.d.ts.map +1 -1
  123. package/dist/lib/palette.d.ts.map +1 -1
  124. package/dist/lib/prevention.d.ts.map +1 -1
  125. package/dist/lib/structs.d.ts +21 -21
  126. package/dist/lib/structs.d.ts.map +1 -1
  127. package/dist/lib/table.d.ts +8 -8
  128. package/dist/lib/table.d.ts.map +1 -1
  129. package/dist/lib/time.d.ts +1 -1
  130. package/dist/lib/time.d.ts.map +1 -1
  131. package/dist/lib/virtualization.d.ts +1 -1
  132. package/dist/lib/virtualization.d.ts.map +1 -1
  133. package/dist/parsers/core.d.ts +4 -4
  134. package/dist/parsers/core.d.ts.map +1 -1
  135. package/dist/renderers/checkbox.d.ts.map +1 -1
  136. package/dist/renderers/core.d.ts +4 -4
  137. package/dist/renderers/core.d.ts.map +1 -1
  138. package/dist/renderers/thousand_separator.d.ts.map +1 -1
  139. package/dist/store/actions.d.ts +7 -4
  140. package/dist/store/actions.d.ts.map +1 -1
  141. package/dist/store/helpers.d.ts.map +1 -1
  142. package/dist/store/index.d.ts +2 -2
  143. package/dist/store/index.d.ts.map +1 -1
  144. package/dist/styles/embedder.d.ts.map +1 -1
  145. package/dist/styles/minified.d.ts +2 -2
  146. package/dist/styles/minified.d.ts.map +1 -1
  147. package/dist/types.d.ts +51 -49
  148. package/dist/types.d.ts.map +1 -1
  149. package/dist/utils.d.ts.map +1 -1
  150. package/package.json +19 -43
  151. package/LICENSE +0 -190
  152. package/README.md +0 -26
  153. package/dist/components/Cell.js +0 -188
  154. package/dist/components/Cell.js.map +0 -1
  155. package/dist/components/ContextMenu.js +0 -246
  156. package/dist/components/ContextMenu.js.map +0 -1
  157. package/dist/components/Editor.js +0 -436
  158. package/dist/components/Editor.js.map +0 -1
  159. package/dist/components/Emitter.js +0 -33
  160. package/dist/components/Emitter.js.map +0 -1
  161. package/dist/components/Fixed.js +0 -30
  162. package/dist/components/Fixed.js.map +0 -1
  163. package/dist/components/FormulaBar.js +0 -152
  164. package/dist/components/FormulaBar.js.map +0 -1
  165. package/dist/components/GridSheet.js +0 -208
  166. package/dist/components/GridSheet.js.map +0 -1
  167. package/dist/components/HeaderCellLeft.js +0 -121
  168. package/dist/components/HeaderCellLeft.js.map +0 -1
  169. package/dist/components/HeaderCellTop.js +0 -122
  170. package/dist/components/HeaderCellTop.js.map +0 -1
  171. package/dist/components/PluginBase.js +0 -41
  172. package/dist/components/PluginBase.js.map +0 -1
  173. package/dist/components/Resizer.js +0 -91
  174. package/dist/components/Resizer.js.map +0 -1
  175. package/dist/components/SearchBar.js +0 -73
  176. package/dist/components/SearchBar.js.map +0 -1
  177. package/dist/components/SheetProvider.js +0 -60
  178. package/dist/components/SheetProvider.js.map +0 -1
  179. package/dist/components/StoreInitializer.js +0 -73
  180. package/dist/components/StoreInitializer.js.map +0 -1
  181. package/dist/components/Tabular.js +0 -249
  182. package/dist/components/Tabular.js.map +0 -1
  183. package/dist/components/hooks.js +0 -20
  184. package/dist/components/hooks.js.map +0 -1
  185. package/dist/components/svg/Base.js +0 -13
  186. package/dist/components/svg/Base.js.map +0 -1
  187. package/dist/components/svg/CloseIcon.js +0 -17
  188. package/dist/components/svg/CloseIcon.js.map +0 -1
  189. package/dist/components/svg/SearchIcon.js +0 -17
  190. package/dist/components/svg/SearchIcon.js.map +0 -1
  191. package/dist/constants.js +0 -29
  192. package/dist/constants.js.map +0 -1
  193. package/dist/formula/evaluator.js +0 -726
  194. package/dist/formula/evaluator.js.map +0 -1
  195. package/dist/formula/functions/__base.js +0 -22
  196. package/dist/formula/functions/__base.js.map +0 -1
  197. package/dist/formula/functions/__utils.js +0 -162
  198. package/dist/formula/functions/__utils.js.map +0 -1
  199. package/dist/formula/functions/abs.js +0 -25
  200. package/dist/formula/functions/abs.js.map +0 -1
  201. package/dist/formula/functions/abs.spec.js +0 -30
  202. package/dist/formula/functions/abs.spec.js.map +0 -1
  203. package/dist/formula/functions/acos.js +0 -33
  204. package/dist/formula/functions/acos.js.map +0 -1
  205. package/dist/formula/functions/add.js +0 -65
  206. package/dist/formula/functions/add.js.map +0 -1
  207. package/dist/formula/functions/and.js +0 -29
  208. package/dist/formula/functions/and.js.map +0 -1
  209. package/dist/formula/functions/asin.js +0 -33
  210. package/dist/formula/functions/asin.js.map +0 -1
  211. package/dist/formula/functions/atan.js +0 -30
  212. package/dist/formula/functions/atan.js.map +0 -1
  213. package/dist/formula/functions/atan2.js +0 -36
  214. package/dist/formula/functions/atan2.js.map +0 -1
  215. package/dist/formula/functions/average.js +0 -47
  216. package/dist/formula/functions/average.js.map +0 -1
  217. package/dist/formula/functions/col.js +0 -35
  218. package/dist/formula/functions/col.js.map +0 -1
  219. package/dist/formula/functions/concat.js +0 -28
  220. package/dist/formula/functions/concat.js.map +0 -1
  221. package/dist/formula/functions/concatenate.js +0 -29
  222. package/dist/formula/functions/concatenate.js.map +0 -1
  223. package/dist/formula/functions/cos.js +0 -30
  224. package/dist/formula/functions/cos.js.map +0 -1
  225. package/dist/formula/functions/count.js +0 -40
  226. package/dist/formula/functions/count.js.map +0 -1
  227. package/dist/formula/functions/counta.js +0 -40
  228. package/dist/formula/functions/counta.js.map +0 -1
  229. package/dist/formula/functions/countif.js +0 -33
  230. package/dist/formula/functions/countif.js.map +0 -1
  231. package/dist/formula/functions/countif.spec.js +0 -185
  232. package/dist/formula/functions/countif.spec.js.map +0 -1
  233. package/dist/formula/functions/divide.js +0 -34
  234. package/dist/formula/functions/divide.js.map +0 -1
  235. package/dist/formula/functions/eq.js +0 -30
  236. package/dist/formula/functions/eq.js.map +0 -1
  237. package/dist/formula/functions/eq.spec.js +0 -92
  238. package/dist/formula/functions/eq.spec.js.map +0 -1
  239. package/dist/formula/functions/exp.js +0 -30
  240. package/dist/formula/functions/exp.js.map +0 -1
  241. package/dist/formula/functions/gt.js +0 -30
  242. package/dist/formula/functions/gt.js.map +0 -1
  243. package/dist/formula/functions/gte.js +0 -30
  244. package/dist/formula/functions/gte.js.map +0 -1
  245. package/dist/formula/functions/hlookup.js +0 -78
  246. package/dist/formula/functions/hlookup.js.map +0 -1
  247. package/dist/formula/functions/if.js +0 -40
  248. package/dist/formula/functions/if.js.map +0 -1
  249. package/dist/formula/functions/iferror.js +0 -45
  250. package/dist/formula/functions/iferror.js.map +0 -1
  251. package/dist/formula/functions/iferror.spec.js +0 -62
  252. package/dist/formula/functions/iferror.spec.js.map +0 -1
  253. package/dist/formula/functions/len.js +0 -30
  254. package/dist/formula/functions/len.js.map +0 -1
  255. package/dist/formula/functions/lenb.js +0 -30
  256. package/dist/formula/functions/lenb.js.map +0 -1
  257. package/dist/formula/functions/ln.js +0 -33
  258. package/dist/formula/functions/ln.js.map +0 -1
  259. package/dist/formula/functions/log.js +0 -37
  260. package/dist/formula/functions/log.js.map +0 -1
  261. package/dist/formula/functions/log10.js +0 -33
  262. package/dist/formula/functions/log10.js.map +0 -1
  263. package/dist/formula/functions/lt.js +0 -30
  264. package/dist/formula/functions/lt.js.map +0 -1
  265. package/dist/formula/functions/lte.js +0 -30
  266. package/dist/formula/functions/lte.js.map +0 -1
  267. package/dist/formula/functions/max.js +0 -50
  268. package/dist/formula/functions/max.js.map +0 -1
  269. package/dist/formula/functions/min.js +0 -50
  270. package/dist/formula/functions/min.js.map +0 -1
  271. package/dist/formula/functions/minus.js +0 -63
  272. package/dist/formula/functions/minus.js.map +0 -1
  273. package/dist/formula/functions/mod.js +0 -35
  274. package/dist/formula/functions/mod.js.map +0 -1
  275. package/dist/formula/functions/mod.spec.js +0 -67
  276. package/dist/formula/functions/mod.spec.js.map +0 -1
  277. package/dist/formula/functions/multiply.js +0 -28
  278. package/dist/formula/functions/multiply.js.map +0 -1
  279. package/dist/formula/functions/ne.js +0 -30
  280. package/dist/formula/functions/ne.js.map +0 -1
  281. package/dist/formula/functions/not.js +0 -31
  282. package/dist/formula/functions/not.js.map +0 -1
  283. package/dist/formula/functions/now.js +0 -23
  284. package/dist/formula/functions/now.js.map +0 -1
  285. package/dist/formula/functions/or.js +0 -29
  286. package/dist/formula/functions/or.js.map +0 -1
  287. package/dist/formula/functions/pi.js +0 -23
  288. package/dist/formula/functions/pi.js.map +0 -1
  289. package/dist/formula/functions/power.js +0 -28
  290. package/dist/formula/functions/power.js.map +0 -1
  291. package/dist/formula/functions/product.js +0 -43
  292. package/dist/formula/functions/product.js.map +0 -1
  293. package/dist/formula/functions/radians.js +0 -30
  294. package/dist/formula/functions/radians.js.map +0 -1
  295. package/dist/formula/functions/rand.js +0 -23
  296. package/dist/formula/functions/rand.js.map +0 -1
  297. package/dist/formula/functions/round.js +0 -36
  298. package/dist/formula/functions/round.js.map +0 -1
  299. package/dist/formula/functions/rounddown.js +0 -36
  300. package/dist/formula/functions/rounddown.js.map +0 -1
  301. package/dist/formula/functions/roundup.js +0 -36
  302. package/dist/formula/functions/roundup.js.map +0 -1
  303. package/dist/formula/functions/row.js +0 -35
  304. package/dist/formula/functions/row.js.map +0 -1
  305. package/dist/formula/functions/sin.js +0 -30
  306. package/dist/formula/functions/sin.js.map +0 -1
  307. package/dist/formula/functions/sqrt.js +0 -33
  308. package/dist/formula/functions/sqrt.js.map +0 -1
  309. package/dist/formula/functions/sum.js +0 -50
  310. package/dist/formula/functions/sum.js.map +0 -1
  311. package/dist/formula/functions/sum.spec.js +0 -39
  312. package/dist/formula/functions/sum.spec.js.map +0 -1
  313. package/dist/formula/functions/sumif.js +0 -64
  314. package/dist/formula/functions/sumif.js.map +0 -1
  315. package/dist/formula/functions/tan.js +0 -30
  316. package/dist/formula/functions/tan.js.map +0 -1
  317. package/dist/formula/functions/uminus.js +0 -25
  318. package/dist/formula/functions/uminus.js.map +0 -1
  319. package/dist/formula/functions/vlookup.js +0 -78
  320. package/dist/formula/functions/vlookup.js.map +0 -1
  321. package/dist/formula/mapping.js +0 -118
  322. package/dist/formula/mapping.js.map +0 -1
  323. package/dist/formula/solver.js +0 -75
  324. package/dist/formula/solver.js.map +0 -1
  325. package/dist/index.js.map +0 -1
  326. package/dist/lib/autofill.js +0 -406
  327. package/dist/lib/autofill.js.map +0 -1
  328. package/dist/lib/clipboard.js +0 -50
  329. package/dist/lib/clipboard.js.map +0 -1
  330. package/dist/lib/converters.js +0 -145
  331. package/dist/lib/converters.js.map +0 -1
  332. package/dist/lib/input.js +0 -60
  333. package/dist/lib/input.js.map +0 -1
  334. package/dist/lib/palette.js +0 -24
  335. package/dist/lib/palette.js.map +0 -1
  336. package/dist/lib/prevention.js +0 -64
  337. package/dist/lib/prevention.js.map +0 -1
  338. package/dist/lib/structs.js +0 -308
  339. package/dist/lib/structs.js.map +0 -1
  340. package/dist/lib/table.js +0 -1160
  341. package/dist/lib/table.js.map +0 -1
  342. package/dist/lib/time.js +0 -78
  343. package/dist/lib/time.js.map +0 -1
  344. package/dist/lib/virtualization.js +0 -149
  345. package/dist/lib/virtualization.js.map +0 -1
  346. package/dist/parsers/core.js +0 -147
  347. package/dist/parsers/core.js.map +0 -1
  348. package/dist/renderers/checkbox.js +0 -16
  349. package/dist/renderers/checkbox.js.map +0 -1
  350. package/dist/renderers/core.js +0 -161
  351. package/dist/renderers/core.js.map +0 -1
  352. package/dist/renderers/thousand_separator.js +0 -17
  353. package/dist/renderers/thousand_separator.js.map +0 -1
  354. package/dist/store/actions.js +0 -603
  355. package/dist/store/actions.js.map +0 -1
  356. package/dist/store/helpers.js +0 -89
  357. package/dist/store/helpers.js.map +0 -1
  358. package/dist/store/index.js +0 -29
  359. package/dist/store/index.js.map +0 -1
  360. package/dist/styles/embedder.js +0 -20
  361. package/dist/styles/embedder.js.map +0 -1
  362. package/dist/styles/minified.js +0 -7
  363. package/dist/styles/minified.js.map +0 -1
  364. package/dist/types.js +0 -3
  365. package/dist/types.js.map +0 -1
  366. package/dist/utils.js +0 -12
  367. package/dist/utils.js.map +0 -1
@@ -1,726 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stripSheetName = exports.absolutizeFormula = exports.Parser = exports.Lexer = exports.Token = exports.FunctionEntity = exports.IdRangeEntity = exports.IdEntity = exports.RangeEntity = exports.RefEntity = exports.InvalidRefEntity = exports.UnreferencedEntity = exports.ValueEntity = exports.FormulaError = void 0;
4
- const converters_1 = require("../lib/converters");
5
- // strip sharp and dollars
6
- const getId = (idString, stripAbsolute = true) => {
7
- let id = idString.slice(1);
8
- if (stripAbsolute && id.startsWith('$')) {
9
- id = id.slice(1);
10
- }
11
- if (stripAbsolute && id.endsWith('$')) {
12
- id = id.slice(0, -1);
13
- }
14
- return id;
15
- };
16
- class FormulaError {
17
- constructor(code, message, error) {
18
- this.code = code;
19
- this.message = message;
20
- this.error = error;
21
- }
22
- }
23
- exports.FormulaError = FormulaError;
24
- class Entity {
25
- constructor(value) {
26
- this.value = value;
27
- }
28
- }
29
- class ValueEntity extends Entity {
30
- evaluate() {
31
- return this.value;
32
- }
33
- }
34
- exports.ValueEntity = ValueEntity;
35
- class UnreferencedEntity extends Entity {
36
- evaluate() {
37
- throw new FormulaError('#REF!', `Reference does not exist.`);
38
- }
39
- }
40
- exports.UnreferencedEntity = UnreferencedEntity;
41
- class InvalidRefEntity extends Entity {
42
- evaluate() {
43
- throw new FormulaError('#NAME?', `Invalid ref: ${this.value}`);
44
- }
45
- }
46
- exports.InvalidRefEntity = InvalidRefEntity;
47
- class RefEntity extends Entity {
48
- constructor(value) {
49
- super(value);
50
- }
51
- stringify() {
52
- return this.value.toUpperCase();
53
- }
54
- parse(table) {
55
- if (this.value.indexOf('!') !== -1) {
56
- const [rawSheetName, ref] = this.value.split('!');
57
- const sheetName = (0, exports.stripSheetName)(rawSheetName);
58
- return {
59
- table: table.getTableBySheetName(sheetName),
60
- ref: ref.toUpperCase(),
61
- sheetName,
62
- };
63
- }
64
- return {
65
- table,
66
- ref: this.value.toUpperCase(),
67
- sheetName: (0, exports.stripSheetName)(table.sheetName),
68
- };
69
- }
70
- evaluate({ table }) {
71
- const parsed = this.parse(table);
72
- if (parsed.table == null) {
73
- throw new FormulaError('#REF!', `Unknown sheet: ${parsed.sheetName}`);
74
- }
75
- const { y, x } = (0, converters_1.a2p)(parsed.ref);
76
- return parsed.table.trim({ top: y, left: x, bottom: y, right: x });
77
- }
78
- id(table) {
79
- const parsed = this.parse(table);
80
- if (parsed.table == null) {
81
- return this.value;
82
- }
83
- const id = parsed.table.getIdByAddress(parsed.ref);
84
- if (id) {
85
- if (parsed.table === table) {
86
- return id;
87
- }
88
- return `#${parsed.table.sheetId}!${id}`;
89
- }
90
- return this.value;
91
- }
92
- }
93
- exports.RefEntity = RefEntity;
94
- class RangeEntity extends Entity {
95
- parse(table) {
96
- const rawRefs = this.value.split(':');
97
- const refs = [];
98
- let sheetName = '';
99
- for (let i = 0; i < rawRefs.length; i++) {
100
- const ref = rawRefs[i];
101
- if (ref.indexOf('!') !== -1) {
102
- const [rawSheetName, rawRef] = ref.split('!');
103
- refs.push(rawRef.toUpperCase());
104
- if (i === 0) {
105
- sheetName = (0, exports.stripSheetName)(rawSheetName);
106
- table = table.getTableBySheetName(sheetName);
107
- }
108
- if (table == null) {
109
- return { table, refs, sheetName };
110
- }
111
- }
112
- else {
113
- refs.push(ref);
114
- }
115
- }
116
- return { table, refs, sheetName: sheetName || table.sheetName };
117
- }
118
- stringify() {
119
- return this.value.toUpperCase();
120
- }
121
- evaluate({ table }) {
122
- const parsed = this.parse(table);
123
- if (parsed.table == null) {
124
- throw new FormulaError('#REF!', `Unknown sheet: ${parsed.sheetName}`);
125
- }
126
- const area = parsed.table.rangeToArea(parsed.refs.join(':'));
127
- return parsed.table.trim(area);
128
- }
129
- idRange(table) {
130
- const parsed = this.parse(table);
131
- if (parsed.table == null) {
132
- return this.value;
133
- }
134
- const range = parsed.refs.map((ref) => parsed.table.getIdByAddress(ref)).join(':');
135
- if (parsed.table === table) {
136
- return range;
137
- }
138
- return `#${parsed.table.sheetId}!${range}`;
139
- }
140
- }
141
- exports.RangeEntity = RangeEntity;
142
- class IdEntity extends Entity {
143
- parse(table) {
144
- if (this.value.indexOf('!') !== -1) {
145
- const [tableId, id] = this.value.split('!');
146
- return { table: table.tables[tableId.slice(1)], id: getId(id, false) };
147
- }
148
- return { table, id: getId(this.value, false) };
149
- }
150
- evaluate({ table }) {
151
- const parsed = this.parse(table);
152
- const { y, x } = parsed.table.getPointById(parsed.id);
153
- const [absY, absX] = [Math.abs(y), Math.abs(x)];
154
- return parsed.table.trim({
155
- top: absY,
156
- left: absX,
157
- bottom: absY,
158
- right: absX,
159
- });
160
- }
161
- ref(table, slideY = 0, slideX = 0) {
162
- const parsed = this.parse(table);
163
- const address = parsed.table.getAddressById(parsed.id, slideY, slideX);
164
- if (parsed.table.sheetId === table.sheetId) {
165
- return address;
166
- }
167
- return `${parsed.table.sheetPrefix()}${address}`;
168
- }
169
- slide(table, slideY = 0, slideX = 0) {
170
- const address = this.ref(table, slideY, slideX);
171
- if (address == null || address.length < 2) {
172
- return '#REF!';
173
- }
174
- return table.getIdByAddress(address);
175
- }
176
- }
177
- exports.IdEntity = IdEntity;
178
- class IdRangeEntity extends Entity {
179
- parse(table) {
180
- const range = this.value;
181
- if (range.indexOf('!') !== -1) {
182
- const [sheetId, idRange] = range.split('!');
183
- table = table.tables[sheetId.slice(1)];
184
- return { table, ids: idRange.split(':') };
185
- }
186
- return { table, ids: range.split(':') };
187
- }
188
- evaluate({ table }) {
189
- const parsed = this.parse(table);
190
- const [p1, p2] = parsed.ids.map((id) => getId(id)).map((id) => parsed.table.getPointById(id));
191
- const [top, left, bottom, right] = [
192
- p1.y,
193
- p1.x,
194
- p2.y || parsed.table.getNumRows(),
195
- p2.x || parsed.table.getNumCols(),
196
- ];
197
- return parsed.table.trim({ top, left, bottom, right });
198
- }
199
- range(table, slideY = 0, slideX = 0) {
200
- const parsed = this.parse(table);
201
- const range = parsed.ids
202
- .map((id) => getId(id, false))
203
- .map((id) => parsed.table.getAddressById(id, slideY, slideX))
204
- .join(':');
205
- if (parsed.table.sheetId === table.sheetId) {
206
- return range;
207
- }
208
- return `${parsed.table.sheetPrefix()}${range}`;
209
- }
210
- slide(table, slideY = 0, slideX = 0) {
211
- const range = this.range(table, slideY, slideX);
212
- return new RangeEntity(range).idRange(table);
213
- }
214
- }
215
- exports.IdRangeEntity = IdRangeEntity;
216
- class FunctionEntity {
217
- constructor(name, precedence = 0, args = []) {
218
- this.name = name;
219
- this.precedence = precedence;
220
- this.args = args;
221
- }
222
- evaluate({ table }) {
223
- const name = this.name.toLowerCase();
224
- const Func = table.getFunction(name);
225
- if (Func == null) {
226
- throw new FormulaError('#NAME?', `Unknown function: ${name}`);
227
- }
228
- const func = new Func({ args: this.args, table });
229
- return func.call();
230
- }
231
- }
232
- exports.FunctionEntity = FunctionEntity;
233
- const ZERO = new ValueEntity(0);
234
- const INFIX_FUNCTION_NAME_MAP = {
235
- '+': 'add',
236
- '-': 'minus',
237
- '/': 'divide',
238
- '*': 'multiply',
239
- '^': 'power',
240
- '&': 'concat',
241
- '=': 'eq',
242
- '<>': 'ne',
243
- '>': 'gt',
244
- '>=': 'gte',
245
- '<': 'lt',
246
- '<=': 'lte',
247
- };
248
- const PREFIX_FUNCTION_NAME_MAP = {
249
- '-': 'uminus',
250
- };
251
- const WHITESPACE_CHARS = new Set([' ', '\n', '\r', '\t', '\f']);
252
- const SPECIAL_CHARS = new Set([...WHITESPACE_CHARS, '+', '-', '/', '*', '^', '&', '=', '<', '>', ')', ',', '%']);
253
- class Token {
254
- constructor(type, entity, precedence = 0) {
255
- this.type = type;
256
- this.entity = entity;
257
- this.precedence = precedence;
258
- }
259
- length() {
260
- if (this.type === 'VALUE' && typeof this.entity === 'string') {
261
- return this.entity.length + 2;
262
- }
263
- return new String(this.entity).length;
264
- }
265
- stringify() {
266
- if (this.type === 'VALUE') {
267
- if (typeof this.entity === 'string') {
268
- return `"${this.entity}"`;
269
- }
270
- if (typeof this.entity === 'boolean') {
271
- return this.entity ? 'TRUE' : 'FALSE';
272
- }
273
- }
274
- return this.entity;
275
- }
276
- convert() {
277
- switch (this.type) {
278
- case 'VALUE':
279
- return new ValueEntity(this.entity);
280
- // eslint-disable-next-line no-fallthrough
281
- case 'ID':
282
- return new IdEntity(this.entity);
283
- // eslint-disable-next-line no-fallthrough
284
- case 'ID_RANGE':
285
- return new IdRangeEntity(this.entity);
286
- // eslint-disable-next-line no-fallthrough
287
- case 'REF':
288
- return new RefEntity(this.entity);
289
- // eslint-disable-next-line no-fallthrough
290
- case 'RANGE':
291
- return new RangeEntity(this.entity);
292
- // eslint-disable-next-line no-fallthrough
293
- case 'INFIX_OPERATOR': {
294
- const name = INFIX_FUNCTION_NAME_MAP[this.entity];
295
- return new FunctionEntity(name, this.precedence);
296
- // eslint-disable-next-line no-fallthrough
297
- }
298
- case 'PREFIX_OPERATOR': {
299
- const name = PREFIX_FUNCTION_NAME_MAP[this.entity];
300
- return new FunctionEntity(name, this.precedence);
301
- // eslint-disable-next-line no-fallthrough
302
- }
303
- case 'FUNCTION':
304
- return new FunctionEntity(this.entity);
305
- // eslint-disable-next-line no-fallthrough
306
- case 'UNREFERENCED':
307
- return new UnreferencedEntity(this.entity);
308
- // eslint-disable-next-line no-fallthrough
309
- case 'INVALID_REF':
310
- return new InvalidRefEntity(this.entity);
311
- // eslint-disable-next-line no-fallthrough
312
- }
313
- }
314
- }
315
- exports.Token = Token;
316
- const isWhiteSpace = (char) => {
317
- return WHITESPACE_CHARS.has(char);
318
- };
319
- const TOKEN_OPEN = new Token('OPEN', '('), TOKEN_CLOSE = new Token('CLOSE', ')'), TOKEN_COMMA = new Token('COMMA', ','), TOKEN_ADD = new Token('INFIX_OPERATOR', '+', 3), TOKEN_MINUS = new Token('INFIX_OPERATOR', '-', 3), TOKEN_UMINUS = new Token('PREFIX_OPERATOR', '-', 6), TOKEN_DIVIDE = new Token('INFIX_OPERATOR', '/', 4), TOKEN_MULTIPLY = new Token('INFIX_OPERATOR', '*', 4), TOKEN_POWER = new Token('INFIX_OPERATOR', '^', 5), TOKEN_CONCAT = new Token('INFIX_OPERATOR', '&', 4), TOKEN_GTE = new Token('INFIX_OPERATOR', '>=', 2), TOKEN_GT = new Token('INFIX_OPERATOR', '>', 2), TOKEN_LTE = new Token('INFIX_OPERATOR', '<=', 2), TOKEN_LT = new Token('INFIX_OPERATOR', '<', 2), TOKEN_NE = new Token('INFIX_OPERATOR', '<>', 1), TOKEN_EQ = new Token('INFIX_OPERATOR', '=', 1);
320
- const BOOLS = { ['true']: true, ['false']: false };
321
- class Lexer {
322
- constructor(formula) {
323
- this.tokens = [];
324
- this.foreign = false;
325
- this.formula = formula;
326
- this.index = 0;
327
- this.tokens = [];
328
- }
329
- isWhiteSpace() {
330
- return isWhiteSpace(this.formula[this.index]);
331
- }
332
- next(base = 1) {
333
- this.index += base;
334
- }
335
- get(base = 0) {
336
- const c = this.formula[this.index + base];
337
- return c;
338
- }
339
- getToken(base = 0) {
340
- return this.tokens[this.tokens.length + base];
341
- }
342
- getTokenIndexByCharPosition(pos) {
343
- let start = 0, end = 0;
344
- for (let i = 0; i < this.tokens.length; i++) {
345
- const token = this.tokens[i];
346
- end = start + token.length();
347
- if (start <= pos && pos <= end) {
348
- return i;
349
- }
350
- start = end;
351
- }
352
- return -1;
353
- }
354
- getTokenPositionRange(index, slide = 1) {
355
- let start = 0, end = 0;
356
- for (let i = 0; i < index; i++) {
357
- start = end;
358
- end += this.tokens[i].length();
359
- }
360
- return [start + slide, end + slide];
361
- }
362
- stringify() {
363
- return this.tokens.map((t) => t.stringify()).join('');
364
- }
365
- stringifyToId(table, slideY = 0, slideX = 0) {
366
- return this.tokens
367
- .map((t) => {
368
- switch (t.type) {
369
- case 'VALUE':
370
- if (typeof t.entity === 'number' || typeof t.entity === 'boolean') {
371
- return t.entity;
372
- }
373
- return `"${t.entity}"`;
374
- // eslint-disable-next-line no-fallthrough
375
- case 'ID':
376
- return new IdEntity(t.entity).slide(table, slideY, slideX);
377
- // eslint-disable-next-line no-fallthrough
378
- case 'ID_RANGE':
379
- return new IdRangeEntity(t.entity).slide(table, slideY, slideX);
380
- // eslint-disable-next-line no-fallthrough
381
- case 'REF':
382
- return new RefEntity(t.entity).id(table);
383
- // eslint-disable-next-line no-fallthrough
384
- case 'RANGE':
385
- return new RangeEntity(t.entity).idRange(table);
386
- // eslint-disable-next-line no-fallthrough
387
- }
388
- return t.entity;
389
- })
390
- .join('');
391
- }
392
- stringifyToRef(table) {
393
- return this.tokens
394
- .map((t) => {
395
- switch (t.type) {
396
- case 'VALUE':
397
- if (typeof t.entity === 'number' || typeof t.entity === 'boolean') {
398
- return t.entity;
399
- }
400
- return `"${t.entity}"`;
401
- case 'ID':
402
- return new IdEntity(t.entity).ref(table);
403
- case 'ID_RANGE':
404
- return new IdRangeEntity(t.entity).range(table);
405
- }
406
- return t.entity;
407
- })
408
- .join('');
409
- }
410
- tokenize() {
411
- var _a, _b;
412
- while (this.index <= this.formula.length) {
413
- this.skipSpaces();
414
- let char = this.get();
415
- this.next();
416
- switch (char) {
417
- case undefined:
418
- return;
419
- case '(':
420
- this.tokens.push(TOKEN_OPEN);
421
- continue;
422
- case ')':
423
- this.tokens.push(TOKEN_CLOSE);
424
- continue;
425
- case ',':
426
- this.tokens.push(TOKEN_COMMA);
427
- continue;
428
- case '+':
429
- this.tokens.push(TOKEN_ADD);
430
- continue;
431
- case '-': {
432
- const prev1 = (_a = this.getToken(-1)) === null || _a === void 0 ? void 0 : _a.type;
433
- const prev2 = (_b = this.getToken(-2)) === null || _b === void 0 ? void 0 : _b.type;
434
- if (prev1 === 'INFIX_OPERATOR' || (prev1 === 'SPACE' && prev2 === 'INFIX_OPERATOR')) {
435
- this.tokens.push(TOKEN_UMINUS);
436
- }
437
- else {
438
- this.tokens.push(TOKEN_MINUS);
439
- }
440
- continue;
441
- }
442
- case '/':
443
- this.tokens.push(TOKEN_DIVIDE);
444
- continue;
445
- case '*':
446
- this.tokens.push(TOKEN_MULTIPLY);
447
- continue;
448
- case '^':
449
- this.tokens.push(TOKEN_POWER);
450
- continue;
451
- case '&':
452
- this.tokens.push(TOKEN_CONCAT);
453
- continue;
454
- case '=':
455
- this.tokens.push(TOKEN_EQ);
456
- continue;
457
- case '>':
458
- if (this.get() === '=') {
459
- this.next();
460
- this.tokens.push(TOKEN_GTE);
461
- continue;
462
- }
463
- this.tokens.push(TOKEN_GT);
464
- continue;
465
- case '<':
466
- if (this.get() === '=') {
467
- this.next();
468
- this.tokens.push(TOKEN_LTE);
469
- continue;
470
- }
471
- if (this.get() === '>') {
472
- this.next();
473
- this.tokens.push(TOKEN_NE);
474
- continue;
475
- }
476
- this.tokens.push(TOKEN_LT);
477
- continue;
478
- case '"': {
479
- const buf = this.getString('"');
480
- this.tokens.push(new Token('VALUE', buf));
481
- continue;
482
- }
483
- case "'": {
484
- const buf = this.getString("'");
485
- char = `'${buf}'`;
486
- break;
487
- }
488
- case '!': {
489
- this.foreign = true;
490
- break;
491
- // not continue
492
- }
493
- case '%': {
494
- this.tokens.push(new Token('POSTFIX_OPERATOR', '%', 4));
495
- continue;
496
- }
497
- } // switch end
498
- let buf = char;
499
- // eslint-disable-next-line no-constant-condition
500
- while (true) {
501
- const c = this.get();
502
- if (c === '(') {
503
- this.tokens.push(new Token('FUNCTION', buf), TOKEN_OPEN);
504
- this.next();
505
- break;
506
- }
507
- if (c == null || SPECIAL_CHARS.has(c)) {
508
- if (buf.length === 0) {
509
- break;
510
- }
511
- if (buf.match(/^[+-]?(\d*[.])?\d+$/)) {
512
- this.tokens.push(new Token('VALUE', parseFloat(buf)));
513
- }
514
- else {
515
- const bool = BOOLS[buf.toLowerCase()];
516
- if (bool != null) {
517
- this.tokens.push(new Token('VALUE', bool));
518
- }
519
- else if (buf.startsWith('#')) {
520
- if (buf === '#REF!') {
521
- this.tokens.push(new Token('UNREFERENCED', buf));
522
- }
523
- else if (buf.indexOf(':') !== -1) {
524
- this.tokens.push(new Token('ID_RANGE', buf));
525
- }
526
- else {
527
- this.tokens.push(new Token('ID', buf));
528
- }
529
- }
530
- else if (buf.indexOf(':') !== -1) {
531
- this.tokens.push(new Token('RANGE', buf));
532
- }
533
- else {
534
- if (isNaN(buf[buf.length - 1])) {
535
- this.tokens.push(new Token('INVALID_REF', buf));
536
- }
537
- else {
538
- this.tokens.push(new Token('REF', buf));
539
- }
540
- }
541
- }
542
- break;
543
- }
544
- buf += c;
545
- this.next();
546
- }
547
- }
548
- }
549
- skipSpaces() {
550
- let space = '';
551
- while (this.isWhiteSpace()) {
552
- space += this.formula[this.index++];
553
- }
554
- if (space !== '') {
555
- this.tokens.push(new Token('SPACE', space));
556
- }
557
- }
558
- getString(quote = '"') {
559
- let buf = '';
560
- // eslint-disable-next-line no-constant-condition
561
- while (true) {
562
- const c = this.get();
563
- this.next();
564
- if (c == null) {
565
- break;
566
- }
567
- if (c === quote) {
568
- if (this.get() === quote) {
569
- // escape
570
- buf += quote;
571
- this.next();
572
- continue;
573
- }
574
- else {
575
- break;
576
- }
577
- }
578
- else {
579
- buf += c;
580
- }
581
- }
582
- return buf;
583
- }
584
- }
585
- exports.Lexer = Lexer;
586
- class Parser {
587
- constructor(tokens) {
588
- this.index = 0;
589
- this.depth = 0;
590
- this.tokens = tokens;
591
- }
592
- build() {
593
- const { expr } = this.parse(false);
594
- return expr;
595
- }
596
- parse(underFunction) {
597
- const stack = [];
598
- let lastOperator;
599
- const complement = (hasNext = false) => {
600
- if (lastOperator) {
601
- const outer = stack.pop();
602
- lastOperator.args.push(outer);
603
- }
604
- return { hasNext, expr: stack.shift() };
605
- };
606
- while (this.tokens.length > this.index) {
607
- const token = this.tokens[this.index++];
608
- if (token.type === 'SPACE') {
609
- continue;
610
- }
611
- if (token.type === 'COMMA') {
612
- if (!underFunction) {
613
- throw new FormulaError('#ERROR!', 'Invalid comma');
614
- }
615
- return complement(true);
616
- }
617
- else if (token.type === 'VALUE' ||
618
- token.type === 'ID' ||
619
- token.type === 'ID_RANGE' ||
620
- token.type === 'REF' ||
621
- token.type === 'RANGE' ||
622
- token.type === 'UNREFERENCED' ||
623
- token.type === 'INVALID_REF') {
624
- const expr = token.convert();
625
- stack.push(expr);
626
- }
627
- else if (token.type === 'POSTFIX_OPERATOR' && token.entity === '%') {
628
- const expr = stack.pop();
629
- if (!expr) {
630
- throw new FormulaError('#ERROR!', 'Missing expression before %');
631
- }
632
- const divideBy100 = new FunctionEntity('divide', 4, [expr, new ValueEntity(100)]);
633
- stack.push(divideBy100);
634
- }
635
- else if (token.type === 'FUNCTION') {
636
- this.index++;
637
- this.depth++;
638
- const func = token.convert();
639
- stack.push(func);
640
- // eslint-disable-next-line no-constant-condition
641
- while (true) {
642
- const { expr, hasNext } = this.parse(true);
643
- if (expr) {
644
- func.args.push(expr);
645
- }
646
- if (!hasNext) {
647
- break;
648
- }
649
- }
650
- }
651
- else if (token.type === 'OPEN') {
652
- this.depth++;
653
- const { expr } = this.parse(false);
654
- stack.push(expr);
655
- }
656
- else if (token.type === 'CLOSE') {
657
- if (this.depth-- === 0) {
658
- throw new FormulaError('#ERROR!', 'Unexpected end paren');
659
- }
660
- return complement();
661
- }
662
- else if (token.type === 'INFIX_OPERATOR') {
663
- const operator = token.convert();
664
- let left = stack.pop();
665
- if (left == null) {
666
- if (operator.name === 'minus' || operator.name === 'add') {
667
- left = ZERO;
668
- }
669
- else {
670
- throw new FormulaError('#ERROR!', 'Missing left expression');
671
- }
672
- }
673
- if (lastOperator == null) {
674
- operator.args.push(left);
675
- stack.unshift(operator);
676
- }
677
- else if (operator.precedence > lastOperator.precedence) {
678
- operator.args.push(left);
679
- lastOperator.args.push(operator);
680
- stack.unshift(lastOperator);
681
- }
682
- else {
683
- const outer = stack.shift();
684
- operator.args.push(outer);
685
- lastOperator.args.push(left);
686
- stack.unshift(operator);
687
- }
688
- lastOperator = operator;
689
- }
690
- else if (token.type === 'PREFIX_OPERATOR') {
691
- const operator = token.convert();
692
- if (lastOperator) {
693
- lastOperator.args.push(operator);
694
- }
695
- else {
696
- stack.unshift(operator);
697
- }
698
- lastOperator = operator;
699
- }
700
- }
701
- return complement();
702
- }
703
- }
704
- exports.Parser = Parser;
705
- const absolutizeFormula = ({ value, table, slideY = 0, slideX = 0, }) => {
706
- if (typeof value === 'string' || value instanceof String) {
707
- if (value.charAt(0) === '=') {
708
- const lexer = new Lexer(value.substring(1));
709
- lexer.tokenize();
710
- return '=' + lexer.stringifyToId(table, slideY, slideX);
711
- }
712
- }
713
- return value;
714
- };
715
- exports.absolutizeFormula = absolutizeFormula;
716
- const stripSheetName = (sheetName) => {
717
- if (sheetName.charAt(0) === "'") {
718
- sheetName = sheetName.slice(1);
719
- }
720
- if (sheetName.charAt(sheetName.length - 1) === "'") {
721
- sheetName = sheetName.slice(0, -1);
722
- }
723
- return sheetName;
724
- };
725
- exports.stripSheetName = stripSheetName;
726
- //# sourceMappingURL=evaluator.js.map