@dxos/plugin-sheet 0.6.12 → 0.6.13-main.548ca8d
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-NDNIS44E.mjs +265 -0
- package/dist/lib/browser/SheetContainer-NDNIS44E.mjs.map +7 -0
- package/dist/lib/browser/chunk-AQSGDA4X.mjs +1614 -0
- package/dist/lib/browser/chunk-AQSGDA4X.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-GKI67SEF.mjs +69 -0
- package/dist/lib/browser/chunk-GKI67SEF.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 +4 -10
- package/dist/lib/node/SheetContainer-YSQGJD7K.cjs +276 -0
- package/dist/lib/node/SheetContainer-YSQGJD7K.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-6F43RV45.cjs +1610 -0
- package/dist/lib/node/chunk-6F43RV45.cjs.map +7 -0
- package/dist/lib/node/{chunk-DSYKOI4E.cjs → chunk-ER3PM7GD.cjs} +29 -45
- package/dist/lib/node/chunk-ER3PM7GD.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 +8 -14
- package/dist/lib/node/types.cjs.map +2 -2
- package/dist/lib/node-esm/SheetContainer-M7WRMZDU.mjs +266 -0
- package/dist/lib/node-esm/SheetContainer-M7WRMZDU.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-ELTFPX5B.mjs +1615 -0
- package/dist/lib/node-esm/chunk-ELTFPX5B.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-ZVLLQ2PJ.mjs +70 -0
- package/dist/lib/node-esm/chunk-ZVLLQ2PJ.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 +9 -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} +4 -4
- 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 +11 -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 +27 -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 -6
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +19 -14
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +3 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/defs/index.d.ts +3 -0
- package/dist/types/src/defs/index.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 +26 -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 +10 -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 +11 -0
- package/dist/types/src/hooks/hooks.stories.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +5 -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/useFormattingModel.d.ts +3 -0
- package/dist/types/src/hooks/useFormattingModel.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 +25 -0
- package/dist/types/src/model/decorations.d.ts.map +1 -0
- package/dist/types/src/model/formatting-model.d.ts +19 -0
- package/dist/types/src/model/formatting-model.d.ts.map +1 -0
- package/dist/types/src/model/index.d.ts +3 -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 +98 -32
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/vendor/hyperformula.mjs +37145 -0
- package/package.json +57 -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 +41 -0
- package/src/components/GridSheet/GridSheet.tsx +161 -0
- package/src/components/{CellEditor/CellEditor.stories.tsx → GridSheet/SheetCellEditor.stories.tsx} +8 -8
- package/src/components/GridSheet/index.ts +5 -0
- package/src/components/GridSheet/util.ts +144 -0
- package/src/components/SheetContainer/SheetContainer.stories.tsx +40 -0
- package/src/components/SheetContainer/SheetContainer.tsx +52 -0
- package/src/components/SheetContainer/index.ts +7 -0
- package/src/components/SheetContext/SheetContext.tsx +108 -0
- package/src/components/SheetContext/index.ts +5 -0
- package/src/components/Toolbar/Toolbar.tsx +167 -85
- package/src/components/index.ts +2 -0
- package/src/defs/index.ts +6 -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 +151 -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 +93 -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 +50 -0
- package/src/hooks/index.ts +8 -0
- package/src/hooks/threads.ts +147 -0
- package/src/hooks/useComputeGraph.ts +28 -0
- package/src/hooks/useFormattingModel.ts +11 -0
- package/src/hooks/useSheetModel.ts +40 -0
- package/src/meta.ts +14 -0
- package/src/model/decorations.ts +64 -0
- package/src/{components/Sheet/formatting.ts → model/formatting-model.ts} +30 -20
- package/src/model/index.ts +3 -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 -41
- 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/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
|
@@ -1,1160 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
type Active,
|
|
7
|
-
DndContext,
|
|
8
|
-
type DragEndEvent,
|
|
9
|
-
DragOverlay,
|
|
10
|
-
type DragStartEvent,
|
|
11
|
-
KeyboardSensor,
|
|
12
|
-
type Modifier,
|
|
13
|
-
MouseSensor,
|
|
14
|
-
type PointerActivationConstraint,
|
|
15
|
-
TouchSensor,
|
|
16
|
-
useDraggable,
|
|
17
|
-
useDroppable,
|
|
18
|
-
useSensor,
|
|
19
|
-
useSensors,
|
|
20
|
-
} from '@dnd-kit/core';
|
|
21
|
-
import { restrictToHorizontalAxis, restrictToVerticalAxis } from '@dnd-kit/modifiers';
|
|
22
|
-
import { getEventCoordinates, useCombinedRefs } from '@dnd-kit/utilities';
|
|
23
|
-
import { Function as FunctionIcon } from '@phosphor-icons/react';
|
|
24
|
-
import { Resizable, type ResizeCallback, type ResizeStartCallback } from 're-resizable';
|
|
25
|
-
import React, {
|
|
26
|
-
type CSSProperties,
|
|
27
|
-
type DOMAttributes,
|
|
28
|
-
type PropsWithChildren,
|
|
29
|
-
forwardRef,
|
|
30
|
-
useEffect,
|
|
31
|
-
useImperativeHandle,
|
|
32
|
-
useMemo,
|
|
33
|
-
useRef,
|
|
34
|
-
useState,
|
|
35
|
-
} from 'react';
|
|
36
|
-
import { createPortal } from 'react-dom';
|
|
37
|
-
import { useResizeDetector } from 'react-resize-detector';
|
|
38
|
-
|
|
39
|
-
import { debounce } from '@dxos/async';
|
|
40
|
-
import { fullyQualifiedId, createDocAccessor } from '@dxos/client/echo';
|
|
41
|
-
import { log } from '@dxos/log';
|
|
42
|
-
import { type ThemedClassName } from '@dxos/react-ui';
|
|
43
|
-
import { createAttendableAttributes, useHasAttention } from '@dxos/react-ui-attention';
|
|
44
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
45
|
-
|
|
46
|
-
import {
|
|
47
|
-
type GridLayoutProps,
|
|
48
|
-
type SizeMap,
|
|
49
|
-
CELL_DATA_KEY,
|
|
50
|
-
axisHeight,
|
|
51
|
-
axisWidth,
|
|
52
|
-
defaultHeight,
|
|
53
|
-
defaultWidth,
|
|
54
|
-
maxWidth,
|
|
55
|
-
maxHeight,
|
|
56
|
-
minWidth,
|
|
57
|
-
minHeight,
|
|
58
|
-
getCellElement,
|
|
59
|
-
useGridLayout,
|
|
60
|
-
} from './grid';
|
|
61
|
-
import { type GridSize, handleArrowNav, handleNav, useRangeSelect } from './nav';
|
|
62
|
-
import { type SheetContextProps, SheetContextProvider, useSheetContext } from './sheet-context';
|
|
63
|
-
import { getRectUnion, getRelativeClientRect, scrollIntoView } from './util';
|
|
64
|
-
import {
|
|
65
|
-
type CellIndex,
|
|
66
|
-
type CellAddress,
|
|
67
|
-
addressToA1Notation,
|
|
68
|
-
columnLetter,
|
|
69
|
-
posEquals,
|
|
70
|
-
rangeToA1Notation,
|
|
71
|
-
} from '../../model';
|
|
72
|
-
import {
|
|
73
|
-
CellEditor,
|
|
74
|
-
type CellRangeNotifier,
|
|
75
|
-
type EditorKeysProps,
|
|
76
|
-
editorKeys,
|
|
77
|
-
rangeExtension,
|
|
78
|
-
sheetExtension,
|
|
79
|
-
} from '../CellEditor';
|
|
80
|
-
|
|
81
|
-
// TODO(burdon): Virtualization bug.
|
|
82
|
-
// TODO(burdon): Toolbar styles and formatting.
|
|
83
|
-
// TODO(burdon): Insert/delete rows/columns (menu).
|
|
84
|
-
// TODO(burdon): Scroll to position if off screen.
|
|
85
|
-
// TODO(burdon): Don't render until sizes were updated (otherwise, flickers).
|
|
86
|
-
|
|
87
|
-
// TODO(burdon): Model multiple sheets (e.g., documents). And cross sheet references.
|
|
88
|
-
// TODO(burdon): Factor out react-ui-sheet.
|
|
89
|
-
// TODO(burdon): Comments (josiah).
|
|
90
|
-
// TODO(burdon): Realtime long text.
|
|
91
|
-
// TODO(burdon): Search.
|
|
92
|
-
|
|
93
|
-
// TODO(burdon): Virtualization:
|
|
94
|
-
// https://github.com/TanStack/virtual/blob/main/examples/react/dynamic/src/main.tsx#L171
|
|
95
|
-
// https://tanstack.com/virtual/v3/docs/framework/react/examples/variable
|
|
96
|
-
// https://canvas-grid-demo.vercel.app
|
|
97
|
-
// https://sheet.brianhung.me
|
|
98
|
-
// https://github.com/BrianHung
|
|
99
|
-
// https://daybrush.com/moveable
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Features:
|
|
103
|
-
* - Move rows/columns.
|
|
104
|
-
* - Insert/delete rows/columns.
|
|
105
|
-
* - Copy/paste.
|
|
106
|
-
* - Undo/redo.
|
|
107
|
-
* - Comments.
|
|
108
|
-
* - Real time collaborative editing of large text cells.
|
|
109
|
-
* - Select range.
|
|
110
|
-
* - Format cells.
|
|
111
|
-
* - Formulae.
|
|
112
|
-
* - Update formula ranges by selection.
|
|
113
|
-
*/
|
|
114
|
-
|
|
115
|
-
const fragments = {
|
|
116
|
-
axis: 'bg-axisSurface text-axisText text-xs select-none',
|
|
117
|
-
axisSelected: 'bg-attention text-baseText',
|
|
118
|
-
cell: 'bg-gridCell',
|
|
119
|
-
cellSelected: 'bg-gridCellSelected text-baseText border !border-accentSurface',
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
//
|
|
123
|
-
// Root
|
|
124
|
-
//
|
|
125
|
-
|
|
126
|
-
type SheetRootProps = SheetContextProps;
|
|
127
|
-
|
|
128
|
-
const SheetRoot = ({ children, ...props }: PropsWithChildren<SheetContextProps>) => {
|
|
129
|
-
return <SheetContextProvider {...props}>{children}</SheetContextProvider>;
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
//
|
|
133
|
-
// Main
|
|
134
|
-
//
|
|
135
|
-
|
|
136
|
-
type SheetMainProps = ThemedClassName<Partial<GridSize>>;
|
|
137
|
-
|
|
138
|
-
const SheetMain = forwardRef<HTMLDivElement, SheetMainProps>(({ classNames, numRows, numColumns }, forwardRef) => {
|
|
139
|
-
const { model, cursor, setCursor, setRange, setEditing } = useSheetContext();
|
|
140
|
-
|
|
141
|
-
// Scrolling.
|
|
142
|
-
const { rowsRef, columnsRef, contentRef } = useScrollHandlers();
|
|
143
|
-
|
|
144
|
-
//
|
|
145
|
-
// Order of Row/columns.
|
|
146
|
-
//
|
|
147
|
-
const [rows, setRows] = useState([...model.sheet.rows]);
|
|
148
|
-
const [columns, setColumns] = useState([...model.sheet.columns]);
|
|
149
|
-
useEffect(() => {
|
|
150
|
-
const rowsAccessor = createDocAccessor(model.sheet, ['rows']);
|
|
151
|
-
const columnsAccessor = createDocAccessor(model.sheet, ['columns']);
|
|
152
|
-
const handleUpdate = debounce(() => {
|
|
153
|
-
setRows([...model.sheet.rows]);
|
|
154
|
-
setColumns([...model.sheet.columns]);
|
|
155
|
-
}, 100);
|
|
156
|
-
|
|
157
|
-
rowsAccessor.handle.addListener('change', handleUpdate);
|
|
158
|
-
columnsAccessor.handle.addListener('change', handleUpdate);
|
|
159
|
-
handleUpdate();
|
|
160
|
-
return () => {
|
|
161
|
-
rowsAccessor.handle.removeListener('change', handleUpdate);
|
|
162
|
-
columnsAccessor.handle.removeListener('change', handleUpdate);
|
|
163
|
-
};
|
|
164
|
-
}, [model]);
|
|
165
|
-
|
|
166
|
-
// Refresh the model.
|
|
167
|
-
// TODO(burdon): Breaks undo.
|
|
168
|
-
useEffect(() => {
|
|
169
|
-
model.reset();
|
|
170
|
-
}, [rows, columns]);
|
|
171
|
-
|
|
172
|
-
const handleMoveRows: SheetRowsProps['onMove'] = (from, to, num = 1) => {
|
|
173
|
-
const cursorIdx = cursor ? model.addressToIndex(cursor) : undefined;
|
|
174
|
-
const [rows] = model.sheet.rows.splice(from, num);
|
|
175
|
-
model.sheet.rows.splice(to, 0, rows);
|
|
176
|
-
if (cursorIdx) {
|
|
177
|
-
setCursor(model.addressFromIndex(cursorIdx));
|
|
178
|
-
}
|
|
179
|
-
setRows([...model.sheet.rows]);
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
const handleMoveColumns: SheetColumnsProps['onMove'] = (from, to, num = 1) => {
|
|
183
|
-
const cursorIdx = cursor ? model.addressToIndex(cursor) : undefined;
|
|
184
|
-
const columns = model.sheet.columns.splice(from, num);
|
|
185
|
-
model.sheet.columns.splice(to, 0, ...columns);
|
|
186
|
-
if (cursorIdx) {
|
|
187
|
-
setCursor(model.addressFromIndex(cursorIdx));
|
|
188
|
-
}
|
|
189
|
-
setColumns([...model.sheet.columns]);
|
|
190
|
-
};
|
|
191
|
-
|
|
192
|
-
//
|
|
193
|
-
// Row/column sizes.
|
|
194
|
-
//
|
|
195
|
-
const [rowSizes, setRowSizes] = useState<SizeMap>();
|
|
196
|
-
const [columnSizes, setColumnSizes] = useState<SizeMap>();
|
|
197
|
-
useEffect(() => {
|
|
198
|
-
const rowAccessor = createDocAccessor(model.sheet, ['rowMeta']);
|
|
199
|
-
const columnAccessor = createDocAccessor(model.sheet, ['columnMeta']);
|
|
200
|
-
const handleUpdate = debounce(() => {
|
|
201
|
-
const mapSizes = (values: [string, { size?: number | undefined }][]) =>
|
|
202
|
-
values.reduce<SizeMap>((map, [idx, meta]) => {
|
|
203
|
-
if (meta.size) {
|
|
204
|
-
map[idx] = meta.size;
|
|
205
|
-
}
|
|
206
|
-
return map;
|
|
207
|
-
}, {});
|
|
208
|
-
|
|
209
|
-
setRowSizes(mapSizes(Object.entries(model.sheet.rowMeta)));
|
|
210
|
-
setColumnSizes(mapSizes(Object.entries(model.sheet.columnMeta)));
|
|
211
|
-
}, 100);
|
|
212
|
-
|
|
213
|
-
rowAccessor.handle.addListener('change', handleUpdate);
|
|
214
|
-
columnAccessor.handle.addListener('change', handleUpdate);
|
|
215
|
-
handleUpdate();
|
|
216
|
-
return () => {
|
|
217
|
-
rowAccessor.handle.removeListener('change', handleUpdate);
|
|
218
|
-
columnAccessor.handle.removeListener('change', handleUpdate);
|
|
219
|
-
};
|
|
220
|
-
}, [model]);
|
|
221
|
-
|
|
222
|
-
const handleResizeRow: SheetRowsProps['onResize'] = (idx, size, save) => {
|
|
223
|
-
if (save) {
|
|
224
|
-
model.sheet.rowMeta[idx] ??= {};
|
|
225
|
-
model.sheet.rowMeta[idx].size = size;
|
|
226
|
-
} else {
|
|
227
|
-
setRowSizes((sizes) => ({ ...sizes, [idx]: size }));
|
|
228
|
-
}
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const handleResizeColumn: SheetColumnsProps['onResize'] = (idx, size, save) => {
|
|
232
|
-
if (save) {
|
|
233
|
-
model.sheet.columnMeta[idx] ??= {};
|
|
234
|
-
model.sheet.columnMeta[idx].size = size;
|
|
235
|
-
} else {
|
|
236
|
-
setColumnSizes((sizes) => ({ ...sizes, [idx]: size }));
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
return (
|
|
241
|
-
<div
|
|
242
|
-
role='none'
|
|
243
|
-
className={mx(
|
|
244
|
-
'grid grid-cols-[calc(var(--rail-size)-2px)_1fr] grid-rows-[32px_1fr_32px] bs-full is-full overflow-hidden',
|
|
245
|
-
classNames,
|
|
246
|
-
)}
|
|
247
|
-
>
|
|
248
|
-
<GridCorner
|
|
249
|
-
onClick={() => {
|
|
250
|
-
setCursor(undefined);
|
|
251
|
-
setRange(undefined);
|
|
252
|
-
setEditing(false);
|
|
253
|
-
}}
|
|
254
|
-
/>
|
|
255
|
-
<SheetColumns
|
|
256
|
-
ref={columnsRef}
|
|
257
|
-
columns={columns}
|
|
258
|
-
sizes={columnSizes}
|
|
259
|
-
selected={cursor?.column}
|
|
260
|
-
onSelect={(column) => setCursor(cursor?.column === column ? undefined : { row: -1, column })}
|
|
261
|
-
onResize={handleResizeColumn}
|
|
262
|
-
onMove={handleMoveColumns}
|
|
263
|
-
/>
|
|
264
|
-
|
|
265
|
-
<SheetRows
|
|
266
|
-
ref={rowsRef}
|
|
267
|
-
rows={rows}
|
|
268
|
-
sizes={rowSizes}
|
|
269
|
-
selected={cursor?.row}
|
|
270
|
-
onSelect={(row) => setCursor(cursor?.row === row ? undefined : { row, column: -1 })}
|
|
271
|
-
onResize={handleResizeRow}
|
|
272
|
-
onMove={handleMoveRows}
|
|
273
|
-
/>
|
|
274
|
-
<SheetGrid
|
|
275
|
-
ref={contentRef}
|
|
276
|
-
size={{ numRows: numRows ?? rows.length, numColumns: numColumns ?? columns.length }}
|
|
277
|
-
rows={rows}
|
|
278
|
-
columns={columns}
|
|
279
|
-
rowSizes={rowSizes}
|
|
280
|
-
columnSizes={columnSizes}
|
|
281
|
-
/>
|
|
282
|
-
|
|
283
|
-
<GridCorner />
|
|
284
|
-
<SheetStatusBar />
|
|
285
|
-
</div>
|
|
286
|
-
);
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Coordinate scrolling across components.
|
|
291
|
-
*/
|
|
292
|
-
const useScrollHandlers = () => {
|
|
293
|
-
const rowsRef = useRef<HTMLDivElement>(null);
|
|
294
|
-
const columnsRef = useRef<HTMLDivElement>(null);
|
|
295
|
-
const contentRef = useRef<HTMLDivElement>(null);
|
|
296
|
-
|
|
297
|
-
useEffect(() => {
|
|
298
|
-
const handleRowsScroll = (ev: Event) => {
|
|
299
|
-
const { scrollTop } = ev.target as HTMLDivElement;
|
|
300
|
-
if (!rowsRef.current!.dataset.locked) {
|
|
301
|
-
contentRef.current!.scrollTop = scrollTop;
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
|
|
305
|
-
const handleColumnsScroll = (ev: Event) => {
|
|
306
|
-
const { scrollLeft } = ev.target as HTMLDivElement;
|
|
307
|
-
if (!columnsRef.current!.dataset.locked) {
|
|
308
|
-
contentRef.current!.scrollLeft = scrollLeft;
|
|
309
|
-
}
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
const handleContentScroll = (ev: Event) => {
|
|
313
|
-
const { scrollTop, scrollLeft } = ev.target as HTMLDivElement;
|
|
314
|
-
rowsRef.current!.scrollTop = scrollTop;
|
|
315
|
-
columnsRef.current!.scrollLeft = scrollLeft;
|
|
316
|
-
};
|
|
317
|
-
|
|
318
|
-
const rows = rowsRef.current!;
|
|
319
|
-
const columns = columnsRef.current!;
|
|
320
|
-
const content = contentRef.current!;
|
|
321
|
-
|
|
322
|
-
rows.addEventListener('scroll', handleRowsScroll);
|
|
323
|
-
columns.addEventListener('scroll', handleColumnsScroll);
|
|
324
|
-
content.addEventListener('scroll', handleContentScroll);
|
|
325
|
-
return () => {
|
|
326
|
-
rows.removeEventListener('scroll', handleRowsScroll);
|
|
327
|
-
columns.removeEventListener('scroll', handleColumnsScroll);
|
|
328
|
-
content.removeEventListener('scroll', handleContentScroll);
|
|
329
|
-
};
|
|
330
|
-
}, []);
|
|
331
|
-
|
|
332
|
-
return { rowsRef, columnsRef, contentRef };
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
//
|
|
336
|
-
// Row/Column
|
|
337
|
-
//
|
|
338
|
-
|
|
339
|
-
const GridCorner = (props: { className?: string } & Pick<DOMAttributes<HTMLDivElement>, 'onClick'>) => {
|
|
340
|
-
return <div className={fragments.axis} {...props} />;
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
const MovingOverlay = ({ label }: { label: string }) => {
|
|
344
|
-
return (
|
|
345
|
-
<div className='flex w-full h-full justify-center items-center text-sm p-1 bg-gridOverlay cursor-pointer'>
|
|
346
|
-
{label}
|
|
347
|
-
</div>
|
|
348
|
-
);
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
// https://docs.dndkit.com/api-documentation/sensors/pointer#activation-constraints
|
|
352
|
-
const mouseConstraints: PointerActivationConstraint = { distance: 10 };
|
|
353
|
-
const touchConstraints: PointerActivationConstraint = { delay: 250, tolerance: 5 };
|
|
354
|
-
|
|
355
|
-
type ResizeProps = {
|
|
356
|
-
sizes?: SizeMap;
|
|
357
|
-
onResize?: (idx: CellIndex, size: number, save?: boolean) => void;
|
|
358
|
-
};
|
|
359
|
-
|
|
360
|
-
type MoveProps = {
|
|
361
|
-
onMove?: (from: number, to: number) => void;
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
type RowColumnSelection = {
|
|
365
|
-
selected?: number;
|
|
366
|
-
onSelect?: (selected: number) => void;
|
|
367
|
-
};
|
|
368
|
-
|
|
369
|
-
type RowColumnProps = {
|
|
370
|
-
idx: CellIndex;
|
|
371
|
-
index: number;
|
|
372
|
-
label: string;
|
|
373
|
-
size: number;
|
|
374
|
-
resize: boolean;
|
|
375
|
-
selected: boolean;
|
|
376
|
-
} & Pick<ResizeProps, 'onResize'> &
|
|
377
|
-
Pick<RowColumnSelection, 'onSelect'>;
|
|
378
|
-
|
|
379
|
-
//
|
|
380
|
-
// Rows
|
|
381
|
-
//
|
|
382
|
-
|
|
383
|
-
type SheetRowsProps = { rows: CellIndex[] } & RowColumnSelection & ResizeProps & MoveProps;
|
|
384
|
-
|
|
385
|
-
const SheetRows = forwardRef<HTMLDivElement, SheetRowsProps>(
|
|
386
|
-
({ rows, sizes, selected, onSelect, onResize, onMove }, forwardRef) => {
|
|
387
|
-
const mouseSensor = useSensor(MouseSensor, { activationConstraint: mouseConstraints });
|
|
388
|
-
const touchSensor = useSensor(TouchSensor, { activationConstraint: touchConstraints });
|
|
389
|
-
const keyboardSensor = useSensor(KeyboardSensor, {});
|
|
390
|
-
const sensors = useSensors(mouseSensor, touchSensor, keyboardSensor);
|
|
391
|
-
|
|
392
|
-
const [active, setActive] = useState<Active | null>(null);
|
|
393
|
-
const handleDragStart = ({ active }: DragStartEvent) => {
|
|
394
|
-
setActive(active);
|
|
395
|
-
};
|
|
396
|
-
|
|
397
|
-
const handleDragEnd = ({ over, active }: DragEndEvent) => {
|
|
398
|
-
if (over && over.id !== active.id) {
|
|
399
|
-
setActive(null);
|
|
400
|
-
onMove?.(active.data.current!.index, over.data.current!.index);
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
const snapToCenter: Modifier = ({ activatorEvent, draggingNodeRect, transform }) => {
|
|
405
|
-
if (draggingNodeRect && activatorEvent) {
|
|
406
|
-
const activatorCoordinates = getEventCoordinates(activatorEvent);
|
|
407
|
-
if (!activatorCoordinates) {
|
|
408
|
-
return transform;
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
const offset = activatorCoordinates.y - draggingNodeRect.top;
|
|
412
|
-
return {
|
|
413
|
-
...transform,
|
|
414
|
-
y: transform.y + offset - draggingNodeRect.height / 2,
|
|
415
|
-
};
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
return transform;
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
return (
|
|
422
|
-
<div className='relative flex grow overflow-hidden'>
|
|
423
|
-
{/* Fixed border. */}
|
|
424
|
-
<div
|
|
425
|
-
className={mx('z-20 absolute inset-0 border-y border-gridLine pointer-events-none')}
|
|
426
|
-
style={{ width: axisWidth }}
|
|
427
|
-
/>
|
|
428
|
-
|
|
429
|
-
{/* Scrollbar. */}
|
|
430
|
-
<div ref={forwardRef} role='rowheader' className='grow overflow-y-auto scrollbar-none'>
|
|
431
|
-
<DndContext
|
|
432
|
-
sensors={sensors}
|
|
433
|
-
modifiers={[restrictToVerticalAxis, snapToCenter]}
|
|
434
|
-
onDragStart={handleDragStart}
|
|
435
|
-
onDragEnd={handleDragEnd}
|
|
436
|
-
>
|
|
437
|
-
<div className='flex flex-col' style={{ width: axisWidth }}>
|
|
438
|
-
{rows.map((idx, index) => (
|
|
439
|
-
<GridRowCell
|
|
440
|
-
key={idx}
|
|
441
|
-
idx={idx}
|
|
442
|
-
index={index}
|
|
443
|
-
label={String(index + 1)}
|
|
444
|
-
size={sizes?.[idx] ?? defaultHeight}
|
|
445
|
-
resize={index < rows.length - 1}
|
|
446
|
-
selected={selected === index}
|
|
447
|
-
onResize={onResize}
|
|
448
|
-
onSelect={onSelect}
|
|
449
|
-
/>
|
|
450
|
-
))}
|
|
451
|
-
</div>
|
|
452
|
-
|
|
453
|
-
{createPortal(
|
|
454
|
-
<DragOverlay>{active && <MovingOverlay label={String(active.data.current!.index + 1)} />}</DragOverlay>,
|
|
455
|
-
document.body,
|
|
456
|
-
)}
|
|
457
|
-
</DndContext>
|
|
458
|
-
</div>
|
|
459
|
-
</div>
|
|
460
|
-
);
|
|
461
|
-
},
|
|
462
|
-
);
|
|
463
|
-
|
|
464
|
-
const GridRowCell = ({ idx, index, label, size, resize, selected, onSelect, onResize }: RowColumnProps) => {
|
|
465
|
-
const { setNodeRef: setDroppableNodeRef } = useDroppable({ id: idx, data: { index } });
|
|
466
|
-
const {
|
|
467
|
-
setNodeRef: setDraggableNodeRef,
|
|
468
|
-
attributes,
|
|
469
|
-
listeners,
|
|
470
|
-
isDragging,
|
|
471
|
-
over,
|
|
472
|
-
} = useDraggable({ id: idx, data: { index } });
|
|
473
|
-
const setNodeRef = useCombinedRefs(setDroppableNodeRef, setDraggableNodeRef);
|
|
474
|
-
const [initialSize, setInitialSize] = useState(size);
|
|
475
|
-
const [resizing, setResizing] = useState(false);
|
|
476
|
-
|
|
477
|
-
// Lock scroll container while resizing (fixes scroll bug).
|
|
478
|
-
// https://github.com/bokuweb/re-resizable/issues/727
|
|
479
|
-
const scrollHandler = useRef<any>();
|
|
480
|
-
const handleResizeStart: ResizeStartCallback = (_ev, _dir, elementRef) => {
|
|
481
|
-
const scrollContainer = elementRef.closest<HTMLDivElement>('[role="rowheader"]')!;
|
|
482
|
-
const scrollTop = scrollContainer.scrollTop;
|
|
483
|
-
scrollHandler.current = (ev: Event) => ((ev.target as HTMLElement).scrollTop = scrollTop);
|
|
484
|
-
scrollContainer.addEventListener('scroll', scrollHandler.current);
|
|
485
|
-
scrollContainer.dataset.locked = 'true';
|
|
486
|
-
setResizing(true);
|
|
487
|
-
};
|
|
488
|
-
|
|
489
|
-
const handleResize: ResizeCallback = (_ev, _dir, _elementRef, { height }) => {
|
|
490
|
-
onResize?.(idx, initialSize + height);
|
|
491
|
-
};
|
|
492
|
-
|
|
493
|
-
const handleResizeStop: ResizeCallback = (_ev, _dir, elementRef, { height }) => {
|
|
494
|
-
const scrollContainer = elementRef.closest<HTMLDivElement>('[role="rowheader"]')!;
|
|
495
|
-
scrollContainer.removeEventListener('scroll', scrollHandler.current!);
|
|
496
|
-
delete scrollContainer.dataset.locked;
|
|
497
|
-
scrollHandler.current = undefined;
|
|
498
|
-
setInitialSize(initialSize + height);
|
|
499
|
-
onResize?.(idx, initialSize + height, true);
|
|
500
|
-
setResizing(false);
|
|
501
|
-
};
|
|
502
|
-
|
|
503
|
-
// Row.
|
|
504
|
-
return (
|
|
505
|
-
<Resizable
|
|
506
|
-
enable={{ bottom: resize }}
|
|
507
|
-
size={{ height: size - 1 }}
|
|
508
|
-
minHeight={minHeight - 1}
|
|
509
|
-
maxHeight={maxHeight}
|
|
510
|
-
onResizeStart={handleResizeStart}
|
|
511
|
-
onResize={handleResize}
|
|
512
|
-
onResizeStop={handleResizeStop}
|
|
513
|
-
>
|
|
514
|
-
<div
|
|
515
|
-
ref={setNodeRef}
|
|
516
|
-
{...attributes}
|
|
517
|
-
{...listeners}
|
|
518
|
-
className={mx(
|
|
519
|
-
'flex h-full items-center justify-center cursor-pointer',
|
|
520
|
-
'border-t border-gridLine focus-visible:outline-none',
|
|
521
|
-
fragments.axis,
|
|
522
|
-
selected && fragments.axisSelected,
|
|
523
|
-
isDragging && fragments.axisSelected,
|
|
524
|
-
)}
|
|
525
|
-
onClick={() => onSelect?.(index)}
|
|
526
|
-
>
|
|
527
|
-
<span className='flex w-full justify-center'>{label}</span>
|
|
528
|
-
|
|
529
|
-
{/* Drop indicator. */}
|
|
530
|
-
{over?.id === idx && !isDragging && (
|
|
531
|
-
<div className='z-20 absolute top-0 w-full min-h-[4px] border-b-4 border-accentSurface' />
|
|
532
|
-
)}
|
|
533
|
-
|
|
534
|
-
{/* Resize indicator. */}
|
|
535
|
-
{resizing && <div className='z-20 absolute bottom-0 w-full min-h-[4px] border-b-4 border-accentSurface' />}
|
|
536
|
-
</div>
|
|
537
|
-
</Resizable>
|
|
538
|
-
);
|
|
539
|
-
};
|
|
540
|
-
|
|
541
|
-
//
|
|
542
|
-
// Columns
|
|
543
|
-
//
|
|
544
|
-
|
|
545
|
-
type SheetColumnsProps = { columns: CellIndex[] } & RowColumnSelection & ResizeProps & MoveProps;
|
|
546
|
-
|
|
547
|
-
const SheetColumns = forwardRef<HTMLDivElement, SheetColumnsProps>(
|
|
548
|
-
({ columns, sizes, selected, onSelect, onResize, onMove }, forwardRef) => {
|
|
549
|
-
const mouseSensor = useSensor(MouseSensor, { activationConstraint: mouseConstraints });
|
|
550
|
-
const touchSensor = useSensor(TouchSensor, { activationConstraint: touchConstraints });
|
|
551
|
-
const keyboardSensor = useSensor(KeyboardSensor, {});
|
|
552
|
-
const sensors = useSensors(mouseSensor, touchSensor, keyboardSensor);
|
|
553
|
-
|
|
554
|
-
const [active, setActive] = useState<Active | null>(null);
|
|
555
|
-
const handleDragStart = ({ active }: DragStartEvent) => {
|
|
556
|
-
setActive(active);
|
|
557
|
-
};
|
|
558
|
-
|
|
559
|
-
const handleDragEnd = ({ active, over }: DragEndEvent) => {
|
|
560
|
-
if (over && over.id !== active.id) {
|
|
561
|
-
setActive(null);
|
|
562
|
-
onMove?.(active.data.current!.index, over.data.current!.index);
|
|
563
|
-
}
|
|
564
|
-
};
|
|
565
|
-
|
|
566
|
-
const snapToCenter: Modifier = ({ activatorEvent, draggingNodeRect, transform }) => {
|
|
567
|
-
if (draggingNodeRect && activatorEvent) {
|
|
568
|
-
const activatorCoordinates = getEventCoordinates(activatorEvent);
|
|
569
|
-
if (!activatorCoordinates) {
|
|
570
|
-
return transform;
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
const offset = activatorCoordinates.x - draggingNodeRect.left;
|
|
574
|
-
return {
|
|
575
|
-
...transform,
|
|
576
|
-
x: transform.x + offset - draggingNodeRect.width / 2,
|
|
577
|
-
};
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
return transform;
|
|
581
|
-
};
|
|
582
|
-
|
|
583
|
-
return (
|
|
584
|
-
<div className='relative flex grow overflow-hidden'>
|
|
585
|
-
{/* Fixed border. */}
|
|
586
|
-
<div
|
|
587
|
-
className={mx('z-20 absolute inset-0 border-x border-gridLine pointer-events-none')}
|
|
588
|
-
style={{ height: axisHeight }}
|
|
589
|
-
/>
|
|
590
|
-
|
|
591
|
-
{/* Scrollbar. */}
|
|
592
|
-
<div ref={forwardRef} role='columnheader' className='grow overflow-x-auto scrollbar-none'>
|
|
593
|
-
<DndContext
|
|
594
|
-
autoScroll={{ enabled: true }}
|
|
595
|
-
sensors={sensors}
|
|
596
|
-
modifiers={[restrictToHorizontalAxis, snapToCenter]}
|
|
597
|
-
onDragStart={handleDragStart}
|
|
598
|
-
onDragEnd={handleDragEnd}
|
|
599
|
-
>
|
|
600
|
-
<div className='flex h-full' style={{ height: axisHeight }}>
|
|
601
|
-
{columns.map((idx, index) => (
|
|
602
|
-
<GridColumnCell
|
|
603
|
-
key={idx}
|
|
604
|
-
idx={idx}
|
|
605
|
-
index={index}
|
|
606
|
-
label={columnLetter(index)}
|
|
607
|
-
size={sizes?.[idx] ?? defaultWidth}
|
|
608
|
-
resize={index < columns.length - 1}
|
|
609
|
-
selected={selected === index}
|
|
610
|
-
onResize={onResize}
|
|
611
|
-
onSelect={onSelect}
|
|
612
|
-
/>
|
|
613
|
-
))}
|
|
614
|
-
</div>
|
|
615
|
-
|
|
616
|
-
{createPortal(
|
|
617
|
-
<DragOverlay>{active && <MovingOverlay label={columnLetter(active.data.current!.index)} />}</DragOverlay>,
|
|
618
|
-
document.body,
|
|
619
|
-
)}
|
|
620
|
-
</DndContext>
|
|
621
|
-
</div>
|
|
622
|
-
</div>
|
|
623
|
-
);
|
|
624
|
-
},
|
|
625
|
-
);
|
|
626
|
-
|
|
627
|
-
const GridColumnCell = ({ idx, index, label, size, resize, selected, onSelect, onResize }: RowColumnProps) => {
|
|
628
|
-
const { setNodeRef: setDroppableNodeRef } = useDroppable({ id: idx, data: { index } });
|
|
629
|
-
const {
|
|
630
|
-
setNodeRef: setDraggableNodeRef,
|
|
631
|
-
attributes,
|
|
632
|
-
listeners,
|
|
633
|
-
over,
|
|
634
|
-
isDragging,
|
|
635
|
-
} = useDraggable({ id: idx, data: { index } });
|
|
636
|
-
const setNodeRef = useCombinedRefs(setDroppableNodeRef, setDraggableNodeRef);
|
|
637
|
-
const [initialSize, setInitialSize] = useState(size);
|
|
638
|
-
const [resizing, setResizing] = useState(false);
|
|
639
|
-
|
|
640
|
-
// Lock scroll container while resizing (fixes scroll bug).
|
|
641
|
-
// https://github.com/bokuweb/re-resizable/issues/727
|
|
642
|
-
const scrollHandler = useRef<any>();
|
|
643
|
-
const handleResizeStart: ResizeStartCallback = (_ev, _dir, elementRef) => {
|
|
644
|
-
const scrollContainer = elementRef.closest<HTMLDivElement>('[role="columnheader"]')!;
|
|
645
|
-
const scrollLeft = scrollContainer.scrollLeft;
|
|
646
|
-
scrollHandler.current = (ev: Event) => ((ev.target as HTMLElement).scrollLeft = scrollLeft);
|
|
647
|
-
scrollContainer.addEventListener('scroll', scrollHandler.current);
|
|
648
|
-
scrollContainer.dataset.locked = 'true';
|
|
649
|
-
setResizing(true);
|
|
650
|
-
};
|
|
651
|
-
|
|
652
|
-
const handleResize: ResizeCallback = (_ev, _dir, _elementRef, { width }) => {
|
|
653
|
-
onResize?.(idx, initialSize + width);
|
|
654
|
-
};
|
|
655
|
-
|
|
656
|
-
const handleResizeStop: ResizeCallback = (_ev, _dir, elementRef, { width }) => {
|
|
657
|
-
const scrollContainer = elementRef.closest<HTMLDivElement>('[role="columnheader"]')!;
|
|
658
|
-
scrollContainer.removeEventListener('scroll', scrollHandler.current!);
|
|
659
|
-
delete scrollContainer.dataset.locked;
|
|
660
|
-
scrollHandler.current = undefined;
|
|
661
|
-
setInitialSize(initialSize + width);
|
|
662
|
-
onResize?.(idx, initialSize + width, true);
|
|
663
|
-
setResizing(false);
|
|
664
|
-
};
|
|
665
|
-
|
|
666
|
-
// Column.
|
|
667
|
-
return (
|
|
668
|
-
<Resizable
|
|
669
|
-
enable={{ right: resize }}
|
|
670
|
-
size={{ width: size - 1 }}
|
|
671
|
-
minWidth={minWidth - 1}
|
|
672
|
-
maxWidth={maxWidth}
|
|
673
|
-
onResizeStart={handleResizeStart}
|
|
674
|
-
onResize={handleResize}
|
|
675
|
-
onResizeStop={handleResizeStop}
|
|
676
|
-
>
|
|
677
|
-
<div
|
|
678
|
-
ref={setNodeRef}
|
|
679
|
-
{...attributes}
|
|
680
|
-
{...listeners}
|
|
681
|
-
className={mx(
|
|
682
|
-
'flex h-full items-center justify-center cursor-pointer',
|
|
683
|
-
'border-l border-gridLine focus-visible:outline-none',
|
|
684
|
-
fragments.axis,
|
|
685
|
-
selected && fragments.axisSelected,
|
|
686
|
-
isDragging && fragments.axisSelected,
|
|
687
|
-
)}
|
|
688
|
-
onClick={() => onSelect?.(index)}
|
|
689
|
-
>
|
|
690
|
-
<span className='flex w-full justify-center'>{label}</span>
|
|
691
|
-
|
|
692
|
-
{/* Drop indicator. */}
|
|
693
|
-
{over?.id === idx && !isDragging && (
|
|
694
|
-
<div className='z-20 absolute left-0 h-full min-w-[4px] border-l-4 border-accentSurface' />
|
|
695
|
-
)}
|
|
696
|
-
|
|
697
|
-
{/* Resize indicator. */}
|
|
698
|
-
{resizing && <div className='z-20 absolute right-0 h-full min-h-[4px] border-l-4 border-accentSurface' />}
|
|
699
|
-
</div>
|
|
700
|
-
</Resizable>
|
|
701
|
-
);
|
|
702
|
-
};
|
|
703
|
-
|
|
704
|
-
//
|
|
705
|
-
// Content
|
|
706
|
-
//
|
|
707
|
-
|
|
708
|
-
type SheetGridProps = GridLayoutProps & {
|
|
709
|
-
size: GridSize;
|
|
710
|
-
};
|
|
711
|
-
|
|
712
|
-
const SheetGrid = forwardRef<HTMLDivElement, SheetGridProps>(
|
|
713
|
-
({ size, rows, columns, rowSizes, columnSizes }, forwardRef) => {
|
|
714
|
-
const {
|
|
715
|
-
ref: containerRef,
|
|
716
|
-
width: containerWidth = 0,
|
|
717
|
-
height: containerHeight = 0,
|
|
718
|
-
} = useResizeDetector({ refreshRate: 200 });
|
|
719
|
-
const scrollerRef = useRef<HTMLDivElement>(null);
|
|
720
|
-
useImperativeHandle(forwardRef, () => scrollerRef.current!);
|
|
721
|
-
|
|
722
|
-
const { model, cursor, range, editing, setCursor, setRange, setEditing, onInfo } = useSheetContext();
|
|
723
|
-
const initialText = useRef<string>();
|
|
724
|
-
const quickEdit = useRef(false);
|
|
725
|
-
|
|
726
|
-
// Listen for async calculation updates.
|
|
727
|
-
const [, forceUpdate] = useState({});
|
|
728
|
-
useEffect(() => {
|
|
729
|
-
const unsubscribe = model.update.on(() => {
|
|
730
|
-
log('updated', { id: model.id });
|
|
731
|
-
forceUpdate({});
|
|
732
|
-
});
|
|
733
|
-
|
|
734
|
-
return () => {
|
|
735
|
-
unsubscribe();
|
|
736
|
-
};
|
|
737
|
-
}, [model]);
|
|
738
|
-
|
|
739
|
-
//
|
|
740
|
-
// Event handling.
|
|
741
|
-
//
|
|
742
|
-
|
|
743
|
-
const inputRef = useRef<HTMLInputElement>(null);
|
|
744
|
-
const handleKeyDown: DOMAttributes<HTMLInputElement>['onKeyDown'] = (ev) => {
|
|
745
|
-
// Cut-and-paste.
|
|
746
|
-
const isMacOS = /Mac|iPhone|iPod|iPad/.test(navigator.userAgent);
|
|
747
|
-
if (cursor && ((isMacOS && ev.metaKey) || ev.ctrlKey)) {
|
|
748
|
-
switch (ev.key) {
|
|
749
|
-
case 'x': {
|
|
750
|
-
model.cut(range ?? { from: cursor });
|
|
751
|
-
return;
|
|
752
|
-
}
|
|
753
|
-
case 'c': {
|
|
754
|
-
model.copy(range ?? { from: cursor });
|
|
755
|
-
return;
|
|
756
|
-
}
|
|
757
|
-
case 'v': {
|
|
758
|
-
model.paste(cursor);
|
|
759
|
-
return;
|
|
760
|
-
}
|
|
761
|
-
case 'z': {
|
|
762
|
-
if (ev.shiftKey) {
|
|
763
|
-
model.redo();
|
|
764
|
-
} else {
|
|
765
|
-
model.undo();
|
|
766
|
-
}
|
|
767
|
-
return;
|
|
768
|
-
}
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
switch (ev.key) {
|
|
773
|
-
case 'ArrowUp':
|
|
774
|
-
case 'ArrowDown':
|
|
775
|
-
case 'ArrowLeft':
|
|
776
|
-
case 'ArrowRight':
|
|
777
|
-
case 'Home':
|
|
778
|
-
case 'End': {
|
|
779
|
-
const next = handleNav(ev, cursor, range, size);
|
|
780
|
-
setRange(next.range);
|
|
781
|
-
if (next.cursor) {
|
|
782
|
-
setCursor(next.cursor);
|
|
783
|
-
const element = getCellElement(scrollerRef.current!, next.cursor);
|
|
784
|
-
if (element) {
|
|
785
|
-
scrollIntoView(scrollerRef.current!, element);
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
break;
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
case 'Backspace': {
|
|
792
|
-
if (cursor) {
|
|
793
|
-
if (range) {
|
|
794
|
-
model.clear(range);
|
|
795
|
-
} else {
|
|
796
|
-
model.setValue(cursor, null);
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
break;
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
case 'Escape': {
|
|
803
|
-
setRange(undefined);
|
|
804
|
-
break;
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
case 'Enter': {
|
|
808
|
-
ev.stopPropagation();
|
|
809
|
-
if (cursor) {
|
|
810
|
-
setEditing(true);
|
|
811
|
-
}
|
|
812
|
-
break;
|
|
813
|
-
}
|
|
814
|
-
|
|
815
|
-
case '?': {
|
|
816
|
-
onInfo?.();
|
|
817
|
-
break;
|
|
818
|
-
}
|
|
819
|
-
|
|
820
|
-
default: {
|
|
821
|
-
if (ev.key.length === 1) {
|
|
822
|
-
initialText.current = ev.key;
|
|
823
|
-
quickEdit.current = true;
|
|
824
|
-
setEditing(true);
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
};
|
|
829
|
-
|
|
830
|
-
// Mouse handlers for selection.
|
|
831
|
-
const { handlers } = useRangeSelect((event, range) => {
|
|
832
|
-
switch (event) {
|
|
833
|
-
case 'start': {
|
|
834
|
-
// if (!editing) {
|
|
835
|
-
// setCursor(range?.from);
|
|
836
|
-
// }
|
|
837
|
-
setRange(undefined);
|
|
838
|
-
break;
|
|
839
|
-
}
|
|
840
|
-
|
|
841
|
-
default: {
|
|
842
|
-
setRange(range);
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
});
|
|
846
|
-
|
|
847
|
-
// Calculate visible grid.
|
|
848
|
-
const { width, height, rowRange, columnRange } = useGridLayout({
|
|
849
|
-
scroller: scrollerRef.current,
|
|
850
|
-
size: { width: containerWidth, height: containerHeight },
|
|
851
|
-
rows,
|
|
852
|
-
columns,
|
|
853
|
-
rowSizes,
|
|
854
|
-
columnSizes,
|
|
855
|
-
});
|
|
856
|
-
|
|
857
|
-
// TODO(burdon): Prevent scroll if not attended.
|
|
858
|
-
const id = fullyQualifiedId(model.sheet);
|
|
859
|
-
const attendableAttrs = createAttendableAttributes(id);
|
|
860
|
-
const hasAttention = useHasAttention(id);
|
|
861
|
-
|
|
862
|
-
return (
|
|
863
|
-
<div ref={containerRef} role='grid' className='relative flex grow overflow-hidden'>
|
|
864
|
-
{/* Fixed border. */}
|
|
865
|
-
<div className={mx('z-20 absolute inset-0 border border-gridLine pointer-events-none')} />
|
|
866
|
-
|
|
867
|
-
{/* Grid scroll container. */}
|
|
868
|
-
<div ref={scrollerRef} className={mx('grow', hasAttention && 'overflow-auto scrollbar-thin')}>
|
|
869
|
-
{/* Scroll content. */}
|
|
870
|
-
<div
|
|
871
|
-
className='relative select-none'
|
|
872
|
-
style={{ width, height }}
|
|
873
|
-
onClick={() => inputRef.current?.focus()}
|
|
874
|
-
{...handlers}
|
|
875
|
-
>
|
|
876
|
-
{/* Selection. */}
|
|
877
|
-
{scrollerRef.current && <SelectionOverlay root={scrollerRef.current} />}
|
|
878
|
-
|
|
879
|
-
{/* Grid cells. */}
|
|
880
|
-
{rowRange.map(({ row, top, height }) => {
|
|
881
|
-
return columnRange.map(({ column, left, width }) => {
|
|
882
|
-
const style: CSSProperties = { position: 'absolute', top, left, width, height };
|
|
883
|
-
const cell = { row, column };
|
|
884
|
-
const id = addressToA1Notation(cell);
|
|
885
|
-
const idx = model.addressToIndex(cell);
|
|
886
|
-
const active = posEquals(cursor, cell);
|
|
887
|
-
if (active && editing) {
|
|
888
|
-
const value = initialText.current ?? model.getCellText(cell) ?? '';
|
|
889
|
-
|
|
890
|
-
// TODO(burdon): Validate formula before closing: hf.validateFormula();
|
|
891
|
-
const handleClose: GridCellEditorProps['onClose'] = (value) => {
|
|
892
|
-
initialText.current = undefined;
|
|
893
|
-
quickEdit.current = false;
|
|
894
|
-
if (value !== undefined) {
|
|
895
|
-
model.setValue(cell, value);
|
|
896
|
-
// Auto-advance to next cell.
|
|
897
|
-
const next = handleArrowNav({ key: 'ArrowDown', metaKey: false }, cursor, size);
|
|
898
|
-
if (next) {
|
|
899
|
-
setCursor(next);
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
inputRef.current?.focus();
|
|
903
|
-
setEditing(false);
|
|
904
|
-
};
|
|
905
|
-
|
|
906
|
-
// Quick entry mode: i.e., typing to enter cell.
|
|
907
|
-
const handleNav: GridCellEditorProps['onNav'] = (value, { key }) => {
|
|
908
|
-
initialText.current = undefined;
|
|
909
|
-
model.setValue(cell, value ?? null);
|
|
910
|
-
const next = handleArrowNav({ key, metaKey: false }, cursor, size);
|
|
911
|
-
if (next) {
|
|
912
|
-
setCursor(next);
|
|
913
|
-
}
|
|
914
|
-
inputRef.current?.focus();
|
|
915
|
-
setEditing(false);
|
|
916
|
-
};
|
|
917
|
-
|
|
918
|
-
return (
|
|
919
|
-
<GridCellEditor
|
|
920
|
-
key={idx}
|
|
921
|
-
value={value}
|
|
922
|
-
style={style}
|
|
923
|
-
onNav={quickEdit.current ? handleNav : undefined}
|
|
924
|
-
onClose={handleClose}
|
|
925
|
-
/>
|
|
926
|
-
);
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
return (
|
|
930
|
-
<SheetCell
|
|
931
|
-
key={id}
|
|
932
|
-
id={id}
|
|
933
|
-
cell={cell}
|
|
934
|
-
active={active}
|
|
935
|
-
style={style}
|
|
936
|
-
onSelect={(cell, edit) => {
|
|
937
|
-
setEditing(edit);
|
|
938
|
-
setCursor(cell);
|
|
939
|
-
}}
|
|
940
|
-
/>
|
|
941
|
-
);
|
|
942
|
-
});
|
|
943
|
-
})}
|
|
944
|
-
</div>
|
|
945
|
-
</div>
|
|
946
|
-
|
|
947
|
-
{/* Hidden input for key navigation. */}
|
|
948
|
-
{createPortal(
|
|
949
|
-
<input
|
|
950
|
-
ref={inputRef}
|
|
951
|
-
autoFocus
|
|
952
|
-
className='absolute w-[1px] h-[1px] bg-transparent outline-none border-none caret-transparent'
|
|
953
|
-
onKeyDown={handleKeyDown}
|
|
954
|
-
{...attendableAttrs}
|
|
955
|
-
/>,
|
|
956
|
-
document.body,
|
|
957
|
-
)}
|
|
958
|
-
</div>
|
|
959
|
-
);
|
|
960
|
-
},
|
|
961
|
-
);
|
|
962
|
-
|
|
963
|
-
//
|
|
964
|
-
// Selection
|
|
965
|
-
//
|
|
966
|
-
|
|
967
|
-
const SelectionOverlay = ({ root }: { root: HTMLDivElement }) => {
|
|
968
|
-
const { range } = useSheetContext();
|
|
969
|
-
if (!range) {
|
|
970
|
-
return null;
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
const c1 = getCellElement(root, range.from);
|
|
974
|
-
const c2 = range.to ? getCellElement(root, range.to)! : c1;
|
|
975
|
-
if (!c1 || !c2) {
|
|
976
|
-
return null;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
// TODO(burdon): Instead of measuring cells, get from grid layout?
|
|
980
|
-
const b1 = getRelativeClientRect(root, c1);
|
|
981
|
-
const b2 = getRelativeClientRect(root, c2);
|
|
982
|
-
const bounds = getRectUnion(b1, b2);
|
|
983
|
-
|
|
984
|
-
return (
|
|
985
|
-
<div
|
|
986
|
-
role='none'
|
|
987
|
-
style={bounds}
|
|
988
|
-
className='z-10 absolute pointer-events-none bg-gridSelectionOverlay border border-gridOverlay'
|
|
989
|
-
/>
|
|
990
|
-
);
|
|
991
|
-
};
|
|
992
|
-
|
|
993
|
-
//
|
|
994
|
-
// Cell
|
|
995
|
-
//
|
|
996
|
-
|
|
997
|
-
type SheetCellProps = {
|
|
998
|
-
id: string; // TODO(burdon): Should this be the index?
|
|
999
|
-
cell: CellAddress;
|
|
1000
|
-
style: CSSProperties;
|
|
1001
|
-
active: boolean;
|
|
1002
|
-
onSelect?: (selected: CellAddress, edit: boolean) => void;
|
|
1003
|
-
};
|
|
1004
|
-
|
|
1005
|
-
const SheetCell = ({ id, cell, style, active, onSelect }: SheetCellProps) => {
|
|
1006
|
-
const { formatting, editing, setRange } = useSheetContext();
|
|
1007
|
-
const { value, classNames } = formatting.getFormatting(cell);
|
|
1008
|
-
|
|
1009
|
-
return (
|
|
1010
|
-
<div
|
|
1011
|
-
{...{ [`data-${CELL_DATA_KEY}`]: id }}
|
|
1012
|
-
role='cell'
|
|
1013
|
-
style={style}
|
|
1014
|
-
className={mx(
|
|
1015
|
-
'flex w-full h-full px-2 py-1 truncate items-center border border-gridLine cursor-pointer',
|
|
1016
|
-
fragments.cell,
|
|
1017
|
-
active && ['z-20', fragments.cellSelected],
|
|
1018
|
-
classNames,
|
|
1019
|
-
)}
|
|
1020
|
-
onClick={() => {
|
|
1021
|
-
if (editing) {
|
|
1022
|
-
setRange?.({ from: cell });
|
|
1023
|
-
} else {
|
|
1024
|
-
onSelect?.(cell, false);
|
|
1025
|
-
}
|
|
1026
|
-
}}
|
|
1027
|
-
onDoubleClick={() => onSelect?.(cell, true)}
|
|
1028
|
-
>
|
|
1029
|
-
{value}
|
|
1030
|
-
</div>
|
|
1031
|
-
);
|
|
1032
|
-
};
|
|
1033
|
-
|
|
1034
|
-
type GridCellEditorProps = {
|
|
1035
|
-
style: CSSProperties;
|
|
1036
|
-
value: string;
|
|
1037
|
-
} & EditorKeysProps;
|
|
1038
|
-
|
|
1039
|
-
const GridCellEditor = ({ style, value, onNav, onClose }: GridCellEditorProps) => {
|
|
1040
|
-
const { model, range } = useSheetContext();
|
|
1041
|
-
const notifier = useRef<CellRangeNotifier>();
|
|
1042
|
-
useEffect(() => {
|
|
1043
|
-
if (range) {
|
|
1044
|
-
// Update range selection in formula.
|
|
1045
|
-
notifier.current?.(rangeToA1Notation(range));
|
|
1046
|
-
}
|
|
1047
|
-
}, [range]);
|
|
1048
|
-
const extension = useMemo(
|
|
1049
|
-
() => [
|
|
1050
|
-
editorKeys({ onNav, onClose }),
|
|
1051
|
-
sheetExtension({ functions: model.functions }),
|
|
1052
|
-
rangeExtension((fn) => (notifier.current = fn)),
|
|
1053
|
-
],
|
|
1054
|
-
[model],
|
|
1055
|
-
);
|
|
1056
|
-
|
|
1057
|
-
return (
|
|
1058
|
-
<div
|
|
1059
|
-
role='cell'
|
|
1060
|
-
style={style}
|
|
1061
|
-
className={mx('z-20 flex', fragments.cellSelected)}
|
|
1062
|
-
onClick={(ev) => ev.stopPropagation()}
|
|
1063
|
-
>
|
|
1064
|
-
<CellEditor autoFocus value={value} extension={extension} />
|
|
1065
|
-
</div>
|
|
1066
|
-
);
|
|
1067
|
-
};
|
|
1068
|
-
|
|
1069
|
-
//
|
|
1070
|
-
// StatusBar
|
|
1071
|
-
//
|
|
1072
|
-
|
|
1073
|
-
const SheetStatusBar = () => {
|
|
1074
|
-
const { model, cursor, range } = useSheetContext();
|
|
1075
|
-
let value;
|
|
1076
|
-
let isFormula = false;
|
|
1077
|
-
if (cursor) {
|
|
1078
|
-
value = model.getCellValue(cursor);
|
|
1079
|
-
if (typeof value === 'string' && value.charAt(0) === '=') {
|
|
1080
|
-
value = model.mapFormulaBindingFromId(model.mapFormulaIndicesToRefs(value));
|
|
1081
|
-
isFormula = true;
|
|
1082
|
-
} else if (value != null) {
|
|
1083
|
-
value = String(value);
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
return (
|
|
1088
|
-
<div className={mx('flex shrink-0 justify-between items-center px-4 py-1 text-sm border-x border-gridLine')}>
|
|
1089
|
-
<div className='flex gap-4 items-center'>
|
|
1090
|
-
<div className='flex w-16 items-center font-mono'>
|
|
1091
|
-
{(range && rangeToA1Notation(range)) || (cursor && addressToA1Notation(cursor))}
|
|
1092
|
-
</div>
|
|
1093
|
-
<div className='flex gap-2 items-center'>
|
|
1094
|
-
<FunctionIcon className={mx('text-greenText', isFormula ? 'visible' : 'invisible')} />
|
|
1095
|
-
<span className='font-mono'>{value}</span>
|
|
1096
|
-
</div>
|
|
1097
|
-
</div>
|
|
1098
|
-
</div>
|
|
1099
|
-
);
|
|
1100
|
-
};
|
|
1101
|
-
|
|
1102
|
-
//
|
|
1103
|
-
// Debug
|
|
1104
|
-
//
|
|
1105
|
-
|
|
1106
|
-
const SheetDebug = () => {
|
|
1107
|
-
const { model, cursor, range } = useSheetContext();
|
|
1108
|
-
const [, forceUpdate] = useState({});
|
|
1109
|
-
useEffect(() => {
|
|
1110
|
-
// TODO(burdon): This is called without registering a listener.
|
|
1111
|
-
const accessor = createDocAccessor(model.sheet, []);
|
|
1112
|
-
const handleUpdate = () => forceUpdate({});
|
|
1113
|
-
accessor.handle.addListener('change', handleUpdate);
|
|
1114
|
-
handleUpdate();
|
|
1115
|
-
return () => {
|
|
1116
|
-
accessor.handle.removeListener('change', handleUpdate);
|
|
1117
|
-
};
|
|
1118
|
-
}, [model]);
|
|
1119
|
-
|
|
1120
|
-
return (
|
|
1121
|
-
<div
|
|
1122
|
-
className={mx(
|
|
1123
|
-
'z-20 absolute right-0 top-20 bottom-20 w-[30rem] overflow-auto scrollbar-thin',
|
|
1124
|
-
'border border-gridLine text-xs bg-neutral-50 dark:bg-black text-cyan-500 font-mono p-1 opacity-80',
|
|
1125
|
-
)}
|
|
1126
|
-
>
|
|
1127
|
-
<pre className='whitespace-pre-wrap'>
|
|
1128
|
-
{JSON.stringify(
|
|
1129
|
-
{
|
|
1130
|
-
cursor,
|
|
1131
|
-
range,
|
|
1132
|
-
cells: model.sheet.cells,
|
|
1133
|
-
rowMeta: model.sheet.rowMeta,
|
|
1134
|
-
columnMeta: model.sheet.columnMeta,
|
|
1135
|
-
formatting: model.sheet.formatting,
|
|
1136
|
-
},
|
|
1137
|
-
undefined,
|
|
1138
|
-
2,
|
|
1139
|
-
)}
|
|
1140
|
-
</pre>
|
|
1141
|
-
</div>
|
|
1142
|
-
);
|
|
1143
|
-
};
|
|
1144
|
-
|
|
1145
|
-
//
|
|
1146
|
-
// Grid
|
|
1147
|
-
//
|
|
1148
|
-
|
|
1149
|
-
export const Sheet = {
|
|
1150
|
-
Root: SheetRoot,
|
|
1151
|
-
Main: SheetMain,
|
|
1152
|
-
Rows: SheetRows,
|
|
1153
|
-
Columns: SheetColumns,
|
|
1154
|
-
Grid: SheetGrid,
|
|
1155
|
-
Cell: SheetCell,
|
|
1156
|
-
StatusBar: SheetStatusBar,
|
|
1157
|
-
Debug: SheetDebug,
|
|
1158
|
-
};
|
|
1159
|
-
|
|
1160
|
-
export type { SheetRootProps, SheetMainProps, SheetRowsProps, SheetColumnsProps, SheetGridProps, SheetCellProps };
|