@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
|
@@ -2,167 +2,265 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
type Icon,
|
|
7
|
-
Calendar,
|
|
8
|
-
ChatText,
|
|
9
|
-
CurrencyDollar,
|
|
10
|
-
Eraser,
|
|
11
|
-
HighlighterCircle,
|
|
12
|
-
TextAlignCenter,
|
|
13
|
-
TextAlignLeft,
|
|
14
|
-
TextAlignRight,
|
|
15
|
-
} from '@phosphor-icons/react';
|
|
16
5
|
import { createContext } from '@radix-ui/react-context';
|
|
17
|
-
import React, { type PropsWithChildren } from 'react';
|
|
6
|
+
import React, { type PropsWithChildren, useCallback, useMemo } from 'react';
|
|
18
7
|
|
|
8
|
+
import { useIntentDispatcher } from '@dxos/app-framework';
|
|
19
9
|
import {
|
|
20
|
-
|
|
21
|
-
ElevationProvider,
|
|
10
|
+
Icon,
|
|
22
11
|
Toolbar as NaturalToolbar,
|
|
23
|
-
type ThemedClassName,
|
|
24
12
|
useTranslation,
|
|
13
|
+
Tooltip,
|
|
14
|
+
type ToolbarToggleGroupItemProps as NaturalToolbarToggleGroupItemProps,
|
|
15
|
+
type ToolbarButtonProps as NaturalToolbarButtonProps,
|
|
16
|
+
type ToolbarToggleProps as NaturalToolbarToggleProps,
|
|
17
|
+
type ThemedClassName,
|
|
25
18
|
} from '@dxos/react-ui';
|
|
19
|
+
import { useAttention } from '@dxos/react-ui-attention';
|
|
20
|
+
import { nonNullable } from '@dxos/util';
|
|
26
21
|
|
|
27
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
addressToIndex,
|
|
24
|
+
type AlignKey,
|
|
25
|
+
type AlignValue,
|
|
26
|
+
type CommentKey,
|
|
27
|
+
type CommentValue,
|
|
28
|
+
inRange,
|
|
29
|
+
type StyleKey,
|
|
30
|
+
type StyleValue,
|
|
31
|
+
} from '../../defs';
|
|
28
32
|
import { SHEET_PLUGIN } from '../../meta';
|
|
29
|
-
import { type
|
|
33
|
+
import { type SheetType } from '../../types';
|
|
34
|
+
import { useSheetContext } from '../SheetContext';
|
|
30
35
|
|
|
31
36
|
//
|
|
32
|
-
//
|
|
37
|
+
// Buttons
|
|
38
|
+
//
|
|
39
|
+
|
|
40
|
+
const buttonStyles = 'min-bs-0 p-2';
|
|
41
|
+
const tooltipProps = { side: 'bottom' as const, classNames: 'z-10' };
|
|
42
|
+
|
|
43
|
+
const ToolbarSeparator = () => <div role='separator' className='grow' />;
|
|
44
|
+
|
|
45
|
+
//
|
|
46
|
+
// ToolbarItem
|
|
33
47
|
//
|
|
34
48
|
|
|
35
|
-
|
|
49
|
+
type ToolbarItemProps =
|
|
50
|
+
| (NaturalToolbarButtonProps & { itemType: 'button'; icon: string })
|
|
51
|
+
| (NaturalToolbarToggleGroupItemProps & { itemType: 'toggleGroupItem'; icon: string })
|
|
52
|
+
| (NaturalToolbarToggleProps & { itemType: 'toggle'; icon: string });
|
|
36
53
|
|
|
37
|
-
export
|
|
38
|
-
|
|
54
|
+
export const ToolbarItem = ({ itemType, icon, children, ...props }: ToolbarItemProps) => {
|
|
55
|
+
const Invoker =
|
|
56
|
+
itemType === 'toggleGroupItem'
|
|
57
|
+
? NaturalToolbar.ToggleGroupItem
|
|
58
|
+
: itemType === 'toggle'
|
|
59
|
+
? NaturalToolbar.Toggle
|
|
60
|
+
: NaturalToolbar.Button;
|
|
61
|
+
return (
|
|
62
|
+
<Tooltip.Root>
|
|
63
|
+
<Tooltip.Trigger asChild>
|
|
64
|
+
{/* TODO(thure): type the props spread better. */}
|
|
65
|
+
<Invoker variant='ghost' {...(props as any)} classNames={buttonStyles}>
|
|
66
|
+
<Icon icon={icon} size={5} />
|
|
67
|
+
<span className='sr-only'>{children}</span>
|
|
68
|
+
</Invoker>
|
|
69
|
+
</Tooltip.Trigger>
|
|
70
|
+
<Tooltip.Portal>
|
|
71
|
+
<Tooltip.Content {...tooltipProps}>
|
|
72
|
+
{children}
|
|
73
|
+
<Tooltip.Arrow />
|
|
74
|
+
</Tooltip.Content>
|
|
75
|
+
</Tooltip.Portal>
|
|
76
|
+
</Tooltip.Root>
|
|
77
|
+
);
|
|
39
78
|
};
|
|
40
79
|
|
|
41
|
-
|
|
80
|
+
//
|
|
81
|
+
// Root
|
|
82
|
+
//
|
|
83
|
+
|
|
84
|
+
type AlignAction = { key: AlignKey; value: AlignValue };
|
|
85
|
+
type CommentAction = { key: CommentKey; value: CommentValue; cellContent?: string };
|
|
86
|
+
type StyleAction = { key: StyleKey; value: StyleValue };
|
|
87
|
+
|
|
88
|
+
export type ToolbarAction = StyleAction | AlignAction | CommentAction;
|
|
89
|
+
|
|
90
|
+
export type ToolbarActionType = ToolbarAction['key'];
|
|
91
|
+
|
|
92
|
+
export type ToolbarActionHandler = (action: ToolbarAction) => void;
|
|
42
93
|
|
|
43
94
|
export type ToolbarProps = ThemedClassName<
|
|
44
95
|
PropsWithChildren<{
|
|
45
|
-
|
|
96
|
+
role?: string;
|
|
46
97
|
}>
|
|
47
98
|
>;
|
|
48
99
|
|
|
49
|
-
const [ToolbarContextProvider, useToolbarContext] = createContext<
|
|
100
|
+
const [ToolbarContextProvider, useToolbarContext] = createContext<{ onAction: (action: ToolbarAction) => void }>(
|
|
101
|
+
'Toolbar',
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
// TODO(Zan): Factor out, copied this from MarkdownPlugin.
|
|
105
|
+
const sectionToolbarLayout =
|
|
106
|
+
'bs-[--rail-action] bg-[--sticky-bg] sticky block-start-0 __-block-start-px transition-opacity';
|
|
107
|
+
|
|
108
|
+
type Range = SheetType['ranges'][number];
|
|
109
|
+
|
|
110
|
+
const ToolbarRoot = ({ children, role, classNames }: ToolbarProps) => {
|
|
111
|
+
const { id, model, range, cursor } = useSheetContext();
|
|
112
|
+
const { hasAttention } = useAttention(id);
|
|
113
|
+
const dispatch = useIntentDispatcher();
|
|
114
|
+
|
|
115
|
+
// TODO(Zan): Centralise the toolbar action handler. Current implementation in stories.
|
|
116
|
+
const handleAction = useCallback(
|
|
117
|
+
(action: ToolbarAction) => {
|
|
118
|
+
switch (action.key) {
|
|
119
|
+
case 'align':
|
|
120
|
+
if (cursor) {
|
|
121
|
+
const index = model.sheet.ranges?.findIndex(
|
|
122
|
+
(range) => range.key === action.key && inRange(range.range, cursor),
|
|
123
|
+
);
|
|
124
|
+
const nextRange = range ? { from: range.from, to: range.to ?? range.from } : { from: cursor, to: cursor };
|
|
125
|
+
const nextRangeEntity = {
|
|
126
|
+
range: nextRange as Range['range'],
|
|
127
|
+
key: action.key,
|
|
128
|
+
value: action.value,
|
|
129
|
+
};
|
|
130
|
+
if (index < 0) {
|
|
131
|
+
model.sheet.ranges?.push(nextRangeEntity);
|
|
132
|
+
} else {
|
|
133
|
+
model.sheet.ranges?.splice(index, 1, nextRangeEntity);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
case 'style':
|
|
138
|
+
if (action.value === 'unset') {
|
|
139
|
+
const index = model.sheet.ranges?.findIndex((range) => range.key === action.key);
|
|
140
|
+
if (index >= 0) {
|
|
141
|
+
model.sheet.ranges?.splice(index, 1);
|
|
142
|
+
}
|
|
143
|
+
} else if (range || cursor) {
|
|
144
|
+
const nextRange = range ? { from: range.from, to: range.to ?? range.from } : { from: cursor, to: cursor };
|
|
145
|
+
model.sheet.ranges?.push({
|
|
146
|
+
range: nextRange as Range['range'],
|
|
147
|
+
key: action.key,
|
|
148
|
+
value: action.value,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
case 'comment': {
|
|
153
|
+
// TODO(Zan): We shouldn't hardcode the action ID.
|
|
154
|
+
void dispatch({
|
|
155
|
+
action: 'dxos.org/plugin/thread/action/create',
|
|
156
|
+
data: {
|
|
157
|
+
cursor: action.value,
|
|
158
|
+
name: action.cellContent,
|
|
159
|
+
subject: model.sheet,
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
[model.sheet, range, cursor, dispatch],
|
|
166
|
+
);
|
|
50
167
|
|
|
51
|
-
const ToolbarRoot = ({ children, onAction, classNames }: ToolbarProps) => {
|
|
52
168
|
return (
|
|
53
|
-
<ToolbarContextProvider onAction={
|
|
54
|
-
<
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
169
|
+
<ToolbarContextProvider onAction={handleAction}>
|
|
170
|
+
<NaturalToolbar.Root
|
|
171
|
+
classNames={[
|
|
172
|
+
...(role === 'section'
|
|
173
|
+
? ['z-[2] group-focus-within/section:visible', !hasAttention && 'invisible', sectionToolbarLayout]
|
|
174
|
+
: ['attention-surface']),
|
|
175
|
+
classNames,
|
|
176
|
+
]}
|
|
177
|
+
>
|
|
178
|
+
{children}
|
|
179
|
+
</NaturalToolbar.Root>
|
|
61
180
|
</ToolbarContextProvider>
|
|
62
181
|
);
|
|
63
182
|
};
|
|
64
183
|
|
|
65
184
|
// TODO(burdon): Generalize.
|
|
66
185
|
// TODO(burdon): Detect and display current state.
|
|
67
|
-
type ButtonProps = {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
disabled?: (state: Formatting) => boolean;
|
|
186
|
+
type ButtonProps<T> = {
|
|
187
|
+
value: T;
|
|
188
|
+
icon: string;
|
|
189
|
+
disabled?: (state: Range) => boolean;
|
|
72
190
|
};
|
|
73
191
|
|
|
74
192
|
//
|
|
75
193
|
// Alignment
|
|
76
194
|
//
|
|
77
195
|
|
|
78
|
-
const
|
|
79
|
-
{
|
|
80
|
-
{
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const Format = () => {
|
|
84
|
-
const { onAction } = useToolbarContext('Format');
|
|
85
|
-
const { t } = useTranslation(SHEET_PLUGIN);
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<NaturalToolbar.ToggleGroup
|
|
89
|
-
type='single'
|
|
90
|
-
// value={cellStyles.filter(({ getState }) => state && getState(state)).map(({ type }) => type)}
|
|
91
|
-
>
|
|
92
|
-
{formatOptions.map(({ type, getState, Icon }) => (
|
|
93
|
-
<ToolbarToggleButton
|
|
94
|
-
key={type}
|
|
95
|
-
value={type}
|
|
96
|
-
Icon={Icon}
|
|
97
|
-
// disabled={state?.blockType === 'codeblock'}
|
|
98
|
-
// onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
|
|
99
|
-
onClick={() => onAction?.({ type })}
|
|
100
|
-
>
|
|
101
|
-
{t(`toolbar ${type} label`)}
|
|
102
|
-
</ToolbarToggleButton>
|
|
103
|
-
))}
|
|
104
|
-
</NaturalToolbar.ToggleGroup>
|
|
105
|
-
);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const alignmentOptions: ButtonProps[] = [
|
|
109
|
-
{ type: 'left', Icon: TextAlignLeft, getState: (state) => false },
|
|
110
|
-
{ type: 'center', Icon: TextAlignCenter, getState: (state) => false },
|
|
111
|
-
{ type: 'right', Icon: TextAlignRight, getState: (state) => false },
|
|
196
|
+
const alignmentOptions: ButtonProps<AlignValue>[] = [
|
|
197
|
+
{ value: 'start', icon: 'ph--text-align-left--regular' },
|
|
198
|
+
{ value: 'center', icon: 'ph--text-align-center--regular' },
|
|
199
|
+
{ value: 'end', icon: 'ph--text-align-right--regular' },
|
|
112
200
|
];
|
|
113
201
|
|
|
114
202
|
const Alignment = () => {
|
|
203
|
+
const { cursor, model } = useSheetContext();
|
|
115
204
|
const { onAction } = useToolbarContext('Alignment');
|
|
116
205
|
const { t } = useTranslation(SHEET_PLUGIN);
|
|
117
206
|
|
|
207
|
+
const value = useMemo(
|
|
208
|
+
() =>
|
|
209
|
+
cursor
|
|
210
|
+
? model.sheet.ranges?.find(({ range, key }) => key === 'alignment' && inRange(range, cursor))?.value
|
|
211
|
+
: undefined,
|
|
212
|
+
[cursor, model.sheet.ranges],
|
|
213
|
+
);
|
|
214
|
+
|
|
118
215
|
return (
|
|
119
216
|
<NaturalToolbar.ToggleGroup
|
|
120
217
|
type='single'
|
|
121
|
-
|
|
218
|
+
value={value}
|
|
219
|
+
onValueChange={(value: AlignValue) => onAction?.({ key: 'align', value })}
|
|
122
220
|
>
|
|
123
|
-
{alignmentOptions.map(({
|
|
124
|
-
<
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
Icon={Icon}
|
|
128
|
-
// disabled={state?.blockType === 'codeblock'}
|
|
129
|
-
// onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
|
|
130
|
-
onClick={() => onAction?.({ type })}
|
|
131
|
-
>
|
|
132
|
-
{t(`toolbar ${type} label`)}
|
|
133
|
-
</ToolbarToggleButton>
|
|
221
|
+
{alignmentOptions.map(({ value, icon }) => (
|
|
222
|
+
<ToolbarItem itemType='toggleGroupItem' key={value} value={value} icon={icon}>
|
|
223
|
+
{t(`toolbar ${value} label`)}
|
|
224
|
+
</ToolbarItem>
|
|
134
225
|
))}
|
|
135
226
|
</NaturalToolbar.ToggleGroup>
|
|
136
227
|
);
|
|
137
228
|
};
|
|
138
229
|
|
|
139
|
-
const styleOptions: ButtonProps[] = [
|
|
140
|
-
{ type: 'clear', Icon: Eraser, getState: (state) => false },
|
|
141
|
-
{ type: 'highlight', Icon: HighlighterCircle, getState: (state) => false },
|
|
142
|
-
];
|
|
230
|
+
const styleOptions: ButtonProps<StyleValue>[] = [{ value: 'highlight', icon: 'ph--highlighter--regular' }];
|
|
143
231
|
|
|
144
232
|
const Styles = () => {
|
|
145
|
-
const {
|
|
233
|
+
const { cursor, model } = useSheetContext();
|
|
234
|
+
const { onAction } = useToolbarContext('Styles');
|
|
146
235
|
const { t } = useTranslation(SHEET_PLUGIN);
|
|
147
236
|
|
|
237
|
+
const activeValues = useMemo(
|
|
238
|
+
() =>
|
|
239
|
+
cursor
|
|
240
|
+
? model.sheet.ranges
|
|
241
|
+
?.filter(({ range, key }) => key === 'style' && inRange(range, cursor))
|
|
242
|
+
.reduce((acc, { value }) => {
|
|
243
|
+
acc.add(value);
|
|
244
|
+
return acc;
|
|
245
|
+
}, new Set())
|
|
246
|
+
: undefined,
|
|
247
|
+
[cursor, model.sheet.ranges],
|
|
248
|
+
);
|
|
249
|
+
|
|
148
250
|
return (
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
Icon={Icon}
|
|
158
|
-
// disabled={state?.blockType === 'codeblock'}
|
|
159
|
-
// onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
|
|
160
|
-
onClick={() => onAction?.({ type })}
|
|
251
|
+
<>
|
|
252
|
+
{styleOptions.map(({ value, icon }) => (
|
|
253
|
+
<ToolbarItem
|
|
254
|
+
itemType='toggle'
|
|
255
|
+
key={value}
|
|
256
|
+
pressed={activeValues?.has(value)}
|
|
257
|
+
onPressedChange={(nextPressed: boolean) => onAction?.({ key: 'style', value: nextPressed ? value : 'unset' })}
|
|
258
|
+
icon={icon}
|
|
161
259
|
>
|
|
162
|
-
{t(`toolbar ${
|
|
163
|
-
</
|
|
260
|
+
{t(`toolbar ${value} label`)}
|
|
261
|
+
</ToolbarItem>
|
|
164
262
|
))}
|
|
165
|
-
|
|
263
|
+
</>
|
|
166
264
|
);
|
|
167
265
|
};
|
|
168
266
|
|
|
@@ -171,18 +269,51 @@ const Styles = () => {
|
|
|
171
269
|
//
|
|
172
270
|
|
|
173
271
|
const Actions = () => {
|
|
174
|
-
|
|
272
|
+
const { onAction } = useToolbarContext('Actions');
|
|
273
|
+
const { cursor, range, model } = useSheetContext();
|
|
175
274
|
const { t } = useTranslation(SHEET_PLUGIN);
|
|
275
|
+
|
|
276
|
+
const overlapsCommentAnchor = (model.sheet.threads ?? [])
|
|
277
|
+
.filter(nonNullable)
|
|
278
|
+
.filter((thread) => thread.status !== 'resolved')
|
|
279
|
+
.some((thread) => {
|
|
280
|
+
if (!cursor) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
return addressToIndex(model.sheet, cursor) === thread.anchor;
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
const hasCursor = !!cursor;
|
|
287
|
+
const cursorOnly = hasCursor && !range && !overlapsCommentAnchor;
|
|
288
|
+
|
|
289
|
+
const tooltipLabelKey = !hasCursor
|
|
290
|
+
? 'no cursor label'
|
|
291
|
+
: overlapsCommentAnchor
|
|
292
|
+
? 'selection overlaps existing comment label'
|
|
293
|
+
: range
|
|
294
|
+
? 'comment ranges not supported label'
|
|
295
|
+
: 'comment label';
|
|
296
|
+
|
|
176
297
|
return (
|
|
177
|
-
<
|
|
298
|
+
<ToolbarItem
|
|
299
|
+
itemType='button'
|
|
178
300
|
value='comment'
|
|
179
|
-
|
|
301
|
+
icon='ph--chat-text--regular'
|
|
180
302
|
data-testid='editor.toolbar.comment'
|
|
181
|
-
|
|
182
|
-
|
|
303
|
+
onClick={() => {
|
|
304
|
+
if (!cursor) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
return onAction?.({
|
|
308
|
+
key: 'comment',
|
|
309
|
+
value: addressToIndex(model.sheet, cursor),
|
|
310
|
+
cellContent: model.getCellText(cursor),
|
|
311
|
+
});
|
|
312
|
+
}}
|
|
313
|
+
disabled={!cursorOnly || overlapsCommentAnchor}
|
|
183
314
|
>
|
|
184
|
-
{t(
|
|
185
|
-
</
|
|
315
|
+
{t(tooltipLabelKey)}
|
|
316
|
+
</ToolbarItem>
|
|
186
317
|
);
|
|
187
318
|
};
|
|
188
319
|
|
|
@@ -190,7 +321,6 @@ export const Toolbar = {
|
|
|
190
321
|
Root: ToolbarRoot,
|
|
191
322
|
Separator: ToolbarSeparator,
|
|
192
323
|
Alignment,
|
|
193
|
-
Format,
|
|
194
324
|
Styles,
|
|
195
325
|
Actions,
|
|
196
326
|
};
|
package/src/components/index.ts
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import { lazy } from 'react';
|
|
6
6
|
|
|
7
7
|
export * from './ComputeGraph';
|
|
8
|
+
export * from './GridSheet';
|
|
9
|
+
export * from './SheetContext';
|
|
8
10
|
|
|
9
|
-
|
|
10
|
-
export const SheetContainer = React.lazy(() => import('./SheetContainer'));
|
|
11
|
+
export const SheetContainer = lazy(() => import('./SheetContainer'));
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type ClassNameValue } from '@dxos/react-ui';
|
|
6
|
+
|
|
7
|
+
import { type SheetType } from '../types';
|
|
8
|
+
|
|
9
|
+
export const alignKey = 'align';
|
|
10
|
+
export type AlignKey = typeof alignKey;
|
|
11
|
+
export type AlignValue = 'start' | 'center' | 'end' | 'unset';
|
|
12
|
+
|
|
13
|
+
export const commentKey = 'comment';
|
|
14
|
+
export type CommentKey = typeof commentKey;
|
|
15
|
+
export type CommentValue = string;
|
|
16
|
+
|
|
17
|
+
export const styleKey = 'style';
|
|
18
|
+
export type StyleKey = typeof styleKey;
|
|
19
|
+
export type StyleValue = 'highlight' | 'unset';
|
|
20
|
+
|
|
21
|
+
export const cellClassNameForRange = ({ key, value }: SheetType['ranges'][number]): ClassNameValue => {
|
|
22
|
+
switch (key) {
|
|
23
|
+
case 'align':
|
|
24
|
+
switch (value) {
|
|
25
|
+
case 'start':
|
|
26
|
+
return 'text-start';
|
|
27
|
+
case 'center':
|
|
28
|
+
return 'text-center';
|
|
29
|
+
case 'end':
|
|
30
|
+
return 'text-end';
|
|
31
|
+
default:
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
case 'comment':
|
|
35
|
+
return 'bg-gridComment';
|
|
36
|
+
case 'style':
|
|
37
|
+
switch (value) {
|
|
38
|
+
case 'highlight':
|
|
39
|
+
return 'bg-gridHighlight';
|
|
40
|
+
default:
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
default:
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
@@ -3,15 +3,14 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { getIndices, sortByIndex, getIndicesBelow, getIndicesAbove, getIndicesBetween } from '@tldraw/indices';
|
|
6
|
-
import { expect } from '
|
|
7
|
-
import { describe, test } from 'vitest';
|
|
6
|
+
import { describe, expect, test } from 'vitest';
|
|
8
7
|
|
|
9
8
|
import { inRange, addressFromA1Notation, addressToA1Notation, rangeFromA1Notation, rangeToA1Notation } from './types';
|
|
10
9
|
|
|
11
10
|
describe('cell', () => {
|
|
12
11
|
test('posToA1Notation', () => {
|
|
13
|
-
expect(addressToA1Notation({
|
|
14
|
-
expect(addressFromA1Notation('C2')).to.deep.eq({
|
|
12
|
+
expect(addressToA1Notation({ col: 0, row: 0 })).to.eq('A1');
|
|
13
|
+
expect(addressFromA1Notation('C2')).to.deep.eq({ col: 2, row: 1 });
|
|
15
14
|
});
|
|
16
15
|
|
|
17
16
|
test('rangeToA1Notation', () => {
|
|
@@ -56,19 +55,19 @@ describe('cell', () => {
|
|
|
56
55
|
// Values.
|
|
57
56
|
const cells: Record<string, any> = {};
|
|
58
57
|
const setCell = (cell: string, value: any) => {
|
|
59
|
-
const {
|
|
58
|
+
const { col, row } = addressFromA1Notation(cell);
|
|
60
59
|
// Reallocate if > current bounds.
|
|
61
|
-
if (
|
|
62
|
-
insertIndex(columns,
|
|
60
|
+
if (col >= columns.length) {
|
|
61
|
+
insertIndex(columns, col);
|
|
63
62
|
}
|
|
64
63
|
if (row >= rows.length) {
|
|
65
64
|
insertIndex(rows, row);
|
|
66
65
|
}
|
|
67
|
-
const index = `${columns[
|
|
66
|
+
const index = `${columns[col]}@${rows[row]}`;
|
|
68
67
|
cells[index] = value;
|
|
69
68
|
};
|
|
70
69
|
|
|
71
|
-
expect(addressFromA1Notation('A1')).to.deep.eq({
|
|
70
|
+
expect(addressFromA1Notation('A1')).to.deep.eq({ col: 0, row: 0 });
|
|
72
71
|
|
|
73
72
|
expect(columns).to.deep.eq(['a1', 'a2', 'a3', 'a4', 'a5']);
|
|
74
73
|
insertIndex(columns, 7);
|
|
@@ -4,33 +4,43 @@
|
|
|
4
4
|
|
|
5
5
|
import { invariant } from '@dxos/invariant';
|
|
6
6
|
|
|
7
|
-
export const
|
|
7
|
+
export const DEFAULT_ROWS = 50;
|
|
8
|
+
export const DEFAULT_COLUMNS = 26;
|
|
9
|
+
|
|
10
|
+
export const MAX_ROWS = 500;
|
|
11
|
+
export const MAX_COLUMNS = 26 * 2;
|
|
12
|
+
|
|
13
|
+
export type CellAddress = { col: number; row: number };
|
|
8
14
|
|
|
9
|
-
export type CellAddress = { column: number; row: number };
|
|
10
15
|
export type CellRange = { from: CellAddress; to?: CellAddress };
|
|
11
16
|
|
|
17
|
+
export type CellIndex = string;
|
|
18
|
+
|
|
19
|
+
export type CellContentValue = number | string | boolean | null;
|
|
20
|
+
|
|
12
21
|
export const posEquals = (a: CellAddress | undefined, b: CellAddress | undefined) => {
|
|
13
|
-
return a?.
|
|
22
|
+
return a?.col === b?.col && a?.row === b?.row;
|
|
14
23
|
};
|
|
15
24
|
|
|
16
|
-
export const columnLetter = (
|
|
17
|
-
invariant(
|
|
25
|
+
export const columnLetter = (col: number): string => {
|
|
26
|
+
invariant(col < MAX_COLUMNS, `Invalid column: ${col}`);
|
|
18
27
|
return (
|
|
19
|
-
(
|
|
20
|
-
String.fromCharCode('A'.charCodeAt(0) + (
|
|
28
|
+
(col >= 26 ? String.fromCharCode('A'.charCodeAt(0) + Math.floor(col / 26) - 1) : '') +
|
|
29
|
+
String.fromCharCode('A'.charCodeAt(0) + (col % 26))
|
|
21
30
|
);
|
|
22
31
|
};
|
|
23
32
|
|
|
24
|
-
export const addressToA1Notation = ({
|
|
25
|
-
return `${columnLetter(
|
|
33
|
+
export const addressToA1Notation = ({ col, row }: CellAddress): string => {
|
|
34
|
+
return `${columnLetter(col)}${row + 1}`;
|
|
26
35
|
};
|
|
27
36
|
|
|
37
|
+
// TODO(burdon): See simpleCellAddressFromString
|
|
28
38
|
export const addressFromA1Notation = (ref: string): CellAddress => {
|
|
29
39
|
const match = ref.match(/([A-Z]+)(\d+)/);
|
|
30
40
|
invariant(match, `Invalid notation: ${ref}`);
|
|
31
41
|
return {
|
|
32
42
|
row: parseInt(match[2], 10) - 1,
|
|
33
|
-
|
|
43
|
+
col: match[1].split('').reduce((acc, c) => acc * 26 + c.charCodeAt(0) - 'A'.charCodeAt(0) + 1, 0) - 1,
|
|
34
44
|
};
|
|
35
45
|
};
|
|
36
46
|
|
|
@@ -59,13 +69,13 @@ export const inRange = (range: CellRange | undefined, cell: CellAddress): boolea
|
|
|
59
69
|
return false;
|
|
60
70
|
}
|
|
61
71
|
|
|
62
|
-
const {
|
|
63
|
-
const {
|
|
72
|
+
const { col: c1, row: r1 } = from;
|
|
73
|
+
const { col: c2, row: r2 } = to;
|
|
64
74
|
const cMin = Math.min(c1, c2);
|
|
65
75
|
const cMax = Math.max(c1, c2);
|
|
66
76
|
const rMin = Math.min(r1, r2);
|
|
67
77
|
const rMax = Math.max(r1, r2);
|
|
68
78
|
|
|
69
|
-
const {
|
|
70
|
-
return
|
|
79
|
+
const { col, row } = cell;
|
|
80
|
+
return col >= cMin && col <= cMax && row >= rMin && row <= rMax;
|
|
71
81
|
};
|