@dxos/plugin-sheet 0.6.13 → 0.6.14-main.1366248
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-JZEKRM4Z.mjs +297 -0
- package/dist/lib/browser/SheetContainer-JZEKRM4Z.mjs.map +7 -0
- package/dist/lib/browser/chunk-BVUN7SHF.mjs +67 -0
- package/dist/lib/browser/chunk-BVUN7SHF.mjs.map +7 -0
- package/dist/lib/browser/chunk-G2FUL6PK.mjs +1671 -0
- package/dist/lib/browser/chunk-G2FUL6PK.mjs.map +7 -0
- package/dist/lib/browser/chunk-RABELMEQ.mjs +15 -0
- package/dist/lib/browser/chunk-RABELMEQ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-D5AGLXJP.mjs → chunk-VMSX6Z4X.mjs} +659 -675
- package/dist/lib/browser/chunk-VMSX6Z4X.mjs.map +7 -0
- package/dist/lib/browser/compute-graph-GGWUX644.mjs +35 -0
- package/dist/lib/browser/compute-graph-GGWUX644.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +168 -67
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +1 -1
- package/dist/lib/browser/types.mjs +6 -12
- package/dist/lib/node/SheetContainer-PJE74VO4.cjs +300 -0
- package/dist/lib/node/SheetContainer-PJE74VO4.cjs.map +7 -0
- package/dist/lib/node/chunk-2ZVZI2KJ.cjs +38 -0
- package/dist/lib/node/chunk-2ZVZI2KJ.cjs.map +7 -0
- package/dist/lib/node/{chunk-DSYKOI4E.cjs → chunk-AWKOWDMI.cjs} +34 -52
- package/dist/lib/node/chunk-AWKOWDMI.cjs.map +7 -0
- package/dist/lib/node/{chunk-5KKJ4NPP.cjs → chunk-O7XR4R7Y.cjs} +678 -674
- package/dist/lib/node/chunk-O7XR4R7Y.cjs.map +7 -0
- package/dist/lib/node/chunk-STZ7S7RF.cjs +1656 -0
- package/dist/lib/node/chunk-STZ7S7RF.cjs.map +7 -0
- package/dist/lib/node/compute-graph-KGWA2QLE.cjs +57 -0
- package/dist/lib/node/compute-graph-KGWA2QLE.cjs.map +7 -0
- package/dist/lib/node/index.cjs +178 -75
- package/dist/lib/node/index.cjs.map +4 -4
- 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 +9 -15
- package/dist/lib/node/types.cjs.map +2 -2
- package/dist/lib/node-esm/SheetContainer-R73XEXHU.mjs +298 -0
- package/dist/lib/node-esm/SheetContainer-R73XEXHU.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-BM2Q3FFC.mjs +17 -0
- package/dist/lib/node-esm/chunk-BM2Q3FFC.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-CR4K75EL.mjs +3220 -0
- package/dist/lib/node-esm/chunk-CR4K75EL.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-UIBWRHW7.mjs +68 -0
- package/dist/lib/node-esm/chunk-UIBWRHW7.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-V5N3Y2O5.mjs +1672 -0
- package/dist/lib/node-esm/chunk-V5N3Y2O5.mjs.map +7 -0
- package/dist/lib/node-esm/compute-graph-2SCZT7N5.mjs +36 -0
- package/dist/lib/node-esm/compute-graph-2SCZT7N5.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +350 -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 +13 -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 +6 -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} +5 -9
- 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 +15 -0
- package/dist/types/src/components/GridSheet/util.d.ts.map +1 -0
- package/dist/types/src/components/RangeList/RangeList.d.ts +7 -0
- package/dist/types/src/components/RangeList/RangeList.d.ts.map +1 -0
- package/dist/types/src/components/RangeList/index.d.ts +2 -0
- package/dist/types/src/components/RangeList/index.d.ts.map +1 -0
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +9 -0
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -0
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +6 -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 +28 -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 -9
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +4 -32
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +7 -4
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/compute-graph/compute-graph-registry.d.ts +34 -0
- package/dist/types/src/compute-graph/compute-graph-registry.d.ts.map +1 -0
- package/dist/types/src/compute-graph/compute-graph.d.ts +64 -0
- package/dist/types/src/compute-graph/compute-graph.d.ts.map +1 -0
- package/dist/types/src/compute-graph/compute-graph.stories.d.ts +6 -0
- package/dist/types/src/compute-graph/compute-graph.stories.d.ts.map +1 -0
- package/dist/types/src/compute-graph/compute-graph.test.d.ts +2 -0
- package/dist/types/src/compute-graph/compute-graph.test.d.ts.map +1 -0
- package/dist/types/src/compute-graph/compute-node.d.ts +26 -0
- package/dist/types/src/compute-graph/compute-node.d.ts.map +1 -0
- package/dist/types/src/{components/ComputeGraph → compute-graph/functions}/async-function.d.ts +14 -5
- package/dist/types/src/compute-graph/functions/async-function.d.ts.map +1 -0
- package/dist/types/src/compute-graph/functions/edge-function.d.ts +21 -0
- package/dist/types/src/compute-graph/functions/edge-function.d.ts.map +1 -0
- package/dist/types/src/{model/functions.d.ts → compute-graph/functions/function-defs.d.ts} +1 -1
- package/dist/types/src/compute-graph/functions/function-defs.d.ts.map +1 -0
- package/dist/types/src/compute-graph/functions/index.d.ts +4 -0
- package/dist/types/src/compute-graph/functions/index.d.ts.map +1 -0
- package/dist/types/src/compute-graph/hyperformula.test.d.ts +2 -0
- package/dist/types/src/compute-graph/hyperformula.test.d.ts.map +1 -0
- package/dist/types/src/compute-graph/index.d.ts +5 -0
- package/dist/types/src/compute-graph/index.d.ts.map +1 -0
- package/dist/types/src/compute-graph/testing/index.d.ts +3 -0
- package/dist/types/src/compute-graph/testing/index.d.ts.map +1 -0
- package/dist/types/src/compute-graph/testing/test-builder.d.ts +15 -0
- package/dist/types/src/compute-graph/testing/test-builder.d.ts.map +1 -0
- package/dist/types/src/compute-graph/testing/test-plugin.d.ts +36 -0
- package/dist/types/src/compute-graph/testing/test-plugin.d.ts.map +1 -0
- package/dist/types/src/compute-graph/util.d.ts +2 -0
- package/dist/types/src/compute-graph/util.d.ts.map +1 -0
- package/dist/types/src/defs/index.d.ts +4 -0
- package/dist/types/src/defs/index.d.ts.map +1 -0
- package/dist/types/src/defs/sheet-range-types.d.ts +13 -0
- package/dist/types/src/defs/sheet-range-types.d.ts.map +1 -0
- package/dist/types/src/defs/types.d.ts +28 -0
- 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 +39 -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 +21 -0
- package/dist/types/src/extensions/compute.stories.d.ts.map +1 -0
- package/dist/types/src/extensions/editor/extension.d.ts +39 -0
- 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/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/integrations/index.d.ts +2 -0
- package/dist/types/src/integrations/index.d.ts.map +1 -0
- package/dist/types/src/integrations/thread-ranges.d.ts +7 -0
- package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +4 -9
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/model/index.d.ts +2 -3
- package/dist/types/src/model/index.d.ts.map +1 -1
- package/dist/types/src/model/{model.d.ts → sheet-model.d.ts} +22 -69
- 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/model/useSheetModel.d.ts +8 -0
- package/dist/types/src/model/useSheetModel.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/serializer.d.ts +4 -0
- package/dist/types/src/serializer.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 +32 -12
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +132 -43
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/vendor/hyperformula.mjs +37145 -0
- package/package.json +60 -61
- package/src/SheetPlugin.tsx +89 -78
- package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +37 -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 +46 -0
- package/src/components/GridSheet/GridSheet.tsx +358 -0
- package/src/components/{CellEditor/CellEditor.stories.tsx → GridSheet/SheetCellEditor.stories.tsx} +18 -15
- package/src/components/GridSheet/index.ts +5 -0
- package/src/components/GridSheet/util.ts +170 -0
- package/src/components/RangeList/RangeList.tsx +53 -0
- package/src/components/RangeList/index.ts +5 -0
- package/src/components/SheetContainer/SheetContainer.stories.tsx +45 -0
- package/src/components/SheetContainer/SheetContainer.tsx +33 -0
- package/src/components/SheetContainer/index.ts +7 -0
- package/src/components/SheetContext/SheetContext.tsx +127 -0
- package/src/components/SheetContext/index.ts +5 -0
- package/src/components/Toolbar/Toolbar.stories.tsx +9 -6
- package/src/components/Toolbar/Toolbar.tsx +265 -111
- package/src/components/index.ts +5 -3
- package/src/compute-graph/compute-graph-registry.ts +90 -0
- package/src/compute-graph/compute-graph.stories.tsx +97 -0
- package/src/compute-graph/compute-graph.test.ts +87 -0
- package/src/compute-graph/compute-graph.ts +260 -0
- package/src/compute-graph/compute-node.ts +62 -0
- package/src/{components/ComputeGraph → compute-graph/functions}/async-function.ts +26 -15
- package/src/{components/ComputeGraph → compute-graph/functions}/edge-function.ts +21 -17
- package/src/compute-graph/functions/index.ts +7 -0
- package/src/compute-graph/hyperformula.test.ts +14 -0
- package/src/compute-graph/index.ts +8 -0
- package/src/compute-graph/testing/index.ts +6 -0
- package/src/compute-graph/testing/test-builder.ts +54 -0
- package/src/{components/ComputeGraph/custom.ts → compute-graph/testing/test-plugin.ts} +44 -14
- package/src/compute-graph/util.ts +8 -0
- package/src/defs/index.ts +7 -0
- package/src/defs/sheet-range-types.ts +49 -0
- package/src/{model → defs}/types.test.ts +8 -9
- package/src/defs/types.ts +86 -0
- package/src/defs/util.ts +136 -0
- package/src/extensions/compute.stories.tsx +155 -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 +51 -27
- package/src/{components/CellEditor → extensions/editor}/index.ts +0 -1
- package/src/extensions/index.ts +6 -0
- package/src/index.ts +2 -2
- package/src/integrations/index.ts +5 -0
- package/src/integrations/thread-ranges.ts +101 -0
- package/src/meta.ts +15 -0
- package/src/model/index.ts +2 -3
- package/src/model/sheet-model.test.ts +59 -0
- package/src/model/sheet-model.ts +495 -0
- package/src/model/useSheetModel.ts +40 -0
- package/src/sanity.test.ts +40 -0
- package/src/serializer.ts +27 -0
- package/src/{components/Sheet → testing}/index.ts +1 -1
- package/src/testing/testing.tsx +68 -0
- package/src/translations.ts +24 -4
- package/src/types.ts +62 -47
- 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 +0 -19
- 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 +0 -17
- 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/formatting.ts +0 -106
- 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/types.ts +0 -71
- 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 → compute-graph/functions/function-defs.ts} +0 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Client, type ClientOptions } from '@dxos/client';
|
|
6
|
+
import { type Context, Resource } from '@dxos/context';
|
|
7
|
+
import { invariant } from '@dxos/invariant';
|
|
8
|
+
|
|
9
|
+
import { type ComputeGraphOptions, ComputeGraphRegistry } from '../compute-graph-registry';
|
|
10
|
+
|
|
11
|
+
export type TestBuilderOptions = ClientOptions & ComputeGraphOptions;
|
|
12
|
+
|
|
13
|
+
// TODO(burdon): Reconcile with @dxos/client/testing.
|
|
14
|
+
export class TestBuilder extends Resource {
|
|
15
|
+
private _client?: Client;
|
|
16
|
+
private _registry?: ComputeGraphRegistry;
|
|
17
|
+
|
|
18
|
+
constructor(private readonly _options: TestBuilderOptions = {}) {
|
|
19
|
+
super();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get ctx(): Context {
|
|
23
|
+
return this._ctx;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get client(): Client {
|
|
27
|
+
invariant(this._client);
|
|
28
|
+
return this._client;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
get registry(): ComputeGraphRegistry {
|
|
32
|
+
invariant(this._registry);
|
|
33
|
+
return this._registry;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
override async _open() {
|
|
37
|
+
const client = new Client(this._options);
|
|
38
|
+
await client.initialize();
|
|
39
|
+
await client.halo.createIdentity();
|
|
40
|
+
this._client = client;
|
|
41
|
+
this._ctx.onDispose(async () => {
|
|
42
|
+
await client.destroy();
|
|
43
|
+
this._client = undefined;
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const registry = new ComputeGraphRegistry(this._options);
|
|
47
|
+
await registry.open();
|
|
48
|
+
this._registry = registry;
|
|
49
|
+
this._ctx.onDispose(async () => {
|
|
50
|
+
await registry.close();
|
|
51
|
+
this._registry = undefined;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -2,24 +2,36 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { FunctionArgumentType } from 'hyperformula';
|
|
6
5
|
import { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';
|
|
7
6
|
import { type ProcedureAst } from 'hyperformula/typings/parser';
|
|
8
7
|
|
|
9
8
|
import { getDeep } from '@dxos/util';
|
|
10
9
|
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return parseFloat(str.replace(/[^\d.]/g, ''));
|
|
16
|
-
};
|
|
10
|
+
import { FunctionArgumentType } from '#hyperformula';
|
|
11
|
+
import { type ComputeGraphPlugin } from '../compute-graph-registry';
|
|
12
|
+
import { type AsyncFunction, AsyncFunctionPlugin } from '../functions';
|
|
13
|
+
import { parseNumberString } from '../util';
|
|
17
14
|
|
|
18
15
|
/**
|
|
16
|
+
* Testing functions run locally (not run via EDGE).
|
|
19
17
|
* https://hyperformula.handsontable.com/guide/custom-functions.html#add-a-simple-custom-function
|
|
20
18
|
*/
|
|
21
|
-
export class
|
|
19
|
+
export class TestPlugin extends AsyncFunctionPlugin {
|
|
20
|
+
/**
|
|
21
|
+
* Simple local function returns input value.
|
|
22
|
+
*/
|
|
22
23
|
test(ast: ProcedureAst, state: InterpreterState) {
|
|
24
|
+
const handler: AsyncFunction = async (_value) => {
|
|
25
|
+
return _value;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return this.runAsyncFunction(ast, state, handler);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Simple local function returns random number.
|
|
33
|
+
*/
|
|
34
|
+
random(ast: ProcedureAst, state: InterpreterState) {
|
|
23
35
|
const handler: AsyncFunction = async () => {
|
|
24
36
|
return Math.random();
|
|
25
37
|
};
|
|
@@ -27,6 +39,9 @@ export class CustomPlugin extends FunctionPluginAsync {
|
|
|
27
39
|
return this.runAsyncFunction(ast, state, handler);
|
|
28
40
|
}
|
|
29
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Async HTTP function.
|
|
44
|
+
*/
|
|
30
45
|
crypto(ast: ProcedureAst, state: InterpreterState) {
|
|
31
46
|
const handler: AsyncFunction = async (_currency) => {
|
|
32
47
|
const currency = (_currency || 'USD').toUpperCase();
|
|
@@ -44,9 +59,15 @@ export class CustomPlugin extends FunctionPluginAsync {
|
|
|
44
59
|
}
|
|
45
60
|
}
|
|
46
61
|
|
|
47
|
-
|
|
62
|
+
TestPlugin.implementedFunctions = {
|
|
48
63
|
TEST: {
|
|
49
64
|
method: 'test',
|
|
65
|
+
parameters: [{ argumentType: FunctionArgumentType.NUMBER, optionalArg: false }],
|
|
66
|
+
isVolatile: true,
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
RANDOM: {
|
|
70
|
+
method: 'random',
|
|
50
71
|
parameters: [],
|
|
51
72
|
isVolatile: true,
|
|
52
73
|
},
|
|
@@ -58,13 +79,22 @@ CustomPlugin.implementedFunctions = {
|
|
|
58
79
|
},
|
|
59
80
|
};
|
|
60
81
|
|
|
61
|
-
export const
|
|
82
|
+
export const TestPluginTranslations = {
|
|
62
83
|
enGB: {
|
|
63
|
-
TEST: '
|
|
64
|
-
|
|
84
|
+
TEST: 'Returns input value',
|
|
85
|
+
RANDOM: 'Random number',
|
|
86
|
+
CRYPTO: 'Crypto token value',
|
|
65
87
|
},
|
|
66
88
|
enUS: {
|
|
67
|
-
TEST: '
|
|
68
|
-
|
|
89
|
+
TEST: 'Returns input value',
|
|
90
|
+
RANDOM: 'Random number',
|
|
91
|
+
CRYPTO: 'Crypto token value',
|
|
69
92
|
},
|
|
70
93
|
};
|
|
94
|
+
|
|
95
|
+
export const testFunctionPlugins: ComputeGraphPlugin[] = [
|
|
96
|
+
{
|
|
97
|
+
plugin: TestPlugin,
|
|
98
|
+
translations: TestPluginTranslations,
|
|
99
|
+
},
|
|
100
|
+
];
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type ClassNameValue } from '@dxos/react-ui';
|
|
6
|
+
|
|
7
|
+
import { type SheetType } from '../types';
|
|
8
|
+
|
|
9
|
+
export const alignKey = 'alignment';
|
|
10
|
+
export type AlignKey = typeof alignKey;
|
|
11
|
+
export type AlignValue = 'start' | 'center' | 'end' | 'unset';
|
|
12
|
+
|
|
13
|
+
export const commentKey = 'comment';
|
|
14
|
+
export type CommentKey = typeof commentKey;
|
|
15
|
+
export type CommentValue = string;
|
|
16
|
+
|
|
17
|
+
export const styleKey = 'style';
|
|
18
|
+
export type StyleKey = typeof styleKey;
|
|
19
|
+
export type StyleValue = 'highlight' | 'softwrap';
|
|
20
|
+
|
|
21
|
+
// TODO(burdon): Reconcile with plugin-table.
|
|
22
|
+
export const cellClassNameForRange = ({ key, value }: SheetType['ranges'][number]): ClassNameValue => {
|
|
23
|
+
switch (key) {
|
|
24
|
+
case alignKey:
|
|
25
|
+
switch (value) {
|
|
26
|
+
case 'start':
|
|
27
|
+
return 'text-start';
|
|
28
|
+
case 'center':
|
|
29
|
+
return 'text-center';
|
|
30
|
+
case 'end':
|
|
31
|
+
return 'text-end';
|
|
32
|
+
default:
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
case commentKey:
|
|
36
|
+
return 'bg-gridComment';
|
|
37
|
+
case styleKey:
|
|
38
|
+
switch (value) {
|
|
39
|
+
case 'highlight':
|
|
40
|
+
return '!bg-gridHighlight';
|
|
41
|
+
case 'softwrap':
|
|
42
|
+
return '!whitespace-normal';
|
|
43
|
+
default:
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
default:
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
@@ -3,15 +3,14 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { getIndices, sortByIndex, getIndicesBelow, getIndicesAbove, getIndicesBetween } from '@tldraw/indices';
|
|
6
|
-
import { expect } from '
|
|
7
|
-
import { describe, test } from 'vitest';
|
|
6
|
+
import { describe, expect, test } from 'vitest';
|
|
8
7
|
|
|
9
8
|
import { inRange, addressFromA1Notation, addressToA1Notation, rangeFromA1Notation, rangeToA1Notation } from './types';
|
|
10
9
|
|
|
11
10
|
describe('cell', () => {
|
|
12
11
|
test('posToA1Notation', () => {
|
|
13
|
-
expect(addressToA1Notation({
|
|
14
|
-
expect(addressFromA1Notation('C2')).to.deep.eq({
|
|
12
|
+
expect(addressToA1Notation({ col: 0, row: 0 })).to.eq('A1');
|
|
13
|
+
expect(addressFromA1Notation('C2')).to.deep.eq({ col: 2, row: 1 });
|
|
15
14
|
});
|
|
16
15
|
|
|
17
16
|
test('rangeToA1Notation', () => {
|
|
@@ -56,19 +55,19 @@ describe('cell', () => {
|
|
|
56
55
|
// Values.
|
|
57
56
|
const cells: Record<string, any> = {};
|
|
58
57
|
const setCell = (cell: string, value: any) => {
|
|
59
|
-
const {
|
|
58
|
+
const { col, row } = addressFromA1Notation(cell);
|
|
60
59
|
// Reallocate if > current bounds.
|
|
61
|
-
if (
|
|
62
|
-
insertIndex(columns,
|
|
60
|
+
if (col >= columns.length) {
|
|
61
|
+
insertIndex(columns, col);
|
|
63
62
|
}
|
|
64
63
|
if (row >= rows.length) {
|
|
65
64
|
insertIndex(rows, row);
|
|
66
65
|
}
|
|
67
|
-
const index = `${columns[
|
|
66
|
+
const index = `${columns[col]}@${rows[row]}`;
|
|
68
67
|
cells[index] = value;
|
|
69
68
|
};
|
|
70
69
|
|
|
71
|
-
expect(addressFromA1Notation('A1')).to.deep.eq({
|
|
70
|
+
expect(addressFromA1Notation('A1')).to.deep.eq({ col: 0, row: 0 });
|
|
72
71
|
|
|
73
72
|
expect(columns).to.deep.eq(['a1', 'a2', 'a3', 'a4', 'a5']);
|
|
74
73
|
insertIndex(columns, 7);
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { invariant } from '@dxos/invariant';
|
|
6
|
+
|
|
7
|
+
export const DEFAULT_ROWS = 50;
|
|
8
|
+
export const DEFAULT_COLUMNS = 26;
|
|
9
|
+
|
|
10
|
+
export const MAX_ROWS = 500;
|
|
11
|
+
export const MAX_COLUMNS = 26 * 2;
|
|
12
|
+
|
|
13
|
+
export type CellAddress = { col: number; row: number };
|
|
14
|
+
|
|
15
|
+
export type CellRange = { from: CellAddress; to?: CellAddress };
|
|
16
|
+
export type CompleteCellRange = { from: CellAddress; to: CellAddress };
|
|
17
|
+
|
|
18
|
+
export type CellIndex = string;
|
|
19
|
+
|
|
20
|
+
export type CellContentValue = number | string | boolean | null;
|
|
21
|
+
|
|
22
|
+
export const RANGE_NOTATION = /^[A-Z]+[0-9]+(:[A-Z]+[0-9]+)?$/;
|
|
23
|
+
|
|
24
|
+
export const isFormula = (value: any): value is string => typeof value === 'string' && value.charAt(0) === '=';
|
|
25
|
+
|
|
26
|
+
export const posEquals = (a: CellAddress | undefined, b: CellAddress | undefined) => {
|
|
27
|
+
return a?.col === b?.col && a?.row === b?.row;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const columnLetter = (col: number): string => {
|
|
31
|
+
invariant(col < MAX_COLUMNS, `Invalid column: ${col}`);
|
|
32
|
+
return (
|
|
33
|
+
(col >= 26 ? String.fromCharCode('A'.charCodeAt(0) + Math.floor(col / 26) - 1) : '') +
|
|
34
|
+
String.fromCharCode('A'.charCodeAt(0) + (col % 26))
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const addressToA1Notation = ({ col, row }: CellAddress): string => {
|
|
39
|
+
return `${columnLetter(col)}${row + 1}`;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// TODO(burdon): See (HF) simpleCellAddressFromString.
|
|
43
|
+
export const addressFromA1Notation = (ref: string): CellAddress => {
|
|
44
|
+
const match = ref.match(/([A-Z]+)(\d+)/);
|
|
45
|
+
invariant(match, `Invalid notation: ${ref}`);
|
|
46
|
+
return {
|
|
47
|
+
row: parseInt(match[2], 10) - 1,
|
|
48
|
+
col: match[1].split('').reduce((acc, c) => acc * 26 + c.charCodeAt(0) - 'A'.charCodeAt(0) + 1, 0) - 1,
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const rangeToA1Notation = (range: CellRange) => {
|
|
53
|
+
return [range?.from && addressToA1Notation(range?.from), range?.to && addressToA1Notation(range?.to)]
|
|
54
|
+
.filter(Boolean)
|
|
55
|
+
.join(':');
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const rangeFromA1Notation = (ref: string): CellRange => {
|
|
59
|
+
const [from, to] = ref.split(':').map(addressFromA1Notation);
|
|
60
|
+
return { from, to };
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const inRange = (range: CellRange | undefined, cell: CellAddress): boolean => {
|
|
64
|
+
if (!range) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const { from, to } = range;
|
|
69
|
+
if ((from && posEquals(from, cell)) || (to && posEquals(to, cell))) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!from || !to) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const { col: c1, row: r1 } = from;
|
|
78
|
+
const { col: c2, row: r2 } = to;
|
|
79
|
+
const cMin = Math.min(c1, c2);
|
|
80
|
+
const cMax = Math.max(c1, c2);
|
|
81
|
+
const rMin = Math.min(r1, r2);
|
|
82
|
+
const rMax = Math.max(r1, r2);
|
|
83
|
+
|
|
84
|
+
const { col, row } = cell;
|
|
85
|
+
return col >= cMin && col <= cMax && row >= rMin && row <= rMax;
|
|
86
|
+
};
|
package/src/defs/util.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { randomBytes } from '@dxos/crypto';
|
|
6
|
+
import { create } from '@dxos/echo-schema';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
addressFromA1Notation,
|
|
10
|
+
type CellAddress,
|
|
11
|
+
type CellRange,
|
|
12
|
+
type CompleteCellRange,
|
|
13
|
+
DEFAULT_COLUMNS,
|
|
14
|
+
DEFAULT_ROWS,
|
|
15
|
+
MAX_COLUMNS,
|
|
16
|
+
MAX_ROWS,
|
|
17
|
+
} from './types';
|
|
18
|
+
import { type CreateSheetOptions, type SheetSize, SheetType } from '../types';
|
|
19
|
+
|
|
20
|
+
// TODO(burdon): Factor out from dxos/protocols to new common package.
|
|
21
|
+
export class ApiError extends Error {}
|
|
22
|
+
|
|
23
|
+
export class ReadonlyException extends ApiError {}
|
|
24
|
+
|
|
25
|
+
export class RangeException extends ApiError {
|
|
26
|
+
constructor(n: number) {
|
|
27
|
+
super();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* With a string length of 8, the chance of a collision is 0.02% for a sheet with 10,000 strings.
|
|
33
|
+
*/
|
|
34
|
+
export const createIndex = (length = 8): string => {
|
|
35
|
+
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
36
|
+
const charactersLength = characters.length;
|
|
37
|
+
const randomBuffer = randomBytes(length);
|
|
38
|
+
return Array.from(randomBuffer, (byte) => characters[byte % charactersLength]).join('');
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const createIndices = (length: number): string[] => Array.from({ length }).map(() => createIndex());
|
|
42
|
+
|
|
43
|
+
export const insertIndices = (indices: string[], i: number, n: number, max: number) => {
|
|
44
|
+
if (i + n > max) {
|
|
45
|
+
throw new RangeException(i + n);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const idx = createIndices(n);
|
|
49
|
+
indices.splice(i, 0, ...idx);
|
|
50
|
+
return idx;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const initialize = (
|
|
54
|
+
sheet: SheetType,
|
|
55
|
+
{ rows = DEFAULT_ROWS, columns = DEFAULT_COLUMNS }: Partial<SheetSize> = {},
|
|
56
|
+
) => {
|
|
57
|
+
if (!sheet.rows.length) {
|
|
58
|
+
insertIndices(sheet.rows, 0, rows, MAX_ROWS);
|
|
59
|
+
}
|
|
60
|
+
if (!sheet.columns.length) {
|
|
61
|
+
insertIndices(sheet.columns, 0, columns, MAX_COLUMNS);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const createSheet = ({ name, cells, ...size }: CreateSheetOptions = {}): SheetType => {
|
|
66
|
+
const sheet = create(SheetType, {
|
|
67
|
+
name,
|
|
68
|
+
cells: {},
|
|
69
|
+
rows: [],
|
|
70
|
+
columns: [],
|
|
71
|
+
rowMeta: {},
|
|
72
|
+
columnMeta: {},
|
|
73
|
+
ranges: [],
|
|
74
|
+
threads: [],
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
initialize(sheet, size);
|
|
78
|
+
|
|
79
|
+
if (cells) {
|
|
80
|
+
Object.entries(cells).forEach(([key, { value }]) => {
|
|
81
|
+
const idx = addressToIndex(sheet, addressFromA1Notation(key));
|
|
82
|
+
sheet.cells[idx] = { value };
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return sheet;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* E.g., "A1" => "CA2@CB3".
|
|
91
|
+
*/
|
|
92
|
+
export const addressToIndex = (sheet: SheetType, cell: CellAddress): string => {
|
|
93
|
+
return `${sheet.columns[cell.col]}@${sheet.rows[cell.row]}`;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* E.g., "CA2@CB3" => "A1".
|
|
98
|
+
*/
|
|
99
|
+
export const addressFromIndex = (sheet: SheetType, idx: string): CellAddress => {
|
|
100
|
+
const [column, row] = idx.split('@');
|
|
101
|
+
return {
|
|
102
|
+
col: sheet.columns.indexOf(column),
|
|
103
|
+
row: sheet.rows.indexOf(row),
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* E.g., "A1:B2" => "CA2@CB3:CC4@CD5".
|
|
109
|
+
*/
|
|
110
|
+
export const rangeToIndex = (sheet: SheetType, range: CellRange): string => {
|
|
111
|
+
return [range.from, range.to ?? range.from].map((cell) => addressToIndex(sheet, cell)).join(':');
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* E.g., "CA2@CB3:CC4@CD5" => "A1:B2".
|
|
116
|
+
*/
|
|
117
|
+
export const rangeFromIndex = (sheet: SheetType, idx: string): CompleteCellRange => {
|
|
118
|
+
const [from, to] = idx.split(':').map((index) => addressFromIndex(sheet, index));
|
|
119
|
+
return { from, to };
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Compares the positions of two cell indexes in a sheet.
|
|
124
|
+
* Sorts primarily by row, then by column if rows are equal.
|
|
125
|
+
*/
|
|
126
|
+
export const compareIndexPositions = (sheet: SheetType, indexA: string, indexB: string): number => {
|
|
127
|
+
const { row: rowA, col: columnA } = addressFromIndex(sheet, indexA);
|
|
128
|
+
const { row: rowB, col: columnB } = addressFromIndex(sheet, indexB);
|
|
129
|
+
|
|
130
|
+
// Sort by row first, then by column.
|
|
131
|
+
if (rowA !== rowB) {
|
|
132
|
+
return rowA - rowB;
|
|
133
|
+
} else {
|
|
134
|
+
return columnA - columnB;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxos-theme';
|
|
6
|
+
|
|
7
|
+
import { type Meta } from '@storybook/react';
|
|
8
|
+
import React, { useEffect, useMemo } from 'react';
|
|
9
|
+
|
|
10
|
+
import { PublicKey } from '@dxos/keys';
|
|
11
|
+
import { useSpace } from '@dxos/react-client/echo';
|
|
12
|
+
import { withClientProvider } from '@dxos/react-client/testing';
|
|
13
|
+
import { useThemeContext } from '@dxos/react-ui';
|
|
14
|
+
import {
|
|
15
|
+
createBasicExtensions,
|
|
16
|
+
createMarkdownExtensions,
|
|
17
|
+
createThemeExtensions,
|
|
18
|
+
decorateMarkdown,
|
|
19
|
+
documentId,
|
|
20
|
+
useTextEditor,
|
|
21
|
+
} from '@dxos/react-ui-editor';
|
|
22
|
+
import { withTheme, withLayout } from '@dxos/storybook-utils';
|
|
23
|
+
import { nonNullable } from '@dxos/util';
|
|
24
|
+
|
|
25
|
+
import { compute, computeGraphFacet } from './compute';
|
|
26
|
+
import { GridSheet, SheetProvider, useComputeGraph } from '../components';
|
|
27
|
+
import { useSheetModel } from '../model';
|
|
28
|
+
import { useTestSheet, withComputeGraphDecorator } from '../testing';
|
|
29
|
+
import { SheetType } from '../types';
|
|
30
|
+
|
|
31
|
+
const str = (...lines: string[]) => lines.join('\n');
|
|
32
|
+
|
|
33
|
+
type EditorProps = {
|
|
34
|
+
text?: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// TODO(burdon): Implement named expressions.
|
|
38
|
+
// https://hyperformula.handsontable.com/guide/cell-references.html
|
|
39
|
+
|
|
40
|
+
// TODO(burdon): Inline Adobe eCharts.
|
|
41
|
+
|
|
42
|
+
const SHEET_NAME = 'Test Sheet';
|
|
43
|
+
|
|
44
|
+
const EditorStory = ({ text }: EditorProps) => {
|
|
45
|
+
const id = useMemo(() => PublicKey.random(), []);
|
|
46
|
+
const { themeMode } = useThemeContext();
|
|
47
|
+
const space = useSpace();
|
|
48
|
+
const computeGraph = useComputeGraph(space);
|
|
49
|
+
const { parentRef, focusAttributes } = useTextEditor(
|
|
50
|
+
() => ({
|
|
51
|
+
initialValue: text,
|
|
52
|
+
extensions: [
|
|
53
|
+
createBasicExtensions(),
|
|
54
|
+
createMarkdownExtensions({ themeMode }),
|
|
55
|
+
createThemeExtensions({ themeMode, syntaxHighlighting: true }),
|
|
56
|
+
documentId.of(id.toHex()),
|
|
57
|
+
computeGraph && computeGraphFacet.of(computeGraph),
|
|
58
|
+
compute(),
|
|
59
|
+
decorateMarkdown(),
|
|
60
|
+
].filter(nonNullable),
|
|
61
|
+
}),
|
|
62
|
+
[computeGraph, themeMode],
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return <div className='w-[40rem] overflow-hidden' ref={parentRef} {...focusAttributes} />;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const Grid = () => {
|
|
69
|
+
const space = useSpace();
|
|
70
|
+
const graph = useComputeGraph(space);
|
|
71
|
+
const sheet = useTestSheet(space, graph, { name: SHEET_NAME });
|
|
72
|
+
const model = useSheetModel(graph, sheet);
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
if (model) {
|
|
75
|
+
model.setValues({ A1: { value: 100 }, A2: { value: 200 }, A3: { value: 300 }, A5: { value: '=SUM(A1:A3)' } });
|
|
76
|
+
}
|
|
77
|
+
}, [model]);
|
|
78
|
+
|
|
79
|
+
if (!graph || !sheet) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return (
|
|
84
|
+
<div className='flex w-[40rem] overflow-hidden'>
|
|
85
|
+
<SheetProvider graph={graph} sheet={sheet}>
|
|
86
|
+
<GridSheet />
|
|
87
|
+
</SheetProvider>
|
|
88
|
+
</div>
|
|
89
|
+
);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const GraphStory = (props: EditorProps) => {
|
|
93
|
+
return (
|
|
94
|
+
<div className='grid grid-rows-2'>
|
|
95
|
+
<EditorStory {...props} />
|
|
96
|
+
<Grid />
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
// TODO(burdon): Inline formulae.
|
|
102
|
+
export const Default = {
|
|
103
|
+
render: EditorStory,
|
|
104
|
+
args: {
|
|
105
|
+
text: str(
|
|
106
|
+
//
|
|
107
|
+
'# Compute Graph',
|
|
108
|
+
'',
|
|
109
|
+
'This is a compute expression:',
|
|
110
|
+
'',
|
|
111
|
+
'```dx',
|
|
112
|
+
'=SUM(1, 2)',
|
|
113
|
+
'```',
|
|
114
|
+
'',
|
|
115
|
+
'It should change in realtime.',
|
|
116
|
+
'',
|
|
117
|
+
'```dx',
|
|
118
|
+
'=SUM(3, 5)',
|
|
119
|
+
'```',
|
|
120
|
+
'',
|
|
121
|
+
'',
|
|
122
|
+
),
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const Graph = {
|
|
127
|
+
render: GraphStory,
|
|
128
|
+
args: {
|
|
129
|
+
text: str(
|
|
130
|
+
//
|
|
131
|
+
'# Compute Graph',
|
|
132
|
+
'',
|
|
133
|
+
'The total projected cost is:',
|
|
134
|
+
'',
|
|
135
|
+
'```dx',
|
|
136
|
+
`="${SHEET_NAME}"!A5`,
|
|
137
|
+
'```',
|
|
138
|
+
'',
|
|
139
|
+
'',
|
|
140
|
+
),
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const meta: Meta = {
|
|
145
|
+
title: 'plugins/plugin-sheet/extensions',
|
|
146
|
+
decorators: [
|
|
147
|
+
withClientProvider({ types: [SheetType], createIdentity: true, createSpace: true }),
|
|
148
|
+
withComputeGraphDecorator(),
|
|
149
|
+
withTheme,
|
|
150
|
+
withLayout({ fullscreen: true, classNames: 'justify-center' }),
|
|
151
|
+
],
|
|
152
|
+
parameters: { layout: 'fullscreen' },
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export default meta;
|