@dxos/plugin-sheet 0.6.12-main.15a606f → 0.6.12-main.2d19bf1
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-QILRZNE5.mjs → chunk-D3QTX46O.mjs} +4 -5
- package/dist/lib/browser/chunk-D3QTX46O.mjs.map +7 -0
- package/dist/lib/browser/{chunk-T3NJFTD4.mjs → chunk-GKI67SEF.mjs} +20 -26
- package/dist/lib/browser/chunk-GKI67SEF.mjs.map +7 -0
- package/dist/lib/browser/{chunk-6ZMQVB4Z.mjs → chunk-GSV5QNLD.mjs} +220 -177
- package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +7 -0
- package/dist/lib/browser/graph-M4IQ76QX.mjs +33 -0
- package/dist/lib/browser/index.mjs +41 -22
- 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 -8
- package/dist/lib/node/SheetContainer-YSQGJD7K.cjs +276 -0
- package/dist/lib/node/SheetContainer-YSQGJD7K.cjs.map +7 -0
- package/dist/lib/node/{chunk-DD6FIXWC.cjs → chunk-5XPK2V4A.cjs} +222 -175
- 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-Q3HBHPRL.cjs → chunk-ER3PM7GD.cjs} +26 -34
- package/dist/lib/node/chunk-ER3PM7GD.cjs.map +7 -0
- package/dist/lib/node/{chunk-BNARJ5GM.cjs → chunk-QIFIGEKV.cjs} +6 -7
- 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 +61 -44
- 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 -12
- 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/node-esm/{chunk-D6KU5MI7.mjs → chunk-5WPZCXNS.mjs} +220 -177
- 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-IU2L277A.mjs → chunk-VCYJWE3O.mjs} +4 -5
- package/dist/lib/node-esm/chunk-VCYJWE3O.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-BMNA27EX.mjs → chunk-ZVLLQ2PJ.mjs} +20 -26
- 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/index.mjs +41 -22
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/meta.mjs +1 -1
- package/dist/lib/node-esm/types.mjs +4 -8
- package/dist/types/src/SheetPlugin.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 +1 -8
- package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +1 -1
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -1
- package/dist/types/src/components/{CellEditor/CellEditor.stories.d.ts → GridSheet/SheetCellEditor.stories.d.ts} +2 -2
- 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 +13 -3
- package/dist/types/src/components/GridSheet/util.d.ts.map +1 -1
- 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 +31 -17
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +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/types.d.ts.map +1 -1
- package/dist/types/src/defs/util.d.ts +1 -1
- package/dist/types/src/defs/util.d.ts.map +1 -1
- package/dist/types/src/extensions/compute.d.ts +3 -2
- package/dist/types/src/extensions/compute.d.ts.map +1 -1
- package/dist/types/src/extensions/compute.stories.d.ts.map +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 +1 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- 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 +17 -34
- package/dist/types/src/graph/compute-graph.d.ts.map +1 -1
- package/dist/types/src/graph/compute-graph.stories.d.ts.map +1 -1
- 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 +9 -2
- package/dist/types/src/graph/compute-node.d.ts.map +1 -1
- package/dist/types/src/graph/{async-function.d.ts → functions/async-function.d.ts} +13 -4
- 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/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/index.d.ts +2 -1
- package/dist/types/src/graph/index.d.ts.map +1 -1
- 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/hooks/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/types/src/hooks/useSheetModel.d.ts +2 -2
- package/dist/types/src/hooks/useSheetModel.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +3 -6
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/{components/Sheet → model}/decorations.d.ts +1 -0
- package/dist/types/src/model/decorations.d.ts.map +1 -0
- package/dist/types/src/model/formatting-model.d.ts +3 -0
- package/dist/types/src/model/formatting-model.d.ts.map +1 -1
- package/dist/types/src/model/index.d.ts +1 -0
- package/dist/types/src/model/index.d.ts.map +1 -1
- package/dist/types/src/model/sheet-model.d.ts +6 -5
- package/dist/types/src/model/sheet-model.d.ts.map +1 -1
- 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/testing/testing.d.ts +4 -5
- package/dist/types/src/testing/testing.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +17 -31
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +42 -41
- package/src/SheetPlugin.tsx +22 -17
- package/src/components/FunctionEditor/FunctionEditor.tsx +45 -0
- package/src/components/FunctionEditor/index.ts +5 -0
- package/src/components/GridSheet/GridSheet.stories.tsx +11 -5
- package/src/components/GridSheet/GridSheet.tsx +78 -70
- package/src/components/{CellEditor/CellEditor.stories.tsx → GridSheet/SheetCellEditor.stories.tsx} +4 -5
- package/src/components/{Sheet → GridSheet}/index.ts +1 -1
- package/src/components/GridSheet/util.ts +94 -39
- 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/{Sheet/sheet-context.tsx → SheetContext/SheetContext.tsx} +48 -28
- package/src/components/SheetContext/index.ts +5 -0
- package/src/components/Toolbar/Toolbar.tsx +127 -86
- package/src/components/index.ts +2 -1
- package/src/defs/types.ts +1 -0
- package/src/defs/util.ts +20 -4
- package/src/extensions/compute.stories.tsx +23 -23
- package/src/extensions/compute.ts +91 -42
- package/src/{components/CellEditor → extensions/editor}/extension.test.ts +0 -1
- package/src/{components/CellEditor → extensions/editor}/extension.ts +4 -3
- package/src/{components/CellEditor → extensions/editor}/index.ts +0 -1
- package/src/extensions/index.ts +1 -0
- package/src/graph/compute-graph-registry.ts +90 -0
- package/src/graph/compute-graph.stories.tsx +4 -3
- package/src/graph/compute-graph.test.ts +87 -0
- package/src/graph/compute-graph.ts +73 -121
- package/src/graph/compute-node.ts +17 -5
- package/src/graph/{async-function.ts → functions/async-function.ts} +23 -15
- package/src/graph/{edge-function.ts → functions/edge-function.ts} +14 -13
- package/src/graph/functions/index.ts +7 -0
- package/src/graph/hyperformula.test.ts +1 -2
- package/src/graph/index.ts +2 -1
- package/src/graph/testing/index.ts +6 -0
- package/src/graph/testing/test-builder.ts +54 -0
- package/src/graph/{custom-function.ts → testing/test-plugin.ts} +43 -9
- package/src/hooks/hooks.stories.tsx +3 -3
- package/src/hooks/index.ts +1 -0
- package/src/{components/Sheet/threads.tsx → hooks/threads.ts} +26 -84
- package/src/hooks/useComputeGraph.ts +9 -1
- package/src/hooks/useSheetModel.ts +4 -7
- package/src/{meta.tsx → meta.ts} +3 -3
- package/src/{components/Sheet → model}/decorations.ts +2 -0
- package/src/model/formatting-model.ts +12 -9
- package/src/model/index.ts +1 -0
- package/src/model/sheet-model.test.ts +57 -0
- package/src/model/sheet-model.ts +60 -41
- package/src/testing/testing.tsx +17 -15
- package/src/types.ts +12 -38
- package/dist/lib/browser/SheetContainer-V4GCCZTX.mjs +0 -261
- package/dist/lib/browser/SheetContainer-V4GCCZTX.mjs.map +0 -7
- package/dist/lib/browser/chunk-6ZMQVB4Z.mjs.map +0 -7
- package/dist/lib/browser/chunk-QILRZNE5.mjs.map +0 -7
- package/dist/lib/browser/chunk-T3NJFTD4.mjs.map +0 -7
- package/dist/lib/browser/chunk-U2JHW3L6.mjs +0 -2552
- package/dist/lib/browser/chunk-U2JHW3L6.mjs.map +0 -7
- package/dist/lib/browser/graph-T27BOBOV.mjs +0 -21
- package/dist/lib/node/SheetContainer-3ZY7MPWJ.cjs +0 -279
- package/dist/lib/node/SheetContainer-3ZY7MPWJ.cjs.map +0 -7
- package/dist/lib/node/chunk-BNARJ5GM.cjs.map +0 -7
- package/dist/lib/node/chunk-DD6FIXWC.cjs.map +0 -7
- package/dist/lib/node/chunk-OTTD7FBK.cjs +0 -2536
- package/dist/lib/node/chunk-OTTD7FBK.cjs.map +0 -7
- package/dist/lib/node/chunk-Q3HBHPRL.cjs.map +0 -7
- package/dist/lib/node/graph-SPKGX7W4.cjs +0 -43
- package/dist/lib/node/graph-SPKGX7W4.cjs.map +0 -7
- package/dist/lib/node-esm/SheetContainer-PXSJX6XK.mjs +0 -262
- package/dist/lib/node-esm/SheetContainer-PXSJX6XK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-7HVSOTGA.mjs +0 -2553
- package/dist/lib/node-esm/chunk-7HVSOTGA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BMNA27EX.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-D6KU5MI7.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-IU2L277A.mjs.map +0 -7
- package/dist/lib/node-esm/graph-U67IO4UC.mjs +0 -22
- package/dist/types/src/components/CellEditor/CellEditor.d.ts +0 -34
- 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/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 -53
- package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/decorations.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 -26
- package/dist/types/src/components/Sheet/sheet-context.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/threads.d.ts +0 -2
- package/dist/types/src/components/Sheet/threads.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 -8
- 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/graph/async-function.d.ts.map +0 -1
- package/dist/types/src/graph/compute-graph.browser.test.d.ts +0 -2
- package/dist/types/src/graph/compute-graph.browser.test.d.ts.map +0 -1
- package/dist/types/src/graph/custom-function.d.ts +0 -21
- package/dist/types/src/graph/custom-function.d.ts.map +0 -1
- package/dist/types/src/graph/edge-function.d.ts +0 -20
- package/dist/types/src/graph/edge-function.d.ts.map +0 -1
- package/dist/types/src/graph/function-defs.d.ts.map +0 -1
- package/src/components/CellEditor/CellEditor.tsx +0 -163
- package/src/components/Sheet/Sheet.stories.tsx +0 -250
- package/src/components/Sheet/Sheet.tsx +0 -1199
- package/src/components/Sheet/grid.ts +0 -191
- package/src/components/Sheet/nav.ts +0 -157
- package/src/components/Sheet/util.ts +0 -56
- package/src/components/SheetContainer.tsx +0 -88
- package/src/components/Toolbar/common.tsx +0 -72
- package/src/graph/compute-graph.browser.test.ts +0 -104
- /package/dist/lib/browser/{graph-T27BOBOV.mjs.map → graph-M4IQ76QX.mjs.map} +0 -0
- /package/dist/lib/node-esm/{graph-U67IO4UC.mjs.map → graph-SMPUMOV2.mjs.map} +0 -0
- /package/dist/types/src/{components/CellEditor → extensions/editor}/extension.d.ts +0 -0
- /package/dist/types/src/{components/CellEditor → extensions/editor}/extension.test.d.ts +0 -0
- /package/dist/types/src/graph/{function-defs.d.ts → functions/function-defs.d.ts} +0 -0
- /package/src/graph/{function-defs.ts → functions/function-defs.ts} +0 -0
|
@@ -2,48 +2,87 @@
|
|
|
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
6
|
import React, { type PropsWithChildren } from 'react';
|
|
18
7
|
|
|
19
8
|
import {
|
|
20
|
-
|
|
21
|
-
ElevationProvider,
|
|
9
|
+
Icon,
|
|
22
10
|
Toolbar as NaturalToolbar,
|
|
23
|
-
type ThemedClassName,
|
|
24
11
|
useTranslation,
|
|
12
|
+
Tooltip,
|
|
13
|
+
type ToolbarToggleGroupItemProps as NaturalToolbarToggleGroupItemProps,
|
|
14
|
+
type ToolbarButtonProps as NaturalToolbarButtonProps,
|
|
15
|
+
type ToolbarToggleProps as NaturalToolbarToggleProps,
|
|
16
|
+
type ThemedClassName,
|
|
25
17
|
} from '@dxos/react-ui';
|
|
18
|
+
import { useAttention } from '@dxos/react-ui-attention';
|
|
26
19
|
import { nonNullable } from '@dxos/util';
|
|
27
20
|
|
|
28
|
-
import { ToolbarButton, ToolbarSeparator, ToolbarToggleButton } from './common';
|
|
29
21
|
import { addressToIndex } from '../../defs';
|
|
30
22
|
import { SHEET_PLUGIN } from '../../meta';
|
|
31
23
|
import { type Formatting } from '../../types';
|
|
32
|
-
import { useSheetContext } from '../
|
|
24
|
+
import { useSheetContext } from '../SheetContext';
|
|
25
|
+
|
|
26
|
+
//
|
|
27
|
+
// Buttons
|
|
28
|
+
//
|
|
29
|
+
|
|
30
|
+
const buttonStyles = 'min-bs-0 p-2';
|
|
31
|
+
const tooltipProps = { side: 'bottom' as const, classNames: 'z-10' };
|
|
32
|
+
|
|
33
|
+
const ToolbarSeparator = () => <div role='separator' className='grow' />;
|
|
34
|
+
|
|
35
|
+
//
|
|
36
|
+
// ToolbarItem
|
|
37
|
+
//
|
|
38
|
+
|
|
39
|
+
type ToolbarItemProps =
|
|
40
|
+
| (NaturalToolbarButtonProps & { itemType: 'button'; icon: string })
|
|
41
|
+
| (NaturalToolbarToggleGroupItemProps & { itemType: 'toggleGroupItem'; icon: string })
|
|
42
|
+
| (NaturalToolbarToggleProps & { itemType: 'toggle'; icon: string });
|
|
43
|
+
|
|
44
|
+
export const ToolbarItem = ({ itemType, icon, children, ...props }: ToolbarItemProps) => {
|
|
45
|
+
const Invoker =
|
|
46
|
+
itemType === 'toggleGroupItem'
|
|
47
|
+
? NaturalToolbar.ToggleGroupItem
|
|
48
|
+
: itemType === 'toggle'
|
|
49
|
+
? NaturalToolbar.Toggle
|
|
50
|
+
: NaturalToolbar.Button;
|
|
51
|
+
return (
|
|
52
|
+
<Tooltip.Root>
|
|
53
|
+
<Tooltip.Trigger asChild>
|
|
54
|
+
{/* TODO(thure): type the props spread better. */}
|
|
55
|
+
<Invoker variant='ghost' {...(props as any)} classNames={buttonStyles}>
|
|
56
|
+
<Icon icon={icon} size={5} />
|
|
57
|
+
<span className='sr-only'>{children}</span>
|
|
58
|
+
</Invoker>
|
|
59
|
+
</Tooltip.Trigger>
|
|
60
|
+
<Tooltip.Portal>
|
|
61
|
+
<Tooltip.Content {...tooltipProps}>
|
|
62
|
+
{children}
|
|
63
|
+
<Tooltip.Arrow />
|
|
64
|
+
</Tooltip.Content>
|
|
65
|
+
</Tooltip.Portal>
|
|
66
|
+
</Tooltip.Root>
|
|
67
|
+
);
|
|
68
|
+
};
|
|
33
69
|
|
|
34
70
|
//
|
|
35
71
|
// Root
|
|
36
72
|
//
|
|
37
73
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
74
|
+
type AlignValue = 'left' | 'center' | 'right' | 'unset';
|
|
75
|
+
type AlignAction = { type: 'align'; value: AlignValue };
|
|
76
|
+
|
|
77
|
+
type CommentAction = { type: 'comment'; anchor: string; cellContent?: string };
|
|
78
|
+
|
|
79
|
+
type FormatValue = 'date' | 'currency' | 'unset';
|
|
80
|
+
type FormatAction = { type: 'format'; value: FormatValue };
|
|
81
|
+
|
|
82
|
+
type StyleValue = 'highlight' | 'unset';
|
|
83
|
+
type StyleAction = { type: 'style'; value: StyleValue };
|
|
84
|
+
|
|
85
|
+
export type ToolbarAction = StyleAction | AlignAction | FormatAction | CommentAction;
|
|
47
86
|
|
|
48
87
|
export type ToolbarActionType = ToolbarAction['type'];
|
|
49
88
|
|
|
@@ -52,30 +91,41 @@ export type ToolbarActionHandler = (action: ToolbarAction) => void;
|
|
|
52
91
|
export type ToolbarProps = ThemedClassName<
|
|
53
92
|
PropsWithChildren<{
|
|
54
93
|
onAction?: ToolbarActionHandler;
|
|
94
|
+
role?: string;
|
|
55
95
|
}>
|
|
56
96
|
>;
|
|
57
97
|
|
|
58
98
|
const [ToolbarContextProvider, useToolbarContext] = createContext<ToolbarProps>('Toolbar');
|
|
59
99
|
|
|
60
|
-
|
|
100
|
+
// TODO(Zan): Factor out, copied this from MarkdownPlugin.
|
|
101
|
+
const sectionToolbarLayout =
|
|
102
|
+
'bs-[--rail-action] bg-[--sticky-bg] sticky block-start-0 __-block-start-px transition-opacity';
|
|
103
|
+
|
|
104
|
+
const ToolbarRoot = ({ children, onAction, role, classNames }: ToolbarProps) => {
|
|
105
|
+
const { id } = useSheetContext();
|
|
106
|
+
const { hasAttention } = useAttention(id);
|
|
107
|
+
|
|
61
108
|
return (
|
|
62
109
|
<ToolbarContextProvider onAction={onAction}>
|
|
63
|
-
<
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
110
|
+
<NaturalToolbar.Root
|
|
111
|
+
classNames={[
|
|
112
|
+
...(role === 'section'
|
|
113
|
+
? ['z-[2] group-focus-within/section:visible', !hasAttention && 'invisible', sectionToolbarLayout]
|
|
114
|
+
: ['attention-surface']),
|
|
115
|
+
classNames,
|
|
116
|
+
]}
|
|
117
|
+
>
|
|
118
|
+
{children}
|
|
119
|
+
</NaturalToolbar.Root>
|
|
70
120
|
</ToolbarContextProvider>
|
|
71
121
|
);
|
|
72
122
|
};
|
|
73
123
|
|
|
74
124
|
// TODO(burdon): Generalize.
|
|
75
125
|
// TODO(burdon): Detect and display current state.
|
|
76
|
-
type ButtonProps = {
|
|
77
|
-
|
|
78
|
-
|
|
126
|
+
type ButtonProps<T> = {
|
|
127
|
+
value: T;
|
|
128
|
+
icon: string;
|
|
79
129
|
getState: (state: Formatting) => boolean;
|
|
80
130
|
disabled?: (state: Formatting) => boolean;
|
|
81
131
|
};
|
|
@@ -84,9 +134,9 @@ type ButtonProps = {
|
|
|
84
134
|
// Alignment
|
|
85
135
|
//
|
|
86
136
|
|
|
87
|
-
const formatOptions: ButtonProps[] = [
|
|
88
|
-
{
|
|
89
|
-
{
|
|
137
|
+
const formatOptions: ButtonProps<FormatValue>[] = [
|
|
138
|
+
{ value: 'date', icon: 'ph--calendar--regular', getState: (state) => false },
|
|
139
|
+
{ value: 'currency', icon: 'ph--currency-dollar--regular', getState: (state) => false },
|
|
90
140
|
];
|
|
91
141
|
|
|
92
142
|
const Format = () => {
|
|
@@ -98,26 +148,25 @@ const Format = () => {
|
|
|
98
148
|
type='single'
|
|
99
149
|
// value={cellStyles.filter(({ getState }) => state && getState(state)).map(({ type }) => type)}
|
|
100
150
|
>
|
|
101
|
-
{formatOptions.map(({
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
onClick={() => onAction?.({ type: type as Exclude<typeof type, 'comment'> })}
|
|
151
|
+
{formatOptions.map(({ value, getState, icon }) => (
|
|
152
|
+
<ToolbarItem
|
|
153
|
+
itemType='toggleGroupItem'
|
|
154
|
+
key={value}
|
|
155
|
+
value={value}
|
|
156
|
+
icon={icon}
|
|
157
|
+
onClick={() => onAction?.({ type: 'format', value })}
|
|
109
158
|
>
|
|
110
|
-
{t(`toolbar ${
|
|
111
|
-
</
|
|
159
|
+
{t(`toolbar ${value} label`)}
|
|
160
|
+
</ToolbarItem>
|
|
112
161
|
))}
|
|
113
162
|
</NaturalToolbar.ToggleGroup>
|
|
114
163
|
);
|
|
115
164
|
};
|
|
116
165
|
|
|
117
|
-
const alignmentOptions: ButtonProps[] = [
|
|
118
|
-
{
|
|
119
|
-
{
|
|
120
|
-
{
|
|
166
|
+
const alignmentOptions: ButtonProps<AlignValue>[] = [
|
|
167
|
+
{ value: 'left', icon: 'ph--text-align-left--regular', getState: (state) => false },
|
|
168
|
+
{ value: 'center', icon: 'ph--text-align-center--regular', getState: (state) => false },
|
|
169
|
+
{ value: 'right', icon: 'ph--text-align-right--regular', getState: (state) => false },
|
|
121
170
|
];
|
|
122
171
|
|
|
123
172
|
const Alignment = () => {
|
|
@@ -128,50 +177,41 @@ const Alignment = () => {
|
|
|
128
177
|
<NaturalToolbar.ToggleGroup
|
|
129
178
|
type='single'
|
|
130
179
|
// value={cellStyles.filter(({ getState }) => state && getState(state)).map(({ type }) => type)}
|
|
180
|
+
// disabled={state?.blockType === 'codeblock'}
|
|
181
|
+
onValueChange={(value: AlignValue) => onAction?.({ type: 'align', value })}
|
|
131
182
|
>
|
|
132
|
-
{alignmentOptions.map(({
|
|
133
|
-
<
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
Icon={Icon}
|
|
137
|
-
// disabled={state?.blockType === 'codeblock'}
|
|
138
|
-
// onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
|
|
139
|
-
onClick={() => onAction?.({ type: type as Exclude<typeof type, 'comment'> })}
|
|
140
|
-
>
|
|
141
|
-
{t(`toolbar ${type} label`)}
|
|
142
|
-
</ToolbarToggleButton>
|
|
183
|
+
{alignmentOptions.map(({ value, getState, icon }) => (
|
|
184
|
+
<ToolbarItem itemType='toggleGroupItem' key={value} value={value} icon={icon}>
|
|
185
|
+
{t(`toolbar ${value} label`)}
|
|
186
|
+
</ToolbarItem>
|
|
143
187
|
))}
|
|
144
188
|
</NaturalToolbar.ToggleGroup>
|
|
145
189
|
);
|
|
146
190
|
};
|
|
147
191
|
|
|
148
|
-
const styleOptions: ButtonProps[] = [
|
|
149
|
-
{
|
|
150
|
-
{ type: 'highlight', Icon: HighlighterCircle, getState: (state) => false },
|
|
192
|
+
const styleOptions: ButtonProps<StyleValue>[] = [
|
|
193
|
+
{ value: 'highlight', icon: 'ph--highlighter--regular', getState: (state) => false },
|
|
151
194
|
];
|
|
152
195
|
|
|
153
196
|
const Styles = () => {
|
|
154
|
-
const { onAction } = useToolbarContext('
|
|
197
|
+
const { onAction } = useToolbarContext('Styles');
|
|
155
198
|
const { t } = useTranslation(SHEET_PLUGIN);
|
|
156
199
|
|
|
157
200
|
return (
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
// disabled={state?.blockType === 'codeblock'}
|
|
168
|
-
// onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
|
|
169
|
-
onClick={() => onAction?.({ type: type as Exclude<typeof type, 'comment'> })}
|
|
201
|
+
<>
|
|
202
|
+
{styleOptions.map(({ value, getState, icon }) => (
|
|
203
|
+
<ToolbarItem
|
|
204
|
+
itemType='toggle'
|
|
205
|
+
key={value}
|
|
206
|
+
onPressedChange={(nextPressed: boolean) =>
|
|
207
|
+
onAction?.({ type: 'style', value: nextPressed ? 'highlight' : 'unset' })
|
|
208
|
+
}
|
|
209
|
+
icon={icon}
|
|
170
210
|
>
|
|
171
|
-
{t(`toolbar ${
|
|
172
|
-
</
|
|
211
|
+
{t(`toolbar ${value} label`)}
|
|
212
|
+
</ToolbarItem>
|
|
173
213
|
))}
|
|
174
|
-
|
|
214
|
+
</>
|
|
175
215
|
);
|
|
176
216
|
};
|
|
177
217
|
|
|
@@ -206,9 +246,10 @@ const Actions = () => {
|
|
|
206
246
|
: 'comment label';
|
|
207
247
|
|
|
208
248
|
return (
|
|
209
|
-
<
|
|
249
|
+
<ToolbarItem
|
|
250
|
+
itemType='button'
|
|
210
251
|
value='comment'
|
|
211
|
-
|
|
252
|
+
icon='ph--chat-text--regular'
|
|
212
253
|
data-testid='editor.toolbar.comment'
|
|
213
254
|
onClick={() => {
|
|
214
255
|
if (!cursor) {
|
|
@@ -223,7 +264,7 @@ const Actions = () => {
|
|
|
223
264
|
disabled={!cursorOnly || overlapsCommentAnchor}
|
|
224
265
|
>
|
|
225
266
|
{t(tooltipLabelKey)}
|
|
226
|
-
</
|
|
267
|
+
</ToolbarItem>
|
|
227
268
|
);
|
|
228
269
|
};
|
|
229
270
|
|
package/src/components/index.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
7
|
export * from './ComputeGraph';
|
|
8
|
-
export * from './
|
|
8
|
+
export * from './GridSheet';
|
|
9
|
+
export * from './SheetContext';
|
|
9
10
|
|
|
10
11
|
// Lazily load components for content surfaces.
|
|
11
12
|
export const SheetContainer = React.lazy(() => import('./SheetContainer'));
|
package/src/defs/types.ts
CHANGED
|
@@ -34,6 +34,7 @@ export const addressToA1Notation = ({ col, row }: CellAddress): string => {
|
|
|
34
34
|
return `${columnLetter(col)}${row + 1}`;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
// TODO(burdon): See simpleCellAddressFromString
|
|
37
38
|
export const addressFromA1Notation = (ref: string): CellAddress => {
|
|
38
39
|
const match = ref.match(/([A-Z]+)(\d+)/);
|
|
39
40
|
invariant(match, `Invalid notation: ${ref}`);
|
package/src/defs/util.ts
CHANGED
|
@@ -5,7 +5,15 @@
|
|
|
5
5
|
import { randomBytes } from '@dxos/crypto';
|
|
6
6
|
import { create } from '@dxos/echo-schema';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
addressFromA1Notation,
|
|
10
|
+
type CellAddress,
|
|
11
|
+
type CellRange,
|
|
12
|
+
DEFAULT_COLUMNS,
|
|
13
|
+
DEFAULT_ROWS,
|
|
14
|
+
MAX_COLUMNS,
|
|
15
|
+
MAX_ROWS,
|
|
16
|
+
} from './types';
|
|
9
17
|
import { type CreateSheetOptions, type SheetSize, SheetType } from '../types';
|
|
10
18
|
|
|
11
19
|
// TODO(burdon): Factor out from dxos/protocols to new common package.
|
|
@@ -52,18 +60,26 @@ export const initialize = (
|
|
|
52
60
|
}
|
|
53
61
|
};
|
|
54
62
|
|
|
55
|
-
export const createSheet = ({
|
|
63
|
+
export const createSheet = ({ name, cells, ...size }: CreateSheetOptions = {}): SheetType => {
|
|
56
64
|
const sheet = create(SheetType, {
|
|
57
|
-
|
|
65
|
+
name,
|
|
58
66
|
cells: {},
|
|
59
67
|
rows: [],
|
|
60
68
|
columns: [],
|
|
61
69
|
rowMeta: {},
|
|
62
70
|
columnMeta: {},
|
|
63
|
-
formatting:
|
|
71
|
+
formatting: [],
|
|
64
72
|
});
|
|
65
73
|
|
|
66
74
|
initialize(sheet, size);
|
|
75
|
+
|
|
76
|
+
if (cells) {
|
|
77
|
+
Object.entries(cells).forEach(([key, { value }]) => {
|
|
78
|
+
const idx = addressToIndex(sheet, addressFromA1Notation(key));
|
|
79
|
+
sheet.cells[idx] = { value };
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
67
83
|
return sheet;
|
|
68
84
|
};
|
|
69
85
|
|
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
|
-
import React, { useEffect,
|
|
6
|
+
import React, { useEffect, useMemo } from 'react';
|
|
7
7
|
|
|
8
|
+
import { PublicKey } from '@dxos/keys';
|
|
8
9
|
import { useSpace } from '@dxos/react-client/echo';
|
|
9
10
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
10
11
|
import { useThemeContext } from '@dxos/react-ui';
|
|
@@ -13,16 +14,16 @@ import {
|
|
|
13
14
|
createMarkdownExtensions,
|
|
14
15
|
createThemeExtensions,
|
|
15
16
|
decorateMarkdown,
|
|
17
|
+
documentId,
|
|
16
18
|
useTextEditor,
|
|
17
19
|
} from '@dxos/react-ui-editor';
|
|
18
20
|
import { withTheme, withLayout } from '@dxos/storybook-utils';
|
|
19
21
|
import { nonNullable } from '@dxos/util';
|
|
20
22
|
|
|
21
|
-
import { compute } from './compute';
|
|
22
|
-
import {
|
|
23
|
-
import { type ComputeNode } from '../graph';
|
|
23
|
+
import { compute, computeGraphFacet } from './compute';
|
|
24
|
+
import { GridSheet, SheetProvider } from '../components';
|
|
24
25
|
import { useComputeGraph, useSheetModel } from '../hooks';
|
|
25
|
-
import { useTestSheet,
|
|
26
|
+
import { useTestSheet, withComputeGraphDecorator } from '../testing';
|
|
26
27
|
import { SheetType } from '../types';
|
|
27
28
|
|
|
28
29
|
const str = (...lines: string[]) => lines.join('\n');
|
|
@@ -34,20 +35,15 @@ type EditorProps = {
|
|
|
34
35
|
// TODO(burdon): Implement named expressions.
|
|
35
36
|
// https://hyperformula.handsontable.com/guide/cell-references.html
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
// TODO(burdon): Inline Adobe eCharts.
|
|
39
|
+
|
|
38
40
|
const SHEET_NAME = 'Test Sheet';
|
|
39
41
|
|
|
40
42
|
const Editor = ({ text }: EditorProps) => {
|
|
43
|
+
const id = useMemo(() => PublicKey.random(), []);
|
|
41
44
|
const { themeMode } = useThemeContext();
|
|
42
45
|
const space = useSpace();
|
|
43
|
-
const
|
|
44
|
-
const [node, setNode] = useState<ComputeNode>();
|
|
45
|
-
// TODO(burdon): Virtualize SheetModel.
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
if (graph) {
|
|
48
|
-
setNode(graph.getOrCreateNode(DOC_NAME));
|
|
49
|
-
}
|
|
50
|
-
}, [graph]);
|
|
46
|
+
const computeGraph = useComputeGraph(space);
|
|
51
47
|
const { parentRef, focusAttributes } = useTextEditor(
|
|
52
48
|
() => ({
|
|
53
49
|
initialValue: text,
|
|
@@ -55,11 +51,13 @@ const Editor = ({ text }: EditorProps) => {
|
|
|
55
51
|
createBasicExtensions(),
|
|
56
52
|
createMarkdownExtensions({ themeMode }),
|
|
57
53
|
createThemeExtensions({ themeMode, syntaxHighlighting: true }),
|
|
58
|
-
|
|
54
|
+
documentId.of(id.toHex()),
|
|
55
|
+
computeGraph && computeGraphFacet.of(computeGraph),
|
|
56
|
+
compute(),
|
|
59
57
|
decorateMarkdown(),
|
|
60
58
|
].filter(nonNullable),
|
|
61
59
|
}),
|
|
62
|
-
[
|
|
60
|
+
[computeGraph, themeMode],
|
|
63
61
|
);
|
|
64
62
|
|
|
65
63
|
return <div className='w-[40rem] overflow-hidden' ref={parentRef} {...focusAttributes} />;
|
|
@@ -68,23 +66,23 @@ const Editor = ({ text }: EditorProps) => {
|
|
|
68
66
|
const Grid = () => {
|
|
69
67
|
const space = useSpace();
|
|
70
68
|
const graph = useComputeGraph(space);
|
|
71
|
-
const sheet = useTestSheet(space, graph, {
|
|
72
|
-
const model = useSheetModel(
|
|
69
|
+
const sheet = useTestSheet(space, graph, { name: SHEET_NAME });
|
|
70
|
+
const model = useSheetModel(graph, sheet);
|
|
73
71
|
useEffect(() => {
|
|
74
72
|
if (model) {
|
|
75
73
|
model.setValues({ A1: { value: 100 }, A2: { value: 200 }, A3: { value: 300 }, A5: { value: '=SUM(A1:A3)' } });
|
|
76
74
|
}
|
|
77
75
|
}, [model]);
|
|
78
76
|
|
|
79
|
-
if (!
|
|
77
|
+
if (!graph || !sheet) {
|
|
80
78
|
return null;
|
|
81
79
|
}
|
|
82
80
|
|
|
83
81
|
return (
|
|
84
82
|
<div className='flex w-[40rem] overflow-hidden'>
|
|
85
|
-
<
|
|
86
|
-
<
|
|
87
|
-
</
|
|
83
|
+
<SheetProvider graph={graph} sheet={sheet}>
|
|
84
|
+
<GridSheet />
|
|
85
|
+
</SheetProvider>
|
|
88
86
|
</div>
|
|
89
87
|
);
|
|
90
88
|
};
|
|
@@ -102,13 +100,14 @@ export default {
|
|
|
102
100
|
title: 'plugin-sheet/extensions',
|
|
103
101
|
decorators: [
|
|
104
102
|
withClientProvider({ types: [SheetType], createIdentity: true, createSpace: true }),
|
|
105
|
-
|
|
103
|
+
withComputeGraphDecorator(),
|
|
106
104
|
withTheme,
|
|
107
105
|
withLayout({ fullscreen: true, classNames: 'justify-center' }),
|
|
108
106
|
],
|
|
109
107
|
parameters: { layout: 'fullscreen' },
|
|
110
108
|
};
|
|
111
109
|
|
|
110
|
+
// TODO(burdon): Inline formulae.
|
|
112
111
|
export const Default = {
|
|
113
112
|
render: Editor,
|
|
114
113
|
args: {
|
|
@@ -146,6 +145,7 @@ export const Graph = {
|
|
|
146
145
|
`="${SHEET_NAME}"!A5`,
|
|
147
146
|
'```',
|
|
148
147
|
'',
|
|
148
|
+
'',
|
|
149
149
|
),
|
|
150
150
|
},
|
|
151
151
|
};
|