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