@dxos/plugin-sheet 0.6.13 → 0.6.14-main.1366248
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/SheetContainer-JZEKRM4Z.mjs +297 -0
- package/dist/lib/browser/SheetContainer-JZEKRM4Z.mjs.map +7 -0
- package/dist/lib/browser/chunk-BVUN7SHF.mjs +67 -0
- package/dist/lib/browser/chunk-BVUN7SHF.mjs.map +7 -0
- package/dist/lib/browser/chunk-G2FUL6PK.mjs +1671 -0
- package/dist/lib/browser/chunk-G2FUL6PK.mjs.map +7 -0
- package/dist/lib/browser/chunk-RABELMEQ.mjs +15 -0
- package/dist/lib/browser/chunk-RABELMEQ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-D5AGLXJP.mjs → chunk-VMSX6Z4X.mjs} +659 -675
- package/dist/lib/browser/chunk-VMSX6Z4X.mjs.map +7 -0
- package/dist/lib/browser/compute-graph-GGWUX644.mjs +35 -0
- package/dist/lib/browser/compute-graph-GGWUX644.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +168 -67
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +1 -1
- package/dist/lib/browser/types.mjs +6 -12
- package/dist/lib/node/SheetContainer-PJE74VO4.cjs +300 -0
- package/dist/lib/node/SheetContainer-PJE74VO4.cjs.map +7 -0
- package/dist/lib/node/chunk-2ZVZI2KJ.cjs +38 -0
- package/dist/lib/node/chunk-2ZVZI2KJ.cjs.map +7 -0
- package/dist/lib/node/{chunk-DSYKOI4E.cjs → chunk-AWKOWDMI.cjs} +34 -52
- package/dist/lib/node/chunk-AWKOWDMI.cjs.map +7 -0
- package/dist/lib/node/{chunk-5KKJ4NPP.cjs → chunk-O7XR4R7Y.cjs} +678 -674
- package/dist/lib/node/chunk-O7XR4R7Y.cjs.map +7 -0
- package/dist/lib/node/chunk-STZ7S7RF.cjs +1656 -0
- package/dist/lib/node/chunk-STZ7S7RF.cjs.map +7 -0
- package/dist/lib/node/compute-graph-KGWA2QLE.cjs +57 -0
- package/dist/lib/node/compute-graph-KGWA2QLE.cjs.map +7 -0
- package/dist/lib/node/index.cjs +178 -75
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.cjs +3 -3
- package/dist/lib/node/meta.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types.cjs +9 -15
- package/dist/lib/node/types.cjs.map +2 -2
- package/dist/lib/node-esm/SheetContainer-R73XEXHU.mjs +298 -0
- package/dist/lib/node-esm/SheetContainer-R73XEXHU.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-BM2Q3FFC.mjs +17 -0
- package/dist/lib/node-esm/chunk-BM2Q3FFC.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-CR4K75EL.mjs +3220 -0
- package/dist/lib/node-esm/chunk-CR4K75EL.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-UIBWRHW7.mjs +68 -0
- package/dist/lib/node-esm/chunk-UIBWRHW7.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-V5N3Y2O5.mjs +1672 -0
- package/dist/lib/node-esm/chunk-V5N3Y2O5.mjs.map +7 -0
- package/dist/lib/node-esm/compute-graph-2SCZT7N5.mjs +36 -0
- package/dist/lib/node-esm/compute-graph-2SCZT7N5.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +350 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/meta.mjs +10 -0
- package/dist/lib/node-esm/meta.mjs.map +7 -0
- package/dist/lib/node-esm/types.mjs +17 -0
- package/dist/lib/node-esm/types.mjs.map +7 -0
- package/dist/types/src/SheetPlugin.d.ts.map +1 -1
- package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +13 -0
- package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/index.d.ts +1 -3
- package/dist/types/src/components/ComputeGraph/index.d.ts.map +1 -1
- package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts +3 -0
- package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +1 -0
- package/dist/types/src/components/FunctionEditor/index.d.ts +2 -0
- package/dist/types/src/components/FunctionEditor/index.d.ts.map +1 -0
- package/dist/types/src/components/GridSheet/GridSheet.d.ts +3 -0
- package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -0
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +6 -0
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -0
- package/dist/types/src/components/{CellEditor/CellEditor.stories.d.ts → GridSheet/SheetCellEditor.stories.d.ts} +5 -9
- package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +1 -0
- package/dist/types/src/components/GridSheet/index.d.ts +2 -0
- package/dist/types/src/components/GridSheet/index.d.ts.map +1 -0
- package/dist/types/src/components/GridSheet/util.d.ts +15 -0
- package/dist/types/src/components/GridSheet/util.d.ts.map +1 -0
- package/dist/types/src/components/RangeList/RangeList.d.ts +7 -0
- package/dist/types/src/components/RangeList/RangeList.d.ts.map +1 -0
- package/dist/types/src/components/RangeList/index.d.ts +2 -0
- package/dist/types/src/components/RangeList/index.d.ts.map +1 -0
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +9 -0
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -0
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +6 -0
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -0
- package/dist/types/src/components/SheetContainer/index.d.ts +3 -0
- package/dist/types/src/components/SheetContainer/index.d.ts.map +1 -0
- package/dist/types/src/components/SheetContext/SheetContext.d.ts +28 -0
- package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -0
- package/dist/types/src/components/SheetContext/index.d.ts +2 -0
- package/dist/types/src/components/SheetContext/index.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +36 -9
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +4 -32
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +7 -4
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/compute-graph/compute-graph-registry.d.ts +34 -0
- package/dist/types/src/compute-graph/compute-graph-registry.d.ts.map +1 -0
- package/dist/types/src/compute-graph/compute-graph.d.ts +64 -0
- package/dist/types/src/compute-graph/compute-graph.d.ts.map +1 -0
- package/dist/types/src/compute-graph/compute-graph.stories.d.ts +6 -0
- package/dist/types/src/compute-graph/compute-graph.stories.d.ts.map +1 -0
- package/dist/types/src/compute-graph/compute-graph.test.d.ts +2 -0
- package/dist/types/src/compute-graph/compute-graph.test.d.ts.map +1 -0
- package/dist/types/src/compute-graph/compute-node.d.ts +26 -0
- package/dist/types/src/compute-graph/compute-node.d.ts.map +1 -0
- package/dist/types/src/{components/ComputeGraph → compute-graph/functions}/async-function.d.ts +14 -5
- package/dist/types/src/compute-graph/functions/async-function.d.ts.map +1 -0
- package/dist/types/src/compute-graph/functions/edge-function.d.ts +21 -0
- package/dist/types/src/compute-graph/functions/edge-function.d.ts.map +1 -0
- package/dist/types/src/{model/functions.d.ts → compute-graph/functions/function-defs.d.ts} +1 -1
- package/dist/types/src/compute-graph/functions/function-defs.d.ts.map +1 -0
- package/dist/types/src/compute-graph/functions/index.d.ts +4 -0
- package/dist/types/src/compute-graph/functions/index.d.ts.map +1 -0
- package/dist/types/src/compute-graph/hyperformula.test.d.ts +2 -0
- package/dist/types/src/compute-graph/hyperformula.test.d.ts.map +1 -0
- package/dist/types/src/compute-graph/index.d.ts +5 -0
- package/dist/types/src/compute-graph/index.d.ts.map +1 -0
- package/dist/types/src/compute-graph/testing/index.d.ts +3 -0
- package/dist/types/src/compute-graph/testing/index.d.ts.map +1 -0
- package/dist/types/src/compute-graph/testing/test-builder.d.ts +15 -0
- package/dist/types/src/compute-graph/testing/test-builder.d.ts.map +1 -0
- package/dist/types/src/compute-graph/testing/test-plugin.d.ts +36 -0
- package/dist/types/src/compute-graph/testing/test-plugin.d.ts.map +1 -0
- package/dist/types/src/compute-graph/util.d.ts +2 -0
- package/dist/types/src/compute-graph/util.d.ts.map +1 -0
- package/dist/types/src/defs/index.d.ts +4 -0
- package/dist/types/src/defs/index.d.ts.map +1 -0
- package/dist/types/src/defs/sheet-range-types.d.ts +13 -0
- package/dist/types/src/defs/sheet-range-types.d.ts.map +1 -0
- package/dist/types/src/defs/types.d.ts +28 -0
- package/dist/types/src/defs/types.d.ts.map +1 -0
- package/dist/types/src/defs/types.test.d.ts.map +1 -0
- package/dist/types/src/defs/util.d.ts +39 -0
- package/dist/types/src/defs/util.d.ts.map +1 -0
- package/dist/types/src/extensions/compute.d.ts +6 -0
- package/dist/types/src/extensions/compute.d.ts.map +1 -0
- package/dist/types/src/extensions/compute.stories.d.ts +21 -0
- package/dist/types/src/extensions/compute.stories.d.ts.map +1 -0
- package/dist/types/src/extensions/editor/extension.d.ts +39 -0
- package/dist/types/src/extensions/editor/extension.d.ts.map +1 -0
- package/dist/types/src/extensions/editor/extension.test.d.ts.map +1 -0
- package/dist/types/src/extensions/editor/index.d.ts +2 -0
- package/dist/types/src/extensions/editor/index.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +3 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/integrations/index.d.ts +2 -0
- package/dist/types/src/integrations/index.d.ts.map +1 -0
- package/dist/types/src/integrations/thread-ranges.d.ts +7 -0
- package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +4 -9
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/model/index.d.ts +2 -3
- package/dist/types/src/model/index.d.ts.map +1 -1
- package/dist/types/src/model/{model.d.ts → sheet-model.d.ts} +22 -69
- package/dist/types/src/model/sheet-model.d.ts.map +1 -0
- package/dist/types/src/model/sheet-model.test.d.ts +2 -0
- package/dist/types/src/model/sheet-model.test.d.ts.map +1 -0
- package/dist/types/src/model/useSheetModel.d.ts +8 -0
- package/dist/types/src/model/useSheetModel.d.ts.map +1 -0
- package/dist/types/src/sanity.test.d.ts +2 -0
- package/dist/types/src/sanity.test.d.ts.map +1 -0
- package/dist/types/src/serializer.d.ts +4 -0
- package/dist/types/src/serializer.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/testing.d.ts +8 -0
- package/dist/types/src/testing/testing.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +32 -12
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +132 -43
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/vendor/hyperformula.mjs +37145 -0
- package/package.json +60 -61
- package/src/SheetPlugin.tsx +89 -78
- package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +37 -0
- package/src/components/ComputeGraph/index.ts +1 -3
- package/src/components/FunctionEditor/FunctionEditor.tsx +45 -0
- package/src/components/FunctionEditor/index.ts +5 -0
- package/src/components/GridSheet/GridSheet.stories.tsx +46 -0
- package/src/components/GridSheet/GridSheet.tsx +358 -0
- package/src/components/{CellEditor/CellEditor.stories.tsx → GridSheet/SheetCellEditor.stories.tsx} +18 -15
- package/src/components/GridSheet/index.ts +5 -0
- package/src/components/GridSheet/util.ts +170 -0
- package/src/components/RangeList/RangeList.tsx +53 -0
- package/src/components/RangeList/index.ts +5 -0
- package/src/components/SheetContainer/SheetContainer.stories.tsx +45 -0
- package/src/components/SheetContainer/SheetContainer.tsx +33 -0
- package/src/components/SheetContainer/index.ts +7 -0
- package/src/components/SheetContext/SheetContext.tsx +127 -0
- package/src/components/SheetContext/index.ts +5 -0
- package/src/components/Toolbar/Toolbar.stories.tsx +9 -6
- package/src/components/Toolbar/Toolbar.tsx +265 -111
- package/src/components/index.ts +5 -3
- package/src/compute-graph/compute-graph-registry.ts +90 -0
- package/src/compute-graph/compute-graph.stories.tsx +97 -0
- package/src/compute-graph/compute-graph.test.ts +87 -0
- package/src/compute-graph/compute-graph.ts +260 -0
- package/src/compute-graph/compute-node.ts +62 -0
- package/src/{components/ComputeGraph → compute-graph/functions}/async-function.ts +26 -15
- package/src/{components/ComputeGraph → compute-graph/functions}/edge-function.ts +21 -17
- package/src/compute-graph/functions/index.ts +7 -0
- package/src/compute-graph/hyperformula.test.ts +14 -0
- package/src/compute-graph/index.ts +8 -0
- package/src/compute-graph/testing/index.ts +6 -0
- package/src/compute-graph/testing/test-builder.ts +54 -0
- package/src/{components/ComputeGraph/custom.ts → compute-graph/testing/test-plugin.ts} +44 -14
- package/src/compute-graph/util.ts +8 -0
- package/src/defs/index.ts +7 -0
- package/src/defs/sheet-range-types.ts +49 -0
- package/src/{model → defs}/types.test.ts +8 -9
- package/src/defs/types.ts +86 -0
- package/src/defs/util.ts +136 -0
- package/src/extensions/compute.stories.tsx +155 -0
- package/src/extensions/compute.ts +147 -0
- package/src/{components/CellEditor → extensions/editor}/extension.test.ts +4 -6
- package/src/{components/CellEditor → extensions/editor}/extension.ts +51 -27
- package/src/{components/CellEditor → extensions/editor}/index.ts +0 -1
- package/src/extensions/index.ts +6 -0
- package/src/index.ts +2 -2
- package/src/integrations/index.ts +5 -0
- package/src/integrations/thread-ranges.ts +101 -0
- package/src/meta.ts +15 -0
- package/src/model/index.ts +2 -3
- package/src/model/sheet-model.test.ts +59 -0
- package/src/model/sheet-model.ts +495 -0
- package/src/model/useSheetModel.ts +40 -0
- package/src/sanity.test.ts +40 -0
- package/src/serializer.ts +27 -0
- package/src/{components/Sheet → testing}/index.ts +1 -1
- package/src/testing/testing.tsx +68 -0
- package/src/translations.ts +24 -4
- package/src/types.ts +62 -47
- package/dist/lib/browser/SheetContainer-U4H5D34A.mjs +0 -1772
- package/dist/lib/browser/SheetContainer-U4H5D34A.mjs.map +0 -7
- package/dist/lib/browser/chunk-APHOLYUB.mjs +0 -175
- package/dist/lib/browser/chunk-APHOLYUB.mjs.map +0 -7
- package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +0 -7
- package/dist/lib/browser/chunk-FUAGSXA4.mjs +0 -82
- package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +0 -7
- package/dist/lib/browser/chunk-JRL5LGCE.mjs +0 -18
- package/dist/lib/browser/chunk-JRL5LGCE.mjs.map +0 -7
- package/dist/lib/browser/chunk-NU4PBN33.mjs +0 -8
- package/dist/lib/browser/chunk-NU4PBN33.mjs.map +0 -7
- package/dist/lib/browser/testing.mjs +0 -92
- package/dist/lib/browser/testing.mjs.map +0 -7
- package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs +0 -1765
- package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +0 -7
- package/dist/lib/node/chunk-5KKJ4NPP.cjs.map +0 -7
- package/dist/lib/node/chunk-BJ6ZD7MN.cjs +0 -51
- package/dist/lib/node/chunk-BJ6ZD7MN.cjs.map +0 -7
- package/dist/lib/node/chunk-CN3RPESU.cjs +0 -202
- package/dist/lib/node/chunk-CN3RPESU.cjs.map +0 -7
- package/dist/lib/node/chunk-DSYKOI4E.cjs.map +0 -7
- package/dist/lib/node/chunk-PYXHNAAK.cjs +0 -40
- package/dist/lib/node/chunk-PYXHNAAK.cjs.map +0 -7
- package/dist/lib/node/testing.cjs +0 -111
- package/dist/lib/node/testing.cjs.map +0 -7
- package/dist/types/src/components/CellEditor/CellEditor.d.ts +0 -14
- package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +0 -1
- package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +0 -1
- package/dist/types/src/components/CellEditor/extension.d.ts +0 -19
- package/dist/types/src/components/CellEditor/extension.d.ts.map +0 -1
- package/dist/types/src/components/CellEditor/extension.test.d.ts.map +0 -1
- package/dist/types/src/components/CellEditor/index.d.ts +0 -3
- package/dist/types/src/components/CellEditor/index.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/custom.d.ts +0 -21
- package/dist/types/src/components/ComputeGraph/custom.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/edge-function.d.ts +0 -20
- package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/graph-context.d.ts +0 -12
- package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts +0 -2
- package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/graph.d.ts +0 -26
- package/dist/types/src/components/ComputeGraph/graph.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/Sheet.d.ts +0 -55
- package/dist/types/src/components/Sheet/Sheet.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/Sheet.stories.d.ts +0 -54
- package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/formatting.d.ts +0 -14
- package/dist/types/src/components/Sheet/formatting.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/grid.d.ts +0 -52
- package/dist/types/src/components/Sheet/grid.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/index.d.ts +0 -2
- package/dist/types/src/components/Sheet/index.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/nav.d.ts +0 -29
- package/dist/types/src/components/Sheet/nav.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/sheet-context.d.ts +0 -25
- package/dist/types/src/components/Sheet/sheet-context.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/util.d.ts +0 -18
- package/dist/types/src/components/Sheet/util.d.ts.map +0 -1
- package/dist/types/src/components/SheetContainer.d.ts +0 -9
- package/dist/types/src/components/SheetContainer.d.ts.map +0 -1
- package/dist/types/src/components/Toolbar/common.d.ts +0 -20
- package/dist/types/src/components/Toolbar/common.d.ts.map +0 -1
- package/dist/types/src/model/functions.d.ts.map +0 -1
- package/dist/types/src/model/model.browser.test.d.ts +0 -2
- package/dist/types/src/model/model.browser.test.d.ts.map +0 -1
- package/dist/types/src/model/model.d.ts.map +0 -1
- package/dist/types/src/model/types.d.ts +0 -17
- package/dist/types/src/model/types.d.ts.map +0 -1
- package/dist/types/src/model/types.test.d.ts.map +0 -1
- package/dist/types/src/model/util.d.ts +0 -15
- package/dist/types/src/model/util.d.ts.map +0 -1
- package/dist/types/src/testing.d.ts +0 -9
- package/dist/types/src/testing.d.ts.map +0 -1
- package/src/components/CellEditor/CellEditor.tsx +0 -113
- package/src/components/ComputeGraph/graph-context.tsx +0 -50
- package/src/components/ComputeGraph/graph.browser.test.ts +0 -50
- package/src/components/ComputeGraph/graph.ts +0 -62
- package/src/components/Sheet/Sheet.stories.tsx +0 -287
- package/src/components/Sheet/Sheet.tsx +0 -1160
- package/src/components/Sheet/formatting.ts +0 -106
- package/src/components/Sheet/grid.ts +0 -191
- package/src/components/Sheet/nav.ts +0 -157
- package/src/components/Sheet/sheet-context.tsx +0 -150
- package/src/components/Sheet/util.ts +0 -56
- package/src/components/SheetContainer.tsx +0 -34
- package/src/components/Toolbar/common.tsx +0 -72
- package/src/meta.tsx +0 -18
- package/src/model/model.browser.test.ts +0 -100
- package/src/model/model.ts +0 -550
- package/src/model/types.ts +0 -71
- package/src/model/util.ts +0 -36
- package/src/testing.ts +0 -50
- /package/dist/types/src/{model → defs}/types.test.d.ts +0 -0
- /package/dist/types/src/{components/CellEditor → extensions/editor}/extension.test.d.ts +0 -0
- /package/src/{model/functions.ts → compute-graph/functions/function-defs.ts} +0 -0
|
@@ -0,0 +1,1671 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_COLUMNS,
|
|
3
|
+
DEFAULT_ROWS,
|
|
4
|
+
MAX_COLUMNS,
|
|
5
|
+
MAX_ROWS,
|
|
6
|
+
RANGE_NOTATION,
|
|
7
|
+
ReadonlyException,
|
|
8
|
+
addressFromA1Notation,
|
|
9
|
+
addressFromIndex,
|
|
10
|
+
addressToA1Notation,
|
|
11
|
+
addressToIndex,
|
|
12
|
+
cellClassNameForRange,
|
|
13
|
+
createSheetName,
|
|
14
|
+
inRange,
|
|
15
|
+
initialize,
|
|
16
|
+
insertIndices,
|
|
17
|
+
isFormula,
|
|
18
|
+
rangeFromIndex,
|
|
19
|
+
rangeToA1Notation
|
|
20
|
+
} from "./chunk-VMSX6Z4X.mjs";
|
|
21
|
+
import {
|
|
22
|
+
Range,
|
|
23
|
+
SheetAction
|
|
24
|
+
} from "./chunk-BVUN7SHF.mjs";
|
|
25
|
+
import {
|
|
26
|
+
SHEET_PLUGIN
|
|
27
|
+
} from "./chunk-RABELMEQ.mjs";
|
|
28
|
+
|
|
29
|
+
// packages/plugins/plugin-sheet/src/components/ComputeGraph/ComputeGraphContextProvider.tsx
|
|
30
|
+
import React, { createContext, useContext } from "react";
|
|
31
|
+
import { raise } from "@dxos/debug";
|
|
32
|
+
import { useAsyncState } from "@dxos/react-hooks";
|
|
33
|
+
var ComputeGraphContext = /* @__PURE__ */ createContext(void 0);
|
|
34
|
+
var ComputeGraphContextProvider = ({ registry, children }) => {
|
|
35
|
+
return /* @__PURE__ */ React.createElement(ComputeGraphContext.Provider, {
|
|
36
|
+
value: {
|
|
37
|
+
registry
|
|
38
|
+
}
|
|
39
|
+
}, children);
|
|
40
|
+
};
|
|
41
|
+
var useComputeGraph = (space) => {
|
|
42
|
+
const { registry } = useContext(ComputeGraphContext) ?? raise(new Error("Missing ComputeGraphContext"));
|
|
43
|
+
const [graph] = useAsyncState(async () => {
|
|
44
|
+
if (space) {
|
|
45
|
+
const graph2 = registry.getOrCreateGraph(space);
|
|
46
|
+
await graph2.open();
|
|
47
|
+
return graph2;
|
|
48
|
+
}
|
|
49
|
+
}, [
|
|
50
|
+
space,
|
|
51
|
+
registry
|
|
52
|
+
]);
|
|
53
|
+
return graph;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
// packages/plugins/plugin-sheet/src/extensions/compute.ts
|
|
57
|
+
import { syntaxTree } from "@codemirror/language";
|
|
58
|
+
import { RangeSetBuilder, StateEffect, StateField } from "@codemirror/state";
|
|
59
|
+
import { Decoration, EditorView, ViewPlugin, WidgetType } from "@codemirror/view";
|
|
60
|
+
import { debounce } from "@dxos/async";
|
|
61
|
+
import { invariant } from "@dxos/invariant";
|
|
62
|
+
import { documentId, singleValueFacet } from "@dxos/react-ui-editor";
|
|
63
|
+
var updateAllDecorations = StateEffect.define();
|
|
64
|
+
var computeGraphFacet = singleValueFacet();
|
|
65
|
+
|
|
66
|
+
// packages/plugins/plugin-sheet/src/extensions/editor/extension.ts
|
|
67
|
+
import { acceptCompletion, autocompletion, completionStatus, startCompletion } from "@codemirror/autocomplete";
|
|
68
|
+
import { HighlightStyle, syntaxHighlighting } from "@codemirror/language";
|
|
69
|
+
import { ViewPlugin as ViewPlugin2, keymap } from "@codemirror/view";
|
|
70
|
+
import { tags } from "@lezer/highlight";
|
|
71
|
+
import { spreadsheet } from "codemirror-lang-spreadsheet";
|
|
72
|
+
import { singleValueFacet as singleValueFacet2 } from "@dxos/react-ui-editor";
|
|
73
|
+
import { mx } from "@dxos/react-ui-theme";
|
|
74
|
+
var highlightStyles = HighlightStyle.define([
|
|
75
|
+
// Function.
|
|
76
|
+
{
|
|
77
|
+
tag: tags.name,
|
|
78
|
+
class: "text-accentText"
|
|
79
|
+
},
|
|
80
|
+
// Range.
|
|
81
|
+
{
|
|
82
|
+
tag: tags.tagName,
|
|
83
|
+
class: "text-pinkText"
|
|
84
|
+
},
|
|
85
|
+
// Values.
|
|
86
|
+
{
|
|
87
|
+
tag: tags.number,
|
|
88
|
+
class: "text-tealText"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
tag: tags.bool,
|
|
92
|
+
class: "text-tealText"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
tag: tags.string,
|
|
96
|
+
class: "text-tealText"
|
|
97
|
+
},
|
|
98
|
+
// Error.
|
|
99
|
+
{
|
|
100
|
+
tag: tags.invalid,
|
|
101
|
+
class: "text-unAccent"
|
|
102
|
+
}
|
|
103
|
+
]);
|
|
104
|
+
var languageFacet = singleValueFacet2();
|
|
105
|
+
var sheetExtension = ({ functions = [] }) => {
|
|
106
|
+
const { extension, language } = spreadsheet({
|
|
107
|
+
idiom: "en-US",
|
|
108
|
+
decimalSeparator: "."
|
|
109
|
+
});
|
|
110
|
+
const createCompletion = (name) => {
|
|
111
|
+
const { section = "Custom", description, syntax } = functions.find((value) => value.name === name) ?? {};
|
|
112
|
+
return {
|
|
113
|
+
section,
|
|
114
|
+
label: name,
|
|
115
|
+
info: () => {
|
|
116
|
+
if (!description && !syntax) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
const root = document.createElement("div");
|
|
120
|
+
root.className = "flex flex-col gap-2 text-sm";
|
|
121
|
+
const title = document.createElement("h2");
|
|
122
|
+
title.innerText = name;
|
|
123
|
+
title.className = "text-lg font-mono text-accentText";
|
|
124
|
+
root.appendChild(title);
|
|
125
|
+
if (description) {
|
|
126
|
+
const info = document.createElement("p");
|
|
127
|
+
info.innerText = description;
|
|
128
|
+
info.className = "text-subdued";
|
|
129
|
+
root.appendChild(info);
|
|
130
|
+
}
|
|
131
|
+
if (syntax) {
|
|
132
|
+
const detail = document.createElement("pre");
|
|
133
|
+
detail.innerText = syntax;
|
|
134
|
+
detail.className = "whitespace-pre-wrap text-greenText";
|
|
135
|
+
root.appendChild(detail);
|
|
136
|
+
}
|
|
137
|
+
return root;
|
|
138
|
+
},
|
|
139
|
+
apply: (view, completion, from, to) => {
|
|
140
|
+
const insertParens = to === view.state.doc.toString().length;
|
|
141
|
+
view.dispatch(view.state.update({
|
|
142
|
+
changes: {
|
|
143
|
+
from,
|
|
144
|
+
to,
|
|
145
|
+
insert: completion.label + (insertParens ? "()" : "")
|
|
146
|
+
},
|
|
147
|
+
selection: {
|
|
148
|
+
anchor: from + completion.label.length + 1
|
|
149
|
+
}
|
|
150
|
+
}));
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
return [
|
|
155
|
+
extension,
|
|
156
|
+
languageFacet.of(language),
|
|
157
|
+
language.data.of({
|
|
158
|
+
autocomplete: (context) => {
|
|
159
|
+
if (context.state.doc.toString()[0] !== "=") {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
const match = context.matchBefore(/\w*/);
|
|
163
|
+
if (!match || match.from === match.to) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
const text = match.text.toUpperCase();
|
|
167
|
+
if (!context.explicit && match.text.length < 2) {
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
from: match.from,
|
|
172
|
+
options: functions?.filter(({ name }) => name.startsWith(text)).map(({ name }) => createCompletion(name)) ?? []
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
}),
|
|
176
|
+
syntaxHighlighting(highlightStyles),
|
|
177
|
+
autocompletion({
|
|
178
|
+
aboveCursor: false,
|
|
179
|
+
defaultKeymap: true,
|
|
180
|
+
activateOnTyping: true,
|
|
181
|
+
// NOTE: Useful for debugging.
|
|
182
|
+
closeOnBlur: false,
|
|
183
|
+
icons: false,
|
|
184
|
+
tooltipClass: () => mx("!-left-[1px] !top-[33px] !-m-0 border !border-t-0 [&>ul]:!min-w-[198px]", "[&>ul>li[aria-selected]]:!bg-accentSurface", "border-separator")
|
|
185
|
+
}),
|
|
186
|
+
keymap.of([
|
|
187
|
+
{
|
|
188
|
+
key: "Tab",
|
|
189
|
+
run: (view) => {
|
|
190
|
+
return completionStatus(view.state) === "active" ? acceptCompletion(view) : startCompletion(view);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
])
|
|
194
|
+
];
|
|
195
|
+
};
|
|
196
|
+
var rangeExtension = ({ onInit, onStateChange }) => {
|
|
197
|
+
let view;
|
|
198
|
+
let activeRange;
|
|
199
|
+
const notifier = {
|
|
200
|
+
setRange: (range) => {
|
|
201
|
+
if (activeRange) {
|
|
202
|
+
view.dispatch(view.state.update({
|
|
203
|
+
changes: {
|
|
204
|
+
...activeRange,
|
|
205
|
+
insert: range.toString()
|
|
206
|
+
},
|
|
207
|
+
selection: {
|
|
208
|
+
anchor: activeRange.from + range.length
|
|
209
|
+
}
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
212
|
+
view.focus();
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
return ViewPlugin2.fromClass(class {
|
|
216
|
+
constructor(_view) {
|
|
217
|
+
view = _view;
|
|
218
|
+
onInit?.(notifier);
|
|
219
|
+
}
|
|
220
|
+
update(view2) {
|
|
221
|
+
const { anchor } = view2.state.selection.ranges[0];
|
|
222
|
+
activeRange = void 0;
|
|
223
|
+
const language = view2.state.facet(languageFacet);
|
|
224
|
+
const { topNode } = language.parser.parse(view2.state.doc.toString());
|
|
225
|
+
visitTree(topNode, ({ type, from, to }) => {
|
|
226
|
+
if (from <= anchor && to >= anchor) {
|
|
227
|
+
switch (type.name) {
|
|
228
|
+
case "Function":
|
|
229
|
+
activeRange = {
|
|
230
|
+
from: to,
|
|
231
|
+
to
|
|
232
|
+
};
|
|
233
|
+
break;
|
|
234
|
+
case "CloseParen":
|
|
235
|
+
activeRange = {
|
|
236
|
+
from,
|
|
237
|
+
to: from
|
|
238
|
+
};
|
|
239
|
+
break;
|
|
240
|
+
case "RangeToken":
|
|
241
|
+
case "CellToken":
|
|
242
|
+
activeRange = {
|
|
243
|
+
from,
|
|
244
|
+
to
|
|
245
|
+
};
|
|
246
|
+
return true;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return false;
|
|
250
|
+
});
|
|
251
|
+
if (!activeRange && view2.state.doc.toString()[0] === "=") {
|
|
252
|
+
const str = view2.state.doc.sliceString(1);
|
|
253
|
+
if (RANGE_NOTATION.test(str)) {
|
|
254
|
+
activeRange = {
|
|
255
|
+
from: 1,
|
|
256
|
+
to: str.length + 1
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
onStateChange?.({
|
|
261
|
+
activeRange: activeRange ? view2.state.doc.sliceString(activeRange.from, activeRange.to) : void 0
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
};
|
|
266
|
+
var visitTree = (node, callback) => {
|
|
267
|
+
if (callback(node)) {
|
|
268
|
+
return true;
|
|
269
|
+
}
|
|
270
|
+
for (let child = node.firstChild; child !== null; child = child.nextSibling) {
|
|
271
|
+
if (visitTree(child, callback)) {
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return false;
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// packages/plugins/plugin-sheet/src/components/SheetContext/SheetContext.tsx
|
|
279
|
+
import React2, { createContext as createContext2, useCallback, useContext as useContext2, useState as useState2 } from "react";
|
|
280
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
281
|
+
import { fullyQualifiedId } from "@dxos/react-client/echo";
|
|
282
|
+
import { Grid, useGridContext } from "@dxos/react-ui-grid";
|
|
283
|
+
|
|
284
|
+
// packages/plugins/plugin-sheet/src/model/sheet-model.ts
|
|
285
|
+
import { Event } from "@dxos/async";
|
|
286
|
+
import { Resource } from "@dxos/context";
|
|
287
|
+
import { getTypename, FormatEnum, TypeEnum } from "@dxos/echo-schema";
|
|
288
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
289
|
+
import { PublicKey } from "@dxos/keys";
|
|
290
|
+
import { log } from "@dxos/log";
|
|
291
|
+
import { DetailedCellError, ExportedCellChange } from "#hyperformula";
|
|
292
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/model/sheet-model.ts";
|
|
293
|
+
var typeMap = {
|
|
294
|
+
BOOLEAN: {
|
|
295
|
+
type: TypeEnum.Boolean
|
|
296
|
+
},
|
|
297
|
+
NUMBER_RAW: {
|
|
298
|
+
type: TypeEnum.Number
|
|
299
|
+
},
|
|
300
|
+
NUMBER_PERCENT: {
|
|
301
|
+
type: TypeEnum.Number,
|
|
302
|
+
format: FormatEnum.Percent
|
|
303
|
+
},
|
|
304
|
+
NUMBER_CURRENCY: {
|
|
305
|
+
type: TypeEnum.Number,
|
|
306
|
+
format: FormatEnum.Currency
|
|
307
|
+
},
|
|
308
|
+
NUMBER_DATETIME: {
|
|
309
|
+
type: TypeEnum.String,
|
|
310
|
+
format: FormatEnum.DateTime
|
|
311
|
+
},
|
|
312
|
+
NUMBER_DATE: {
|
|
313
|
+
type: TypeEnum.String,
|
|
314
|
+
format: FormatEnum.Date
|
|
315
|
+
},
|
|
316
|
+
NUMBER_TIME: {
|
|
317
|
+
type: TypeEnum.String,
|
|
318
|
+
format: FormatEnum.Time
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
var getTopLeft = (range) => {
|
|
322
|
+
const to = range.to ?? range.from;
|
|
323
|
+
return {
|
|
324
|
+
row: Math.min(range.from.row, to.row),
|
|
325
|
+
col: Math.min(range.from.col, to.col)
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
var toSimpleCellAddress = (sheet, cell) => ({
|
|
329
|
+
sheet,
|
|
330
|
+
row: cell.row,
|
|
331
|
+
col: cell.col
|
|
332
|
+
});
|
|
333
|
+
var toModelRange = (sheet, range) => ({
|
|
334
|
+
start: toSimpleCellAddress(sheet, range.from),
|
|
335
|
+
end: toSimpleCellAddress(sheet, range.to ?? range.from)
|
|
336
|
+
});
|
|
337
|
+
var SheetModel = class extends Resource {
|
|
338
|
+
constructor(_graph, _sheet, _options = {}) {
|
|
339
|
+
super();
|
|
340
|
+
this._graph = _graph;
|
|
341
|
+
this._sheet = _sheet;
|
|
342
|
+
this._options = _options;
|
|
343
|
+
this.id = `model-${PublicKey.random().truncate()}`;
|
|
344
|
+
this.update = new Event();
|
|
345
|
+
}
|
|
346
|
+
get graph() {
|
|
347
|
+
return this._graph;
|
|
348
|
+
}
|
|
349
|
+
get sheet() {
|
|
350
|
+
return this._sheet;
|
|
351
|
+
}
|
|
352
|
+
get readonly() {
|
|
353
|
+
return this._options.readonly;
|
|
354
|
+
}
|
|
355
|
+
get bounds() {
|
|
356
|
+
return {
|
|
357
|
+
rows: this._sheet.rows.length,
|
|
358
|
+
columns: this._sheet.columns.length
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Initialize sheet and engine.
|
|
363
|
+
*/
|
|
364
|
+
async _open() {
|
|
365
|
+
log("initialize", {
|
|
366
|
+
id: this.id
|
|
367
|
+
}, {
|
|
368
|
+
F: __dxlog_file,
|
|
369
|
+
L: 113,
|
|
370
|
+
S: this,
|
|
371
|
+
C: (f, a) => f(...a)
|
|
372
|
+
});
|
|
373
|
+
initialize(this._sheet);
|
|
374
|
+
this._graph.update.on((event) => {
|
|
375
|
+
if (event.type === "functionsUpdated") {
|
|
376
|
+
this.reset();
|
|
377
|
+
}
|
|
378
|
+
});
|
|
379
|
+
this._node = this._graph.getOrCreateNode(createSheetName({
|
|
380
|
+
type: getTypename(this._sheet),
|
|
381
|
+
id: this._sheet.id
|
|
382
|
+
}));
|
|
383
|
+
await this._node.open();
|
|
384
|
+
const unsubscribe = this._node.update.on((event) => this.update.emit(event));
|
|
385
|
+
this._ctx.onDispose(unsubscribe);
|
|
386
|
+
this.reset();
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Update engine.
|
|
390
|
+
* NOTE: This resets the undo history.
|
|
391
|
+
* @deprecated
|
|
392
|
+
*/
|
|
393
|
+
reset() {
|
|
394
|
+
invariant2(this._node, void 0, {
|
|
395
|
+
F: __dxlog_file,
|
|
396
|
+
L: 139,
|
|
397
|
+
S: this,
|
|
398
|
+
A: [
|
|
399
|
+
"this._node",
|
|
400
|
+
""
|
|
401
|
+
]
|
|
402
|
+
});
|
|
403
|
+
this._node.graph.hf.clearSheet(this._node.sheetId);
|
|
404
|
+
Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
|
|
405
|
+
invariant2(this._node, void 0, {
|
|
406
|
+
F: __dxlog_file,
|
|
407
|
+
L: 142,
|
|
408
|
+
S: this,
|
|
409
|
+
A: [
|
|
410
|
+
"this._node",
|
|
411
|
+
""
|
|
412
|
+
]
|
|
413
|
+
});
|
|
414
|
+
const { col, row } = addressFromIndex(this._sheet, key);
|
|
415
|
+
if (isFormula(value)) {
|
|
416
|
+
const binding = this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value));
|
|
417
|
+
if (binding) {
|
|
418
|
+
value = this._graph.mapFormulaToNative(binding);
|
|
419
|
+
} else {
|
|
420
|
+
value = "";
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
this._node.graph.hf.setCellContents({
|
|
424
|
+
sheet: this._node.sheetId,
|
|
425
|
+
row,
|
|
426
|
+
col
|
|
427
|
+
}, value);
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Recalculate formulas.
|
|
432
|
+
* NOTE: This resets the undo history.
|
|
433
|
+
* https://hyperformula.handsontable.com/guide/volatile-functions.html#volatile-actions
|
|
434
|
+
* @deprecated
|
|
435
|
+
*/
|
|
436
|
+
// TODO(burdon): Remove.
|
|
437
|
+
recalculate() {
|
|
438
|
+
this._node?.graph.hf.rebuildAndRecalculate();
|
|
439
|
+
}
|
|
440
|
+
insertRows(i, n = 1) {
|
|
441
|
+
const idx = insertIndices(this._sheet.rows, i, n, MAX_ROWS);
|
|
442
|
+
this.reset();
|
|
443
|
+
return idx;
|
|
444
|
+
}
|
|
445
|
+
insertColumns(i, n = 1) {
|
|
446
|
+
const idx = insertIndices(this._sheet.columns, i, n, MAX_COLUMNS);
|
|
447
|
+
this.reset();
|
|
448
|
+
return idx;
|
|
449
|
+
}
|
|
450
|
+
dropRow(rowIndex) {
|
|
451
|
+
const range = {
|
|
452
|
+
from: addressFromIndex(this._sheet, `${this._sheet.columns[0]}@${rowIndex}`),
|
|
453
|
+
to: addressFromIndex(this._sheet, `${this._sheet.columns[this._sheet.columns.length - 1]}@${rowIndex}`)
|
|
454
|
+
};
|
|
455
|
+
const values = this.getCellValues(range).flat();
|
|
456
|
+
const index = this._sheet.rows.indexOf(rowIndex);
|
|
457
|
+
this.clear(range);
|
|
458
|
+
this._sheet.rows.splice(index, 1);
|
|
459
|
+
delete this._sheet.rowMeta[rowIndex];
|
|
460
|
+
this.reset();
|
|
461
|
+
return {
|
|
462
|
+
axis: "row",
|
|
463
|
+
index,
|
|
464
|
+
axisIndex: rowIndex,
|
|
465
|
+
axisMeta: this._sheet.rowMeta[rowIndex],
|
|
466
|
+
values
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
dropColumn(colIndex) {
|
|
470
|
+
const range = {
|
|
471
|
+
from: addressFromIndex(this._sheet, `${colIndex}@${this._sheet.rows[0]}`),
|
|
472
|
+
to: addressFromIndex(this._sheet, `${colIndex}@${this._sheet.rows[this._sheet.rows.length - 1]}`)
|
|
473
|
+
};
|
|
474
|
+
const values = this.getCellValues(range).flat();
|
|
475
|
+
const index = this._sheet.columns.indexOf(colIndex);
|
|
476
|
+
this.clear(range);
|
|
477
|
+
this._sheet.columns.splice(index, 1);
|
|
478
|
+
delete this._sheet.columnMeta[colIndex];
|
|
479
|
+
this.reset();
|
|
480
|
+
return {
|
|
481
|
+
axis: "col",
|
|
482
|
+
index,
|
|
483
|
+
axisIndex: colIndex,
|
|
484
|
+
axisMeta: this._sheet.rowMeta[colIndex],
|
|
485
|
+
values
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
restoreRow({ index, axisIndex, axisMeta, values }) {
|
|
489
|
+
this._sheet.rows.splice(index, 0, axisIndex);
|
|
490
|
+
values.forEach((value, col) => {
|
|
491
|
+
if (value) {
|
|
492
|
+
this._sheet.cells[`${this._sheet.columns[col]}@${axisIndex}`] = {
|
|
493
|
+
value
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
if (axisMeta) {
|
|
498
|
+
this._sheet.rowMeta[axisIndex] = axisMeta;
|
|
499
|
+
}
|
|
500
|
+
this.reset();
|
|
501
|
+
}
|
|
502
|
+
restoreColumn({ index, axisIndex, axisMeta, values }) {
|
|
503
|
+
this._sheet.columns.splice(index, 0, axisIndex);
|
|
504
|
+
values.forEach((value, row) => {
|
|
505
|
+
if (value) {
|
|
506
|
+
this._sheet.cells[`${axisIndex}@${this._sheet.rows[row]}`] = {
|
|
507
|
+
value
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
if (axisMeta) {
|
|
512
|
+
this._sheet.columnMeta[axisIndex] = axisMeta;
|
|
513
|
+
}
|
|
514
|
+
this.reset();
|
|
515
|
+
}
|
|
516
|
+
//
|
|
517
|
+
// Undoable actions.
|
|
518
|
+
// TODO(burdon): Group undoable methods; consistently update hf/sheet.
|
|
519
|
+
//
|
|
520
|
+
/**
|
|
521
|
+
* Clear range of values.
|
|
522
|
+
*/
|
|
523
|
+
clear(range) {
|
|
524
|
+
invariant2(this._node, void 0, {
|
|
525
|
+
F: __dxlog_file,
|
|
526
|
+
L: 245,
|
|
527
|
+
S: this,
|
|
528
|
+
A: [
|
|
529
|
+
"this._node",
|
|
530
|
+
""
|
|
531
|
+
]
|
|
532
|
+
});
|
|
533
|
+
const topLeft = getTopLeft(range);
|
|
534
|
+
const values = this._iterRange(range, () => null);
|
|
535
|
+
this._node.graph.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
|
|
536
|
+
this._iterRange(range, (cell) => {
|
|
537
|
+
const idx = addressToIndex(this._sheet, cell);
|
|
538
|
+
delete this._sheet.cells[idx];
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
cut(range) {
|
|
542
|
+
invariant2(this._node, void 0, {
|
|
543
|
+
F: __dxlog_file,
|
|
544
|
+
L: 256,
|
|
545
|
+
S: this,
|
|
546
|
+
A: [
|
|
547
|
+
"this._node",
|
|
548
|
+
""
|
|
549
|
+
]
|
|
550
|
+
});
|
|
551
|
+
this._node.graph.hf.cut(toModelRange(this._node.sheetId, range));
|
|
552
|
+
this._iterRange(range, (cell) => {
|
|
553
|
+
const idx = addressToIndex(this._sheet, cell);
|
|
554
|
+
delete this._sheet.cells[idx];
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
copy(range) {
|
|
558
|
+
invariant2(this._node, void 0, {
|
|
559
|
+
F: __dxlog_file,
|
|
560
|
+
L: 265,
|
|
561
|
+
S: this,
|
|
562
|
+
A: [
|
|
563
|
+
"this._node",
|
|
564
|
+
""
|
|
565
|
+
]
|
|
566
|
+
});
|
|
567
|
+
this._node.graph.hf.copy(toModelRange(this._node.sheetId, range));
|
|
568
|
+
}
|
|
569
|
+
paste(cell) {
|
|
570
|
+
invariant2(this._node, void 0, {
|
|
571
|
+
F: __dxlog_file,
|
|
572
|
+
L: 270,
|
|
573
|
+
S: this,
|
|
574
|
+
A: [
|
|
575
|
+
"this._node",
|
|
576
|
+
""
|
|
577
|
+
]
|
|
578
|
+
});
|
|
579
|
+
if (!this._node.graph.hf.isClipboardEmpty()) {
|
|
580
|
+
const changes = this._node.graph.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
|
|
581
|
+
for (const change of changes) {
|
|
582
|
+
if (change instanceof ExportedCellChange) {
|
|
583
|
+
const { address, newValue } = change;
|
|
584
|
+
const idx = addressToIndex(this._sheet, {
|
|
585
|
+
row: address.row,
|
|
586
|
+
col: address.col
|
|
587
|
+
});
|
|
588
|
+
this._sheet.cells[idx] = {
|
|
589
|
+
value: newValue
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
// TODO(burdon): Display undo/redo state.
|
|
596
|
+
undo() {
|
|
597
|
+
invariant2(this._node, void 0, {
|
|
598
|
+
F: __dxlog_file,
|
|
599
|
+
L: 285,
|
|
600
|
+
S: this,
|
|
601
|
+
A: [
|
|
602
|
+
"this._node",
|
|
603
|
+
""
|
|
604
|
+
]
|
|
605
|
+
});
|
|
606
|
+
if (this._node.graph.hf.isThereSomethingToUndo()) {
|
|
607
|
+
this._node.graph.hf.undo();
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
redo() {
|
|
611
|
+
invariant2(this._node, void 0, {
|
|
612
|
+
F: __dxlog_file,
|
|
613
|
+
L: 293,
|
|
614
|
+
S: this,
|
|
615
|
+
A: [
|
|
616
|
+
"this._node",
|
|
617
|
+
""
|
|
618
|
+
]
|
|
619
|
+
});
|
|
620
|
+
if (this._node.graph.hf.isThereSomethingToRedo()) {
|
|
621
|
+
this._node.graph.hf.redo();
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* Get value from sheet.
|
|
626
|
+
*/
|
|
627
|
+
getCellValue(cell) {
|
|
628
|
+
const idx = addressToIndex(this._sheet, cell);
|
|
629
|
+
return this._sheet.cells[idx]?.value ?? null;
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* Get value as a string for editing.
|
|
633
|
+
*/
|
|
634
|
+
getCellText(cell) {
|
|
635
|
+
const value = this.getCellValue(cell);
|
|
636
|
+
if (value == null) {
|
|
637
|
+
return void 0;
|
|
638
|
+
}
|
|
639
|
+
if (isFormula(value)) {
|
|
640
|
+
return this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value));
|
|
641
|
+
} else {
|
|
642
|
+
return String(value);
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Get array of raw values from sheet.
|
|
647
|
+
*/
|
|
648
|
+
getCellValues(range) {
|
|
649
|
+
return this._iterRange(range, (cell) => this.getCellValue(cell));
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Gets the regular or computed value from the engine.
|
|
653
|
+
*/
|
|
654
|
+
getValue(cell) {
|
|
655
|
+
invariant2(this._node, void 0, {
|
|
656
|
+
F: __dxlog_file,
|
|
657
|
+
L: 336,
|
|
658
|
+
S: this,
|
|
659
|
+
A: [
|
|
660
|
+
"this._node",
|
|
661
|
+
""
|
|
662
|
+
]
|
|
663
|
+
});
|
|
664
|
+
const address = toSimpleCellAddress(this._node.sheetId, cell);
|
|
665
|
+
const value = this._node.graph.hf.getCellValue(address);
|
|
666
|
+
if (value instanceof DetailedCellError) {
|
|
667
|
+
log.info("cell error", {
|
|
668
|
+
cell,
|
|
669
|
+
error: value
|
|
670
|
+
}, {
|
|
671
|
+
F: __dxlog_file,
|
|
672
|
+
L: 341,
|
|
673
|
+
S: this,
|
|
674
|
+
C: (f, a) => f(...a)
|
|
675
|
+
});
|
|
676
|
+
return value.toString();
|
|
677
|
+
}
|
|
678
|
+
return value;
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Get value type.
|
|
682
|
+
*/
|
|
683
|
+
getValueDescription(cell) {
|
|
684
|
+
invariant2(this._node, void 0, {
|
|
685
|
+
F: __dxlog_file,
|
|
686
|
+
L: 352,
|
|
687
|
+
S: this,
|
|
688
|
+
A: [
|
|
689
|
+
"this._node",
|
|
690
|
+
""
|
|
691
|
+
]
|
|
692
|
+
});
|
|
693
|
+
const addr = toSimpleCellAddress(this._node.sheetId, cell);
|
|
694
|
+
const type = this._node.graph.hf.getCellValueDetailedType(addr);
|
|
695
|
+
return typeMap[type];
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Sets the value, updating the sheet and engine.
|
|
699
|
+
*/
|
|
700
|
+
setValue(cell, value) {
|
|
701
|
+
invariant2(this._node, void 0, {
|
|
702
|
+
F: __dxlog_file,
|
|
703
|
+
L: 362,
|
|
704
|
+
S: this,
|
|
705
|
+
A: [
|
|
706
|
+
"this._node",
|
|
707
|
+
""
|
|
708
|
+
]
|
|
709
|
+
});
|
|
710
|
+
if (this._options.readonly) {
|
|
711
|
+
throw new ReadonlyException();
|
|
712
|
+
}
|
|
713
|
+
let refresh = false;
|
|
714
|
+
if (cell.row >= this._sheet.rows.length) {
|
|
715
|
+
insertIndices(this._sheet.rows, cell.row, 1, MAX_ROWS);
|
|
716
|
+
refresh = true;
|
|
717
|
+
}
|
|
718
|
+
if (cell.col >= this._sheet.columns.length) {
|
|
719
|
+
insertIndices(this._sheet.columns, cell.col, 1, MAX_COLUMNS);
|
|
720
|
+
refresh = true;
|
|
721
|
+
}
|
|
722
|
+
if (refresh) {
|
|
723
|
+
this.reset();
|
|
724
|
+
}
|
|
725
|
+
this._node.graph.hf.setCellContents({
|
|
726
|
+
sheet: this._node.sheetId,
|
|
727
|
+
row: cell.row,
|
|
728
|
+
col: cell.col
|
|
729
|
+
}, [
|
|
730
|
+
[
|
|
731
|
+
isFormula(value) ? this._graph.mapFormulaToNative(value) : value
|
|
732
|
+
]
|
|
733
|
+
]);
|
|
734
|
+
const idx = addressToIndex(this._sheet, cell);
|
|
735
|
+
if (value === void 0 || value === null) {
|
|
736
|
+
delete this._sheet.cells[idx];
|
|
737
|
+
} else {
|
|
738
|
+
if (isFormula(value)) {
|
|
739
|
+
value = this._graph.mapFunctionBindingToId(this.mapFormulaRefsToIndices(value));
|
|
740
|
+
}
|
|
741
|
+
this._sheet.cells[idx] = {
|
|
742
|
+
value
|
|
743
|
+
};
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Sets values from a simple map.
|
|
748
|
+
*/
|
|
749
|
+
setValues(values) {
|
|
750
|
+
Object.entries(values).forEach(([key, { value }]) => {
|
|
751
|
+
this.setValue(addressFromA1Notation(key), value);
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
/**
|
|
755
|
+
* Iterate range.
|
|
756
|
+
*/
|
|
757
|
+
_iterRange(range, cb) {
|
|
758
|
+
const to = range.to ?? range.from;
|
|
759
|
+
const rowRange = [
|
|
760
|
+
Math.min(range.from.row, to.row),
|
|
761
|
+
Math.max(range.from.row, to.row)
|
|
762
|
+
];
|
|
763
|
+
const columnRange = [
|
|
764
|
+
Math.min(range.from.col, to.col),
|
|
765
|
+
Math.max(range.from.col, to.col)
|
|
766
|
+
];
|
|
767
|
+
const rows = [];
|
|
768
|
+
for (let row = rowRange[0]; row <= rowRange[1]; row++) {
|
|
769
|
+
const rowCells = [];
|
|
770
|
+
for (let column = columnRange[0]; column <= columnRange[1]; column++) {
|
|
771
|
+
const value = cb({
|
|
772
|
+
row,
|
|
773
|
+
col: column
|
|
774
|
+
});
|
|
775
|
+
if (value !== void 0) {
|
|
776
|
+
rowCells.push(value);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
rows.push(rowCells);
|
|
780
|
+
}
|
|
781
|
+
return rows;
|
|
782
|
+
}
|
|
783
|
+
// TODO(burdon): Delete index.
|
|
784
|
+
_deleteIndices(indices, i, n) {
|
|
785
|
+
throw new Error("Not implemented");
|
|
786
|
+
}
|
|
787
|
+
// TODO(burdon): Move. Cannot use fractional without changing. Switch back to using unique IDs?
|
|
788
|
+
_moveIndices(indices, i, j, n) {
|
|
789
|
+
throw new Error("Not implemented");
|
|
790
|
+
}
|
|
791
|
+
//
|
|
792
|
+
// Indices.
|
|
793
|
+
//
|
|
794
|
+
/**
|
|
795
|
+
* Map from A1 notation to indices.
|
|
796
|
+
*/
|
|
797
|
+
mapFormulaRefsToIndices(formula) {
|
|
798
|
+
invariant2(isFormula(formula), void 0, {
|
|
799
|
+
F: __dxlog_file,
|
|
800
|
+
L: 451,
|
|
801
|
+
S: this,
|
|
802
|
+
A: [
|
|
803
|
+
"isFormula(formula)",
|
|
804
|
+
""
|
|
805
|
+
]
|
|
806
|
+
});
|
|
807
|
+
return formula.replace(/([a-zA-Z]+)([0-9]+)/g, (match) => {
|
|
808
|
+
return addressToIndex(this._sheet, addressFromA1Notation(match));
|
|
809
|
+
});
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Map from indices to A1 notation.
|
|
813
|
+
*/
|
|
814
|
+
mapFormulaIndicesToRefs(formula) {
|
|
815
|
+
invariant2(isFormula(formula), void 0, {
|
|
816
|
+
F: __dxlog_file,
|
|
817
|
+
L: 461,
|
|
818
|
+
S: this,
|
|
819
|
+
A: [
|
|
820
|
+
"isFormula(formula)",
|
|
821
|
+
""
|
|
822
|
+
]
|
|
823
|
+
});
|
|
824
|
+
return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
|
|
825
|
+
return addressToA1Notation(addressFromIndex(this._sheet, idx));
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
//
|
|
829
|
+
// Values
|
|
830
|
+
//
|
|
831
|
+
/**
|
|
832
|
+
* https://hyperformula.handsontable.com/guide/date-and-time-handling.html#example
|
|
833
|
+
* https://hyperformula.handsontable.com/api/interfaces/configparams.html#nulldate
|
|
834
|
+
* NOTE: TODAY() is number of FULL days since nullDate. It will typically be -1 days from NOW().
|
|
835
|
+
*/
|
|
836
|
+
toLocalDate(num) {
|
|
837
|
+
const { year, month, day, hours, minutes, seconds } = this.toDateTime(num);
|
|
838
|
+
return new Date(year, month - 1, day, hours, minutes, seconds);
|
|
839
|
+
}
|
|
840
|
+
toDateTime(num) {
|
|
841
|
+
invariant2(this._node, void 0, {
|
|
842
|
+
F: __dxlog_file,
|
|
843
|
+
L: 482,
|
|
844
|
+
S: this,
|
|
845
|
+
A: [
|
|
846
|
+
"this._node",
|
|
847
|
+
""
|
|
848
|
+
]
|
|
849
|
+
});
|
|
850
|
+
return this._node.graph.hf.numberToDateTime(num);
|
|
851
|
+
}
|
|
852
|
+
toDate(num) {
|
|
853
|
+
invariant2(this._node, void 0, {
|
|
854
|
+
F: __dxlog_file,
|
|
855
|
+
L: 487,
|
|
856
|
+
S: this,
|
|
857
|
+
A: [
|
|
858
|
+
"this._node",
|
|
859
|
+
""
|
|
860
|
+
]
|
|
861
|
+
});
|
|
862
|
+
return this._node.graph.hf.numberToDate(num);
|
|
863
|
+
}
|
|
864
|
+
toTime(num) {
|
|
865
|
+
invariant2(this._node, void 0, {
|
|
866
|
+
F: __dxlog_file,
|
|
867
|
+
L: 492,
|
|
868
|
+
S: this,
|
|
869
|
+
A: [
|
|
870
|
+
"this._node",
|
|
871
|
+
""
|
|
872
|
+
]
|
|
873
|
+
});
|
|
874
|
+
return this._node.graph.hf.numberToTime(num);
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
|
|
878
|
+
// packages/plugins/plugin-sheet/src/model/useSheetModel.ts
|
|
879
|
+
import { useEffect, useState } from "react";
|
|
880
|
+
var useSheetModel = (graph, sheet, { readonly } = {}) => {
|
|
881
|
+
const [model, setModel] = useState();
|
|
882
|
+
useEffect(() => {
|
|
883
|
+
if (!graph || !sheet) {
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
let model2;
|
|
887
|
+
const t = setTimeout(async () => {
|
|
888
|
+
model2 = new SheetModel(graph, sheet, {
|
|
889
|
+
readonly
|
|
890
|
+
});
|
|
891
|
+
await model2.open();
|
|
892
|
+
setModel(model2);
|
|
893
|
+
});
|
|
894
|
+
return () => {
|
|
895
|
+
clearTimeout(t);
|
|
896
|
+
void model2?.close();
|
|
897
|
+
};
|
|
898
|
+
}, [
|
|
899
|
+
graph,
|
|
900
|
+
sheet,
|
|
901
|
+
readonly
|
|
902
|
+
]);
|
|
903
|
+
return model;
|
|
904
|
+
};
|
|
905
|
+
|
|
906
|
+
// packages/plugins/plugin-sheet/src/components/SheetContext/SheetContext.tsx
|
|
907
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/components/SheetContext/SheetContext.tsx";
|
|
908
|
+
var SheetContext = /* @__PURE__ */ createContext2(void 0);
|
|
909
|
+
var useSheetContext = () => {
|
|
910
|
+
const context = useContext2(SheetContext);
|
|
911
|
+
invariant3(context, void 0, {
|
|
912
|
+
F: __dxlog_file2,
|
|
913
|
+
L: 52,
|
|
914
|
+
S: void 0,
|
|
915
|
+
A: [
|
|
916
|
+
"context",
|
|
917
|
+
""
|
|
918
|
+
]
|
|
919
|
+
});
|
|
920
|
+
return context;
|
|
921
|
+
};
|
|
922
|
+
var SheetProviderImpl = ({ model, onInfo, children, __gridScope }) => {
|
|
923
|
+
const { id, editing, setEditing } = useGridContext("SheetProvider", __gridScope);
|
|
924
|
+
const [cursor, setCursorInternal] = useState2();
|
|
925
|
+
const [range, setRangeInternal] = useState2();
|
|
926
|
+
const [cursorFallbackRange, setCursorFallbackRange] = useState2();
|
|
927
|
+
const [activeRefs, setActiveRefs] = useState2("");
|
|
928
|
+
const setCursor = useCallback((nextCursor) => {
|
|
929
|
+
setCursorInternal(nextCursor);
|
|
930
|
+
setCursorFallbackRange(range?.to ? range : nextCursor ? {
|
|
931
|
+
from: nextCursor,
|
|
932
|
+
to: nextCursor
|
|
933
|
+
} : void 0);
|
|
934
|
+
}, [
|
|
935
|
+
range
|
|
936
|
+
]);
|
|
937
|
+
const setRange = useCallback((nextRange) => {
|
|
938
|
+
setRangeInternal(nextRange);
|
|
939
|
+
setCursorFallbackRange(nextRange?.to ? nextRange : cursor ? {
|
|
940
|
+
from: cursor,
|
|
941
|
+
to: cursor
|
|
942
|
+
} : void 0);
|
|
943
|
+
}, [
|
|
944
|
+
cursor
|
|
945
|
+
]);
|
|
946
|
+
return /* @__PURE__ */ React2.createElement(SheetContext.Provider, {
|
|
947
|
+
value: {
|
|
948
|
+
id,
|
|
949
|
+
model,
|
|
950
|
+
editing,
|
|
951
|
+
setEditing,
|
|
952
|
+
cursor,
|
|
953
|
+
setCursor,
|
|
954
|
+
range,
|
|
955
|
+
setRange,
|
|
956
|
+
cursorFallbackRange,
|
|
957
|
+
activeRefs,
|
|
958
|
+
setActiveRefs,
|
|
959
|
+
// TODO(burdon): Change to event.
|
|
960
|
+
onInfo
|
|
961
|
+
}
|
|
962
|
+
}, children);
|
|
963
|
+
};
|
|
964
|
+
var SheetProvider = ({ children, graph, sheet, readonly, onInfo }) => {
|
|
965
|
+
const model = useSheetModel(graph, sheet, {
|
|
966
|
+
readonly
|
|
967
|
+
});
|
|
968
|
+
return !model ? null : /* @__PURE__ */ React2.createElement(Grid.Root, {
|
|
969
|
+
id: fullyQualifiedId(sheet)
|
|
970
|
+
}, /* @__PURE__ */ React2.createElement(SheetProviderImpl, {
|
|
971
|
+
model,
|
|
972
|
+
onInfo
|
|
973
|
+
}, children));
|
|
974
|
+
};
|
|
975
|
+
|
|
976
|
+
// packages/plugins/plugin-sheet/src/components/GridSheet/GridSheet.tsx
|
|
977
|
+
import React4, { useCallback as useCallback4, useMemo as useMemo2, useRef, useState as useState4 } from "react";
|
|
978
|
+
import { useIntentDispatcher as useIntentDispatcher2 } from "@dxos/app-framework";
|
|
979
|
+
import { DropdownMenu, Icon, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
980
|
+
import { useAttention } from "@dxos/react-ui-attention";
|
|
981
|
+
import { closestCell, editorKeys, Grid as Grid2, GridCellEditor } from "@dxos/react-ui-grid";
|
|
982
|
+
|
|
983
|
+
// packages/plugins/plugin-sheet/src/components/GridSheet/util.ts
|
|
984
|
+
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
985
|
+
import { createDocAccessor, fullyQualifiedId as fullyQualifiedId3 } from "@dxos/react-client/echo";
|
|
986
|
+
import { parseValue, cellClassesForFieldType } from "@dxos/react-ui-data";
|
|
987
|
+
import { colToA1Notation, rowToA1Notation, commentedClassName } from "@dxos/react-ui-grid";
|
|
988
|
+
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
989
|
+
|
|
990
|
+
// packages/plugins/plugin-sheet/src/integrations/thread-ranges.ts
|
|
991
|
+
import { useCallback as useCallback3, useEffect as useEffect2, useMemo } from "react";
|
|
992
|
+
import { LayoutAction, useIntentDispatcher, useIntentResolver } from "@dxos/app-framework";
|
|
993
|
+
import { debounce as debounce2 } from "@dxos/async";
|
|
994
|
+
import { fullyQualifiedId as fullyQualifiedId2 } from "@dxos/react-client/echo";
|
|
995
|
+
|
|
996
|
+
// packages/plugins/plugin-sheet/src/components/index.ts
|
|
997
|
+
import { lazy } from "react";
|
|
998
|
+
|
|
999
|
+
// packages/plugins/plugin-sheet/src/components/RangeList/RangeList.tsx
|
|
1000
|
+
import React3, { useCallback as useCallback2 } from "react";
|
|
1001
|
+
import { S } from "@dxos/echo-schema";
|
|
1002
|
+
import { useTranslation } from "@dxos/react-ui";
|
|
1003
|
+
import { List } from "@dxos/react-ui-list";
|
|
1004
|
+
import { ghostHover } from "@dxos/react-ui-theme";
|
|
1005
|
+
var RangeList = ({ sheet }) => {
|
|
1006
|
+
const { t } = useTranslation(SHEET_PLUGIN);
|
|
1007
|
+
const handleSelectRange = (range) => {
|
|
1008
|
+
};
|
|
1009
|
+
const handleDeleteRange = useCallback2((range) => {
|
|
1010
|
+
const index = sheet.ranges.findIndex((sheetRange) => sheetRange === range);
|
|
1011
|
+
sheet.ranges.splice(index, 1);
|
|
1012
|
+
}, [
|
|
1013
|
+
sheet
|
|
1014
|
+
]);
|
|
1015
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement("h2", {
|
|
1016
|
+
className: "p-2 text-sm font-semibold"
|
|
1017
|
+
}, t("range list heading")), /* @__PURE__ */ React3.createElement(List.Root, {
|
|
1018
|
+
items: sheet.ranges,
|
|
1019
|
+
isItem: S.is(Range)
|
|
1020
|
+
}, ({ items: ranges }) => ranges.map((range, i) => /* @__PURE__ */ React3.createElement(List.Item, {
|
|
1021
|
+
key: i,
|
|
1022
|
+
item: range,
|
|
1023
|
+
classNames: [
|
|
1024
|
+
"p-2",
|
|
1025
|
+
ghostHover
|
|
1026
|
+
]
|
|
1027
|
+
}, /* @__PURE__ */ React3.createElement(List.ItemDragHandle, null), /* @__PURE__ */ React3.createElement(List.ItemTitle, {
|
|
1028
|
+
onClick: () => handleSelectRange(range)
|
|
1029
|
+
}, t("range title", {
|
|
1030
|
+
position: rangeToA1Notation(rangeFromIndex(sheet, range.range)),
|
|
1031
|
+
key: t(`range key ${range.key} label`),
|
|
1032
|
+
value: t(`range value ${range.value} label`)
|
|
1033
|
+
})), /* @__PURE__ */ React3.createElement(List.ItemDeleteButton, {
|
|
1034
|
+
onClick: () => handleDeleteRange(range)
|
|
1035
|
+
})))));
|
|
1036
|
+
};
|
|
1037
|
+
|
|
1038
|
+
// packages/plugins/plugin-sheet/src/components/index.ts
|
|
1039
|
+
var SheetContainer = lazy(() => import("./SheetContainer-JZEKRM4Z.mjs"));
|
|
1040
|
+
|
|
1041
|
+
// packages/plugins/plugin-sheet/src/integrations/thread-ranges.ts
|
|
1042
|
+
var completeCellRangeToThreadCursor = (range) => {
|
|
1043
|
+
return `${range.from.col},${range.from.row},${range.to.col},${range.to.row}`;
|
|
1044
|
+
};
|
|
1045
|
+
var parseThreadAnchorAsCellRange = (cursor) => {
|
|
1046
|
+
const coords = cursor.split(",");
|
|
1047
|
+
if (coords.length !== 4) {
|
|
1048
|
+
return null;
|
|
1049
|
+
} else {
|
|
1050
|
+
const [fromCol, fromRow, toCol, toRow] = coords;
|
|
1051
|
+
return {
|
|
1052
|
+
from: {
|
|
1053
|
+
col: parseInt(fromCol),
|
|
1054
|
+
row: parseInt(fromRow)
|
|
1055
|
+
},
|
|
1056
|
+
to: {
|
|
1057
|
+
col: parseInt(toCol),
|
|
1058
|
+
row: parseInt(toRow)
|
|
1059
|
+
}
|
|
1060
|
+
};
|
|
1061
|
+
}
|
|
1062
|
+
};
|
|
1063
|
+
var useUpdateFocusedCellOnThreadSelection = (grid) => {
|
|
1064
|
+
const { model, setActiveRefs } = useSheetContext();
|
|
1065
|
+
const handleScrollIntoView = useCallback3(({ action, data }) => {
|
|
1066
|
+
switch (action) {
|
|
1067
|
+
case LayoutAction.SCROLL_INTO_VIEW: {
|
|
1068
|
+
if (!data?.id || data?.cursor === void 0 || data?.id !== fullyQualifiedId2(model.sheet)) {
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
setActiveRefs(data.thread);
|
|
1072
|
+
const range = parseThreadAnchorAsCellRange(data.cursor);
|
|
1073
|
+
range && grid?.setFocus({
|
|
1074
|
+
...range.to,
|
|
1075
|
+
plane: "grid"
|
|
1076
|
+
}, true);
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
}, [
|
|
1080
|
+
model.sheet,
|
|
1081
|
+
setActiveRefs
|
|
1082
|
+
]);
|
|
1083
|
+
useIntentResolver(SHEET_PLUGIN, handleScrollIntoView);
|
|
1084
|
+
};
|
|
1085
|
+
var useSelectThreadOnCellFocus = () => {
|
|
1086
|
+
const { model, cursor } = useSheetContext();
|
|
1087
|
+
const dispatch = useIntentDispatcher();
|
|
1088
|
+
const threads = useMemo(() => model.sheet.threads?.filter((thread) => !!thread) ?? [], [
|
|
1089
|
+
// TODO(thure): Surely we can find a better dependency for this…
|
|
1090
|
+
JSON.stringify(model.sheet.threads)
|
|
1091
|
+
]);
|
|
1092
|
+
const selectClosestThread = useCallback3((cellAddress) => {
|
|
1093
|
+
if (!cellAddress || !threads) {
|
|
1094
|
+
return;
|
|
1095
|
+
}
|
|
1096
|
+
const closestThread = threads?.find(({ anchor }) => {
|
|
1097
|
+
if (anchor) {
|
|
1098
|
+
const range = parseThreadAnchorAsCellRange(anchor);
|
|
1099
|
+
return range ? inRange(range, cellAddress) : false;
|
|
1100
|
+
} else {
|
|
1101
|
+
return false;
|
|
1102
|
+
}
|
|
1103
|
+
});
|
|
1104
|
+
if (closestThread) {
|
|
1105
|
+
void dispatch([
|
|
1106
|
+
{
|
|
1107
|
+
action: "dxos.org/plugin/thread/action/select",
|
|
1108
|
+
data: {
|
|
1109
|
+
current: fullyQualifiedId2(closestThread)
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
]);
|
|
1113
|
+
}
|
|
1114
|
+
}, [
|
|
1115
|
+
dispatch,
|
|
1116
|
+
threads
|
|
1117
|
+
]);
|
|
1118
|
+
const debounced = useMemo(() => {
|
|
1119
|
+
return debounce2((cellCoords) => requestAnimationFrame(() => selectClosestThread(cellCoords)), 50);
|
|
1120
|
+
}, [
|
|
1121
|
+
selectClosestThread
|
|
1122
|
+
]);
|
|
1123
|
+
useEffect2(() => {
|
|
1124
|
+
if (!cursor) {
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
debounced(cursor);
|
|
1128
|
+
}, [
|
|
1129
|
+
cursor,
|
|
1130
|
+
debounced
|
|
1131
|
+
]);
|
|
1132
|
+
};
|
|
1133
|
+
|
|
1134
|
+
// packages/plugins/plugin-sheet/src/components/GridSheet/util.ts
|
|
1135
|
+
var dxGridCellIndexToSheetCellAddress = (index) => {
|
|
1136
|
+
const [colStr, rowStr] = index.split(",");
|
|
1137
|
+
return {
|
|
1138
|
+
col: parseInt(colStr),
|
|
1139
|
+
row: parseInt(rowStr)
|
|
1140
|
+
};
|
|
1141
|
+
};
|
|
1142
|
+
var createDxGridColumns = (model) => {
|
|
1143
|
+
return model.sheet.columns.reduce((acc, columnId, numericIndex) => {
|
|
1144
|
+
if (model.sheet.columnMeta[columnId] && model.sheet.columnMeta[columnId].size) {
|
|
1145
|
+
acc.grid[numericIndex] = {
|
|
1146
|
+
size: model.sheet.columnMeta[columnId].size,
|
|
1147
|
+
resizeable: true
|
|
1148
|
+
};
|
|
1149
|
+
}
|
|
1150
|
+
return acc;
|
|
1151
|
+
}, {
|
|
1152
|
+
grid: {}
|
|
1153
|
+
});
|
|
1154
|
+
};
|
|
1155
|
+
var createDxGridRows = (model) => {
|
|
1156
|
+
return model.sheet.rows.reduce((acc, rowId, numericIndex) => {
|
|
1157
|
+
if (model.sheet.rowMeta[rowId] && model.sheet.rowMeta[rowId].size) {
|
|
1158
|
+
acc.grid[numericIndex] = {
|
|
1159
|
+
size: model.sheet.rowMeta[rowId].size,
|
|
1160
|
+
resizeable: true
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
return acc;
|
|
1164
|
+
}, {
|
|
1165
|
+
grid: {}
|
|
1166
|
+
});
|
|
1167
|
+
};
|
|
1168
|
+
var projectCellProps = (model, col, row) => {
|
|
1169
|
+
const address = {
|
|
1170
|
+
col,
|
|
1171
|
+
row
|
|
1172
|
+
};
|
|
1173
|
+
const rawValue = model.getValue(address);
|
|
1174
|
+
const ranges = model.sheet.ranges?.filter(({ range }) => inRange(rangeFromIndex(model.sheet, range), address));
|
|
1175
|
+
const threadRefs = model.sheet.threads?.filter((thread) => {
|
|
1176
|
+
const range = thread?.anchor && parseThreadAnchorAsCellRange(thread.anchor);
|
|
1177
|
+
return thread && range ? inRange(range, address) : false;
|
|
1178
|
+
}).map((thread) => fullyQualifiedId3(thread)).join(" ");
|
|
1179
|
+
const description = model.getValueDescription(address);
|
|
1180
|
+
const type = description?.type;
|
|
1181
|
+
const format = description?.format;
|
|
1182
|
+
const classNames = ranges?.map(cellClassNameForRange).reverse();
|
|
1183
|
+
return {
|
|
1184
|
+
value: parseValue({
|
|
1185
|
+
type,
|
|
1186
|
+
format,
|
|
1187
|
+
value: rawValue
|
|
1188
|
+
}),
|
|
1189
|
+
className: mx2(cellClassesForFieldType({
|
|
1190
|
+
type,
|
|
1191
|
+
format
|
|
1192
|
+
}), threadRefs && commentedClassName, classNames),
|
|
1193
|
+
dataRefs: threadRefs
|
|
1194
|
+
};
|
|
1195
|
+
};
|
|
1196
|
+
var gridCellGetter = (model) => {
|
|
1197
|
+
const cachedGridCells = {};
|
|
1198
|
+
return (nextBounds) => {
|
|
1199
|
+
[
|
|
1200
|
+
...Array(nextBounds.end.col - nextBounds.start.col)
|
|
1201
|
+
].forEach((_, c0) => {
|
|
1202
|
+
return [
|
|
1203
|
+
...Array(nextBounds.end.row - nextBounds.start.row)
|
|
1204
|
+
].forEach((_2, r0) => {
|
|
1205
|
+
const col = nextBounds.start.col + c0;
|
|
1206
|
+
const row = nextBounds.start.row + r0;
|
|
1207
|
+
cachedGridCells[`${col},${row}`] = projectCellProps(model, col, row);
|
|
1208
|
+
});
|
|
1209
|
+
});
|
|
1210
|
+
return cachedGridCells;
|
|
1211
|
+
};
|
|
1212
|
+
};
|
|
1213
|
+
var rowLabelCell = (row) => ({
|
|
1214
|
+
value: rowToA1Notation(row),
|
|
1215
|
+
className: "text-end !pie-1",
|
|
1216
|
+
resizeHandle: "row"
|
|
1217
|
+
});
|
|
1218
|
+
var colLabelCell = (col) => ({
|
|
1219
|
+
value: colToA1Notation(col),
|
|
1220
|
+
resizeHandle: "col"
|
|
1221
|
+
});
|
|
1222
|
+
var cellGetter = (model) => {
|
|
1223
|
+
const getGridCells = gridCellGetter(model);
|
|
1224
|
+
return (nextBounds, plane) => {
|
|
1225
|
+
switch (plane) {
|
|
1226
|
+
case "grid":
|
|
1227
|
+
return getGridCells(nextBounds);
|
|
1228
|
+
case "frozenColsStart":
|
|
1229
|
+
return [
|
|
1230
|
+
...Array(nextBounds.end.row - nextBounds.start.row)
|
|
1231
|
+
].reduce((acc, _, r0) => {
|
|
1232
|
+
const r = nextBounds.start.row + r0;
|
|
1233
|
+
acc[`0,${r}`] = rowLabelCell(r);
|
|
1234
|
+
return acc;
|
|
1235
|
+
}, {});
|
|
1236
|
+
case "frozenRowsStart":
|
|
1237
|
+
return [
|
|
1238
|
+
...Array(nextBounds.end.col - nextBounds.start.col)
|
|
1239
|
+
].reduce((acc, _, c0) => {
|
|
1240
|
+
const c = nextBounds.start.col + c0;
|
|
1241
|
+
acc[`${c},0`] = colLabelCell(c);
|
|
1242
|
+
return acc;
|
|
1243
|
+
}, {});
|
|
1244
|
+
default:
|
|
1245
|
+
return {};
|
|
1246
|
+
}
|
|
1247
|
+
};
|
|
1248
|
+
};
|
|
1249
|
+
var useSheetModelDxGridProps = (dxGrid, model) => {
|
|
1250
|
+
const [columns, setColumns] = useState3(createDxGridColumns(model));
|
|
1251
|
+
const [rows, setRows] = useState3(createDxGridColumns(model));
|
|
1252
|
+
useEffect3(() => {
|
|
1253
|
+
const cellsAccessor = createDocAccessor(model.sheet, [
|
|
1254
|
+
"cells"
|
|
1255
|
+
]);
|
|
1256
|
+
if (dxGrid) {
|
|
1257
|
+
dxGrid.getCells = cellGetter(model);
|
|
1258
|
+
}
|
|
1259
|
+
const handleCellsUpdate = () => {
|
|
1260
|
+
dxGrid?.requestUpdate("initialCells");
|
|
1261
|
+
};
|
|
1262
|
+
cellsAccessor.handle.addListener("change", handleCellsUpdate);
|
|
1263
|
+
const unsubscribe = model.graph.update.on(handleCellsUpdate);
|
|
1264
|
+
return () => {
|
|
1265
|
+
cellsAccessor.handle.removeListener("change", handleCellsUpdate);
|
|
1266
|
+
unsubscribe();
|
|
1267
|
+
};
|
|
1268
|
+
}, [
|
|
1269
|
+
model,
|
|
1270
|
+
dxGrid
|
|
1271
|
+
]);
|
|
1272
|
+
useEffect3(() => {
|
|
1273
|
+
const columnMetaAccessor = createDocAccessor(model.sheet, [
|
|
1274
|
+
"columnMeta"
|
|
1275
|
+
]);
|
|
1276
|
+
const rowMetaAccessor = createDocAccessor(model.sheet, [
|
|
1277
|
+
"rowMeta"
|
|
1278
|
+
]);
|
|
1279
|
+
const handleColumnMetaUpdate = () => {
|
|
1280
|
+
setColumns(createDxGridColumns(model));
|
|
1281
|
+
};
|
|
1282
|
+
const handleRowMetaUpdate = () => {
|
|
1283
|
+
setRows(createDxGridRows(model));
|
|
1284
|
+
};
|
|
1285
|
+
columnMetaAccessor.handle.addListener("change", handleColumnMetaUpdate);
|
|
1286
|
+
rowMetaAccessor.handle.addListener("change", handleRowMetaUpdate);
|
|
1287
|
+
return () => {
|
|
1288
|
+
columnMetaAccessor.handle.removeListener("change", handleColumnMetaUpdate);
|
|
1289
|
+
rowMetaAccessor.handle.removeListener("change", handleRowMetaUpdate);
|
|
1290
|
+
};
|
|
1291
|
+
}, [
|
|
1292
|
+
model,
|
|
1293
|
+
dxGrid
|
|
1294
|
+
]);
|
|
1295
|
+
return {
|
|
1296
|
+
columns,
|
|
1297
|
+
rows
|
|
1298
|
+
};
|
|
1299
|
+
};
|
|
1300
|
+
|
|
1301
|
+
// packages/plugins/plugin-sheet/src/components/GridSheet/GridSheet.tsx
|
|
1302
|
+
var inertPosition = {
|
|
1303
|
+
plane: "grid",
|
|
1304
|
+
col: 0,
|
|
1305
|
+
row: 0
|
|
1306
|
+
};
|
|
1307
|
+
var initialCells = {
|
|
1308
|
+
grid: {},
|
|
1309
|
+
frozenColsStart: [
|
|
1310
|
+
...Array(64)
|
|
1311
|
+
].reduce((acc, _, i) => {
|
|
1312
|
+
acc[`0,${i}`] = rowLabelCell(i);
|
|
1313
|
+
return acc;
|
|
1314
|
+
}, {}),
|
|
1315
|
+
frozenRowsStart: [
|
|
1316
|
+
...Array(12)
|
|
1317
|
+
].reduce((acc, _, i) => {
|
|
1318
|
+
acc[`${i},0`] = colLabelCell(i);
|
|
1319
|
+
return acc;
|
|
1320
|
+
}, {})
|
|
1321
|
+
};
|
|
1322
|
+
var frozen = {
|
|
1323
|
+
frozenColsStart: 1,
|
|
1324
|
+
frozenRowsStart: 1
|
|
1325
|
+
};
|
|
1326
|
+
var sheetRowDefault = {
|
|
1327
|
+
frozenRowsStart: {
|
|
1328
|
+
size: 32,
|
|
1329
|
+
readonly: true
|
|
1330
|
+
},
|
|
1331
|
+
grid: {
|
|
1332
|
+
size: 32,
|
|
1333
|
+
resizeable: true
|
|
1334
|
+
}
|
|
1335
|
+
};
|
|
1336
|
+
var sheetColDefault = {
|
|
1337
|
+
frozenColsStart: {
|
|
1338
|
+
size: 48,
|
|
1339
|
+
readonly: true
|
|
1340
|
+
},
|
|
1341
|
+
grid: {
|
|
1342
|
+
size: 180,
|
|
1343
|
+
resizeable: true
|
|
1344
|
+
}
|
|
1345
|
+
};
|
|
1346
|
+
var GridSheet = () => {
|
|
1347
|
+
const { t } = useTranslation2(SHEET_PLUGIN);
|
|
1348
|
+
const { id, model, editing, setEditing, setCursor, setRange, cursor, cursorFallbackRange, activeRefs } = useSheetContext();
|
|
1349
|
+
const [dxGrid, setDxGrid] = useState4(null);
|
|
1350
|
+
const [extraplanarFocus, setExtraplanarFocus] = useState4(null);
|
|
1351
|
+
const dispatch = useIntentDispatcher2();
|
|
1352
|
+
const rangeController = useRef();
|
|
1353
|
+
const { hasAttention } = useAttention(id);
|
|
1354
|
+
const handleFocus = useCallback4((event) => {
|
|
1355
|
+
if (!editing) {
|
|
1356
|
+
const cell = closestCell(event.target);
|
|
1357
|
+
if (cell) {
|
|
1358
|
+
if (cell.plane === "grid") {
|
|
1359
|
+
setCursor({
|
|
1360
|
+
col: cell.col,
|
|
1361
|
+
row: cell.row
|
|
1362
|
+
});
|
|
1363
|
+
setExtraplanarFocus(null);
|
|
1364
|
+
} else {
|
|
1365
|
+
setExtraplanarFocus(cell);
|
|
1366
|
+
}
|
|
1367
|
+
} else {
|
|
1368
|
+
setExtraplanarFocus(null);
|
|
1369
|
+
}
|
|
1370
|
+
}
|
|
1371
|
+
}, [
|
|
1372
|
+
editing
|
|
1373
|
+
]);
|
|
1374
|
+
const handleClose = useCallback4((value, { key, shift }) => {
|
|
1375
|
+
if (value !== void 0) {
|
|
1376
|
+
model.setValue(dxGridCellIndexToSheetCellAddress(editing.index), value);
|
|
1377
|
+
}
|
|
1378
|
+
setEditing(null);
|
|
1379
|
+
const axis = [
|
|
1380
|
+
"Enter",
|
|
1381
|
+
"ArrowUp",
|
|
1382
|
+
"ArrowDown"
|
|
1383
|
+
].includes(key) ? "row" : [
|
|
1384
|
+
"Tab",
|
|
1385
|
+
"ArrowLeft",
|
|
1386
|
+
"ArrowRight"
|
|
1387
|
+
].includes(key) ? "col" : void 0;
|
|
1388
|
+
const delta = key.startsWith("Arrow") ? [
|
|
1389
|
+
"ArrowUp",
|
|
1390
|
+
"ArrowLeft"
|
|
1391
|
+
].includes(key) ? -1 : 1 : shift ? -1 : 1;
|
|
1392
|
+
dxGrid?.refocus(axis, delta);
|
|
1393
|
+
}, [
|
|
1394
|
+
model,
|
|
1395
|
+
editing,
|
|
1396
|
+
dxGrid
|
|
1397
|
+
]);
|
|
1398
|
+
const handleBlur = useCallback4((value) => {
|
|
1399
|
+
if (value !== void 0) {
|
|
1400
|
+
model.setValue(dxGridCellIndexToSheetCellAddress(editing.index), value);
|
|
1401
|
+
}
|
|
1402
|
+
setEditing(null);
|
|
1403
|
+
}, [
|
|
1404
|
+
model,
|
|
1405
|
+
editing
|
|
1406
|
+
]);
|
|
1407
|
+
const handleAxisResize = useCallback4(({ axis, size, index: numericIndex }) => {
|
|
1408
|
+
if (axis === "row") {
|
|
1409
|
+
const rowId = model.sheet.rows[parseInt(numericIndex)];
|
|
1410
|
+
model.sheet.rowMeta[rowId] ??= {};
|
|
1411
|
+
model.sheet.rowMeta[rowId].size = size;
|
|
1412
|
+
} else {
|
|
1413
|
+
const columnId = model.sheet.columns[parseInt(numericIndex)];
|
|
1414
|
+
model.sheet.columnMeta[columnId] ??= {};
|
|
1415
|
+
model.sheet.columnMeta[columnId].size = size;
|
|
1416
|
+
}
|
|
1417
|
+
}, [
|
|
1418
|
+
model
|
|
1419
|
+
]);
|
|
1420
|
+
const handleSelect = useCallback4(({ minCol, maxCol, minRow, maxRow }) => {
|
|
1421
|
+
const range = {
|
|
1422
|
+
from: {
|
|
1423
|
+
col: minCol,
|
|
1424
|
+
row: minRow
|
|
1425
|
+
}
|
|
1426
|
+
};
|
|
1427
|
+
if (minCol !== maxCol || minRow !== maxRow) {
|
|
1428
|
+
range.to = {
|
|
1429
|
+
col: maxCol,
|
|
1430
|
+
row: maxRow
|
|
1431
|
+
};
|
|
1432
|
+
}
|
|
1433
|
+
if (editing) {
|
|
1434
|
+
rangeController.current?.setRange(rangeToA1Notation(range));
|
|
1435
|
+
} else {
|
|
1436
|
+
setRange(range.to ? range : void 0);
|
|
1437
|
+
}
|
|
1438
|
+
}, [
|
|
1439
|
+
editing
|
|
1440
|
+
]);
|
|
1441
|
+
const handleWheel = useCallback4((event) => {
|
|
1442
|
+
if (!hasAttention) {
|
|
1443
|
+
event.stopPropagation();
|
|
1444
|
+
}
|
|
1445
|
+
}, [
|
|
1446
|
+
hasAttention
|
|
1447
|
+
]);
|
|
1448
|
+
const selectEntireAxis = useCallback4((pos) => {
|
|
1449
|
+
switch (pos.plane) {
|
|
1450
|
+
case "frozenRowsStart":
|
|
1451
|
+
return dxGrid?.setSelection({
|
|
1452
|
+
start: {
|
|
1453
|
+
col: pos.col,
|
|
1454
|
+
row: 0,
|
|
1455
|
+
plane: "grid"
|
|
1456
|
+
},
|
|
1457
|
+
end: {
|
|
1458
|
+
col: pos.col,
|
|
1459
|
+
row: model.sheet.rows.length - 1,
|
|
1460
|
+
plane: "grid"
|
|
1461
|
+
}
|
|
1462
|
+
});
|
|
1463
|
+
case "frozenColsStart":
|
|
1464
|
+
return dxGrid?.setSelection({
|
|
1465
|
+
start: {
|
|
1466
|
+
row: pos.row,
|
|
1467
|
+
col: 0,
|
|
1468
|
+
plane: "grid"
|
|
1469
|
+
},
|
|
1470
|
+
end: {
|
|
1471
|
+
row: pos.row,
|
|
1472
|
+
col: model.sheet.columns.length - 1,
|
|
1473
|
+
plane: "grid"
|
|
1474
|
+
}
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
}, [
|
|
1478
|
+
dxGrid,
|
|
1479
|
+
model.sheet
|
|
1480
|
+
]);
|
|
1481
|
+
const handleClick = useCallback4((event) => {
|
|
1482
|
+
const cell = closestCell(event.target);
|
|
1483
|
+
if (cell) {
|
|
1484
|
+
selectEntireAxis(cell);
|
|
1485
|
+
}
|
|
1486
|
+
}, [
|
|
1487
|
+
selectEntireAxis
|
|
1488
|
+
]);
|
|
1489
|
+
const handleKeyDown = useCallback4((event) => {
|
|
1490
|
+
switch (event.key) {
|
|
1491
|
+
case "Backspace":
|
|
1492
|
+
case "Delete":
|
|
1493
|
+
event.preventDefault();
|
|
1494
|
+
return cursorFallbackRange && model.clear(cursorFallbackRange);
|
|
1495
|
+
case "Enter":
|
|
1496
|
+
case "Space":
|
|
1497
|
+
if (dxGrid && extraplanarFocus) {
|
|
1498
|
+
switch (extraplanarFocus.plane) {
|
|
1499
|
+
case "frozenRowsStart":
|
|
1500
|
+
case "frozenColsStart":
|
|
1501
|
+
event.preventDefault();
|
|
1502
|
+
return selectEntireAxis(extraplanarFocus);
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
if (event.metaKey || event.ctrlKey) {
|
|
1507
|
+
switch (event.key) {
|
|
1508
|
+
case "x":
|
|
1509
|
+
case "X":
|
|
1510
|
+
event.preventDefault();
|
|
1511
|
+
return cursorFallbackRange && model.cut(cursorFallbackRange);
|
|
1512
|
+
case "c":
|
|
1513
|
+
case "C":
|
|
1514
|
+
event.preventDefault();
|
|
1515
|
+
return cursorFallbackRange && model.copy(cursorFallbackRange);
|
|
1516
|
+
case "v":
|
|
1517
|
+
case "V":
|
|
1518
|
+
event.preventDefault();
|
|
1519
|
+
return cursor && model.paste(cursor);
|
|
1520
|
+
case "z":
|
|
1521
|
+
event.preventDefault();
|
|
1522
|
+
return event.shiftKey ? model.redo() : model.undo();
|
|
1523
|
+
case "Z":
|
|
1524
|
+
case "y":
|
|
1525
|
+
event.preventDefault();
|
|
1526
|
+
return model.redo();
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
}, [
|
|
1530
|
+
cursorFallbackRange,
|
|
1531
|
+
model,
|
|
1532
|
+
cursor,
|
|
1533
|
+
extraplanarFocus,
|
|
1534
|
+
selectEntireAxis
|
|
1535
|
+
]);
|
|
1536
|
+
const contextMenuAnchorRef = useRef(null);
|
|
1537
|
+
const [contextMenuOpen, setContextMenuOpen] = useState4(null);
|
|
1538
|
+
const contextMenuAxis = contextMenuOpen?.plane.startsWith("frozenRows") ? "col" : "row";
|
|
1539
|
+
const handleContextMenu = useCallback4((event) => {
|
|
1540
|
+
const cell = closestCell(event.target);
|
|
1541
|
+
if (cell && cell.plane.startsWith("frozen")) {
|
|
1542
|
+
event.preventDefault();
|
|
1543
|
+
contextMenuAnchorRef.current = event.target;
|
|
1544
|
+
setContextMenuOpen(cell);
|
|
1545
|
+
}
|
|
1546
|
+
}, []);
|
|
1547
|
+
const handleAxisMenuAction = useCallback4((operation) => {
|
|
1548
|
+
switch (operation) {
|
|
1549
|
+
case "insert-before":
|
|
1550
|
+
case "insert-after":
|
|
1551
|
+
return dispatch({
|
|
1552
|
+
action: SheetAction.INSERT_AXIS,
|
|
1553
|
+
data: {
|
|
1554
|
+
model,
|
|
1555
|
+
axis: contextMenuAxis,
|
|
1556
|
+
index: contextMenuOpen[contextMenuAxis] + (operation === "insert-before" ? 0 : 1)
|
|
1557
|
+
}
|
|
1558
|
+
});
|
|
1559
|
+
break;
|
|
1560
|
+
case "drop":
|
|
1561
|
+
return dispatch({
|
|
1562
|
+
action: SheetAction.DROP_AXIS,
|
|
1563
|
+
data: {
|
|
1564
|
+
model,
|
|
1565
|
+
axis: contextMenuAxis,
|
|
1566
|
+
axisIndex: model.sheet[contextMenuAxis === "row" ? "rows" : "columns"][contextMenuOpen[contextMenuAxis]]
|
|
1567
|
+
}
|
|
1568
|
+
});
|
|
1569
|
+
}
|
|
1570
|
+
}, [
|
|
1571
|
+
contextMenuAxis,
|
|
1572
|
+
contextMenuOpen,
|
|
1573
|
+
model,
|
|
1574
|
+
dispatch
|
|
1575
|
+
]);
|
|
1576
|
+
const { columns, rows } = useSheetModelDxGridProps(dxGrid, model);
|
|
1577
|
+
const extension = useMemo2(() => [
|
|
1578
|
+
editorKeys({
|
|
1579
|
+
onClose: handleClose,
|
|
1580
|
+
...editing?.initialContent && {
|
|
1581
|
+
onNav: handleClose
|
|
1582
|
+
}
|
|
1583
|
+
}),
|
|
1584
|
+
sheetExtension({
|
|
1585
|
+
functions: model.graph.getFunctions()
|
|
1586
|
+
}),
|
|
1587
|
+
rangeExtension({
|
|
1588
|
+
onInit: (fn) => rangeController.current = fn,
|
|
1589
|
+
onStateChange: (state) => {
|
|
1590
|
+
if (dxGrid) {
|
|
1591
|
+
dxGrid.mode = typeof state.activeRange === "undefined" ? "edit" : "edit-select";
|
|
1592
|
+
}
|
|
1593
|
+
}
|
|
1594
|
+
})
|
|
1595
|
+
], [
|
|
1596
|
+
model,
|
|
1597
|
+
handleClose,
|
|
1598
|
+
editing
|
|
1599
|
+
]);
|
|
1600
|
+
const getCellContent = useCallback4((index) => {
|
|
1601
|
+
const cell = dxGridCellIndexToSheetCellAddress(index);
|
|
1602
|
+
return model.getCellText(cell);
|
|
1603
|
+
}, [
|
|
1604
|
+
model
|
|
1605
|
+
]);
|
|
1606
|
+
useUpdateFocusedCellOnThreadSelection(dxGrid);
|
|
1607
|
+
useSelectThreadOnCellFocus();
|
|
1608
|
+
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(GridCellEditor, {
|
|
1609
|
+
getCellContent,
|
|
1610
|
+
extension,
|
|
1611
|
+
onBlur: handleBlur
|
|
1612
|
+
}), /* @__PURE__ */ React4.createElement(Grid2.Content, {
|
|
1613
|
+
initialCells,
|
|
1614
|
+
limitColumns: DEFAULT_COLUMNS,
|
|
1615
|
+
limitRows: DEFAULT_ROWS,
|
|
1616
|
+
columns,
|
|
1617
|
+
rows,
|
|
1618
|
+
onAxisResize: handleAxisResize,
|
|
1619
|
+
onSelect: handleSelect,
|
|
1620
|
+
rowDefault: sheetRowDefault,
|
|
1621
|
+
columnDefault: sheetColDefault,
|
|
1622
|
+
frozen,
|
|
1623
|
+
onFocus: handleFocus,
|
|
1624
|
+
onWheelCapture: handleWheel,
|
|
1625
|
+
onKeyDown: handleKeyDown,
|
|
1626
|
+
onContextMenu: handleContextMenu,
|
|
1627
|
+
onClick: handleClick,
|
|
1628
|
+
overscroll: "inline",
|
|
1629
|
+
className: "[--dx-grid-base:var(--surface-bg)]",
|
|
1630
|
+
activeRefs,
|
|
1631
|
+
ref: setDxGrid
|
|
1632
|
+
}), /* @__PURE__ */ React4.createElement(DropdownMenu.Root, {
|
|
1633
|
+
modal: false,
|
|
1634
|
+
open: !!contextMenuOpen,
|
|
1635
|
+
onOpenChange: (nextOpen) => setContextMenuOpen(nextOpen ? inertPosition : null)
|
|
1636
|
+
}, /* @__PURE__ */ React4.createElement(DropdownMenu.VirtualTrigger, {
|
|
1637
|
+
virtualRef: contextMenuAnchorRef
|
|
1638
|
+
}), /* @__PURE__ */ React4.createElement(DropdownMenu.Content, {
|
|
1639
|
+
side: contextMenuAxis === "col" ? "bottom" : "right",
|
|
1640
|
+
sideOffset: 4,
|
|
1641
|
+
collisionPadding: 8
|
|
1642
|
+
}, /* @__PURE__ */ React4.createElement(DropdownMenu.Viewport, null, /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
|
|
1643
|
+
onClick: () => handleAxisMenuAction("insert-before")
|
|
1644
|
+
}, /* @__PURE__ */ React4.createElement(Icon, {
|
|
1645
|
+
size: 5,
|
|
1646
|
+
icon: contextMenuAxis === "col" ? "ph--columns-plus-left--regular" : "ph--rows-plus-top--regular"
|
|
1647
|
+
}), /* @__PURE__ */ React4.createElement("span", null, t(`add ${contextMenuAxis} before label`))), /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
|
|
1648
|
+
onClick: () => handleAxisMenuAction("insert-after")
|
|
1649
|
+
}, /* @__PURE__ */ React4.createElement(Icon, {
|
|
1650
|
+
size: 5,
|
|
1651
|
+
icon: contextMenuAxis === "col" ? "ph--columns-plus-right--regular" : "ph--rows-plus-bottom--regular"
|
|
1652
|
+
}), /* @__PURE__ */ React4.createElement("span", null, t(`add ${contextMenuAxis} after label`))), /* @__PURE__ */ React4.createElement(DropdownMenu.Item, {
|
|
1653
|
+
onClick: () => handleAxisMenuAction("drop")
|
|
1654
|
+
}, /* @__PURE__ */ React4.createElement(Icon, {
|
|
1655
|
+
size: 5,
|
|
1656
|
+
icon: "ph--backspace--regular"
|
|
1657
|
+
}), /* @__PURE__ */ React4.createElement("span", null, t(`delete ${contextMenuAxis} label`)))), /* @__PURE__ */ React4.createElement(DropdownMenu.Arrow, null))));
|
|
1658
|
+
};
|
|
1659
|
+
|
|
1660
|
+
export {
|
|
1661
|
+
ComputeGraphContextProvider,
|
|
1662
|
+
useComputeGraph,
|
|
1663
|
+
completeCellRangeToThreadCursor,
|
|
1664
|
+
computeGraphFacet,
|
|
1665
|
+
useSheetContext,
|
|
1666
|
+
SheetProvider,
|
|
1667
|
+
GridSheet,
|
|
1668
|
+
RangeList,
|
|
1669
|
+
SheetContainer
|
|
1670
|
+
};
|
|
1671
|
+
//# sourceMappingURL=chunk-G2FUL6PK.mjs.map
|