@dxos/plugin-sheet 0.6.13-main.ed424a1 → 0.6.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/SheetContainer-U4H5D34A.mjs +1772 -0
- package/dist/lib/browser/SheetContainer-U4H5D34A.mjs.map +7 -0
- package/dist/lib/browser/chunk-APHOLYUB.mjs +175 -0
- package/dist/lib/browser/chunk-APHOLYUB.mjs.map +7 -0
- package/dist/lib/{node-esm/chunk-5WPZCXNS.mjs → browser/chunk-D5AGLXJP.mjs} +678 -411
- package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +7 -0
- package/dist/lib/browser/chunk-FUAGSXA4.mjs +82 -0
- package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +7 -0
- package/dist/lib/browser/chunk-JRL5LGCE.mjs +18 -0
- package/dist/lib/browser/chunk-JRL5LGCE.mjs.map +7 -0
- package/dist/lib/browser/chunk-NU4PBN33.mjs +8 -0
- package/dist/lib/browser/chunk-NU4PBN33.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +62 -93
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +1 -1
- package/dist/lib/browser/testing.mjs +92 -0
- package/dist/lib/browser/testing.mjs.map +7 -0
- package/dist/lib/browser/types.mjs +12 -6
- package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs +1765 -0
- package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +7 -0
- package/dist/lib/node/{chunk-5XPK2V4A.cjs → chunk-5KKJ4NPP.cjs} +678 -418
- package/dist/lib/node/chunk-5KKJ4NPP.cjs.map +7 -0
- package/dist/lib/node/chunk-BJ6ZD7MN.cjs +51 -0
- package/dist/lib/node/chunk-BJ6ZD7MN.cjs.map +7 -0
- package/dist/lib/node/chunk-CN3RPESU.cjs +202 -0
- package/dist/lib/node/chunk-CN3RPESU.cjs.map +7 -0
- package/dist/lib/node/{chunk-NZARD7UP.cjs → chunk-DSYKOI4E.cjs} +51 -40
- package/dist/lib/node/chunk-DSYKOI4E.cjs.map +7 -0
- package/dist/lib/node/chunk-PYXHNAAK.cjs +40 -0
- package/dist/lib/node/chunk-PYXHNAAK.cjs.map +7 -0
- package/dist/lib/node/index.cjs +69 -105
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.cjs +3 -3
- package/dist/lib/node/meta.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing.cjs +111 -0
- package/dist/lib/node/testing.cjs.map +7 -0
- package/dist/lib/node/types.cjs +15 -9
- package/dist/lib/node/types.cjs.map +2 -2
- package/dist/types/src/SheetPlugin.d.ts.map +1 -1
- package/dist/types/src/components/CellEditor/CellEditor.d.ts +14 -0
- package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +1 -0
- package/dist/types/src/components/{GridSheet/SheetCellEditor.stories.d.ts → CellEditor/CellEditor.stories.d.ts} +4 -4
- package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +1 -0
- package/dist/types/src/{extensions/editor → components/CellEditor}/extension.d.ts +1 -1
- package/dist/types/src/components/CellEditor/extension.d.ts.map +1 -0
- package/dist/types/src/components/CellEditor/extension.test.d.ts.map +1 -0
- package/dist/types/src/components/CellEditor/index.d.ts +3 -0
- package/dist/types/src/components/CellEditor/index.d.ts.map +1 -0
- package/dist/types/src/{graph/functions → components/ComputeGraph}/async-function.d.ts +5 -14
- package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/custom.d.ts +21 -0
- package/dist/types/src/components/ComputeGraph/custom.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/edge-function.d.ts +20 -0
- package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/graph-context.d.ts +12 -0
- package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts +2 -0
- package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/graph.d.ts +26 -0
- package/dist/types/src/components/ComputeGraph/graph.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/index.d.ts +3 -1
- package/dist/types/src/components/ComputeGraph/index.d.ts.map +1 -1
- package/dist/types/src/components/Sheet/Sheet.d.ts +55 -0
- package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/Sheet.stories.d.ts +54 -0
- package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/formatting.d.ts +14 -0
- package/dist/types/src/components/Sheet/formatting.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/grid.d.ts +52 -0
- package/dist/types/src/components/Sheet/grid.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/index.d.ts +2 -0
- package/dist/types/src/components/Sheet/index.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/nav.d.ts +29 -0
- package/dist/types/src/components/Sheet/nav.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/sheet-context.d.ts +25 -0
- package/dist/types/src/components/Sheet/sheet-context.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/util.d.ts +18 -0
- package/dist/types/src/components/Sheet/util.d.ts.map +1 -0
- package/dist/types/src/components/SheetContainer.d.ts +9 -0
- package/dist/types/src/components/SheetContainer.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +9 -33
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +15 -19
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/common.d.ts +20 -0
- package/dist/types/src/components/Toolbar/common.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +2 -3
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +9 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/{graph/functions/function-defs.d.ts → model/functions.d.ts} +1 -1
- package/dist/types/src/model/functions.d.ts.map +1 -0
- package/dist/types/src/model/index.d.ts +3 -2
- package/dist/types/src/model/index.d.ts.map +1 -1
- package/dist/types/src/model/model.browser.test.d.ts +2 -0
- package/dist/types/src/model/model.browser.test.d.ts.map +1 -0
- package/dist/types/src/model/{sheet-model.d.ts → model.d.ts} +67 -13
- package/dist/types/src/model/model.d.ts.map +1 -0
- package/dist/types/src/{defs → model}/types.d.ts +3 -8
- package/dist/types/src/model/types.d.ts.map +1 -0
- package/dist/types/src/model/types.test.d.ts.map +1 -0
- package/dist/types/src/model/util.d.ts +15 -0
- package/dist/types/src/model/util.d.ts.map +1 -0
- package/dist/types/src/testing.d.ts +9 -0
- package/dist/types/src/testing.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +12 -17
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +40 -125
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +52 -58
- package/src/SheetPlugin.tsx +74 -52
- package/src/components/{GridSheet/SheetCellEditor.stories.tsx → CellEditor/CellEditor.stories.tsx} +8 -8
- package/src/components/CellEditor/CellEditor.tsx +113 -0
- package/src/{extensions/editor → components/CellEditor}/extension.test.ts +6 -4
- package/src/{extensions/editor → components/CellEditor}/extension.ts +6 -5
- package/src/{extensions/editor → components/CellEditor}/index.ts +1 -0
- package/src/{graph/functions → components/ComputeGraph}/async-function.ts +15 -25
- package/src/{graph/testing/test-plugin.ts → components/ComputeGraph/custom.ts} +14 -44
- package/src/{graph/functions → components/ComputeGraph}/edge-function.ts +14 -16
- package/src/components/ComputeGraph/graph-context.tsx +50 -0
- package/src/components/ComputeGraph/graph.browser.test.ts +50 -0
- package/src/components/ComputeGraph/graph.ts +62 -0
- package/src/components/ComputeGraph/index.ts +3 -1
- package/src/components/Sheet/Sheet.stories.tsx +287 -0
- package/src/components/Sheet/Sheet.tsx +1160 -0
- package/src/components/Sheet/formatting.ts +106 -0
- package/src/components/Sheet/grid.ts +191 -0
- package/src/{testing → components/Sheet}/index.ts +1 -1
- package/src/components/Sheet/nav.ts +157 -0
- package/src/components/Sheet/sheet-context.tsx +150 -0
- package/src/components/Sheet/util.ts +56 -0
- package/src/components/SheetContainer.tsx +34 -0
- package/src/components/Toolbar/Toolbar.tsx +112 -242
- package/src/components/Toolbar/common.tsx +72 -0
- package/src/components/index.ts +0 -2
- package/src/meta.tsx +18 -0
- package/src/model/index.ts +3 -2
- package/src/model/model.browser.test.ts +100 -0
- package/src/model/model.ts +550 -0
- package/src/{defs → model}/types.test.ts +9 -8
- package/src/{defs → model}/types.ts +14 -24
- package/src/model/util.ts +36 -0
- package/src/testing.ts +50 -0
- package/src/translations.ts +1 -6
- package/src/types.ts +47 -40
- package/dist/lib/browser/SheetContainer-RVRACGCZ.mjs +0 -290
- package/dist/lib/browser/SheetContainer-RVRACGCZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-BWN5DZWZ.mjs +0 -74
- package/dist/lib/browser/chunk-BWN5DZWZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-D3QTX46O.mjs +0 -14
- package/dist/lib/browser/chunk-D3QTX46O.mjs.map +0 -7
- package/dist/lib/browser/chunk-GSV5QNLD.mjs +0 -2966
- package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +0 -7
- package/dist/lib/browser/chunk-HOG37RYS.mjs +0 -1528
- package/dist/lib/browser/chunk-HOG37RYS.mjs.map +0 -7
- package/dist/lib/browser/graph-M4IQ76QX.mjs +0 -33
- package/dist/lib/browser/graph-M4IQ76QX.mjs.map +0 -7
- package/dist/lib/node/SheetContainer-J7XROAMN.cjs +0 -300
- package/dist/lib/node/SheetContainer-J7XROAMN.cjs.map +0 -7
- package/dist/lib/node/chunk-5XPK2V4A.cjs.map +0 -7
- package/dist/lib/node/chunk-AXQZA2YS.cjs +0 -1527
- package/dist/lib/node/chunk-AXQZA2YS.cjs.map +0 -7
- package/dist/lib/node/chunk-NZARD7UP.cjs.map +0 -7
- package/dist/lib/node/chunk-QIFIGEKV.cjs +0 -37
- package/dist/lib/node/chunk-QIFIGEKV.cjs.map +0 -7
- package/dist/lib/node/graph-Q3N2X26H.cjs +0 -55
- package/dist/lib/node/graph-Q3N2X26H.cjs.map +0 -7
- package/dist/lib/node-esm/SheetContainer-YWQVKHQB.mjs +0 -291
- package/dist/lib/node-esm/SheetContainer-YWQVKHQB.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BPXXIAOQ.mjs +0 -1529
- package/dist/lib/node-esm/chunk-BPXXIAOQ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-VCYJWE3O.mjs +0 -16
- package/dist/lib/node-esm/chunk-VCYJWE3O.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-WFDTY3IC.mjs +0 -75
- package/dist/lib/node-esm/chunk-WFDTY3IC.mjs.map +0 -7
- package/dist/lib/node-esm/graph-SMPUMOV2.mjs +0 -34
- package/dist/lib/node-esm/graph-SMPUMOV2.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -280
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/meta.mjs +0 -10
- package/dist/lib/node-esm/meta.mjs.map +0 -7
- package/dist/lib/node-esm/types.mjs +0 -17
- package/dist/lib/node-esm/types.mjs.map +0 -7
- package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +0 -11
- package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +0 -1
- package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts +0 -3
- package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +0 -1
- package/dist/types/src/components/FunctionEditor/index.d.ts +0 -2
- package/dist/types/src/components/FunctionEditor/index.d.ts.map +0 -1
- package/dist/types/src/components/GridSheet/GridSheet.d.ts +0 -3
- package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +0 -1
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +0 -9
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +0 -1
- package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +0 -1
- package/dist/types/src/components/GridSheet/index.d.ts +0 -2
- package/dist/types/src/components/GridSheet/index.d.ts.map +0 -1
- package/dist/types/src/components/GridSheet/util.d.ts +0 -16
- package/dist/types/src/components/GridSheet/util.d.ts.map +0 -1
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +0 -6
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +0 -1
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +0 -11
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +0 -1
- package/dist/types/src/components/SheetContainer/index.d.ts +0 -3
- package/dist/types/src/components/SheetContainer/index.d.ts.map +0 -1
- package/dist/types/src/components/SheetContext/SheetContext.d.ts +0 -26
- package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +0 -1
- package/dist/types/src/components/SheetContext/index.d.ts +0 -2
- package/dist/types/src/components/SheetContext/index.d.ts.map +0 -1
- package/dist/types/src/defs/index.d.ts +0 -4
- package/dist/types/src/defs/index.d.ts.map +0 -1
- package/dist/types/src/defs/sheet-range-types.d.ts +0 -13
- package/dist/types/src/defs/sheet-range-types.d.ts.map +0 -1
- package/dist/types/src/defs/types.d.ts.map +0 -1
- package/dist/types/src/defs/types.test.d.ts.map +0 -1
- package/dist/types/src/defs/util.d.ts +0 -43
- package/dist/types/src/defs/util.d.ts.map +0 -1
- package/dist/types/src/extensions/compute.d.ts +0 -6
- package/dist/types/src/extensions/compute.d.ts.map +0 -1
- package/dist/types/src/extensions/compute.stories.d.ts +0 -26
- package/dist/types/src/extensions/compute.stories.d.ts.map +0 -1
- package/dist/types/src/extensions/editor/extension.d.ts.map +0 -1
- package/dist/types/src/extensions/editor/extension.test.d.ts.map +0 -1
- package/dist/types/src/extensions/editor/index.d.ts +0 -2
- package/dist/types/src/extensions/editor/index.d.ts.map +0 -1
- package/dist/types/src/extensions/index.d.ts +0 -3
- package/dist/types/src/extensions/index.d.ts.map +0 -1
- package/dist/types/src/graph/compute-graph-registry.d.ts +0 -34
- package/dist/types/src/graph/compute-graph-registry.d.ts.map +0 -1
- package/dist/types/src/graph/compute-graph.d.ts +0 -64
- package/dist/types/src/graph/compute-graph.d.ts.map +0 -1
- package/dist/types/src/graph/compute-graph.stories.d.ts +0 -10
- package/dist/types/src/graph/compute-graph.stories.d.ts.map +0 -1
- package/dist/types/src/graph/compute-graph.test.d.ts +0 -2
- package/dist/types/src/graph/compute-graph.test.d.ts.map +0 -1
- package/dist/types/src/graph/compute-node.d.ts +0 -26
- package/dist/types/src/graph/compute-node.d.ts.map +0 -1
- package/dist/types/src/graph/functions/async-function.d.ts.map +0 -1
- package/dist/types/src/graph/functions/edge-function.d.ts +0 -21
- package/dist/types/src/graph/functions/edge-function.d.ts.map +0 -1
- package/dist/types/src/graph/functions/function-defs.d.ts.map +0 -1
- package/dist/types/src/graph/functions/index.d.ts +0 -4
- package/dist/types/src/graph/functions/index.d.ts.map +0 -1
- package/dist/types/src/graph/hyperformula.test.d.ts +0 -2
- package/dist/types/src/graph/hyperformula.test.d.ts.map +0 -1
- package/dist/types/src/graph/index.d.ts +0 -5
- package/dist/types/src/graph/index.d.ts.map +0 -1
- package/dist/types/src/graph/testing/index.d.ts +0 -3
- package/dist/types/src/graph/testing/index.d.ts.map +0 -1
- package/dist/types/src/graph/testing/test-builder.d.ts +0 -15
- package/dist/types/src/graph/testing/test-builder.d.ts.map +0 -1
- package/dist/types/src/graph/testing/test-plugin.d.ts +0 -36
- package/dist/types/src/graph/testing/test-plugin.d.ts.map +0 -1
- package/dist/types/src/graph/util.d.ts +0 -2
- package/dist/types/src/graph/util.d.ts.map +0 -1
- package/dist/types/src/hooks/hooks.stories.d.ts +0 -11
- package/dist/types/src/hooks/hooks.stories.d.ts.map +0 -1
- package/dist/types/src/hooks/index.d.ts +0 -4
- package/dist/types/src/hooks/index.d.ts.map +0 -1
- package/dist/types/src/hooks/threads.d.ts +0 -8
- package/dist/types/src/hooks/threads.d.ts.map +0 -1
- package/dist/types/src/hooks/useComputeGraph.d.ts +0 -7
- package/dist/types/src/hooks/useComputeGraph.d.ts.map +0 -1
- package/dist/types/src/hooks/useSheetModel.d.ts +0 -8
- package/dist/types/src/hooks/useSheetModel.d.ts.map +0 -1
- package/dist/types/src/model/decorations.d.ts +0 -25
- package/dist/types/src/model/decorations.d.ts.map +0 -1
- package/dist/types/src/model/sheet-model.d.ts.map +0 -1
- package/dist/types/src/model/sheet-model.test.d.ts +0 -2
- package/dist/types/src/model/sheet-model.test.d.ts.map +0 -1
- package/dist/types/src/sanity.test.d.ts +0 -2
- package/dist/types/src/sanity.test.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -2
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/testing.d.ts +0 -8
- package/dist/types/src/testing/testing.d.ts.map +0 -1
- package/dist/vendor/hyperformula.mjs +0 -37145
- package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +0 -20
- package/src/components/FunctionEditor/FunctionEditor.tsx +0 -45
- package/src/components/FunctionEditor/index.ts +0 -5
- package/src/components/GridSheet/GridSheet.stories.tsx +0 -41
- package/src/components/GridSheet/GridSheet.tsx +0 -163
- package/src/components/GridSheet/index.ts +0 -5
- package/src/components/GridSheet/util.ts +0 -158
- package/src/components/SheetContainer/SheetContainer.stories.tsx +0 -40
- package/src/components/SheetContainer/SheetContainer.tsx +0 -27
- package/src/components/SheetContainer/index.ts +0 -7
- package/src/components/SheetContext/SheetContext.tsx +0 -104
- package/src/components/SheetContext/index.ts +0 -5
- package/src/defs/index.ts +0 -7
- package/src/defs/sheet-range-types.ts +0 -46
- package/src/defs/util.ts +0 -151
- package/src/extensions/compute.stories.tsx +0 -151
- package/src/extensions/compute.ts +0 -147
- package/src/extensions/index.ts +0 -6
- package/src/graph/compute-graph-registry.ts +0 -90
- package/src/graph/compute-graph.stories.tsx +0 -93
- package/src/graph/compute-graph.test.ts +0 -87
- package/src/graph/compute-graph.ts +0 -242
- package/src/graph/compute-node.ts +0 -63
- package/src/graph/functions/index.ts +0 -7
- package/src/graph/hyperformula.test.ts +0 -14
- package/src/graph/index.ts +0 -8
- package/src/graph/testing/index.ts +0 -6
- package/src/graph/testing/test-builder.ts +0 -54
- package/src/graph/util.ts +0 -8
- package/src/hooks/hooks.stories.tsx +0 -50
- package/src/hooks/index.ts +0 -7
- package/src/hooks/threads.ts +0 -147
- package/src/hooks/useComputeGraph.ts +0 -28
- package/src/hooks/useSheetModel.ts +0 -40
- package/src/meta.ts +0 -14
- package/src/model/decorations.ts +0 -64
- package/src/model/sheet-model.test.ts +0 -57
- package/src/model/sheet-model.ts +0 -418
- package/src/sanity.test.ts +0 -40
- package/src/testing/testing.tsx +0 -68
- /package/dist/types/src/{extensions/editor → components/CellEditor}/extension.test.d.ts +0 -0
- /package/dist/types/src/{defs → model}/types.test.d.ts +0 -0
- /package/src/{graph/functions/function-defs.ts → model/functions.ts} +0 -0
|
@@ -2,265 +2,167 @@
|
|
|
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';
|
|
5
16
|
import { createContext } from '@radix-ui/react-context';
|
|
6
|
-
import React, { type PropsWithChildren
|
|
17
|
+
import React, { type PropsWithChildren } from 'react';
|
|
7
18
|
|
|
8
|
-
import { useIntentDispatcher } from '@dxos/app-framework';
|
|
9
19
|
import {
|
|
10
|
-
|
|
20
|
+
DensityProvider,
|
|
21
|
+
ElevationProvider,
|
|
11
22
|
Toolbar as NaturalToolbar,
|
|
12
|
-
useTranslation,
|
|
13
|
-
Tooltip,
|
|
14
|
-
type ToolbarToggleGroupItemProps as NaturalToolbarToggleGroupItemProps,
|
|
15
|
-
type ToolbarButtonProps as NaturalToolbarButtonProps,
|
|
16
|
-
type ToolbarToggleProps as NaturalToolbarToggleProps,
|
|
17
23
|
type ThemedClassName,
|
|
24
|
+
useTranslation,
|
|
18
25
|
} from '@dxos/react-ui';
|
|
19
|
-
import { useAttention } from '@dxos/react-ui-attention';
|
|
20
|
-
import { nonNullable } from '@dxos/util';
|
|
21
26
|
|
|
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';
|
|
27
|
+
import { ToolbarButton, ToolbarSeparator, ToolbarToggleButton } from './common';
|
|
32
28
|
import { SHEET_PLUGIN } from '../../meta';
|
|
33
|
-
import { type
|
|
34
|
-
import { useSheetContext } from '../SheetContext';
|
|
35
|
-
|
|
36
|
-
//
|
|
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
|
|
47
|
-
//
|
|
48
|
-
|
|
49
|
-
type ToolbarItemProps =
|
|
50
|
-
| (NaturalToolbarButtonProps & { itemType: 'button'; icon: string })
|
|
51
|
-
| (NaturalToolbarToggleGroupItemProps & { itemType: 'toggleGroupItem'; icon: string })
|
|
52
|
-
| (NaturalToolbarToggleProps & { itemType: 'toggle'; icon: string });
|
|
53
|
-
|
|
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
|
-
);
|
|
78
|
-
};
|
|
29
|
+
import { type Formatting } from '../../types';
|
|
79
30
|
|
|
80
31
|
//
|
|
81
32
|
// Root
|
|
82
33
|
//
|
|
83
34
|
|
|
84
|
-
type
|
|
85
|
-
type CommentAction = { key: CommentKey; value: CommentValue; cellContent?: string };
|
|
86
|
-
type StyleAction = { key: StyleKey; value: StyleValue };
|
|
87
|
-
|
|
88
|
-
export type ToolbarAction = StyleAction | AlignAction | CommentAction;
|
|
35
|
+
export type ToolbarActionType = 'clear' | 'highlight' | 'left' | 'center' | 'right' | 'date' | 'currency';
|
|
89
36
|
|
|
90
|
-
export type
|
|
37
|
+
export type ToolbarAction = {
|
|
38
|
+
type: ToolbarActionType;
|
|
39
|
+
};
|
|
91
40
|
|
|
92
|
-
export type ToolbarActionHandler = (
|
|
41
|
+
export type ToolbarActionHandler = ({ type }: ToolbarAction) => void;
|
|
93
42
|
|
|
94
43
|
export type ToolbarProps = ThemedClassName<
|
|
95
44
|
PropsWithChildren<{
|
|
96
|
-
|
|
45
|
+
onAction?: ToolbarActionHandler;
|
|
97
46
|
}>
|
|
98
47
|
>;
|
|
99
48
|
|
|
100
|
-
const [ToolbarContextProvider, useToolbarContext] = createContext<
|
|
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
|
-
);
|
|
49
|
+
const [ToolbarContextProvider, useToolbarContext] = createContext<ToolbarProps>('Toolbar');
|
|
167
50
|
|
|
51
|
+
const ToolbarRoot = ({ children, onAction, classNames }: ToolbarProps) => {
|
|
168
52
|
return (
|
|
169
|
-
<ToolbarContextProvider onAction={
|
|
170
|
-
<
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
>
|
|
178
|
-
{children}
|
|
179
|
-
</NaturalToolbar.Root>
|
|
53
|
+
<ToolbarContextProvider onAction={onAction}>
|
|
54
|
+
<DensityProvider density='fine'>
|
|
55
|
+
<ElevationProvider elevation='chrome'>
|
|
56
|
+
<NaturalToolbar.Root classNames={['is-full shrink-0 overflow-x-auto overflow-y-hidden p-1', classNames]}>
|
|
57
|
+
{children}
|
|
58
|
+
</NaturalToolbar.Root>
|
|
59
|
+
</ElevationProvider>
|
|
60
|
+
</DensityProvider>
|
|
180
61
|
</ToolbarContextProvider>
|
|
181
62
|
);
|
|
182
63
|
};
|
|
183
64
|
|
|
184
65
|
// TODO(burdon): Generalize.
|
|
185
66
|
// TODO(burdon): Detect and display current state.
|
|
186
|
-
type ButtonProps
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
67
|
+
type ButtonProps = {
|
|
68
|
+
type: ToolbarActionType;
|
|
69
|
+
Icon: Icon;
|
|
70
|
+
getState: (state: Formatting) => boolean;
|
|
71
|
+
disabled?: (state: Formatting) => boolean;
|
|
190
72
|
};
|
|
191
73
|
|
|
192
74
|
//
|
|
193
75
|
// Alignment
|
|
194
76
|
//
|
|
195
77
|
|
|
196
|
-
const
|
|
197
|
-
{
|
|
198
|
-
{
|
|
199
|
-
{ value: 'end', icon: 'ph--text-align-right--regular' },
|
|
78
|
+
const formatOptions: ButtonProps[] = [
|
|
79
|
+
{ type: 'date', Icon: Calendar, getState: (state) => false },
|
|
80
|
+
{ type: 'currency', Icon: CurrencyDollar, getState: (state) => false },
|
|
200
81
|
];
|
|
201
82
|
|
|
202
|
-
const
|
|
203
|
-
const {
|
|
204
|
-
const { onAction } = useToolbarContext('Alignment');
|
|
83
|
+
const Format = () => {
|
|
84
|
+
const { onAction } = useToolbarContext('Format');
|
|
205
85
|
const { t } = useTranslation(SHEET_PLUGIN);
|
|
206
86
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
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>
|
|
213
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 },
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
const Alignment = () => {
|
|
115
|
+
const { onAction } = useToolbarContext('Alignment');
|
|
116
|
+
const { t } = useTranslation(SHEET_PLUGIN);
|
|
214
117
|
|
|
215
118
|
return (
|
|
216
119
|
<NaturalToolbar.ToggleGroup
|
|
217
120
|
type='single'
|
|
218
|
-
value={
|
|
219
|
-
onValueChange={(value: AlignValue) => onAction?.({ key: 'align', value })}
|
|
121
|
+
// value={cellStyles.filter(({ getState }) => state && getState(state)).map(({ type }) => type)}
|
|
220
122
|
>
|
|
221
|
-
{alignmentOptions.map(({
|
|
222
|
-
<
|
|
223
|
-
{
|
|
224
|
-
|
|
123
|
+
{alignmentOptions.map(({ type, getState, Icon }) => (
|
|
124
|
+
<ToolbarToggleButton
|
|
125
|
+
key={type}
|
|
126
|
+
value={type}
|
|
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>
|
|
225
134
|
))}
|
|
226
135
|
</NaturalToolbar.ToggleGroup>
|
|
227
136
|
);
|
|
228
137
|
};
|
|
229
138
|
|
|
230
|
-
const styleOptions: ButtonProps
|
|
139
|
+
const styleOptions: ButtonProps[] = [
|
|
140
|
+
{ type: 'clear', Icon: Eraser, getState: (state) => false },
|
|
141
|
+
{ type: 'highlight', Icon: HighlighterCircle, getState: (state) => false },
|
|
142
|
+
];
|
|
231
143
|
|
|
232
144
|
const Styles = () => {
|
|
233
|
-
const {
|
|
234
|
-
const { onAction } = useToolbarContext('Styles');
|
|
145
|
+
const { onAction } = useToolbarContext('Alignment');
|
|
235
146
|
const { t } = useTranslation(SHEET_PLUGIN);
|
|
236
147
|
|
|
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
|
-
|
|
250
148
|
return (
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
149
|
+
<NaturalToolbar.ToggleGroup
|
|
150
|
+
type='single'
|
|
151
|
+
// value={cellStyles.filter(({ getState }) => state && getState(state)).map(({ type }) => type)}
|
|
152
|
+
>
|
|
153
|
+
{styleOptions.map(({ type, getState, Icon }) => (
|
|
154
|
+
<ToolbarToggleButton
|
|
155
|
+
key={type}
|
|
156
|
+
value={type}
|
|
157
|
+
Icon={Icon}
|
|
158
|
+
// disabled={state?.blockType === 'codeblock'}
|
|
159
|
+
// onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
|
|
160
|
+
onClick={() => onAction?.({ type })}
|
|
259
161
|
>
|
|
260
|
-
{t(`toolbar ${
|
|
261
|
-
</
|
|
162
|
+
{t(`toolbar ${type} label`)}
|
|
163
|
+
</ToolbarToggleButton>
|
|
262
164
|
))}
|
|
263
|
-
|
|
165
|
+
</NaturalToolbar.ToggleGroup>
|
|
264
166
|
);
|
|
265
167
|
};
|
|
266
168
|
|
|
@@ -269,51 +171,18 @@ const Styles = () => {
|
|
|
269
171
|
//
|
|
270
172
|
|
|
271
173
|
const Actions = () => {
|
|
272
|
-
const { onAction } = useToolbarContext('Actions');
|
|
273
|
-
const { cursor, range, model } = useSheetContext();
|
|
174
|
+
// const { onAction } = useToolbarContext('Actions');
|
|
274
175
|
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
|
-
|
|
297
176
|
return (
|
|
298
|
-
<
|
|
299
|
-
itemType='button'
|
|
177
|
+
<ToolbarButton
|
|
300
178
|
value='comment'
|
|
301
|
-
|
|
179
|
+
Icon={ChatText}
|
|
302
180
|
data-testid='editor.toolbar.comment'
|
|
303
|
-
onClick={() => {
|
|
304
|
-
|
|
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}
|
|
181
|
+
// onClick={() => onAction?.({ type: 'comment' })}
|
|
182
|
+
// disabled={!state || state.comment || !state.selection}
|
|
314
183
|
>
|
|
315
|
-
{t(
|
|
316
|
-
</
|
|
184
|
+
{t('comment label')}
|
|
185
|
+
</ToolbarButton>
|
|
317
186
|
);
|
|
318
187
|
};
|
|
319
188
|
|
|
@@ -321,6 +190,7 @@ export const Toolbar = {
|
|
|
321
190
|
Root: ToolbarRoot,
|
|
322
191
|
Separator: ToolbarSeparator,
|
|
323
192
|
Alignment,
|
|
193
|
+
Format,
|
|
324
194
|
Styles,
|
|
325
195
|
Actions,
|
|
326
196
|
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Icon } from '@phosphor-icons/react';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
Toolbar as NaturalToolbar,
|
|
10
|
+
Tooltip,
|
|
11
|
+
type ToolbarButtonProps as NaturalToolbarButtonProps,
|
|
12
|
+
type ToolbarToggleGroupItemProps as NaturalToolbarToggleGroupItemProps,
|
|
13
|
+
} from '@dxos/react-ui';
|
|
14
|
+
import { getSize } from '@dxos/react-ui-theme';
|
|
15
|
+
|
|
16
|
+
// TODO(burdon): Factor out in common with react-ui-editor.
|
|
17
|
+
|
|
18
|
+
export const iconStyles = getSize(5);
|
|
19
|
+
export const buttonStyles = 'min-bs-0 p-2';
|
|
20
|
+
export const tooltipProps = { side: 'top' as const, classNames: 'z-10' };
|
|
21
|
+
|
|
22
|
+
export const ToolbarSeparator = () => <div role='separator' className='grow' />;
|
|
23
|
+
|
|
24
|
+
//
|
|
25
|
+
// ToolbarButton
|
|
26
|
+
//
|
|
27
|
+
|
|
28
|
+
type ToolbarButtonProps = NaturalToolbarButtonProps & { Icon: Icon };
|
|
29
|
+
|
|
30
|
+
export const ToolbarButton = ({ Icon, children, ...props }: ToolbarButtonProps) => {
|
|
31
|
+
return (
|
|
32
|
+
<Tooltip.Root>
|
|
33
|
+
<Tooltip.Trigger asChild>
|
|
34
|
+
<NaturalToolbar.Button variant='ghost' {...props} classNames={buttonStyles}>
|
|
35
|
+
<Icon className={iconStyles} />
|
|
36
|
+
<span className='sr-only'>{children}</span>
|
|
37
|
+
</NaturalToolbar.Button>
|
|
38
|
+
</Tooltip.Trigger>
|
|
39
|
+
<Tooltip.Portal>
|
|
40
|
+
<Tooltip.Content {...tooltipProps}>
|
|
41
|
+
{children}
|
|
42
|
+
<Tooltip.Arrow />
|
|
43
|
+
</Tooltip.Content>
|
|
44
|
+
</Tooltip.Portal>
|
|
45
|
+
</Tooltip.Root>
|
|
46
|
+
);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
//
|
|
50
|
+
// ToolbarToggleButton
|
|
51
|
+
//
|
|
52
|
+
|
|
53
|
+
export type ToolbarToggleButtonProps = NaturalToolbarToggleGroupItemProps & { Icon: Icon };
|
|
54
|
+
|
|
55
|
+
export const ToolbarToggleButton = ({ Icon, children, ...props }: ToolbarToggleButtonProps) => {
|
|
56
|
+
return (
|
|
57
|
+
<Tooltip.Root>
|
|
58
|
+
<Tooltip.Trigger asChild>
|
|
59
|
+
<NaturalToolbar.ToggleGroupItem variant='ghost' {...props} classNames={buttonStyles}>
|
|
60
|
+
<Icon className={iconStyles} />
|
|
61
|
+
<span className='sr-only'>{children}</span>
|
|
62
|
+
</NaturalToolbar.ToggleGroupItem>
|
|
63
|
+
</Tooltip.Trigger>
|
|
64
|
+
<Tooltip.Portal>
|
|
65
|
+
<Tooltip.Content {...tooltipProps}>
|
|
66
|
+
{children}
|
|
67
|
+
<Tooltip.Arrow />
|
|
68
|
+
</Tooltip.Content>
|
|
69
|
+
</Tooltip.Portal>
|
|
70
|
+
</Tooltip.Root>
|
|
71
|
+
);
|
|
72
|
+
};
|
package/src/components/index.ts
CHANGED
package/src/meta.tsx
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { GridNine, type IconProps } from '@phosphor-icons/react';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
|
|
8
|
+
import { pluginMeta } from '@dxos/app-framework';
|
|
9
|
+
|
|
10
|
+
export const SHEET_PLUGIN = 'dxos.org/plugin/sheet';
|
|
11
|
+
|
|
12
|
+
export default pluginMeta({
|
|
13
|
+
id: SHEET_PLUGIN,
|
|
14
|
+
name: 'Sheet',
|
|
15
|
+
description: 'A simple spreadsheet plugin.',
|
|
16
|
+
iconComponent: (props: IconProps) => <GridNine {...props} />,
|
|
17
|
+
iconSymbol: 'ph--grid-nine--regular',
|
|
18
|
+
});
|
package/src/model/index.ts
CHANGED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { expect } from 'chai';
|
|
6
|
+
import { describe, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { SheetModel } from './model';
|
|
9
|
+
import { addressFromA1Notation, rangeFromA1Notation } from './types';
|
|
10
|
+
import { createComputeGraph } from '../components';
|
|
11
|
+
import { createSheet, ValueTypeEnum } from '../types';
|
|
12
|
+
|
|
13
|
+
// TODO(burdon): Test undo (e.g., clear cells).
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* VITEST_ENV=chrome p vitest --watch
|
|
17
|
+
* NOTE: Browser test required for hyperformula due to raw translation files.
|
|
18
|
+
*/
|
|
19
|
+
describe('model', () => {
|
|
20
|
+
const createModel = async () => {
|
|
21
|
+
const graph = createComputeGraph();
|
|
22
|
+
const sheet = createSheet();
|
|
23
|
+
const model = new SheetModel(graph, sheet, undefined, { rows: 5, columns: 5 });
|
|
24
|
+
await model.initialize();
|
|
25
|
+
return model;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
test('create', async () => {
|
|
29
|
+
const model = await createModel();
|
|
30
|
+
expect(model.bounds).to.deep.eq({ rows: 5, columns: 5 });
|
|
31
|
+
model.setValue(addressFromA1Notation('A1'), 100);
|
|
32
|
+
const value = model.getValue(addressFromA1Notation('A1'));
|
|
33
|
+
expect(value).to.eq(100);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('map formula', async () => {
|
|
37
|
+
const model = await createModel();
|
|
38
|
+
const x1 = model.mapFormulaRefsToIndices('=SUM(A1:A3)');
|
|
39
|
+
const x2 = model.mapFormulaIndicesToRefs(x1);
|
|
40
|
+
expect(x2).to.eq('=SUM(A1:A3)');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('dates', async () => {
|
|
44
|
+
const model = await createModel();
|
|
45
|
+
const cell = addressFromA1Notation('A1');
|
|
46
|
+
model.setValue(cell, '=NOW()');
|
|
47
|
+
const type = model.getValueType(cell);
|
|
48
|
+
expect(type).to.eq(ValueTypeEnum.DateTime);
|
|
49
|
+
const value = model.getValue(cell);
|
|
50
|
+
const date = model.toLocalDate(value as number);
|
|
51
|
+
const now = new Date();
|
|
52
|
+
expect(date.getUTCFullYear()).to.eq(now.getUTCFullYear());
|
|
53
|
+
expect(date.getUTCMonth()).to.eq(now.getUTCMonth());
|
|
54
|
+
expect(date.getUTCDate()).to.eq(now.getUTCDate());
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('formula', async () => {
|
|
58
|
+
const model = await createModel();
|
|
59
|
+
|
|
60
|
+
// Nested formula.
|
|
61
|
+
{
|
|
62
|
+
model.setValue(addressFromA1Notation('A1'), 100);
|
|
63
|
+
model.setValue(addressFromA1Notation('A2'), 200);
|
|
64
|
+
model.setValue(addressFromA1Notation('A3'), '=SUM(A1:A2)');
|
|
65
|
+
model.setValue(addressFromA1Notation('A4'), '=SUM(A1:A3)');
|
|
66
|
+
const value = model.getValue(addressFromA1Notation('A4'));
|
|
67
|
+
expect(value).to.eq(600);
|
|
68
|
+
// console.log(JSON.stringify(model.sheet.cells, undefined, 2));
|
|
69
|
+
|
|
70
|
+
const cells = model.getCellValues(rangeFromA1Notation('A1:A4'));
|
|
71
|
+
expect(cells).to.deep.eq([
|
|
72
|
+
[100],
|
|
73
|
+
[200],
|
|
74
|
+
[model.mapFormulaRefsToIndices('=SUM(A1:A2)')],
|
|
75
|
+
[model.mapFormulaRefsToIndices('=SUM(A1:A3)')],
|
|
76
|
+
]);
|
|
77
|
+
// console.log(JSON.stringify(model.sheet.cells, undefined, 2));
|
|
78
|
+
// console.log(cells);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Insert row.
|
|
82
|
+
{
|
|
83
|
+
model.insertRows(2, 1);
|
|
84
|
+
model.setValue(addressFromA1Notation('A3'), 400);
|
|
85
|
+
const value = model.getValue(addressFromA1Notation('A5'));
|
|
86
|
+
expect(value).to.eq(1000);
|
|
87
|
+
|
|
88
|
+
const cells = model.getCellValues(rangeFromA1Notation('A1:A5'));
|
|
89
|
+
expect(cells).to.deep.eq([
|
|
90
|
+
[100],
|
|
91
|
+
[200],
|
|
92
|
+
[400],
|
|
93
|
+
[model.mapFormulaRefsToIndices('=SUM(A1:A2)')],
|
|
94
|
+
[model.mapFormulaRefsToIndices('=SUM(A1:A4)')],
|
|
95
|
+
]);
|
|
96
|
+
// console.log(JSON.stringify(model.sheet.cells, undefined, 2));
|
|
97
|
+
// console.log(cells);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|