@dxos/plugin-sheet 0.6.13 → 0.6.14-main.7bd9c89
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-AKWROARP.mjs +290 -0
- package/dist/lib/browser/SheetContainer-AKWROARP.mjs.map +7 -0
- package/dist/lib/browser/chunk-BWN5DZWZ.mjs +74 -0
- package/dist/lib/browser/chunk-BWN5DZWZ.mjs.map +7 -0
- package/dist/lib/browser/chunk-D3QTX46O.mjs +14 -0
- package/dist/lib/browser/chunk-D3QTX46O.mjs.map +7 -0
- package/dist/lib/browser/chunk-FGMFOW6U.mjs +1570 -0
- package/dist/lib/browser/chunk-FGMFOW6U.mjs.map +7 -0
- package/dist/lib/browser/chunk-GSV5QNLD.mjs +2966 -0
- package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +7 -0
- package/dist/lib/browser/graph-M4IQ76QX.mjs +33 -0
- package/dist/lib/browser/graph-M4IQ76QX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +93 -62
- 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/types.mjs +6 -12
- package/dist/lib/node/SheetContainer-N5IQGEFL.cjs +300 -0
- package/dist/lib/node/SheetContainer-N5IQGEFL.cjs.map +7 -0
- package/dist/lib/node/chunk-53BMSUIK.cjs +1569 -0
- package/dist/lib/node/chunk-53BMSUIK.cjs.map +7 -0
- package/dist/lib/node/{chunk-5KKJ4NPP.cjs → chunk-5XPK2V4A.cjs} +418 -678
- package/dist/lib/node/chunk-5XPK2V4A.cjs.map +7 -0
- package/dist/lib/node/{chunk-DSYKOI4E.cjs → chunk-NZARD7UP.cjs} +40 -51
- package/dist/lib/node/chunk-NZARD7UP.cjs.map +7 -0
- package/dist/lib/node/chunk-QIFIGEKV.cjs +37 -0
- package/dist/lib/node/chunk-QIFIGEKV.cjs.map +7 -0
- package/dist/lib/node/graph-Q3N2X26H.cjs +55 -0
- package/dist/lib/node/graph-Q3N2X26H.cjs.map +7 -0
- package/dist/lib/node/index.cjs +105 -69
- 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/types.cjs +9 -15
- package/dist/lib/node/types.cjs.map +2 -2
- package/dist/lib/node-esm/SheetContainer-46PBMF2E.mjs +291 -0
- package/dist/lib/node-esm/SheetContainer-46PBMF2E.mjs.map +7 -0
- package/dist/lib/{browser/chunk-D5AGLXJP.mjs → node-esm/chunk-5WPZCXNS.mjs} +411 -678
- package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-T3PRH7QS.mjs +1571 -0
- package/dist/lib/node-esm/chunk-T3PRH7QS.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-VCYJWE3O.mjs +16 -0
- package/dist/lib/node-esm/chunk-VCYJWE3O.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-WFDTY3IC.mjs +75 -0
- package/dist/lib/node-esm/chunk-WFDTY3IC.mjs.map +7 -0
- package/dist/lib/node-esm/graph-SMPUMOV2.mjs +34 -0
- package/dist/lib/node-esm/graph-SMPUMOV2.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +280 -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 +11 -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 +16 -0
- package/dist/types/src/components/GridSheet/util.d.ts.map +1 -0
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +6 -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 +26 -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 +33 -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 +4 -4
- package/dist/types/src/components/index.d.ts.map +1 -1
- 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/{model → defs}/types.d.ts +8 -3
- 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 +43 -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/{components/CellEditor → extensions/editor}/extension.d.ts +1 -1
- 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/graph/compute-graph-registry.d.ts +34 -0
- package/dist/types/src/graph/compute-graph-registry.d.ts.map +1 -0
- package/dist/types/src/graph/compute-graph.d.ts +64 -0
- package/dist/types/src/graph/compute-graph.d.ts.map +1 -0
- package/dist/types/src/graph/compute-graph.stories.d.ts +6 -0
- package/dist/types/src/graph/compute-graph.stories.d.ts.map +1 -0
- package/dist/types/src/graph/compute-graph.test.d.ts +2 -0
- package/dist/types/src/graph/compute-graph.test.d.ts.map +1 -0
- package/dist/types/src/graph/compute-node.d.ts +26 -0
- package/dist/types/src/graph/compute-node.d.ts.map +1 -0
- package/dist/types/src/{components/ComputeGraph → graph/functions}/async-function.d.ts +14 -5
- package/dist/types/src/graph/functions/async-function.d.ts.map +1 -0
- package/dist/types/src/graph/functions/edge-function.d.ts +21 -0
- package/dist/types/src/graph/functions/edge-function.d.ts.map +1 -0
- package/dist/types/src/{model/functions.d.ts → graph/functions/function-defs.d.ts} +1 -1
- package/dist/types/src/graph/functions/function-defs.d.ts.map +1 -0
- package/dist/types/src/graph/functions/index.d.ts +4 -0
- package/dist/types/src/graph/functions/index.d.ts.map +1 -0
- package/dist/types/src/graph/hyperformula.test.d.ts +2 -0
- package/dist/types/src/graph/hyperformula.test.d.ts.map +1 -0
- package/dist/types/src/graph/index.d.ts +5 -0
- package/dist/types/src/graph/index.d.ts.map +1 -0
- package/dist/types/src/graph/testing/index.d.ts +3 -0
- package/dist/types/src/graph/testing/index.d.ts.map +1 -0
- package/dist/types/src/graph/testing/test-builder.d.ts +15 -0
- package/dist/types/src/graph/testing/test-builder.d.ts.map +1 -0
- package/dist/types/src/graph/testing/test-plugin.d.ts +36 -0
- package/dist/types/src/graph/testing/test-plugin.d.ts.map +1 -0
- package/dist/types/src/graph/util.d.ts +2 -0
- package/dist/types/src/graph/util.d.ts.map +1 -0
- package/dist/types/src/hooks/hooks.stories.d.ts +6 -0
- package/dist/types/src/hooks/hooks.stories.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +4 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/threads.d.ts +8 -0
- package/dist/types/src/hooks/threads.d.ts.map +1 -0
- package/dist/types/src/hooks/useComputeGraph.d.ts +7 -0
- package/dist/types/src/hooks/useComputeGraph.d.ts.map +1 -0
- package/dist/types/src/hooks/useSheetModel.d.ts +8 -0
- package/dist/types/src/hooks/useSheetModel.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +3 -9
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/model/decorations.d.ts +26 -0
- package/dist/types/src/model/decorations.d.ts.map +1 -0
- 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} +13 -67
- 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/sanity.test.d.ts +2 -0
- package/dist/types/src/sanity.test.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 +17 -12
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +125 -40
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/vendor/hyperformula.mjs +37145 -0
- package/package.json +58 -52
- package/src/SheetPlugin.tsx +52 -74
- package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +20 -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 +44 -0
- package/src/components/GridSheet/GridSheet.tsx +201 -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 +154 -0
- package/src/components/SheetContainer/SheetContainer.stories.tsx +43 -0
- package/src/components/SheetContainer/SheetContainer.tsx +27 -0
- package/src/components/SheetContainer/index.ts +7 -0
- package/src/components/SheetContext/SheetContext.tsx +104 -0
- package/src/components/SheetContext/index.ts +5 -0
- package/src/components/Toolbar/Toolbar.stories.tsx +9 -6
- package/src/components/Toolbar/Toolbar.tsx +242 -112
- package/src/components/index.ts +4 -3
- package/src/defs/index.ts +7 -0
- package/src/defs/sheet-range-types.ts +46 -0
- package/src/{model → defs}/types.test.ts +8 -9
- package/src/{model → defs}/types.ts +24 -14
- package/src/defs/util.ts +151 -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 +5 -6
- package/src/{components/CellEditor → extensions/editor}/index.ts +0 -1
- package/src/extensions/index.ts +6 -0
- package/src/graph/compute-graph-registry.ts +90 -0
- package/src/graph/compute-graph.stories.tsx +96 -0
- package/src/graph/compute-graph.test.ts +87 -0
- package/src/graph/compute-graph.ts +242 -0
- package/src/graph/compute-node.ts +63 -0
- package/src/{components/ComputeGraph → graph/functions}/async-function.ts +25 -15
- package/src/{components/ComputeGraph → graph/functions}/edge-function.ts +16 -14
- package/src/graph/functions/index.ts +7 -0
- package/src/graph/hyperformula.test.ts +14 -0
- package/src/graph/index.ts +8 -0
- package/src/graph/testing/index.ts +6 -0
- package/src/graph/testing/test-builder.ts +54 -0
- package/src/{components/ComputeGraph/custom.ts → graph/testing/test-plugin.ts} +44 -14
- package/src/graph/util.ts +8 -0
- package/src/hooks/hooks.stories.tsx +53 -0
- package/src/hooks/index.ts +7 -0
- package/src/hooks/threads.ts +147 -0
- package/src/hooks/useComputeGraph.ts +28 -0
- package/src/hooks/useSheetModel.ts +40 -0
- package/src/meta.ts +14 -0
- package/src/model/decorations.ts +66 -0
- package/src/model/index.ts +2 -3
- package/src/model/sheet-model.test.ts +57 -0
- package/src/model/sheet-model.ts +418 -0
- package/src/sanity.test.ts +40 -0
- package/src/{components/Sheet → testing}/index.ts +1 -1
- package/src/testing/testing.tsx +68 -0
- package/src/translations.ts +6 -1
- package/src/types.ts +40 -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.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.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/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 → graph/functions/function-defs.ts} +0 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { useCallback, useMemo, useRef, type FocusEvent, type WheelEvent, type KeyboardEvent } from 'react';
|
|
6
|
+
|
|
7
|
+
import { useAttention } from '@dxos/react-ui-attention';
|
|
8
|
+
import {
|
|
9
|
+
type DxGridElement,
|
|
10
|
+
Grid,
|
|
11
|
+
type GridContentProps,
|
|
12
|
+
editorKeys,
|
|
13
|
+
type EditorKeysProps,
|
|
14
|
+
GridCellEditor,
|
|
15
|
+
closestCell,
|
|
16
|
+
} from '@dxos/react-ui-grid';
|
|
17
|
+
|
|
18
|
+
import { colLabelCell, dxGridCellIndexToSheetCellAddress, rowLabelCell, useSheetModelDxGridProps } from './util';
|
|
19
|
+
import { rangeToA1Notation, type CellRange, DEFAULT_COLUMNS, DEFAULT_ROWS } from '../../defs';
|
|
20
|
+
import { rangeExtension, sheetExtension, type CellRangeNotifier } from '../../extensions';
|
|
21
|
+
import { useUpdateFocusedCellOnThreadSelection } from '../../hooks';
|
|
22
|
+
import { useSheetContext } from '../SheetContext';
|
|
23
|
+
|
|
24
|
+
const initialCells = {
|
|
25
|
+
grid: {},
|
|
26
|
+
frozenColsStart: [...Array(64)].reduce((acc, _, i) => {
|
|
27
|
+
acc[`0,${i}`] = rowLabelCell(i);
|
|
28
|
+
return acc;
|
|
29
|
+
}, {}),
|
|
30
|
+
frozenRowsStart: [...Array(12)].reduce((acc, _, i) => {
|
|
31
|
+
acc[`${i},0`] = colLabelCell(i);
|
|
32
|
+
return acc;
|
|
33
|
+
}, {}),
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const frozen = {
|
|
37
|
+
frozenColsStart: 1,
|
|
38
|
+
frozenRowsStart: 1,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const sheetRowDefault = { frozenRowsStart: { size: 32, readonly: true }, grid: { size: 32, resizeable: true } };
|
|
42
|
+
const sheetColDefault = { frozenColsStart: { size: 48, readonly: true }, grid: { size: 180, resizeable: true } };
|
|
43
|
+
|
|
44
|
+
export const GridSheet = () => {
|
|
45
|
+
const { id, model, editing, setEditing, setCursor, setRange, range, cursor } = useSheetContext();
|
|
46
|
+
const dxGrid = useRef<DxGridElement | null>(null);
|
|
47
|
+
const rangeNotifier = useRef<CellRangeNotifier>();
|
|
48
|
+
const { hasAttention } = useAttention(id);
|
|
49
|
+
|
|
50
|
+
const handleFocus = useCallback(
|
|
51
|
+
(event: FocusEvent) => {
|
|
52
|
+
if (!editing) {
|
|
53
|
+
const cell = closestCell(event.target);
|
|
54
|
+
if (cell && cell.plane === 'grid') {
|
|
55
|
+
setCursor({ col: cell.col, row: cell.row });
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
[editing],
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// TODO(burdon): Validate formula before closing: hf.validateFormula();
|
|
63
|
+
const handleClose = useCallback<NonNullable<EditorKeysProps['onClose']> | NonNullable<EditorKeysProps['onNav']>>(
|
|
64
|
+
(value, { key, shift }) => {
|
|
65
|
+
if (value !== undefined) {
|
|
66
|
+
model.setValue(dxGridCellIndexToSheetCellAddress(editing!.index), value);
|
|
67
|
+
}
|
|
68
|
+
setEditing(null);
|
|
69
|
+
const axis = ['Enter', 'ArrowUp', 'ArrowDown'].includes(key)
|
|
70
|
+
? 'row'
|
|
71
|
+
: ['Tab', 'ArrowLeft', 'ArrowRight'].includes(key)
|
|
72
|
+
? 'col'
|
|
73
|
+
: undefined;
|
|
74
|
+
const delta = key.startsWith('Arrow') ? (['ArrowUp', 'ArrowLeft'].includes(key) ? -1 : 1) : shift ? -1 : 1;
|
|
75
|
+
dxGrid.current?.refocus(axis, delta);
|
|
76
|
+
},
|
|
77
|
+
[model, editing, setEditing],
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
const handleAxisResize = useCallback<NonNullable<GridContentProps['onAxisResize']>>(
|
|
81
|
+
({ axis, size, index: numericIndex }) => {
|
|
82
|
+
if (axis === 'row') {
|
|
83
|
+
const rowId = model.sheet.rows[parseInt(numericIndex)];
|
|
84
|
+
model.sheet.rowMeta[rowId] ??= {};
|
|
85
|
+
model.sheet.rowMeta[rowId].size = size;
|
|
86
|
+
} else {
|
|
87
|
+
const columnId = model.sheet.columns[parseInt(numericIndex)];
|
|
88
|
+
model.sheet.columnMeta[columnId] ??= {};
|
|
89
|
+
model.sheet.columnMeta[columnId].size = size;
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
[model],
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
const handleSelect = useCallback<NonNullable<GridContentProps['onSelect']>>(
|
|
96
|
+
({ minCol, maxCol, minRow, maxRow }) => {
|
|
97
|
+
const range: CellRange = { from: { col: minCol, row: minRow } };
|
|
98
|
+
if (minCol !== maxCol || minRow !== maxRow) {
|
|
99
|
+
range.to = { col: maxCol, row: maxRow };
|
|
100
|
+
}
|
|
101
|
+
if (editing) {
|
|
102
|
+
// Update range selection in formula.
|
|
103
|
+
rangeNotifier.current?.(rangeToA1Notation(range));
|
|
104
|
+
} else {
|
|
105
|
+
// Setting range while editing causes focus to move to null, avoid doing so.
|
|
106
|
+
setRange(range.to ? range : undefined);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
[editing],
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
const handleWheel = useCallback(
|
|
113
|
+
(event: WheelEvent) => {
|
|
114
|
+
if (!hasAttention) {
|
|
115
|
+
event.stopPropagation();
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
[hasAttention],
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
const handleKeyDown = useCallback(
|
|
122
|
+
(event: KeyboardEvent) => {
|
|
123
|
+
const cursorFallbackRange: CellRange | null = range ?? cursor ? { from: cursor!, to: cursor! } : null;
|
|
124
|
+
switch (event.key) {
|
|
125
|
+
case 'Backspace':
|
|
126
|
+
case 'Delete':
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
return cursorFallbackRange && model.clear(cursorFallbackRange);
|
|
129
|
+
}
|
|
130
|
+
if (event.metaKey || event.ctrlKey) {
|
|
131
|
+
switch (event.key) {
|
|
132
|
+
case 'x':
|
|
133
|
+
case 'X':
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
return cursorFallbackRange && model.cut(cursorFallbackRange);
|
|
136
|
+
case 'c':
|
|
137
|
+
case 'C':
|
|
138
|
+
event.preventDefault();
|
|
139
|
+
return cursorFallbackRange && model.copy(cursorFallbackRange);
|
|
140
|
+
case 'v':
|
|
141
|
+
case 'V':
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
return cursor && model.paste(cursor);
|
|
144
|
+
case 'z':
|
|
145
|
+
event.preventDefault();
|
|
146
|
+
return event.shiftKey ? model.redo() : model.undo();
|
|
147
|
+
case 'Z':
|
|
148
|
+
case 'y':
|
|
149
|
+
event.preventDefault();
|
|
150
|
+
return model.redo();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
[range, model, cursor],
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const { columns, rows } = useSheetModelDxGridProps(dxGrid, model);
|
|
158
|
+
|
|
159
|
+
const extension = useMemo(
|
|
160
|
+
() => [
|
|
161
|
+
editorKeys({ onClose: handleClose, ...(editing?.initialContent && { onNav: handleClose }) }),
|
|
162
|
+
sheetExtension({ functions: model.graph.getFunctions() }),
|
|
163
|
+
rangeExtension((fn) => (rangeNotifier.current = fn)),
|
|
164
|
+
],
|
|
165
|
+
[model, handleClose, editing],
|
|
166
|
+
);
|
|
167
|
+
|
|
168
|
+
const getCellContent = useCallback(
|
|
169
|
+
(index: string) => {
|
|
170
|
+
const cell = dxGridCellIndexToSheetCellAddress(index);
|
|
171
|
+
return model.getCellText(cell);
|
|
172
|
+
},
|
|
173
|
+
[model],
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
useUpdateFocusedCellOnThreadSelection(model, dxGrid);
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<>
|
|
180
|
+
<GridCellEditor getCellContent={getCellContent} extension={extension} />
|
|
181
|
+
<Grid.Content
|
|
182
|
+
initialCells={initialCells}
|
|
183
|
+
limitColumns={DEFAULT_COLUMNS}
|
|
184
|
+
limitRows={DEFAULT_ROWS}
|
|
185
|
+
columns={columns}
|
|
186
|
+
rows={rows}
|
|
187
|
+
onAxisResize={handleAxisResize}
|
|
188
|
+
onSelect={handleSelect}
|
|
189
|
+
rowDefault={sheetRowDefault}
|
|
190
|
+
columnDefault={sheetColDefault}
|
|
191
|
+
frozen={frozen}
|
|
192
|
+
onFocus={handleFocus}
|
|
193
|
+
onWheelCapture={handleWheel}
|
|
194
|
+
onKeyDown={handleKeyDown}
|
|
195
|
+
overscroll='inline'
|
|
196
|
+
className='[--dx-grid-base:var(--surface-bg)]'
|
|
197
|
+
ref={dxGrid}
|
|
198
|
+
/>
|
|
199
|
+
</>
|
|
200
|
+
);
|
|
201
|
+
};
|
package/src/components/{CellEditor/CellEditor.stories.tsx → GridSheet/SheetCellEditor.stories.tsx}
RENAMED
|
@@ -4,25 +4,20 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { type Meta } from '@storybook/react';
|
|
8
8
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
9
9
|
|
|
10
10
|
import { Client } from '@dxos/client';
|
|
11
11
|
import { createDocAccessor, type EchoReactiveObject } from '@dxos/client/echo';
|
|
12
12
|
import { automerge } from '@dxos/react-ui-editor';
|
|
13
|
+
import { CellEditor, type CellEditorProps } from '@dxos/react-ui-grid';
|
|
13
14
|
import { withTheme } from '@dxos/storybook-utils';
|
|
14
15
|
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
export default {
|
|
21
|
-
title: 'plugin-sheet/CellEditor',
|
|
22
|
-
component: CellEditor,
|
|
23
|
-
render: (args: StoryProps) => <Story {...args} />,
|
|
24
|
-
decorators: [withTheme],
|
|
25
|
-
};
|
|
16
|
+
import { HyperFormula } from '#hyperformula';
|
|
17
|
+
import { createSheet } from '../../defs';
|
|
18
|
+
import { sheetExtension } from '../../extensions';
|
|
19
|
+
import { defaultFunctions } from '../../graph';
|
|
20
|
+
import { SheetType } from '../../types';
|
|
26
21
|
|
|
27
22
|
type StoryProps = CellEditorProps;
|
|
28
23
|
|
|
@@ -41,14 +36,13 @@ const AutomergeStory = ({ value, ...props }: StoryProps) => {
|
|
|
41
36
|
const [object, setObject] = useState<EchoReactiveObject<SheetType>>();
|
|
42
37
|
useEffect(() => {
|
|
43
38
|
setTimeout(async () => {
|
|
44
|
-
const client = new Client();
|
|
39
|
+
const client = new Client({ types: [SheetType] });
|
|
45
40
|
await client.initialize();
|
|
46
41
|
await client.halo.createIdentity();
|
|
47
42
|
const space = await client.spaces.create();
|
|
48
|
-
client.addTypes([SheetType]);
|
|
49
43
|
|
|
50
44
|
const sheet = createSheet();
|
|
51
|
-
sheet.
|
|
45
|
+
sheet.name = 'Test';
|
|
52
46
|
sheet.cells[cell] = { value };
|
|
53
47
|
space.db.add(sheet);
|
|
54
48
|
setObject(sheet);
|
|
@@ -89,3 +83,12 @@ export const Automerge = {
|
|
|
89
83
|
value: '=SUM(A1:A2, 100, TRUE, "100", SUM(A1:A2, B1:B2))',
|
|
90
84
|
},
|
|
91
85
|
};
|
|
86
|
+
|
|
87
|
+
const meta: Meta = {
|
|
88
|
+
title: 'plugins/plugin-sheet/CellEditor',
|
|
89
|
+
component: CellEditor,
|
|
90
|
+
render: (args: StoryProps) => <Story {...args} />,
|
|
91
|
+
decorators: [withTheme],
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export default meta;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type MutableRefObject, useEffect, useLayoutEffect, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { createDocAccessor } from '@dxos/react-client/echo';
|
|
8
|
+
import { parseValue, cellClassesForFieldType } from '@dxos/react-ui-data';
|
|
9
|
+
import {
|
|
10
|
+
type GridContentProps,
|
|
11
|
+
type DxGridElement,
|
|
12
|
+
type DxGridAxisMeta,
|
|
13
|
+
type DxGridPlane,
|
|
14
|
+
type DxGridPlaneRange,
|
|
15
|
+
type DxGridPlaneCells,
|
|
16
|
+
type DxGridCellValue,
|
|
17
|
+
colToA1Notation,
|
|
18
|
+
rowToA1Notation,
|
|
19
|
+
} from '@dxos/react-ui-grid';
|
|
20
|
+
import { mx } from '@dxos/react-ui-theme';
|
|
21
|
+
|
|
22
|
+
import { type CellAddress, inRange, cellClassNameForRange } from '../../defs';
|
|
23
|
+
import { type SheetModel } from '../../model';
|
|
24
|
+
|
|
25
|
+
export const dxGridCellIndexToSheetCellAddress = (index: string): CellAddress => {
|
|
26
|
+
const [colStr, rowStr] = index.split(',');
|
|
27
|
+
return {
|
|
28
|
+
col: parseInt(colStr),
|
|
29
|
+
row: parseInt(rowStr),
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const createDxGridColumns = (model: SheetModel): DxGridAxisMeta => {
|
|
34
|
+
return model.sheet.columns.reduce(
|
|
35
|
+
(acc: DxGridAxisMeta, columnId, numericIndex) => {
|
|
36
|
+
if (model.sheet.columnMeta[columnId] && model.sheet.columnMeta[columnId].size) {
|
|
37
|
+
acc.grid[numericIndex] = { size: model.sheet.columnMeta[columnId].size, resizeable: true };
|
|
38
|
+
}
|
|
39
|
+
return acc;
|
|
40
|
+
},
|
|
41
|
+
{ grid: {} },
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const createDxGridRows = (model: SheetModel): DxGridAxisMeta => {
|
|
46
|
+
return model.sheet.rows.reduce(
|
|
47
|
+
(acc: DxGridAxisMeta, rowId, numericIndex) => {
|
|
48
|
+
if (model.sheet.rowMeta[rowId] && model.sheet.rowMeta[rowId].size) {
|
|
49
|
+
acc.grid[numericIndex] = { size: model.sheet.rowMeta[rowId].size, resizeable: true };
|
|
50
|
+
}
|
|
51
|
+
return acc;
|
|
52
|
+
},
|
|
53
|
+
{ grid: {} },
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const projectCellProps = (model: SheetModel, col: number, row: number): DxGridCellValue => {
|
|
58
|
+
const address = { col, row };
|
|
59
|
+
const rawValue = model.getValue(address);
|
|
60
|
+
if (rawValue === undefined || rawValue === null) {
|
|
61
|
+
return { value: '' };
|
|
62
|
+
}
|
|
63
|
+
const ranges = model.sheet.ranges?.filter(({ range }) => inRange(range, address));
|
|
64
|
+
const type = model.getValueType(address);
|
|
65
|
+
const classNames = ranges?.map(cellClassNameForRange).reverse();
|
|
66
|
+
|
|
67
|
+
return { value: parseValue(type, rawValue), className: mx(cellClassesForFieldType(type), classNames) };
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const gridCellGetter = (model: SheetModel) => {
|
|
71
|
+
// TODO(thure): Actually use the cache.
|
|
72
|
+
const cachedGridCells: DxGridPlaneCells = {};
|
|
73
|
+
return (nextBounds: DxGridPlaneRange): DxGridPlaneCells => {
|
|
74
|
+
[...Array(nextBounds.end.col - nextBounds.start.col)].forEach((_, c0) => {
|
|
75
|
+
return [...Array(nextBounds.end.row - nextBounds.start.row)].forEach((_, r0) => {
|
|
76
|
+
const col = nextBounds.start.col + c0;
|
|
77
|
+
const row = nextBounds.start.row + r0;
|
|
78
|
+
cachedGridCells[`${col},${row}`] = projectCellProps(model, col, row);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
return cachedGridCells;
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export const rowLabelCell = (row: number) => ({
|
|
86
|
+
value: rowToA1Notation(row),
|
|
87
|
+
className: 'text-end !pie-1',
|
|
88
|
+
resizeHandle: 'row',
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
export const colLabelCell = (col: number) => ({ value: colToA1Notation(col), resizeHandle: 'col' });
|
|
92
|
+
|
|
93
|
+
const cellGetter = (model: SheetModel) => {
|
|
94
|
+
const getGridCells = gridCellGetter(model);
|
|
95
|
+
return (nextBounds: DxGridPlaneRange, plane: DxGridPlane): DxGridPlaneCells => {
|
|
96
|
+
switch (plane) {
|
|
97
|
+
case 'grid':
|
|
98
|
+
return getGridCells(nextBounds);
|
|
99
|
+
case 'frozenColsStart':
|
|
100
|
+
return [...Array(nextBounds.end.row - nextBounds.start.row)].reduce((acc, _, r0) => {
|
|
101
|
+
const r = nextBounds.start.row + r0;
|
|
102
|
+
acc[`0,${r}`] = rowLabelCell(r);
|
|
103
|
+
return acc;
|
|
104
|
+
}, {});
|
|
105
|
+
case 'frozenRowsStart':
|
|
106
|
+
return [...Array(nextBounds.end.col - nextBounds.start.col)].reduce((acc, _, c0) => {
|
|
107
|
+
const c = nextBounds.start.col + c0;
|
|
108
|
+
acc[`${c},0`] = colLabelCell(c);
|
|
109
|
+
return acc;
|
|
110
|
+
}, {});
|
|
111
|
+
default:
|
|
112
|
+
return {};
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const useSheetModelDxGridProps = (
|
|
118
|
+
dxGridRef: MutableRefObject<DxGridElement | null>,
|
|
119
|
+
model: SheetModel,
|
|
120
|
+
): Pick<GridContentProps, 'columns' | 'rows'> => {
|
|
121
|
+
const [columns, setColumns] = useState<DxGridAxisMeta>(createDxGridColumns(model));
|
|
122
|
+
const [rows, setRows] = useState<DxGridAxisMeta>(createDxGridColumns(model));
|
|
123
|
+
|
|
124
|
+
useLayoutEffect(() => {
|
|
125
|
+
const cellsAccessor = createDocAccessor(model.sheet, ['cells']);
|
|
126
|
+
if (dxGridRef.current) {
|
|
127
|
+
dxGridRef.current.getCells = cellGetter(model);
|
|
128
|
+
}
|
|
129
|
+
const handleCellsUpdate = () => {
|
|
130
|
+
dxGridRef.current?.requestUpdate('initialCells');
|
|
131
|
+
};
|
|
132
|
+
cellsAccessor.handle.addListener('change', handleCellsUpdate);
|
|
133
|
+
return () => cellsAccessor.handle.removeListener('change', handleCellsUpdate);
|
|
134
|
+
}, [model]);
|
|
135
|
+
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
const columnMetaAccessor = createDocAccessor(model.sheet, ['columnMeta']);
|
|
138
|
+
const rowMetaAccessor = createDocAccessor(model.sheet, ['rowMeta']);
|
|
139
|
+
const handleColumnMetaUpdate = () => {
|
|
140
|
+
setColumns(createDxGridColumns(model));
|
|
141
|
+
};
|
|
142
|
+
const handleRowMetaUpdate = () => {
|
|
143
|
+
setRows(createDxGridRows(model));
|
|
144
|
+
};
|
|
145
|
+
columnMetaAccessor.handle.addListener('change', handleColumnMetaUpdate);
|
|
146
|
+
rowMetaAccessor.handle.addListener('change', handleRowMetaUpdate);
|
|
147
|
+
return () => {
|
|
148
|
+
columnMetaAccessor.handle.removeListener('change', handleColumnMetaUpdate);
|
|
149
|
+
rowMetaAccessor.handle.removeListener('change', handleRowMetaUpdate);
|
|
150
|
+
};
|
|
151
|
+
}, [model]);
|
|
152
|
+
|
|
153
|
+
return { columns, rows };
|
|
154
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Meta } from '@storybook/react';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
import { useSpace } from '@dxos/react-client/echo';
|
|
9
|
+
import { withClientProvider } from '@dxos/react-client/testing';
|
|
10
|
+
import { withTheme, withLayout } from '@dxos/storybook-utils';
|
|
11
|
+
|
|
12
|
+
import { SheetContainer } from './SheetContainer';
|
|
13
|
+
import { useComputeGraph } from '../../hooks';
|
|
14
|
+
import { createTestCells, useTestSheet, withComputeGraphDecorator } from '../../testing';
|
|
15
|
+
import { SheetType } from '../../types';
|
|
16
|
+
|
|
17
|
+
export const Basic = () => {
|
|
18
|
+
const space = useSpace();
|
|
19
|
+
const graph = useComputeGraph(space);
|
|
20
|
+
const sheet = useTestSheet(space, graph, { cells: createTestCells() });
|
|
21
|
+
if (!sheet || !graph) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return <SheetContainer graph={graph} sheet={sheet} role='article' />;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const meta: Meta = {
|
|
29
|
+
title: 'plugins/plugin-sheet/SheetContainer',
|
|
30
|
+
component: SheetContainer,
|
|
31
|
+
decorators: [
|
|
32
|
+
withClientProvider({ types: [SheetType], createSpace: true }),
|
|
33
|
+
withComputeGraphDecorator(),
|
|
34
|
+
withTheme,
|
|
35
|
+
withLayout({
|
|
36
|
+
fullscreen: true,
|
|
37
|
+
tooltips: true,
|
|
38
|
+
classNames: 'grid grid-cols-1 grid-rows-[min-content_minmax(0,1fr)_min-content]',
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default meta;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React from 'react';
|
|
6
|
+
|
|
7
|
+
import { FunctionEditor } from '../FunctionEditor';
|
|
8
|
+
import { GridSheet } from '../GridSheet';
|
|
9
|
+
import { SheetProvider, type SheetProviderProps } from '../SheetContext';
|
|
10
|
+
import { Toolbar } from '../Toolbar';
|
|
11
|
+
|
|
12
|
+
export const SheetContainer = ({ graph, sheet, role }: SheetProviderProps & { role?: string }) => {
|
|
13
|
+
return (
|
|
14
|
+
<SheetProvider sheet={sheet} graph={graph}>
|
|
15
|
+
<Toolbar.Root role={role}>
|
|
16
|
+
<Toolbar.Styles />
|
|
17
|
+
<Toolbar.Alignment />
|
|
18
|
+
<Toolbar.Separator />
|
|
19
|
+
<Toolbar.Actions />
|
|
20
|
+
</Toolbar.Root>
|
|
21
|
+
<div role='none' className='border-bs border-separator grid cols-1 rows-[1fr_min-content] min-bs-0'>
|
|
22
|
+
<GridSheet />
|
|
23
|
+
<FunctionEditor />
|
|
24
|
+
</div>
|
|
25
|
+
</SheetProvider>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { type PropsWithChildren, createContext, useContext, useMemo, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { invariant } from '@dxos/invariant';
|
|
8
|
+
import { fullyQualifiedId } from '@dxos/react-client/echo';
|
|
9
|
+
import { Grid, useGridContext, type GridScopedProps, type GridEditing } from '@dxos/react-ui-grid';
|
|
10
|
+
|
|
11
|
+
import { type CellAddress, type CellRange } from '../../defs';
|
|
12
|
+
import { type ComputeGraph } from '../../graph';
|
|
13
|
+
import { useSheetModel, useSelectThreadOnCellFocus, useThreadDecorations } from '../../hooks';
|
|
14
|
+
import { type SheetModel, createDecorations } from '../../model';
|
|
15
|
+
import { type SheetType } from '../../types';
|
|
16
|
+
|
|
17
|
+
export type SheetContextValue = {
|
|
18
|
+
id: string;
|
|
19
|
+
|
|
20
|
+
model: SheetModel;
|
|
21
|
+
|
|
22
|
+
// Cursor state.
|
|
23
|
+
// TODO(burdon): Cursor and range should use indices.
|
|
24
|
+
cursor?: CellAddress;
|
|
25
|
+
setCursor: (cell: CellAddress | undefined) => void;
|
|
26
|
+
range?: CellRange;
|
|
27
|
+
setRange: (range: CellRange | undefined) => void;
|
|
28
|
+
|
|
29
|
+
// Editing state (undefined if not editing).
|
|
30
|
+
editing: GridEditing;
|
|
31
|
+
setEditing: (editing: GridEditing) => void;
|
|
32
|
+
|
|
33
|
+
// Events.
|
|
34
|
+
// TODO(burdon): Generalize.
|
|
35
|
+
onInfo?: () => void;
|
|
36
|
+
|
|
37
|
+
// Decorations.
|
|
38
|
+
decorations: ReturnType<typeof createDecorations>;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const SheetContext = createContext<SheetContextValue | undefined>(undefined);
|
|
42
|
+
|
|
43
|
+
export const useSheetContext = (): SheetContextValue => {
|
|
44
|
+
const context = useContext(SheetContext);
|
|
45
|
+
invariant(context);
|
|
46
|
+
return context;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const SheetProviderImpl = ({
|
|
50
|
+
model,
|
|
51
|
+
onInfo,
|
|
52
|
+
children,
|
|
53
|
+
__gridScope,
|
|
54
|
+
}: GridScopedProps<PropsWithChildren<Pick<SheetContextValue, 'onInfo' | 'model'>>>) => {
|
|
55
|
+
const { id, editing, setEditing } = useGridContext('SheetProvider', __gridScope);
|
|
56
|
+
|
|
57
|
+
// TODO(Zan): Impl. set range and set cursor that scrolls to that cell or range if it is not visible.
|
|
58
|
+
const decorations = useMemo(() => createDecorations(), []);
|
|
59
|
+
|
|
60
|
+
// TODO(thure): Reconnect these.
|
|
61
|
+
const [cursor, setCursor] = useState<CellAddress>();
|
|
62
|
+
const [range, setRange] = useState<CellRange>();
|
|
63
|
+
|
|
64
|
+
useSelectThreadOnCellFocus(model, cursor);
|
|
65
|
+
useThreadDecorations(model, decorations);
|
|
66
|
+
|
|
67
|
+
return (
|
|
68
|
+
<SheetContext.Provider
|
|
69
|
+
value={{
|
|
70
|
+
id,
|
|
71
|
+
model,
|
|
72
|
+
editing,
|
|
73
|
+
setEditing,
|
|
74
|
+
cursor,
|
|
75
|
+
setCursor,
|
|
76
|
+
range,
|
|
77
|
+
setRange,
|
|
78
|
+
// TODO(burdon): Change to event.
|
|
79
|
+
onInfo,
|
|
80
|
+
decorations,
|
|
81
|
+
}}
|
|
82
|
+
>
|
|
83
|
+
{children}
|
|
84
|
+
</SheetContext.Provider>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export type SheetProviderProps = {
|
|
89
|
+
graph: ComputeGraph;
|
|
90
|
+
sheet: SheetType;
|
|
91
|
+
readonly?: boolean;
|
|
92
|
+
} & Pick<SheetContextValue, 'onInfo'>;
|
|
93
|
+
|
|
94
|
+
export const SheetProvider = ({ children, graph, sheet, readonly, onInfo }: PropsWithChildren<SheetProviderProps>) => {
|
|
95
|
+
const model = useSheetModel(graph, sheet, { readonly });
|
|
96
|
+
|
|
97
|
+
return !model ? null : (
|
|
98
|
+
<Grid.Root id={fullyQualifiedId(sheet)}>
|
|
99
|
+
<SheetProviderImpl model={model} onInfo={onInfo}>
|
|
100
|
+
{children}
|
|
101
|
+
</SheetProviderImpl>
|
|
102
|
+
</Grid.Root>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
|
+
import { type Meta } from '@storybook/react';
|
|
7
8
|
import React from 'react';
|
|
8
9
|
|
|
9
10
|
import { textBlockWidth } from '@dxos/react-ui-theme';
|
|
@@ -12,7 +13,7 @@ import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
|
12
13
|
import { Toolbar } from './Toolbar';
|
|
13
14
|
import translations from '../../translations';
|
|
14
15
|
|
|
15
|
-
const
|
|
16
|
+
const DefaultStory = () => {
|
|
16
17
|
return (
|
|
17
18
|
<Toolbar.Root classNames={textBlockWidth}>
|
|
18
19
|
<Toolbar.Alignment />
|
|
@@ -20,12 +21,14 @@ const Story = () => {
|
|
|
20
21
|
);
|
|
21
22
|
};
|
|
22
23
|
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
export const Default = {};
|
|
25
|
+
|
|
26
|
+
const meta: Meta<typeof Toolbar.Root> = {
|
|
27
|
+
title: 'plugins/plugin-sheet/Toolbar',
|
|
28
|
+
component: Toolbar.Root,
|
|
29
|
+
render: DefaultStory,
|
|
26
30
|
decorators: [withTheme, withLayout({ tooltips: true })],
|
|
27
31
|
parameters: { translations, layout: 'fullscreen' },
|
|
28
|
-
render: (args: any) => <Story {...args} />,
|
|
29
32
|
};
|
|
30
33
|
|
|
31
|
-
export
|
|
34
|
+
export default meta;
|