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