@dxos/plugin-sheet 0.6.12 → 0.6.13-main.548ca8d
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/dist/lib/browser/SheetContainer-NDNIS44E.mjs +265 -0
- package/dist/lib/browser/SheetContainer-NDNIS44E.mjs.map +7 -0
- package/dist/lib/browser/chunk-AQSGDA4X.mjs +1614 -0
- package/dist/lib/browser/chunk-AQSGDA4X.mjs.map +7 -0
- package/dist/lib/browser/chunk-D3QTX46O.mjs +14 -0
- package/dist/lib/browser/chunk-D3QTX46O.mjs.map +7 -0
- package/dist/lib/browser/chunk-GKI67SEF.mjs +69 -0
- package/dist/lib/browser/chunk-GKI67SEF.mjs.map +7 -0
- package/dist/lib/browser/chunk-GSV5QNLD.mjs +2966 -0
- package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +7 -0
- package/dist/lib/browser/graph-M4IQ76QX.mjs +33 -0
- package/dist/lib/browser/graph-M4IQ76QX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +93 -62
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +1 -1
- package/dist/lib/browser/types.mjs +4 -10
- package/dist/lib/node/SheetContainer-YSQGJD7K.cjs +276 -0
- package/dist/lib/node/SheetContainer-YSQGJD7K.cjs.map +7 -0
- package/dist/lib/node/{chunk-5KKJ4NPP.cjs → chunk-5XPK2V4A.cjs} +418 -678
- package/dist/lib/node/chunk-5XPK2V4A.cjs.map +7 -0
- package/dist/lib/node/chunk-6F43RV45.cjs +1610 -0
- package/dist/lib/node/chunk-6F43RV45.cjs.map +7 -0
- package/dist/lib/node/{chunk-DSYKOI4E.cjs → chunk-ER3PM7GD.cjs} +29 -45
- package/dist/lib/node/chunk-ER3PM7GD.cjs.map +7 -0
- package/dist/lib/node/chunk-QIFIGEKV.cjs +37 -0
- package/dist/lib/node/chunk-QIFIGEKV.cjs.map +7 -0
- package/dist/lib/node/graph-Q3N2X26H.cjs +55 -0
- package/dist/lib/node/graph-Q3N2X26H.cjs.map +7 -0
- package/dist/lib/node/index.cjs +105 -69
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.cjs +3 -3
- package/dist/lib/node/meta.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types.cjs +8 -14
- package/dist/lib/node/types.cjs.map +2 -2
- package/dist/lib/node-esm/SheetContainer-M7WRMZDU.mjs +266 -0
- package/dist/lib/node-esm/SheetContainer-M7WRMZDU.mjs.map +7 -0
- package/dist/lib/{browser/chunk-D5AGLXJP.mjs → node-esm/chunk-5WPZCXNS.mjs} +411 -678
- package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-ELTFPX5B.mjs +1615 -0
- package/dist/lib/node-esm/chunk-ELTFPX5B.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-VCYJWE3O.mjs +16 -0
- package/dist/lib/node-esm/chunk-VCYJWE3O.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-ZVLLQ2PJ.mjs +70 -0
- package/dist/lib/node-esm/chunk-ZVLLQ2PJ.mjs.map +7 -0
- package/dist/lib/node-esm/graph-SMPUMOV2.mjs +34 -0
- package/dist/lib/node-esm/graph-SMPUMOV2.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +280 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/meta.mjs +10 -0
- package/dist/lib/node-esm/meta.mjs.map +7 -0
- package/dist/lib/node-esm/types.mjs +17 -0
- package/dist/lib/node-esm/types.mjs.map +7 -0
- package/dist/types/src/SheetPlugin.d.ts.map +1 -1
- package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +11 -0
- package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/index.d.ts +1 -3
- package/dist/types/src/components/ComputeGraph/index.d.ts.map +1 -1
- package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts +3 -0
- package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +1 -0
- package/dist/types/src/components/FunctionEditor/index.d.ts +2 -0
- package/dist/types/src/components/FunctionEditor/index.d.ts.map +1 -0
- package/dist/types/src/components/GridSheet/GridSheet.d.ts +3 -0
- package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -0
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +9 -0
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -0
- package/dist/types/src/components/{CellEditor/CellEditor.stories.d.ts → GridSheet/SheetCellEditor.stories.d.ts} +4 -4
- package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +1 -0
- package/dist/types/src/components/GridSheet/index.d.ts +2 -0
- package/dist/types/src/components/GridSheet/index.d.ts.map +1 -0
- package/dist/types/src/components/GridSheet/util.d.ts +16 -0
- package/dist/types/src/components/GridSheet/util.d.ts.map +1 -0
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +6 -0
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -0
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +11 -0
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -0
- package/dist/types/src/components/SheetContainer/index.d.ts +3 -0
- package/dist/types/src/components/SheetContainer/index.d.ts.map +1 -0
- package/dist/types/src/components/SheetContext/SheetContext.d.ts +27 -0
- package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -0
- package/dist/types/src/components/SheetContext/index.d.ts +2 -0
- package/dist/types/src/components/SheetContext/index.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +36 -6
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +19 -14
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +3 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/defs/index.d.ts +3 -0
- package/dist/types/src/defs/index.d.ts.map +1 -0
- package/dist/types/src/{model → defs}/types.d.ts +8 -3
- package/dist/types/src/defs/types.d.ts.map +1 -0
- package/dist/types/src/defs/types.test.d.ts.map +1 -0
- package/dist/types/src/defs/util.d.ts +43 -0
- package/dist/types/src/defs/util.d.ts.map +1 -0
- package/dist/types/src/extensions/compute.d.ts +6 -0
- package/dist/types/src/extensions/compute.d.ts.map +1 -0
- package/dist/types/src/extensions/compute.stories.d.ts +26 -0
- package/dist/types/src/extensions/compute.stories.d.ts.map +1 -0
- package/dist/types/src/{components/CellEditor → extensions/editor}/extension.d.ts +1 -1
- package/dist/types/src/extensions/editor/extension.d.ts.map +1 -0
- package/dist/types/src/extensions/editor/extension.test.d.ts.map +1 -0
- package/dist/types/src/extensions/editor/index.d.ts +2 -0
- package/dist/types/src/extensions/editor/index.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +3 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -0
- package/dist/types/src/graph/compute-graph-registry.d.ts +34 -0
- package/dist/types/src/graph/compute-graph-registry.d.ts.map +1 -0
- package/dist/types/src/graph/compute-graph.d.ts +64 -0
- package/dist/types/src/graph/compute-graph.d.ts.map +1 -0
- package/dist/types/src/graph/compute-graph.stories.d.ts +10 -0
- package/dist/types/src/graph/compute-graph.stories.d.ts.map +1 -0
- package/dist/types/src/graph/compute-graph.test.d.ts +2 -0
- package/dist/types/src/graph/compute-graph.test.d.ts.map +1 -0
- package/dist/types/src/graph/compute-node.d.ts +26 -0
- package/dist/types/src/graph/compute-node.d.ts.map +1 -0
- package/dist/types/src/{components/ComputeGraph → graph/functions}/async-function.d.ts +14 -5
- package/dist/types/src/graph/functions/async-function.d.ts.map +1 -0
- package/dist/types/src/graph/functions/edge-function.d.ts +21 -0
- package/dist/types/src/graph/functions/edge-function.d.ts.map +1 -0
- package/dist/types/src/{model/functions.d.ts → graph/functions/function-defs.d.ts} +1 -1
- package/dist/types/src/graph/functions/function-defs.d.ts.map +1 -0
- package/dist/types/src/graph/functions/index.d.ts +4 -0
- package/dist/types/src/graph/functions/index.d.ts.map +1 -0
- package/dist/types/src/graph/hyperformula.test.d.ts +2 -0
- package/dist/types/src/graph/hyperformula.test.d.ts.map +1 -0
- package/dist/types/src/graph/index.d.ts +5 -0
- package/dist/types/src/graph/index.d.ts.map +1 -0
- package/dist/types/src/graph/testing/index.d.ts +3 -0
- package/dist/types/src/graph/testing/index.d.ts.map +1 -0
- package/dist/types/src/graph/testing/test-builder.d.ts +15 -0
- package/dist/types/src/graph/testing/test-builder.d.ts.map +1 -0
- package/dist/types/src/graph/testing/test-plugin.d.ts +36 -0
- package/dist/types/src/graph/testing/test-plugin.d.ts.map +1 -0
- package/dist/types/src/graph/util.d.ts +2 -0
- package/dist/types/src/graph/util.d.ts.map +1 -0
- package/dist/types/src/hooks/hooks.stories.d.ts +11 -0
- package/dist/types/src/hooks/hooks.stories.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +5 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/threads.d.ts +8 -0
- package/dist/types/src/hooks/threads.d.ts.map +1 -0
- package/dist/types/src/hooks/useComputeGraph.d.ts +7 -0
- package/dist/types/src/hooks/useComputeGraph.d.ts.map +1 -0
- package/dist/types/src/hooks/useFormattingModel.d.ts +3 -0
- package/dist/types/src/hooks/useFormattingModel.d.ts.map +1 -0
- package/dist/types/src/hooks/useSheetModel.d.ts +8 -0
- package/dist/types/src/hooks/useSheetModel.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +3 -9
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/model/decorations.d.ts +25 -0
- package/dist/types/src/model/decorations.d.ts.map +1 -0
- package/dist/types/src/model/formatting-model.d.ts +19 -0
- package/dist/types/src/model/formatting-model.d.ts.map +1 -0
- package/dist/types/src/model/index.d.ts +3 -3
- package/dist/types/src/model/index.d.ts.map +1 -1
- package/dist/types/src/model/{model.d.ts → sheet-model.d.ts} +13 -67
- package/dist/types/src/model/sheet-model.d.ts.map +1 -0
- package/dist/types/src/model/sheet-model.test.d.ts +2 -0
- package/dist/types/src/model/sheet-model.test.d.ts.map +1 -0
- package/dist/types/src/sanity.test.d.ts +2 -0
- package/dist/types/src/sanity.test.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/testing.d.ts +8 -0
- package/dist/types/src/testing/testing.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +17 -12
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +98 -32
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/vendor/hyperformula.mjs +37145 -0
- package/package.json +57 -52
- package/src/SheetPlugin.tsx +52 -74
- package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +20 -0
- package/src/components/ComputeGraph/index.ts +1 -3
- package/src/components/FunctionEditor/FunctionEditor.tsx +45 -0
- package/src/components/FunctionEditor/index.ts +5 -0
- package/src/components/GridSheet/GridSheet.stories.tsx +41 -0
- package/src/components/GridSheet/GridSheet.tsx +161 -0
- package/src/components/{CellEditor/CellEditor.stories.tsx → GridSheet/SheetCellEditor.stories.tsx} +8 -8
- package/src/components/GridSheet/index.ts +5 -0
- package/src/components/GridSheet/util.ts +144 -0
- package/src/components/SheetContainer/SheetContainer.stories.tsx +40 -0
- package/src/components/SheetContainer/SheetContainer.tsx +52 -0
- package/src/components/SheetContainer/index.ts +7 -0
- package/src/components/SheetContext/SheetContext.tsx +108 -0
- package/src/components/SheetContext/index.ts +5 -0
- package/src/components/Toolbar/Toolbar.tsx +167 -85
- package/src/components/index.ts +2 -0
- package/src/defs/index.ts +6 -0
- package/src/{model → defs}/types.test.ts +8 -9
- package/src/{model → defs}/types.ts +24 -14
- package/src/defs/util.ts +151 -0
- package/src/extensions/compute.stories.tsx +151 -0
- package/src/extensions/compute.ts +147 -0
- package/src/{components/CellEditor → extensions/editor}/extension.test.ts +4 -6
- package/src/{components/CellEditor → extensions/editor}/extension.ts +5 -6
- package/src/{components/CellEditor → extensions/editor}/index.ts +0 -1
- package/src/extensions/index.ts +6 -0
- package/src/graph/compute-graph-registry.ts +90 -0
- package/src/graph/compute-graph.stories.tsx +93 -0
- package/src/graph/compute-graph.test.ts +87 -0
- package/src/graph/compute-graph.ts +242 -0
- package/src/graph/compute-node.ts +63 -0
- package/src/{components/ComputeGraph → graph/functions}/async-function.ts +25 -15
- package/src/{components/ComputeGraph → graph/functions}/edge-function.ts +16 -14
- package/src/graph/functions/index.ts +7 -0
- package/src/graph/hyperformula.test.ts +14 -0
- package/src/graph/index.ts +8 -0
- package/src/graph/testing/index.ts +6 -0
- package/src/graph/testing/test-builder.ts +54 -0
- package/src/{components/ComputeGraph/custom.ts → graph/testing/test-plugin.ts} +44 -14
- package/src/graph/util.ts +8 -0
- package/src/hooks/hooks.stories.tsx +50 -0
- package/src/hooks/index.ts +8 -0
- package/src/hooks/threads.ts +147 -0
- package/src/hooks/useComputeGraph.ts +28 -0
- package/src/hooks/useFormattingModel.ts +11 -0
- package/src/hooks/useSheetModel.ts +40 -0
- package/src/meta.ts +14 -0
- package/src/model/decorations.ts +64 -0
- package/src/{components/Sheet/formatting.ts → model/formatting-model.ts} +30 -20
- package/src/model/index.ts +3 -3
- package/src/model/sheet-model.test.ts +57 -0
- package/src/model/sheet-model.ts +418 -0
- package/src/sanity.test.ts +40 -0
- package/src/{components/Sheet → testing}/index.ts +1 -1
- package/src/testing/testing.tsx +68 -0
- package/src/translations.ts +6 -1
- package/src/types.ts +40 -41
- package/dist/lib/browser/SheetContainer-U4H5D34A.mjs +0 -1772
- package/dist/lib/browser/SheetContainer-U4H5D34A.mjs.map +0 -7
- package/dist/lib/browser/chunk-APHOLYUB.mjs +0 -175
- package/dist/lib/browser/chunk-APHOLYUB.mjs.map +0 -7
- package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +0 -7
- package/dist/lib/browser/chunk-FUAGSXA4.mjs +0 -82
- package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +0 -7
- package/dist/lib/browser/chunk-JRL5LGCE.mjs +0 -18
- package/dist/lib/browser/chunk-JRL5LGCE.mjs.map +0 -7
- package/dist/lib/browser/chunk-NU4PBN33.mjs +0 -8
- package/dist/lib/browser/chunk-NU4PBN33.mjs.map +0 -7
- package/dist/lib/browser/testing.mjs +0 -92
- package/dist/lib/browser/testing.mjs.map +0 -7
- package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs +0 -1765
- package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +0 -7
- package/dist/lib/node/chunk-5KKJ4NPP.cjs.map +0 -7
- package/dist/lib/node/chunk-BJ6ZD7MN.cjs +0 -51
- package/dist/lib/node/chunk-BJ6ZD7MN.cjs.map +0 -7
- package/dist/lib/node/chunk-CN3RPESU.cjs +0 -202
- package/dist/lib/node/chunk-CN3RPESU.cjs.map +0 -7
- package/dist/lib/node/chunk-DSYKOI4E.cjs.map +0 -7
- package/dist/lib/node/chunk-PYXHNAAK.cjs +0 -40
- package/dist/lib/node/chunk-PYXHNAAK.cjs.map +0 -7
- package/dist/lib/node/testing.cjs +0 -111
- package/dist/lib/node/testing.cjs.map +0 -7
- package/dist/types/src/components/CellEditor/CellEditor.d.ts +0 -14
- package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +0 -1
- package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +0 -1
- package/dist/types/src/components/CellEditor/extension.d.ts.map +0 -1
- package/dist/types/src/components/CellEditor/extension.test.d.ts.map +0 -1
- package/dist/types/src/components/CellEditor/index.d.ts +0 -3
- package/dist/types/src/components/CellEditor/index.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/custom.d.ts +0 -21
- package/dist/types/src/components/ComputeGraph/custom.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/edge-function.d.ts +0 -20
- package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/graph-context.d.ts +0 -12
- package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts +0 -2
- package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/graph.d.ts +0 -26
- package/dist/types/src/components/ComputeGraph/graph.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/Sheet.d.ts +0 -55
- package/dist/types/src/components/Sheet/Sheet.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/Sheet.stories.d.ts +0 -54
- package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/formatting.d.ts +0 -14
- package/dist/types/src/components/Sheet/formatting.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/grid.d.ts +0 -52
- package/dist/types/src/components/Sheet/grid.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/index.d.ts +0 -2
- package/dist/types/src/components/Sheet/index.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/nav.d.ts +0 -29
- package/dist/types/src/components/Sheet/nav.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/sheet-context.d.ts +0 -25
- package/dist/types/src/components/Sheet/sheet-context.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/util.d.ts +0 -18
- package/dist/types/src/components/Sheet/util.d.ts.map +0 -1
- package/dist/types/src/components/SheetContainer.d.ts +0 -9
- package/dist/types/src/components/SheetContainer.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/common.d.ts +0 -20
- package/dist/types/src/components/Toolbar/common.d.ts.map +0 -1
- package/dist/types/src/model/functions.d.ts.map +0 -1
- package/dist/types/src/model/model.browser.test.d.ts +0 -2
- package/dist/types/src/model/model.browser.test.d.ts.map +0 -1
- package/dist/types/src/model/model.d.ts.map +0 -1
- package/dist/types/src/model/types.d.ts.map +0 -1
- package/dist/types/src/model/types.test.d.ts.map +0 -1
- package/dist/types/src/model/util.d.ts +0 -15
- package/dist/types/src/model/util.d.ts.map +0 -1
- package/dist/types/src/testing.d.ts +0 -9
- package/dist/types/src/testing.d.ts.map +0 -1
- package/src/components/CellEditor/CellEditor.tsx +0 -113
- package/src/components/ComputeGraph/graph-context.tsx +0 -50
- package/src/components/ComputeGraph/graph.browser.test.ts +0 -50
- package/src/components/ComputeGraph/graph.ts +0 -62
- package/src/components/Sheet/Sheet.stories.tsx +0 -287
- package/src/components/Sheet/Sheet.tsx +0 -1160
- package/src/components/Sheet/grid.ts +0 -191
- package/src/components/Sheet/nav.ts +0 -157
- package/src/components/Sheet/sheet-context.tsx +0 -150
- package/src/components/Sheet/util.ts +0 -56
- package/src/components/SheetContainer.tsx +0 -34
- package/src/components/Toolbar/common.tsx +0 -72
- package/src/meta.tsx +0 -18
- package/src/model/model.browser.test.ts +0 -100
- package/src/model/model.ts +0 -550
- package/src/model/util.ts +0 -36
- package/src/testing.ts +0 -50
- /package/dist/types/src/{model → defs}/types.test.d.ts +0 -0
- /package/dist/types/src/{components/CellEditor → extensions/editor}/extension.test.d.ts +0 -0
- /package/src/{model/functions.ts → graph/functions/function-defs.ts} +0 -0
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { expect } from 'chai';
|
|
6
|
-
import { describe, test } from 'vitest';
|
|
7
|
-
|
|
8
|
-
import { SheetModel } from './model';
|
|
9
|
-
import { addressFromA1Notation, rangeFromA1Notation } from './types';
|
|
10
|
-
import { createComputeGraph } from '../components';
|
|
11
|
-
import { createSheet, ValueTypeEnum } from '../types';
|
|
12
|
-
|
|
13
|
-
// TODO(burdon): Test undo (e.g., clear cells).
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* VITEST_ENV=chrome p vitest --watch
|
|
17
|
-
* NOTE: Browser test required for hyperformula due to raw translation files.
|
|
18
|
-
*/
|
|
19
|
-
describe('model', () => {
|
|
20
|
-
const createModel = async () => {
|
|
21
|
-
const graph = createComputeGraph();
|
|
22
|
-
const sheet = createSheet();
|
|
23
|
-
const model = new SheetModel(graph, sheet, undefined, { rows: 5, columns: 5 });
|
|
24
|
-
await model.initialize();
|
|
25
|
-
return model;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
test('create', async () => {
|
|
29
|
-
const model = await createModel();
|
|
30
|
-
expect(model.bounds).to.deep.eq({ rows: 5, columns: 5 });
|
|
31
|
-
model.setValue(addressFromA1Notation('A1'), 100);
|
|
32
|
-
const value = model.getValue(addressFromA1Notation('A1'));
|
|
33
|
-
expect(value).to.eq(100);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('map formula', async () => {
|
|
37
|
-
const model = await createModel();
|
|
38
|
-
const x1 = model.mapFormulaRefsToIndices('=SUM(A1:A3)');
|
|
39
|
-
const x2 = model.mapFormulaIndicesToRefs(x1);
|
|
40
|
-
expect(x2).to.eq('=SUM(A1:A3)');
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
test('dates', async () => {
|
|
44
|
-
const model = await createModel();
|
|
45
|
-
const cell = addressFromA1Notation('A1');
|
|
46
|
-
model.setValue(cell, '=NOW()');
|
|
47
|
-
const type = model.getValueType(cell);
|
|
48
|
-
expect(type).to.eq(ValueTypeEnum.DateTime);
|
|
49
|
-
const value = model.getValue(cell);
|
|
50
|
-
const date = model.toLocalDate(value as number);
|
|
51
|
-
const now = new Date();
|
|
52
|
-
expect(date.getUTCFullYear()).to.eq(now.getUTCFullYear());
|
|
53
|
-
expect(date.getUTCMonth()).to.eq(now.getUTCMonth());
|
|
54
|
-
expect(date.getUTCDate()).to.eq(now.getUTCDate());
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
test('formula', async () => {
|
|
58
|
-
const model = await createModel();
|
|
59
|
-
|
|
60
|
-
// Nested formula.
|
|
61
|
-
{
|
|
62
|
-
model.setValue(addressFromA1Notation('A1'), 100);
|
|
63
|
-
model.setValue(addressFromA1Notation('A2'), 200);
|
|
64
|
-
model.setValue(addressFromA1Notation('A3'), '=SUM(A1:A2)');
|
|
65
|
-
model.setValue(addressFromA1Notation('A4'), '=SUM(A1:A3)');
|
|
66
|
-
const value = model.getValue(addressFromA1Notation('A4'));
|
|
67
|
-
expect(value).to.eq(600);
|
|
68
|
-
// console.log(JSON.stringify(model.sheet.cells, undefined, 2));
|
|
69
|
-
|
|
70
|
-
const cells = model.getCellValues(rangeFromA1Notation('A1:A4'));
|
|
71
|
-
expect(cells).to.deep.eq([
|
|
72
|
-
[100],
|
|
73
|
-
[200],
|
|
74
|
-
[model.mapFormulaRefsToIndices('=SUM(A1:A2)')],
|
|
75
|
-
[model.mapFormulaRefsToIndices('=SUM(A1:A3)')],
|
|
76
|
-
]);
|
|
77
|
-
// console.log(JSON.stringify(model.sheet.cells, undefined, 2));
|
|
78
|
-
// console.log(cells);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Insert row.
|
|
82
|
-
{
|
|
83
|
-
model.insertRows(2, 1);
|
|
84
|
-
model.setValue(addressFromA1Notation('A3'), 400);
|
|
85
|
-
const value = model.getValue(addressFromA1Notation('A5'));
|
|
86
|
-
expect(value).to.eq(1000);
|
|
87
|
-
|
|
88
|
-
const cells = model.getCellValues(rangeFromA1Notation('A1:A5'));
|
|
89
|
-
expect(cells).to.deep.eq([
|
|
90
|
-
[100],
|
|
91
|
-
[200],
|
|
92
|
-
[400],
|
|
93
|
-
[model.mapFormulaRefsToIndices('=SUM(A1:A2)')],
|
|
94
|
-
[model.mapFormulaRefsToIndices('=SUM(A1:A4)')],
|
|
95
|
-
]);
|
|
96
|
-
// console.log(JSON.stringify(model.sheet.cells, undefined, 2));
|
|
97
|
-
// console.log(cells);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
});
|
package/src/model/model.ts
DELETED
|
@@ -1,550 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { DetailedCellError, ExportedCellChange } from 'hyperformula';
|
|
6
|
-
import { type SimpleCellRange } from 'hyperformula/typings/AbsoluteCellRange';
|
|
7
|
-
import { type SimpleCellAddress } from 'hyperformula/typings/Cell';
|
|
8
|
-
import { type SimpleDate, type SimpleDateTime } from 'hyperformula/typings/DateTimeHelper';
|
|
9
|
-
|
|
10
|
-
import { Event } from '@dxos/async';
|
|
11
|
-
import { type Space } from '@dxos/client/echo';
|
|
12
|
-
import { Context } from '@dxos/context';
|
|
13
|
-
import { invariant } from '@dxos/invariant';
|
|
14
|
-
import { PublicKey } from '@dxos/keys';
|
|
15
|
-
import { log } from '@dxos/log';
|
|
16
|
-
import { type FunctionType } from '@dxos/plugin-script/types';
|
|
17
|
-
|
|
18
|
-
import { defaultFunctions, type FunctionDefinition } from './functions';
|
|
19
|
-
import { addressFromA1Notation, addressToA1Notation, type CellAddress, type CellRange } from './types';
|
|
20
|
-
import { createIndices, RangeException, ReadonlyException } from './util';
|
|
21
|
-
import { type ComputeGraph } from '../components';
|
|
22
|
-
import { type CellScalarValue, type CellValue, type SheetType, ValueTypeEnum } from '../types';
|
|
23
|
-
|
|
24
|
-
const DEFAULT_ROWS = 100;
|
|
25
|
-
const DEFAULT_COLUMNS = 26;
|
|
26
|
-
|
|
27
|
-
export type CellIndex = string;
|
|
28
|
-
|
|
29
|
-
export type CellContentValue = number | string | boolean | null;
|
|
30
|
-
|
|
31
|
-
export type SheetModelOptions = {
|
|
32
|
-
readonly?: boolean;
|
|
33
|
-
rows: number;
|
|
34
|
-
columns: number;
|
|
35
|
-
mapFormulaBindingToId: (functions: FunctionType[]) => (formula: string) => string;
|
|
36
|
-
mapFormulaBindingFromId: (functions: FunctionType[]) => (formula: string) => string;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const typeMap: Record<string, ValueTypeEnum> = {
|
|
40
|
-
BOOLEAN: ValueTypeEnum.Boolean,
|
|
41
|
-
NUMBER_RAW: ValueTypeEnum.Number,
|
|
42
|
-
NUMBER_PERCENT: ValueTypeEnum.Percent,
|
|
43
|
-
NUMBER_CURRENCY: ValueTypeEnum.Currency,
|
|
44
|
-
NUMBER_DATETIME: ValueTypeEnum.DateTime,
|
|
45
|
-
NUMBER_DATE: ValueTypeEnum.Date,
|
|
46
|
-
NUMBER_TIME: ValueTypeEnum.Time,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export const defaultOptions: SheetModelOptions = {
|
|
50
|
-
rows: 50,
|
|
51
|
-
columns: 26,
|
|
52
|
-
mapFormulaBindingFromId: () => (formula) => formula,
|
|
53
|
-
mapFormulaBindingToId: () => (formula) => formula,
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const getTopLeft = (range: CellRange) => {
|
|
57
|
-
const to = range.to ?? range.from;
|
|
58
|
-
return { row: Math.min(range.from.row, to.row), column: Math.min(range.from.column, to.column) };
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const toSimpleCellAddress = (sheet: number, cell: CellAddress): SimpleCellAddress => ({
|
|
62
|
-
sheet,
|
|
63
|
-
row: cell.row,
|
|
64
|
-
col: cell.column,
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
const toModelRange = (sheet: number, range: CellRange): SimpleCellRange => ({
|
|
68
|
-
start: toSimpleCellAddress(sheet, range.from),
|
|
69
|
-
end: toSimpleCellAddress(sheet, range.to ?? range.from),
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Spreadsheet data model.
|
|
74
|
-
*
|
|
75
|
-
* [ComputeGraphContext] > [SheetContext]:[SheetModel] > [Sheet.Root]
|
|
76
|
-
*/
|
|
77
|
-
export class SheetModel {
|
|
78
|
-
public readonly id = `model-${PublicKey.random().truncate()}`;
|
|
79
|
-
private _ctx?: Context = undefined;
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Formula engine.
|
|
83
|
-
* Acts as a write through cache for scalar and computed values.
|
|
84
|
-
*/
|
|
85
|
-
private readonly _sheetId: number;
|
|
86
|
-
private readonly _options: SheetModelOptions;
|
|
87
|
-
private _functions: FunctionType[] = [];
|
|
88
|
-
|
|
89
|
-
public readonly update = new Event();
|
|
90
|
-
|
|
91
|
-
constructor(
|
|
92
|
-
private readonly _graph: ComputeGraph,
|
|
93
|
-
private readonly _sheet: SheetType,
|
|
94
|
-
private readonly _space?: Space,
|
|
95
|
-
options: Partial<SheetModelOptions> = {},
|
|
96
|
-
) {
|
|
97
|
-
// Sheet for this object.
|
|
98
|
-
const name = this._sheet.id;
|
|
99
|
-
if (!this._graph.hf.doesSheetExist(name)) {
|
|
100
|
-
this._graph.hf.addSheet(name);
|
|
101
|
-
}
|
|
102
|
-
this._sheetId = this._graph.hf.getSheetId(name)!;
|
|
103
|
-
this._options = { ...defaultOptions, ...options };
|
|
104
|
-
this.reset();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
get graph() {
|
|
108
|
-
return this._graph;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
get sheet() {
|
|
112
|
-
return this._sheet;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
get readonly() {
|
|
116
|
-
return this._options.readonly;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
get bounds() {
|
|
120
|
-
return {
|
|
121
|
-
rows: this._sheet.rows.length,
|
|
122
|
-
columns: this._sheet.columns.length,
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
get functions(): FunctionDefinition[] {
|
|
127
|
-
const hfFunctions = this._graph.hf
|
|
128
|
-
.getRegisteredFunctionNames()
|
|
129
|
-
.map((name) => defaultFunctions.find((fn) => fn.name === name) ?? { name });
|
|
130
|
-
const echoFunctions = this._functions.map((fn) => ({ name: fn.binding! }));
|
|
131
|
-
return [...hfFunctions, ...echoFunctions];
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
get initialized(): boolean {
|
|
135
|
-
return !!this._ctx;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Initialize sheet and engine.
|
|
140
|
-
*/
|
|
141
|
-
async initialize() {
|
|
142
|
-
log('initialize', { id: this.id });
|
|
143
|
-
invariant(!this.initialized, 'Already initialized.');
|
|
144
|
-
this._ctx = new Context();
|
|
145
|
-
if (!this._sheet.rows.length) {
|
|
146
|
-
this._insertIndices(this._sheet.rows, 0, this._options.rows, DEFAULT_ROWS);
|
|
147
|
-
}
|
|
148
|
-
if (!this._sheet.columns.length) {
|
|
149
|
-
this._insertIndices(this._sheet.columns, 0, this._options.columns, DEFAULT_COLUMNS);
|
|
150
|
-
}
|
|
151
|
-
this.reset();
|
|
152
|
-
|
|
153
|
-
// Listen for model updates (e.g., async calculations).
|
|
154
|
-
const unsubscribe = this._graph.update.on(() => this.update.emit());
|
|
155
|
-
this._ctx.onDispose(unsubscribe);
|
|
156
|
-
|
|
157
|
-
if (this._space) {
|
|
158
|
-
const { Filter } = await import('@dxos/client/echo');
|
|
159
|
-
const { FunctionType } = await import('@dxos/plugin-script/types');
|
|
160
|
-
|
|
161
|
-
// Listen for function changes.
|
|
162
|
-
const query = this._space?.db.query(Filter.schema(FunctionType));
|
|
163
|
-
const unsubscribe = query.subscribe(({ objects }) => {
|
|
164
|
-
this._functions = objects.filter((fn) => fn.binding);
|
|
165
|
-
this.update.emit();
|
|
166
|
-
});
|
|
167
|
-
this._ctx.onDispose(unsubscribe);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return this;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
async destroy() {
|
|
174
|
-
log('destroy', { id: this.id });
|
|
175
|
-
if (this._ctx) {
|
|
176
|
-
await this._ctx.dispose();
|
|
177
|
-
this._ctx = undefined;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Update engine.
|
|
183
|
-
* NOTE: This resets the undo history.
|
|
184
|
-
* @deprecated
|
|
185
|
-
*/
|
|
186
|
-
reset() {
|
|
187
|
-
this._graph.hf.clearSheet(this._sheetId);
|
|
188
|
-
Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
|
|
189
|
-
const { column, row } = this.addressFromIndex(key);
|
|
190
|
-
if (typeof value === 'string' && value.charAt(0) === '=') {
|
|
191
|
-
value = this.mapFormulaBindingToFormula(this.mapFormulaBindingFromId(this.mapFormulaIndicesToRefs(value)));
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
this._graph.hf.setCellContents({ sheet: this._sheetId, row, col: column }, value);
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* Recalculate formulas.
|
|
200
|
-
* NOTE: This resets the undo history.
|
|
201
|
-
* https://hyperformula.handsontable.com/guide/volatile-functions.html#volatile-actions
|
|
202
|
-
* @deprecated
|
|
203
|
-
*/
|
|
204
|
-
// TODO(burdon): Remove.
|
|
205
|
-
recalculate() {
|
|
206
|
-
this._graph.hf.rebuildAndRecalculate();
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
insertRows(i: number, n = 1) {
|
|
210
|
-
this._insertIndices(this._sheet.rows, i, n, DEFAULT_ROWS);
|
|
211
|
-
this.reset();
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
insertColumns(i: number, n = 1) {
|
|
215
|
-
this._insertIndices(this._sheet.columns, i, n, DEFAULT_COLUMNS);
|
|
216
|
-
this.reset();
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
//
|
|
220
|
-
// Undoable actions.
|
|
221
|
-
// TODO(burdon): Group undoable methods; consistently update hf/sheet.
|
|
222
|
-
//
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Clear range of values.
|
|
226
|
-
*/
|
|
227
|
-
clear(range: CellRange) {
|
|
228
|
-
const topLeft = getTopLeft(range);
|
|
229
|
-
const values = this._iterRange(range, () => null);
|
|
230
|
-
this._graph.hf.setCellContents(toSimpleCellAddress(this._sheetId, topLeft), values);
|
|
231
|
-
this._iterRange(range, (cell) => {
|
|
232
|
-
const idx = this.addressToIndex(cell);
|
|
233
|
-
delete this._sheet.cells[idx];
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
cut(range: CellRange) {
|
|
238
|
-
this._graph.hf.cut(toModelRange(this._sheetId, range));
|
|
239
|
-
this._iterRange(range, (cell) => {
|
|
240
|
-
const idx = this.addressToIndex(cell);
|
|
241
|
-
delete this._sheet.cells[idx];
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
copy(range: CellRange) {
|
|
246
|
-
this._graph.hf.copy(toModelRange(this._sheetId, range));
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
paste(cell: CellAddress) {
|
|
250
|
-
if (!this._graph.hf.isClipboardEmpty()) {
|
|
251
|
-
const changes = this._graph.hf.paste(toSimpleCellAddress(this._sheetId, cell));
|
|
252
|
-
for (const change of changes) {
|
|
253
|
-
if (change instanceof ExportedCellChange) {
|
|
254
|
-
const { address, newValue } = change;
|
|
255
|
-
const idx = this.addressToIndex({ row: address.row, column: address.col });
|
|
256
|
-
this._sheet.cells[idx] = { value: newValue };
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
// TODO(burdon): Display undo/redo state.
|
|
263
|
-
undo() {
|
|
264
|
-
if (this._graph.hf.isThereSomethingToUndo()) {
|
|
265
|
-
this._graph.hf.undo();
|
|
266
|
-
this.update.emit();
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
redo() {
|
|
271
|
-
if (this._graph.hf.isThereSomethingToRedo()) {
|
|
272
|
-
this._graph.hf.redo();
|
|
273
|
-
this.update.emit();
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Get value from sheet.
|
|
279
|
-
*/
|
|
280
|
-
getCellValue(cell: CellAddress): CellScalarValue {
|
|
281
|
-
const idx = this.addressToIndex(cell);
|
|
282
|
-
return this._sheet.cells[idx]?.value ?? null;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Get value as a string for editing.
|
|
287
|
-
*/
|
|
288
|
-
getCellText(cell: CellAddress): string | undefined {
|
|
289
|
-
const value = this.getCellValue(cell);
|
|
290
|
-
if (value == null) {
|
|
291
|
-
return undefined;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
if (typeof value === 'string' && value.charAt(0) === '=') {
|
|
295
|
-
return this.mapFormulaBindingFromId(this.mapFormulaIndicesToRefs(value));
|
|
296
|
-
} else {
|
|
297
|
-
return String(value);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Get array of raw values from sheet.
|
|
303
|
-
*/
|
|
304
|
-
getCellValues(range: CellRange): CellScalarValue[][] {
|
|
305
|
-
return this._iterRange(range, (cell) => this.getCellValue(cell));
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* Gets the regular or computed value from the engine.
|
|
310
|
-
*/
|
|
311
|
-
getValue(cell: CellAddress): CellScalarValue {
|
|
312
|
-
// Applies rounding and post-processing.
|
|
313
|
-
const value = this._graph.hf.getCellValue(toSimpleCellAddress(this._sheetId, cell));
|
|
314
|
-
if (value instanceof DetailedCellError) {
|
|
315
|
-
return value.toString();
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
return value;
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* Get value type.
|
|
323
|
-
*/
|
|
324
|
-
getValueType(cell: CellAddress): ValueTypeEnum {
|
|
325
|
-
const addr = toSimpleCellAddress(this._sheetId, cell);
|
|
326
|
-
const type = this._graph.hf.getCellValueDetailedType(addr);
|
|
327
|
-
return typeMap[type];
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* Sets the value, updating the sheet and engine.
|
|
332
|
-
*/
|
|
333
|
-
setValue(cell: CellAddress, value: CellScalarValue) {
|
|
334
|
-
if (this._options.readonly) {
|
|
335
|
-
throw new ReadonlyException();
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// Reallocate if > current bounds.
|
|
339
|
-
let refresh = false;
|
|
340
|
-
if (cell.row >= this._sheet.rows.length) {
|
|
341
|
-
this._insertIndices(this._sheet.rows, cell.row, 1, DEFAULT_ROWS);
|
|
342
|
-
refresh = true;
|
|
343
|
-
}
|
|
344
|
-
if (cell.column >= this._sheet.columns.length) {
|
|
345
|
-
this._insertIndices(this._sheet.columns, cell.column, 1, DEFAULT_COLUMNS);
|
|
346
|
-
refresh = true;
|
|
347
|
-
}
|
|
348
|
-
if (refresh) {
|
|
349
|
-
// TODO(burdon): Remove.
|
|
350
|
-
this.reset();
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// Insert into engine.
|
|
354
|
-
this._graph.hf.setCellContents({ sheet: this._sheetId, row: cell.row, col: cell.column }, [
|
|
355
|
-
[typeof value === 'string' && value.charAt(0) === '=' ? this.mapFormulaBindingToFormula(value) : value],
|
|
356
|
-
]);
|
|
357
|
-
|
|
358
|
-
// Insert into sheet.
|
|
359
|
-
const idx = this.addressToIndex(cell);
|
|
360
|
-
if (value === undefined || value === null) {
|
|
361
|
-
delete this._sheet.cells[idx];
|
|
362
|
-
} else {
|
|
363
|
-
if (typeof value === 'string' && value.charAt(0) === '=') {
|
|
364
|
-
value = this.mapFormulaBindingToId(this.mapFormulaRefsToIndices(value));
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
this._sheet.cells[idx] = { value };
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Sets values from a simple map.
|
|
373
|
-
*/
|
|
374
|
-
setValues(values: Record<string, CellValue>) {
|
|
375
|
-
Object.entries(values).forEach(([key, { value }]) => {
|
|
376
|
-
this.setValue(addressFromA1Notation(key), value);
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Iterate range.
|
|
382
|
-
*/
|
|
383
|
-
private _iterRange(range: CellRange, cb: (cell: CellAddress) => CellScalarValue | void): CellScalarValue[][] {
|
|
384
|
-
const to = range.to ?? range.from;
|
|
385
|
-
const rowRange = [Math.min(range.from.row, to.row), Math.max(range.from.row, to.row)];
|
|
386
|
-
const columnRange = [Math.min(range.from.column, to.column), Math.max(range.from.column, to.column)];
|
|
387
|
-
const rows: CellScalarValue[][] = [];
|
|
388
|
-
for (let row = rowRange[0]; row <= rowRange[1]; row++) {
|
|
389
|
-
const rowCells: CellScalarValue[] = [];
|
|
390
|
-
for (let column = columnRange[0]; column <= columnRange[1]; column++) {
|
|
391
|
-
const value = cb({ row, column });
|
|
392
|
-
if (value !== undefined) {
|
|
393
|
-
rowCells.push(value);
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
rows.push(rowCells);
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
return rows;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
*
|
|
404
|
-
*/
|
|
405
|
-
// TODO(burdon): Insert indices into sheet.
|
|
406
|
-
private _insertIndices(indices: string[], i: number, n: number, max: number) {
|
|
407
|
-
if (i + n > max) {
|
|
408
|
-
throw new RangeException(i + n);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
const idx = createIndices(n);
|
|
412
|
-
indices.splice(i, 0, ...idx);
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
// TODO(burdon): Delete index.
|
|
416
|
-
private _deleteIndices(indices: string[], i: number, n: number) {
|
|
417
|
-
throw new Error('Not implemented');
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
// TODO(burdon): Move. Cannot use fractional without changing. Switch back to using unique IDs?
|
|
421
|
-
private _moveIndices(indices: string[], i: number, j: number, n: number) {
|
|
422
|
-
throw new Error('Not implemented');
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
//
|
|
426
|
-
// Indices.
|
|
427
|
-
//
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
* E.g., "A1" => "x1@y1".
|
|
431
|
-
*/
|
|
432
|
-
addressToIndex(cell: CellAddress): CellIndex {
|
|
433
|
-
return `${this._sheet.columns[cell.column]}@${this._sheet.rows[cell.row]}`;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
/**
|
|
437
|
-
* E.g., "x1@y1" => "A1".
|
|
438
|
-
*/
|
|
439
|
-
addressFromIndex(idx: CellIndex): CellAddress {
|
|
440
|
-
const [column, row] = idx.split('@');
|
|
441
|
-
return {
|
|
442
|
-
column: this._sheet.columns.indexOf(column),
|
|
443
|
-
row: this._sheet.rows.indexOf(row),
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* E.g., "A1:B2" => "x1@y1:x2@y2".
|
|
449
|
-
*/
|
|
450
|
-
rangeToIndex(range: CellRange): string {
|
|
451
|
-
return [range.from, range.to ?? range.from].map((cell) => this.addressToIndex(cell)).join(':');
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
/**
|
|
455
|
-
* E.g., "x1@y1:x2@y2" => "A1:B2".
|
|
456
|
-
*/
|
|
457
|
-
rangeFromIndex(idx: string): CellRange {
|
|
458
|
-
const [from, to] = idx.split(':').map((idx) => this.addressFromIndex(idx));
|
|
459
|
-
return { from, to };
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
/**
|
|
463
|
-
* E.g., "HELLO()" => "EDGE("HELLO")".
|
|
464
|
-
*/
|
|
465
|
-
mapFormulaBindingToFormula(formula: string): string {
|
|
466
|
-
return formula.replace(/([a-zA-Z0-9]+)\((.*)\)/g, (match, binding, args) => {
|
|
467
|
-
const fn = this._functions.find((fn) => fn.binding === binding);
|
|
468
|
-
if (!fn) {
|
|
469
|
-
return match;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
if (args.trim() === '') {
|
|
473
|
-
return `EDGE("${binding}")`;
|
|
474
|
-
}
|
|
475
|
-
return `EDGE("${binding}", ${args})`;
|
|
476
|
-
});
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* E.g., "EDGE("HELLO")" => "HELLO()".
|
|
481
|
-
*/
|
|
482
|
-
mapFormulaBindingFromFormula(formula: string): string {
|
|
483
|
-
return formula.replace(/EDGE\("([a-zA-Z0-9]+)"(.*)\)/, (_match, binding, args) => {
|
|
484
|
-
if (args.trim() === '') {
|
|
485
|
-
return `${binding}()`;
|
|
486
|
-
}
|
|
487
|
-
return `${binding}(${args.slice(2)})`;
|
|
488
|
-
});
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
/**
|
|
492
|
-
* Map from binding to fully qualified ECHO ID.
|
|
493
|
-
*/
|
|
494
|
-
mapFormulaBindingToId(formula: string): string {
|
|
495
|
-
return this._options.mapFormulaBindingToId(this._functions)(formula);
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
/**
|
|
499
|
-
* Map from fully qualified ECHO ID to binding.
|
|
500
|
-
*/
|
|
501
|
-
mapFormulaBindingFromId(formula: string): string {
|
|
502
|
-
return this._options.mapFormulaBindingFromId(this._functions)(formula);
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* Map from A1 notation to indices.
|
|
507
|
-
*/
|
|
508
|
-
mapFormulaRefsToIndices(formula: string): string {
|
|
509
|
-
invariant(formula.charAt(0) === '=');
|
|
510
|
-
return formula.replace(/([a-zA-Z]+)([0-9]+)/g, (match) => {
|
|
511
|
-
return this.addressToIndex(addressFromA1Notation(match));
|
|
512
|
-
});
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
/**
|
|
516
|
-
* Map from indices to A1 notation.
|
|
517
|
-
*/
|
|
518
|
-
mapFormulaIndicesToRefs(formula: string): string {
|
|
519
|
-
invariant(formula.charAt(0) === '=');
|
|
520
|
-
return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
|
|
521
|
-
return addressToA1Notation(this.addressFromIndex(idx));
|
|
522
|
-
});
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
//
|
|
526
|
-
// Values
|
|
527
|
-
//
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* https://hyperformula.handsontable.com/guide/date-and-time-handling.html#example
|
|
531
|
-
* https://hyperformula.handsontable.com/api/interfaces/configparams.html#nulldate
|
|
532
|
-
* NOTE: TODAY() is number of FULL days since nullDate. It will typically be -1 days from NOW().
|
|
533
|
-
*/
|
|
534
|
-
toLocalDate(num: number): Date {
|
|
535
|
-
const { year, month, day, hours, minutes, seconds } = this.toDateTime(num);
|
|
536
|
-
return new Date(year, month - 1, day, hours, minutes, seconds);
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
toDateTime(num: number): SimpleDateTime {
|
|
540
|
-
return this._graph.hf.numberToDateTime(num) as SimpleDateTime;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
toDate(num: number): SimpleDate {
|
|
544
|
-
return this._graph.hf.numberToDate(num) as SimpleDate;
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
toTime(num: number): SimpleDate {
|
|
548
|
-
return this._graph.hf.numberToTime(num) as SimpleDate;
|
|
549
|
-
}
|
|
550
|
-
}
|
package/src/model/util.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { randomBytes } from '@dxos/crypto';
|
|
6
|
-
|
|
7
|
-
// TODO(burdon): Factor out from dxos/protocols to new common package.
|
|
8
|
-
export class ApiError extends Error {}
|
|
9
|
-
export class ReadonlyException extends ApiError {}
|
|
10
|
-
export class RangeException extends ApiError {
|
|
11
|
-
constructor(n: number) {
|
|
12
|
-
super();
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* With a string length of 8, the chance of a collision is 0.02% for a sheet with 10,000 strings.
|
|
18
|
-
*/
|
|
19
|
-
export const createIndex = (length = 8): string => {
|
|
20
|
-
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
21
|
-
const charactersLength = characters.length;
|
|
22
|
-
const randomBuffer = randomBytes(length);
|
|
23
|
-
return Array.from(randomBuffer, (byte) => characters[byte % charactersLength]).join('');
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const createIndices = (length: number): string[] => Array.from({ length }).map(() => createIndex());
|
|
27
|
-
|
|
28
|
-
// TODO(burdon): Factor out.
|
|
29
|
-
export const pickOne = <T>(values: T[]): T => values[Math.floor(Math.random() * values.length)];
|
|
30
|
-
export const pickSome = <T>(values: T[], n = 1): T[] => {
|
|
31
|
-
const result = new Set<T>();
|
|
32
|
-
while (result.size < n) {
|
|
33
|
-
result.add(pickOne(values));
|
|
34
|
-
}
|
|
35
|
-
return Array.from(result.values());
|
|
36
|
-
};
|