@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
|
@@ -2,167 +2,293 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
type Icon,
|
|
7
|
-
Calendar,
|
|
8
|
-
ChatText,
|
|
9
|
-
CurrencyDollar,
|
|
10
|
-
Eraser,
|
|
11
|
-
HighlighterCircle,
|
|
12
|
-
TextAlignCenter,
|
|
13
|
-
TextAlignLeft,
|
|
14
|
-
TextAlignRight,
|
|
15
|
-
} from '@phosphor-icons/react';
|
|
16
5
|
import { createContext } from '@radix-ui/react-context';
|
|
17
|
-
import React, { type PropsWithChildren } from 'react';
|
|
6
|
+
import React, { type PropsWithChildren, useCallback } from 'react';
|
|
18
7
|
|
|
8
|
+
import { useIntentDispatcher } from '@dxos/app-framework';
|
|
19
9
|
import {
|
|
20
|
-
|
|
21
|
-
ElevationProvider,
|
|
22
|
-
Toolbar as NaturalToolbar,
|
|
10
|
+
Icon,
|
|
23
11
|
type ThemedClassName,
|
|
12
|
+
Toolbar as NaturalToolbar,
|
|
13
|
+
type ToolbarButtonProps as NaturalToolbarButtonProps,
|
|
14
|
+
type ToolbarToggleGroupItemProps as NaturalToolbarToggleGroupItemProps,
|
|
15
|
+
type ToolbarToggleProps as NaturalToolbarToggleProps,
|
|
16
|
+
Tooltip,
|
|
24
17
|
useTranslation,
|
|
25
18
|
} from '@dxos/react-ui';
|
|
19
|
+
import { useAttention } from '@dxos/react-ui-attention';
|
|
20
|
+
import { nonNullable } from '@dxos/util';
|
|
26
21
|
|
|
27
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
alignKey,
|
|
24
|
+
type AlignKey,
|
|
25
|
+
type AlignValue,
|
|
26
|
+
type CommentKey,
|
|
27
|
+
type CommentValue,
|
|
28
|
+
inRange,
|
|
29
|
+
rangeFromIndex,
|
|
30
|
+
rangeToIndex,
|
|
31
|
+
styleKey,
|
|
32
|
+
type StyleKey,
|
|
33
|
+
type StyleValue,
|
|
34
|
+
} from '../../defs';
|
|
35
|
+
import { completeCellRangeToThreadCursor } from '../../integrations';
|
|
28
36
|
import { SHEET_PLUGIN } from '../../meta';
|
|
29
|
-
import { type
|
|
37
|
+
import { type SheetType } from '../../types';
|
|
38
|
+
import { useSheetContext } from '../SheetContext';
|
|
30
39
|
|
|
31
40
|
//
|
|
32
|
-
//
|
|
41
|
+
// Buttons
|
|
33
42
|
//
|
|
34
43
|
|
|
35
|
-
|
|
44
|
+
const buttonStyles = 'min-bs-0 p-2';
|
|
45
|
+
const tooltipProps = { side: 'bottom' as const, classNames: 'z-10' };
|
|
46
|
+
|
|
47
|
+
const ToolbarSeparator = () => <div role='separator' className='grow' />;
|
|
36
48
|
|
|
37
|
-
|
|
38
|
-
|
|
49
|
+
//
|
|
50
|
+
// ToolbarItem
|
|
51
|
+
//
|
|
52
|
+
|
|
53
|
+
type ToolbarItemProps =
|
|
54
|
+
| (NaturalToolbarButtonProps & { itemType: 'button'; icon: string })
|
|
55
|
+
| (NaturalToolbarToggleGroupItemProps & { itemType: 'toggleGroupItem'; icon: string })
|
|
56
|
+
| (NaturalToolbarToggleProps & { itemType: 'toggle'; icon: string });
|
|
57
|
+
|
|
58
|
+
export const ToolbarItem = ({ itemType, icon, children, ...props }: ToolbarItemProps) => {
|
|
59
|
+
const Invoker =
|
|
60
|
+
itemType === 'toggleGroupItem'
|
|
61
|
+
? NaturalToolbar.ToggleGroupItem
|
|
62
|
+
: itemType === 'toggle'
|
|
63
|
+
? NaturalToolbar.Toggle
|
|
64
|
+
: NaturalToolbar.Button;
|
|
65
|
+
return (
|
|
66
|
+
<Tooltip.Root>
|
|
67
|
+
<Tooltip.Trigger asChild>
|
|
68
|
+
{/* TODO(thure): type the props spread better. */}
|
|
69
|
+
<Invoker variant='ghost' {...(props as any)} classNames={buttonStyles}>
|
|
70
|
+
<Icon icon={icon} size={5} />
|
|
71
|
+
<span className='sr-only'>{children}</span>
|
|
72
|
+
</Invoker>
|
|
73
|
+
</Tooltip.Trigger>
|
|
74
|
+
<Tooltip.Portal>
|
|
75
|
+
<Tooltip.Content {...tooltipProps}>
|
|
76
|
+
{children}
|
|
77
|
+
<Tooltip.Arrow />
|
|
78
|
+
</Tooltip.Content>
|
|
79
|
+
</Tooltip.Portal>
|
|
80
|
+
</Tooltip.Root>
|
|
81
|
+
);
|
|
39
82
|
};
|
|
40
83
|
|
|
41
|
-
|
|
84
|
+
//
|
|
85
|
+
// Root
|
|
86
|
+
//
|
|
87
|
+
|
|
88
|
+
type AlignAction = { key: AlignKey; value: AlignValue };
|
|
89
|
+
type CommentAction = { key: CommentKey; value: CommentValue; cellContent?: string };
|
|
90
|
+
type StyleAction = { key: StyleKey; value: StyleValue };
|
|
91
|
+
|
|
92
|
+
export type ToolbarAction = StyleAction | AlignAction | CommentAction;
|
|
93
|
+
export type ToolbarActionAnnotated = ToolbarAction & { unset?: boolean };
|
|
94
|
+
|
|
95
|
+
export type ToolbarActionType = ToolbarAction['key'];
|
|
96
|
+
|
|
97
|
+
export type ToolbarActionHandler = (action: ToolbarActionAnnotated) => void;
|
|
42
98
|
|
|
43
99
|
export type ToolbarProps = ThemedClassName<
|
|
44
100
|
PropsWithChildren<{
|
|
45
|
-
|
|
101
|
+
role?: string;
|
|
46
102
|
}>
|
|
47
103
|
>;
|
|
48
104
|
|
|
49
|
-
const [ToolbarContextProvider, useToolbarContext] = createContext<
|
|
105
|
+
const [ToolbarContextProvider, useToolbarContext] = createContext<{
|
|
106
|
+
onAction: (action: ToolbarActionAnnotated) => void;
|
|
107
|
+
}>('Toolbar');
|
|
108
|
+
|
|
109
|
+
// TODO(Zan): Factor out, copied this from MarkdownPlugin.
|
|
110
|
+
const sectionToolbarLayout =
|
|
111
|
+
'bs-[--rail-action] bg-[--sticky-bg] sticky block-start-0 __-block-start-px transition-opacity';
|
|
112
|
+
|
|
113
|
+
type Range = SheetType['ranges'][number];
|
|
114
|
+
|
|
115
|
+
const ToolbarRoot = ({ children, role, classNames }: ToolbarProps) => {
|
|
116
|
+
const { id, model, cursorFallbackRange, cursor } = useSheetContext();
|
|
117
|
+
const { hasAttention } = useAttention(id);
|
|
118
|
+
const dispatch = useIntentDispatcher();
|
|
119
|
+
|
|
120
|
+
// TODO(Zan): Externalize the toolbar action handler. E.g., Toolbar/keys should both fire events.
|
|
121
|
+
const handleAction = useCallback(
|
|
122
|
+
(action: ToolbarActionAnnotated) => {
|
|
123
|
+
switch (action.key) {
|
|
124
|
+
case 'alignment':
|
|
125
|
+
if (cursorFallbackRange) {
|
|
126
|
+
const index =
|
|
127
|
+
model.sheet.ranges?.findIndex(
|
|
128
|
+
(range) =>
|
|
129
|
+
range.key === action.key &&
|
|
130
|
+
inRange(rangeFromIndex(model.sheet, range.range), cursorFallbackRange.from),
|
|
131
|
+
) ?? -1;
|
|
132
|
+
const nextRangeEntity = {
|
|
133
|
+
range: rangeToIndex(model.sheet, cursorFallbackRange),
|
|
134
|
+
key: action.key,
|
|
135
|
+
value: action.value,
|
|
136
|
+
};
|
|
137
|
+
if (index < 0) {
|
|
138
|
+
model.sheet.ranges?.push(nextRangeEntity);
|
|
139
|
+
} else if (model.sheet.ranges![index].value === action.value) {
|
|
140
|
+
model.sheet.ranges?.splice(index, 1);
|
|
141
|
+
} else {
|
|
142
|
+
model.sheet.ranges?.splice(index, 1, nextRangeEntity);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
break;
|
|
146
|
+
case 'style':
|
|
147
|
+
if (action.unset) {
|
|
148
|
+
const index = model.sheet.ranges?.findIndex(
|
|
149
|
+
(range) =>
|
|
150
|
+
range.key === action.key &&
|
|
151
|
+
cursorFallbackRange &&
|
|
152
|
+
inRange(rangeFromIndex(model.sheet, range.range), cursorFallbackRange.from),
|
|
153
|
+
);
|
|
154
|
+
if (index >= 0) {
|
|
155
|
+
model.sheet.ranges?.splice(index, 1);
|
|
156
|
+
}
|
|
157
|
+
} else if (cursorFallbackRange) {
|
|
158
|
+
model.sheet.ranges?.push({
|
|
159
|
+
range: rangeToIndex(model.sheet, cursorFallbackRange),
|
|
160
|
+
key: action.key,
|
|
161
|
+
value: action.value,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
165
|
+
case 'comment': {
|
|
166
|
+
// TODO(Zan): We shouldn't hardcode the action ID.
|
|
167
|
+
if (cursorFallbackRange) {
|
|
168
|
+
void dispatch({
|
|
169
|
+
action: 'dxos.org/plugin/thread/action/create',
|
|
170
|
+
data: {
|
|
171
|
+
cursor: completeCellRangeToThreadCursor(cursorFallbackRange),
|
|
172
|
+
name: action.cellContent,
|
|
173
|
+
subject: model.sheet,
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
[model.sheet, cursorFallbackRange, cursor, dispatch],
|
|
181
|
+
);
|
|
50
182
|
|
|
51
|
-
const ToolbarRoot = ({ children, onAction, classNames }: ToolbarProps) => {
|
|
52
183
|
return (
|
|
53
|
-
<ToolbarContextProvider onAction={
|
|
54
|
-
<
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
184
|
+
<ToolbarContextProvider onAction={handleAction}>
|
|
185
|
+
<NaturalToolbar.Root
|
|
186
|
+
classNames={[
|
|
187
|
+
'pli-0.5',
|
|
188
|
+
...(role === 'section'
|
|
189
|
+
? ['z-[2] group-focus-within/section:visible', !hasAttention && 'invisible', sectionToolbarLayout]
|
|
190
|
+
: ['attention-surface']),
|
|
191
|
+
classNames,
|
|
192
|
+
]}
|
|
193
|
+
>
|
|
194
|
+
{children}
|
|
195
|
+
</NaturalToolbar.Root>
|
|
61
196
|
</ToolbarContextProvider>
|
|
62
197
|
);
|
|
63
198
|
};
|
|
64
199
|
|
|
65
200
|
// TODO(burdon): Generalize.
|
|
66
201
|
// TODO(burdon): Detect and display current state.
|
|
67
|
-
type ButtonProps = {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
disabled?: (state: Formatting) => boolean;
|
|
202
|
+
type ButtonProps<T> = {
|
|
203
|
+
value: T;
|
|
204
|
+
icon: string;
|
|
205
|
+
disabled?: (state: Range) => boolean;
|
|
72
206
|
};
|
|
73
207
|
|
|
74
208
|
//
|
|
75
209
|
// Alignment
|
|
76
210
|
//
|
|
77
211
|
|
|
78
|
-
const
|
|
79
|
-
{
|
|
80
|
-
{
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const Format = () => {
|
|
84
|
-
const { onAction } = useToolbarContext('Format');
|
|
85
|
-
const { t } = useTranslation(SHEET_PLUGIN);
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<NaturalToolbar.ToggleGroup
|
|
89
|
-
type='single'
|
|
90
|
-
// value={cellStyles.filter(({ getState }) => state && getState(state)).map(({ type }) => type)}
|
|
91
|
-
>
|
|
92
|
-
{formatOptions.map(({ type, getState, Icon }) => (
|
|
93
|
-
<ToolbarToggleButton
|
|
94
|
-
key={type}
|
|
95
|
-
value={type}
|
|
96
|
-
Icon={Icon}
|
|
97
|
-
// disabled={state?.blockType === 'codeblock'}
|
|
98
|
-
// onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
|
|
99
|
-
onClick={() => onAction?.({ type })}
|
|
100
|
-
>
|
|
101
|
-
{t(`toolbar ${type} label`)}
|
|
102
|
-
</ToolbarToggleButton>
|
|
103
|
-
))}
|
|
104
|
-
</NaturalToolbar.ToggleGroup>
|
|
105
|
-
);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const alignmentOptions: ButtonProps[] = [
|
|
109
|
-
{ type: 'left', Icon: TextAlignLeft, getState: (state) => false },
|
|
110
|
-
{ type: 'center', Icon: TextAlignCenter, getState: (state) => false },
|
|
111
|
-
{ type: 'right', Icon: TextAlignRight, getState: (state) => false },
|
|
212
|
+
const alignmentOptions: ButtonProps<AlignValue>[] = [
|
|
213
|
+
{ value: 'start', icon: 'ph--text-align-left--regular' },
|
|
214
|
+
{ value: 'center', icon: 'ph--text-align-center--regular' },
|
|
215
|
+
{ value: 'end', icon: 'ph--text-align-right--regular' },
|
|
112
216
|
];
|
|
113
217
|
|
|
114
218
|
const Alignment = () => {
|
|
219
|
+
const { cursor, model } = useSheetContext();
|
|
115
220
|
const { onAction } = useToolbarContext('Alignment');
|
|
116
221
|
const { t } = useTranslation(SHEET_PLUGIN);
|
|
117
222
|
|
|
223
|
+
// TODO(thure): Can this O(n) call be memoized?
|
|
224
|
+
const value = cursor
|
|
225
|
+
? model.sheet.ranges?.findLast(
|
|
226
|
+
({ range, key }) => key === alignKey && inRange(rangeFromIndex(model.sheet, range), cursor),
|
|
227
|
+
)?.value
|
|
228
|
+
: undefined;
|
|
229
|
+
|
|
118
230
|
return (
|
|
119
231
|
<NaturalToolbar.ToggleGroup
|
|
120
232
|
type='single'
|
|
121
|
-
|
|
233
|
+
value={
|
|
234
|
+
// TODO(thure): providing `undefined` leaves the last item active which was active rather than showing none.
|
|
235
|
+
value ?? 'never'
|
|
236
|
+
}
|
|
237
|
+
onValueChange={(value: AlignValue) => onAction?.({ key: alignKey, value })}
|
|
122
238
|
>
|
|
123
|
-
{alignmentOptions.map(({
|
|
124
|
-
<
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
onClick={() => onAction?.({ type })}
|
|
131
|
-
>
|
|
132
|
-
{t(`toolbar ${type} label`)}
|
|
133
|
-
</ToolbarToggleButton>
|
|
239
|
+
{alignmentOptions.map(({ value, icon }) => (
|
|
240
|
+
<ToolbarItem itemType='toggleGroupItem' key={value} value={value} icon={icon}>
|
|
241
|
+
{t('toolbar action label', {
|
|
242
|
+
key: t(`range key ${alignKey} label`),
|
|
243
|
+
value: t(`range value ${value} label`),
|
|
244
|
+
})}
|
|
245
|
+
</ToolbarItem>
|
|
134
246
|
))}
|
|
135
247
|
</NaturalToolbar.ToggleGroup>
|
|
136
248
|
);
|
|
137
249
|
};
|
|
138
250
|
|
|
139
|
-
const styleOptions: ButtonProps[] = [
|
|
140
|
-
{
|
|
141
|
-
{
|
|
251
|
+
const styleOptions: ButtonProps<StyleValue>[] = [
|
|
252
|
+
{ value: 'highlight', icon: 'ph--highlighter--regular' },
|
|
253
|
+
{ value: 'softwrap', icon: 'ph--paragraph--regular' },
|
|
142
254
|
];
|
|
143
255
|
|
|
144
256
|
const Styles = () => {
|
|
145
|
-
const {
|
|
257
|
+
const { cursorFallbackRange, model } = useSheetContext();
|
|
258
|
+
const { onAction } = useToolbarContext('Styles');
|
|
146
259
|
const { t } = useTranslation(SHEET_PLUGIN);
|
|
147
260
|
|
|
261
|
+
// TODO(thure): Can this O(n) call be memoized?
|
|
262
|
+
const activeValues = cursorFallbackRange
|
|
263
|
+
? model.sheet.ranges
|
|
264
|
+
?.filter(
|
|
265
|
+
({ range, key }) => key === 'style' && inRange(rangeFromIndex(model.sheet, range), cursorFallbackRange.from),
|
|
266
|
+
)
|
|
267
|
+
.reduce((acc, { value }) => {
|
|
268
|
+
acc.add(value);
|
|
269
|
+
return acc;
|
|
270
|
+
}, new Set())
|
|
271
|
+
: undefined;
|
|
272
|
+
|
|
148
273
|
return (
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
// onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
|
|
160
|
-
onClick={() => onAction?.({ type })}
|
|
274
|
+
<>
|
|
275
|
+
{styleOptions.map(({ value, icon }) => (
|
|
276
|
+
<ToolbarItem
|
|
277
|
+
itemType='toggle'
|
|
278
|
+
key={value}
|
|
279
|
+
pressed={activeValues?.has(value)}
|
|
280
|
+
onPressedChange={(nextPressed: boolean) => {
|
|
281
|
+
onAction?.({ key: 'style', value, unset: !nextPressed });
|
|
282
|
+
}}
|
|
283
|
+
icon={icon}
|
|
161
284
|
>
|
|
162
|
-
{t(
|
|
163
|
-
|
|
285
|
+
{t('toolbar action label', {
|
|
286
|
+
key: t(`range key ${styleKey} label`),
|
|
287
|
+
value: t(`range value ${value} label`),
|
|
288
|
+
})}
|
|
289
|
+
</ToolbarItem>
|
|
164
290
|
))}
|
|
165
|
-
|
|
291
|
+
</>
|
|
166
292
|
);
|
|
167
293
|
};
|
|
168
294
|
|
|
@@ -171,18 +297,47 @@ const Styles = () => {
|
|
|
171
297
|
//
|
|
172
298
|
|
|
173
299
|
const Actions = () => {
|
|
174
|
-
|
|
300
|
+
const { onAction } = useToolbarContext('Actions');
|
|
301
|
+
const { cursorFallbackRange, cursor, model } = useSheetContext();
|
|
175
302
|
const { t } = useTranslation(SHEET_PLUGIN);
|
|
303
|
+
|
|
304
|
+
// TODO(thure): Can this O(n) call be memoized?
|
|
305
|
+
const overlapsCommentAnchor = (model.sheet.threads ?? [])
|
|
306
|
+
.filter(nonNullable)
|
|
307
|
+
.filter((thread) => thread.status !== 'resolved')
|
|
308
|
+
.some((thread) => {
|
|
309
|
+
if (!cursorFallbackRange) {
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
return rangeToIndex(model.sheet, cursorFallbackRange) === thread.anchor;
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
const tooltipLabelKey = !cursor
|
|
316
|
+
? 'no cursor label'
|
|
317
|
+
: overlapsCommentAnchor
|
|
318
|
+
? 'selection overlaps existing comment label'
|
|
319
|
+
: 'comment label';
|
|
320
|
+
|
|
176
321
|
return (
|
|
177
|
-
<
|
|
322
|
+
<ToolbarItem
|
|
323
|
+
itemType='button'
|
|
178
324
|
value='comment'
|
|
179
|
-
|
|
325
|
+
icon='ph--chat-text--regular'
|
|
180
326
|
data-testid='editor.toolbar.comment'
|
|
181
|
-
|
|
182
|
-
|
|
327
|
+
onClick={() => {
|
|
328
|
+
if (!cursorFallbackRange) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
return onAction?.({
|
|
332
|
+
key: 'comment',
|
|
333
|
+
value: rangeToIndex(model.sheet, cursorFallbackRange),
|
|
334
|
+
cellContent: model.getCellText(cursorFallbackRange.from),
|
|
335
|
+
});
|
|
336
|
+
}}
|
|
337
|
+
disabled={!cursorFallbackRange || overlapsCommentAnchor}
|
|
183
338
|
>
|
|
184
|
-
{t(
|
|
185
|
-
</
|
|
339
|
+
{t(tooltipLabelKey)}
|
|
340
|
+
</ToolbarItem>
|
|
186
341
|
);
|
|
187
342
|
};
|
|
188
343
|
|
|
@@ -190,7 +345,6 @@ export const Toolbar = {
|
|
|
190
345
|
Root: ToolbarRoot,
|
|
191
346
|
Separator: ToolbarSeparator,
|
|
192
347
|
Alignment,
|
|
193
|
-
Format,
|
|
194
348
|
Styles,
|
|
195
349
|
Actions,
|
|
196
350
|
};
|
package/src/components/index.ts
CHANGED
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import { lazy } from 'react';
|
|
6
6
|
|
|
7
7
|
export * from './ComputeGraph';
|
|
8
|
+
export * from './GridSheet';
|
|
9
|
+
export * from './RangeList';
|
|
10
|
+
export * from './SheetContext';
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
export const SheetContainer = React.lazy(() => import('./SheetContainer'));
|
|
12
|
+
export const SheetContainer = lazy(() => import('./SheetContainer'));
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import type { FunctionPluginDefinition } from 'hyperformula';
|
|
6
|
+
import type { ConfigParams } from 'hyperformula/typings/ConfigParams';
|
|
7
|
+
import type { FunctionTranslationsPackage } from 'hyperformula/typings/interpreter';
|
|
8
|
+
import defaultsDeep from 'lodash.defaultsdeep';
|
|
9
|
+
|
|
10
|
+
import { type SpaceId, type Space } from '@dxos/client/echo';
|
|
11
|
+
import { Resource } from '@dxos/context';
|
|
12
|
+
import { invariant } from '@dxos/invariant';
|
|
13
|
+
import { log } from '@dxos/log';
|
|
14
|
+
|
|
15
|
+
import { HyperFormula } from '#hyperformula';
|
|
16
|
+
import { ComputeGraph } from './compute-graph';
|
|
17
|
+
import { EdgeFunctionPlugin, EdgeFunctionPluginTranslations, type FunctionContextOptions } from './functions';
|
|
18
|
+
|
|
19
|
+
export type ComputeGraphPlugin = {
|
|
20
|
+
plugin: FunctionPluginDefinition;
|
|
21
|
+
translations: FunctionTranslationsPackage;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type ComputeGraphOptions = {
|
|
25
|
+
plugins?: ComputeGraphPlugin[];
|
|
26
|
+
} & Partial<FunctionContextOptions> &
|
|
27
|
+
Partial<ConfigParams>;
|
|
28
|
+
|
|
29
|
+
export const defaultOptions: ComputeGraphOptions = {
|
|
30
|
+
licenseKey: 'gpl-v3',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const defaultPlugins: ComputeGraphPlugin[] = [
|
|
34
|
+
{
|
|
35
|
+
plugin: EdgeFunctionPlugin,
|
|
36
|
+
translations: EdgeFunctionPluginTranslations,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Manages a collection of ComputeGraph instances for each space.
|
|
42
|
+
*
|
|
43
|
+
* [ComputePlugin] => [ComputeGraphRegistry] => [ComputeGraph(Space)] => [ComputeNode(Object)]
|
|
44
|
+
*
|
|
45
|
+
* NOTE: The ComputeGraphRegistry manages the hierarchy of resources via its root Context.
|
|
46
|
+
* NOTE: The package.json file defines the packaged #hyperformula module.
|
|
47
|
+
*/
|
|
48
|
+
// TODO(burdon): Move graph into separate plugin; isolate HF deps.
|
|
49
|
+
export class ComputeGraphRegistry extends Resource {
|
|
50
|
+
private readonly _graphs = new Map<SpaceId, ComputeGraph>();
|
|
51
|
+
|
|
52
|
+
private readonly _options: ComputeGraphOptions;
|
|
53
|
+
|
|
54
|
+
constructor(options: ComputeGraphOptions = { plugins: defaultPlugins }) {
|
|
55
|
+
super();
|
|
56
|
+
this._options = defaultsDeep({}, options, defaultOptions);
|
|
57
|
+
this._options.plugins?.forEach(({ plugin, translations }) => {
|
|
58
|
+
HyperFormula.registerFunctionPlugin(plugin, translations);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
getGraph(spaceId: SpaceId): ComputeGraph | undefined {
|
|
63
|
+
return this._graphs.get(spaceId);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getOrCreateGraph(space: Space): ComputeGraph {
|
|
67
|
+
let graph = this._graphs.get(space.id);
|
|
68
|
+
if (!graph) {
|
|
69
|
+
log('create graph', { space: space.id });
|
|
70
|
+
graph = this.createGraph(space);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return graph;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
createGraph(space: Space): ComputeGraph {
|
|
77
|
+
invariant(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`);
|
|
78
|
+
const hf = HyperFormula.buildEmpty(this._options);
|
|
79
|
+
const graph = new ComputeGraph(hf, space, this._options);
|
|
80
|
+
this._graphs.set(space.id, graph);
|
|
81
|
+
return graph;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
protected override async _close() {
|
|
85
|
+
for (const graph of this._graphs.values()) {
|
|
86
|
+
await graph.close();
|
|
87
|
+
}
|
|
88
|
+
this._graphs.clear();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxos-theme';
|
|
6
|
+
|
|
7
|
+
import { type Meta } from '@storybook/react';
|
|
8
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
9
|
+
|
|
10
|
+
import { FunctionType } from '@dxos/plugin-script/types';
|
|
11
|
+
import { create, useSpace, Filter } from '@dxos/react-client/echo';
|
|
12
|
+
import { withClientProvider } from '@dxos/react-client/testing';
|
|
13
|
+
import { Toolbar, Button, Input } from '@dxos/react-ui';
|
|
14
|
+
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
15
|
+
import { withTheme } from '@dxos/storybook-utils';
|
|
16
|
+
|
|
17
|
+
import { testFunctionPlugins } from './testing';
|
|
18
|
+
import { useComputeGraph } from '../components';
|
|
19
|
+
import { createSheet } from '../defs';
|
|
20
|
+
import { useSheetModel } from '../model';
|
|
21
|
+
import { withComputeGraphDecorator } from '../testing';
|
|
22
|
+
import { SheetType } from '../types';
|
|
23
|
+
|
|
24
|
+
const FUNCTION_NAME = 'TEST';
|
|
25
|
+
|
|
26
|
+
const Story = () => {
|
|
27
|
+
const space = useSpace();
|
|
28
|
+
const graph = useComputeGraph(space);
|
|
29
|
+
const [sheet, setSheet] = useState<SheetType>();
|
|
30
|
+
const [text, setText] = useState(`${FUNCTION_NAME}(100)`);
|
|
31
|
+
const [result, setResult] = useState<any>();
|
|
32
|
+
const model = useSheetModel(graph, sheet);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
if (space) {
|
|
35
|
+
const sheet = space.db.add(createSheet());
|
|
36
|
+
setSheet(sheet);
|
|
37
|
+
}
|
|
38
|
+
}, [space]);
|
|
39
|
+
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (space && graph) {
|
|
42
|
+
graph.update.on(() => {
|
|
43
|
+
const f1 = graph.getFunctions({ standard: true, echo: false });
|
|
44
|
+
const f2 = graph.getFunctions({ standard: false, echo: true });
|
|
45
|
+
setResult({ functions: { standard: f1.length, echo: f2.length } });
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
space.db.add(create(FunctionType, { version: 1, binding: FUNCTION_NAME }));
|
|
49
|
+
}
|
|
50
|
+
}, [space, graph]);
|
|
51
|
+
|
|
52
|
+
const inputRef = useRef<HTMLInputElement | null>(null);
|
|
53
|
+
const handleTest = async () => {
|
|
54
|
+
if (space && graph) {
|
|
55
|
+
const { objects } = await space.db.query(Filter.schema(FunctionType)).run();
|
|
56
|
+
const mapped = graph.mapFunctionBindingToId(text);
|
|
57
|
+
const unmapped = graph.mapFunctionBindingFromId(mapped);
|
|
58
|
+
const internal = graph.mapFormulaToNative(text);
|
|
59
|
+
setResult({ mapped, unmapped, internal, functions: objects.map((object) => object.id) });
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
inputRef.current?.focus();
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div className='flex flex-col gap-2 '>
|
|
67
|
+
<Toolbar.Root>
|
|
68
|
+
<Input.Root>
|
|
69
|
+
<Input.TextInput
|
|
70
|
+
ref={inputRef}
|
|
71
|
+
placeholder='Formula'
|
|
72
|
+
value={text}
|
|
73
|
+
onChange={(ev) => setText(ev.target.value)}
|
|
74
|
+
/>
|
|
75
|
+
</Input.Root>
|
|
76
|
+
<Button onClick={handleTest}>Test</Button>
|
|
77
|
+
</Toolbar.Root>
|
|
78
|
+
<SyntaxHighlighter language='json'>
|
|
79
|
+
{JSON.stringify({ space: space?.id, graph: graph?.id, sheet: sheet?.id, model: model?.id, result }, null, 2)}
|
|
80
|
+
</SyntaxHighlighter>
|
|
81
|
+
</div>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const Default = {};
|
|
86
|
+
|
|
87
|
+
const meta: Meta = {
|
|
88
|
+
title: 'plugins/plugin-sheet/functions',
|
|
89
|
+
decorators: [
|
|
90
|
+
withClientProvider({ types: [FunctionType, SheetType], createIdentity: true, createSpace: true }),
|
|
91
|
+
withComputeGraphDecorator({ plugins: testFunctionPlugins }),
|
|
92
|
+
withTheme,
|
|
93
|
+
],
|
|
94
|
+
render: (args: any) => <Story {...args} />,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export default meta;
|