@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
|
@@ -1,71 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ValueTypeEnum
|
|
3
|
+
} from "./chunk-FUAGSXA4.mjs";
|
|
2
4
|
|
|
3
|
-
// packages/plugins/plugin-sheet/src/
|
|
4
|
-
import {
|
|
5
|
-
import { Filter as Filter2, fullyQualifiedId } from "@dxos/client/echo";
|
|
6
|
-
import { Resource as Resource2 } from "@dxos/context";
|
|
7
|
-
import { getTypename } from "@dxos/echo-schema";
|
|
8
|
-
import { invariant } from "@dxos/invariant";
|
|
9
|
-
import { PublicKey } from "@dxos/keys";
|
|
10
|
-
import { log as log3 } from "@dxos/log";
|
|
11
|
-
import { FunctionType as FunctionType2 } from "@dxos/plugin-script/types";
|
|
12
|
-
import { nonNullable as nonNullable2 } from "@dxos/util";
|
|
13
|
-
import { ExportedCellChange } from "#hyperformula";
|
|
14
|
-
|
|
15
|
-
// packages/plugins/plugin-sheet/src/graph/compute-node.ts
|
|
5
|
+
// packages/plugins/plugin-sheet/src/components/ComputeGraph/graph.ts
|
|
6
|
+
import { HyperFormula } from "hyperformula";
|
|
16
7
|
import { Event } from "@dxos/async";
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
var ComputeNode = class extends Resource {
|
|
20
|
-
constructor(_graph, sheetId) {
|
|
21
|
-
super();
|
|
22
|
-
this._graph = _graph;
|
|
23
|
-
this.sheetId = sheetId;
|
|
24
|
-
this.update = new Event();
|
|
25
|
-
}
|
|
26
|
-
get graph() {
|
|
27
|
-
return this._graph;
|
|
28
|
-
}
|
|
29
|
-
clear() {
|
|
30
|
-
this._graph.hf.clearSheet(this.sheetId);
|
|
31
|
-
}
|
|
32
|
-
getValue(cell) {
|
|
33
|
-
const value = this._graph.hf.getCellValue({
|
|
34
|
-
sheet: this.sheetId,
|
|
35
|
-
row: cell.row,
|
|
36
|
-
col: cell.col
|
|
37
|
-
});
|
|
38
|
-
if (value instanceof DetailedCellError) {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
return value;
|
|
42
|
-
}
|
|
43
|
-
setValue(cell, value) {
|
|
44
|
-
const mappedValue = typeof value === "string" && value.charAt(0) === "=" ? this._graph.mapFormulaToNative(value) : value;
|
|
45
|
-
this._graph.hf.setCellContents({
|
|
46
|
-
sheet: this.sheetId,
|
|
47
|
-
row: cell.row,
|
|
48
|
-
col: cell.col
|
|
49
|
-
}, [
|
|
50
|
-
[
|
|
51
|
-
mappedValue
|
|
52
|
-
]
|
|
53
|
-
]);
|
|
54
|
-
}
|
|
55
|
-
// TODO(burdon): Load data into sheet.
|
|
56
|
-
async _open() {
|
|
57
|
-
}
|
|
58
|
-
};
|
|
8
|
+
import { PublicKey } from "@dxos/keys";
|
|
9
|
+
import { log as log2 } from "@dxos/log";
|
|
59
10
|
|
|
60
|
-
// packages/plugins/plugin-sheet/src/
|
|
11
|
+
// packages/plugins/plugin-sheet/src/components/ComputeGraph/async-function.ts
|
|
12
|
+
import { CellError, ErrorType, EmptyValue, FunctionPlugin } from "hyperformula";
|
|
61
13
|
import defaultsDeep from "lodash.defaultsdeep";
|
|
62
14
|
import { debounce } from "@dxos/async";
|
|
63
15
|
import { log } from "@dxos/log";
|
|
64
|
-
|
|
65
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/functions/async-function.ts";
|
|
16
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/components/ComputeGraph/async-function.ts";
|
|
66
17
|
var defaultFunctionContextOptions = {
|
|
67
18
|
defaultTtl: 5e3,
|
|
68
|
-
|
|
19
|
+
recalculationDelay: 200,
|
|
69
20
|
remoteFunctionUrl: "https://edge.dxos.workers.dev/functions"
|
|
70
21
|
};
|
|
71
22
|
var FunctionContext = class _FunctionContext {
|
|
@@ -76,7 +27,7 @@ var FunctionContext = class _FunctionContext {
|
|
|
76
27
|
...args
|
|
77
28
|
});
|
|
78
29
|
}
|
|
79
|
-
constructor(_hf, _space, _options) {
|
|
30
|
+
constructor(_hf, _space, onUpdate, _options) {
|
|
80
31
|
this._hf = _hf;
|
|
81
32
|
this._space = _space;
|
|
82
33
|
this._cache = /* @__PURE__ */ new Map();
|
|
@@ -84,10 +35,10 @@ var FunctionContext = class _FunctionContext {
|
|
|
84
35
|
this._subscriptions = /* @__PURE__ */ new Map();
|
|
85
36
|
this._invocations = {};
|
|
86
37
|
this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
|
|
87
|
-
this._onUpdate = debounce((
|
|
38
|
+
this._onUpdate = debounce(() => {
|
|
88
39
|
this._hf.resumeEvaluation();
|
|
89
|
-
|
|
90
|
-
}, this._options.
|
|
40
|
+
onUpdate(this);
|
|
41
|
+
}, this._options.recalculationDelay);
|
|
91
42
|
}
|
|
92
43
|
get space() {
|
|
93
44
|
return this._space;
|
|
@@ -137,21 +88,18 @@ var FunctionContext = class _FunctionContext {
|
|
|
137
88
|
value: value2
|
|
138
89
|
}, {
|
|
139
90
|
F: __dxlog_file,
|
|
140
|
-
L:
|
|
91
|
+
L: 136,
|
|
141
92
|
S: this,
|
|
142
93
|
C: (f, a) => f(...a)
|
|
143
94
|
});
|
|
144
|
-
this._onUpdate(
|
|
145
|
-
name,
|
|
146
|
-
cell
|
|
147
|
-
});
|
|
95
|
+
this._onUpdate();
|
|
148
96
|
} catch (err) {
|
|
149
97
|
log.warn("failed", {
|
|
150
98
|
cell,
|
|
151
99
|
err
|
|
152
100
|
}, {
|
|
153
101
|
F: __dxlog_file,
|
|
154
|
-
L:
|
|
102
|
+
L: 140,
|
|
155
103
|
S: this,
|
|
156
104
|
C: (f, a) => f(...a)
|
|
157
105
|
});
|
|
@@ -171,20 +119,17 @@ var FunctionContext = class _FunctionContext {
|
|
|
171
119
|
cache: value
|
|
172
120
|
}, {
|
|
173
121
|
F: __dxlog_file,
|
|
174
|
-
L:
|
|
122
|
+
L: 148,
|
|
175
123
|
S: this,
|
|
176
124
|
C: (f, a) => f(...a)
|
|
177
125
|
});
|
|
178
126
|
return value;
|
|
179
127
|
}
|
|
180
128
|
};
|
|
181
|
-
var
|
|
129
|
+
var FunctionPluginAsync = class extends FunctionPlugin {
|
|
182
130
|
get context() {
|
|
183
131
|
return this.config.context;
|
|
184
132
|
}
|
|
185
|
-
/**
|
|
186
|
-
* Immediately returns cached value then runs the async function.
|
|
187
|
-
*/
|
|
188
133
|
runAsyncFunction(ast, state, cb, options) {
|
|
189
134
|
const { procedureName } = ast;
|
|
190
135
|
const metadata = this.metadata(procedureName);
|
|
@@ -194,127 +139,53 @@ var AsyncFunctionPlugin = class extends FunctionPlugin {
|
|
|
194
139
|
}
|
|
195
140
|
};
|
|
196
141
|
|
|
197
|
-
// packages/plugins/plugin-sheet/src/
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
var FUNCTION_TTL = 1e4;
|
|
208
|
-
var EdgeFunctionPlugin = class extends AsyncFunctionPlugin {
|
|
209
|
-
dx(ast, state) {
|
|
210
|
-
const handler = (subscribe = false) => async (binding, ...args) => {
|
|
211
|
-
const space = this.context.space;
|
|
212
|
-
if (!space) {
|
|
213
|
-
return new CellError2(ErrorType2.REF, "Missing space");
|
|
214
|
-
}
|
|
215
|
-
const { objects: [fn] } = await space.db.query(Filter.schema(FunctionType, {
|
|
216
|
-
binding
|
|
217
|
-
})).run();
|
|
218
|
-
if (!fn) {
|
|
219
|
-
log2.info("Function not found", {
|
|
220
|
-
binding
|
|
221
|
-
}, {
|
|
222
|
-
F: __dxlog_file2,
|
|
223
|
-
L: 41,
|
|
224
|
-
S: this,
|
|
225
|
-
C: (f, a) => f(...a)
|
|
226
|
-
});
|
|
227
|
-
return new CellError2(ErrorType2.REF, "Function not found");
|
|
228
|
-
}
|
|
229
|
-
if (subscribe) {
|
|
230
|
-
const unsubscribe = effect(() => {
|
|
231
|
-
log2.info("function changed", {
|
|
232
|
-
fn
|
|
233
|
-
}, {
|
|
234
|
-
F: __dxlog_file2,
|
|
235
|
-
L: 47,
|
|
236
|
-
S: this,
|
|
237
|
-
C: (f, a) => f(...a)
|
|
238
|
-
});
|
|
239
|
-
const _ = fn?.version;
|
|
240
|
-
this.runAsyncFunction(ast, state, handler(false), {
|
|
241
|
-
ttl: FUNCTION_TTL
|
|
242
|
-
});
|
|
243
|
-
});
|
|
244
|
-
this.context.createSubscription(ast.procedureName, unsubscribe);
|
|
245
|
-
}
|
|
246
|
-
const path = getUserFunctionUrlInMetadata(getMeta(fn));
|
|
247
|
-
const result = await fetch(`${this.context.remoteFunctionUrl}${path}`, {
|
|
248
|
-
method: "POST",
|
|
249
|
-
headers: {
|
|
250
|
-
"Content-Type": "application/json"
|
|
251
|
-
},
|
|
252
|
-
body: JSON.stringify({
|
|
253
|
-
args: args.filter(nonNullable)
|
|
254
|
-
})
|
|
255
|
-
});
|
|
256
|
-
return await result.text();
|
|
257
|
-
};
|
|
258
|
-
return this.runAsyncFunction(ast, state, handler(true), {
|
|
259
|
-
ttl: FUNCTION_TTL
|
|
260
|
-
});
|
|
261
|
-
}
|
|
142
|
+
// packages/plugins/plugin-sheet/src/components/ComputeGraph/graph.ts
|
|
143
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/components/ComputeGraph/graph.ts";
|
|
144
|
+
var createComputeGraph = (functionPlugins = [], space, options) => {
|
|
145
|
+
functionPlugins.forEach(({ plugin, translations }) => {
|
|
146
|
+
HyperFormula.registerFunctionPlugin(plugin, translations);
|
|
147
|
+
});
|
|
148
|
+
const hf = HyperFormula.buildEmpty({
|
|
149
|
+
licenseKey: "gpl-v3"
|
|
150
|
+
});
|
|
151
|
+
return new ComputeGraph(hf, space, options);
|
|
262
152
|
};
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
{
|
|
277
|
-
argumentType: FunctionArgumentType.ANY,
|
|
278
|
-
optionalArg: true
|
|
279
|
-
},
|
|
280
|
-
{
|
|
281
|
-
argumentType: FunctionArgumentType.ANY,
|
|
282
|
-
optionalArg: true
|
|
283
|
-
},
|
|
284
|
-
{
|
|
285
|
-
argumentType: FunctionArgumentType.ANY,
|
|
286
|
-
optionalArg: true
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
argumentType: FunctionArgumentType.ANY,
|
|
290
|
-
optionalArg: true
|
|
291
|
-
},
|
|
292
|
-
{
|
|
293
|
-
argumentType: FunctionArgumentType.ANY,
|
|
294
|
-
optionalArg: true
|
|
295
|
-
},
|
|
296
|
-
{
|
|
297
|
-
argumentType: FunctionArgumentType.ANY,
|
|
298
|
-
optionalArg: true
|
|
299
|
-
},
|
|
300
|
-
{
|
|
301
|
-
argumentType: FunctionArgumentType.ANY,
|
|
302
|
-
optionalArg: true
|
|
303
|
-
}
|
|
304
|
-
],
|
|
305
|
-
isVolatile: true
|
|
153
|
+
var ComputeGraph = class {
|
|
154
|
+
constructor(hf, _space, _options) {
|
|
155
|
+
this.hf = hf;
|
|
156
|
+
this._space = _space;
|
|
157
|
+
this._options = _options;
|
|
158
|
+
this.id = `graph-${PublicKey.random().truncate()}`;
|
|
159
|
+
this.update = new Event();
|
|
160
|
+
this.context = new FunctionContext(this.hf, this._space, () => {
|
|
161
|
+
this.refresh();
|
|
162
|
+
}, this._options);
|
|
163
|
+
this.hf.updateConfig({
|
|
164
|
+
context: this.context
|
|
165
|
+
});
|
|
306
166
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
167
|
+
refresh() {
|
|
168
|
+
log2("refresh", {
|
|
169
|
+
id: this.id
|
|
170
|
+
}, {
|
|
171
|
+
F: __dxlog_file2,
|
|
172
|
+
L: 59,
|
|
173
|
+
S: this,
|
|
174
|
+
C: (f, a) => f(...a)
|
|
175
|
+
});
|
|
176
|
+
this.update.emit();
|
|
314
177
|
}
|
|
315
178
|
};
|
|
316
179
|
|
|
317
|
-
// packages/plugins/plugin-sheet/src/
|
|
180
|
+
// packages/plugins/plugin-sheet/src/model/model.ts
|
|
181
|
+
import { DetailedCellError, ExportedCellChange } from "hyperformula";
|
|
182
|
+
import { Event as Event2 } from "@dxos/async";
|
|
183
|
+
import { Context } from "@dxos/context";
|
|
184
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
185
|
+
import { PublicKey as PublicKey2 } from "@dxos/keys";
|
|
186
|
+
import { log as log3 } from "@dxos/log";
|
|
187
|
+
|
|
188
|
+
// packages/plugins/plugin-sheet/src/model/functions.ts
|
|
318
189
|
var defaultFunctions = [
|
|
319
190
|
// Array
|
|
320
191
|
{
|
|
@@ -2688,281 +2559,677 @@ var defaultFunctions = [
|
|
|
2688
2559
|
}
|
|
2689
2560
|
];
|
|
2690
2561
|
|
|
2691
|
-
// packages/plugins/plugin-sheet/src/
|
|
2692
|
-
|
|
2693
|
-
var
|
|
2694
|
-
var
|
|
2695
|
-
var
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2562
|
+
// packages/plugins/plugin-sheet/src/model/types.ts
|
|
2563
|
+
import { invariant } from "@dxos/invariant";
|
|
2564
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/model/types.ts";
|
|
2565
|
+
var MAX_COLUMNS = 26 * 26;
|
|
2566
|
+
var posEquals = (a, b) => {
|
|
2567
|
+
return a?.column === b?.column && a?.row === b?.row;
|
|
2568
|
+
};
|
|
2569
|
+
var columnLetter = (column) => {
|
|
2570
|
+
invariant(column < MAX_COLUMNS, `Invalid column: ${column}`, {
|
|
2571
|
+
F: __dxlog_file3,
|
|
2572
|
+
L: 17,
|
|
2573
|
+
S: void 0,
|
|
2574
|
+
A: [
|
|
2575
|
+
"column < MAX_COLUMNS",
|
|
2576
|
+
"`Invalid column: ${column}`"
|
|
2577
|
+
]
|
|
2578
|
+
});
|
|
2579
|
+
return (column >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(column / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + column % 26);
|
|
2580
|
+
};
|
|
2581
|
+
var addressToA1Notation = ({ column, row }) => {
|
|
2582
|
+
return `${columnLetter(column)}${row + 1}`;
|
|
2583
|
+
};
|
|
2584
|
+
var addressFromA1Notation = (ref) => {
|
|
2585
|
+
const match = ref.match(/([A-Z]+)(\d+)/);
|
|
2586
|
+
invariant(match, `Invalid notation: ${ref}`, {
|
|
2587
|
+
F: __dxlog_file3,
|
|
2588
|
+
L: 30,
|
|
2589
|
+
S: void 0,
|
|
2590
|
+
A: [
|
|
2591
|
+
"match",
|
|
2592
|
+
"`Invalid notation: ${ref}`"
|
|
2593
|
+
]
|
|
2594
|
+
});
|
|
2595
|
+
return {
|
|
2596
|
+
row: parseInt(match[2], 10) - 1,
|
|
2597
|
+
column: match[1].split("").reduce((acc, c) => acc * 26 + c.charCodeAt(0) - "A".charCodeAt(0) + 1, 0) - 1
|
|
2702
2598
|
};
|
|
2703
2599
|
};
|
|
2704
|
-
var
|
|
2705
|
-
|
|
2600
|
+
var rangeToA1Notation = (range) => {
|
|
2601
|
+
return [
|
|
2602
|
+
range?.from && addressToA1Notation(range?.from),
|
|
2603
|
+
range?.to && addressToA1Notation(range?.to)
|
|
2604
|
+
].filter(Boolean).join(":");
|
|
2605
|
+
};
|
|
2606
|
+
var inRange = (range, cell) => {
|
|
2607
|
+
if (!range) {
|
|
2608
|
+
return false;
|
|
2609
|
+
}
|
|
2610
|
+
const { from, to } = range;
|
|
2611
|
+
if (from && posEquals(from, cell) || to && posEquals(to, cell)) {
|
|
2612
|
+
return true;
|
|
2613
|
+
}
|
|
2614
|
+
if (!from || !to) {
|
|
2615
|
+
return false;
|
|
2616
|
+
}
|
|
2617
|
+
const { column: c1, row: r1 } = from;
|
|
2618
|
+
const { column: c2, row: r2 } = to;
|
|
2619
|
+
const cMin = Math.min(c1, c2);
|
|
2620
|
+
const cMax = Math.max(c1, c2);
|
|
2621
|
+
const rMin = Math.min(r1, r2);
|
|
2622
|
+
const rMax = Math.max(r1, r2);
|
|
2623
|
+
const { column, row } = cell;
|
|
2624
|
+
return column >= cMin && column <= cMax && row >= rMin && row <= rMax;
|
|
2625
|
+
};
|
|
2626
|
+
|
|
2627
|
+
// packages/plugins/plugin-sheet/src/model/util.ts
|
|
2628
|
+
import { randomBytes } from "@dxos/crypto";
|
|
2629
|
+
var ApiError = class extends Error {
|
|
2630
|
+
};
|
|
2631
|
+
var ReadonlyException = class extends ApiError {
|
|
2632
|
+
};
|
|
2633
|
+
var RangeException = class extends ApiError {
|
|
2634
|
+
constructor(n) {
|
|
2706
2635
|
super();
|
|
2707
|
-
|
|
2636
|
+
}
|
|
2637
|
+
};
|
|
2638
|
+
var createIndex = (length = 8) => {
|
|
2639
|
+
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
2640
|
+
const charactersLength = characters.length;
|
|
2641
|
+
const randomBuffer = randomBytes(length);
|
|
2642
|
+
return Array.from(randomBuffer, (byte) => characters[byte % charactersLength]).join("");
|
|
2643
|
+
};
|
|
2644
|
+
var createIndices = (length) => Array.from({
|
|
2645
|
+
length
|
|
2646
|
+
}).map(() => createIndex());
|
|
2647
|
+
|
|
2648
|
+
// packages/plugins/plugin-sheet/src/model/model.ts
|
|
2649
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/model/model.ts";
|
|
2650
|
+
var DEFAULT_ROWS = 100;
|
|
2651
|
+
var DEFAULT_COLUMNS = 26;
|
|
2652
|
+
var typeMap = {
|
|
2653
|
+
BOOLEAN: ValueTypeEnum.Boolean,
|
|
2654
|
+
NUMBER_RAW: ValueTypeEnum.Number,
|
|
2655
|
+
NUMBER_PERCENT: ValueTypeEnum.Percent,
|
|
2656
|
+
NUMBER_CURRENCY: ValueTypeEnum.Currency,
|
|
2657
|
+
NUMBER_DATETIME: ValueTypeEnum.DateTime,
|
|
2658
|
+
NUMBER_DATE: ValueTypeEnum.Date,
|
|
2659
|
+
NUMBER_TIME: ValueTypeEnum.Time
|
|
2660
|
+
};
|
|
2661
|
+
var defaultOptions = {
|
|
2662
|
+
rows: 50,
|
|
2663
|
+
columns: 26,
|
|
2664
|
+
mapFormulaBindingFromId: () => (formula) => formula,
|
|
2665
|
+
mapFormulaBindingToId: () => (formula) => formula
|
|
2666
|
+
};
|
|
2667
|
+
var getTopLeft = (range) => {
|
|
2668
|
+
const to = range.to ?? range.from;
|
|
2669
|
+
return {
|
|
2670
|
+
row: Math.min(range.from.row, to.row),
|
|
2671
|
+
column: Math.min(range.from.column, to.column)
|
|
2672
|
+
};
|
|
2673
|
+
};
|
|
2674
|
+
var toSimpleCellAddress = (sheet, cell) => ({
|
|
2675
|
+
sheet,
|
|
2676
|
+
row: cell.row,
|
|
2677
|
+
col: cell.column
|
|
2678
|
+
});
|
|
2679
|
+
var toModelRange = (sheet, range) => ({
|
|
2680
|
+
start: toSimpleCellAddress(sheet, range.from),
|
|
2681
|
+
end: toSimpleCellAddress(sheet, range.to ?? range.from)
|
|
2682
|
+
});
|
|
2683
|
+
var SheetModel = class {
|
|
2684
|
+
constructor(_graph, _sheet, _space, options = {}) {
|
|
2685
|
+
this._graph = _graph;
|
|
2686
|
+
this._sheet = _sheet;
|
|
2708
2687
|
this._space = _space;
|
|
2709
|
-
this.
|
|
2710
|
-
this.
|
|
2711
|
-
this.
|
|
2712
|
-
this._remoteFunctions = [];
|
|
2688
|
+
this.id = `model-${PublicKey2.random().truncate()}`;
|
|
2689
|
+
this._ctx = void 0;
|
|
2690
|
+
this._functions = [];
|
|
2713
2691
|
this.update = new Event2();
|
|
2714
|
-
|
|
2715
|
-
this.
|
|
2716
|
-
|
|
2717
|
-
}
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
const node = this._nodes.get(sheet);
|
|
2723
|
-
if (node) {
|
|
2724
|
-
node.update.emit({
|
|
2725
|
-
type: "valuesUpdated",
|
|
2726
|
-
change
|
|
2727
|
-
});
|
|
2728
|
-
}
|
|
2729
|
-
}
|
|
2730
|
-
}
|
|
2692
|
+
const name = this._sheet.id;
|
|
2693
|
+
if (!this._graph.hf.doesSheetExist(name)) {
|
|
2694
|
+
this._graph.hf.addSheet(name);
|
|
2695
|
+
}
|
|
2696
|
+
this._sheetId = this._graph.hf.getSheetId(name);
|
|
2697
|
+
this._options = {
|
|
2698
|
+
...defaultOptions,
|
|
2699
|
+
...options
|
|
2731
2700
|
};
|
|
2732
|
-
this.
|
|
2733
|
-
|
|
2701
|
+
this.reset();
|
|
2702
|
+
}
|
|
2703
|
+
get graph() {
|
|
2704
|
+
return this._graph;
|
|
2705
|
+
}
|
|
2706
|
+
get sheet() {
|
|
2707
|
+
return this._sheet;
|
|
2708
|
+
}
|
|
2709
|
+
get readonly() {
|
|
2710
|
+
return this._options.readonly;
|
|
2734
2711
|
}
|
|
2735
|
-
get
|
|
2736
|
-
return
|
|
2712
|
+
get bounds() {
|
|
2713
|
+
return {
|
|
2714
|
+
rows: this._sheet.rows.length,
|
|
2715
|
+
columns: this._sheet.columns.length
|
|
2716
|
+
};
|
|
2737
2717
|
}
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2718
|
+
get functions() {
|
|
2719
|
+
const hfFunctions = this._graph.hf.getRegisteredFunctionNames().map((name) => defaultFunctions.find((fn) => fn.name === name) ?? {
|
|
2720
|
+
name
|
|
2721
|
+
});
|
|
2722
|
+
const echoFunctions = this._functions.map((fn) => ({
|
|
2723
|
+
name: fn.binding
|
|
2724
|
+
}));
|
|
2742
2725
|
return [
|
|
2743
|
-
...
|
|
2744
|
-
|
|
2745
|
-
}) : [],
|
|
2746
|
-
...echo ? this._remoteFunctions.map((fn) => ({
|
|
2747
|
-
name: fn.binding
|
|
2748
|
-
})) : []
|
|
2726
|
+
...hfFunctions,
|
|
2727
|
+
...echoFunctions
|
|
2749
2728
|
];
|
|
2750
2729
|
}
|
|
2730
|
+
get initialized() {
|
|
2731
|
+
return !!this._ctx;
|
|
2732
|
+
}
|
|
2751
2733
|
/**
|
|
2752
|
-
*
|
|
2734
|
+
* Initialize sheet and engine.
|
|
2753
2735
|
*/
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2736
|
+
async initialize() {
|
|
2737
|
+
log3("initialize", {
|
|
2738
|
+
id: this.id
|
|
2739
|
+
}, {
|
|
2740
|
+
F: __dxlog_file4,
|
|
2741
|
+
L: 142,
|
|
2742
|
+
S: this,
|
|
2743
|
+
C: (f, a) => f(...a)
|
|
2744
|
+
});
|
|
2745
|
+
invariant2(!this.initialized, "Already initialized.", {
|
|
2746
|
+
F: __dxlog_file4,
|
|
2747
|
+
L: 143,
|
|
2763
2748
|
S: this,
|
|
2764
2749
|
A: [
|
|
2765
|
-
"
|
|
2766
|
-
""
|
|
2750
|
+
"!this.initialized",
|
|
2751
|
+
"'Already initialized.'"
|
|
2767
2752
|
]
|
|
2768
2753
|
});
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2754
|
+
this._ctx = new Context(void 0, {
|
|
2755
|
+
F: __dxlog_file4,
|
|
2756
|
+
L: 144
|
|
2757
|
+
});
|
|
2758
|
+
if (!this._sheet.rows.length) {
|
|
2759
|
+
this._insertIndices(this._sheet.rows, 0, this._options.rows, DEFAULT_ROWS);
|
|
2760
|
+
}
|
|
2761
|
+
if (!this._sheet.columns.length) {
|
|
2762
|
+
this._insertIndices(this._sheet.columns, 0, this._options.columns, DEFAULT_COLUMNS);
|
|
2763
|
+
}
|
|
2764
|
+
this.reset();
|
|
2765
|
+
const unsubscribe = this._graph.update.on(() => this.update.emit());
|
|
2766
|
+
this._ctx.onDispose(unsubscribe);
|
|
2767
|
+
if (this._space) {
|
|
2768
|
+
const { Filter } = await import("@dxos/client/echo");
|
|
2769
|
+
const { FunctionType } = await import("@dxos/plugin-script/types");
|
|
2770
|
+
const query = this._space?.db.query(Filter.schema(FunctionType));
|
|
2771
|
+
const unsubscribe2 = query.subscribe(({ objects }) => {
|
|
2772
|
+
this._functions = objects.filter((fn) => fn.binding);
|
|
2773
|
+
this.update.emit();
|
|
2778
2774
|
});
|
|
2779
|
-
this.
|
|
2775
|
+
this._ctx.onDispose(unsubscribe2);
|
|
2780
2776
|
}
|
|
2781
|
-
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2777
|
+
return this;
|
|
2778
|
+
}
|
|
2779
|
+
async destroy() {
|
|
2780
|
+
log3("destroy", {
|
|
2781
|
+
id: this.id
|
|
2782
|
+
}, {
|
|
2783
|
+
F: __dxlog_file4,
|
|
2784
|
+
L: 174,
|
|
2785
2785
|
S: this,
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2786
|
+
C: (f, a) => f(...a)
|
|
2787
|
+
});
|
|
2788
|
+
if (this._ctx) {
|
|
2789
|
+
await this._ctx.dispose();
|
|
2790
|
+
this._ctx = void 0;
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2793
|
+
/**
|
|
2794
|
+
* Update engine.
|
|
2795
|
+
* NOTE: This resets the undo history.
|
|
2796
|
+
* @deprecated
|
|
2797
|
+
*/
|
|
2798
|
+
reset() {
|
|
2799
|
+
this._graph.hf.clearSheet(this._sheetId);
|
|
2800
|
+
Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
|
|
2801
|
+
const { column, row } = this.addressFromIndex(key);
|
|
2802
|
+
if (typeof value === "string" && value.charAt(0) === "=") {
|
|
2803
|
+
value = this.mapFormulaBindingToFormula(this.mapFormulaBindingFromId(this.mapFormulaIndicesToRefs(value)));
|
|
2804
|
+
}
|
|
2805
|
+
this._graph.hf.setCellContents({
|
|
2806
|
+
sheet: this._sheetId,
|
|
2807
|
+
row,
|
|
2808
|
+
col: column
|
|
2809
|
+
}, value);
|
|
2810
|
+
});
|
|
2811
|
+
}
|
|
2812
|
+
/**
|
|
2813
|
+
* Recalculate formulas.
|
|
2814
|
+
* NOTE: This resets the undo history.
|
|
2815
|
+
* https://hyperformula.handsontable.com/guide/volatile-functions.html#volatile-actions
|
|
2816
|
+
* @deprecated
|
|
2817
|
+
*/
|
|
2818
|
+
// TODO(burdon): Remove.
|
|
2819
|
+
recalculate() {
|
|
2820
|
+
this._graph.hf.rebuildAndRecalculate();
|
|
2821
|
+
}
|
|
2822
|
+
insertRows(i, n = 1) {
|
|
2823
|
+
this._insertIndices(this._sheet.rows, i, n, DEFAULT_ROWS);
|
|
2824
|
+
this.reset();
|
|
2825
|
+
}
|
|
2826
|
+
insertColumns(i, n = 1) {
|
|
2827
|
+
this._insertIndices(this._sheet.columns, i, n, DEFAULT_COLUMNS);
|
|
2828
|
+
this.reset();
|
|
2829
|
+
}
|
|
2830
|
+
//
|
|
2831
|
+
// Undoable actions.
|
|
2832
|
+
// TODO(burdon): Group undoable methods; consistently update hf/sheet.
|
|
2833
|
+
//
|
|
2834
|
+
/**
|
|
2835
|
+
* Clear range of values.
|
|
2836
|
+
*/
|
|
2837
|
+
clear(range) {
|
|
2838
|
+
const topLeft = getTopLeft(range);
|
|
2839
|
+
const values = this._iterRange(range, () => null);
|
|
2840
|
+
this._graph.hf.setCellContents(toSimpleCellAddress(this._sheetId, topLeft), values);
|
|
2841
|
+
this._iterRange(range, (cell) => {
|
|
2842
|
+
const idx = this.addressToIndex(cell);
|
|
2843
|
+
delete this._sheet.cells[idx];
|
|
2844
|
+
});
|
|
2845
|
+
}
|
|
2846
|
+
cut(range) {
|
|
2847
|
+
this._graph.hf.cut(toModelRange(this._sheetId, range));
|
|
2848
|
+
this._iterRange(range, (cell) => {
|
|
2849
|
+
const idx = this.addressToIndex(cell);
|
|
2850
|
+
delete this._sheet.cells[idx];
|
|
2851
|
+
});
|
|
2852
|
+
}
|
|
2853
|
+
copy(range) {
|
|
2854
|
+
this._graph.hf.copy(toModelRange(this._sheetId, range));
|
|
2855
|
+
}
|
|
2856
|
+
paste(cell) {
|
|
2857
|
+
if (!this._graph.hf.isClipboardEmpty()) {
|
|
2858
|
+
const changes = this._graph.hf.paste(toSimpleCellAddress(this._sheetId, cell));
|
|
2859
|
+
for (const change of changes) {
|
|
2860
|
+
if (change instanceof ExportedCellChange) {
|
|
2861
|
+
const { address, newValue } = change;
|
|
2862
|
+
const idx = this.addressToIndex({
|
|
2863
|
+
row: address.row,
|
|
2864
|
+
column: address.col
|
|
2865
|
+
});
|
|
2866
|
+
this._sheet.cells[idx] = {
|
|
2867
|
+
value: newValue
|
|
2868
|
+
};
|
|
2869
|
+
}
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
}
|
|
2873
|
+
// TODO(burdon): Display undo/redo state.
|
|
2874
|
+
undo() {
|
|
2875
|
+
if (this._graph.hf.isThereSomethingToUndo()) {
|
|
2876
|
+
this._graph.hf.undo();
|
|
2877
|
+
this.update.emit();
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
redo() {
|
|
2881
|
+
if (this._graph.hf.isThereSomethingToRedo()) {
|
|
2882
|
+
this._graph.hf.redo();
|
|
2883
|
+
this.update.emit();
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
/**
|
|
2887
|
+
* Get value from sheet.
|
|
2888
|
+
*/
|
|
2889
|
+
getCellValue(cell) {
|
|
2890
|
+
const idx = this.addressToIndex(cell);
|
|
2891
|
+
return this._sheet.cells[idx]?.value ?? null;
|
|
2892
|
+
}
|
|
2893
|
+
/**
|
|
2894
|
+
* Get value as a string for editing.
|
|
2895
|
+
*/
|
|
2896
|
+
getCellText(cell) {
|
|
2897
|
+
const value = this.getCellValue(cell);
|
|
2898
|
+
if (value == null) {
|
|
2899
|
+
return void 0;
|
|
2900
|
+
}
|
|
2901
|
+
if (typeof value === "string" && value.charAt(0) === "=") {
|
|
2902
|
+
return this.mapFormulaBindingFromId(this.mapFormulaIndicesToRefs(value));
|
|
2903
|
+
} else {
|
|
2904
|
+
return String(value);
|
|
2905
|
+
}
|
|
2906
|
+
}
|
|
2907
|
+
/**
|
|
2908
|
+
* Get array of raw values from sheet.
|
|
2909
|
+
*/
|
|
2910
|
+
getCellValues(range) {
|
|
2911
|
+
return this._iterRange(range, (cell) => this.getCellValue(cell));
|
|
2912
|
+
}
|
|
2913
|
+
/**
|
|
2914
|
+
* Gets the regular or computed value from the engine.
|
|
2915
|
+
*/
|
|
2916
|
+
getValue(cell) {
|
|
2917
|
+
const value = this._graph.hf.getCellValue(toSimpleCellAddress(this._sheetId, cell));
|
|
2918
|
+
if (value instanceof DetailedCellError) {
|
|
2919
|
+
return value.toString();
|
|
2920
|
+
}
|
|
2921
|
+
return value;
|
|
2922
|
+
}
|
|
2923
|
+
/**
|
|
2924
|
+
* Get value type.
|
|
2925
|
+
*/
|
|
2926
|
+
getValueType(cell) {
|
|
2927
|
+
const addr = toSimpleCellAddress(this._sheetId, cell);
|
|
2928
|
+
const type = this._graph.hf.getCellValueDetailedType(addr);
|
|
2929
|
+
return typeMap[type];
|
|
2930
|
+
}
|
|
2931
|
+
/**
|
|
2932
|
+
* Sets the value, updating the sheet and engine.
|
|
2933
|
+
*/
|
|
2934
|
+
setValue(cell, value) {
|
|
2935
|
+
if (this._options.readonly) {
|
|
2936
|
+
throw new ReadonlyException();
|
|
2937
|
+
}
|
|
2938
|
+
let refresh = false;
|
|
2939
|
+
if (cell.row >= this._sheet.rows.length) {
|
|
2940
|
+
this._insertIndices(this._sheet.rows, cell.row, 1, DEFAULT_ROWS);
|
|
2941
|
+
refresh = true;
|
|
2942
|
+
}
|
|
2943
|
+
if (cell.column >= this._sheet.columns.length) {
|
|
2944
|
+
this._insertIndices(this._sheet.columns, cell.column, 1, DEFAULT_COLUMNS);
|
|
2945
|
+
refresh = true;
|
|
2946
|
+
}
|
|
2947
|
+
if (refresh) {
|
|
2948
|
+
this.reset();
|
|
2949
|
+
}
|
|
2950
|
+
this._graph.hf.setCellContents({
|
|
2951
|
+
sheet: this._sheetId,
|
|
2952
|
+
row: cell.row,
|
|
2953
|
+
col: cell.column
|
|
2954
|
+
}, [
|
|
2955
|
+
[
|
|
2956
|
+
typeof value === "string" && value.charAt(0) === "=" ? this.mapFormulaBindingToFormula(value) : value
|
|
2789
2957
|
]
|
|
2958
|
+
]);
|
|
2959
|
+
const idx = this.addressToIndex(cell);
|
|
2960
|
+
if (value === void 0 || value === null) {
|
|
2961
|
+
delete this._sheet.cells[idx];
|
|
2962
|
+
} else {
|
|
2963
|
+
if (typeof value === "string" && value.charAt(0) === "=") {
|
|
2964
|
+
value = this.mapFormulaBindingToId(this.mapFormulaRefsToIndices(value));
|
|
2965
|
+
}
|
|
2966
|
+
this._sheet.cells[idx] = {
|
|
2967
|
+
value
|
|
2968
|
+
};
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2971
|
+
/**
|
|
2972
|
+
* Sets values from a simple map.
|
|
2973
|
+
*/
|
|
2974
|
+
setValues(values) {
|
|
2975
|
+
Object.entries(values).forEach(([key, { value }]) => {
|
|
2976
|
+
this.setValue(addressFromA1Notation(key), value);
|
|
2790
2977
|
});
|
|
2791
|
-
const node = new ComputeNode(this, sheetId);
|
|
2792
|
-
this._nodes.set(sheetId, node);
|
|
2793
|
-
return node;
|
|
2794
2978
|
}
|
|
2795
2979
|
/**
|
|
2796
|
-
*
|
|
2797
|
-
* E.g., "HELLO(...args)" => "EDGE("HELLO", ...args)".
|
|
2980
|
+
* Iterate range.
|
|
2798
2981
|
*/
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2982
|
+
_iterRange(range, cb) {
|
|
2983
|
+
const to = range.to ?? range.from;
|
|
2984
|
+
const rowRange = [
|
|
2985
|
+
Math.min(range.from.row, to.row),
|
|
2986
|
+
Math.max(range.from.row, to.row)
|
|
2987
|
+
];
|
|
2988
|
+
const columnRange = [
|
|
2989
|
+
Math.min(range.from.column, to.column),
|
|
2990
|
+
Math.max(range.from.column, to.column)
|
|
2991
|
+
];
|
|
2992
|
+
const rows = [];
|
|
2993
|
+
for (let row = rowRange[0]; row <= rowRange[1]; row++) {
|
|
2994
|
+
const rowCells = [];
|
|
2995
|
+
for (let column = columnRange[0]; column <= columnRange[1]; column++) {
|
|
2996
|
+
const value = cb({
|
|
2997
|
+
row,
|
|
2998
|
+
column
|
|
2999
|
+
});
|
|
3000
|
+
if (value !== void 0) {
|
|
3001
|
+
rowCells.push(value);
|
|
2814
3002
|
}
|
|
2815
3003
|
}
|
|
2816
|
-
|
|
2817
|
-
}
|
|
2818
|
-
|
|
3004
|
+
rows.push(rowCells);
|
|
3005
|
+
}
|
|
3006
|
+
return rows;
|
|
3007
|
+
}
|
|
3008
|
+
/**
|
|
3009
|
+
*
|
|
3010
|
+
*/
|
|
3011
|
+
// TODO(burdon): Insert indices into sheet.
|
|
3012
|
+
_insertIndices(indices, i, n, max) {
|
|
3013
|
+
if (i + n > max) {
|
|
3014
|
+
throw new RangeException(i + n);
|
|
3015
|
+
}
|
|
3016
|
+
const idx = createIndices(n);
|
|
3017
|
+
indices.splice(i, 0, ...idx);
|
|
3018
|
+
}
|
|
3019
|
+
// TODO(burdon): Delete index.
|
|
3020
|
+
_deleteIndices(indices, i, n) {
|
|
3021
|
+
throw new Error("Not implemented");
|
|
3022
|
+
}
|
|
3023
|
+
// TODO(burdon): Move. Cannot use fractional without changing. Switch back to using unique IDs?
|
|
3024
|
+
_moveIndices(indices, i, j, n) {
|
|
3025
|
+
throw new Error("Not implemented");
|
|
3026
|
+
}
|
|
3027
|
+
//
|
|
3028
|
+
// Indices.
|
|
3029
|
+
//
|
|
3030
|
+
/**
|
|
3031
|
+
* E.g., "A1" => "x1@y1".
|
|
3032
|
+
*/
|
|
3033
|
+
addressToIndex(cell) {
|
|
3034
|
+
return `${this._sheet.columns[cell.column]}@${this._sheet.rows[cell.row]}`;
|
|
3035
|
+
}
|
|
3036
|
+
/**
|
|
3037
|
+
* E.g., "x1@y1" => "A1".
|
|
3038
|
+
*/
|
|
3039
|
+
addressFromIndex(idx) {
|
|
3040
|
+
const [column, row] = idx.split("@");
|
|
3041
|
+
return {
|
|
3042
|
+
column: this._sheet.columns.indexOf(column),
|
|
3043
|
+
row: this._sheet.rows.indexOf(row)
|
|
3044
|
+
};
|
|
3045
|
+
}
|
|
3046
|
+
/**
|
|
3047
|
+
* E.g., "A1:B2" => "x1@y1:x2@y2".
|
|
3048
|
+
*/
|
|
3049
|
+
rangeToIndex(range) {
|
|
3050
|
+
return [
|
|
3051
|
+
range.from,
|
|
3052
|
+
range.to ?? range.from
|
|
3053
|
+
].map((cell) => this.addressToIndex(cell)).join(":");
|
|
3054
|
+
}
|
|
3055
|
+
/**
|
|
3056
|
+
* E.g., "x1@y1:x2@y2" => "A1:B2".
|
|
3057
|
+
*/
|
|
3058
|
+
rangeFromIndex(idx) {
|
|
3059
|
+
const [from, to] = idx.split(":").map((idx2) => this.addressFromIndex(idx2));
|
|
3060
|
+
return {
|
|
3061
|
+
from,
|
|
3062
|
+
to
|
|
3063
|
+
};
|
|
3064
|
+
}
|
|
3065
|
+
/**
|
|
3066
|
+
* E.g., "HELLO()" => "EDGE("HELLO")".
|
|
3067
|
+
*/
|
|
3068
|
+
mapFormulaBindingToFormula(formula) {
|
|
3069
|
+
return formula.replace(/([a-zA-Z0-9]+)\((.*)\)/g, (match, binding, args) => {
|
|
3070
|
+
const fn = this._functions.find((fn2) => fn2.binding === binding);
|
|
2819
3071
|
if (!fn) {
|
|
2820
3072
|
return match;
|
|
2821
3073
|
}
|
|
2822
3074
|
if (args.trim() === "") {
|
|
2823
|
-
return
|
|
2824
|
-
} else {
|
|
2825
|
-
return `${EDGE_FUNCTION_NAME}("${binding}", ${args})`;
|
|
3075
|
+
return `EDGE("${binding}")`;
|
|
2826
3076
|
}
|
|
3077
|
+
return `EDGE("${binding}", ${args})`;
|
|
2827
3078
|
});
|
|
2828
3079
|
}
|
|
2829
3080
|
/**
|
|
2830
|
-
*
|
|
2831
|
-
* E.g., HELLO() => spaceId:objectId()
|
|
3081
|
+
* E.g., "EDGE("HELLO")" => "HELLO()".
|
|
2832
3082
|
*/
|
|
2833
|
-
|
|
2834
|
-
return formula.replace(/(
|
|
2835
|
-
if (
|
|
2836
|
-
return
|
|
2837
|
-
}
|
|
2838
|
-
const fn = this._remoteFunctions.find((fn2) => fn2.binding === binding);
|
|
2839
|
-
if (fn) {
|
|
2840
|
-
const id = fullyQualifiedId(fn);
|
|
2841
|
-
return `${id}(${args})`;
|
|
2842
|
-
} else {
|
|
2843
|
-
return match;
|
|
3083
|
+
mapFormulaBindingFromFormula(formula) {
|
|
3084
|
+
return formula.replace(/EDGE\("([a-zA-Z0-9]+)"(.*)\)/, (_match, binding, args) => {
|
|
3085
|
+
if (args.trim() === "") {
|
|
3086
|
+
return `${binding}()`;
|
|
2844
3087
|
}
|
|
3088
|
+
return `${binding}(${args.slice(2)})`;
|
|
2845
3089
|
});
|
|
2846
3090
|
}
|
|
2847
3091
|
/**
|
|
2848
|
-
* Map from fully qualified ECHO ID
|
|
2849
|
-
* E.g., spaceId:objectId() => HELLO()
|
|
3092
|
+
* Map from binding to fully qualified ECHO ID.
|
|
2850
3093
|
*/
|
|
2851
|
-
|
|
2852
|
-
return
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
3094
|
+
mapFormulaBindingToId(formula) {
|
|
3095
|
+
return this._options.mapFormulaBindingToId(this._functions)(formula);
|
|
3096
|
+
}
|
|
3097
|
+
/**
|
|
3098
|
+
* Map from fully qualified ECHO ID to binding.
|
|
3099
|
+
*/
|
|
3100
|
+
mapFormulaBindingFromId(formula) {
|
|
3101
|
+
return this._options.mapFormulaBindingFromId(this._functions)(formula);
|
|
3102
|
+
}
|
|
3103
|
+
/**
|
|
3104
|
+
* Map from A1 notation to indices.
|
|
3105
|
+
*/
|
|
3106
|
+
mapFormulaRefsToIndices(formula) {
|
|
3107
|
+
invariant2(formula.charAt(0) === "=", void 0, {
|
|
3108
|
+
F: __dxlog_file4,
|
|
3109
|
+
L: 509,
|
|
3110
|
+
S: this,
|
|
3111
|
+
A: [
|
|
3112
|
+
"formula.charAt(0) === '='",
|
|
3113
|
+
""
|
|
3114
|
+
]
|
|
3115
|
+
});
|
|
3116
|
+
return formula.replace(/([a-zA-Z]+)([0-9]+)/g, (match) => {
|
|
3117
|
+
return this.addressToIndex(addressFromA1Notation(match));
|
|
2863
3118
|
});
|
|
2864
3119
|
}
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
3120
|
+
/**
|
|
3121
|
+
* Map from indices to A1 notation.
|
|
3122
|
+
*/
|
|
3123
|
+
mapFormulaIndicesToRefs(formula) {
|
|
3124
|
+
invariant2(formula.charAt(0) === "=", void 0, {
|
|
3125
|
+
F: __dxlog_file4,
|
|
3126
|
+
L: 519,
|
|
3127
|
+
S: this,
|
|
3128
|
+
A: [
|
|
3129
|
+
"formula.charAt(0) === '='",
|
|
3130
|
+
""
|
|
3131
|
+
]
|
|
3132
|
+
});
|
|
3133
|
+
return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
|
|
3134
|
+
return addressToA1Notation(this.addressFromIndex(idx));
|
|
3135
|
+
});
|
|
2876
3136
|
}
|
|
2877
|
-
|
|
2878
|
-
|
|
2879
|
-
|
|
2880
|
-
|
|
3137
|
+
//
|
|
3138
|
+
// Values
|
|
3139
|
+
//
|
|
3140
|
+
/**
|
|
3141
|
+
* https://hyperformula.handsontable.com/guide/date-and-time-handling.html#example
|
|
3142
|
+
* https://hyperformula.handsontable.com/api/interfaces/configparams.html#nulldate
|
|
3143
|
+
* NOTE: TODAY() is number of FULL days since nullDate. It will typically be -1 days from NOW().
|
|
3144
|
+
*/
|
|
3145
|
+
toLocalDate(num) {
|
|
3146
|
+
const { year, month, day, hours, minutes, seconds } = this.toDateTime(num);
|
|
3147
|
+
return new Date(year, month - 1, day, hours, minutes, seconds);
|
|
3148
|
+
}
|
|
3149
|
+
toDateTime(num) {
|
|
3150
|
+
return this._graph.hf.numberToDateTime(num);
|
|
3151
|
+
}
|
|
3152
|
+
toDate(num) {
|
|
3153
|
+
return this._graph.hf.numberToDate(num);
|
|
3154
|
+
}
|
|
3155
|
+
toTime(num) {
|
|
3156
|
+
return this._graph.hf.numberToTime(num);
|
|
2881
3157
|
}
|
|
2882
3158
|
};
|
|
2883
3159
|
|
|
2884
|
-
// packages/plugins/plugin-sheet/src/
|
|
2885
|
-
import
|
|
2886
|
-
import {
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
import { HyperFormula } from "#hyperformula";
|
|
2890
|
-
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/graph/compute-graph-registry.ts";
|
|
2891
|
-
var defaultOptions = {
|
|
2892
|
-
licenseKey: "gpl-v3"
|
|
3160
|
+
// packages/plugins/plugin-sheet/src/components/ComputeGraph/custom.ts
|
|
3161
|
+
import { FunctionArgumentType } from "hyperformula";
|
|
3162
|
+
import { getDeep } from "@dxos/util";
|
|
3163
|
+
var parseNumberString = (str) => {
|
|
3164
|
+
return parseFloat(str.replace(/[^\d.]/g, ""));
|
|
2893
3165
|
};
|
|
2894
|
-
var
|
|
2895
|
-
{
|
|
2896
|
-
|
|
2897
|
-
|
|
3166
|
+
var CustomPlugin = class extends FunctionPluginAsync {
|
|
3167
|
+
test(ast, state) {
|
|
3168
|
+
const handler = async () => {
|
|
3169
|
+
return Math.random();
|
|
3170
|
+
};
|
|
3171
|
+
return this.runAsyncFunction(ast, state, handler);
|
|
2898
3172
|
}
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
3173
|
+
crypto(ast, state) {
|
|
3174
|
+
const handler = async (_currency) => {
|
|
3175
|
+
const currency = (_currency || "USD").toUpperCase();
|
|
3176
|
+
const result = await fetch(`https://api.coindesk.com/v1/bpi/currentprice/${currency}.json`);
|
|
3177
|
+
const data = await result.json();
|
|
3178
|
+
const rate = getDeep(data, [
|
|
3179
|
+
"bpi",
|
|
3180
|
+
currency,
|
|
3181
|
+
"rate"
|
|
3182
|
+
]);
|
|
3183
|
+
if (!rate) {
|
|
3184
|
+
return NaN;
|
|
3185
|
+
}
|
|
3186
|
+
return parseNumberString(rate);
|
|
3187
|
+
};
|
|
3188
|
+
return this.runAsyncFunction(ast, state, handler, {
|
|
3189
|
+
ttl: 1e4
|
|
2909
3190
|
});
|
|
2910
3191
|
}
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
}
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
return graph;
|
|
3192
|
+
};
|
|
3193
|
+
CustomPlugin.implementedFunctions = {
|
|
3194
|
+
TEST: {
|
|
3195
|
+
method: "test",
|
|
3196
|
+
parameters: [],
|
|
3197
|
+
isVolatile: true
|
|
3198
|
+
},
|
|
3199
|
+
CRYPTO: {
|
|
3200
|
+
method: "crypto",
|
|
3201
|
+
parameters: [
|
|
3202
|
+
{
|
|
3203
|
+
argumentType: FunctionArgumentType.STRING,
|
|
3204
|
+
optionalArg: true
|
|
3205
|
+
}
|
|
3206
|
+
],
|
|
3207
|
+
isVolatile: true
|
|
2928
3208
|
}
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
});
|
|
2939
|
-
const hf = HyperFormula.buildEmpty(this._options);
|
|
2940
|
-
const graph = new ComputeGraph(hf, space, this._options);
|
|
2941
|
-
this._graphs.set(space.id, graph);
|
|
2942
|
-
return graph;
|
|
2943
|
-
}
|
|
2944
|
-
async _close() {
|
|
2945
|
-
for (const graph of this._graphs.values()) {
|
|
2946
|
-
await graph.close();
|
|
2947
|
-
}
|
|
2948
|
-
this._graphs.clear();
|
|
3209
|
+
};
|
|
3210
|
+
var CustomPluginTranslations = {
|
|
3211
|
+
enGB: {
|
|
3212
|
+
TEST: "TEST",
|
|
3213
|
+
CRYPTO: "CRYPTO"
|
|
3214
|
+
},
|
|
3215
|
+
enUS: {
|
|
3216
|
+
TEST: "TEST",
|
|
3217
|
+
CRYPTO: "CRYPTO"
|
|
2949
3218
|
}
|
|
2950
3219
|
};
|
|
2951
3220
|
|
|
2952
3221
|
export {
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
EDGE_FUNCTION_NAME,
|
|
2958
|
-
EdgeFunctionPlugin,
|
|
2959
|
-
EdgeFunctionPluginTranslations,
|
|
3222
|
+
FunctionPluginAsync,
|
|
3223
|
+
CustomPlugin,
|
|
3224
|
+
CustomPluginTranslations,
|
|
3225
|
+
createComputeGraph,
|
|
2960
3226
|
defaultFunctions,
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
3227
|
+
posEquals,
|
|
3228
|
+
columnLetter,
|
|
3229
|
+
addressToA1Notation,
|
|
3230
|
+
addressFromA1Notation,
|
|
3231
|
+
rangeToA1Notation,
|
|
3232
|
+
inRange,
|
|
3233
|
+
SheetModel
|
|
2967
3234
|
};
|
|
2968
|
-
//# sourceMappingURL=chunk-
|
|
3235
|
+
//# sourceMappingURL=chunk-D5AGLXJP.mjs.map
|