@dxos/plugin-sheet 0.6.8-main.046e6cf
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/LICENSE +8 -0
- package/README.md +14 -0
- package/dist/lib/browser/SheetContainer-H22IDJ43.mjs +3740 -0
- package/dist/lib/browser/SheetContainer-H22IDJ43.mjs.map +7 -0
- package/dist/lib/browser/chunk-6VPEAUG6.mjs +82 -0
- package/dist/lib/browser/chunk-6VPEAUG6.mjs.map +7 -0
- package/dist/lib/browser/chunk-AT2FJXQX.mjs +861 -0
- package/dist/lib/browser/chunk-AT2FJXQX.mjs.map +7 -0
- package/dist/lib/browser/chunk-JRL5LGCE.mjs +18 -0
- package/dist/lib/browser/chunk-JRL5LGCE.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +213 -0
- package/dist/lib/browser/index.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -0
- package/dist/lib/browser/meta.mjs +9 -0
- package/dist/lib/browser/meta.mjs.map +7 -0
- package/dist/lib/browser/types.mjs +22 -0
- package/dist/lib/browser/types.mjs.map +7 -0
- package/dist/lib/node/SheetContainer-S32KTNZ6.cjs +3731 -0
- package/dist/lib/node/SheetContainer-S32KTNZ6.cjs.map +7 -0
- package/dist/lib/node/chunk-4CE6FK5Z.cjs +108 -0
- package/dist/lib/node/chunk-4CE6FK5Z.cjs.map +7 -0
- package/dist/lib/node/chunk-BJ6ZD7MN.cjs +51 -0
- package/dist/lib/node/chunk-BJ6ZD7MN.cjs.map +7 -0
- package/dist/lib/node/chunk-FCKJ4QRM.cjs +881 -0
- package/dist/lib/node/chunk-FCKJ4QRM.cjs.map +7 -0
- package/dist/lib/node/index.cjs +226 -0
- package/dist/lib/node/index.cjs.map +7 -0
- package/dist/lib/node/meta.cjs +30 -0
- package/dist/lib/node/meta.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -0
- package/dist/lib/node/types.cjs +44 -0
- package/dist/lib/node/types.cjs.map +7 -0
- package/dist/types/src/SheetPlugin.d.ts +4 -0
- package/dist/types/src/SheetPlugin.d.ts.map +1 -0
- package/dist/types/src/components/CellEditor/CellEditor.d.ts +14 -0
- package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +1 -0
- package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts +29 -0
- package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +1 -0
- package/dist/types/src/components/CellEditor/extension.d.ts +18 -0
- package/dist/types/src/components/CellEditor/extension.d.ts.map +1 -0
- package/dist/types/src/components/CellEditor/extension.test.d.ts +2 -0
- package/dist/types/src/components/CellEditor/extension.test.d.ts.map +1 -0
- package/dist/types/src/components/CellEditor/functions.d.ts +66 -0
- package/dist/types/src/components/CellEditor/functions.d.ts.map +1 -0
- package/dist/types/src/components/CellEditor/index.d.ts +3 -0
- package/dist/types/src/components/CellEditor/index.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/async-function.d.ts +52 -0
- package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/custom.d.ts +21 -0
- package/dist/types/src/components/ComputeGraph/custom.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/edge-function.d.ts +20 -0
- package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/graph-context.d.ts +11 -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 +21 -0
- package/dist/types/src/components/ComputeGraph/graph.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/index.d.ts +4 -0
- package/dist/types/src/components/ComputeGraph/index.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/Sheet.d.ts +55 -0
- package/dist/types/src/components/Sheet/Sheet.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/Sheet.stories.d.ts +54 -0
- package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/formatting.d.ts +14 -0
- package/dist/types/src/components/Sheet/formatting.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/grid.d.ts +52 -0
- package/dist/types/src/components/Sheet/grid.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/index.d.ts +2 -0
- package/dist/types/src/components/Sheet/index.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/nav.d.ts +29 -0
- package/dist/types/src/components/Sheet/nav.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/sheet-context.d.ts +24 -0
- package/dist/types/src/components/Sheet/sheet-context.d.ts.map +1 -0
- package/dist/types/src/components/Sheet/util.d.ts +18 -0
- package/dist/types/src/components/Sheet/util.d.ts.map +1 -0
- package/dist/types/src/components/SheetContainer.d.ts +9 -0
- package/dist/types/src/components/SheetContainer.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +21 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +35 -0
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/common.d.ts +20 -0
- package/dist/types/src/components/Toolbar/common.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/index.d.ts +2 -0
- package/dist/types/src/components/Toolbar/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +7 -0
- package/dist/types/src/components/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +4 -0
- package/dist/types/src/index.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +15 -0
- package/dist/types/src/meta.d.ts.map +1 -0
- package/dist/types/src/model/index.d.ts +3 -0
- package/dist/types/src/model/index.d.ts.map +1 -0
- 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/model.d.ts +142 -0
- package/dist/types/src/model/model.d.ts.map +1 -0
- package/dist/types/src/model/types.d.ts +17 -0
- package/dist/types/src/model/types.d.ts.map +1 -0
- package/dist/types/src/model/types.test.d.ts +2 -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/translations.d.ts +16 -0
- package/dist/types/src/translations.d.ts.map +1 -0
- package/dist/types/src/types.d.ts +94 -0
- package/dist/types/src/types.d.ts.map +1 -0
- package/package.json +122 -0
- package/src/SheetPlugin.tsx +150 -0
- package/src/components/CellEditor/CellEditor.stories.tsx +88 -0
- package/src/components/CellEditor/CellEditor.tsx +113 -0
- package/src/components/CellEditor/extension.test.ts +42 -0
- package/src/components/CellEditor/extension.ts +286 -0
- package/src/components/CellEditor/functions.ts +2017 -0
- package/src/components/CellEditor/index.ts +6 -0
- package/src/components/ComputeGraph/async-function.ts +148 -0
- package/src/components/ComputeGraph/custom.ts +70 -0
- package/src/components/ComputeGraph/edge-function.ts +60 -0
- package/src/components/ComputeGraph/graph-context.tsx +37 -0
- package/src/components/ComputeGraph/graph.browser.test.ts +49 -0
- package/src/components/ComputeGraph/graph.ts +52 -0
- package/src/components/ComputeGraph/index.ts +7 -0
- package/src/components/Sheet/Sheet.stories.tsx +329 -0
- package/src/components/Sheet/Sheet.tsx +1164 -0
- package/src/components/Sheet/formatting.ts +106 -0
- package/src/components/Sheet/grid.ts +191 -0
- package/src/components/Sheet/index.ts +5 -0
- package/src/components/Sheet/nav.ts +157 -0
- package/src/components/Sheet/sheet-context.tsx +101 -0
- package/src/components/Sheet/util.ts +56 -0
- package/src/components/SheetContainer.tsx +30 -0
- package/src/components/Toolbar/Toolbar.stories.tsx +36 -0
- package/src/components/Toolbar/Toolbar.tsx +198 -0
- package/src/components/Toolbar/common.tsx +72 -0
- package/src/components/Toolbar/index.ts +5 -0
- package/src/components/index.ts +10 -0
- package/src/index.ts +9 -0
- package/src/meta.tsx +18 -0
- package/src/model/index.ts +6 -0
- package/src/model/model.browser.test.ts +100 -0
- package/src/model/model.ts +480 -0
- package/src/model/types.test.ts +92 -0
- package/src/model/types.ts +71 -0
- package/src/model/util.ts +36 -0
- package/src/translations.ts +22 -0
- package/src/types.ts +110 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxosTheme';
|
|
6
|
+
|
|
7
|
+
import { type Decorator } from '@storybook/react';
|
|
8
|
+
import React, { useContext, useEffect, useState } from 'react';
|
|
9
|
+
|
|
10
|
+
import { Client } from '@dxos/client';
|
|
11
|
+
import { type EchoReactiveObject } from '@dxos/echo-schema';
|
|
12
|
+
import { log } from '@dxos/log';
|
|
13
|
+
import { getSpace, type Space } from '@dxos/react-client/echo';
|
|
14
|
+
import { Button, Tooltip } from '@dxos/react-ui';
|
|
15
|
+
import { mx } from '@dxos/react-ui-theme';
|
|
16
|
+
import { withTheme, withFullscreen } from '@dxos/storybook-utils';
|
|
17
|
+
|
|
18
|
+
import { Sheet } from './Sheet';
|
|
19
|
+
import { type SizeMap } from './grid';
|
|
20
|
+
import { useSheetContext } from './sheet-context';
|
|
21
|
+
import { SheetModel } from '../../model';
|
|
22
|
+
import { ValueTypeEnum, type CellValue, createSheet, SheetType } from '../../types';
|
|
23
|
+
import {
|
|
24
|
+
type ComputeGraph,
|
|
25
|
+
ComputeGraphContext,
|
|
26
|
+
ComputeGraphContextProvider,
|
|
27
|
+
createComputeGraph,
|
|
28
|
+
useComputeGraph,
|
|
29
|
+
} from '../ComputeGraph';
|
|
30
|
+
import { Toolbar, type ToolbarActionHandler } from '../Toolbar';
|
|
31
|
+
|
|
32
|
+
// TODO(burdon): Allow toolbar to access sheet context; provide state for current cursor/range.
|
|
33
|
+
const SheetWithToolbar = ({ debug, space }: { debug?: boolean; space: Space }) => {
|
|
34
|
+
const { model, cursor, range } = useSheetContext();
|
|
35
|
+
|
|
36
|
+
// TODO(burdon): Factor out.
|
|
37
|
+
const handleAction: ToolbarActionHandler = ({ type }) => {
|
|
38
|
+
log.info('action', { type, cursor, range });
|
|
39
|
+
if (!cursor) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const idx = range ? model.rangeToIndex(range) : model.addressToIndex(cursor);
|
|
44
|
+
model.sheet.formatting[idx] ??= {};
|
|
45
|
+
const format = model.sheet.formatting[idx];
|
|
46
|
+
|
|
47
|
+
switch (type) {
|
|
48
|
+
case 'clear': {
|
|
49
|
+
// TODO(burdon): Toggle to show all ranges to allow user to delete range.
|
|
50
|
+
format.classNames = [];
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
case 'highlight': {
|
|
54
|
+
// TODO(burdon): Util to add to set.
|
|
55
|
+
format.classNames = ['bg-green-300 dark:bg-green-700'];
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
case 'left': {
|
|
60
|
+
format.classNames = ['text-left'];
|
|
61
|
+
break;
|
|
62
|
+
}
|
|
63
|
+
case 'center': {
|
|
64
|
+
format.classNames = ['text-center'];
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
case 'right': {
|
|
68
|
+
format.classNames = ['text-right'];
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
case 'date': {
|
|
73
|
+
format.type = ValueTypeEnum.Date;
|
|
74
|
+
format.format = 'YYYY-MM-DD';
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
case 'currency': {
|
|
78
|
+
format.type = ValueTypeEnum.Currency;
|
|
79
|
+
format.precision = 2;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const graph = useComputeGraph(space);
|
|
86
|
+
const handleRefresh = () => {
|
|
87
|
+
graph.refresh();
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<div className='flex flex-col overflow-hidden'>
|
|
92
|
+
<Toolbar.Root onAction={handleAction}>
|
|
93
|
+
<Toolbar.Styles />
|
|
94
|
+
<Toolbar.Format />
|
|
95
|
+
<Toolbar.Alignment />
|
|
96
|
+
<Toolbar.Separator />
|
|
97
|
+
<Toolbar.Actions />
|
|
98
|
+
<Button onClick={handleRefresh}>Refresh</Button>
|
|
99
|
+
</Toolbar.Root>
|
|
100
|
+
<Sheet.Main />
|
|
101
|
+
{debug && <Sheet.Debug />}
|
|
102
|
+
</div>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const testSheetName = 'test';
|
|
107
|
+
|
|
108
|
+
const withGraphDecorator: Decorator = (Story) => {
|
|
109
|
+
const [graphs, setGraphs] = useState<Record<string, ComputeGraph>>({});
|
|
110
|
+
|
|
111
|
+
const setGraph = (key: string, graph: ComputeGraph) => {
|
|
112
|
+
if (!graph.hf.doesSheetExist(testSheetName)) {
|
|
113
|
+
const sheetName = graph.hf.addSheet(testSheetName);
|
|
114
|
+
const sheet = graph.hf.getSheetId(sheetName)!;
|
|
115
|
+
graph.hf.setCellContents({ sheet, col: 0, row: 0 }, Math.random());
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
setGraphs((graphs) => ({ ...graphs, [key]: graph }));
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<ComputeGraphContextProvider graphs={graphs} setGraph={setGraph}>
|
|
123
|
+
<Story />
|
|
124
|
+
</ComputeGraphContextProvider>
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export default {
|
|
129
|
+
title: 'plugin-sheet/Sheet',
|
|
130
|
+
component: Sheet,
|
|
131
|
+
decorators: [withGraphDecorator, withTheme, withFullscreen({ classNames: 'inset-4' })],
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
export const Default = () => {
|
|
135
|
+
const [debug, setDebug] = useState(false);
|
|
136
|
+
const sheet = useTestSheet();
|
|
137
|
+
const space = getSpace(sheet);
|
|
138
|
+
if (!sheet || !space) {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<Tooltip.Provider>
|
|
144
|
+
<Sheet.Root sheet={sheet} space={space} onInfo={() => setDebug((debug) => !debug)}>
|
|
145
|
+
<SheetWithToolbar debug={debug} space={space} />
|
|
146
|
+
</Sheet.Root>
|
|
147
|
+
</Tooltip.Provider>
|
|
148
|
+
);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
export const Debug = () => {
|
|
152
|
+
const sheet = useTestSheet();
|
|
153
|
+
const space = getSpace(sheet);
|
|
154
|
+
if (!sheet || !space) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return (
|
|
159
|
+
<Sheet.Root sheet={sheet} space={space}>
|
|
160
|
+
<Sheet.Main />
|
|
161
|
+
<Sheet.Debug />
|
|
162
|
+
</Sheet.Root>
|
|
163
|
+
);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export const Rows = () => {
|
|
167
|
+
const [rowSizes, setRowSizes] = useState<SizeMap>({});
|
|
168
|
+
const sheet = useTestSheet();
|
|
169
|
+
const space = getSpace(sheet);
|
|
170
|
+
if (!sheet || !space) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<Sheet.Root sheet={sheet} space={space}>
|
|
176
|
+
<Sheet.Rows
|
|
177
|
+
rows={sheet.rows}
|
|
178
|
+
sizes={rowSizes}
|
|
179
|
+
onResize={(id, size) => setRowSizes((sizes) => ({ ...sizes, [id]: size }))}
|
|
180
|
+
/>
|
|
181
|
+
</Sheet.Root>
|
|
182
|
+
);
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
export const Columns = () => {
|
|
186
|
+
const [columnSizes, setColumnSizes] = useState<SizeMap>({});
|
|
187
|
+
const sheet = useTestSheet();
|
|
188
|
+
const space = getSpace(sheet);
|
|
189
|
+
if (!sheet || !space) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<Sheet.Root sheet={sheet} space={space}>
|
|
195
|
+
<Sheet.Columns
|
|
196
|
+
columns={sheet.columns}
|
|
197
|
+
sizes={columnSizes}
|
|
198
|
+
onResize={(id, size) => setColumnSizes((sizes) => ({ ...sizes, [id]: size }))}
|
|
199
|
+
/>
|
|
200
|
+
</Sheet.Root>
|
|
201
|
+
);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export const Main = () => {
|
|
205
|
+
const sheet = useTestSheet();
|
|
206
|
+
const space = getSpace(sheet);
|
|
207
|
+
if (!sheet || !space) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
<Sheet.Root sheet={sheet} space={space}>
|
|
213
|
+
<Sheet.Grid
|
|
214
|
+
size={{
|
|
215
|
+
numRows: 50,
|
|
216
|
+
numColumns: 26,
|
|
217
|
+
}}
|
|
218
|
+
rows={sheet.rows}
|
|
219
|
+
columns={sheet.columns}
|
|
220
|
+
rowSizes={{}}
|
|
221
|
+
columnSizes={{}}
|
|
222
|
+
/>
|
|
223
|
+
</Sheet.Root>
|
|
224
|
+
);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Scrolling container with fixed border that overlaps the border of inner elements.
|
|
229
|
+
*/
|
|
230
|
+
export const ScrollLayout = () => {
|
|
231
|
+
return (
|
|
232
|
+
<div className='relative flex grow overflow-hidden'>
|
|
233
|
+
{/* Fixed border. */}
|
|
234
|
+
<div className='z-20 absolute inset-0 border border-primary-500 pointer-events-none' />
|
|
235
|
+
|
|
236
|
+
{/* Scroll container. */}
|
|
237
|
+
<div className='grow overflow-auto scrollbar-thin'>
|
|
238
|
+
{/* Scroll content. */}
|
|
239
|
+
<div className='relative w-[2000px] h-[2000px]'>
|
|
240
|
+
<Cell label='A1' className='absolute left-0 top-0 w-20 h-20' />
|
|
241
|
+
<Cell label='A1' className='absolute right-0 top-0 w-20 h-20' />
|
|
242
|
+
<Cell label='A1' className='absolute left-0 bottom-0 w-20 h-20' />
|
|
243
|
+
<Cell label='A1' className='absolute right-0 bottom-0 w-20 h-20' />
|
|
244
|
+
</div>
|
|
245
|
+
</div>
|
|
246
|
+
</div>
|
|
247
|
+
);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
export const GridLayout = () => {
|
|
251
|
+
return (
|
|
252
|
+
<div className='grid grid-cols-[40px_1fr_40px] grid-rows-[40px_1fr_40px] grow'>
|
|
253
|
+
<Cell label='A1' />
|
|
254
|
+
<Cell label='B1' />
|
|
255
|
+
<Cell label='C1' />
|
|
256
|
+
<Cell label='A2' />
|
|
257
|
+
<Cell label='B2' />
|
|
258
|
+
<Cell label='C2' />
|
|
259
|
+
<Cell label='A3' />
|
|
260
|
+
<Cell label='B3' />
|
|
261
|
+
<Cell label='C3' />
|
|
262
|
+
</div>
|
|
263
|
+
);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const Cell = ({ className, label }: { className?: string; label: string }) => (
|
|
267
|
+
<div className={mx('flex items-center justify-center border', className)}>{label}</div>
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
const createCells = (): Record<string, CellValue> => ({
|
|
271
|
+
B1: { value: 'Qty' },
|
|
272
|
+
B3: { value: 1 },
|
|
273
|
+
B4: { value: 2 },
|
|
274
|
+
B5: { value: 3 },
|
|
275
|
+
B7: { value: 'Total' },
|
|
276
|
+
|
|
277
|
+
C1: { value: 'Price' },
|
|
278
|
+
C3: { value: 2_000 },
|
|
279
|
+
C4: { value: 2_500 },
|
|
280
|
+
C5: { value: 3_000 },
|
|
281
|
+
C7: { value: '=SUMPRODUCT(B2:B6, C2:C6)' },
|
|
282
|
+
// C8: { value: '=C7*CRYPTO(D7)' },
|
|
283
|
+
C8: { value: '=C7*TEST()' },
|
|
284
|
+
|
|
285
|
+
D7: { value: 'USD' },
|
|
286
|
+
D8: { value: 'BTC' },
|
|
287
|
+
|
|
288
|
+
E3: { value: '=TODAY()' },
|
|
289
|
+
E4: { value: '=NOW()' },
|
|
290
|
+
|
|
291
|
+
F1: { value: `=${testSheetName}!A1` }, // Ref test sheet.
|
|
292
|
+
F3: { value: true },
|
|
293
|
+
F4: { value: false },
|
|
294
|
+
F5: { value: '8%' },
|
|
295
|
+
F6: { value: '$10000' },
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
const useTestSheet = () => {
|
|
299
|
+
const { graphs, setGraph } = useContext(ComputeGraphContext);
|
|
300
|
+
const [sheet, setSheet] = useState<EchoReactiveObject<SheetType>>();
|
|
301
|
+
useEffect(() => {
|
|
302
|
+
const t = setTimeout(async () => {
|
|
303
|
+
const client = new Client();
|
|
304
|
+
await client.initialize();
|
|
305
|
+
await client.halo.createIdentity();
|
|
306
|
+
const space = await client.spaces.create();
|
|
307
|
+
client.addTypes([SheetType]);
|
|
308
|
+
|
|
309
|
+
const graph = graphs[space.id] ?? createComputeGraph();
|
|
310
|
+
if (!graphs[space.id]) {
|
|
311
|
+
setGraph(space.id, graph);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
const sheet = createSheet();
|
|
315
|
+
const model = new SheetModel(graph, sheet);
|
|
316
|
+
await model.initialize();
|
|
317
|
+
model.setValues(createCells());
|
|
318
|
+
model.sheet.columnMeta[model.sheet.columns[0]] = { size: 100 };
|
|
319
|
+
await model.destroy();
|
|
320
|
+
|
|
321
|
+
space.db.add(sheet);
|
|
322
|
+
setSheet(sheet);
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
return () => clearTimeout(t);
|
|
326
|
+
}, []);
|
|
327
|
+
|
|
328
|
+
return sheet;
|
|
329
|
+
};
|