@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,87 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type CellValue } from 'hyperformula';
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { Trigger } from '@dxos/async';
|
|
9
|
+
import { create, fullyQualifiedId } from '@dxos/client/echo';
|
|
10
|
+
import { FunctionType } from '@dxos/plugin-script/types';
|
|
11
|
+
|
|
12
|
+
import { DetailedCellError } from '#hyperformula';
|
|
13
|
+
import { TestBuilder } from './testing';
|
|
14
|
+
|
|
15
|
+
describe('ComputeGraph', () => {
|
|
16
|
+
let testBuilder: TestBuilder;
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
testBuilder = new TestBuilder({ types: [FunctionType] });
|
|
19
|
+
await testBuilder.open();
|
|
20
|
+
});
|
|
21
|
+
afterEach(async () => {
|
|
22
|
+
await testBuilder.close();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('map functions', async () => {
|
|
26
|
+
const space = await testBuilder.client.spaces.create();
|
|
27
|
+
const graph = testBuilder.registry.createGraph(space);
|
|
28
|
+
await graph.open();
|
|
29
|
+
|
|
30
|
+
// Create script.
|
|
31
|
+
const trigger = new Trigger();
|
|
32
|
+
graph.update.once(() => trigger.wake());
|
|
33
|
+
const functionObject = space.db.add(create(FunctionType, { version: 1, binding: 'TEST' }));
|
|
34
|
+
await trigger.wait();
|
|
35
|
+
const functions = graph.getFunctions({ echo: true });
|
|
36
|
+
expect(functions).to.toHaveLength(1);
|
|
37
|
+
|
|
38
|
+
const id = graph.mapFunctionBindingToId('TEST()');
|
|
39
|
+
expect(id).to.eq(`${fullyQualifiedId(functionObject)}()`);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test('cross-node references', async () => {
|
|
43
|
+
const space = await testBuilder.client.spaces.create();
|
|
44
|
+
const graph = testBuilder.registry.createGraph(space);
|
|
45
|
+
|
|
46
|
+
// Create nodes.
|
|
47
|
+
const node1 = await graph.getOrCreateNode('node-1').open();
|
|
48
|
+
const node2 = await graph.getOrCreateNode('node-2').open();
|
|
49
|
+
expect(graph.hf.getSheetNames()).to.toHaveLength(2);
|
|
50
|
+
|
|
51
|
+
{
|
|
52
|
+
node1.graph.hf.setCellContents({ sheet: node1.sheetId, row: 0, col: 0 }, [[100, 200, 300, '=SUM(A1:C1)']]);
|
|
53
|
+
node2.graph.hf.setCellContents({ sheet: node2.sheetId, row: 0, col: 0 }, "='node-1'!D1");
|
|
54
|
+
const value1 = node1.graph.hf.getCellValue({ sheet: node1.sheetId, col: 3, row: 0 });
|
|
55
|
+
const value2 = node2.graph.hf.getCellValue({ sheet: node2.sheetId, col: 0, row: 0 });
|
|
56
|
+
expect(value1).to.eq(value2);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Get updated event.
|
|
60
|
+
const trigger = new Trigger<CellValue>();
|
|
61
|
+
node2.update.on(({ change }) => {
|
|
62
|
+
const value = node2.graph.hf.getCellValue({ sheet: node2.sheetId, col: 0, row: 0 });
|
|
63
|
+
expect(value).to.eq(change?.newValue);
|
|
64
|
+
trigger.wake(value);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
{
|
|
68
|
+
node1.graph.hf.setCellContents({ sheet: node1.sheetId, row: 0, col: 0 }, 400);
|
|
69
|
+
const value1 = node1.graph.hf.getCellValue({ sheet: node1.sheetId, col: 3, row: 0 });
|
|
70
|
+
const value2 = await trigger.wait();
|
|
71
|
+
expect(value1).to.eq(value2);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// TODO(burdon): Dynamically load node/model based on dependencies.
|
|
76
|
+
// - Create dependency then close model.
|
|
77
|
+
test('dynamic loading', async () => {
|
|
78
|
+
const space = await testBuilder.client.spaces.create();
|
|
79
|
+
const graph = testBuilder.registry.createGraph(space);
|
|
80
|
+
|
|
81
|
+
const node1 = await graph.getOrCreateNode('node-1').open();
|
|
82
|
+
node1.graph.hf.setCellContents({ sheet: node1.sheetId, row: 0, col: 0 }, "='node-2'!A1");
|
|
83
|
+
const value1 = node1.graph.hf.getCellValue({ sheet: node1.sheetId, col: 0, row: 0 });
|
|
84
|
+
expect(value1).to.be.instanceof(DetailedCellError);
|
|
85
|
+
expect((value1 as DetailedCellError).type).to.eq('REF');
|
|
86
|
+
});
|
|
87
|
+
});
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Listeners } from 'hyperformula/typings/Emitter';
|
|
6
|
+
|
|
7
|
+
import { Event } from '@dxos/async';
|
|
8
|
+
import { type Space, Filter, fullyQualifiedId } from '@dxos/client/echo';
|
|
9
|
+
import { FQ_ID_LENGTH } from '@dxos/client/echo';
|
|
10
|
+
import { Resource } from '@dxos/context';
|
|
11
|
+
import { getTypename } from '@dxos/echo-schema';
|
|
12
|
+
import { invariant } from '@dxos/invariant';
|
|
13
|
+
import { PublicKey } from '@dxos/keys';
|
|
14
|
+
import { log } from '@dxos/log';
|
|
15
|
+
import { FunctionType } from '@dxos/plugin-script/types';
|
|
16
|
+
import { nonNullable } from '@dxos/util';
|
|
17
|
+
|
|
18
|
+
import { ExportedCellChange, type HyperFormula } from '#hyperformula';
|
|
19
|
+
import { ComputeNode } from './compute-node';
|
|
20
|
+
import {
|
|
21
|
+
defaultFunctions,
|
|
22
|
+
FunctionContext,
|
|
23
|
+
type FunctionContextOptions,
|
|
24
|
+
type FunctionDefinition,
|
|
25
|
+
EDGE_FUNCTION_NAME,
|
|
26
|
+
} from './functions';
|
|
27
|
+
|
|
28
|
+
// TODO(burdon): Factor out compute-graph.
|
|
29
|
+
|
|
30
|
+
const UNKNOWN_BINDING = '__UNKNOWN__';
|
|
31
|
+
|
|
32
|
+
// TODO(burdon): Factory.
|
|
33
|
+
// export type ComputeNodeGenerator = <T>(obj: T) => ComputeNode;
|
|
34
|
+
|
|
35
|
+
type ObjectRef = { type: string; id: string };
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Marker for sheets that are managed by an ECHO object.
|
|
39
|
+
* Sheet ID: `dxos.org/type/SheetType@1234`
|
|
40
|
+
*/
|
|
41
|
+
export const createSheetName = ({ type, id }: ObjectRef) => `${type}@${id}`;
|
|
42
|
+
export const parseSheetName = (name: string): Partial<ObjectRef> => {
|
|
43
|
+
const [type, id] = name.split('@');
|
|
44
|
+
return id ? { type, id } : { id: type };
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export type ComputeGraphEvent = 'functionsUpdated' | 'valuesUpdated';
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Per-space compute and dependency graph.
|
|
51
|
+
* Consists of multiple ComputeNode (corresponding to a HyperFormula sheet).
|
|
52
|
+
* Manages the set of custom functions.
|
|
53
|
+
* HyperFormula manages the dependency graph.
|
|
54
|
+
*/
|
|
55
|
+
export class ComputeGraph extends Resource {
|
|
56
|
+
public readonly id = `graph-${PublicKey.random().truncate()}`;
|
|
57
|
+
|
|
58
|
+
// Map of nodes indexed by sheet number.
|
|
59
|
+
private readonly _nodes = new Map<number, ComputeNode>();
|
|
60
|
+
|
|
61
|
+
// Cached function objects.
|
|
62
|
+
private _remoteFunctions: FunctionType[] = [];
|
|
63
|
+
|
|
64
|
+
public readonly update = new Event<{ type: ComputeGraphEvent }>();
|
|
65
|
+
|
|
66
|
+
// The context is passed to all functions.
|
|
67
|
+
public readonly context: FunctionContext;
|
|
68
|
+
|
|
69
|
+
constructor(
|
|
70
|
+
private readonly _hf: HyperFormula,
|
|
71
|
+
private readonly _space?: Space,
|
|
72
|
+
private readonly _options?: Partial<FunctionContextOptions>,
|
|
73
|
+
) {
|
|
74
|
+
super();
|
|
75
|
+
|
|
76
|
+
const contextOptions = {
|
|
77
|
+
...this._options,
|
|
78
|
+
onUpdate: (update) => {
|
|
79
|
+
this._options?.onUpdate?.(update);
|
|
80
|
+
this.update.emit({ type: 'valuesUpdated' });
|
|
81
|
+
},
|
|
82
|
+
} satisfies Partial<FunctionContextOptions>;
|
|
83
|
+
this.context = new FunctionContext(this._hf, this._space, contextOptions);
|
|
84
|
+
this._hf.updateConfig({ context: this.context });
|
|
85
|
+
|
|
86
|
+
// TODO(burdon): If debounce then aggregate changes.
|
|
87
|
+
const onValuesUpdate: Listeners['valuesUpdated'] = (changes) => {
|
|
88
|
+
for (const change of changes) {
|
|
89
|
+
if (change instanceof ExportedCellChange) {
|
|
90
|
+
const { sheet } = change;
|
|
91
|
+
const node = this._nodes.get(sheet);
|
|
92
|
+
if (node) {
|
|
93
|
+
node.update.emit({ type: 'valuesUpdated', change });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
this._hf.on('valuesUpdated', onValuesUpdate);
|
|
100
|
+
this._ctx.onDispose(() => this._hf.off('valuesUpdated', onValuesUpdate));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
get hf() {
|
|
104
|
+
return this._hf;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
getFunctions(
|
|
108
|
+
{ standard, echo }: { standard?: boolean; echo?: boolean } = { standard: true, echo: true },
|
|
109
|
+
): FunctionDefinition[] {
|
|
110
|
+
return [
|
|
111
|
+
...(standard
|
|
112
|
+
? this._hf
|
|
113
|
+
.getRegisteredFunctionNames()
|
|
114
|
+
.map((name) => defaultFunctions.find((fn) => fn.name === name) ?? { name })
|
|
115
|
+
: []),
|
|
116
|
+
...(echo ? this._remoteFunctions.map((fn) => ({ name: fn.binding! })) : []),
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Get or create cell representing a sheet.
|
|
122
|
+
*/
|
|
123
|
+
// TODO(burdon): Async (open node).
|
|
124
|
+
// The graph should be an extensible factory that plugins extend with model constructors.
|
|
125
|
+
// This would enable on-the-fly instantiation of new models when then are referenced.
|
|
126
|
+
// E.g., Cross-object reference would be stored as "ObjectId!A1"
|
|
127
|
+
// The graph would then load the object and create a ComputeNode (model) of the appropriate type.
|
|
128
|
+
getOrCreateNode(name: string): ComputeNode {
|
|
129
|
+
invariant(name.length);
|
|
130
|
+
if (!this._hf.doesSheetExist(name)) {
|
|
131
|
+
log('created node', { space: this._space?.id, sheet: name });
|
|
132
|
+
this._hf.addSheet(name);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const sheetId = this._hf.getSheetId(name);
|
|
136
|
+
invariant(sheetId !== undefined);
|
|
137
|
+
|
|
138
|
+
const node = new ComputeNode(this, sheetId);
|
|
139
|
+
this._nodes.set(sheetId, node);
|
|
140
|
+
return node;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Map bound value to custom function invocation.
|
|
145
|
+
* E.g., "HELLO(...args)" => "DX("HELLO", ...args)".
|
|
146
|
+
*/
|
|
147
|
+
mapFormulaToNative(formula: string): string {
|
|
148
|
+
return (
|
|
149
|
+
formula
|
|
150
|
+
//
|
|
151
|
+
// Map cross-sheet references by name onto sheet stored by ECHO object/model.
|
|
152
|
+
// Example: "Test Sheet"!A0 => "dxos.org/type/SheetType@1234"!A0
|
|
153
|
+
// https://hyperformula.handsontable.com/guide/cell-references.html#cell-references
|
|
154
|
+
//
|
|
155
|
+
.replace(/['"]?([ \w]+)['"]?!/, (_match, name) => {
|
|
156
|
+
if (name) {
|
|
157
|
+
// TODO(burdon): Cache map.
|
|
158
|
+
const objects = this._hf
|
|
159
|
+
.getSheetNames()
|
|
160
|
+
.map((name) => {
|
|
161
|
+
const { type, id } = parseSheetName(name);
|
|
162
|
+
return type && id ? this._space?.db.getObjectById(id) : undefined;
|
|
163
|
+
})
|
|
164
|
+
.filter(nonNullable);
|
|
165
|
+
|
|
166
|
+
for (const obj of objects) {
|
|
167
|
+
if (obj.name === name) {
|
|
168
|
+
const type = getTypename(obj)!;
|
|
169
|
+
// NOTE: Names must be single quoted.
|
|
170
|
+
return `'${createSheetName({ type, id: obj.id })}'!`;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return `${name}!`;
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
//
|
|
179
|
+
// Map remote function references (i.e., to remote DX function invocation).
|
|
180
|
+
//
|
|
181
|
+
.replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
|
|
182
|
+
const fn = this._remoteFunctions.find((fn) => fn.binding === binding);
|
|
183
|
+
if (!fn) {
|
|
184
|
+
return match;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (args.trim() === '') {
|
|
188
|
+
return `${EDGE_FUNCTION_NAME}("${binding}")`;
|
|
189
|
+
} else {
|
|
190
|
+
return `${EDGE_FUNCTION_NAME}("${binding}", ${args})`;
|
|
191
|
+
}
|
|
192
|
+
})
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Map from binding to fully qualified ECHO ID (to store).
|
|
198
|
+
* E.g., HELLO() => spaceId:objectId()
|
|
199
|
+
*/
|
|
200
|
+
mapFunctionBindingToId(formula: string) {
|
|
201
|
+
return formula.replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
|
|
202
|
+
if (binding === EDGE_FUNCTION_NAME || defaultFunctions.find((fn) => fn.name === binding)) {
|
|
203
|
+
return match;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const fn = this._remoteFunctions.find((fn) => fn.binding === binding);
|
|
207
|
+
if (fn) {
|
|
208
|
+
const id = fullyQualifiedId(fn);
|
|
209
|
+
return `${id}(${args})`;
|
|
210
|
+
} else {
|
|
211
|
+
return match;
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Map from fully qualified ECHO ID to binding (from store).
|
|
218
|
+
* E.g., spaceId:objectId() => HELLO()
|
|
219
|
+
*/
|
|
220
|
+
mapFunctionBindingFromId(formula: string) {
|
|
221
|
+
const binding = formula.replace(/(\w+):([a-zA-Z0-9]+)\((.*)\)/g, (match, spaceId, objectId, args) => {
|
|
222
|
+
const id = `${spaceId}:${objectId}`;
|
|
223
|
+
if (id.length !== FQ_ID_LENGTH) {
|
|
224
|
+
return match;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const fn = this._remoteFunctions.find((fn) => fullyQualifiedId(fn) === id);
|
|
228
|
+
if (fn?.binding) {
|
|
229
|
+
return `${fn.binding}(${args})`;
|
|
230
|
+
} else {
|
|
231
|
+
return UNKNOWN_BINDING;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
if (binding.startsWith(`=${UNKNOWN_BINDING}`)) {
|
|
236
|
+
return undefined;
|
|
237
|
+
} else {
|
|
238
|
+
return binding;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
protected override async _open() {
|
|
243
|
+
if (this._space) {
|
|
244
|
+
// Subscribe to remote function definitions.
|
|
245
|
+
const query = this._space.db.query(Filter.schema(FunctionType));
|
|
246
|
+
const unsubscribe = query.subscribe(({ objects }) => {
|
|
247
|
+
this._remoteFunctions = objects.filter(({ binding }) => binding);
|
|
248
|
+
this.update.emit({ type: 'functionsUpdated' });
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
this._ctx.onDispose(unsubscribe);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
protected override async _close() {
|
|
256
|
+
for (const node of this._nodes.values()) {
|
|
257
|
+
await node.close();
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Listeners } from 'hyperformula/typings/Emitter';
|
|
6
|
+
import { type ExportedCellChange } from 'hyperformula/typings/Exporter';
|
|
7
|
+
|
|
8
|
+
import { Event } from '@dxos/async';
|
|
9
|
+
import { Resource } from '@dxos/context';
|
|
10
|
+
|
|
11
|
+
import { DetailedCellError } from '#hyperformula';
|
|
12
|
+
import { type ComputeGraph } from './compute-graph';
|
|
13
|
+
import { type CellAddress, isFormula } from '../defs';
|
|
14
|
+
import { type CellScalarValue } from '../types';
|
|
15
|
+
|
|
16
|
+
export type ComputeNodeEvent = {
|
|
17
|
+
type: keyof Listeners;
|
|
18
|
+
change?: ExportedCellChange;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Individual "sheet" (typically corresponds to an ECHO object).
|
|
23
|
+
*/
|
|
24
|
+
// TODO(burdon): Factor out common HF wrapper from from SheetModel.
|
|
25
|
+
export class ComputeNode extends Resource {
|
|
26
|
+
public readonly update = new Event<ComputeNodeEvent>();
|
|
27
|
+
|
|
28
|
+
constructor(
|
|
29
|
+
private readonly _graph: ComputeGraph,
|
|
30
|
+
public readonly sheetId: number,
|
|
31
|
+
) {
|
|
32
|
+
super();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get graph() {
|
|
36
|
+
return this._graph;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
clear() {
|
|
40
|
+
this._graph.hf.clearSheet(this.sheetId);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
getValue(cell: CellAddress): CellScalarValue {
|
|
44
|
+
const value = this._graph.hf.getCellValue({ sheet: this.sheetId, row: cell.row, col: cell.col });
|
|
45
|
+
if (value instanceof DetailedCellError) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
setValue(cell: CellAddress, value: CellScalarValue) {
|
|
53
|
+
const mappedValue = isFormula(value) ? this._graph.mapFormulaToNative(value) : value;
|
|
54
|
+
this._graph.hf.setCellContents({ sheet: this.sheetId, row: cell.row, col: cell.col }, [[mappedValue]]);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// TODO(burdon): Load data into sheet.
|
|
58
|
+
protected override async _open() {
|
|
59
|
+
// const unsubscribe = this._graph.update.on(this.update.emit);
|
|
60
|
+
// this._ctx.onDispose(unsubscribe);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { type SimpleCellAddress } from 'hyperformula/typings/Cell';
|
|
6
6
|
import { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';
|
|
7
7
|
import { type InterpreterValue } from 'hyperformula/typings/interpreter/InterpreterValue';
|
|
8
8
|
import { type ProcedureAst } from 'hyperformula/typings/parser';
|
|
@@ -12,28 +12,35 @@ import { debounce, type UnsubscribeCallback } from '@dxos/async';
|
|
|
12
12
|
import { type Space } from '@dxos/client/echo';
|
|
13
13
|
import { log } from '@dxos/log';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
import { CellError, ErrorType, EmptyValue, FunctionPlugin, type HyperFormula } from '#hyperformula';
|
|
16
|
+
|
|
17
|
+
// TODO(burdon): Create API gateways:
|
|
16
18
|
// https://publicapis.io
|
|
17
19
|
// https://api-ninjas.com/api/cryptoprice
|
|
18
20
|
// https://developers.google.com/apis-explorer
|
|
19
21
|
// https://publicapis.io/coin-desk-api
|
|
20
22
|
|
|
21
|
-
// TODO(burdon): Create wrapper.
|
|
22
23
|
export type AsyncFunction = (...args: any) => Promise<InterpreterValue>;
|
|
23
24
|
|
|
25
|
+
export type FunctionUpdateEvent = {
|
|
26
|
+
name: string;
|
|
27
|
+
cell: SimpleCellAddress;
|
|
28
|
+
};
|
|
29
|
+
|
|
24
30
|
export type FunctionOptions = {
|
|
25
31
|
ttl?: number;
|
|
26
32
|
};
|
|
27
33
|
|
|
28
34
|
export type FunctionContextOptions = {
|
|
29
35
|
defaultTtl: number;
|
|
30
|
-
|
|
36
|
+
debounceDelay: number;
|
|
31
37
|
remoteFunctionUrl: string;
|
|
38
|
+
onUpdate?: (update: FunctionUpdateEvent) => void;
|
|
32
39
|
};
|
|
33
40
|
|
|
34
41
|
export const defaultFunctionContextOptions: FunctionContextOptions = {
|
|
35
42
|
defaultTtl: 5_000,
|
|
36
|
-
|
|
43
|
+
debounceDelay: 200,
|
|
37
44
|
remoteFunctionUrl: 'https://edge.dxos.workers.dev/functions', // TODO(burdon): Config.
|
|
38
45
|
};
|
|
39
46
|
|
|
@@ -65,21 +72,22 @@ export class FunctionContext {
|
|
|
65
72
|
private _invocations: Record<string, number> = {};
|
|
66
73
|
|
|
67
74
|
private readonly _options: FunctionContextOptions;
|
|
68
|
-
|
|
75
|
+
|
|
76
|
+
// Debounced update handler.
|
|
77
|
+
private readonly _onUpdate: (update: FunctionUpdateEvent) => void;
|
|
69
78
|
|
|
70
79
|
constructor(
|
|
71
80
|
private readonly _hf: HyperFormula,
|
|
72
81
|
private readonly _space: Space | undefined,
|
|
73
|
-
onUpdate: (context: FunctionContext) => void,
|
|
74
82
|
_options?: Partial<FunctionContextOptions>,
|
|
75
83
|
) {
|
|
76
84
|
this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
|
|
77
|
-
this._onUpdate = debounce(() => {
|
|
78
|
-
|
|
79
|
-
//
|
|
85
|
+
this._onUpdate = debounce((update) => {
|
|
86
|
+
log('update', update);
|
|
87
|
+
// TODO(burdon): Better way to trigger recalculation? (NOTE: rebuildAndRecalculate resets the undo history.)
|
|
80
88
|
this._hf.resumeEvaluation();
|
|
81
|
-
onUpdate(
|
|
82
|
-
}, this._options.
|
|
89
|
+
this._options.onUpdate?.(update);
|
|
90
|
+
}, this._options.debounceDelay);
|
|
83
91
|
}
|
|
84
92
|
|
|
85
93
|
get space() {
|
|
@@ -134,7 +142,7 @@ export class FunctionContext {
|
|
|
134
142
|
const value = await cb(...args);
|
|
135
143
|
this._cache.set(invocationKey, { value, ts: Date.now() });
|
|
136
144
|
log('set', { cell, value });
|
|
137
|
-
this._onUpdate();
|
|
145
|
+
this._onUpdate({ name, cell });
|
|
138
146
|
} catch (err) {
|
|
139
147
|
// TODO(burdon): Show error to user.
|
|
140
148
|
log.warn('failed', { cell, err });
|
|
@@ -153,12 +161,15 @@ export class FunctionContext {
|
|
|
153
161
|
/**
|
|
154
162
|
* Base class for async functions.
|
|
155
163
|
*/
|
|
156
|
-
export class
|
|
164
|
+
export class AsyncFunctionPlugin extends FunctionPlugin {
|
|
157
165
|
get context() {
|
|
158
166
|
return this.config.context as FunctionContext;
|
|
159
167
|
}
|
|
160
168
|
|
|
161
|
-
|
|
169
|
+
/**
|
|
170
|
+
* Immediately returns cached value then runs the async function.
|
|
171
|
+
*/
|
|
172
|
+
protected runAsyncFunction(ast: ProcedureAst, state: InterpreterState, cb: AsyncFunction, options?: FunctionOptions) {
|
|
162
173
|
const { procedureName } = ast;
|
|
163
174
|
const metadata = this.metadata(procedureName);
|
|
164
175
|
return this.runFunction(ast.args, state, metadata, (...args: any) => {
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { effect } from '@preact/signals-core';
|
|
6
|
-
import { CellError, ErrorType, FunctionArgumentType } from 'hyperformula';
|
|
7
6
|
import { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';
|
|
8
7
|
import { type ProcedureAst } from 'hyperformula/typings/parser';
|
|
9
8
|
|
|
@@ -13,17 +12,20 @@ import { getUserFunctionUrlInMetadata } from '@dxos/plugin-script/edge';
|
|
|
13
12
|
import { FunctionType } from '@dxos/plugin-script/types';
|
|
14
13
|
import { nonNullable } from '@dxos/util';
|
|
15
14
|
|
|
16
|
-
import {
|
|
15
|
+
import { CellError, ErrorType, FunctionArgumentType } from '#hyperformula';
|
|
16
|
+
import { type AsyncFunction, AsyncFunctionPlugin } from './async-function';
|
|
17
17
|
|
|
18
|
-
const
|
|
18
|
+
export const EDGE_FUNCTION_NAME = 'DX';
|
|
19
|
+
|
|
20
|
+
const FUNCTION_TTL = 10_000;
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
|
-
* A hyperformula function plugin for calling EDGE functions.
|
|
23
|
+
* A hyperformula function plugin for calling remote (EDGE) functions.
|
|
22
24
|
*
|
|
23
25
|
* https://hyperformula.handsontable.com/guide/custom-functions.html#add-a-simple-custom-function
|
|
24
26
|
*/
|
|
25
|
-
export class EdgeFunctionPlugin extends
|
|
26
|
-
|
|
27
|
+
export class EdgeFunctionPlugin extends AsyncFunctionPlugin {
|
|
28
|
+
dx(ast: ProcedureAst, state: InterpreterState) {
|
|
27
29
|
const handler =
|
|
28
30
|
(subscribe = false): AsyncFunction =>
|
|
29
31
|
async (binding: string, ...args: any) => {
|
|
@@ -42,39 +44,41 @@ export class EdgeFunctionPlugin extends FunctionPluginAsync {
|
|
|
42
44
|
|
|
43
45
|
if (subscribe) {
|
|
44
46
|
const unsubscribe = effect(() => {
|
|
45
|
-
log
|
|
47
|
+
log('function changed', { fn });
|
|
46
48
|
const _ = fn?.version;
|
|
47
49
|
|
|
48
50
|
// TODO(wittjosiah): `ttl` should be 0 to force a recalculation when a new version is deployed.
|
|
49
51
|
// This needs a ttl to prevent a binding change from causing the function not to be found.
|
|
50
|
-
this.runAsyncFunction(ast, state, handler(false), { ttl:
|
|
52
|
+
this.runAsyncFunction(ast, state, handler(false), { ttl: FUNCTION_TTL });
|
|
51
53
|
});
|
|
52
54
|
|
|
53
55
|
this.context.createSubscription(ast.procedureName, unsubscribe);
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
const path = getUserFunctionUrlInMetadata(getMeta(fn));
|
|
57
|
-
const
|
|
59
|
+
const response = await fetch(`${this.context.remoteFunctionUrl}${path}`, {
|
|
58
60
|
method: 'POST',
|
|
59
61
|
headers: { 'Content-Type': 'application/json' },
|
|
60
62
|
body: JSON.stringify({ args: args.filter(nonNullable) }),
|
|
61
63
|
});
|
|
62
|
-
|
|
64
|
+
const result = await response.text();
|
|
65
|
+
log('function executed', { result });
|
|
66
|
+
|
|
67
|
+
return result;
|
|
63
68
|
};
|
|
64
69
|
|
|
65
|
-
return this.runAsyncFunction(ast, state, handler(true), { ttl:
|
|
70
|
+
return this.runAsyncFunction(ast, state, handler(true), { ttl: FUNCTION_TTL });
|
|
66
71
|
}
|
|
67
72
|
}
|
|
68
73
|
|
|
69
74
|
EdgeFunctionPlugin.implementedFunctions = {
|
|
70
|
-
|
|
71
|
-
method: '
|
|
75
|
+
[EDGE_FUNCTION_NAME]: {
|
|
76
|
+
method: 'dx',
|
|
72
77
|
parameters: [
|
|
73
78
|
// Binding
|
|
74
79
|
{ argumentType: FunctionArgumentType.STRING },
|
|
75
80
|
|
|
76
|
-
// Remote function arguments (currently supporting up to
|
|
77
|
-
{ argumentType: FunctionArgumentType.ANY, optionalArg: true },
|
|
81
|
+
// Remote function arguments (currently supporting up to 8).
|
|
78
82
|
{ argumentType: FunctionArgumentType.ANY, optionalArg: true },
|
|
79
83
|
{ argumentType: FunctionArgumentType.ANY, optionalArg: true },
|
|
80
84
|
{ argumentType: FunctionArgumentType.ANY, optionalArg: true },
|
|
@@ -90,9 +94,9 @@ EdgeFunctionPlugin.implementedFunctions = {
|
|
|
90
94
|
|
|
91
95
|
export const EdgeFunctionPluginTranslations = {
|
|
92
96
|
enGB: {
|
|
93
|
-
|
|
97
|
+
[EDGE_FUNCTION_NAME]: 'Remote function',
|
|
94
98
|
},
|
|
95
99
|
enUS: {
|
|
96
|
-
|
|
100
|
+
[EDGE_FUNCTION_NAME]: 'Remote function',
|
|
97
101
|
},
|
|
98
102
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { describe, test, expect } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { HyperFormula } from '#hyperformula';
|
|
8
|
+
|
|
9
|
+
describe('hyperformula', () => {
|
|
10
|
+
test('sanity test', async () => {
|
|
11
|
+
const hf = HyperFormula.buildEmpty({ licenseKey: 'gpl-v3' });
|
|
12
|
+
expect(hf).to.exist;
|
|
13
|
+
});
|
|
14
|
+
});
|