@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/SheetPlugin.tsx
CHANGED
|
@@ -2,71 +2,84 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type IconProps, GridNine } from '@phosphor-icons/react';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
-
|
|
8
|
+
import {
|
|
9
|
+
NavigationAction,
|
|
10
|
+
parseIntentPlugin,
|
|
11
|
+
resolvePlugin,
|
|
12
|
+
type PluginDefinition,
|
|
13
|
+
type LayoutCoordinate,
|
|
14
|
+
} from '@dxos/app-framework';
|
|
15
|
+
import { create } from '@dxos/echo-schema';
|
|
9
16
|
import { parseClientPlugin } from '@dxos/plugin-client';
|
|
10
|
-
import { createExtension, isActionGroup
|
|
17
|
+
import { type ActionGroup, createExtension, isActionGroup } from '@dxos/plugin-graph';
|
|
11
18
|
import { FunctionType } from '@dxos/plugin-script/types';
|
|
12
19
|
import { SpaceAction } from '@dxos/plugin-space';
|
|
13
20
|
import { getSpace, isEchoObject } from '@dxos/react-client/echo';
|
|
14
|
-
import { Icon } from '@dxos/react-ui';
|
|
15
21
|
|
|
16
|
-
import {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
import {
|
|
23
|
+
createComputeGraph,
|
|
24
|
+
CustomPlugin,
|
|
25
|
+
CustomPluginTranslations,
|
|
26
|
+
SheetContainer,
|
|
27
|
+
type ComputeGraph,
|
|
28
|
+
} from './components';
|
|
29
|
+
// TODO(wittjosiah): Refactor. These are not exported from ./components due to depending on ECHO.
|
|
30
|
+
import { EdgeFunctionPlugin, EdgeFunctionPluginTranslations } from './components/ComputeGraph/edge-function';
|
|
31
|
+
import { ComputeGraphContextProvider } from './components/ComputeGraph/graph-context';
|
|
21
32
|
import meta, { SHEET_PLUGIN } from './meta';
|
|
33
|
+
import { SheetModel } from './model';
|
|
22
34
|
import translations from './translations';
|
|
23
|
-
import {
|
|
35
|
+
import { createSheet, SheetAction, type SheetPluginProvides, SheetType } from './types';
|
|
24
36
|
|
|
25
37
|
export const SheetPlugin = (): PluginDefinition<SheetPluginProvides> => {
|
|
26
|
-
let
|
|
38
|
+
let remoteFunctionUrl: string | undefined;
|
|
39
|
+
|
|
40
|
+
const graphs = create<Record<string, ComputeGraph>>({});
|
|
41
|
+
const setGraph = (key: string, graph: ComputeGraph) => {
|
|
42
|
+
graphs[key] = graph;
|
|
43
|
+
};
|
|
27
44
|
|
|
28
45
|
return {
|
|
29
46
|
meta,
|
|
30
47
|
ready: async (plugins) => {
|
|
31
48
|
const client = resolvePlugin(plugins, parseClientPlugin)?.provides.client;
|
|
32
|
-
|
|
33
|
-
|
|
49
|
+
if (!client) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
34
53
|
if (client.config.values.runtime?.services?.edge?.url) {
|
|
35
54
|
const url = new URL('/functions', client.config.values.runtime?.services?.edge?.url);
|
|
36
55
|
url.protocol = 'https';
|
|
37
56
|
remoteFunctionUrl = url.toString();
|
|
38
57
|
}
|
|
39
|
-
|
|
40
|
-
// Async import removes direct dependency on hyperformula.
|
|
41
|
-
const { ComputeGraphRegistry } = await import('./graph');
|
|
42
|
-
computeGraphRegistry = new ComputeGraphRegistry({ remoteFunctionUrl });
|
|
43
58
|
},
|
|
44
59
|
provides: {
|
|
45
60
|
context: ({ children }) => {
|
|
46
|
-
|
|
47
|
-
|
|
61
|
+
return (
|
|
62
|
+
<ComputeGraphContextProvider graphs={graphs} setGraph={setGraph}>
|
|
63
|
+
{children}
|
|
64
|
+
</ComputeGraphContextProvider>
|
|
65
|
+
);
|
|
48
66
|
},
|
|
49
67
|
metadata: {
|
|
50
68
|
records: {
|
|
51
69
|
[SheetType.typename]: {
|
|
52
|
-
label: (object: any) => (object instanceof SheetType ? object.
|
|
70
|
+
label: (object: any) => (object instanceof SheetType ? object.title : undefined),
|
|
53
71
|
placeholder: ['sheet title placeholder', { ns: SHEET_PLUGIN }],
|
|
54
|
-
icon:
|
|
72
|
+
icon: (props: IconProps) => <GridNine {...props} />,
|
|
73
|
+
iconSymbol: 'ph--grid-nine--regular',
|
|
55
74
|
},
|
|
56
75
|
},
|
|
57
76
|
},
|
|
58
77
|
translations,
|
|
59
78
|
echo: {
|
|
60
79
|
// TODO(wittjosiah): Factor out to common package/plugin.
|
|
61
|
-
//
|
|
80
|
+
// FunctionType is currently registered here in case script plugin isn't enabled.
|
|
62
81
|
schema: [SheetType, FunctionType],
|
|
63
82
|
},
|
|
64
|
-
space: {
|
|
65
|
-
onSpaceCreate: {
|
|
66
|
-
label: ['create sheet label', { ns: SHEET_PLUGIN }],
|
|
67
|
-
action: SheetAction.CREATE,
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
83
|
graph: {
|
|
71
84
|
builder: (plugins) => {
|
|
72
85
|
const client = resolvePlugin(plugins, parseClientPlugin)?.provides.client;
|
|
@@ -100,7 +113,8 @@ export const SheetPlugin = (): PluginDefinition<SheetPluginProvides> => {
|
|
|
100
113
|
},
|
|
101
114
|
properties: {
|
|
102
115
|
label: ['create sheet label', { ns: SHEET_PLUGIN }],
|
|
103
|
-
icon:
|
|
116
|
+
icon: (props: IconProps) => <GridNine {...props} />,
|
|
117
|
+
iconSymbol: 'ph--grid-nine--regular',
|
|
104
118
|
testId: 'sheetPlugin.createObject',
|
|
105
119
|
},
|
|
106
120
|
},
|
|
@@ -109,16 +123,6 @@ export const SheetPlugin = (): PluginDefinition<SheetPluginProvides> => {
|
|
|
109
123
|
});
|
|
110
124
|
},
|
|
111
125
|
},
|
|
112
|
-
markdown: {
|
|
113
|
-
extensions: ({ document: doc }) => {
|
|
114
|
-
invariant(computeGraphRegistry);
|
|
115
|
-
const space = getSpace(doc);
|
|
116
|
-
if (space) {
|
|
117
|
-
const computeGraph = computeGraphRegistry.getOrCreateGraph(space);
|
|
118
|
-
return computeGraphFacet.of(computeGraph);
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
126
|
stack: {
|
|
123
127
|
creators: [
|
|
124
128
|
{
|
|
@@ -126,8 +130,7 @@ export const SheetPlugin = (): PluginDefinition<SheetPluginProvides> => {
|
|
|
126
130
|
testId: 'sheetPlugin.createSection',
|
|
127
131
|
type: ['plugin name', { ns: SHEET_PLUGIN }],
|
|
128
132
|
label: ['create sheet section label', { ns: SHEET_PLUGIN }],
|
|
129
|
-
|
|
130
|
-
icon: (props: any) => <Icon icon='ph--grid-nine--regular' {...props} />,
|
|
133
|
+
icon: (props: any) => <GridNine {...props} />,
|
|
131
134
|
intent: {
|
|
132
135
|
plugin: SHEET_PLUGIN,
|
|
133
136
|
action: SheetAction.CREATE,
|
|
@@ -135,20 +138,23 @@ export const SheetPlugin = (): PluginDefinition<SheetPluginProvides> => {
|
|
|
135
138
|
},
|
|
136
139
|
],
|
|
137
140
|
},
|
|
138
|
-
thread: {
|
|
139
|
-
predicate: (data) => data instanceof SheetType,
|
|
140
|
-
createSort: (sheet) => (indexA, indexB) =>
|
|
141
|
-
!indexA || !indexB ? 0 : compareIndexPositions(sheet, indexA, indexB),
|
|
142
|
-
},
|
|
143
141
|
surface: {
|
|
144
|
-
component: ({ data, role }) => {
|
|
145
|
-
|
|
146
|
-
const
|
|
147
|
-
if (
|
|
142
|
+
component: ({ data, role = 'never' }) => {
|
|
143
|
+
// TODO(burdon): Standardize wrapper (with room for toolbar).
|
|
144
|
+
const space = isEchoObject(data.object) && getSpace(data.object);
|
|
145
|
+
if (space && data.object instanceof SheetType) {
|
|
148
146
|
switch (role) {
|
|
149
147
|
case 'article':
|
|
150
148
|
case 'section': {
|
|
151
|
-
return
|
|
149
|
+
return (
|
|
150
|
+
<SheetContainer
|
|
151
|
+
sheet={data.object}
|
|
152
|
+
space={space}
|
|
153
|
+
role={role}
|
|
154
|
+
coordinate={data.coordinate as LayoutCoordinate}
|
|
155
|
+
remoteFunctionUrl={remoteFunctionUrl}
|
|
156
|
+
/>
|
|
157
|
+
);
|
|
152
158
|
}
|
|
153
159
|
}
|
|
154
160
|
}
|
|
@@ -160,7 +166,23 @@ export const SheetPlugin = (): PluginDefinition<SheetPluginProvides> => {
|
|
|
160
166
|
resolver: async (intent) => {
|
|
161
167
|
switch (intent.action) {
|
|
162
168
|
case SheetAction.CREATE: {
|
|
163
|
-
|
|
169
|
+
const space = intent.data?.space;
|
|
170
|
+
const sheet = createSheet();
|
|
171
|
+
const graph =
|
|
172
|
+
graphs[space.id] ??
|
|
173
|
+
createComputeGraph(
|
|
174
|
+
[
|
|
175
|
+
{ plugin: EdgeFunctionPlugin, translations: EdgeFunctionPluginTranslations },
|
|
176
|
+
// TODO(wittjosiah): Remove. Needed for current test sheet generated data.
|
|
177
|
+
{ plugin: CustomPlugin, translations: CustomPluginTranslations },
|
|
178
|
+
],
|
|
179
|
+
space,
|
|
180
|
+
{ remoteFunctionUrl },
|
|
181
|
+
);
|
|
182
|
+
const model = new SheetModel(graph, sheet);
|
|
183
|
+
await model.initialize();
|
|
184
|
+
await model.destroy();
|
|
185
|
+
return { data: sheet };
|
|
164
186
|
}
|
|
165
187
|
}
|
|
166
188
|
},
|
package/src/components/{GridSheet/SheetCellEditor.stories.tsx → CellEditor/CellEditor.stories.tsx}
RENAMED
|
@@ -4,19 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
|
+
import { HyperFormula } from 'hyperformula';
|
|
7
8
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
8
9
|
|
|
9
10
|
import { Client } from '@dxos/client';
|
|
10
11
|
import { createDocAccessor, type EchoReactiveObject } from '@dxos/client/echo';
|
|
11
12
|
import { automerge } from '@dxos/react-ui-editor';
|
|
12
|
-
import { CellEditor, type CellEditorProps } from '@dxos/react-ui-grid';
|
|
13
13
|
import { withTheme } from '@dxos/storybook-utils';
|
|
14
14
|
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { SheetType } from '../../types';
|
|
15
|
+
import { CellEditor, type CellEditorProps } from './CellEditor';
|
|
16
|
+
import { sheetExtension } from './extension';
|
|
17
|
+
import { defaultFunctions } from '../../model';
|
|
18
|
+
import { createSheet, SheetType } from '../../types';
|
|
20
19
|
|
|
21
20
|
export default {
|
|
22
21
|
title: 'plugin-sheet/CellEditor',
|
|
@@ -42,13 +41,14 @@ const AutomergeStory = ({ value, ...props }: StoryProps) => {
|
|
|
42
41
|
const [object, setObject] = useState<EchoReactiveObject<SheetType>>();
|
|
43
42
|
useEffect(() => {
|
|
44
43
|
setTimeout(async () => {
|
|
45
|
-
const client = new Client(
|
|
44
|
+
const client = new Client();
|
|
46
45
|
await client.initialize();
|
|
47
46
|
await client.halo.createIdentity();
|
|
48
47
|
const space = await client.spaces.create();
|
|
48
|
+
client.addTypes([SheetType]);
|
|
49
49
|
|
|
50
50
|
const sheet = createSheet();
|
|
51
|
-
sheet.
|
|
51
|
+
sheet.title = 'Test';
|
|
52
52
|
sheet.cells[cell] = { value };
|
|
53
53
|
space.db.add(sheet);
|
|
54
54
|
setObject(sheet);
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Extension } from '@codemirror/state';
|
|
6
|
+
import { EditorView, keymap } from '@codemirror/view';
|
|
7
|
+
import React, { type DOMAttributes, type KeyboardEvent } from 'react';
|
|
8
|
+
|
|
9
|
+
import { useThemeContext } from '@dxos/react-ui';
|
|
10
|
+
import {
|
|
11
|
+
type UseTextEditorProps,
|
|
12
|
+
createBasicExtensions,
|
|
13
|
+
createThemeExtensions,
|
|
14
|
+
preventNewline,
|
|
15
|
+
useTextEditor,
|
|
16
|
+
} from '@dxos/react-ui-editor';
|
|
17
|
+
|
|
18
|
+
export type EditorKeysProps = {
|
|
19
|
+
onClose: (value: string | undefined) => void;
|
|
20
|
+
onNav?: (value: string | undefined, ev: Pick<KeyboardEvent<HTMLInputElement>, 'key'>) => void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const editorKeys = ({ onNav, onClose }: EditorKeysProps): Extension => {
|
|
24
|
+
return keymap.of([
|
|
25
|
+
{
|
|
26
|
+
key: 'ArrowUp',
|
|
27
|
+
run: (editor) => {
|
|
28
|
+
const value = editor.state.doc.toString();
|
|
29
|
+
onNav?.(value, { key: 'ArrowUp' });
|
|
30
|
+
return !!onNav;
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
key: 'ArrowDown',
|
|
35
|
+
run: (editor) => {
|
|
36
|
+
const value = editor.state.doc.toString();
|
|
37
|
+
onNav?.(value, { key: 'ArrowDown' });
|
|
38
|
+
return !!onNav;
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
key: 'ArrowLeft',
|
|
43
|
+
run: (editor) => {
|
|
44
|
+
const value = editor.state.doc.toString();
|
|
45
|
+
onNav?.(value, { key: 'ArrowLeft' });
|
|
46
|
+
return !!onNav;
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
key: 'ArrowRight',
|
|
51
|
+
run: (editor) => {
|
|
52
|
+
const value = editor.state.doc.toString();
|
|
53
|
+
onNav?.(value, { key: 'ArrowRight' });
|
|
54
|
+
return !!onNav;
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
key: 'Enter',
|
|
59
|
+
run: (editor) => {
|
|
60
|
+
onClose(editor.state.doc.toString());
|
|
61
|
+
return true;
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
key: 'Escape',
|
|
66
|
+
run: () => {
|
|
67
|
+
onClose(undefined);
|
|
68
|
+
return true;
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
]);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export type CellEditorProps = {
|
|
75
|
+
value?: string;
|
|
76
|
+
extension?: Extension;
|
|
77
|
+
} & Pick<UseTextEditorProps, 'autoFocus'> &
|
|
78
|
+
Pick<DOMAttributes<HTMLInputElement>, 'onBlur' | 'onKeyDown'>;
|
|
79
|
+
|
|
80
|
+
export const CellEditor = ({ value, extension, autoFocus, onBlur }: CellEditorProps) => {
|
|
81
|
+
const { themeMode } = useThemeContext();
|
|
82
|
+
const { parentRef } = useTextEditor(() => {
|
|
83
|
+
return {
|
|
84
|
+
autoFocus,
|
|
85
|
+
initialValue: value,
|
|
86
|
+
selection: { anchor: value?.length ?? 0 },
|
|
87
|
+
extensions: [
|
|
88
|
+
extension ?? [],
|
|
89
|
+
preventNewline,
|
|
90
|
+
EditorView.focusChangeEffect.of((_, focusing) => {
|
|
91
|
+
if (!focusing) {
|
|
92
|
+
onBlur?.({ type: 'blur' } as any);
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}),
|
|
96
|
+
createBasicExtensions({ lineWrapping: false }),
|
|
97
|
+
createThemeExtensions({
|
|
98
|
+
themeMode,
|
|
99
|
+
slots: {
|
|
100
|
+
editor: {
|
|
101
|
+
className: 'flex w-full [&>.cm-scroller]:scrollbar-none',
|
|
102
|
+
},
|
|
103
|
+
content: {
|
|
104
|
+
className: '!px-2 !py-1',
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
}),
|
|
108
|
+
],
|
|
109
|
+
};
|
|
110
|
+
}, [extension]);
|
|
111
|
+
|
|
112
|
+
return <div ref={parentRef} className='flex w-full' />;
|
|
113
|
+
};
|
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
import { CompletionContext, type CompletionSource } from '@codemirror/autocomplete';
|
|
6
6
|
import { EditorState } from '@codemirror/state';
|
|
7
|
+
// @ts-ignore
|
|
7
8
|
import { testTree } from '@lezer/generator/test';
|
|
9
|
+
import { expect } from 'chai';
|
|
8
10
|
import { spreadsheet } from 'codemirror-lang-spreadsheet';
|
|
9
|
-
import { describe,
|
|
11
|
+
import { describe, test } from 'vitest';
|
|
10
12
|
|
|
11
13
|
import { sheetExtension } from './extension';
|
|
12
|
-
import { defaultFunctions } from '../../
|
|
14
|
+
import { defaultFunctions } from '../../model/functions';
|
|
13
15
|
|
|
14
16
|
describe('formula parser', () => {
|
|
15
17
|
const {
|
|
@@ -35,8 +37,8 @@ describe('formula parser', () => {
|
|
|
35
37
|
extensions: sheetExtension({ functions }),
|
|
36
38
|
});
|
|
37
39
|
|
|
38
|
-
const [
|
|
39
|
-
const result = await
|
|
40
|
+
const [f] = state.languageDataAt<CompletionSource>('autocomplete', text.length);
|
|
41
|
+
const result = await f(new CompletionContext(state, text.length, true));
|
|
40
42
|
expect(result?.options).to.have.length(1);
|
|
41
43
|
});
|
|
42
44
|
});
|
|
@@ -12,16 +12,15 @@ import {
|
|
|
12
12
|
startCompletion,
|
|
13
13
|
} from '@codemirror/autocomplete';
|
|
14
14
|
import { HighlightStyle, type Language, syntaxHighlighting } from '@codemirror/language';
|
|
15
|
-
import { type Extension } from '@codemirror/state';
|
|
15
|
+
import { type Extension, Facet } from '@codemirror/state';
|
|
16
16
|
import { type EditorView, ViewPlugin, type ViewUpdate, keymap } from '@codemirror/view';
|
|
17
17
|
import { type SyntaxNode } from '@lezer/common';
|
|
18
18
|
import { tags } from '@lezer/highlight';
|
|
19
19
|
import { spreadsheet } from 'codemirror-lang-spreadsheet';
|
|
20
20
|
|
|
21
|
-
import { singleValueFacet } from '@dxos/react-ui-editor/state';
|
|
22
21
|
import { mx } from '@dxos/react-ui-theme';
|
|
23
22
|
|
|
24
|
-
import { type FunctionDefinition } from '../../
|
|
23
|
+
import { type FunctionDefinition } from '../../model';
|
|
25
24
|
|
|
26
25
|
/**
|
|
27
26
|
* https://codemirror.net/examples/styling
|
|
@@ -60,7 +59,7 @@ const highlightStyles = HighlightStyle.define([
|
|
|
60
59
|
},
|
|
61
60
|
]);
|
|
62
61
|
|
|
63
|
-
const languageFacet =
|
|
62
|
+
const languageFacet = Facet.define<Language>();
|
|
64
63
|
|
|
65
64
|
export type SheetExtensionOptions = {
|
|
66
65
|
functions?: FunctionDefinition[];
|
|
@@ -166,6 +165,8 @@ export const sheetExtension = ({ functions = [] }: SheetExtensionOptions): Exten
|
|
|
166
165
|
icons: false,
|
|
167
166
|
tooltipClass: () =>
|
|
168
167
|
mx(
|
|
168
|
+
// TODO(burdon): Factor out fragments.
|
|
169
|
+
// TODO(burdon): Size to make width same as column.
|
|
169
170
|
'!-left-[1px] !top-[33px] !-m-0 border !border-t-0 [&>ul]:!min-w-[198px]',
|
|
170
171
|
'[&>ul>li[aria-selected]]:!bg-accentSurface',
|
|
171
172
|
'border-separator',
|
|
@@ -230,7 +231,7 @@ export const rangeExtension = (onInit: (notifier: CellRangeNotifier) => void): E
|
|
|
230
231
|
|
|
231
232
|
// Find first Range or cell at cursor.
|
|
232
233
|
activeRange = undefined;
|
|
233
|
-
const language = view.state.facet(languageFacet);
|
|
234
|
+
const [language] = view.state.facet(languageFacet);
|
|
234
235
|
const { topNode } = language.parser.parse(view.state.doc.toString());
|
|
235
236
|
visitTree(topNode, ({ type, from, to }) => {
|
|
236
237
|
if (from <= anchor && to >= anchor) {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type
|
|
5
|
+
import { CellError, ErrorType, EmptyValue, FunctionPlugin, type HyperFormula } from 'hyperformula';
|
|
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,35 +12,28 @@ 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
|
-
|
|
16
|
-
|
|
17
|
-
// TODO(burdon): Create API gateways:
|
|
15
|
+
// TODO(burdon): API gateways!
|
|
18
16
|
// https://publicapis.io
|
|
19
17
|
// https://api-ninjas.com/api/cryptoprice
|
|
20
18
|
// https://developers.google.com/apis-explorer
|
|
21
19
|
// https://publicapis.io/coin-desk-api
|
|
22
20
|
|
|
21
|
+
// TODO(burdon): Create wrapper.
|
|
23
22
|
export type AsyncFunction = (...args: any) => Promise<InterpreterValue>;
|
|
24
23
|
|
|
25
|
-
export type FunctionUpdateEvent = {
|
|
26
|
-
name: string;
|
|
27
|
-
cell: SimpleCellAddress;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
24
|
export type FunctionOptions = {
|
|
31
25
|
ttl?: number;
|
|
32
26
|
};
|
|
33
27
|
|
|
34
28
|
export type FunctionContextOptions = {
|
|
35
29
|
defaultTtl: number;
|
|
36
|
-
|
|
30
|
+
recalculationDelay: number;
|
|
37
31
|
remoteFunctionUrl: string;
|
|
38
|
-
onUpdate?: (update: FunctionUpdateEvent) => void;
|
|
39
32
|
};
|
|
40
33
|
|
|
41
34
|
export const defaultFunctionContextOptions: FunctionContextOptions = {
|
|
42
35
|
defaultTtl: 5_000,
|
|
43
|
-
|
|
36
|
+
recalculationDelay: 200,
|
|
44
37
|
remoteFunctionUrl: 'https://edge.dxos.workers.dev/functions', // TODO(burdon): Config.
|
|
45
38
|
};
|
|
46
39
|
|
|
@@ -72,21 +65,21 @@ export class FunctionContext {
|
|
|
72
65
|
private _invocations: Record<string, number> = {};
|
|
73
66
|
|
|
74
67
|
private readonly _options: FunctionContextOptions;
|
|
75
|
-
|
|
76
|
-
// Debounced update handler.
|
|
77
|
-
private readonly _onUpdate: (update: FunctionUpdateEvent) => void;
|
|
68
|
+
private readonly _onUpdate: () => void;
|
|
78
69
|
|
|
79
70
|
constructor(
|
|
80
71
|
private readonly _hf: HyperFormula,
|
|
81
72
|
private readonly _space: Space | undefined,
|
|
73
|
+
onUpdate: (context: FunctionContext) => void,
|
|
82
74
|
_options?: Partial<FunctionContextOptions>,
|
|
83
75
|
) {
|
|
84
76
|
this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
|
|
85
|
-
this._onUpdate = debounce((
|
|
86
|
-
// TODO(burdon): Better way to trigger recalculation?
|
|
77
|
+
this._onUpdate = debounce(() => {
|
|
78
|
+
// TODO(burdon): Better way to trigger recalculation?
|
|
79
|
+
// NOTE: rebuildAndRecalculate resets the undo history.
|
|
87
80
|
this._hf.resumeEvaluation();
|
|
88
|
-
|
|
89
|
-
}, this._options.
|
|
81
|
+
onUpdate(this);
|
|
82
|
+
}, this._options.recalculationDelay);
|
|
90
83
|
}
|
|
91
84
|
|
|
92
85
|
get space() {
|
|
@@ -141,7 +134,7 @@ export class FunctionContext {
|
|
|
141
134
|
const value = await cb(...args);
|
|
142
135
|
this._cache.set(invocationKey, { value, ts: Date.now() });
|
|
143
136
|
log('set', { cell, value });
|
|
144
|
-
this._onUpdate(
|
|
137
|
+
this._onUpdate();
|
|
145
138
|
} catch (err) {
|
|
146
139
|
// TODO(burdon): Show error to user.
|
|
147
140
|
log.warn('failed', { cell, err });
|
|
@@ -160,15 +153,12 @@ export class FunctionContext {
|
|
|
160
153
|
/**
|
|
161
154
|
* Base class for async functions.
|
|
162
155
|
*/
|
|
163
|
-
export class
|
|
156
|
+
export class FunctionPluginAsync extends FunctionPlugin {
|
|
164
157
|
get context() {
|
|
165
158
|
return this.config.context as FunctionContext;
|
|
166
159
|
}
|
|
167
160
|
|
|
168
|
-
|
|
169
|
-
* Immediately returns cached value then runs the async function.
|
|
170
|
-
*/
|
|
171
|
-
protected runAsyncFunction(ast: ProcedureAst, state: InterpreterState, cb: AsyncFunction, options?: FunctionOptions) {
|
|
161
|
+
runAsyncFunction(ast: ProcedureAst, state: InterpreterState, cb: AsyncFunction, options?: FunctionOptions) {
|
|
172
162
|
const { procedureName } = ast;
|
|
173
163
|
const metadata = this.metadata(procedureName);
|
|
174
164
|
return this.runFunction(ast.args, state, metadata, (...args: any) => {
|
|
@@ -2,36 +2,24 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { FunctionArgumentType } from 'hyperformula';
|
|
5
6
|
import { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';
|
|
6
7
|
import { type ProcedureAst } from 'hyperformula/typings/parser';
|
|
7
8
|
|
|
8
9
|
import { getDeep } from '@dxos/util';
|
|
9
10
|
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
import { type AsyncFunction, FunctionPluginAsync } from './async-function';
|
|
12
|
+
|
|
13
|
+
// TODO(burdon): Factor out.
|
|
14
|
+
const parseNumberString = (str: string): number => {
|
|
15
|
+
return parseFloat(str.replace(/[^\d.]/g, ''));
|
|
16
|
+
};
|
|
14
17
|
|
|
15
18
|
/**
|
|
16
|
-
* Testing functions run locally (not run via EDGE).
|
|
17
19
|
* https://hyperformula.handsontable.com/guide/custom-functions.html#add-a-simple-custom-function
|
|
18
20
|
*/
|
|
19
|
-
export class
|
|
20
|
-
/**
|
|
21
|
-
* Simple local function returns input value.
|
|
22
|
-
*/
|
|
21
|
+
export class CustomPlugin extends FunctionPluginAsync {
|
|
23
22
|
test(ast: ProcedureAst, state: InterpreterState) {
|
|
24
|
-
const handler: AsyncFunction = async (_value) => {
|
|
25
|
-
return _value;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
return this.runAsyncFunction(ast, state, handler);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Simple local function returns random number.
|
|
33
|
-
*/
|
|
34
|
-
random(ast: ProcedureAst, state: InterpreterState) {
|
|
35
23
|
const handler: AsyncFunction = async () => {
|
|
36
24
|
return Math.random();
|
|
37
25
|
};
|
|
@@ -39,9 +27,6 @@ export class TestPlugin extends AsyncFunctionPlugin {
|
|
|
39
27
|
return this.runAsyncFunction(ast, state, handler);
|
|
40
28
|
}
|
|
41
29
|
|
|
42
|
-
/**
|
|
43
|
-
* Async HTTP function.
|
|
44
|
-
*/
|
|
45
30
|
crypto(ast: ProcedureAst, state: InterpreterState) {
|
|
46
31
|
const handler: AsyncFunction = async (_currency) => {
|
|
47
32
|
const currency = (_currency || 'USD').toUpperCase();
|
|
@@ -59,15 +44,9 @@ export class TestPlugin extends AsyncFunctionPlugin {
|
|
|
59
44
|
}
|
|
60
45
|
}
|
|
61
46
|
|
|
62
|
-
|
|
47
|
+
CustomPlugin.implementedFunctions = {
|
|
63
48
|
TEST: {
|
|
64
49
|
method: 'test',
|
|
65
|
-
parameters: [{ argumentType: FunctionArgumentType.NUMBER, optionalArg: false }],
|
|
66
|
-
isVolatile: true,
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
RANDOM: {
|
|
70
|
-
method: 'random',
|
|
71
50
|
parameters: [],
|
|
72
51
|
isVolatile: true,
|
|
73
52
|
},
|
|
@@ -79,22 +58,13 @@ TestPlugin.implementedFunctions = {
|
|
|
79
58
|
},
|
|
80
59
|
};
|
|
81
60
|
|
|
82
|
-
export const
|
|
61
|
+
export const CustomPluginTranslations = {
|
|
83
62
|
enGB: {
|
|
84
|
-
TEST: '
|
|
85
|
-
|
|
86
|
-
CRYPTO: 'Crypto token value',
|
|
63
|
+
TEST: 'TEST',
|
|
64
|
+
CRYPTO: 'CRYPTO',
|
|
87
65
|
},
|
|
88
66
|
enUS: {
|
|
89
|
-
TEST: '
|
|
90
|
-
|
|
91
|
-
CRYPTO: 'Crypto token value',
|
|
67
|
+
TEST: 'TEST',
|
|
68
|
+
CRYPTO: 'CRYPTO',
|
|
92
69
|
},
|
|
93
70
|
};
|
|
94
|
-
|
|
95
|
-
export const testFunctionPlugins: ComputeGraphPlugin[] = [
|
|
96
|
-
{
|
|
97
|
-
plugin: TestPlugin,
|
|
98
|
-
translations: TestPluginTranslations,
|
|
99
|
-
},
|
|
100
|
-
];
|