@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
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxos-theme';
|
|
6
|
+
|
|
7
|
+
import React, { useEffect, useState } from 'react';
|
|
8
|
+
|
|
9
|
+
import { useSpace } from '@dxos/react-client/echo';
|
|
10
|
+
import { withClientProvider } from '@dxos/react-client/testing';
|
|
11
|
+
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
12
|
+
import { withTheme } from '@dxos/storybook-utils';
|
|
13
|
+
|
|
14
|
+
import { ComputeGraphContextProvider } from '../components';
|
|
15
|
+
import { createSheet } from '../defs';
|
|
16
|
+
import { useComputeGraph, useSheetModel } from '../hooks';
|
|
17
|
+
import { withComputeGraphDecorator } from '../testing';
|
|
18
|
+
import { SheetType } from '../types';
|
|
19
|
+
|
|
20
|
+
const Story = () => {
|
|
21
|
+
const space = useSpace();
|
|
22
|
+
const graph = useComputeGraph(space);
|
|
23
|
+
const [sheet, setSheet] = useState<SheetType>();
|
|
24
|
+
const model = useSheetModel(graph, sheet);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
if (space) {
|
|
27
|
+
const sheet = space.db.add(createSheet());
|
|
28
|
+
setSheet(sheet);
|
|
29
|
+
}
|
|
30
|
+
}, [space]);
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<SyntaxHighlighter language='json'>
|
|
34
|
+
{JSON.stringify({ space: space?.id, graph: graph?.id, sheet: sheet?.id, model: model?.id }, null, 2)}
|
|
35
|
+
</SyntaxHighlighter>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default {
|
|
40
|
+
title: 'plugin-sheet/hooks',
|
|
41
|
+
component: ComputeGraphContextProvider,
|
|
42
|
+
decorators: [
|
|
43
|
+
withClientProvider({ types: [SheetType], createIdentity: true, createSpace: true }),
|
|
44
|
+
withComputeGraphDecorator(),
|
|
45
|
+
withTheme,
|
|
46
|
+
],
|
|
47
|
+
render: (args: any) => <Story {...args} />,
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const Default = {};
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { effect } from '@preact/signals-core';
|
|
6
|
+
import { type MutableRefObject, useCallback, useEffect, useMemo } from 'react';
|
|
7
|
+
|
|
8
|
+
import { type IntentResolver, LayoutAction, useIntentDispatcher, useIntentResolver } from '@dxos/app-framework';
|
|
9
|
+
import { debounce } from '@dxos/async';
|
|
10
|
+
import { fullyQualifiedId } from '@dxos/react-client/echo';
|
|
11
|
+
import { type DxGridElement, type DxGridPosition } from '@dxos/react-ui-grid';
|
|
12
|
+
|
|
13
|
+
import { addressFromIndex, addressToIndex, type CellAddress, closest } from '../defs';
|
|
14
|
+
import { SHEET_PLUGIN } from '../meta';
|
|
15
|
+
import { type SheetModel, type Decoration, type Decorations } from '../model';
|
|
16
|
+
|
|
17
|
+
export const useUpdateFocusedCellOnThreadSelection = (
|
|
18
|
+
model: SheetModel,
|
|
19
|
+
grid: MutableRefObject<DxGridElement | null>,
|
|
20
|
+
) => {
|
|
21
|
+
const handleScrollIntoView: IntentResolver = useCallback(
|
|
22
|
+
({ action, data }) => {
|
|
23
|
+
switch (action) {
|
|
24
|
+
case LayoutAction.SCROLL_INTO_VIEW: {
|
|
25
|
+
if (!data?.id || data?.cursor === undefined || data?.id !== fullyQualifiedId(model.sheet)) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// TODO(Zan): Everywhere we refer to the cursor in a thread context should change to `anchor`.
|
|
30
|
+
const cellAddress = addressFromIndex(model.sheet, data.cursor);
|
|
31
|
+
grid.current?.setFocus({ ...cellAddress, plane: 'grid' }, true);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
[model.sheet],
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
useIntentResolver(SHEET_PLUGIN, handleScrollIntoView);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const useSelectThreadOnCellFocus = (model: SheetModel, cursor?: CellAddress) => {
|
|
42
|
+
const dispatch = useIntentDispatcher();
|
|
43
|
+
|
|
44
|
+
const activeThreads = useMemo(
|
|
45
|
+
() =>
|
|
46
|
+
model.sheet.threads?.filter(
|
|
47
|
+
(thread): thread is NonNullable<typeof thread> => !!thread && thread.status === 'active',
|
|
48
|
+
) ?? [],
|
|
49
|
+
[
|
|
50
|
+
// TODO(thure): Surely we can find a better dependency for this…
|
|
51
|
+
JSON.stringify(model.sheet.threads),
|
|
52
|
+
],
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const activeThreadAddresses = useMemo(
|
|
56
|
+
() =>
|
|
57
|
+
activeThreads
|
|
58
|
+
.map((thread) => thread.anchor)
|
|
59
|
+
.filter((anchor): anchor is NonNullable<typeof anchor> => anchor !== undefined)
|
|
60
|
+
.map((anchor) => addressFromIndex(model.sheet, anchor)),
|
|
61
|
+
[activeThreads, model.sheet],
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const selectClosestThread = useCallback(
|
|
65
|
+
(cellAddress: CellAddress) => {
|
|
66
|
+
if (!cellAddress || !activeThreads) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const closestThreadAnchor = closest(cellAddress, activeThreadAddresses);
|
|
71
|
+
if (closestThreadAnchor) {
|
|
72
|
+
const closestThread = activeThreads.find(
|
|
73
|
+
(thread) => thread && thread.anchor === addressToIndex(model.sheet, closestThreadAnchor),
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
if (closestThread) {
|
|
77
|
+
void dispatch([
|
|
78
|
+
{ action: 'dxos.org/plugin/thread/action/select', data: { current: fullyQualifiedId(closestThread) } },
|
|
79
|
+
]);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
[dispatch, activeThreads, activeThreadAddresses, model.sheet],
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const debounced = useMemo(() => {
|
|
87
|
+
return debounce((cellCoords: DxGridPosition) => requestAnimationFrame(() => selectClosestThread(cellCoords)), 50);
|
|
88
|
+
}, [selectClosestThread]);
|
|
89
|
+
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
if (!cursor) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
debounced(cursor);
|
|
95
|
+
}, [cursor, selectClosestThread]);
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const createThreadDecoration = (cellIndex: string, threadId: string, sheetId: string): Decoration => {
|
|
99
|
+
return {
|
|
100
|
+
type: 'comment',
|
|
101
|
+
classNames: ['bg-greenFill'],
|
|
102
|
+
cellIndex,
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const useThreadDecorations = (model: SheetModel, decorations: Decorations) => {
|
|
107
|
+
const sheet = useMemo(() => model.sheet, [model.sheet]);
|
|
108
|
+
const sheetId = useMemo(() => fullyQualifiedId(sheet), [sheet]);
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
const unsubscribe = effect(() => {
|
|
112
|
+
const activeThreadAnchors = new Set<string>();
|
|
113
|
+
if (!sheet.threads) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Process active threads
|
|
118
|
+
for (const thread of sheet.threads) {
|
|
119
|
+
if (!thread || thread.anchor === undefined || thread.status === 'resolved') {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
activeThreadAnchors.add(thread.anchor);
|
|
124
|
+
const index = thread.anchor;
|
|
125
|
+
|
|
126
|
+
// Add decoration only if it doesn't already exist
|
|
127
|
+
const existingDecorations = decorations.getDecorationsForCell(index);
|
|
128
|
+
if (!existingDecorations || !existingDecorations.some((d) => d.type === 'comment')) {
|
|
129
|
+
decorations.addDecoration(index, createThreadDecoration(index, thread.id, sheetId));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Remove decorations for resolved or deleted threads
|
|
134
|
+
for (const decoration of decorations.getAllDecorations()) {
|
|
135
|
+
if (decoration.type !== 'comment') {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!activeThreadAnchors.has(decoration.cellIndex)) {
|
|
140
|
+
decorations.removeDecoration(decoration.cellIndex, 'comment');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return () => unsubscribe();
|
|
146
|
+
});
|
|
147
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useContext } from 'react';
|
|
6
|
+
|
|
7
|
+
import { raise } from '@dxos/debug';
|
|
8
|
+
import { type Space } from '@dxos/react-client/echo';
|
|
9
|
+
import { useAsyncState } from '@dxos/react-hooks';
|
|
10
|
+
|
|
11
|
+
import { ComputeGraphContext } from '../components';
|
|
12
|
+
import { type ComputeGraph } from '../graph';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Get existing or create new compute graph for the given space.
|
|
16
|
+
*/
|
|
17
|
+
export const useComputeGraph = (space?: Space): ComputeGraph | undefined => {
|
|
18
|
+
const { registry } = useContext(ComputeGraphContext) ?? raise(new Error('Missing ComputeGraphContext'));
|
|
19
|
+
const [graph] = useAsyncState(async () => {
|
|
20
|
+
if (space) {
|
|
21
|
+
const graph = registry.getOrCreateGraph(space);
|
|
22
|
+
await graph.open();
|
|
23
|
+
return graph;
|
|
24
|
+
}
|
|
25
|
+
}, [space, registry]);
|
|
26
|
+
|
|
27
|
+
return graph;
|
|
28
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type SheetModel, FormattingModel } from '../model';
|
|
8
|
+
|
|
9
|
+
export const useFormattingModel = (model: SheetModel | undefined): FormattingModel | undefined => {
|
|
10
|
+
return useMemo(() => model && new FormattingModel(model), [model]);
|
|
11
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type ComputeGraph } from '../graph';
|
|
8
|
+
import { SheetModel } from '../model';
|
|
9
|
+
import { type SheetType } from '../types';
|
|
10
|
+
|
|
11
|
+
export type UseSheetModelOptions = {
|
|
12
|
+
readonly?: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const useSheetModel = (
|
|
16
|
+
graph?: ComputeGraph,
|
|
17
|
+
sheet?: SheetType,
|
|
18
|
+
{ readonly }: UseSheetModelOptions = {},
|
|
19
|
+
): SheetModel | undefined => {
|
|
20
|
+
const [model, setModel] = useState<SheetModel>();
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!graph || !sheet) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
let model: SheetModel | undefined;
|
|
27
|
+
const t = setTimeout(async () => {
|
|
28
|
+
model = new SheetModel(graph, sheet, { readonly });
|
|
29
|
+
await model.open();
|
|
30
|
+
setModel(model);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
return () => {
|
|
34
|
+
clearTimeout(t);
|
|
35
|
+
void model?.close();
|
|
36
|
+
};
|
|
37
|
+
}, [graph, sheet, readonly]);
|
|
38
|
+
|
|
39
|
+
return model;
|
|
40
|
+
};
|
package/src/meta.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type PluginMeta } from '@dxos/app-framework';
|
|
6
|
+
|
|
7
|
+
export const SHEET_PLUGIN = 'dxos.org/plugin/sheet';
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
id: SHEET_PLUGIN,
|
|
11
|
+
name: 'Sheet',
|
|
12
|
+
description: 'A simple spreadsheet plugin.',
|
|
13
|
+
icon: 'ph--grid-nine--regular',
|
|
14
|
+
} satisfies PluginMeta;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { create } from '@dxos/echo-schema';
|
|
6
|
+
|
|
7
|
+
export type Decoration = {
|
|
8
|
+
type: string;
|
|
9
|
+
/**
|
|
10
|
+
* A wrapping render function to encapsulate cell content. This function is applied between
|
|
11
|
+
* the cell's border and its padding/layout/content, allowing for custom rendering or
|
|
12
|
+
* additional elements to be inserted around the cell's main content.
|
|
13
|
+
*/
|
|
14
|
+
decorate?: (props: { children: React.ReactNode }) => React.ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* An array of CSS class names to be applied to the content of the SheetCell.
|
|
17
|
+
* These classes can be used to style the cell's content independently of its structure.
|
|
18
|
+
*/
|
|
19
|
+
classNames?: string[];
|
|
20
|
+
cellIndex: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const createDecorations = () => {
|
|
24
|
+
// Reactive object to hold decorations
|
|
25
|
+
// TODO(Zan): Use CELL ID's to key the decoration map.
|
|
26
|
+
// TODO(Zan): Consider maintaining an index of decorations by type.
|
|
27
|
+
const { decorations } = create<{ decorations: Record<string, Decoration[]> }>({ decorations: {} });
|
|
28
|
+
|
|
29
|
+
const addDecoration = (cellIndex: string, decorator: Decoration) => {
|
|
30
|
+
decorations[cellIndex] = [...(decorations[cellIndex] || []), decorator];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const removeDecoration = (cellIndex: string, type?: string) => {
|
|
34
|
+
if (type) {
|
|
35
|
+
decorations[cellIndex] = (decorations[cellIndex] || []).filter((d) => d.type !== type);
|
|
36
|
+
} else {
|
|
37
|
+
delete decorations[cellIndex];
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// TODO(Zan): I should check if returning the a value from a map in a deep signal is a reactive slice.
|
|
42
|
+
const getDecorationsForCell = (cellIndex: string): Decoration[] | undefined => {
|
|
43
|
+
return decorations[cellIndex];
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const getAllDecorations = (): Decoration[] => {
|
|
47
|
+
const result: Decoration[] = [];
|
|
48
|
+
for (const decoratorArray of Object.values(decorations)) {
|
|
49
|
+
for (const decorator of decoratorArray) {
|
|
50
|
+
result.push(decorator);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
addDecoration,
|
|
58
|
+
removeDecoration,
|
|
59
|
+
getDecorationsForCell,
|
|
60
|
+
getAllDecorations,
|
|
61
|
+
} as const;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type Decorations = ReturnType<typeof createDecorations>;
|
|
@@ -3,18 +3,28 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type ClassNameValue } from '@dxos/react-ui-types';
|
|
6
|
+
import { FieldValueType } from '@dxos/schema';
|
|
6
7
|
|
|
7
|
-
import { type SheetModel
|
|
8
|
-
import {
|
|
8
|
+
import { type SheetModel } from './sheet-model';
|
|
9
|
+
import { type CellAddress, inRange } from '../defs';
|
|
10
|
+
import { addressToIndex, rangeFromIndex } from '../defs';
|
|
9
11
|
|
|
12
|
+
export type CellFormat = {
|
|
13
|
+
value?: string;
|
|
14
|
+
classNames?: ClassNameValue;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated See react-ui-data.
|
|
19
|
+
*/
|
|
10
20
|
export class FormattingModel {
|
|
11
|
-
constructor(private readonly
|
|
21
|
+
constructor(private readonly _model: SheetModel) {}
|
|
12
22
|
|
|
13
23
|
/**
|
|
14
24
|
* Get formatted string value and className for cell.
|
|
15
25
|
*/
|
|
16
|
-
getFormatting(cell: CellAddress):
|
|
17
|
-
const value = this.
|
|
26
|
+
getFormatting(cell: CellAddress): CellFormat {
|
|
27
|
+
const value = this._model.getValue(cell);
|
|
18
28
|
if (value === undefined || value === null) {
|
|
19
29
|
return {};
|
|
20
30
|
}
|
|
@@ -23,15 +33,15 @@ export class FormattingModel {
|
|
|
23
33
|
const locales = undefined;
|
|
24
34
|
|
|
25
35
|
// Cell-specific formatting.
|
|
26
|
-
const idx = this.
|
|
27
|
-
let formatting = this.
|
|
36
|
+
const idx = addressToIndex(this._model.sheet, cell);
|
|
37
|
+
let formatting = this._model.sheet.formatting.find?.(({ range }) => range === idx);
|
|
28
38
|
const classNames = [...(formatting?.classNames ?? [])];
|
|
29
39
|
|
|
30
40
|
// Range formatting.
|
|
31
41
|
// TODO(burdon): NOTE: D0 means the D column.
|
|
32
42
|
// TODO(burdon): Cache model formatting (e.g., for ranges). Create class out of this function.
|
|
33
|
-
for (const [idx, _formatting] of Object.entries(this.
|
|
34
|
-
const range = this.
|
|
43
|
+
for (const [idx, _formatting] of Object.entries(this._model.sheet.formatting)) {
|
|
44
|
+
const range = rangeFromIndex(this._model.sheet, idx);
|
|
35
45
|
if (inRange(range, cell)) {
|
|
36
46
|
if (_formatting.classNames) {
|
|
37
47
|
classNames.push(..._formatting.classNames);
|
|
@@ -46,9 +56,9 @@ export class FormattingModel {
|
|
|
46
56
|
|
|
47
57
|
const defaultNumber = 'justify-end font-mono';
|
|
48
58
|
|
|
49
|
-
const type = formatting?.type ?? this.
|
|
59
|
+
const type = formatting?.type ?? this._model.getValueType(cell);
|
|
50
60
|
switch (type) {
|
|
51
|
-
case
|
|
61
|
+
case FieldValueType.Boolean: {
|
|
52
62
|
return {
|
|
53
63
|
value: (value as boolean).toLocaleString().toUpperCase(),
|
|
54
64
|
classNames: [...classNames, value ? '!text-greenText' : '!text-orangeText'],
|
|
@@ -59,15 +69,15 @@ export class FormattingModel {
|
|
|
59
69
|
// Numbers.
|
|
60
70
|
//
|
|
61
71
|
|
|
62
|
-
case
|
|
72
|
+
case FieldValueType.Number: {
|
|
63
73
|
return { value: value.toLocaleString(locales), classNames: [...classNames, defaultNumber] };
|
|
64
74
|
}
|
|
65
75
|
|
|
66
|
-
case
|
|
76
|
+
case FieldValueType.Percent: {
|
|
67
77
|
return { value: (value as number) * 100 + '%', classNames: [...classNames, defaultNumber] };
|
|
68
78
|
}
|
|
69
79
|
|
|
70
|
-
case
|
|
80
|
+
case FieldValueType.Currency: {
|
|
71
81
|
return {
|
|
72
82
|
value: (value as number).toLocaleString(locales, {
|
|
73
83
|
style: 'currency',
|
|
@@ -83,18 +93,18 @@ export class FormattingModel {
|
|
|
83
93
|
// Dates.
|
|
84
94
|
//
|
|
85
95
|
|
|
86
|
-
case
|
|
87
|
-
const date = this.
|
|
96
|
+
case FieldValueType.DateTime: {
|
|
97
|
+
const date = this._model.toLocalDate(value as number);
|
|
88
98
|
return { value: date.toLocaleString(locales), classNames };
|
|
89
99
|
}
|
|
90
100
|
|
|
91
|
-
case
|
|
92
|
-
const date = this.
|
|
101
|
+
case FieldValueType.Date: {
|
|
102
|
+
const date = this._model.toLocalDate(value as number);
|
|
93
103
|
return { value: date.toLocaleDateString(locales), classNames };
|
|
94
104
|
}
|
|
95
105
|
|
|
96
|
-
case
|
|
97
|
-
const date = this.
|
|
106
|
+
case FieldValueType.Time: {
|
|
107
|
+
const date = this._model.toLocalDate(value as number);
|
|
98
108
|
return { value: date.toLocaleTimeString(locales), classNames };
|
|
99
109
|
}
|
|
100
110
|
|
package/src/model/index.ts
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { Trigger } from '@dxos/async';
|
|
8
|
+
import { FunctionType } from '@dxos/plugin-script/types';
|
|
9
|
+
|
|
10
|
+
import { SheetModel } from './sheet-model';
|
|
11
|
+
import { addressFromA1Notation, createSheet } from '../defs';
|
|
12
|
+
import { TestBuilder, testFunctionPlugins } from '../graph/testing';
|
|
13
|
+
import { type CellScalarValue } from '../types';
|
|
14
|
+
|
|
15
|
+
describe('SheetModel', () => {
|
|
16
|
+
let testBuilder: TestBuilder;
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
testBuilder = new TestBuilder({ types: [FunctionType], plugins: testFunctionPlugins });
|
|
19
|
+
await testBuilder.open();
|
|
20
|
+
});
|
|
21
|
+
afterEach(async () => {
|
|
22
|
+
await testBuilder.close();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('async function', async () => {
|
|
26
|
+
const space = await testBuilder.client.spaces.create();
|
|
27
|
+
const graph = testBuilder.registry.createGraph(space);
|
|
28
|
+
await graph.open();
|
|
29
|
+
|
|
30
|
+
// TODO(burdon): Create via factory.
|
|
31
|
+
const sheet = createSheet({ rows: 5, columns: 5 });
|
|
32
|
+
const model = new SheetModel(graph, sheet);
|
|
33
|
+
await model.open();
|
|
34
|
+
testBuilder.ctx.onDispose(() => model.close());
|
|
35
|
+
|
|
36
|
+
// Trigger waits for function invocation.
|
|
37
|
+
const trigger = new Trigger<CellScalarValue>();
|
|
38
|
+
model.setValue(addressFromA1Notation('A1'), '=TEST(100)');
|
|
39
|
+
model.update.once((update) => {
|
|
40
|
+
const { type } = update;
|
|
41
|
+
if (type === 'valuesUpdated') {
|
|
42
|
+
const value = model.getValue(addressFromA1Notation('A1'));
|
|
43
|
+
trigger.wake(value);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Initial value will be null.
|
|
48
|
+
const v1 = model.getValue(addressFromA1Notation('A1'));
|
|
49
|
+
expect(v1).to.be.null;
|
|
50
|
+
expect(graph.context.info.invocations.TEST).not.to.exist;
|
|
51
|
+
|
|
52
|
+
// Wait until async update triggered.
|
|
53
|
+
const v2 = await trigger.wait();
|
|
54
|
+
expect(v2).to.eq(100);
|
|
55
|
+
expect(graph.context.info.invocations.TEST).to.eq(1);
|
|
56
|
+
});
|
|
57
|
+
});
|