@dxos/plugin-sheet 0.8.4-main.28f8d3d → 0.8.4-main.2c6827d
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-JZNFXBW3.mjs → SheetContainer-67YEU5EA.mjs} +41 -43
- package/dist/lib/browser/SheetContainer-67YEU5EA.mjs.map +7 -0
- package/dist/lib/browser/anchor-sort-FCQ5OZZK.mjs +23 -0
- package/dist/lib/browser/anchor-sort-FCQ5OZZK.mjs.map +7 -0
- package/dist/lib/browser/{chunk-BVTHIA5U.mjs → chunk-6WBJDEKF.mjs} +37 -32
- package/dist/lib/browser/chunk-6WBJDEKF.mjs.map +7 -0
- package/dist/lib/browser/{chunk-KJWZUQVA.mjs → chunk-73AV3NH6.mjs} +4 -4
- package/dist/lib/browser/chunk-73AV3NH6.mjs.map +7 -0
- package/dist/lib/browser/{chunk-VTTKAHAY.mjs → chunk-7VEWYJJN.mjs} +2 -2
- package/dist/lib/browser/chunk-7VEWYJJN.mjs.map +7 -0
- package/dist/lib/browser/{chunk-ELAASQ5H.mjs → chunk-DVJ3QW3F.mjs} +215 -207
- package/dist/lib/browser/chunk-DVJ3QW3F.mjs.map +7 -0
- package/dist/lib/browser/chunk-FWFAAGXL.mjs +28 -0
- package/dist/lib/browser/chunk-FWFAAGXL.mjs.map +7 -0
- package/dist/lib/browser/compute-graph-registry-AP5RA7W3.mjs +21 -0
- package/dist/lib/browser/compute-graph-registry-AP5RA7W3.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +20 -21
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/{intent-resolver-SSLPTP5O.mjs → intent-resolver-66OAYVQF.mjs} +9 -9
- package/dist/lib/browser/intent-resolver-66OAYVQF.mjs.map +7 -0
- package/dist/lib/browser/{markdown-3VPZYNGU.mjs → markdown-B6VKYY2S.mjs} +6 -6
- package/dist/lib/browser/{markdown-3VPZYNGU.mjs.map → markdown-B6VKYY2S.mjs.map} +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/{react-surface-Y7KTPJW2.mjs → react-surface-HARAYCN7.mjs} +16 -15
- package/dist/lib/browser/react-surface-HARAYCN7.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +4 -12
- package/dist/lib/node-esm/{SheetContainer-GOIBAE2P.mjs → SheetContainer-NJONAMYZ.mjs} +41 -43
- package/dist/lib/node-esm/SheetContainer-NJONAMYZ.mjs.map +7 -0
- package/dist/lib/node-esm/{anchor-sort-YM2UBIKL.mjs → anchor-sort-ZE7IS7SH.mjs} +10 -11
- package/dist/lib/node-esm/anchor-sort-ZE7IS7SH.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-6SK5LJ5S.mjs → chunk-44YTKTMP.mjs} +4 -4
- package/dist/lib/node-esm/chunk-44YTKTMP.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-4L5CIB7E.mjs → chunk-4H2EHVWE.mjs} +215 -207
- package/dist/lib/node-esm/chunk-4H2EHVWE.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-FXRXBHWM.mjs → chunk-4QV4AGWK.mjs} +2 -2
- package/dist/lib/node-esm/chunk-4QV4AGWK.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HILDMVPL.mjs +29 -0
- package/dist/lib/node-esm/chunk-HILDMVPL.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-56HYMW55.mjs → chunk-S3RJ7IY6.mjs} +37 -32
- package/dist/lib/node-esm/chunk-S3RJ7IY6.mjs.map +7 -0
- package/dist/lib/node-esm/compute-graph-registry-UMQ5UYCL.mjs +22 -0
- package/dist/lib/node-esm/compute-graph-registry-UMQ5UYCL.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +20 -21
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/{intent-resolver-5P6DBGK2.mjs → intent-resolver-VNKIMQQT.mjs} +9 -9
- package/dist/lib/node-esm/intent-resolver-VNKIMQQT.mjs.map +7 -0
- package/dist/lib/node-esm/{markdown-SFDGQWYE.mjs → markdown-VKY7HXU2.mjs} +6 -6
- package/dist/lib/node-esm/{markdown-SFDGQWYE.mjs.map → markdown-VKY7HXU2.mjs.map} +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/{react-surface-6Z5FAOBH.mjs → react-surface-KTQWXV2L.mjs} +16 -15
- package/dist/lib/node-esm/react-surface-KTQWXV2L.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +4 -12
- package/dist/types/src/SheetPlugin.d.ts +1 -1
- package/dist/types/src/SheetPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/anchor-sort.d.ts +2 -4
- package/dist/types/src/capabilities/anchor-sort.d.ts.map +1 -1
- package/dist/types/src/capabilities/compute-graph-registry.d.ts +1 -1
- package/dist/types/src/capabilities/compute-graph-registry.d.ts.map +1 -1
- package/dist/types/src/capabilities/index.d.ts +5 -10
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +1 -1
- package/dist/types/src/capabilities/markdown.d.ts +1 -3
- package/dist/types/src/capabilities/markdown.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts +1 -1
- package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
- package/dist/types/src/components/ComputeGraph/compute-graph.stories.d.ts +9 -4
- package/dist/types/src/components/ComputeGraph/compute-graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +50 -3
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts +11 -20
- package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/util.d.ts.map +1 -1
- package/dist/types/src/components/RangeList/RangeList.d.ts +2 -2
- package/dist/types/src/components/RangeList/RangeList.d.ts.map +1 -1
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +2 -2
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -1
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +52 -5
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -1
- package/dist/types/src/components/SheetContext/SheetContext.d.ts +2 -2
- package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -1
- package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts +3 -4
- package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts.map +1 -1
- package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts +86 -4
- package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/compute.d.ts +1 -1
- package/dist/types/src/extensions/compute.d.ts.map +1 -1
- package/dist/types/src/extensions/compute.stories.d.ts +10 -13
- package/dist/types/src/extensions/compute.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/editor/index.d.ts +1 -1
- package/dist/types/src/extensions/editor/index.d.ts.map +1 -1
- package/dist/types/src/extensions/editor/{extension.d.ts → sheet-extension.d.ts} +1 -1
- package/dist/types/src/extensions/editor/sheet-extension.d.ts.map +1 -0
- package/dist/types/src/extensions/editor/sheet-extension.test.d.ts +2 -0
- package/dist/types/src/extensions/editor/sheet-extension.test.d.ts.map +1 -0
- package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +0 -1
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/model/sheet-model.d.ts +5 -5
- package/dist/types/src/model/sheet-model.d.ts.map +1 -1
- package/dist/types/src/model/testing.d.ts +2 -2
- package/dist/types/src/model/testing.d.ts.map +1 -1
- package/dist/types/src/model/useSheetModel.d.ts +2 -2
- package/dist/types/src/model/useSheetModel.d.ts.map +1 -1
- package/dist/types/src/serializer.d.ts +2 -2
- package/dist/types/src/serializer.d.ts.map +1 -1
- package/dist/types/src/testing/data.d.ts +2 -2
- package/dist/types/src/testing/data.d.ts.map +1 -1
- package/dist/types/src/testing/testing.d.ts +27 -3
- package/dist/types/src/testing/testing.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/{schema.d.ts → Sheet.d.ts} +37 -4
- package/dist/types/src/types/Sheet.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/sheet-range-types.d.ts +2 -2
- package/dist/types/src/types/sheet-range-types.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +7 -16
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/src/types/util.d.ts +9 -10
- package/dist/types/src/types/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +65 -64
- package/src/SheetPlugin.tsx +70 -61
- package/src/capabilities/anchor-sort.ts +7 -8
- package/src/capabilities/capabilities.ts +2 -2
- package/src/capabilities/compute-graph-registry.ts +8 -13
- package/src/capabilities/intent-resolver.ts +4 -4
- package/src/capabilities/react-surface.tsx +9 -8
- package/src/components/ComputeGraph/compute-graph.stories.tsx +18 -18
- package/src/components/FunctionEditor/FunctionEditor.tsx +2 -2
- package/src/components/GridSheet/GridSheet.stories.tsx +17 -12
- package/src/components/GridSheet/GridSheet.tsx +24 -12
- package/src/components/GridSheet/SheetCellEditor.stories.tsx +40 -42
- package/src/components/GridSheet/util.ts +9 -3
- package/src/components/RangeList/RangeList.tsx +8 -8
- package/src/components/SheetContainer/SheetContainer.stories.tsx +45 -42
- package/src/components/SheetContainer/SheetContainer.tsx +10 -5
- package/src/components/SheetContext/SheetContext.tsx +4 -4
- package/src/components/SheetToolbar/SheetToolbar.stories.tsx +17 -12
- package/src/components/SheetToolbar/SheetToolbar.tsx +27 -29
- package/src/components/SheetToolbar/align.ts +3 -3
- package/src/components/SheetToolbar/style.ts +2 -2
- package/src/extensions/compute.stories.tsx +29 -26
- package/src/extensions/compute.ts +1 -2
- package/src/extensions/editor/index.ts +1 -1
- package/src/extensions/editor/{extension.test.ts → sheet-extension.test.ts} +1 -1
- package/src/integrations/thread-ranges.ts +15 -20
- package/src/meta.ts +7 -5
- package/src/model/sheet-model.test.ts +4 -4
- package/src/model/sheet-model.ts +4 -4
- package/src/model/testing.ts +4 -4
- package/src/model/useSheetModel.ts +2 -2
- package/src/sanity.test.ts +3 -4
- package/src/serializer.ts +3 -3
- package/src/testing/data.ts +2 -2
- package/src/testing/testing.tsx +11 -5
- package/src/translations.ts +2 -2
- package/src/types/Sheet.ts +103 -0
- package/src/types/index.ts +1 -1
- package/src/types/sheet-range-types.ts +2 -2
- package/src/types/types.ts +6 -16
- package/src/types/util.ts +10 -38
- package/dist/lib/browser/SheetContainer-JZNFXBW3.mjs.map +0 -7
- package/dist/lib/browser/anchor-sort-VRX3YZKT.mjs +0 -24
- package/dist/lib/browser/anchor-sort-VRX3YZKT.mjs.map +0 -7
- package/dist/lib/browser/chunk-6AKBCBL4.mjs +0 -18
- package/dist/lib/browser/chunk-6AKBCBL4.mjs.map +0 -7
- package/dist/lib/browser/chunk-BVTHIA5U.mjs.map +0 -7
- package/dist/lib/browser/chunk-ELAASQ5H.mjs.map +0 -7
- package/dist/lib/browser/chunk-KJWZUQVA.mjs.map +0 -7
- package/dist/lib/browser/chunk-VTTKAHAY.mjs.map +0 -7
- package/dist/lib/browser/compute-graph-registry-6YJHXORG.mjs +0 -30
- package/dist/lib/browser/compute-graph-registry-6YJHXORG.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-SSLPTP5O.mjs.map +0 -7
- package/dist/lib/browser/react-surface-Y7KTPJW2.mjs.map +0 -7
- package/dist/lib/node-esm/SheetContainer-GOIBAE2P.mjs.map +0 -7
- package/dist/lib/node-esm/anchor-sort-YM2UBIKL.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-3K5VNYOF.mjs +0 -20
- package/dist/lib/node-esm/chunk-3K5VNYOF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-4L5CIB7E.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-56HYMW55.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-6SK5LJ5S.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-FXRXBHWM.mjs.map +0 -7
- package/dist/lib/node-esm/compute-graph-registry-ET5KJNLV.mjs +0 -31
- package/dist/lib/node-esm/compute-graph-registry-ET5KJNLV.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-5P6DBGK2.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-6Z5FAOBH.mjs.map +0 -7
- package/dist/types/src/extensions/editor/extension.d.ts.map +0 -1
- package/dist/types/src/extensions/editor/extension.test.d.ts +0 -2
- package/dist/types/src/extensions/editor/extension.test.d.ts.map +0 -1
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/src/types/schema.ts +0 -61
- /package/src/extensions/editor/{extension.ts → sheet-extension.ts} +0 -0
|
@@ -7,7 +7,7 @@ import { useEffect } from 'react';
|
|
|
7
7
|
import { type CompleteCellRange, inRange } from '@dxos/compute';
|
|
8
8
|
import { type ToolbarMenuActionGroupProperties, createMenuAction, createMenuItemGroup } from '@dxos/react-ui-menu';
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { meta } from '../../meta';
|
|
11
11
|
import { type SheetModel } from '../../model';
|
|
12
12
|
import { type AlignKey, type AlignValue, alignKey, rangeFromIndex, rangeToIndex } from '../../types';
|
|
13
13
|
import { useSheetContext } from '../SheetContext';
|
|
@@ -40,7 +40,7 @@ export const useAlignState = (state: Partial<AlignState>) => {
|
|
|
40
40
|
|
|
41
41
|
const createAlignGroupAction = (value?: AlignValue) =>
|
|
42
42
|
createMenuItemGroup('align', {
|
|
43
|
-
label: ['align label', { ns:
|
|
43
|
+
label: ['align label', { ns: meta.id }],
|
|
44
44
|
variant: 'toggleGroup',
|
|
45
45
|
selectCardinality: 'single',
|
|
46
46
|
value: `${alignKey}--${value}`,
|
|
@@ -79,7 +79,7 @@ const createAlignActions = (model: SheetModel, state: ToolbarState, cursorFallba
|
|
|
79
79
|
key: alignKey,
|
|
80
80
|
value: alignValue as AlignValue,
|
|
81
81
|
checked: state[alignKey] === alignValue,
|
|
82
|
-
label: [`range value ${alignValue} label`, { ns:
|
|
82
|
+
label: [`range value ${alignValue} label`, { ns: meta.id }],
|
|
83
83
|
icon,
|
|
84
84
|
testId: `grid.toolbar.${alignKey}.${alignValue}`,
|
|
85
85
|
},
|
|
@@ -7,7 +7,7 @@ import { useEffect } from 'react';
|
|
|
7
7
|
import { type CompleteCellRange, inRange } from '@dxos/compute';
|
|
8
8
|
import { type ToolbarMenuActionGroupProperties, createMenuAction, createMenuItemGroup } from '@dxos/react-ui-menu';
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { meta } from '../../meta';
|
|
11
11
|
import { type SheetModel } from '../../model';
|
|
12
12
|
import { type StyleKey, type StyleValue, rangeFromIndex, rangeToIndex } from '../../types';
|
|
13
13
|
import { useSheetContext } from '../SheetContext';
|
|
@@ -89,7 +89,7 @@ const createStyleActions = (model: SheetModel, state: StyleState, cursorFallback
|
|
|
89
89
|
key: 'style',
|
|
90
90
|
value: styleValue as StyleValue,
|
|
91
91
|
icon,
|
|
92
|
-
label: [`range value ${styleValue} label`, { ns:
|
|
92
|
+
label: [`range value ${styleValue} label`, { ns: meta.id }],
|
|
93
93
|
checked: !!state[styleValue as StyleValue],
|
|
94
94
|
},
|
|
95
95
|
);
|
|
@@ -2,15 +2,16 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
6
|
-
|
|
7
|
-
import { type Meta } from '@storybook/react-vite';
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
8
6
|
import React, { useEffect, useMemo } from 'react';
|
|
9
7
|
|
|
8
|
+
import { IntentPlugin } from '@dxos/app-framework';
|
|
9
|
+
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
10
10
|
import { PublicKey } from '@dxos/keys';
|
|
11
11
|
import { useSpace } from '@dxos/react-client/echo';
|
|
12
12
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
13
13
|
import { useThemeContext } from '@dxos/react-ui';
|
|
14
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
14
15
|
import {
|
|
15
16
|
createBasicExtensions,
|
|
16
17
|
createMarkdownExtensions,
|
|
@@ -19,13 +20,12 @@ import {
|
|
|
19
20
|
documentId,
|
|
20
21
|
useTextEditor,
|
|
21
22
|
} from '@dxos/react-ui-editor';
|
|
22
|
-
import { withLayout, withTheme } from '@dxos/storybook-utils';
|
|
23
23
|
import { isNonNullable } from '@dxos/util';
|
|
24
24
|
|
|
25
25
|
import { GridSheet, SheetProvider, useComputeGraph } from '../components';
|
|
26
26
|
import { useSheetModel } from '../model';
|
|
27
27
|
import { useTestSheet, withComputeGraphDecorator } from '../testing';
|
|
28
|
-
import {
|
|
28
|
+
import { Sheet } from '../types';
|
|
29
29
|
|
|
30
30
|
import { compute, computeGraphFacet } from './compute';
|
|
31
31
|
|
|
@@ -42,7 +42,7 @@ type EditorProps = {
|
|
|
42
42
|
|
|
43
43
|
const SHEET_NAME = 'Test Sheet';
|
|
44
44
|
|
|
45
|
-
const
|
|
45
|
+
const DefaultStory = ({ text }: EditorProps) => {
|
|
46
46
|
const id = useMemo(() => PublicKey.random(), []);
|
|
47
47
|
const { themeMode } = useThemeContext();
|
|
48
48
|
const space = useSpace();
|
|
@@ -52,7 +52,7 @@ const EditorStory = ({ text }: EditorProps) => {
|
|
|
52
52
|
initialValue: text,
|
|
53
53
|
extensions: [
|
|
54
54
|
createBasicExtensions(),
|
|
55
|
-
createMarkdownExtensions(
|
|
55
|
+
createMarkdownExtensions(),
|
|
56
56
|
createThemeExtensions({ themeMode, syntaxHighlighting: true }),
|
|
57
57
|
documentId.of(id.toHex()),
|
|
58
58
|
computeGraph && computeGraphFacet.of(computeGraph),
|
|
@@ -63,7 +63,7 @@ const EditorStory = ({ text }: EditorProps) => {
|
|
|
63
63
|
[computeGraph, themeMode],
|
|
64
64
|
);
|
|
65
65
|
|
|
66
|
-
return <div className='
|
|
66
|
+
return <div className='is-[40rem] overflow-hidden' ref={parentRef} {...focusAttributes} />;
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
const Grid = () => {
|
|
@@ -82,7 +82,7 @@ const Grid = () => {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
return (
|
|
85
|
-
<div className='flex
|
|
85
|
+
<div className='flex is-[40rem] overflow-hidden'>
|
|
86
86
|
<SheetProvider graph={graph} sheet={sheet}>
|
|
87
87
|
<GridSheet />
|
|
88
88
|
</SheetProvider>
|
|
@@ -93,15 +93,31 @@ const Grid = () => {
|
|
|
93
93
|
const GraphStory = (props: EditorProps) => {
|
|
94
94
|
return (
|
|
95
95
|
<div className='grid grid-rows-2'>
|
|
96
|
-
<
|
|
96
|
+
<DefaultStory {...props} />
|
|
97
97
|
<Grid />
|
|
98
98
|
</div>
|
|
99
99
|
);
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
+
const meta = {
|
|
103
|
+
title: 'plugins/plugin-sheet/extensions',
|
|
104
|
+
decorators: [
|
|
105
|
+
withTheme,
|
|
106
|
+
withClientProvider({ types: [Sheet.Sheet], createIdentity: true, createSpace: true }),
|
|
107
|
+
// TODO(wittjosiah): Try to write story which does not depend on plugin manager.
|
|
108
|
+
withPluginManager({ plugins: [IntentPlugin()] }),
|
|
109
|
+
withComputeGraphDecorator(),
|
|
110
|
+
],
|
|
111
|
+
parameters: {
|
|
112
|
+
layout: 'fullscreen',
|
|
113
|
+
},
|
|
114
|
+
} satisfies Meta;
|
|
115
|
+
|
|
116
|
+
export default meta;
|
|
117
|
+
|
|
102
118
|
// TODO(burdon): Inline formulae.
|
|
103
|
-
export const Default = {
|
|
104
|
-
render:
|
|
119
|
+
export const Default: StoryObj<typeof DefaultStory> = {
|
|
120
|
+
render: DefaultStory,
|
|
105
121
|
args: {
|
|
106
122
|
text: str(
|
|
107
123
|
//
|
|
@@ -124,7 +140,7 @@ export const Default = {
|
|
|
124
140
|
},
|
|
125
141
|
};
|
|
126
142
|
|
|
127
|
-
export const Graph = {
|
|
143
|
+
export const Graph: StoryObj<typeof GraphStory> = {
|
|
128
144
|
render: GraphStory,
|
|
129
145
|
args: {
|
|
130
146
|
text: str(
|
|
@@ -141,16 +157,3 @@ export const Graph = {
|
|
|
141
157
|
),
|
|
142
158
|
},
|
|
143
159
|
};
|
|
144
|
-
|
|
145
|
-
const meta: Meta = {
|
|
146
|
-
title: 'plugins/plugin-sheet/extensions',
|
|
147
|
-
decorators: [
|
|
148
|
-
withClientProvider({ types: [SheetType], createIdentity: true, createSpace: true }),
|
|
149
|
-
withComputeGraphDecorator(),
|
|
150
|
-
withTheme,
|
|
151
|
-
withLayout({ fullscreen: true, classNames: 'justify-center' }),
|
|
152
|
-
],
|
|
153
|
-
parameters: { layout: 'fullscreen' },
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
export default meta;
|
|
@@ -34,7 +34,7 @@ export const computeGraphFacet = singleValueFacet<ComputeGraph>();
|
|
|
34
34
|
|
|
35
35
|
export type ComputeOptions = {};
|
|
36
36
|
|
|
37
|
-
export const compute = (
|
|
37
|
+
export const compute = (_options: ComputeOptions = {}): Extension => {
|
|
38
38
|
let computeNode: ComputeNode | undefined;
|
|
39
39
|
|
|
40
40
|
const update = (state: EditorState, current?: RangeSet<Decoration>) => {
|
|
@@ -53,7 +53,6 @@ export const compute = (options: ComputeOptions = {}): Extension => {
|
|
|
53
53
|
const text = node.node.getChild('CodeText');
|
|
54
54
|
if (type === LANGUAGE_TAG && text) {
|
|
55
55
|
const formula = state.sliceDoc(text.from, text.to);
|
|
56
|
-
|
|
57
56
|
const iter = current?.iter(node.node.from);
|
|
58
57
|
if (iter?.value && iter?.value.spec.formula === formula) {
|
|
59
58
|
// Add existing widget.
|
|
@@ -10,7 +10,7 @@ import { describe, expect, test } from 'vitest';
|
|
|
10
10
|
|
|
11
11
|
import { defaultFunctions } from '@dxos/compute';
|
|
12
12
|
|
|
13
|
-
import { sheetExtension } from './extension';
|
|
13
|
+
import { sheetExtension } from './sheet-extension';
|
|
14
14
|
|
|
15
15
|
describe('formula parser', () => {
|
|
16
16
|
const {
|
|
@@ -2,28 +2,23 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Function from 'effect/Function';
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
6
7
|
import { useCallback, useEffect, useMemo } from 'react';
|
|
7
8
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
chain,
|
|
11
|
-
createIntent,
|
|
12
|
-
createResolver,
|
|
13
|
-
useIntentDispatcher,
|
|
14
|
-
useIntentResolver,
|
|
15
|
-
} from '@dxos/app-framework';
|
|
9
|
+
import { LayoutAction, chain, createIntent, createResolver } from '@dxos/app-framework';
|
|
10
|
+
import { useIntentDispatcher, useIntentResolver } from '@dxos/app-framework/react';
|
|
16
11
|
import { debounce } from '@dxos/async';
|
|
17
12
|
import { type CellAddress, type CompleteCellRange, inRange } from '@dxos/compute';
|
|
18
13
|
import { Obj, Relation } from '@dxos/echo';
|
|
19
14
|
import { ATTENDABLE_PATH_SEPARATOR, DeckAction } from '@dxos/plugin-deck/types';
|
|
20
|
-
import { ThreadAction
|
|
21
|
-
import { Filter, Query,
|
|
15
|
+
import { ThreadAction } from '@dxos/plugin-thread/types';
|
|
16
|
+
import { Filter, Query, getSpace, useQuery } from '@dxos/react-client/echo';
|
|
22
17
|
import { type DxGridElement, type GridContentProps } from '@dxos/react-ui-grid';
|
|
23
|
-
import { AnchoredTo } from '@dxos/
|
|
18
|
+
import { AnchoredTo, Thread } from '@dxos/types';
|
|
24
19
|
|
|
25
20
|
import { useSheetContext } from '../components';
|
|
26
|
-
import {
|
|
21
|
+
import { meta } from '../meta';
|
|
27
22
|
|
|
28
23
|
export const completeCellRangeToThreadCursor = (range: CompleteCellRange): string => {
|
|
29
24
|
return `${range.from.col},${range.from.row},${range.to.col},${range.to.row}`;
|
|
@@ -60,7 +55,7 @@ export const useUpdateFocusedCellOnThreadSelection = (grid: DxGridElement | null
|
|
|
60
55
|
return false;
|
|
61
56
|
}
|
|
62
57
|
|
|
63
|
-
return data.subject ===
|
|
58
|
+
return data.subject === Obj.getDXN(model.sheet).toString() && !!data.options?.cursor;
|
|
64
59
|
},
|
|
65
60
|
resolve: ({ options: { cursor, ref } }) => {
|
|
66
61
|
setActiveRefs(ref);
|
|
@@ -72,7 +67,7 @@ export const useUpdateFocusedCellOnThreadSelection = (grid: DxGridElement | null
|
|
|
72
67
|
[model.sheet, setActiveRefs],
|
|
73
68
|
);
|
|
74
69
|
|
|
75
|
-
useIntentResolver(
|
|
70
|
+
useIntentResolver(meta.id, scrollIntoViewResolver);
|
|
76
71
|
};
|
|
77
72
|
|
|
78
73
|
export const useSelectThreadOnCellFocus = () => {
|
|
@@ -80,7 +75,7 @@ export const useSelectThreadOnCellFocus = () => {
|
|
|
80
75
|
const { dispatchPromise: dispatch } = useIntentDispatcher();
|
|
81
76
|
|
|
82
77
|
const space = getSpace(model.sheet);
|
|
83
|
-
const anchors = useQuery(space, Query.select(Filter.ids(model.sheet.id)).targetOf(AnchoredTo));
|
|
78
|
+
const anchors = useQuery(space, Query.select(Filter.ids(model.sheet.id)).targetOf(AnchoredTo.AnchoredTo));
|
|
84
79
|
|
|
85
80
|
const selectClosestThread = useCallback(
|
|
86
81
|
(cellAddress: CellAddress) => {
|
|
@@ -90,7 +85,7 @@ export const useSelectThreadOnCellFocus = () => {
|
|
|
90
85
|
|
|
91
86
|
const closestThread = anchors.find((anchor) => {
|
|
92
87
|
const source = Relation.getSource(anchor);
|
|
93
|
-
if (anchor.anchor && Obj.instanceOf(
|
|
88
|
+
if (anchor.anchor && Obj.instanceOf(Thread.Thread, source)) {
|
|
94
89
|
const range = parseThreadAnchorAsCellRange(anchor.anchor);
|
|
95
90
|
return range ? inRange(range, cellAddress) : false;
|
|
96
91
|
} else {
|
|
@@ -99,9 +94,9 @@ export const useSelectThreadOnCellFocus = () => {
|
|
|
99
94
|
});
|
|
100
95
|
|
|
101
96
|
if (closestThread) {
|
|
102
|
-
const primary =
|
|
103
|
-
const intent = pipe(
|
|
104
|
-
createIntent(ThreadAction.Select, { current:
|
|
97
|
+
const primary = Obj.getDXN(model.sheet).toString();
|
|
98
|
+
const intent = Function.pipe(
|
|
99
|
+
createIntent(ThreadAction.Select, { current: Obj.getDXN(closestThread).toString() }),
|
|
105
100
|
chain(DeckAction.ChangeCompanion, { primary, companion: `${primary}${ATTENDABLE_PATH_SEPARATOR}comments` }),
|
|
106
101
|
);
|
|
107
102
|
void dispatch(intent);
|
package/src/meta.ts
CHANGED
|
@@ -3,15 +3,17 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type PluginMeta } from '@dxos/app-framework';
|
|
6
|
-
|
|
7
|
-
export const SHEET_PLUGIN = 'dxos.org/plugin/sheet';
|
|
6
|
+
import { trim } from '@dxos/util';
|
|
8
7
|
|
|
9
8
|
export const meta: PluginMeta = {
|
|
10
|
-
id:
|
|
9
|
+
id: 'dxos.org/plugin/sheet',
|
|
11
10
|
name: 'Sheet',
|
|
12
|
-
description:
|
|
13
|
-
|
|
11
|
+
description: trim`
|
|
12
|
+
Full-featured spreadsheet application with over 400 built-in formulas for calculations and data analysis.
|
|
13
|
+
Create custom JavaScript functions and integrate with AI agents for advanced automation.
|
|
14
|
+
`,
|
|
14
15
|
icon: 'ph--grid-nine--regular',
|
|
16
|
+
iconHue: 'indigo',
|
|
15
17
|
source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-sheet',
|
|
16
18
|
screenshots: ['https://dxos.network/plugin-details-sheet-dark.png'],
|
|
17
19
|
};
|
|
@@ -7,10 +7,10 @@ import { afterEach, beforeEach, describe, expect, onTestFinished, test } from 'v
|
|
|
7
7
|
import { Trigger } from '@dxos/async';
|
|
8
8
|
import { type CellScalarValue, addressFromA1Notation, isFormula } from '@dxos/compute';
|
|
9
9
|
import { TestBuilder, testFunctionPlugins } from '@dxos/compute/testing';
|
|
10
|
-
import {
|
|
10
|
+
import { Function } from '@dxos/functions';
|
|
11
11
|
import { log } from '@dxos/log';
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import { Sheet, mapFormulaIndicesToRefs, mapFormulaRefsToIndices } from '../types';
|
|
14
14
|
|
|
15
15
|
import { SheetModel } from './sheet-model';
|
|
16
16
|
import { createTestGrid } from './testing';
|
|
@@ -18,7 +18,7 @@ import { createTestGrid } from './testing';
|
|
|
18
18
|
describe('SheetModel', () => {
|
|
19
19
|
let testBuilder: TestBuilder;
|
|
20
20
|
beforeEach(async () => {
|
|
21
|
-
testBuilder = new TestBuilder({ types: [
|
|
21
|
+
testBuilder = new TestBuilder({ types: [Function.Function], plugins: testFunctionPlugins });
|
|
22
22
|
await testBuilder.open();
|
|
23
23
|
});
|
|
24
24
|
afterEach(async () => {
|
|
@@ -31,7 +31,7 @@ describe('SheetModel', () => {
|
|
|
31
31
|
await graph.open();
|
|
32
32
|
|
|
33
33
|
// TODO(burdon): Create via factory.
|
|
34
|
-
const sheet =
|
|
34
|
+
const sheet = Sheet.make({ rows: 5, columns: 5 });
|
|
35
35
|
const model = new SheetModel(graph, sheet);
|
|
36
36
|
await model.open();
|
|
37
37
|
testBuilder.ctx.onDispose(() => model.close());
|
package/src/model/sheet-model.ts
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
} from '@dxos/compute';
|
|
24
24
|
import { Resource } from '@dxos/context';
|
|
25
25
|
import { Obj } from '@dxos/echo';
|
|
26
|
-
import { FormatEnum, TypeEnum } from '@dxos/echo
|
|
26
|
+
import { FormatEnum, TypeEnum } from '@dxos/echo/internal';
|
|
27
27
|
import { invariant } from '@dxos/invariant';
|
|
28
28
|
import { PublicKey } from '@dxos/keys';
|
|
29
29
|
import { log } from '@dxos/log';
|
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
mapFormulaIndicesToRefs,
|
|
40
40
|
mapFormulaRefsToIndices,
|
|
41
41
|
} from '../types';
|
|
42
|
-
import { type
|
|
42
|
+
import { type Sheet, type SheetAction } from '../types';
|
|
43
43
|
|
|
44
44
|
// TODO(burdon): Move to compute.
|
|
45
45
|
// Map sheet types to system types.
|
|
@@ -92,7 +92,7 @@ export class SheetModel extends Resource {
|
|
|
92
92
|
|
|
93
93
|
constructor(
|
|
94
94
|
private readonly _graph: ComputeGraph,
|
|
95
|
-
private readonly _sheet:
|
|
95
|
+
private readonly _sheet: Sheet.Sheet,
|
|
96
96
|
private readonly _options: SheetModelOptions = {},
|
|
97
97
|
) {
|
|
98
98
|
super();
|
|
@@ -414,7 +414,7 @@ export class SheetModel extends Resource {
|
|
|
414
414
|
/**
|
|
415
415
|
* Sets values from a simple map.
|
|
416
416
|
*/
|
|
417
|
-
setValues(values: Record<string, CellValue>): void {
|
|
417
|
+
setValues(values: Record<string, Sheet.CellValue>): void {
|
|
418
418
|
Object.entries(values).forEach(([key, { value }]) => {
|
|
419
419
|
this.setValue(addressFromA1Notation(key), value);
|
|
420
420
|
});
|
package/src/model/testing.ts
CHANGED
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
import { addressToA1Notation } from '@dxos/compute';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { Sheet } from '../types';
|
|
8
8
|
|
|
9
9
|
// TODO(burdon): Create testing endpoint.
|
|
10
10
|
// TODO(burdon): Move to react-ui-sheet.
|
|
11
|
-
export const createTestGrid = ({ cols = 4, rows = 10 }: { cols: number; rows: number }):
|
|
11
|
+
export const createTestGrid = ({ cols = 4, rows = 10 }: { cols: number; rows: number }): Sheet.Sheet => {
|
|
12
12
|
const year = new Date().getFullYear();
|
|
13
13
|
|
|
14
|
-
const cells: Record<string, CellValue> = {};
|
|
14
|
+
const cells: Record<string, Sheet.CellValue> = {};
|
|
15
15
|
for (let col = 1; col <= cols; col++) {
|
|
16
16
|
for (let row = 1; row <= 10; row++) {
|
|
17
17
|
const cell = addressToA1Notation({ col, row });
|
|
@@ -27,7 +27,7 @@ export const createTestGrid = ({ cols = 4, rows = 10 }: { cols: number; rows: nu
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const sheet =
|
|
30
|
+
const sheet = Sheet.make({
|
|
31
31
|
name: 'Test',
|
|
32
32
|
cells,
|
|
33
33
|
});
|
|
@@ -7,7 +7,7 @@ import { useEffect, useState } from 'react';
|
|
|
7
7
|
import { type ComputeGraph } from '@dxos/compute';
|
|
8
8
|
|
|
9
9
|
import { SheetModel } from '../model';
|
|
10
|
-
import { type
|
|
10
|
+
import { type Sheet } from '../types';
|
|
11
11
|
|
|
12
12
|
export type UseSheetModelOptions = {
|
|
13
13
|
readonly?: boolean;
|
|
@@ -15,7 +15,7 @@ export type UseSheetModelOptions = {
|
|
|
15
15
|
|
|
16
16
|
export const useSheetModel = (
|
|
17
17
|
graph?: ComputeGraph,
|
|
18
|
-
sheet?:
|
|
18
|
+
sheet?: Sheet.Sheet,
|
|
19
19
|
{ readonly }: UseSheetModelOptions = {},
|
|
20
20
|
): SheetModel | undefined => {
|
|
21
21
|
const [model, setModel] = useState<SheetModel>();
|
package/src/sanity.test.ts
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
import { describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { Client } from '@dxos/client';
|
|
8
|
-
import {
|
|
9
|
-
import { FunctionType } from '@dxos/functions';
|
|
8
|
+
import { Function } from '@dxos/functions';
|
|
10
9
|
|
|
11
10
|
// Part 2.
|
|
12
11
|
// TODO(burdon): Cannot test outside of browser.
|
|
@@ -23,7 +22,7 @@ import { FunctionType } from '@dxos/functions';
|
|
|
23
22
|
describe('test', () => {
|
|
24
23
|
test('test', async () => {
|
|
25
24
|
const client = new Client();
|
|
26
|
-
client.addTypes([
|
|
25
|
+
client.addTypes([Function.Function]);
|
|
27
26
|
await client.initialize();
|
|
28
27
|
await client.halo.createIdentity();
|
|
29
28
|
|
|
@@ -34,7 +33,7 @@ describe('test', () => {
|
|
|
34
33
|
// - ERROR "process.nextTick is not a function"
|
|
35
34
|
// - ERROR "Identifier 'Buffer' has already been declared" if { nodeExternal: true }
|
|
36
35
|
const space = await client.spaces.create();
|
|
37
|
-
const fn = space.db.add(
|
|
36
|
+
const fn = space.db.add(Function.make({ name: 'test', version: '0.0.1', binding: 'HELLO' }));
|
|
38
37
|
expect(fn).to.exist;
|
|
39
38
|
});
|
|
40
39
|
});
|
package/src/serializer.ts
CHANGED
|
@@ -6,16 +6,16 @@ import { Obj } from '@dxos/echo';
|
|
|
6
6
|
import { type TypedObjectSerializer } from '@dxos/plugin-space/types';
|
|
7
7
|
import { getObjectCore } from '@dxos/react-client/echo';
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { Sheet } from './types';
|
|
10
10
|
|
|
11
|
-
export const serializer: TypedObjectSerializer<
|
|
11
|
+
export const serializer: TypedObjectSerializer<Sheet.Sheet> = {
|
|
12
12
|
serialize: async ({ object }): Promise<string> => {
|
|
13
13
|
return JSON.stringify(object, null, 2);
|
|
14
14
|
},
|
|
15
15
|
|
|
16
16
|
deserialize: async ({ content, newId }) => {
|
|
17
17
|
const { id, ...parsed } = JSON.parse(content);
|
|
18
|
-
const sheet = Obj.make(
|
|
18
|
+
const sheet = Obj.make(Sheet.Sheet, parsed);
|
|
19
19
|
|
|
20
20
|
if (!newId) {
|
|
21
21
|
const core = getObjectCore(sheet);
|
package/src/testing/data.ts
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type { Sheet } from '../types';
|
|
6
6
|
|
|
7
|
-
export const createTestCells = (testSheetName = 'test'): Record<string, CellValue> => ({
|
|
7
|
+
export const createTestCells = (testSheetName = 'test'): Record<string, Sheet.CellValue> => ({
|
|
8
8
|
B1: { value: 'Qty2' },
|
|
9
9
|
B3: { value: 1 },
|
|
10
10
|
B4: { value: 2 },
|
package/src/testing/testing.tsx
CHANGED
|
@@ -6,19 +6,20 @@ import { type Decorator } from '@storybook/react';
|
|
|
6
6
|
import React, { useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { type ComputeGraph, type ComputeGraphOptions, ComputeGraphRegistry } from '@dxos/compute';
|
|
9
|
+
import { createMockedComputeRuntimeProvider } from '@dxos/compute/testing';
|
|
9
10
|
import { type Space } from '@dxos/react-client/echo';
|
|
10
11
|
import { useAsyncState } from '@dxos/react-hooks';
|
|
11
12
|
|
|
12
13
|
import { ComputeGraphContextProvider } from '../components';
|
|
13
|
-
import {
|
|
14
|
+
import { Sheet } from '../types';
|
|
14
15
|
|
|
15
|
-
export const useTestSheet = (space?: Space, graph?: ComputeGraph, options?:
|
|
16
|
+
export const useTestSheet = (space?: Space, graph?: ComputeGraph, options?: Sheet.SheetProps) => {
|
|
16
17
|
const [sheet] = useAsyncState(async () => {
|
|
17
18
|
if (!space || !graph) {
|
|
18
19
|
return;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
const sheet =
|
|
22
|
+
const sheet = Sheet.make(options);
|
|
22
23
|
space.db.add(sheet);
|
|
23
24
|
return sheet;
|
|
24
25
|
}, [space, graph]);
|
|
@@ -26,9 +27,14 @@ export const useTestSheet = (space?: Space, graph?: ComputeGraph, options?: Crea
|
|
|
26
27
|
};
|
|
27
28
|
|
|
28
29
|
export const withComputeGraphDecorator =
|
|
29
|
-
(options?: ComputeGraphOptions): Decorator =>
|
|
30
|
+
(options?: Partial<ComputeGraphOptions>): Decorator =>
|
|
30
31
|
(Story) => {
|
|
31
|
-
const [registry] = useState(
|
|
32
|
+
const [registry] = useState(
|
|
33
|
+
new ComputeGraphRegistry({
|
|
34
|
+
...options,
|
|
35
|
+
computeRuntime: options?.computeRuntime ?? createMockedComputeRuntimeProvider(),
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
32
38
|
return (
|
|
33
39
|
<ComputeGraphContextProvider registry={registry}>
|
|
34
40
|
<Story />
|
package/src/translations.ts
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
import { type Resource } from '@dxos/react-ui';
|
|
6
6
|
|
|
7
7
|
import { meta } from './meta';
|
|
8
|
-
import {
|
|
8
|
+
import { Sheet } from './types';
|
|
9
9
|
|
|
10
10
|
export const translations = [
|
|
11
11
|
{
|
|
12
12
|
'en-US': {
|
|
13
|
-
[
|
|
13
|
+
[Sheet.Sheet.typename]: {
|
|
14
14
|
'typename label': 'Sheet',
|
|
15
15
|
'typename label_zero': 'Sheets',
|
|
16
16
|
'typename label_one': 'Sheet',
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { addressFromA1Notation, isFormula } from '@dxos/compute';
|
|
8
|
+
import { Obj, Type } from '@dxos/echo';
|
|
9
|
+
import { FormAnnotation } from '@dxos/echo/internal';
|
|
10
|
+
|
|
11
|
+
import { addressToIndex, initialize, mapFormulaRefsToIndices } from './util';
|
|
12
|
+
|
|
13
|
+
export type SheetSize = {
|
|
14
|
+
rows: number;
|
|
15
|
+
columns: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const CellValue = Schema.Struct({
|
|
19
|
+
// TODO(burdon): How to store dates (datetime, date, time), percentages, etc.
|
|
20
|
+
// Consider import/export; natural access for other plugins. Special handling for currency (precision).
|
|
21
|
+
// TODO(burdon): Automerge (long string) or short string or number.
|
|
22
|
+
value: Schema.Any,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export type CellValue = Schema.Schema.Type<typeof CellValue>;
|
|
26
|
+
|
|
27
|
+
// TODO(burdon): IMPORTANT: Reconcile with Field definition.
|
|
28
|
+
export const Range = Schema.Struct({
|
|
29
|
+
range: Schema.String,
|
|
30
|
+
key: Schema.String,
|
|
31
|
+
value: Schema.String,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export type Range = Schema.Schema.Type<typeof Range>;
|
|
35
|
+
|
|
36
|
+
// TODO(burdon): Visibility, locked, frozen, etc.
|
|
37
|
+
export const RowColumnMeta = Schema.Struct({
|
|
38
|
+
size: Schema.optional(Schema.Number),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// TODO(burdon): Reconcile col/column (across packages).
|
|
42
|
+
// TODO(burdon): Index to all updates when rows/columns are inserted/deleted.
|
|
43
|
+
export const Sheet = Schema.Struct({
|
|
44
|
+
name: Schema.optional(Schema.String),
|
|
45
|
+
|
|
46
|
+
// Sparse map of cells referenced by index.
|
|
47
|
+
cells: Schema.Record({ key: Schema.String, value: Schema.mutable(CellValue) }).pipe(
|
|
48
|
+
Schema.mutable,
|
|
49
|
+
FormAnnotation.set(false),
|
|
50
|
+
),
|
|
51
|
+
|
|
52
|
+
// Ordered row indices.
|
|
53
|
+
rows: Schema.Array(Schema.String).pipe(Schema.mutable, FormAnnotation.set(false)),
|
|
54
|
+
|
|
55
|
+
// Ordered column indices.
|
|
56
|
+
columns: Schema.Array(Schema.String).pipe(Schema.mutable, FormAnnotation.set(false)),
|
|
57
|
+
|
|
58
|
+
// Row metadata referenced by index.
|
|
59
|
+
rowMeta: Schema.Record({ key: Schema.String, value: Schema.mutable(RowColumnMeta) }).pipe(
|
|
60
|
+
Schema.mutable,
|
|
61
|
+
FormAnnotation.set(false),
|
|
62
|
+
),
|
|
63
|
+
|
|
64
|
+
// Column metadata referenced by index.
|
|
65
|
+
columnMeta: Schema.Record({ key: Schema.String, value: Schema.mutable(RowColumnMeta) }).pipe(
|
|
66
|
+
Schema.mutable,
|
|
67
|
+
FormAnnotation.set(false),
|
|
68
|
+
),
|
|
69
|
+
|
|
70
|
+
// Cell formatting referenced by indexed range.
|
|
71
|
+
ranges: Schema.Array(Range).pipe(Schema.mutable, FormAnnotation.set(false)),
|
|
72
|
+
}).pipe(
|
|
73
|
+
Type.Obj({
|
|
74
|
+
typename: 'dxos.org/type/Sheet',
|
|
75
|
+
version: '0.1.0',
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
export interface Sheet extends Schema.Schema.Type<typeof Sheet> {}
|
|
80
|
+
|
|
81
|
+
export type SheetProps = {
|
|
82
|
+
name?: string;
|
|
83
|
+
cells?: Record<string, CellValue>;
|
|
84
|
+
} & Partial<SheetSize>;
|
|
85
|
+
|
|
86
|
+
export const make = ({ name, cells = {}, ...size }: SheetProps = {}) => {
|
|
87
|
+
const sheet = Obj.make(Sheet, { name, cells: {}, rows: [], columns: [], rowMeta: {}, columnMeta: {}, ranges: [] });
|
|
88
|
+
|
|
89
|
+
initialize(sheet, size);
|
|
90
|
+
|
|
91
|
+
if (cells) {
|
|
92
|
+
Object.entries(cells).forEach(([key, { value }]) => {
|
|
93
|
+
const idx = addressToIndex(sheet, addressFromA1Notation(key));
|
|
94
|
+
if (isFormula(value)) {
|
|
95
|
+
value = mapFormulaRefsToIndices(sheet, value);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
sheet.cells[idx] = { value };
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return sheet;
|
|
103
|
+
};
|