@dxos/plugin-sheet 0.6.13-main.ed424a1 → 0.6.13
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-U4H5D34A.mjs +1772 -0
- package/dist/lib/browser/SheetContainer-U4H5D34A.mjs.map +7 -0
- package/dist/lib/browser/chunk-APHOLYUB.mjs +175 -0
- package/dist/lib/browser/chunk-APHOLYUB.mjs.map +7 -0
- package/dist/lib/{node-esm/chunk-5WPZCXNS.mjs → browser/chunk-D5AGLXJP.mjs} +678 -411
- package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +7 -0
- package/dist/lib/browser/chunk-FUAGSXA4.mjs +82 -0
- package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +7 -0
- package/dist/lib/browser/chunk-JRL5LGCE.mjs +18 -0
- package/dist/lib/browser/chunk-JRL5LGCE.mjs.map +7 -0
- package/dist/lib/browser/chunk-NU4PBN33.mjs +8 -0
- package/dist/lib/browser/chunk-NU4PBN33.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +62 -93
- 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/testing.mjs +92 -0
- package/dist/lib/browser/testing.mjs.map +7 -0
- package/dist/lib/browser/types.mjs +12 -6
- package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs +1765 -0
- package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +7 -0
- package/dist/lib/node/{chunk-5XPK2V4A.cjs → chunk-5KKJ4NPP.cjs} +678 -418
- package/dist/lib/node/chunk-5KKJ4NPP.cjs.map +7 -0
- package/dist/lib/node/chunk-BJ6ZD7MN.cjs +51 -0
- package/dist/lib/node/chunk-BJ6ZD7MN.cjs.map +7 -0
- package/dist/lib/node/chunk-CN3RPESU.cjs +202 -0
- package/dist/lib/node/chunk-CN3RPESU.cjs.map +7 -0
- package/dist/lib/node/{chunk-NZARD7UP.cjs → chunk-DSYKOI4E.cjs} +51 -40
- package/dist/lib/node/chunk-DSYKOI4E.cjs.map +7 -0
- package/dist/lib/node/chunk-PYXHNAAK.cjs +40 -0
- package/dist/lib/node/chunk-PYXHNAAK.cjs.map +7 -0
- package/dist/lib/node/index.cjs +69 -105
- 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/testing.cjs +111 -0
- package/dist/lib/node/testing.cjs.map +7 -0
- package/dist/lib/node/types.cjs +15 -9
- package/dist/lib/node/types.cjs.map +2 -2
- package/dist/types/src/SheetPlugin.d.ts.map +1 -1
- package/dist/types/src/components/CellEditor/CellEditor.d.ts +14 -0
- package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +1 -0
- package/dist/types/src/components/{GridSheet/SheetCellEditor.stories.d.ts → CellEditor/CellEditor.stories.d.ts} +4 -4
- package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +1 -0
- package/dist/types/src/{extensions/editor → components/CellEditor}/extension.d.ts +1 -1
- package/dist/types/src/components/CellEditor/extension.d.ts.map +1 -0
- package/dist/types/src/components/CellEditor/extension.test.d.ts.map +1 -0
- package/dist/types/src/components/CellEditor/index.d.ts +3 -0
- package/dist/types/src/components/CellEditor/index.d.ts.map +1 -0
- package/dist/types/src/{graph/functions → components/ComputeGraph}/async-function.d.ts +5 -14
- package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/custom.d.ts +21 -0
- package/dist/types/src/components/ComputeGraph/custom.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/edge-function.d.ts +20 -0
- package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/graph-context.d.ts +12 -0
- package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts +2 -0
- package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/graph.d.ts +26 -0
- package/dist/types/src/components/ComputeGraph/graph.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/index.d.ts +3 -1
- package/dist/types/src/components/ComputeGraph/index.d.ts.map +1 -1
- package/dist/types/src/components/Sheet/Sheet.d.ts +55 -0
- package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/Sheet.stories.d.ts +54 -0
- package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/formatting.d.ts +14 -0
- package/dist/types/src/components/Sheet/formatting.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/grid.d.ts +52 -0
- package/dist/types/src/components/Sheet/grid.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/index.d.ts +2 -0
- package/dist/types/src/components/Sheet/index.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/nav.d.ts +29 -0
- package/dist/types/src/components/Sheet/nav.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/sheet-context.d.ts +25 -0
- package/dist/types/src/components/Sheet/sheet-context.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/util.d.ts +18 -0
- package/dist/types/src/components/Sheet/util.d.ts.map +1 -0
- package/dist/types/src/components/SheetContainer.d.ts +9 -0
- package/dist/types/src/components/SheetContainer.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +9 -33
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +15 -19
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/common.d.ts +20 -0
- package/dist/types/src/components/Toolbar/common.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +2 -3
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +9 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/{graph/functions/function-defs.d.ts → model/functions.d.ts} +1 -1
- package/dist/types/src/model/functions.d.ts.map +1 -0
- package/dist/types/src/model/index.d.ts +3 -2
- package/dist/types/src/model/index.d.ts.map +1 -1
- package/dist/types/src/model/model.browser.test.d.ts +2 -0
- package/dist/types/src/model/model.browser.test.d.ts.map +1 -0
- package/dist/types/src/model/{sheet-model.d.ts → model.d.ts} +67 -13
- package/dist/types/src/model/model.d.ts.map +1 -0
- package/dist/types/src/{defs → model}/types.d.ts +3 -8
- package/dist/types/src/model/types.d.ts.map +1 -0
- package/dist/types/src/model/types.test.d.ts.map +1 -0
- package/dist/types/src/model/util.d.ts +15 -0
- package/dist/types/src/model/util.d.ts.map +1 -0
- package/dist/types/src/testing.d.ts +9 -0
- package/dist/types/src/testing.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +12 -17
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +40 -125
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +52 -58
- package/src/SheetPlugin.tsx +74 -52
- package/src/components/{GridSheet/SheetCellEditor.stories.tsx → CellEditor/CellEditor.stories.tsx} +8 -8
- package/src/components/CellEditor/CellEditor.tsx +113 -0
- package/src/{extensions/editor → components/CellEditor}/extension.test.ts +6 -4
- package/src/{extensions/editor → components/CellEditor}/extension.ts +6 -5
- package/src/{extensions/editor → components/CellEditor}/index.ts +1 -0
- package/src/{graph/functions → components/ComputeGraph}/async-function.ts +15 -25
- package/src/{graph/testing/test-plugin.ts → components/ComputeGraph/custom.ts} +14 -44
- package/src/{graph/functions → components/ComputeGraph}/edge-function.ts +14 -16
- package/src/components/ComputeGraph/graph-context.tsx +50 -0
- package/src/components/ComputeGraph/graph.browser.test.ts +50 -0
- package/src/components/ComputeGraph/graph.ts +62 -0
- package/src/components/ComputeGraph/index.ts +3 -1
- package/src/components/Sheet/Sheet.stories.tsx +287 -0
- package/src/components/Sheet/Sheet.tsx +1160 -0
- package/src/components/Sheet/formatting.ts +106 -0
- package/src/components/Sheet/grid.ts +191 -0
- package/src/{testing → components/Sheet}/index.ts +1 -1
- package/src/components/Sheet/nav.ts +157 -0
- package/src/components/Sheet/sheet-context.tsx +150 -0
- package/src/components/Sheet/util.ts +56 -0
- package/src/components/SheetContainer.tsx +34 -0
- package/src/components/Toolbar/Toolbar.tsx +112 -242
- package/src/components/Toolbar/common.tsx +72 -0
- package/src/components/index.ts +0 -2
- package/src/meta.tsx +18 -0
- package/src/model/index.ts +3 -2
- package/src/model/model.browser.test.ts +100 -0
- package/src/model/model.ts +550 -0
- package/src/{defs → model}/types.test.ts +9 -8
- package/src/{defs → model}/types.ts +14 -24
- package/src/model/util.ts +36 -0
- package/src/testing.ts +50 -0
- package/src/translations.ts +1 -6
- package/src/types.ts +47 -40
- package/dist/lib/browser/SheetContainer-RVRACGCZ.mjs +0 -290
- package/dist/lib/browser/SheetContainer-RVRACGCZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-BWN5DZWZ.mjs +0 -74
- package/dist/lib/browser/chunk-BWN5DZWZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-D3QTX46O.mjs +0 -14
- package/dist/lib/browser/chunk-D3QTX46O.mjs.map +0 -7
- package/dist/lib/browser/chunk-GSV5QNLD.mjs +0 -2966
- package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +0 -7
- package/dist/lib/browser/chunk-HOG37RYS.mjs +0 -1528
- package/dist/lib/browser/chunk-HOG37RYS.mjs.map +0 -7
- package/dist/lib/browser/graph-M4IQ76QX.mjs +0 -33
- package/dist/lib/browser/graph-M4IQ76QX.mjs.map +0 -7
- package/dist/lib/node/SheetContainer-J7XROAMN.cjs +0 -300
- package/dist/lib/node/SheetContainer-J7XROAMN.cjs.map +0 -7
- package/dist/lib/node/chunk-5XPK2V4A.cjs.map +0 -7
- package/dist/lib/node/chunk-AXQZA2YS.cjs +0 -1527
- package/dist/lib/node/chunk-AXQZA2YS.cjs.map +0 -7
- package/dist/lib/node/chunk-NZARD7UP.cjs.map +0 -7
- package/dist/lib/node/chunk-QIFIGEKV.cjs +0 -37
- package/dist/lib/node/chunk-QIFIGEKV.cjs.map +0 -7
- package/dist/lib/node/graph-Q3N2X26H.cjs +0 -55
- package/dist/lib/node/graph-Q3N2X26H.cjs.map +0 -7
- package/dist/lib/node-esm/SheetContainer-YWQVKHQB.mjs +0 -291
- package/dist/lib/node-esm/SheetContainer-YWQVKHQB.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BPXXIAOQ.mjs +0 -1529
- package/dist/lib/node-esm/chunk-BPXXIAOQ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-VCYJWE3O.mjs +0 -16
- package/dist/lib/node-esm/chunk-VCYJWE3O.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-WFDTY3IC.mjs +0 -75
- package/dist/lib/node-esm/chunk-WFDTY3IC.mjs.map +0 -7
- package/dist/lib/node-esm/graph-SMPUMOV2.mjs +0 -34
- package/dist/lib/node-esm/graph-SMPUMOV2.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -280
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/meta.mjs +0 -10
- package/dist/lib/node-esm/meta.mjs.map +0 -7
- package/dist/lib/node-esm/types.mjs +0 -17
- package/dist/lib/node-esm/types.mjs.map +0 -7
- package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +0 -11
- package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +0 -1
- package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts +0 -3
- package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +0 -1
- package/dist/types/src/components/FunctionEditor/index.d.ts +0 -2
- package/dist/types/src/components/FunctionEditor/index.d.ts.map +0 -1
- package/dist/types/src/components/GridSheet/GridSheet.d.ts +0 -3
- package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +0 -1
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +0 -9
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +0 -1
- package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +0 -1
- package/dist/types/src/components/GridSheet/index.d.ts +0 -2
- package/dist/types/src/components/GridSheet/index.d.ts.map +0 -1
- package/dist/types/src/components/GridSheet/util.d.ts +0 -16
- package/dist/types/src/components/GridSheet/util.d.ts.map +0 -1
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +0 -6
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +0 -1
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +0 -11
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +0 -1
- package/dist/types/src/components/SheetContainer/index.d.ts +0 -3
- package/dist/types/src/components/SheetContainer/index.d.ts.map +0 -1
- package/dist/types/src/components/SheetContext/SheetContext.d.ts +0 -26
- package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +0 -1
- package/dist/types/src/components/SheetContext/index.d.ts +0 -2
- package/dist/types/src/components/SheetContext/index.d.ts.map +0 -1
- package/dist/types/src/defs/index.d.ts +0 -4
- package/dist/types/src/defs/index.d.ts.map +0 -1
- package/dist/types/src/defs/sheet-range-types.d.ts +0 -13
- package/dist/types/src/defs/sheet-range-types.d.ts.map +0 -1
- package/dist/types/src/defs/types.d.ts.map +0 -1
- package/dist/types/src/defs/types.test.d.ts.map +0 -1
- package/dist/types/src/defs/util.d.ts +0 -43
- package/dist/types/src/defs/util.d.ts.map +0 -1
- package/dist/types/src/extensions/compute.d.ts +0 -6
- package/dist/types/src/extensions/compute.d.ts.map +0 -1
- package/dist/types/src/extensions/compute.stories.d.ts +0 -26
- package/dist/types/src/extensions/compute.stories.d.ts.map +0 -1
- package/dist/types/src/extensions/editor/extension.d.ts.map +0 -1
- package/dist/types/src/extensions/editor/extension.test.d.ts.map +0 -1
- package/dist/types/src/extensions/editor/index.d.ts +0 -2
- package/dist/types/src/extensions/editor/index.d.ts.map +0 -1
- package/dist/types/src/extensions/index.d.ts +0 -3
- package/dist/types/src/extensions/index.d.ts.map +0 -1
- package/dist/types/src/graph/compute-graph-registry.d.ts +0 -34
- package/dist/types/src/graph/compute-graph-registry.d.ts.map +0 -1
- package/dist/types/src/graph/compute-graph.d.ts +0 -64
- package/dist/types/src/graph/compute-graph.d.ts.map +0 -1
- package/dist/types/src/graph/compute-graph.stories.d.ts +0 -10
- package/dist/types/src/graph/compute-graph.stories.d.ts.map +0 -1
- package/dist/types/src/graph/compute-graph.test.d.ts +0 -2
- package/dist/types/src/graph/compute-graph.test.d.ts.map +0 -1
- package/dist/types/src/graph/compute-node.d.ts +0 -26
- package/dist/types/src/graph/compute-node.d.ts.map +0 -1
- package/dist/types/src/graph/functions/async-function.d.ts.map +0 -1
- package/dist/types/src/graph/functions/edge-function.d.ts +0 -21
- package/dist/types/src/graph/functions/edge-function.d.ts.map +0 -1
- package/dist/types/src/graph/functions/function-defs.d.ts.map +0 -1
- package/dist/types/src/graph/functions/index.d.ts +0 -4
- package/dist/types/src/graph/functions/index.d.ts.map +0 -1
- package/dist/types/src/graph/hyperformula.test.d.ts +0 -2
- package/dist/types/src/graph/hyperformula.test.d.ts.map +0 -1
- package/dist/types/src/graph/index.d.ts +0 -5
- package/dist/types/src/graph/index.d.ts.map +0 -1
- package/dist/types/src/graph/testing/index.d.ts +0 -3
- package/dist/types/src/graph/testing/index.d.ts.map +0 -1
- package/dist/types/src/graph/testing/test-builder.d.ts +0 -15
- package/dist/types/src/graph/testing/test-builder.d.ts.map +0 -1
- package/dist/types/src/graph/testing/test-plugin.d.ts +0 -36
- package/dist/types/src/graph/testing/test-plugin.d.ts.map +0 -1
- package/dist/types/src/graph/util.d.ts +0 -2
- package/dist/types/src/graph/util.d.ts.map +0 -1
- package/dist/types/src/hooks/hooks.stories.d.ts +0 -11
- package/dist/types/src/hooks/hooks.stories.d.ts.map +0 -1
- package/dist/types/src/hooks/index.d.ts +0 -4
- package/dist/types/src/hooks/index.d.ts.map +0 -1
- package/dist/types/src/hooks/threads.d.ts +0 -8
- package/dist/types/src/hooks/threads.d.ts.map +0 -1
- package/dist/types/src/hooks/useComputeGraph.d.ts +0 -7
- package/dist/types/src/hooks/useComputeGraph.d.ts.map +0 -1
- package/dist/types/src/hooks/useSheetModel.d.ts +0 -8
- package/dist/types/src/hooks/useSheetModel.d.ts.map +0 -1
- package/dist/types/src/model/decorations.d.ts +0 -25
- package/dist/types/src/model/decorations.d.ts.map +0 -1
- package/dist/types/src/model/sheet-model.d.ts.map +0 -1
- package/dist/types/src/model/sheet-model.test.d.ts +0 -2
- package/dist/types/src/model/sheet-model.test.d.ts.map +0 -1
- package/dist/types/src/sanity.test.d.ts +0 -2
- package/dist/types/src/sanity.test.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -2
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/testing.d.ts +0 -8
- package/dist/types/src/testing/testing.d.ts.map +0 -1
- package/dist/vendor/hyperformula.mjs +0 -37145
- package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +0 -20
- package/src/components/FunctionEditor/FunctionEditor.tsx +0 -45
- package/src/components/FunctionEditor/index.ts +0 -5
- package/src/components/GridSheet/GridSheet.stories.tsx +0 -41
- package/src/components/GridSheet/GridSheet.tsx +0 -163
- package/src/components/GridSheet/index.ts +0 -5
- package/src/components/GridSheet/util.ts +0 -158
- package/src/components/SheetContainer/SheetContainer.stories.tsx +0 -40
- package/src/components/SheetContainer/SheetContainer.tsx +0 -27
- package/src/components/SheetContainer/index.ts +0 -7
- package/src/components/SheetContext/SheetContext.tsx +0 -104
- package/src/components/SheetContext/index.ts +0 -5
- package/src/defs/index.ts +0 -7
- package/src/defs/sheet-range-types.ts +0 -46
- package/src/defs/util.ts +0 -151
- package/src/extensions/compute.stories.tsx +0 -151
- package/src/extensions/compute.ts +0 -147
- package/src/extensions/index.ts +0 -6
- package/src/graph/compute-graph-registry.ts +0 -90
- package/src/graph/compute-graph.stories.tsx +0 -93
- package/src/graph/compute-graph.test.ts +0 -87
- package/src/graph/compute-graph.ts +0 -242
- package/src/graph/compute-node.ts +0 -63
- package/src/graph/functions/index.ts +0 -7
- package/src/graph/hyperformula.test.ts +0 -14
- package/src/graph/index.ts +0 -8
- package/src/graph/testing/index.ts +0 -6
- package/src/graph/testing/test-builder.ts +0 -54
- package/src/graph/util.ts +0 -8
- package/src/hooks/hooks.stories.tsx +0 -50
- package/src/hooks/index.ts +0 -7
- package/src/hooks/threads.ts +0 -147
- package/src/hooks/useComputeGraph.ts +0 -28
- package/src/hooks/useSheetModel.ts +0 -40
- package/src/meta.ts +0 -14
- package/src/model/decorations.ts +0 -64
- package/src/model/sheet-model.test.ts +0 -57
- package/src/model/sheet-model.ts +0 -418
- package/src/sanity.test.ts +0 -40
- package/src/testing/testing.tsx +0 -68
- /package/dist/types/src/{extensions/editor → components/CellEditor}/extension.test.d.ts +0 -0
- /package/dist/types/src/{defs → model}/types.test.d.ts +0 -0
- /package/src/{graph/functions/function-defs.ts → model/functions.ts} +0 -0
package/src/defs/util.ts
DELETED
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { randomBytes } from '@dxos/crypto';
|
|
6
|
-
import { create } from '@dxos/echo-schema';
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
addressFromA1Notation,
|
|
10
|
-
type CellAddress,
|
|
11
|
-
type CellRange,
|
|
12
|
-
DEFAULT_COLUMNS,
|
|
13
|
-
DEFAULT_ROWS,
|
|
14
|
-
MAX_COLUMNS,
|
|
15
|
-
MAX_ROWS,
|
|
16
|
-
} from './types';
|
|
17
|
-
import { type CreateSheetOptions, type SheetSize, SheetType } from '../types';
|
|
18
|
-
|
|
19
|
-
// TODO(burdon): Factor out from dxos/protocols to new common package.
|
|
20
|
-
export class ApiError extends Error {}
|
|
21
|
-
|
|
22
|
-
export class ReadonlyException extends ApiError {}
|
|
23
|
-
|
|
24
|
-
export class RangeException extends ApiError {
|
|
25
|
-
constructor(n: number) {
|
|
26
|
-
super();
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* With a string length of 8, the chance of a collision is 0.02% for a sheet with 10,000 strings.
|
|
32
|
-
*/
|
|
33
|
-
export const createIndex = (length = 8): string => {
|
|
34
|
-
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
35
|
-
const charactersLength = characters.length;
|
|
36
|
-
const randomBuffer = randomBytes(length);
|
|
37
|
-
return Array.from(randomBuffer, (byte) => characters[byte % charactersLength]).join('');
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const createIndices = (length: number): string[] => Array.from({ length }).map(() => createIndex());
|
|
41
|
-
|
|
42
|
-
export const insertIndices = (indices: string[], i: number, n: number, max: number) => {
|
|
43
|
-
if (i + n > max) {
|
|
44
|
-
throw new RangeException(i + n);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const idx = createIndices(n);
|
|
48
|
-
indices.splice(i, 0, ...idx);
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const initialize = (
|
|
52
|
-
sheet: SheetType,
|
|
53
|
-
{ rows = DEFAULT_ROWS, columns = DEFAULT_COLUMNS }: Partial<SheetSize> = {},
|
|
54
|
-
) => {
|
|
55
|
-
if (!sheet.rows.length) {
|
|
56
|
-
insertIndices(sheet.rows, 0, rows, MAX_ROWS);
|
|
57
|
-
}
|
|
58
|
-
if (!sheet.columns.length) {
|
|
59
|
-
insertIndices(sheet.columns, 0, columns, MAX_COLUMNS);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const createSheet = ({ name, cells, ...size }: CreateSheetOptions = {}): SheetType => {
|
|
64
|
-
const sheet = create(SheetType, {
|
|
65
|
-
name,
|
|
66
|
-
cells: {},
|
|
67
|
-
rows: [],
|
|
68
|
-
columns: [],
|
|
69
|
-
rowMeta: {},
|
|
70
|
-
columnMeta: {},
|
|
71
|
-
ranges: [],
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
initialize(sheet, size);
|
|
75
|
-
|
|
76
|
-
if (cells) {
|
|
77
|
-
Object.entries(cells).forEach(([key, { value }]) => {
|
|
78
|
-
const idx = addressToIndex(sheet, addressFromA1Notation(key));
|
|
79
|
-
sheet.cells[idx] = { value };
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return sheet;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* E.g., "A1" => "CA2@CB3".
|
|
88
|
-
*/
|
|
89
|
-
export const addressToIndex = (sheet: SheetType, cell: CellAddress): string => {
|
|
90
|
-
return `${sheet.columns[cell.col]}@${sheet.rows[cell.row]}`;
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* E.g., "CA2@CB3" => "A1".
|
|
95
|
-
*/
|
|
96
|
-
export const addressFromIndex = (sheet: SheetType, idx: string): CellAddress => {
|
|
97
|
-
const [column, row] = idx.split('@');
|
|
98
|
-
return {
|
|
99
|
-
col: sheet.columns.indexOf(column),
|
|
100
|
-
row: sheet.rows.indexOf(row),
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* E.g., "A1:B2" => "CA2@CB3:CC4@CD5".
|
|
106
|
-
*/
|
|
107
|
-
export const rangeToIndex = (sheet: SheetType, range: CellRange): string => {
|
|
108
|
-
return [range.from, range.to ?? range.from].map((cell) => addressToIndex(sheet, cell)).join(':');
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* E.g., "CA2@CB3:CC4@CD5" => "A1:B2".
|
|
113
|
-
*/
|
|
114
|
-
export const rangeFromIndex = (sheet: SheetType, idx: string): CellRange => {
|
|
115
|
-
const [from, to] = idx.split(':').map((index) => addressFromIndex(sheet, index));
|
|
116
|
-
return { from, to };
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Find closest cell to cursor.
|
|
121
|
-
*/
|
|
122
|
-
export const closest = (cursor: CellAddress, cells: CellAddress[]): CellAddress | undefined => {
|
|
123
|
-
let closestCell: CellAddress | undefined;
|
|
124
|
-
let closestDistance = Number.MAX_SAFE_INTEGER;
|
|
125
|
-
|
|
126
|
-
for (const cell of cells) {
|
|
127
|
-
const distance = Math.abs(cell.row - cursor.row) + Math.abs(cell.col - cursor.col);
|
|
128
|
-
if (distance < closestDistance) {
|
|
129
|
-
closestCell = cell;
|
|
130
|
-
closestDistance = distance;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return closestCell;
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Compares the positions of two cell indexes in a sheet.
|
|
139
|
-
* Sorts primarily by row, then by column if rows are equal.
|
|
140
|
-
*/
|
|
141
|
-
export const compareIndexPositions = (sheet: SheetType, indexA: string, indexB: string): number => {
|
|
142
|
-
const { row: rowA, col: columnA } = addressFromIndex(sheet, indexA);
|
|
143
|
-
const { row: rowB, col: columnB } = addressFromIndex(sheet, indexB);
|
|
144
|
-
|
|
145
|
-
// Sort by row first, then by column.
|
|
146
|
-
if (rowA !== rowB) {
|
|
147
|
-
return rowA - rowB;
|
|
148
|
-
} else {
|
|
149
|
-
return columnA - columnB;
|
|
150
|
-
}
|
|
151
|
-
};
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
import React, { useEffect, useMemo } from 'react';
|
|
7
|
-
|
|
8
|
-
import { PublicKey } from '@dxos/keys';
|
|
9
|
-
import { useSpace } from '@dxos/react-client/echo';
|
|
10
|
-
import { withClientProvider } from '@dxos/react-client/testing';
|
|
11
|
-
import { useThemeContext } from '@dxos/react-ui';
|
|
12
|
-
import {
|
|
13
|
-
createBasicExtensions,
|
|
14
|
-
createMarkdownExtensions,
|
|
15
|
-
createThemeExtensions,
|
|
16
|
-
decorateMarkdown,
|
|
17
|
-
documentId,
|
|
18
|
-
useTextEditor,
|
|
19
|
-
} from '@dxos/react-ui-editor';
|
|
20
|
-
import { withTheme, withLayout } from '@dxos/storybook-utils';
|
|
21
|
-
import { nonNullable } from '@dxos/util';
|
|
22
|
-
|
|
23
|
-
import { compute, computeGraphFacet } from './compute';
|
|
24
|
-
import { GridSheet, SheetProvider } from '../components';
|
|
25
|
-
import { useComputeGraph, useSheetModel } from '../hooks';
|
|
26
|
-
import { useTestSheet, withComputeGraphDecorator } from '../testing';
|
|
27
|
-
import { SheetType } from '../types';
|
|
28
|
-
|
|
29
|
-
const str = (...lines: string[]) => lines.join('\n');
|
|
30
|
-
|
|
31
|
-
type EditorProps = {
|
|
32
|
-
text?: string;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// TODO(burdon): Implement named expressions.
|
|
36
|
-
// https://hyperformula.handsontable.com/guide/cell-references.html
|
|
37
|
-
|
|
38
|
-
// TODO(burdon): Inline Adobe eCharts.
|
|
39
|
-
|
|
40
|
-
const SHEET_NAME = 'Test Sheet';
|
|
41
|
-
|
|
42
|
-
const Editor = ({ text }: EditorProps) => {
|
|
43
|
-
const id = useMemo(() => PublicKey.random(), []);
|
|
44
|
-
const { themeMode } = useThemeContext();
|
|
45
|
-
const space = useSpace();
|
|
46
|
-
const computeGraph = useComputeGraph(space);
|
|
47
|
-
const { parentRef, focusAttributes } = useTextEditor(
|
|
48
|
-
() => ({
|
|
49
|
-
initialValue: text,
|
|
50
|
-
extensions: [
|
|
51
|
-
createBasicExtensions(),
|
|
52
|
-
createMarkdownExtensions({ themeMode }),
|
|
53
|
-
createThemeExtensions({ themeMode, syntaxHighlighting: true }),
|
|
54
|
-
documentId.of(id.toHex()),
|
|
55
|
-
computeGraph && computeGraphFacet.of(computeGraph),
|
|
56
|
-
compute(),
|
|
57
|
-
decorateMarkdown(),
|
|
58
|
-
].filter(nonNullable),
|
|
59
|
-
}),
|
|
60
|
-
[computeGraph, themeMode],
|
|
61
|
-
);
|
|
62
|
-
|
|
63
|
-
return <div className='w-[40rem] overflow-hidden' ref={parentRef} {...focusAttributes} />;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const Grid = () => {
|
|
67
|
-
const space = useSpace();
|
|
68
|
-
const graph = useComputeGraph(space);
|
|
69
|
-
const sheet = useTestSheet(space, graph, { name: SHEET_NAME });
|
|
70
|
-
const model = useSheetModel(graph, sheet);
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
if (model) {
|
|
73
|
-
model.setValues({ A1: { value: 100 }, A2: { value: 200 }, A3: { value: 300 }, A5: { value: '=SUM(A1:A3)' } });
|
|
74
|
-
}
|
|
75
|
-
}, [model]);
|
|
76
|
-
|
|
77
|
-
if (!graph || !sheet) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return (
|
|
82
|
-
<div className='flex w-[40rem] overflow-hidden'>
|
|
83
|
-
<SheetProvider graph={graph} sheet={sheet}>
|
|
84
|
-
<GridSheet />
|
|
85
|
-
</SheetProvider>
|
|
86
|
-
</div>
|
|
87
|
-
);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const Story = (props: EditorProps) => {
|
|
91
|
-
return (
|
|
92
|
-
<div className='grid grid-rows-2'>
|
|
93
|
-
<Editor {...props} />
|
|
94
|
-
<Grid />
|
|
95
|
-
</div>
|
|
96
|
-
);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
export default {
|
|
100
|
-
title: 'plugin-sheet/extensions',
|
|
101
|
-
decorators: [
|
|
102
|
-
withClientProvider({ types: [SheetType], createIdentity: true, createSpace: true }),
|
|
103
|
-
withComputeGraphDecorator(),
|
|
104
|
-
withTheme,
|
|
105
|
-
withLayout({ fullscreen: true, classNames: 'justify-center' }),
|
|
106
|
-
],
|
|
107
|
-
parameters: { layout: 'fullscreen' },
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// TODO(burdon): Inline formulae.
|
|
111
|
-
export const Default = {
|
|
112
|
-
render: Editor,
|
|
113
|
-
args: {
|
|
114
|
-
text: str(
|
|
115
|
-
//
|
|
116
|
-
'# Compute Graph',
|
|
117
|
-
'',
|
|
118
|
-
'This is a compute expression:',
|
|
119
|
-
'',
|
|
120
|
-
'```dx',
|
|
121
|
-
'=SUM(1, 2)',
|
|
122
|
-
'```',
|
|
123
|
-
'',
|
|
124
|
-
'It should change in realtime.',
|
|
125
|
-
'',
|
|
126
|
-
'```dx',
|
|
127
|
-
'=SUM(3, 5)',
|
|
128
|
-
'```',
|
|
129
|
-
'',
|
|
130
|
-
'',
|
|
131
|
-
),
|
|
132
|
-
},
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export const Graph = {
|
|
136
|
-
render: Story,
|
|
137
|
-
args: {
|
|
138
|
-
text: str(
|
|
139
|
-
//
|
|
140
|
-
'# Compute Graph',
|
|
141
|
-
'',
|
|
142
|
-
'The total projected cost is:',
|
|
143
|
-
'',
|
|
144
|
-
'```dx',
|
|
145
|
-
`="${SHEET_NAME}"!A5`,
|
|
146
|
-
'```',
|
|
147
|
-
'',
|
|
148
|
-
'',
|
|
149
|
-
),
|
|
150
|
-
},
|
|
151
|
-
};
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { syntaxTree } from '@codemirror/language';
|
|
6
|
-
import {
|
|
7
|
-
type EditorState,
|
|
8
|
-
type Extension,
|
|
9
|
-
type RangeSet,
|
|
10
|
-
RangeSetBuilder,
|
|
11
|
-
StateEffect,
|
|
12
|
-
StateField,
|
|
13
|
-
type Transaction,
|
|
14
|
-
} from '@codemirror/state';
|
|
15
|
-
import { Decoration, EditorView, ViewPlugin, WidgetType } from '@codemirror/view';
|
|
16
|
-
|
|
17
|
-
import { type UnsubscribeCallback, debounce } from '@dxos/async';
|
|
18
|
-
import { invariant } from '@dxos/invariant';
|
|
19
|
-
import { documentId, singleValueFacet } from '@dxos/react-ui-editor/state';
|
|
20
|
-
|
|
21
|
-
import { type CellAddress } from '../defs';
|
|
22
|
-
import { type ComputeGraph, type ComputeNode, createSheetName } from '../graph';
|
|
23
|
-
import { type CellScalarValue } from '../types';
|
|
24
|
-
|
|
25
|
-
const LANGUAGE_TAG = 'dx';
|
|
26
|
-
|
|
27
|
-
// TODO(burdon): Create marker just for our decorator?
|
|
28
|
-
const updateAllDecorations = StateEffect.define<void>();
|
|
29
|
-
|
|
30
|
-
export const computeGraphFacet = singleValueFacet<ComputeGraph>();
|
|
31
|
-
|
|
32
|
-
export type ComputeOptions = {};
|
|
33
|
-
|
|
34
|
-
export const compute = (options: ComputeOptions = {}): Extension => {
|
|
35
|
-
let computeNode: ComputeNode | undefined;
|
|
36
|
-
|
|
37
|
-
const update = (state: EditorState, current?: RangeSet<Decoration>) => {
|
|
38
|
-
const builder = new RangeSetBuilder<Decoration>();
|
|
39
|
-
if (computeNode) {
|
|
40
|
-
computeNode.clear();
|
|
41
|
-
syntaxTree(state).iterate({
|
|
42
|
-
enter: (node) => {
|
|
43
|
-
switch (node.name) {
|
|
44
|
-
case 'FencedCode': {
|
|
45
|
-
const cursor = state.selection.main.head;
|
|
46
|
-
if (state.readOnly || cursor < node.from || cursor > node.to) {
|
|
47
|
-
const info = node.node.getChild('CodeInfo');
|
|
48
|
-
if (info) {
|
|
49
|
-
const type = state.sliceDoc(info.from, info.to);
|
|
50
|
-
const text = node.node.getChild('CodeText');
|
|
51
|
-
if (type === LANGUAGE_TAG && text) {
|
|
52
|
-
const formula = state.sliceDoc(text.from, text.to);
|
|
53
|
-
|
|
54
|
-
const iter = current?.iter(node.node.from);
|
|
55
|
-
if (iter?.value && iter?.value.spec.formula === formula) {
|
|
56
|
-
// Add existing widget.
|
|
57
|
-
builder.add(node.from, node.to, iter.value);
|
|
58
|
-
} else {
|
|
59
|
-
// TODO(burdon): Create ordered list of cells on each decoration run.
|
|
60
|
-
const cell: CellAddress = { col: node.node.from, row: 0 };
|
|
61
|
-
invariant(computeNode);
|
|
62
|
-
// NOTE: This triggers re-render (below).
|
|
63
|
-
computeNode.setValue(cell, formula);
|
|
64
|
-
const value = computeNode.getValue(cell);
|
|
65
|
-
builder.add(
|
|
66
|
-
node.from,
|
|
67
|
-
node.to,
|
|
68
|
-
Decoration.replace({
|
|
69
|
-
widget: new ComputeWidget(formula, value),
|
|
70
|
-
formula,
|
|
71
|
-
}),
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
break;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return builder.finish();
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
return [
|
|
89
|
-
ViewPlugin.fromClass(
|
|
90
|
-
class {
|
|
91
|
-
// Graph subscription.
|
|
92
|
-
private _subscription?: UnsubscribeCallback;
|
|
93
|
-
constructor(view: EditorView) {
|
|
94
|
-
const id = view.state.facet(documentId);
|
|
95
|
-
const computeGraph = view.state.facet(computeGraphFacet);
|
|
96
|
-
if (id && computeGraph) {
|
|
97
|
-
queueMicrotask(async () => {
|
|
98
|
-
computeNode = computeGraph.getOrCreateNode(createSheetName({ type: '', id }));
|
|
99
|
-
await computeNode.open();
|
|
100
|
-
|
|
101
|
-
// Trigger re-render if values updated.
|
|
102
|
-
// TODO(burdon): Trigger only if formula value updated (currently triggered during render).
|
|
103
|
-
this._subscription = computeNode.update.on(
|
|
104
|
-
debounce(({ type, ...rest }) => {
|
|
105
|
-
if (type === 'valuesUpdated') {
|
|
106
|
-
view.dispatch({
|
|
107
|
-
effects: updateAllDecorations.of(),
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}, 250),
|
|
111
|
-
);
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
destroy() {
|
|
117
|
-
this._subscription?.();
|
|
118
|
-
void computeNode?.close();
|
|
119
|
-
computeNode = undefined;
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
),
|
|
123
|
-
|
|
124
|
-
StateField.define<RangeSet<Decoration>>({
|
|
125
|
-
create: (state) => update(state),
|
|
126
|
-
update: (rangeSet: RangeSet<Decoration>, tr: Transaction) => update(tr.state, rangeSet),
|
|
127
|
-
provide: (field) => EditorView.decorations.from(field),
|
|
128
|
-
}),
|
|
129
|
-
];
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
// TODO(burdon): Click to edit.
|
|
133
|
-
class ComputeWidget extends WidgetType {
|
|
134
|
-
constructor(
|
|
135
|
-
private readonly formula: string,
|
|
136
|
-
private readonly value: CellScalarValue,
|
|
137
|
-
) {
|
|
138
|
-
super();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
override toDOM(_view: EditorView) {
|
|
142
|
-
const div = document.createElement('div');
|
|
143
|
-
div.setAttribute('title', this.formula);
|
|
144
|
-
div.innerText = String(this.value);
|
|
145
|
-
return div;
|
|
146
|
-
}
|
|
147
|
-
}
|
package/src/extensions/index.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
8
|
-
|
|
9
|
-
import { FunctionType } from '@dxos/plugin-script/types';
|
|
10
|
-
import { create, useSpace, Filter } from '@dxos/react-client/echo';
|
|
11
|
-
import { withClientProvider } from '@dxos/react-client/testing';
|
|
12
|
-
import { Toolbar, Button, Input } from '@dxos/react-ui';
|
|
13
|
-
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
14
|
-
import { withTheme } from '@dxos/storybook-utils';
|
|
15
|
-
|
|
16
|
-
import { testFunctionPlugins } from './testing';
|
|
17
|
-
import { createSheet } from '../defs';
|
|
18
|
-
import { useComputeGraph, useSheetModel } from '../hooks';
|
|
19
|
-
import { withComputeGraphDecorator } from '../testing';
|
|
20
|
-
import { SheetType } from '../types';
|
|
21
|
-
|
|
22
|
-
const FUNCTION_NAME = 'TEST';
|
|
23
|
-
|
|
24
|
-
const Story = () => {
|
|
25
|
-
const space = useSpace();
|
|
26
|
-
const graph = useComputeGraph(space);
|
|
27
|
-
const [sheet, setSheet] = useState<SheetType>();
|
|
28
|
-
const [text, setText] = useState(`${FUNCTION_NAME}(100)`);
|
|
29
|
-
const [result, setResult] = useState<any>();
|
|
30
|
-
const model = useSheetModel(graph, sheet);
|
|
31
|
-
useEffect(() => {
|
|
32
|
-
if (space) {
|
|
33
|
-
const sheet = space.db.add(createSheet());
|
|
34
|
-
setSheet(sheet);
|
|
35
|
-
}
|
|
36
|
-
}, [space]);
|
|
37
|
-
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (space && graph) {
|
|
40
|
-
graph.update.on(() => {
|
|
41
|
-
const f1 = graph.getFunctions({ standard: true, echo: false });
|
|
42
|
-
const f2 = graph.getFunctions({ standard: false, echo: true });
|
|
43
|
-
setResult({ functions: { standard: f1.length, echo: f2.length } });
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
space.db.add(create(FunctionType, { version: 1, binding: FUNCTION_NAME }));
|
|
47
|
-
}
|
|
48
|
-
}, [space, graph]);
|
|
49
|
-
|
|
50
|
-
const inputRef = useRef<HTMLInputElement | null>(null);
|
|
51
|
-
const handleTest = async () => {
|
|
52
|
-
if (space && graph) {
|
|
53
|
-
const { objects } = await space.db.query(Filter.schema(FunctionType)).run();
|
|
54
|
-
const mapped = graph.mapFunctionBindingToId(text);
|
|
55
|
-
const unmapped = graph.mapFunctionBindingFromId(mapped);
|
|
56
|
-
const internal = graph.mapFormulaToNative(text);
|
|
57
|
-
setResult({ mapped, unmapped, internal, functions: objects.map((object) => object.id) });
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
inputRef.current?.focus();
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<div className='flex flex-col gap-2 '>
|
|
65
|
-
<Toolbar.Root>
|
|
66
|
-
<Input.Root>
|
|
67
|
-
<Input.TextInput
|
|
68
|
-
ref={inputRef}
|
|
69
|
-
placeholder='Formula'
|
|
70
|
-
value={text}
|
|
71
|
-
onChange={(ev) => setText(ev.target.value)}
|
|
72
|
-
/>
|
|
73
|
-
</Input.Root>
|
|
74
|
-
<Button onClick={handleTest}>Test</Button>
|
|
75
|
-
</Toolbar.Root>
|
|
76
|
-
<SyntaxHighlighter language='json'>
|
|
77
|
-
{JSON.stringify({ space: space?.id, graph: graph?.id, sheet: sheet?.id, model: model?.id, result }, null, 2)}
|
|
78
|
-
</SyntaxHighlighter>
|
|
79
|
-
</div>
|
|
80
|
-
);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export default {
|
|
84
|
-
title: 'plugin-sheet/functions',
|
|
85
|
-
decorators: [
|
|
86
|
-
withClientProvider({ types: [FunctionType, SheetType], createIdentity: true, createSpace: true }),
|
|
87
|
-
withComputeGraphDecorator({ plugins: testFunctionPlugins }),
|
|
88
|
-
withTheme,
|
|
89
|
-
],
|
|
90
|
-
render: (args: any) => <Story {...args} />,
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
export const Default = {};
|