@dxos/plugin-sheet 0.6.12-main.f9d0246 → 0.6.12-staging.0b4bb48
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/{chunk-ZLJ2GRE2.mjs → SheetContainer-U4H5D34A.mjs} +240 -1151
- 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/browser/{chunk-Z2XOOC2R.mjs → chunk-D5AGLXJP.mjs} +678 -385
- package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +7 -0
- package/dist/lib/browser/{chunk-WZMOZKQZ.mjs → chunk-FUAGSXA4.mjs} +16 -9
- package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +7 -0
- package/dist/lib/{node-esm/chunk-IU2L277A.mjs → browser/chunk-JRL5LGCE.mjs} +5 -4
- 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 +60 -74
- 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 +6 -4
- package/dist/lib/node/{chunk-6DQABRGJ.cjs → SheetContainer-AXQV3ZT5.cjs} +279 -1182
- package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +7 -0
- package/dist/lib/node/{chunk-P5QYYEHQ.cjs → chunk-5KKJ4NPP.cjs} +676 -388
- package/dist/lib/node/chunk-5KKJ4NPP.cjs.map +7 -0
- package/dist/lib/node/{chunk-BNARJ5GM.cjs → chunk-BJ6ZD7MN.cjs} +18 -5
- 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-AOP42UAA.cjs → chunk-DSYKOI4E.cjs} +21 -13
- 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 +66 -86
- 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 +12 -10
- 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 +3 -23
- package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +1 -1
- package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts +2 -2
- package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/CellEditor/extension.d.ts +1 -1
- package/dist/types/src/components/CellEditor/extension.d.ts.map +1 -1
- package/dist/types/src/{graph → components/ComputeGraph}/async-function.d.ts +2 -8
- package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +1 -0
- package/dist/types/src/{graph/testing/custom-function.d.ts → components/ComputeGraph/custom.d.ts} +2 -4
- package/dist/types/src/components/ComputeGraph/custom.d.ts.map +1 -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 +1 -1
- package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -1
- package/dist/types/src/components/Sheet/Sheet.stories.d.ts +6 -5
- package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -1
- 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 +2 -2
- package/dist/types/src/components/Sheet/grid.d.ts.map +1 -1
- package/dist/types/src/components/Sheet/nav.d.ts +3 -3
- package/dist/types/src/components/Sheet/nav.d.ts.map +1 -1
- package/dist/types/src/components/Sheet/sheet-context.d.ts +7 -8
- package/dist/types/src/components/Sheet/sheet-context.d.ts.map +1 -1
- package/dist/types/src/components/SheetContainer.d.ts +3 -2
- package/dist/types/src/components/SheetContainer.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +3 -19
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +13 -18
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +2 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +4 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/{graph/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} +65 -10
- 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 +5 -86
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +41 -48
- package/src/SheetPlugin.tsx +73 -48
- package/src/components/CellEditor/CellEditor.stories.tsx +4 -5
- package/src/components/CellEditor/CellEditor.tsx +9 -59
- package/src/components/CellEditor/extension.test.ts +5 -4
- package/src/components/CellEditor/extension.ts +3 -1
- package/src/{graph → components/ComputeGraph}/async-function.ts +6 -15
- package/src/{graph/testing/custom-function.ts → components/ComputeGraph/custom.ts} +7 -11
- package/src/{graph → components/ComputeGraph}/edge-function.ts +3 -3
- 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 +88 -52
- package/src/components/Sheet/Sheet.tsx +18 -57
- package/src/{model/formatting-model.ts → components/Sheet/formatting.ts} +13 -20
- package/src/components/Sheet/grid.ts +3 -3
- package/src/components/Sheet/nav.ts +19 -19
- package/src/components/Sheet/sheet-context.tsx +80 -18
- package/src/components/SheetContainer.tsx +19 -73
- package/src/components/Toolbar/Toolbar.tsx +12 -53
- package/src/components/index.ts +0 -1
- package/src/meta.tsx +5 -1
- 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 +6 -31
- package/dist/lib/browser/SheetContainer-VISF3VUB.mjs +0 -261
- package/dist/lib/browser/SheetContainer-VISF3VUB.mjs.map +0 -7
- package/dist/lib/browser/chunk-QILRZNE5.mjs +0 -15
- package/dist/lib/browser/chunk-QILRZNE5.mjs.map +0 -7
- package/dist/lib/browser/chunk-WZMOZKQZ.mjs.map +0 -7
- package/dist/lib/browser/chunk-Z2XOOC2R.mjs.map +0 -7
- package/dist/lib/browser/chunk-ZLJ2GRE2.mjs.map +0 -7
- package/dist/lib/browser/graph-4XFKIHRL.mjs +0 -21
- package/dist/lib/browser/graph-4XFKIHRL.mjs.map +0 -7
- package/dist/lib/node/SheetContainer-2MEALQWW.cjs +0 -279
- package/dist/lib/node/SheetContainer-2MEALQWW.cjs.map +0 -7
- package/dist/lib/node/chunk-6DQABRGJ.cjs.map +0 -7
- package/dist/lib/node/chunk-AOP42UAA.cjs.map +0 -7
- package/dist/lib/node/chunk-BNARJ5GM.cjs.map +0 -7
- package/dist/lib/node/chunk-P5QYYEHQ.cjs.map +0 -7
- package/dist/lib/node/graph-2LRDUXBZ.cjs +0 -43
- package/dist/lib/node/graph-2LRDUXBZ.cjs.map +0 -7
- package/dist/lib/node-esm/SheetContainer-RPSUSXWS.mjs +0 -262
- package/dist/lib/node-esm/SheetContainer-RPSUSXWS.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-4MM7THJW.mjs +0 -2944
- package/dist/lib/node-esm/chunk-4MM7THJW.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-5RLTCIE2.mjs +0 -2684
- package/dist/lib/node-esm/chunk-5RLTCIE2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-IU2L277A.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-RR2AO4SM.mjs +0 -76
- package/dist/lib/node-esm/chunk-RR2AO4SM.mjs.map +0 -7
- package/dist/lib/node-esm/graph-WG5EKOMO.mjs +0 -22
- package/dist/lib/node-esm/graph-WG5EKOMO.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -263
- 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 -21
- 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/GridSheet/GridSheet.d.ts +0 -10
- 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/util.d.ts +0 -7
- package/dist/types/src/components/GridSheet/util.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/decorations.d.ts +0 -24
- package/dist/types/src/components/Sheet/decorations.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/defs/index.d.ts +0 -3
- package/dist/types/src/defs/index.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 -9
- 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/index.d.ts +0 -2
- package/dist/types/src/extensions/index.d.ts.map +0 -1
- package/dist/types/src/graph/async-function.d.ts.map +0 -1
- package/dist/types/src/graph/compute-graph.d.ts +0 -84
- 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/edge-function.d.ts.map +0 -1
- package/dist/types/src/graph/function-defs.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 -4
- package/dist/types/src/graph/index.d.ts.map +0 -1
- package/dist/types/src/graph/testing/custom-function.d.ts.map +0 -1
- package/dist/types/src/graph/testing/index.d.ts +0 -2
- package/dist/types/src/graph/testing/index.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/useComputeGraph.d.ts +0 -7
- package/dist/types/src/hooks/useComputeGraph.d.ts.map +0 -1
- package/dist/types/src/hooks/useFormattingModel.d.ts +0 -3
- package/dist/types/src/hooks/useFormattingModel.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/formatting-model.d.ts +0 -16
- package/dist/types/src/model/formatting-model.d.ts.map +0 -1
- package/dist/types/src/model/sheet-model.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/GridSheet/GridSheet.stories.tsx +0 -36
- package/src/components/GridSheet/GridSheet.tsx +0 -153
- package/src/components/GridSheet/util.ts +0 -108
- package/src/components/Sheet/decorations.ts +0 -62
- package/src/components/Sheet/threads.tsx +0 -205
- package/src/defs/index.ts +0 -6
- package/src/defs/util.ts +0 -151
- package/src/extensions/compute.stories.tsx +0 -153
- package/src/extensions/compute.ts +0 -131
- package/src/extensions/index.ts +0 -5
- package/src/graph/compute-graph.stories.tsx +0 -93
- package/src/graph/compute-graph.test.ts +0 -127
- package/src/graph/compute-graph.ts +0 -313
- package/src/graph/compute-node.ts +0 -62
- package/src/graph/hyperformula.test.ts +0 -15
- package/src/graph/index.ts +0 -7
- package/src/graph/testing/index.ts +0 -5
- 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/useComputeGraph.ts +0 -21
- package/src/hooks/useFormattingModel.ts +0 -11
- package/src/hooks/useSheetModel.ts +0 -40
- package/src/model/sheet-model.ts +0 -414
- package/src/sanity.test.ts +0 -40
- package/src/testing/index.ts +0 -5
- package/src/testing/testing.tsx +0 -68
- /package/dist/types/src/{graph → components/ComputeGraph}/edge-function.d.ts +0 -0
- /package/dist/types/src/{defs → model}/types.test.d.ts +0 -0
- /package/src/{graph/function-defs.ts → model/functions.ts} +0 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type FunctionPluginDefinition, HyperFormula } from 'hyperformula';
|
|
6
|
+
import { type FunctionTranslationsPackage } from 'hyperformula/typings/interpreter';
|
|
7
|
+
|
|
8
|
+
import { Event } from '@dxos/async';
|
|
9
|
+
import { type Space } from '@dxos/client/echo';
|
|
10
|
+
import { PublicKey } from '@dxos/keys';
|
|
11
|
+
import { log } from '@dxos/log';
|
|
12
|
+
|
|
13
|
+
import { FunctionContext, type FunctionContextOptions } from './async-function';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Create root graph for space.
|
|
17
|
+
*/
|
|
18
|
+
export const createComputeGraph = (
|
|
19
|
+
// TODO(wittjosiah): Factor out this type to make these easier to define.
|
|
20
|
+
functionPlugins: { plugin: FunctionPluginDefinition; translations: FunctionTranslationsPackage }[] = [],
|
|
21
|
+
space?: Space,
|
|
22
|
+
options?: Partial<FunctionContextOptions>,
|
|
23
|
+
): ComputeGraph => {
|
|
24
|
+
functionPlugins.forEach(({ plugin, translations }) => {
|
|
25
|
+
HyperFormula.registerFunctionPlugin(plugin, translations);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const hf = HyperFormula.buildEmpty({ licenseKey: 'gpl-v3' });
|
|
29
|
+
return new ComputeGraph(hf, space, options);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Per-space compute and dependency graph.
|
|
34
|
+
*/
|
|
35
|
+
// TODO(burdon): Create instance for each space.
|
|
36
|
+
export class ComputeGraph {
|
|
37
|
+
public readonly id = `graph-${PublicKey.random().truncate()}`;
|
|
38
|
+
public readonly update = new Event();
|
|
39
|
+
|
|
40
|
+
// The context is passed to all functions.
|
|
41
|
+
public readonly context = new FunctionContext(
|
|
42
|
+
this.hf,
|
|
43
|
+
this._space,
|
|
44
|
+
() => {
|
|
45
|
+
this.refresh();
|
|
46
|
+
},
|
|
47
|
+
this._options,
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
constructor(
|
|
51
|
+
public readonly hf: HyperFormula,
|
|
52
|
+
private readonly _space?: Space,
|
|
53
|
+
private readonly _options?: Partial<FunctionContextOptions>,
|
|
54
|
+
) {
|
|
55
|
+
this.hf.updateConfig({ context: this.context });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
refresh() {
|
|
59
|
+
log('refresh', { id: this.id });
|
|
60
|
+
this.update.emit();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -4,34 +4,31 @@
|
|
|
4
4
|
|
|
5
5
|
import '@dxos-theme';
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import { type Decorator } from '@storybook/react';
|
|
8
|
+
import React, { useContext, useEffect, useState } from 'react';
|
|
8
9
|
|
|
10
|
+
import { Client } from '@dxos/client';
|
|
11
|
+
import { type EchoReactiveObject } from '@dxos/echo-schema';
|
|
9
12
|
import { log } from '@dxos/log';
|
|
10
|
-
import {
|
|
11
|
-
import { withClientProvider } from '@dxos/react-client/testing';
|
|
13
|
+
import { getSpace, type Space } from '@dxos/react-client/echo';
|
|
12
14
|
import { Button } from '@dxos/react-ui';
|
|
13
15
|
import { mx } from '@dxos/react-ui-theme';
|
|
14
|
-
import {
|
|
16
|
+
import { withTheme, withLayout } from '@dxos/storybook-utils';
|
|
15
17
|
|
|
16
18
|
import { Sheet } from './Sheet';
|
|
17
19
|
import { type SizeMap } from './grid';
|
|
18
20
|
import { useSheetContext } from './sheet-context';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
import {
|
|
24
|
-
import { SheetType, ValueTypeEnum } from '../../types';
|
|
21
|
+
import { createTestSheet, testSheetName } from '../../testing';
|
|
22
|
+
import { ValueTypeEnum, SheetType } from '../../types';
|
|
23
|
+
import { type ComputeGraph, createComputeGraph } from '../ComputeGraph';
|
|
24
|
+
// TODO(wittjosiah): Refactor. This is not exported from ./components due to depending on ECHO.
|
|
25
|
+
import { ComputeGraphContext, ComputeGraphContextProvider, useComputeGraph } from '../ComputeGraph/graph-context';
|
|
25
26
|
import { Toolbar, type ToolbarActionHandler } from '../Toolbar';
|
|
26
27
|
|
|
27
28
|
// TODO(burdon): Allow toolbar to access sheet context; provide state for current cursor/range.
|
|
28
|
-
const SheetWithToolbar = ({
|
|
29
|
+
const SheetWithToolbar = ({ debug, space }: { debug?: boolean; space: Space }) => {
|
|
29
30
|
const { model, cursor, range } = useSheetContext();
|
|
30
31
|
|
|
31
|
-
const handleRefresh = () => {
|
|
32
|
-
// graph?.refresh(); // TODO(burdon): ???
|
|
33
|
-
};
|
|
34
|
-
|
|
35
32
|
// TODO(burdon): Factor out.
|
|
36
33
|
const handleAction: ToolbarActionHandler = ({ type }) => {
|
|
37
34
|
log.info('action', { type, cursor, range });
|
|
@@ -39,7 +36,7 @@ const SheetWithToolbar = ({ graph, debug }: { graph: ComputeGraph; debug?: boole
|
|
|
39
36
|
return;
|
|
40
37
|
}
|
|
41
38
|
|
|
42
|
-
const idx = range ? rangeToIndex(
|
|
39
|
+
const idx = range ? model.rangeToIndex(range) : model.addressToIndex(cursor);
|
|
43
40
|
model.sheet.formatting[idx] ??= {};
|
|
44
41
|
const format = model.sheet.formatting[idx];
|
|
45
42
|
|
|
@@ -78,12 +75,14 @@ const SheetWithToolbar = ({ graph, debug }: { graph: ComputeGraph; debug?: boole
|
|
|
78
75
|
format.precision = 2;
|
|
79
76
|
break;
|
|
80
77
|
}
|
|
81
|
-
case 'comment': {
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
78
|
}
|
|
85
79
|
};
|
|
86
80
|
|
|
81
|
+
const graph = useComputeGraph(space);
|
|
82
|
+
const handleRefresh = () => {
|
|
83
|
+
graph.refresh();
|
|
84
|
+
};
|
|
85
|
+
|
|
87
86
|
return (
|
|
88
87
|
<div className='flex flex-col overflow-hidden'>
|
|
89
88
|
<Toolbar.Root onAction={handleAction}>
|
|
@@ -100,43 +99,56 @@ const SheetWithToolbar = ({ graph, debug }: { graph: ComputeGraph; debug?: boole
|
|
|
100
99
|
);
|
|
101
100
|
};
|
|
102
101
|
|
|
102
|
+
const withGraphDecorator: Decorator = (Story) => {
|
|
103
|
+
const [graphs, setGraphs] = useState<Record<string, ComputeGraph>>({});
|
|
104
|
+
|
|
105
|
+
const setGraph = (key: string, graph: ComputeGraph) => {
|
|
106
|
+
if (!graph.hf.doesSheetExist(testSheetName)) {
|
|
107
|
+
const sheetName = graph.hf.addSheet(testSheetName);
|
|
108
|
+
const sheet = graph.hf.getSheetId(sheetName)!;
|
|
109
|
+
graph.hf.setCellContents({ sheet, col: 0, row: 0 }, Math.random());
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
setGraphs((graphs) => ({ ...graphs, [key]: graph }));
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
return (
|
|
116
|
+
<ComputeGraphContextProvider graphs={graphs} setGraph={setGraph}>
|
|
117
|
+
<Story />
|
|
118
|
+
</ComputeGraphContextProvider>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
|
|
103
122
|
export default {
|
|
104
123
|
title: 'plugin-sheet/Sheet',
|
|
105
124
|
component: Sheet,
|
|
106
|
-
decorators: [
|
|
107
|
-
withClientProvider({ types: [SheetType], createIdentity: true }),
|
|
108
|
-
withComputeGraphDecorator({ plugins: testPlugins }),
|
|
109
|
-
withTheme,
|
|
110
|
-
withLayout({ fullscreen: true, tooltips: true, classNames: 'inset-4' }),
|
|
111
|
-
],
|
|
125
|
+
decorators: [withTheme, withLayout({ fullscreen: true, tooltips: true, classNames: 'inset-4' }), withGraphDecorator],
|
|
112
126
|
};
|
|
113
127
|
|
|
114
128
|
export const Default = () => {
|
|
115
129
|
const [debug, setDebug] = useState(false);
|
|
116
|
-
const
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
if (!graph || !sheet) {
|
|
130
|
+
const sheet = useTestSheet();
|
|
131
|
+
const space = getSpace(sheet);
|
|
132
|
+
if (!sheet || !space) {
|
|
120
133
|
return null;
|
|
121
134
|
}
|
|
122
135
|
|
|
123
136
|
return (
|
|
124
|
-
<Sheet.Root
|
|
125
|
-
<SheetWithToolbar
|
|
137
|
+
<Sheet.Root sheet={sheet} space={space} onInfo={() => setDebug((debug) => !debug)}>
|
|
138
|
+
<SheetWithToolbar debug={debug} space={space} />
|
|
126
139
|
</Sheet.Root>
|
|
127
140
|
);
|
|
128
141
|
};
|
|
129
142
|
|
|
130
143
|
export const Debug = () => {
|
|
131
|
-
const
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
if (!graph || !sheet) {
|
|
144
|
+
const sheet = useTestSheet();
|
|
145
|
+
const space = getSpace(sheet);
|
|
146
|
+
if (!sheet || !space) {
|
|
135
147
|
return null;
|
|
136
148
|
}
|
|
137
149
|
|
|
138
150
|
return (
|
|
139
|
-
<Sheet.Root
|
|
151
|
+
<Sheet.Root sheet={sheet} space={space}>
|
|
140
152
|
<Sheet.Main />
|
|
141
153
|
<Sheet.Debug />
|
|
142
154
|
</Sheet.Root>
|
|
@@ -145,15 +157,14 @@ export const Debug = () => {
|
|
|
145
157
|
|
|
146
158
|
export const Rows = () => {
|
|
147
159
|
const [rowSizes, setRowSizes] = useState<SizeMap>({});
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
if (!graph || !sheet) {
|
|
160
|
+
const sheet = useTestSheet();
|
|
161
|
+
const space = getSpace(sheet);
|
|
162
|
+
if (!sheet || !space) {
|
|
152
163
|
return null;
|
|
153
164
|
}
|
|
154
165
|
|
|
155
166
|
return (
|
|
156
|
-
<Sheet.Root
|
|
167
|
+
<Sheet.Root sheet={sheet} space={space}>
|
|
157
168
|
<Sheet.Rows
|
|
158
169
|
rows={sheet.rows}
|
|
159
170
|
sizes={rowSizes}
|
|
@@ -165,15 +176,14 @@ export const Rows = () => {
|
|
|
165
176
|
|
|
166
177
|
export const Columns = () => {
|
|
167
178
|
const [columnSizes, setColumnSizes] = useState<SizeMap>({});
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
if (!graph || !sheet) {
|
|
179
|
+
const sheet = useTestSheet();
|
|
180
|
+
const space = getSpace(sheet);
|
|
181
|
+
if (!sheet || !space) {
|
|
172
182
|
return null;
|
|
173
183
|
}
|
|
174
184
|
|
|
175
185
|
return (
|
|
176
|
-
<Sheet.Root
|
|
186
|
+
<Sheet.Root sheet={sheet} space={space}>
|
|
177
187
|
<Sheet.Columns
|
|
178
188
|
columns={sheet.columns}
|
|
179
189
|
sizes={columnSizes}
|
|
@@ -184,19 +194,18 @@ export const Columns = () => {
|
|
|
184
194
|
};
|
|
185
195
|
|
|
186
196
|
export const Main = () => {
|
|
187
|
-
const
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
if (!graph || !sheet) {
|
|
197
|
+
const sheet = useTestSheet();
|
|
198
|
+
const space = getSpace(sheet);
|
|
199
|
+
if (!sheet || !space) {
|
|
191
200
|
return null;
|
|
192
201
|
}
|
|
193
202
|
|
|
194
203
|
return (
|
|
195
|
-
<Sheet.Root
|
|
204
|
+
<Sheet.Root sheet={sheet} space={space}>
|
|
196
205
|
<Sheet.Grid
|
|
197
206
|
size={{
|
|
198
207
|
numRows: 50,
|
|
199
|
-
|
|
208
|
+
numColumns: 26,
|
|
200
209
|
}}
|
|
201
210
|
rows={sheet.rows}
|
|
202
211
|
columns={sheet.columns}
|
|
@@ -249,3 +258,30 @@ export const GridLayout = () => {
|
|
|
249
258
|
const Cell = ({ className, label }: { className?: string; label: string }) => (
|
|
250
259
|
<div className={mx('flex items-center justify-center border', className)}>{label}</div>
|
|
251
260
|
);
|
|
261
|
+
|
|
262
|
+
const useTestSheet = () => {
|
|
263
|
+
const { graphs, setGraph } = useContext(ComputeGraphContext);
|
|
264
|
+
const [sheet, setSheet] = useState<EchoReactiveObject<SheetType>>();
|
|
265
|
+
useEffect(() => {
|
|
266
|
+
const t = setTimeout(async () => {
|
|
267
|
+
const client = new Client();
|
|
268
|
+
await client.initialize();
|
|
269
|
+
await client.halo.createIdentity();
|
|
270
|
+
const space = await client.spaces.create();
|
|
271
|
+
client.addTypes([SheetType]);
|
|
272
|
+
|
|
273
|
+
const graph = graphs[space.id] ?? createComputeGraph();
|
|
274
|
+
if (!graphs[space.id]) {
|
|
275
|
+
setGraph(space.id, graph);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const sheet = await createTestSheet({ graph });
|
|
279
|
+
space.db.add(sheet);
|
|
280
|
+
setSheet(sheet);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
return () => clearTimeout(t);
|
|
284
|
+
}, []);
|
|
285
|
+
|
|
286
|
+
return sheet;
|
|
287
|
+
};
|
|
@@ -60,7 +60,6 @@ import {
|
|
|
60
60
|
} from './grid';
|
|
61
61
|
import { type GridSize, handleArrowNav, handleNav, useRangeSelect } from './nav';
|
|
62
62
|
import { type SheetContextProps, SheetContextProvider, useSheetContext } from './sheet-context';
|
|
63
|
-
import { useThreads } from './threads';
|
|
64
63
|
import { getRectUnion, getRelativeClientRect, scrollIntoView } from './util';
|
|
65
64
|
import {
|
|
66
65
|
type CellIndex,
|
|
@@ -69,9 +68,7 @@ import {
|
|
|
69
68
|
columnLetter,
|
|
70
69
|
posEquals,
|
|
71
70
|
rangeToA1Notation,
|
|
72
|
-
|
|
73
|
-
addressFromIndex,
|
|
74
|
-
} from '../../defs';
|
|
71
|
+
} from '../../model';
|
|
75
72
|
import {
|
|
76
73
|
CellEditor,
|
|
77
74
|
type CellRangeNotifier,
|
|
@@ -138,16 +135,12 @@ const SheetRoot = ({ children, ...props }: PropsWithChildren<SheetContextProps>)
|
|
|
138
135
|
|
|
139
136
|
type SheetMainProps = ThemedClassName<Partial<GridSize>>;
|
|
140
137
|
|
|
141
|
-
const SheetMain = forwardRef<HTMLDivElement, SheetMainProps>(({ classNames, numRows,
|
|
138
|
+
const SheetMain = forwardRef<HTMLDivElement, SheetMainProps>(({ classNames, numRows, numColumns }, forwardRef) => {
|
|
142
139
|
const { model, cursor, setCursor, setRange, setEditing } = useSheetContext();
|
|
143
140
|
|
|
144
141
|
// Scrolling.
|
|
145
142
|
const { rowsRef, columnsRef, contentRef } = useScrollHandlers();
|
|
146
143
|
|
|
147
|
-
// Threads.
|
|
148
|
-
// TODO(Zan): Move this to an extension once we have an extension model.
|
|
149
|
-
useThreads();
|
|
150
|
-
|
|
151
144
|
//
|
|
152
145
|
// Order of Row/columns.
|
|
153
146
|
//
|
|
@@ -177,21 +170,21 @@ const SheetMain = forwardRef<HTMLDivElement, SheetMainProps>(({ classNames, numR
|
|
|
177
170
|
}, [rows, columns]);
|
|
178
171
|
|
|
179
172
|
const handleMoveRows: SheetRowsProps['onMove'] = (from, to, num = 1) => {
|
|
180
|
-
const cursorIdx = cursor ? addressToIndex(
|
|
173
|
+
const cursorIdx = cursor ? model.addressToIndex(cursor) : undefined;
|
|
181
174
|
const [rows] = model.sheet.rows.splice(from, num);
|
|
182
175
|
model.sheet.rows.splice(to, 0, rows);
|
|
183
176
|
if (cursorIdx) {
|
|
184
|
-
setCursor(addressFromIndex(
|
|
177
|
+
setCursor(model.addressFromIndex(cursorIdx));
|
|
185
178
|
}
|
|
186
179
|
setRows([...model.sheet.rows]);
|
|
187
180
|
};
|
|
188
181
|
|
|
189
182
|
const handleMoveColumns: SheetColumnsProps['onMove'] = (from, to, num = 1) => {
|
|
190
|
-
const cursorIdx = cursor ? addressToIndex(
|
|
183
|
+
const cursorIdx = cursor ? model.addressToIndex(cursor) : undefined;
|
|
191
184
|
const columns = model.sheet.columns.splice(from, num);
|
|
192
185
|
model.sheet.columns.splice(to, 0, ...columns);
|
|
193
186
|
if (cursorIdx) {
|
|
194
|
-
setCursor(addressFromIndex(
|
|
187
|
+
setCursor(model.addressFromIndex(cursorIdx));
|
|
195
188
|
}
|
|
196
189
|
setColumns([...model.sheet.columns]);
|
|
197
190
|
};
|
|
@@ -263,8 +256,8 @@ const SheetMain = forwardRef<HTMLDivElement, SheetMainProps>(({ classNames, numR
|
|
|
263
256
|
ref={columnsRef}
|
|
264
257
|
columns={columns}
|
|
265
258
|
sizes={columnSizes}
|
|
266
|
-
selected={cursor?.
|
|
267
|
-
onSelect={(
|
|
259
|
+
selected={cursor?.column}
|
|
260
|
+
onSelect={(column) => setCursor(cursor?.column === column ? undefined : { row: -1, column })}
|
|
268
261
|
onResize={handleResizeColumn}
|
|
269
262
|
onMove={handleMoveColumns}
|
|
270
263
|
/>
|
|
@@ -274,13 +267,13 @@ const SheetMain = forwardRef<HTMLDivElement, SheetMainProps>(({ classNames, numR
|
|
|
274
267
|
rows={rows}
|
|
275
268
|
sizes={rowSizes}
|
|
276
269
|
selected={cursor?.row}
|
|
277
|
-
onSelect={(row) => setCursor(cursor?.row === row ? undefined : { row,
|
|
270
|
+
onSelect={(row) => setCursor(cursor?.row === row ? undefined : { row, column: -1 })}
|
|
278
271
|
onResize={handleResizeRow}
|
|
279
272
|
onMove={handleMoveRows}
|
|
280
273
|
/>
|
|
281
274
|
<SheetGrid
|
|
282
275
|
ref={contentRef}
|
|
283
|
-
size={{ numRows: numRows ?? rows.length,
|
|
276
|
+
size={{ numRows: numRows ?? rows.length, numColumns: numColumns ?? columns.length }}
|
|
284
277
|
rows={rows}
|
|
285
278
|
columns={columns}
|
|
286
279
|
rowSizes={rowSizes}
|
|
@@ -885,11 +878,11 @@ const SheetGrid = forwardRef<HTMLDivElement, SheetGridProps>(
|
|
|
885
878
|
|
|
886
879
|
{/* Grid cells. */}
|
|
887
880
|
{rowRange.map(({ row, top, height }) => {
|
|
888
|
-
return columnRange.map(({
|
|
881
|
+
return columnRange.map(({ column, left, width }) => {
|
|
889
882
|
const style: CSSProperties = { position: 'absolute', top, left, width, height };
|
|
890
|
-
const cell
|
|
883
|
+
const cell = { row, column };
|
|
891
884
|
const id = addressToA1Notation(cell);
|
|
892
|
-
const idx = addressToIndex(
|
|
885
|
+
const idx = model.addressToIndex(cell);
|
|
893
886
|
const active = posEquals(cursor, cell);
|
|
894
887
|
if (active && editing) {
|
|
895
888
|
const value = initialText.current ?? model.getCellText(cell) ?? '';
|
|
@@ -1010,46 +1003,16 @@ type SheetCellProps = {
|
|
|
1010
1003
|
};
|
|
1011
1004
|
|
|
1012
1005
|
const SheetCell = ({ id, cell, style, active, onSelect }: SheetCellProps) => {
|
|
1013
|
-
const {
|
|
1014
|
-
formatting,
|
|
1015
|
-
editing,
|
|
1016
|
-
setRange,
|
|
1017
|
-
decorations,
|
|
1018
|
-
model: { sheet },
|
|
1019
|
-
} = useSheetContext();
|
|
1006
|
+
const { formatting, editing, setRange } = useSheetContext();
|
|
1020
1007
|
const { value, classNames } = formatting.getFormatting(cell);
|
|
1021
1008
|
|
|
1022
|
-
const decorationsForCell = decorations.getDecorationsForCell(addressToIndex(sheet, cell)) ?? [];
|
|
1023
|
-
const decorationAddedClasses = useMemo(
|
|
1024
|
-
() => decorationsForCell.flatMap((d) => d.classNames ?? []),
|
|
1025
|
-
[decorationsForCell],
|
|
1026
|
-
);
|
|
1027
|
-
const decoratedContent = decorationsForCell.reduce(
|
|
1028
|
-
(children, { decorate }) => {
|
|
1029
|
-
if (!decorate) {
|
|
1030
|
-
return children;
|
|
1031
|
-
}
|
|
1032
|
-
const DecoratorComponent = decorate;
|
|
1033
|
-
return <DecoratorComponent>{children}</DecoratorComponent>;
|
|
1034
|
-
},
|
|
1035
|
-
<div
|
|
1036
|
-
role='none'
|
|
1037
|
-
className={mx(
|
|
1038
|
-
'flex flex-grow bs-full is-full px-2 items-center truncate cursor-pointer',
|
|
1039
|
-
...decorationAddedClasses,
|
|
1040
|
-
)}
|
|
1041
|
-
>
|
|
1042
|
-
{value}
|
|
1043
|
-
</div>,
|
|
1044
|
-
);
|
|
1045
|
-
|
|
1046
1009
|
return (
|
|
1047
1010
|
<div
|
|
1048
1011
|
{...{ [`data-${CELL_DATA_KEY}`]: id }}
|
|
1049
1012
|
role='cell'
|
|
1050
1013
|
style={style}
|
|
1051
1014
|
className={mx(
|
|
1052
|
-
'border border-gridLine cursor-pointer',
|
|
1015
|
+
'flex w-full h-full px-2 py-1 truncate items-center border border-gridLine cursor-pointer',
|
|
1053
1016
|
fragments.cell,
|
|
1054
1017
|
active && ['z-20', fragments.cellSelected],
|
|
1055
1018
|
classNames,
|
|
@@ -1063,7 +1026,7 @@ const SheetCell = ({ id, cell, style, active, onSelect }: SheetCellProps) => {
|
|
|
1063
1026
|
}}
|
|
1064
1027
|
onDoubleClick={() => onSelect?.(cell, true)}
|
|
1065
1028
|
>
|
|
1066
|
-
{
|
|
1029
|
+
{value}
|
|
1067
1030
|
</div>
|
|
1068
1031
|
);
|
|
1069
1032
|
};
|
|
@@ -1082,11 +1045,10 @@ const GridCellEditor = ({ style, value, onNav, onClose }: GridCellEditorProps) =
|
|
|
1082
1045
|
notifier.current?.(rangeToA1Notation(range));
|
|
1083
1046
|
}
|
|
1084
1047
|
}, [range]);
|
|
1085
|
-
|
|
1086
1048
|
const extension = useMemo(
|
|
1087
1049
|
() => [
|
|
1088
1050
|
editorKeys({ onNav, onClose }),
|
|
1089
|
-
sheetExtension({ functions: model.
|
|
1051
|
+
sheetExtension({ functions: model.functions }),
|
|
1090
1052
|
rangeExtension((fn) => (notifier.current = fn)),
|
|
1091
1053
|
],
|
|
1092
1054
|
[model],
|
|
@@ -1110,13 +1072,12 @@ const GridCellEditor = ({ style, value, onNav, onClose }: GridCellEditorProps) =
|
|
|
1110
1072
|
|
|
1111
1073
|
const SheetStatusBar = () => {
|
|
1112
1074
|
const { model, cursor, range } = useSheetContext();
|
|
1113
|
-
|
|
1114
1075
|
let value;
|
|
1115
1076
|
let isFormula = false;
|
|
1116
1077
|
if (cursor) {
|
|
1117
1078
|
value = model.getCellValue(cursor);
|
|
1118
1079
|
if (typeof value === 'string' && value.charAt(0) === '=') {
|
|
1119
|
-
value = model.
|
|
1080
|
+
value = model.mapFormulaBindingFromId(model.mapFormulaIndicesToRefs(value));
|
|
1120
1081
|
isFormula = true;
|
|
1121
1082
|
} else if (value != null) {
|
|
1122
1083
|
value = String(value);
|
|
@@ -4,24 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
import { type ClassNameValue } from '@dxos/react-ui-types';
|
|
6
6
|
|
|
7
|
-
import { type SheetModel } from '
|
|
8
|
-
import {
|
|
9
|
-
import { addressToIndex, rangeFromIndex } from '../defs';
|
|
10
|
-
import { ValueTypeEnum } from '../types';
|
|
11
|
-
|
|
12
|
-
export type CellFormat = {
|
|
13
|
-
value?: string;
|
|
14
|
-
classNames?: ClassNameValue;
|
|
15
|
-
};
|
|
7
|
+
import { type SheetModel, type CellAddress, inRange } from '../../model';
|
|
8
|
+
import { ValueTypeEnum } from '../../types';
|
|
16
9
|
|
|
17
10
|
export class FormattingModel {
|
|
18
|
-
constructor(private readonly
|
|
11
|
+
constructor(private readonly model: SheetModel) {}
|
|
19
12
|
|
|
20
13
|
/**
|
|
21
14
|
* Get formatted string value and className for cell.
|
|
22
15
|
*/
|
|
23
|
-
getFormatting(cell: CellAddress):
|
|
24
|
-
const value = this.
|
|
16
|
+
getFormatting(cell: CellAddress): { value?: string; classNames?: ClassNameValue } {
|
|
17
|
+
const value = this.model.getValue(cell);
|
|
25
18
|
if (value === undefined || value === null) {
|
|
26
19
|
return {};
|
|
27
20
|
}
|
|
@@ -30,15 +23,15 @@ export class FormattingModel {
|
|
|
30
23
|
const locales = undefined;
|
|
31
24
|
|
|
32
25
|
// Cell-specific formatting.
|
|
33
|
-
const idx =
|
|
34
|
-
let formatting = this.
|
|
26
|
+
const idx = this.model.addressToIndex(cell);
|
|
27
|
+
let formatting = this.model.sheet.formatting?.[idx] ?? {};
|
|
35
28
|
const classNames = [...(formatting?.classNames ?? [])];
|
|
36
29
|
|
|
37
30
|
// Range formatting.
|
|
38
31
|
// TODO(burdon): NOTE: D0 means the D column.
|
|
39
32
|
// TODO(burdon): Cache model formatting (e.g., for ranges). Create class out of this function.
|
|
40
|
-
for (const [idx, _formatting] of Object.entries(this.
|
|
41
|
-
const range =
|
|
33
|
+
for (const [idx, _formatting] of Object.entries(this.model.sheet.formatting)) {
|
|
34
|
+
const range = this.model.rangeFromIndex(idx);
|
|
42
35
|
if (inRange(range, cell)) {
|
|
43
36
|
if (_formatting.classNames) {
|
|
44
37
|
classNames.push(..._formatting.classNames);
|
|
@@ -53,7 +46,7 @@ export class FormattingModel {
|
|
|
53
46
|
|
|
54
47
|
const defaultNumber = 'justify-end font-mono';
|
|
55
48
|
|
|
56
|
-
const type = formatting?.type ?? this.
|
|
49
|
+
const type = formatting?.type ?? this.model.getValueType(cell);
|
|
57
50
|
switch (type) {
|
|
58
51
|
case ValueTypeEnum.Boolean: {
|
|
59
52
|
return {
|
|
@@ -91,17 +84,17 @@ export class FormattingModel {
|
|
|
91
84
|
//
|
|
92
85
|
|
|
93
86
|
case ValueTypeEnum.DateTime: {
|
|
94
|
-
const date = this.
|
|
87
|
+
const date = this.model.toLocalDate(value as number);
|
|
95
88
|
return { value: date.toLocaleString(locales), classNames };
|
|
96
89
|
}
|
|
97
90
|
|
|
98
91
|
case ValueTypeEnum.Date: {
|
|
99
|
-
const date = this.
|
|
92
|
+
const date = this.model.toLocalDate(value as number);
|
|
100
93
|
return { value: date.toLocaleDateString(locales), classNames };
|
|
101
94
|
}
|
|
102
95
|
|
|
103
96
|
case ValueTypeEnum.Time: {
|
|
104
|
-
const date = this.
|
|
97
|
+
const date = this.model.toLocalDate(value as number);
|
|
105
98
|
return { value: date.toLocaleTimeString(locales), classNames };
|
|
106
99
|
}
|
|
107
100
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { type MouseEvent, useEffect, useState } from 'react';
|
|
6
6
|
|
|
7
|
-
import { type CellAddress, type CellIndex, addressFromA1Notation, addressToA1Notation } from '../../
|
|
7
|
+
import { type CellAddress, type CellIndex, addressFromA1Notation, addressToA1Notation } from '../../model';
|
|
8
8
|
|
|
9
9
|
// export type Bounds = Pick<DOMRect, 'left' | 'top' | 'width' | 'height'>;
|
|
10
10
|
// export type Dimension = Pick<DOMRect, 'width' | 'height'>;
|
|
@@ -12,7 +12,7 @@ import { type CellAddress, type CellIndex, addressFromA1Notation, addressToA1Not
|
|
|
12
12
|
export type SizeMap = Record<string, number>;
|
|
13
13
|
|
|
14
14
|
export type RowPosition = { row: number } & Pick<DOMRect, 'top' | 'height'>;
|
|
15
|
-
export type ColumnPosition = {
|
|
15
|
+
export type ColumnPosition = { column: number } & Pick<DOMRect, 'left' | 'width'>;
|
|
16
16
|
|
|
17
17
|
export const axisWidth = 'calc(var(--rail-size)-2px)';
|
|
18
18
|
export const axisHeight = 34;
|
|
@@ -88,7 +88,7 @@ export const useGridLayout = ({
|
|
|
88
88
|
const width = columnSizes?.[idx] ?? defaultWidth;
|
|
89
89
|
const left = x;
|
|
90
90
|
x += width - 1;
|
|
91
|
-
return {
|
|
91
|
+
return { column: i, left, width };
|
|
92
92
|
}),
|
|
93
93
|
);
|
|
94
94
|
}, [columns, columnSizes]);
|