@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
package/src/model/sheet-model.ts
CHANGED
|
@@ -8,9 +8,11 @@ import { type SimpleDate, type SimpleDateTime } from 'hyperformula/typings/DateT
|
|
|
8
8
|
|
|
9
9
|
import { Event } from '@dxos/async';
|
|
10
10
|
import { Resource } from '@dxos/context';
|
|
11
|
+
import { getTypename } from '@dxos/echo-schema';
|
|
11
12
|
import { invariant } from '@dxos/invariant';
|
|
12
13
|
import { PublicKey } from '@dxos/keys';
|
|
13
14
|
import { log } from '@dxos/log';
|
|
15
|
+
import { FieldValueType } from '@dxos/schema';
|
|
14
16
|
|
|
15
17
|
import { DetailedCellError, ExportedCellChange } from '#hyperformula';
|
|
16
18
|
import {
|
|
@@ -22,17 +24,18 @@ import {
|
|
|
22
24
|
MAX_ROWS,
|
|
23
25
|
} from '../defs';
|
|
24
26
|
import { addressFromIndex, addressToIndex, initialize, insertIndices, ReadonlyException } from '../defs';
|
|
25
|
-
import { type ComputeNode, type ComputeGraph, createSheetName } from '../graph';
|
|
26
|
-
import { type CellScalarValue, type CellValue, type SheetType
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
import { type ComputeNode, type ComputeGraph, createSheetName, type ComputeNodeEvent } from '../graph';
|
|
28
|
+
import { type CellScalarValue, type CellValue, type SheetType } from '../types';
|
|
29
|
+
|
|
30
|
+
// Map sheet types to system types.
|
|
31
|
+
const typeMap: Record<string, FieldValueType> = {
|
|
32
|
+
BOOLEAN: FieldValueType.Boolean,
|
|
33
|
+
NUMBER_RAW: FieldValueType.Number,
|
|
34
|
+
NUMBER_PERCENT: FieldValueType.Percent,
|
|
35
|
+
NUMBER_CURRENCY: FieldValueType.Currency,
|
|
36
|
+
NUMBER_DATETIME: FieldValueType.DateTime,
|
|
37
|
+
NUMBER_DATE: FieldValueType.Date,
|
|
38
|
+
NUMBER_TIME: FieldValueType.Time,
|
|
36
39
|
};
|
|
37
40
|
|
|
38
41
|
const getTopLeft = (range: CellRange): CellAddress => {
|
|
@@ -60,13 +63,14 @@ export type SheetModelOptions = {
|
|
|
60
63
|
*
|
|
61
64
|
* [ComputeGraphContext] > [SheetContext]:[SheetModel] > [Sheet.Root]
|
|
62
65
|
*/
|
|
63
|
-
// TODO(burdon): Factor out commonality with ComputeNode.
|
|
66
|
+
// TODO(burdon): Factor out commonality with ComputeNode. Factor out HF.
|
|
64
67
|
export class SheetModel extends Resource {
|
|
65
68
|
public readonly id = `model-${PublicKey.random().truncate()}`;
|
|
66
69
|
|
|
67
|
-
|
|
70
|
+
// Wraps compute node.
|
|
71
|
+
public readonly update = new Event<ComputeNodeEvent>();
|
|
68
72
|
|
|
69
|
-
private
|
|
73
|
+
private _node?: ComputeNode;
|
|
70
74
|
|
|
71
75
|
constructor(
|
|
72
76
|
private readonly _graph: ComputeGraph,
|
|
@@ -74,9 +78,6 @@ export class SheetModel extends Resource {
|
|
|
74
78
|
private readonly _options: SheetModelOptions = {},
|
|
75
79
|
) {
|
|
76
80
|
super();
|
|
77
|
-
// TODO(burdon): SheetModel should extend ComputeNode and be constructed via the graph.
|
|
78
|
-
this._node = this._graph.getOrCreateNode(createSheetName(this._sheet.id));
|
|
79
|
-
this.reset();
|
|
80
81
|
}
|
|
81
82
|
|
|
82
83
|
get graph() {
|
|
@@ -104,12 +105,16 @@ export class SheetModel extends Resource {
|
|
|
104
105
|
protected override async _open() {
|
|
105
106
|
log('initialize', { id: this.id });
|
|
106
107
|
initialize(this._sheet);
|
|
107
|
-
this.reset();
|
|
108
108
|
|
|
109
|
-
// TODO(burdon):
|
|
109
|
+
// TODO(burdon): SheetModel should extend ComputeNode and be constructed via the graph.
|
|
110
|
+
this._node = this._graph.getOrCreateNode(createSheetName({ type: getTypename(this._sheet)!, id: this._sheet.id }));
|
|
111
|
+
await this._node.open();
|
|
112
|
+
|
|
110
113
|
// Listen for model updates (e.g., async calculations).
|
|
111
|
-
const unsubscribe = this.
|
|
114
|
+
const unsubscribe = this._node.update.on((event) => this.update.emit(event));
|
|
112
115
|
this._ctx.onDispose(unsubscribe);
|
|
116
|
+
|
|
117
|
+
this.reset();
|
|
113
118
|
}
|
|
114
119
|
|
|
115
120
|
/**
|
|
@@ -118,8 +123,10 @@ export class SheetModel extends Resource {
|
|
|
118
123
|
* @deprecated
|
|
119
124
|
*/
|
|
120
125
|
reset() {
|
|
121
|
-
|
|
126
|
+
invariant(this._node);
|
|
127
|
+
this._node.graph.hf.clearSheet(this._node.sheetId);
|
|
122
128
|
Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
|
|
129
|
+
invariant(this._node);
|
|
123
130
|
const { col, row } = addressFromIndex(this._sheet, key);
|
|
124
131
|
if (typeof value === 'string' && value.charAt(0) === '=') {
|
|
125
132
|
value = this._graph.mapFormulaToNative(
|
|
@@ -127,7 +134,7 @@ export class SheetModel extends Resource {
|
|
|
127
134
|
);
|
|
128
135
|
}
|
|
129
136
|
|
|
130
|
-
this._node.hf.setCellContents({ sheet: this._node.sheetId, row, col }, value);
|
|
137
|
+
this._node.graph.hf.setCellContents({ sheet: this._node.sheetId, row, col }, value);
|
|
131
138
|
});
|
|
132
139
|
}
|
|
133
140
|
|
|
@@ -139,7 +146,7 @@ export class SheetModel extends Resource {
|
|
|
139
146
|
*/
|
|
140
147
|
// TODO(burdon): Remove.
|
|
141
148
|
recalculate() {
|
|
142
|
-
this._node.hf.rebuildAndRecalculate();
|
|
149
|
+
this._node?.graph.hf.rebuildAndRecalculate();
|
|
143
150
|
}
|
|
144
151
|
|
|
145
152
|
insertRows(i: number, n = 1) {
|
|
@@ -161,9 +168,10 @@ export class SheetModel extends Resource {
|
|
|
161
168
|
* Clear range of values.
|
|
162
169
|
*/
|
|
163
170
|
clear(range: CellRange) {
|
|
171
|
+
invariant(this._node);
|
|
164
172
|
const topLeft = getTopLeft(range);
|
|
165
173
|
const values = this._iterRange(range, () => null);
|
|
166
|
-
this._node.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
|
|
174
|
+
this._node.graph.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
|
|
167
175
|
this._iterRange(range, (cell) => {
|
|
168
176
|
const idx = addressToIndex(this._sheet, cell);
|
|
169
177
|
delete this._sheet.cells[idx];
|
|
@@ -171,7 +179,8 @@ export class SheetModel extends Resource {
|
|
|
171
179
|
}
|
|
172
180
|
|
|
173
181
|
cut(range: CellRange) {
|
|
174
|
-
|
|
182
|
+
invariant(this._node);
|
|
183
|
+
this._node.graph.hf.cut(toModelRange(this._node.sheetId, range));
|
|
175
184
|
this._iterRange(range, (cell) => {
|
|
176
185
|
const idx = addressToIndex(this._sheet, cell);
|
|
177
186
|
delete this._sheet.cells[idx];
|
|
@@ -179,12 +188,14 @@ export class SheetModel extends Resource {
|
|
|
179
188
|
}
|
|
180
189
|
|
|
181
190
|
copy(range: CellRange) {
|
|
182
|
-
|
|
191
|
+
invariant(this._node);
|
|
192
|
+
this._node.graph.hf.copy(toModelRange(this._node.sheetId, range));
|
|
183
193
|
}
|
|
184
194
|
|
|
185
195
|
paste(cell: CellAddress) {
|
|
186
|
-
|
|
187
|
-
|
|
196
|
+
invariant(this._node);
|
|
197
|
+
if (!this._node.graph.hf.isClipboardEmpty()) {
|
|
198
|
+
const changes = this._node.graph.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
|
|
188
199
|
for (const change of changes) {
|
|
189
200
|
if (change instanceof ExportedCellChange) {
|
|
190
201
|
const { address, newValue } = change;
|
|
@@ -197,16 +208,18 @@ export class SheetModel extends Resource {
|
|
|
197
208
|
|
|
198
209
|
// TODO(burdon): Display undo/redo state.
|
|
199
210
|
undo() {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
this.
|
|
211
|
+
invariant(this._node);
|
|
212
|
+
if (this._node.graph.hf.isThereSomethingToUndo()) {
|
|
213
|
+
this._node.graph.hf.undo();
|
|
214
|
+
// this.update.emit();
|
|
203
215
|
}
|
|
204
216
|
}
|
|
205
217
|
|
|
206
218
|
redo() {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
this.
|
|
219
|
+
invariant(this._node);
|
|
220
|
+
if (this._node.graph.hf.isThereSomethingToRedo()) {
|
|
221
|
+
this._node.graph.hf.redo();
|
|
222
|
+
// this.update.emit();
|
|
210
223
|
}
|
|
211
224
|
}
|
|
212
225
|
|
|
@@ -246,7 +259,8 @@ export class SheetModel extends Resource {
|
|
|
246
259
|
*/
|
|
247
260
|
getValue(cell: CellAddress): CellScalarValue {
|
|
248
261
|
// Applies rounding and post-processing.
|
|
249
|
-
|
|
262
|
+
invariant(this._node);
|
|
263
|
+
const value = this._node.graph.hf.getCellValue(toSimpleCellAddress(this._node.sheetId, cell));
|
|
250
264
|
if (value instanceof DetailedCellError) {
|
|
251
265
|
return value.toString();
|
|
252
266
|
}
|
|
@@ -257,9 +271,10 @@ export class SheetModel extends Resource {
|
|
|
257
271
|
/**
|
|
258
272
|
* Get value type.
|
|
259
273
|
*/
|
|
260
|
-
getValueType(cell: CellAddress):
|
|
274
|
+
getValueType(cell: CellAddress): FieldValueType {
|
|
275
|
+
invariant(this._node);
|
|
261
276
|
const addr = toSimpleCellAddress(this._node.sheetId, cell);
|
|
262
|
-
const type = this._node.hf.getCellValueDetailedType(addr);
|
|
277
|
+
const type = this._node.graph.hf.getCellValueDetailedType(addr);
|
|
263
278
|
return typeMap[type];
|
|
264
279
|
}
|
|
265
280
|
|
|
@@ -267,6 +282,7 @@ export class SheetModel extends Resource {
|
|
|
267
282
|
* Sets the value, updating the sheet and engine.
|
|
268
283
|
*/
|
|
269
284
|
setValue(cell: CellAddress, value: CellScalarValue) {
|
|
285
|
+
invariant(this._node);
|
|
270
286
|
if (this._options.readonly) {
|
|
271
287
|
throw new ReadonlyException();
|
|
272
288
|
}
|
|
@@ -288,7 +304,7 @@ export class SheetModel extends Resource {
|
|
|
288
304
|
}
|
|
289
305
|
|
|
290
306
|
// Insert into engine.
|
|
291
|
-
this._node.hf.setCellContents({ sheet: this._node.sheetId, row: cell.row, col: cell.col }, [
|
|
307
|
+
this._node.graph.hf.setCellContents({ sheet: this._node.sheetId, row: cell.row, col: cell.col }, [
|
|
292
308
|
[typeof value === 'string' && value.charAt(0) === '=' ? this._graph.mapFormulaToNative(value) : value],
|
|
293
309
|
]);
|
|
294
310
|
|
|
@@ -386,14 +402,17 @@ export class SheetModel extends Resource {
|
|
|
386
402
|
}
|
|
387
403
|
|
|
388
404
|
toDateTime(num: number): SimpleDateTime {
|
|
389
|
-
|
|
405
|
+
invariant(this._node);
|
|
406
|
+
return this._node.graph.hf.numberToDateTime(num) as SimpleDateTime;
|
|
390
407
|
}
|
|
391
408
|
|
|
392
409
|
toDate(num: number): SimpleDate {
|
|
393
|
-
|
|
410
|
+
invariant(this._node);
|
|
411
|
+
return this._node.graph.hf.numberToDate(num) as SimpleDate;
|
|
394
412
|
}
|
|
395
413
|
|
|
396
414
|
toTime(num: number): SimpleDate {
|
|
397
|
-
|
|
415
|
+
invariant(this._node);
|
|
416
|
+
return this._node.graph.hf.numberToTime(num) as SimpleDate;
|
|
398
417
|
}
|
|
399
418
|
}
|
package/src/testing/testing.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type
|
|
5
|
+
import { type Decorator } from '@storybook/react';
|
|
6
6
|
import React, { useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { type Space } from '@dxos/react-client/echo';
|
|
@@ -10,14 +10,13 @@ import { useAsyncState } from '@dxos/react-hooks';
|
|
|
10
10
|
|
|
11
11
|
import { ComputeGraphContextProvider } from '../components';
|
|
12
12
|
import { createSheet } from '../defs';
|
|
13
|
-
import { type ComputeGraph, ComputeGraphRegistry } from '../graph';
|
|
13
|
+
import { type ComputeGraph, type ComputeGraphOptions, ComputeGraphRegistry } from '../graph';
|
|
14
14
|
import { type CellValue, type CreateSheetOptions } from '../types';
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
const testSheetName = 'test';
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
B1: { value: 'Qty' },
|
|
18
|
+
export const createTestCells = (): Record<string, CellValue> => ({
|
|
19
|
+
B1: { value: 'Qty2' },
|
|
21
20
|
B3: { value: 1 },
|
|
22
21
|
B4: { value: 2 },
|
|
23
22
|
B5: { value: 3 },
|
|
@@ -45,7 +44,7 @@ export const createCells = (): Record<string, CellValue> => ({
|
|
|
45
44
|
});
|
|
46
45
|
|
|
47
46
|
export const useTestSheet = (space?: Space, graph?: ComputeGraph, options?: CreateSheetOptions) => {
|
|
48
|
-
|
|
47
|
+
const [sheet] = useAsyncState(async () => {
|
|
49
48
|
if (!space || !graph) {
|
|
50
49
|
return;
|
|
51
50
|
}
|
|
@@ -54,13 +53,16 @@ export const useTestSheet = (space?: Space, graph?: ComputeGraph, options?: Crea
|
|
|
54
53
|
space.db.add(sheet);
|
|
55
54
|
return sheet;
|
|
56
55
|
}, [space, graph]);
|
|
56
|
+
return sheet;
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
export const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
export const withComputeGraphDecorator =
|
|
60
|
+
(options?: ComputeGraphOptions): Decorator =>
|
|
61
|
+
(Story) => {
|
|
62
|
+
const [registry] = useState(new ComputeGraphRegistry(options));
|
|
63
|
+
return (
|
|
64
|
+
<ComputeGraphContextProvider registry={registry}>
|
|
65
|
+
<Story />
|
|
66
|
+
</ComputeGraphContextProvider>
|
|
67
|
+
);
|
|
68
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { type MarkdownExtensionProvides } from '@dxos/plugin-markdown';
|
|
|
15
15
|
import { type SpaceInitProvides } from '@dxos/plugin-space';
|
|
16
16
|
import { ThreadType } from '@dxos/plugin-space/types';
|
|
17
17
|
import { type StackProvides } from '@dxos/plugin-stack';
|
|
18
|
+
import { FieldValueType } from '@dxos/schema';
|
|
18
19
|
|
|
19
20
|
import { SHEET_PLUGIN } from './meta';
|
|
20
21
|
|
|
@@ -51,41 +52,15 @@ export const CellValue = S.Struct({
|
|
|
51
52
|
// TODO(burdon): How to store dates (datetime, date, time), percentages, etc.
|
|
52
53
|
// Consider import/export; natural access for other plugins. Special handling for currency (precision).
|
|
53
54
|
// TODO(burdon): Automerge (long string) or short string or number.
|
|
54
|
-
// TODO(burdon): Arrays?
|
|
55
55
|
value: S.Any,
|
|
56
56
|
});
|
|
57
57
|
|
|
58
58
|
export type CellValue = S.Schema.Type<typeof CellValue>;
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
* https://www.tutorialsteacher.com/typescript/typescript-number
|
|
62
|
-
*/
|
|
63
|
-
// TODO(burdon): Format vs. value.
|
|
64
|
-
export enum ValueTypeEnum {
|
|
65
|
-
Null = 0,
|
|
66
|
-
Number = 1,
|
|
67
|
-
Boolean = 2,
|
|
68
|
-
String = 3,
|
|
69
|
-
|
|
70
|
-
// Special numbers.
|
|
71
|
-
Percent = 10,
|
|
72
|
-
Currency = 11,
|
|
73
|
-
|
|
74
|
-
// Dates.
|
|
75
|
-
DateTime = 20,
|
|
76
|
-
Date = 21,
|
|
77
|
-
Time = 22,
|
|
78
|
-
|
|
79
|
-
// Validated string types.
|
|
80
|
-
// TODO(burdon): Define effect types.
|
|
81
|
-
URL = 30,
|
|
82
|
-
DID = 31,
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export const ValueType = S.Enums(ValueTypeEnum);
|
|
86
|
-
|
|
60
|
+
// TODO(burdon): IMPORTANT: Reconcile with Field definition.
|
|
87
61
|
export const Formatting = S.Struct({
|
|
88
|
-
|
|
62
|
+
range: S.String,
|
|
63
|
+
type: S.optional(S.Enums(FieldValueType)),
|
|
89
64
|
format: S.optional(S.String),
|
|
90
65
|
precision: S.optional(S.Number),
|
|
91
66
|
classNames: S.optional(S.Array(S.String)),
|
|
@@ -99,13 +74,11 @@ export const RowColumnMeta = S.Struct({
|
|
|
99
74
|
});
|
|
100
75
|
|
|
101
76
|
// TODO(burdon): Index to all updates when rows/columns are inserted/deleted.
|
|
102
|
-
// TODO(wittjosiah): Migrate typename to remove `Type` suffix.
|
|
103
|
-
// TODO(wittjosiah): Rename title to name to align with other schemas.
|
|
104
77
|
export class SheetType extends TypedObject({ typename: 'dxos.org/type/SheetType', version: '0.1.0' })({
|
|
105
|
-
|
|
78
|
+
name: S.optional(S.String),
|
|
106
79
|
|
|
107
80
|
// Sparse map of cells referenced by index.
|
|
108
|
-
cells: S.mutable(S.Record(S.String, S.mutable(CellValue))),
|
|
81
|
+
cells: S.mutable(S.Record({ key: S.String, value: S.mutable(CellValue) })),
|
|
109
82
|
|
|
110
83
|
// Ordered row indices.
|
|
111
84
|
rows: S.mutable(S.Array(S.String)),
|
|
@@ -114,13 +87,14 @@ export class SheetType extends TypedObject({ typename: 'dxos.org/type/SheetType'
|
|
|
114
87
|
columns: S.mutable(S.Array(S.String)),
|
|
115
88
|
|
|
116
89
|
// Row metadata referenced by index.
|
|
117
|
-
rowMeta: S.mutable(S.Record(S.String, S.mutable(RowColumnMeta))),
|
|
90
|
+
rowMeta: S.mutable(S.Record({ key: S.String, value: S.mutable(RowColumnMeta) })),
|
|
118
91
|
|
|
119
92
|
// Column metadata referenced by index.
|
|
120
|
-
columnMeta: S.mutable(S.Record(S.String, S.mutable(RowColumnMeta))),
|
|
93
|
+
columnMeta: S.mutable(S.Record({ key: S.String, value: S.mutable(RowColumnMeta) })),
|
|
121
94
|
|
|
95
|
+
// TODO(burdon): Change to array.
|
|
122
96
|
// Cell formatting referenced by indexed range.
|
|
123
|
-
formatting: S.mutable(S.
|
|
97
|
+
formatting: S.mutable(S.Array(Formatting)),
|
|
124
98
|
|
|
125
99
|
// Threads associated with the sheet
|
|
126
100
|
threads: S.optional(S.mutable(S.Array(ref(ThreadType)))),
|
|
@@ -132,6 +106,6 @@ export type SheetSize = {
|
|
|
132
106
|
};
|
|
133
107
|
|
|
134
108
|
export type CreateSheetOptions = {
|
|
135
|
-
|
|
136
|
-
|
|
109
|
+
name?: string;
|
|
110
|
+
cells?: Record<string, CellValue>;
|
|
137
111
|
} & Partial<SheetSize>;
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Sheet,
|
|
3
|
-
addressToIndex,
|
|
4
|
-
useSheetContext
|
|
5
|
-
} from "./chunk-U2JHW3L6.mjs";
|
|
6
|
-
import "./chunk-T3NJFTD4.mjs";
|
|
7
|
-
import {
|
|
8
|
-
SHEET_PLUGIN
|
|
9
|
-
} from "./chunk-QILRZNE5.mjs";
|
|
10
|
-
import "./chunk-6ZMQVB4Z.mjs";
|
|
11
|
-
|
|
12
|
-
// packages/plugins/plugin-sheet/src/components/SheetContainer.tsx
|
|
13
|
-
import React3, { useCallback } from "react";
|
|
14
|
-
import { useIntentDispatcher } from "@dxos/app-framework";
|
|
15
|
-
import { fullyQualifiedId } from "@dxos/react-client/echo";
|
|
16
|
-
import { useIsDirectlyAttended } from "@dxos/react-ui-attention";
|
|
17
|
-
import { focusRing, mx } from "@dxos/react-ui-theme";
|
|
18
|
-
|
|
19
|
-
// packages/plugins/plugin-sheet/src/components/Toolbar/Toolbar.tsx
|
|
20
|
-
import { Calendar, ChatText, CurrencyDollar, Eraser, HighlighterCircle, TextAlignCenter, TextAlignLeft, TextAlignRight } from "@phosphor-icons/react";
|
|
21
|
-
import { createContext } from "@radix-ui/react-context";
|
|
22
|
-
import React2 from "react";
|
|
23
|
-
import { DensityProvider, ElevationProvider, Toolbar as NaturalToolbar2, useTranslation } from "@dxos/react-ui";
|
|
24
|
-
import { nonNullable } from "@dxos/util";
|
|
25
|
-
|
|
26
|
-
// packages/plugins/plugin-sheet/src/components/Toolbar/common.tsx
|
|
27
|
-
import React from "react";
|
|
28
|
-
import { Toolbar as NaturalToolbar, Tooltip } from "@dxos/react-ui";
|
|
29
|
-
import { getSize } from "@dxos/react-ui-theme";
|
|
30
|
-
var iconStyles = getSize(5);
|
|
31
|
-
var buttonStyles = "min-bs-0 p-2";
|
|
32
|
-
var tooltipProps = {
|
|
33
|
-
side: "top",
|
|
34
|
-
classNames: "z-10"
|
|
35
|
-
};
|
|
36
|
-
var ToolbarSeparator = () => /* @__PURE__ */ React.createElement("div", {
|
|
37
|
-
role: "separator",
|
|
38
|
-
className: "grow"
|
|
39
|
-
});
|
|
40
|
-
var ToolbarButton = ({ Icon, children, ...props }) => {
|
|
41
|
-
return /* @__PURE__ */ React.createElement(Tooltip.Root, null, /* @__PURE__ */ React.createElement(Tooltip.Trigger, {
|
|
42
|
-
asChild: true
|
|
43
|
-
}, /* @__PURE__ */ React.createElement(NaturalToolbar.Button, {
|
|
44
|
-
variant: "ghost",
|
|
45
|
-
...props,
|
|
46
|
-
classNames: buttonStyles
|
|
47
|
-
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
48
|
-
className: iconStyles
|
|
49
|
-
}), /* @__PURE__ */ React.createElement("span", {
|
|
50
|
-
className: "sr-only"
|
|
51
|
-
}, children))), /* @__PURE__ */ React.createElement(Tooltip.Portal, null, /* @__PURE__ */ React.createElement(Tooltip.Content, tooltipProps, children, /* @__PURE__ */ React.createElement(Tooltip.Arrow, null))));
|
|
52
|
-
};
|
|
53
|
-
var ToolbarToggleButton = ({ Icon, children, ...props }) => {
|
|
54
|
-
return /* @__PURE__ */ React.createElement(Tooltip.Root, null, /* @__PURE__ */ React.createElement(Tooltip.Trigger, {
|
|
55
|
-
asChild: true
|
|
56
|
-
}, /* @__PURE__ */ React.createElement(NaturalToolbar.ToggleGroupItem, {
|
|
57
|
-
variant: "ghost",
|
|
58
|
-
...props,
|
|
59
|
-
classNames: buttonStyles
|
|
60
|
-
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
61
|
-
className: iconStyles
|
|
62
|
-
}), /* @__PURE__ */ React.createElement("span", {
|
|
63
|
-
className: "sr-only"
|
|
64
|
-
}, children))), /* @__PURE__ */ React.createElement(Tooltip.Portal, null, /* @__PURE__ */ React.createElement(Tooltip.Content, tooltipProps, children, /* @__PURE__ */ React.createElement(Tooltip.Arrow, null))));
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// packages/plugins/plugin-sheet/src/components/Toolbar/Toolbar.tsx
|
|
68
|
-
var [ToolbarContextProvider, useToolbarContext] = createContext("Toolbar");
|
|
69
|
-
var ToolbarRoot = ({ children, onAction, classNames }) => {
|
|
70
|
-
return /* @__PURE__ */ React2.createElement(ToolbarContextProvider, {
|
|
71
|
-
onAction
|
|
72
|
-
}, /* @__PURE__ */ React2.createElement(DensityProvider, {
|
|
73
|
-
density: "fine"
|
|
74
|
-
}, /* @__PURE__ */ React2.createElement(ElevationProvider, {
|
|
75
|
-
elevation: "chrome"
|
|
76
|
-
}, /* @__PURE__ */ React2.createElement(NaturalToolbar2.Root, {
|
|
77
|
-
classNames: [
|
|
78
|
-
"is-full shrink-0 overflow-x-auto overflow-y-hidden p-1",
|
|
79
|
-
classNames
|
|
80
|
-
]
|
|
81
|
-
}, children))));
|
|
82
|
-
};
|
|
83
|
-
var formatOptions = [
|
|
84
|
-
{
|
|
85
|
-
type: "date",
|
|
86
|
-
Icon: Calendar,
|
|
87
|
-
getState: (state) => false
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
type: "currency",
|
|
91
|
-
Icon: CurrencyDollar,
|
|
92
|
-
getState: (state) => false
|
|
93
|
-
}
|
|
94
|
-
];
|
|
95
|
-
var Format = () => {
|
|
96
|
-
const { onAction } = useToolbarContext("Format");
|
|
97
|
-
const { t } = useTranslation(SHEET_PLUGIN);
|
|
98
|
-
return /* @__PURE__ */ React2.createElement(NaturalToolbar2.ToggleGroup, {
|
|
99
|
-
type: "single"
|
|
100
|
-
}, formatOptions.map(({ type, getState, Icon }) => /* @__PURE__ */ React2.createElement(ToolbarToggleButton, {
|
|
101
|
-
key: type,
|
|
102
|
-
value: type,
|
|
103
|
-
Icon,
|
|
104
|
-
// disabled={state?.blockType === 'codeblock'}
|
|
105
|
-
// onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
|
|
106
|
-
onClick: () => onAction?.({
|
|
107
|
-
type
|
|
108
|
-
})
|
|
109
|
-
}, t(`toolbar ${type} label`))));
|
|
110
|
-
};
|
|
111
|
-
var alignmentOptions = [
|
|
112
|
-
{
|
|
113
|
-
type: "left",
|
|
114
|
-
Icon: TextAlignLeft,
|
|
115
|
-
getState: (state) => false
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
type: "center",
|
|
119
|
-
Icon: TextAlignCenter,
|
|
120
|
-
getState: (state) => false
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
type: "right",
|
|
124
|
-
Icon: TextAlignRight,
|
|
125
|
-
getState: (state) => false
|
|
126
|
-
}
|
|
127
|
-
];
|
|
128
|
-
var Alignment = () => {
|
|
129
|
-
const { onAction } = useToolbarContext("Alignment");
|
|
130
|
-
const { t } = useTranslation(SHEET_PLUGIN);
|
|
131
|
-
return /* @__PURE__ */ React2.createElement(NaturalToolbar2.ToggleGroup, {
|
|
132
|
-
type: "single"
|
|
133
|
-
}, alignmentOptions.map(({ type, getState, Icon }) => /* @__PURE__ */ React2.createElement(ToolbarToggleButton, {
|
|
134
|
-
key: type,
|
|
135
|
-
value: type,
|
|
136
|
-
Icon,
|
|
137
|
-
// disabled={state?.blockType === 'codeblock'}
|
|
138
|
-
// onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
|
|
139
|
-
onClick: () => onAction?.({
|
|
140
|
-
type
|
|
141
|
-
})
|
|
142
|
-
}, t(`toolbar ${type} label`))));
|
|
143
|
-
};
|
|
144
|
-
var styleOptions = [
|
|
145
|
-
{
|
|
146
|
-
type: "clear",
|
|
147
|
-
Icon: Eraser,
|
|
148
|
-
getState: (state) => false
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
type: "highlight",
|
|
152
|
-
Icon: HighlighterCircle,
|
|
153
|
-
getState: (state) => false
|
|
154
|
-
}
|
|
155
|
-
];
|
|
156
|
-
var Styles = () => {
|
|
157
|
-
const { onAction } = useToolbarContext("Alignment");
|
|
158
|
-
const { t } = useTranslation(SHEET_PLUGIN);
|
|
159
|
-
return /* @__PURE__ */ React2.createElement(NaturalToolbar2.ToggleGroup, {
|
|
160
|
-
type: "single"
|
|
161
|
-
}, styleOptions.map(({ type, getState, Icon }) => /* @__PURE__ */ React2.createElement(ToolbarToggleButton, {
|
|
162
|
-
key: type,
|
|
163
|
-
value: type,
|
|
164
|
-
Icon,
|
|
165
|
-
// disabled={state?.blockType === 'codeblock'}
|
|
166
|
-
// onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
|
|
167
|
-
onClick: () => onAction?.({
|
|
168
|
-
type
|
|
169
|
-
})
|
|
170
|
-
}, t(`toolbar ${type} label`))));
|
|
171
|
-
};
|
|
172
|
-
var Actions = () => {
|
|
173
|
-
const { onAction } = useToolbarContext("Actions");
|
|
174
|
-
const { cursor, range, model } = useSheetContext();
|
|
175
|
-
const { t } = useTranslation(SHEET_PLUGIN);
|
|
176
|
-
const overlapsCommentAnchor = (model.sheet.threads ?? []).filter(nonNullable).filter((thread) => thread.status !== "resolved").some((thread) => {
|
|
177
|
-
if (!cursor) {
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
180
|
-
return addressToIndex(model.sheet, cursor) === thread.anchor;
|
|
181
|
-
});
|
|
182
|
-
const hasCursor = !!cursor;
|
|
183
|
-
const cursorOnly = hasCursor && !range && !overlapsCommentAnchor;
|
|
184
|
-
const tooltipLabelKey = !hasCursor ? "no cursor label" : overlapsCommentAnchor ? "selection overlaps existing comment label" : range ? "comment ranges not supported label" : "comment label";
|
|
185
|
-
return /* @__PURE__ */ React2.createElement(ToolbarButton, {
|
|
186
|
-
value: "comment",
|
|
187
|
-
Icon: ChatText,
|
|
188
|
-
"data-testid": "editor.toolbar.comment",
|
|
189
|
-
onClick: () => {
|
|
190
|
-
if (!cursor) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
return onAction?.({
|
|
194
|
-
type: "comment",
|
|
195
|
-
anchor: addressToIndex(model.sheet, cursor),
|
|
196
|
-
cellContent: model.getCellText(cursor)
|
|
197
|
-
});
|
|
198
|
-
},
|
|
199
|
-
disabled: !cursorOnly || overlapsCommentAnchor
|
|
200
|
-
}, t(tooltipLabelKey));
|
|
201
|
-
};
|
|
202
|
-
var Toolbar = {
|
|
203
|
-
Root: ToolbarRoot,
|
|
204
|
-
Separator: ToolbarSeparator,
|
|
205
|
-
Alignment,
|
|
206
|
-
Format,
|
|
207
|
-
Styles,
|
|
208
|
-
Actions
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
// packages/plugins/plugin-sheet/src/components/SheetContainer.tsx
|
|
212
|
-
var attentionFragment = mx("group-focus-within/editor:attention-surface group-[[aria-current]]/editor:attention-surface", "group-focus-within/editor:border-separator");
|
|
213
|
-
var sectionToolbarLayout = "bs-[--rail-action] bg-[--sticky-bg] sticky block-start-0 __-block-start-px transition-opacity";
|
|
214
|
-
var SheetContainer = ({ sheet, space, role }) => {
|
|
215
|
-
const dispatch = useIntentDispatcher();
|
|
216
|
-
const id = fullyQualifiedId(sheet);
|
|
217
|
-
const isDirectlyAttended = useIsDirectlyAttended(id);
|
|
218
|
-
const handleAction = useCallback((action) => {
|
|
219
|
-
switch (action.type) {
|
|
220
|
-
case "comment": {
|
|
221
|
-
void dispatch({
|
|
222
|
-
action: "dxos.org/plugin/thread/action/create",
|
|
223
|
-
data: {
|
|
224
|
-
cursor: action.anchor,
|
|
225
|
-
name: action.cellContent,
|
|
226
|
-
subject: sheet
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}, [
|
|
232
|
-
sheet,
|
|
233
|
-
dispatch
|
|
234
|
-
]);
|
|
235
|
-
return /* @__PURE__ */ React3.createElement("div", {
|
|
236
|
-
role: "none",
|
|
237
|
-
className: role === "article" ? "row-span-2 grid grid-rows-subgrid" : void 0
|
|
238
|
-
}, /* @__PURE__ */ React3.createElement(Sheet.Root, {
|
|
239
|
-
space,
|
|
240
|
-
sheet
|
|
241
|
-
}, /* @__PURE__ */ React3.createElement("div", {
|
|
242
|
-
role: "none",
|
|
243
|
-
className: mx("flex flex-0 justify-center overflow-x-auto")
|
|
244
|
-
}, /* @__PURE__ */ React3.createElement(Toolbar.Root, {
|
|
245
|
-
onAction: handleAction,
|
|
246
|
-
classNames: mx(role === "section" ? [
|
|
247
|
-
"z-[2] group-focus-within/section:visible",
|
|
248
|
-
!isDirectlyAttended && "invisible",
|
|
249
|
-
sectionToolbarLayout
|
|
250
|
-
] : "group-focus-within/editor:border-separator group-[[aria-current]]/editor:border-separator")
|
|
251
|
-
}, /* @__PURE__ */ React3.createElement(Toolbar.Separator, null), /* @__PURE__ */ React3.createElement(Toolbar.Actions, null))), /* @__PURE__ */ React3.createElement("div", {
|
|
252
|
-
role: "none",
|
|
253
|
-
className: mx(role === "section" && "aspect-square border-is border-bs border-be border-separator", role === "article" && "flex is-full overflow-hidden focus-visible:ring-inset row-span-1 data-[toolbar=disabled]:pbs-2 data-[toolbar=disabled]:row-span-2 border-bs border-separator", focusRing, attentionFragment)
|
|
254
|
-
}, /* @__PURE__ */ React3.createElement(Sheet.Main, null))));
|
|
255
|
-
};
|
|
256
|
-
var SheetContainer_default = SheetContainer;
|
|
257
|
-
export {
|
|
258
|
-
SheetContainer_default as default,
|
|
259
|
-
sectionToolbarLayout
|
|
260
|
-
};
|
|
261
|
-
//# sourceMappingURL=SheetContainer-V4GCCZTX.mjs.map
|