@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
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type FunctionPluginDefinition } from 'hyperformula';
|
|
6
|
-
import { type ConfigParams } from 'hyperformula/typings/ConfigParams';
|
|
7
|
-
import { type Listeners } from 'hyperformula/typings/Emitter';
|
|
8
|
-
import { type FunctionTranslationsPackage } from 'hyperformula/typings/interpreter';
|
|
9
|
-
import defaultsDeep from 'lodash.defaultsdeep';
|
|
10
|
-
|
|
11
|
-
import { Event } from '@dxos/async';
|
|
12
|
-
import { type SpaceId, type Space, Filter, fullyQualifiedId } from '@dxos/client/echo';
|
|
13
|
-
import { Resource } from '@dxos/context';
|
|
14
|
-
import { invariant } from '@dxos/invariant';
|
|
15
|
-
import { PublicKey } from '@dxos/keys';
|
|
16
|
-
import { log } from '@dxos/log';
|
|
17
|
-
import { FunctionType } from '@dxos/plugin-script/types';
|
|
18
|
-
import { nonNullable } from '@dxos/util';
|
|
19
|
-
|
|
20
|
-
import { ExportedCellChange, HyperFormula } from '#hyperformula';
|
|
21
|
-
import { FunctionContext, type FunctionContextOptions } from './async-function';
|
|
22
|
-
import { ComputeNode } from './compute-node';
|
|
23
|
-
import { EdgeFunctionPlugin, EdgeFunctionPluginTranslations } from './edge-function';
|
|
24
|
-
import { defaultFunctions, type FunctionDefinition } from './function-defs';
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
// NOTE: The package.json file defines the packaged #hyperformula module.
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
// TODO(wittjosiah): Factor out.
|
|
31
|
-
const OBJECT_ID_LENGTH = 60; // 33 (space id) + 26 (object id) + 1 (separator).
|
|
32
|
-
|
|
33
|
-
// TODO(burdon): Change to "DX".
|
|
34
|
-
const CUSTOM_FUNCTION = 'ECHO';
|
|
35
|
-
|
|
36
|
-
export type ComputeGraphPlugin = {
|
|
37
|
-
plugin: FunctionPluginDefinition;
|
|
38
|
-
translations: FunctionTranslationsPackage;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export type ComputeGraphOptions = {
|
|
42
|
-
plugins?: ComputeGraphPlugin[];
|
|
43
|
-
} & Partial<FunctionContextOptions> &
|
|
44
|
-
Partial<ConfigParams>;
|
|
45
|
-
|
|
46
|
-
export const defaultOptions: ComputeGraphOptions = {
|
|
47
|
-
licenseKey: 'gpl-v3',
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export const defaultPlugins: ComputeGraphPlugin[] = [
|
|
51
|
-
{
|
|
52
|
-
plugin: EdgeFunctionPlugin,
|
|
53
|
-
translations: EdgeFunctionPluginTranslations,
|
|
54
|
-
},
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Marker for sheets that are managed by an ECHO object.
|
|
59
|
-
*/
|
|
60
|
-
const PREFIX = '__';
|
|
61
|
-
export const createSheetName = (id: string) => `${PREFIX}${id}`;
|
|
62
|
-
export const getSheetId = (name: string): string | undefined =>
|
|
63
|
-
name.startsWith(PREFIX) ? name.slice(PREFIX.length) : undefined;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Manages a collection of ComputeGraph instances for each space.
|
|
67
|
-
*
|
|
68
|
-
* [ComputePlugin] => [ComputeGraphRegistry] => [ComputeGraph(Space)] => [ComputeNode(Object)]
|
|
69
|
-
*
|
|
70
|
-
* NOTE: The ComputeGraphRegistry manages the hierarchy of resources via its root Context.
|
|
71
|
-
*/
|
|
72
|
-
// TODO(burdon): Move graph into separate plugin; isolate HF deps.
|
|
73
|
-
export class ComputeGraphRegistry extends Resource {
|
|
74
|
-
private readonly _graphs = new Map<SpaceId, ComputeGraph>();
|
|
75
|
-
|
|
76
|
-
private readonly _options: ComputeGraphOptions;
|
|
77
|
-
|
|
78
|
-
constructor(options: ComputeGraphOptions = { plugins: defaultPlugins }) {
|
|
79
|
-
super();
|
|
80
|
-
this._options = defaultsDeep({}, options, defaultOptions);
|
|
81
|
-
this._options.plugins?.forEach(({ plugin, translations }) => {
|
|
82
|
-
HyperFormula.registerFunctionPlugin(plugin, translations);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
getGraph(spaceId: SpaceId): ComputeGraph | undefined {
|
|
87
|
-
return this._graphs.get(spaceId);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async getOrCreateGraph(space: Space): Promise<ComputeGraph> {
|
|
91
|
-
let graph = this.getGraph(space.id);
|
|
92
|
-
if (!graph) {
|
|
93
|
-
log.info('create graph', { space: space.id });
|
|
94
|
-
graph = await this.createGraph(space);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
return graph;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async createGraph(space: Space): Promise<ComputeGraph> {
|
|
101
|
-
invariant(!this._graphs.has(space.id), `ComputeGraph already exists for space: ${space.id}`);
|
|
102
|
-
const hf = HyperFormula.buildEmpty(this._options);
|
|
103
|
-
const graph = new ComputeGraph(hf, space, this._options);
|
|
104
|
-
this._graphs.set(space.id, graph);
|
|
105
|
-
await graph.open();
|
|
106
|
-
return graph;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
protected override async _close() {
|
|
110
|
-
for (const graph of this._graphs.values()) {
|
|
111
|
-
await graph.close();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export type ComputeGraphEvent = 'functionsUpdated';
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Per-space compute and dependency graph.
|
|
120
|
-
* Consists of multiple ComputeNode (corresponding to a HyperFormula sheet).
|
|
121
|
-
* Manages the set of custom functions.
|
|
122
|
-
* HyperFormula manages the dependency graph.
|
|
123
|
-
*/
|
|
124
|
-
export class ComputeGraph extends Resource {
|
|
125
|
-
public readonly id = `graph-${PublicKey.random().truncate()}`;
|
|
126
|
-
|
|
127
|
-
// Map of nodes indexed by sheet number.
|
|
128
|
-
private readonly _nodes = new Map<number, ComputeNode>();
|
|
129
|
-
|
|
130
|
-
// Cached function objects.
|
|
131
|
-
private _functions: FunctionType[] = [];
|
|
132
|
-
|
|
133
|
-
public readonly update = new Event<{ type: ComputeGraphEvent }>();
|
|
134
|
-
|
|
135
|
-
// The context is passed to all functions.
|
|
136
|
-
public readonly context = new FunctionContext(this._hf, this._space, this._options);
|
|
137
|
-
|
|
138
|
-
constructor(
|
|
139
|
-
private readonly _hf: HyperFormula,
|
|
140
|
-
private readonly _space?: Space,
|
|
141
|
-
private readonly _options?: Partial<FunctionContextOptions>,
|
|
142
|
-
) {
|
|
143
|
-
super();
|
|
144
|
-
this._hf.updateConfig({ context: this.context });
|
|
145
|
-
// TODO(burdon): If debounce then aggregate changes.
|
|
146
|
-
const onValuesUpdate: Listeners['valuesUpdated'] = (changes) => {
|
|
147
|
-
for (const change of changes) {
|
|
148
|
-
if (change instanceof ExportedCellChange) {
|
|
149
|
-
const { sheet } = change;
|
|
150
|
-
const node = this._nodes.get(sheet);
|
|
151
|
-
if (node) {
|
|
152
|
-
node.update.emit({ type: 'valuesUpdated', change });
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
this._hf.on('valuesUpdated', onValuesUpdate);
|
|
159
|
-
this._ctx.onDispose(() => this._hf.off('valuesUpdated', onValuesUpdate));
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
get hf() {
|
|
163
|
-
return this._hf;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// refresh() {
|
|
167
|
-
// log('refresh', { id: this.id });
|
|
168
|
-
// this.update.emit();
|
|
169
|
-
// }
|
|
170
|
-
|
|
171
|
-
getFunctions(
|
|
172
|
-
{ standard, echo }: { standard?: boolean; echo?: boolean } = { standard: true, echo: true },
|
|
173
|
-
): FunctionDefinition[] {
|
|
174
|
-
return [
|
|
175
|
-
...(standard
|
|
176
|
-
? this._hf
|
|
177
|
-
.getRegisteredFunctionNames()
|
|
178
|
-
.map((name) => defaultFunctions.find((fn) => fn.name === name) ?? { name })
|
|
179
|
-
: []),
|
|
180
|
-
...(echo ? this._functions.map((fn) => ({ name: fn.binding! })) : []),
|
|
181
|
-
];
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Get or create cell representing a sheet.
|
|
186
|
-
*/
|
|
187
|
-
// TODO(burdon): Async (open node).
|
|
188
|
-
// The graph should be an extensible factory that plugins extend with model constructors.
|
|
189
|
-
// This would enable on-the-fly instantiation of new models when then are referenced.
|
|
190
|
-
// E.g., Cross-object reference would be stored as "ObjectId!A1"
|
|
191
|
-
// The graph would then load the object and create a ComputeNode (model) of the appropriate type.
|
|
192
|
-
async getOrCreateNode(name: string): Promise<ComputeNode> {
|
|
193
|
-
invariant(name.length);
|
|
194
|
-
if (!this._hf.doesSheetExist(name)) {
|
|
195
|
-
log.info('created node', { space: this._space?.id, name });
|
|
196
|
-
this._hf.addSheet(name);
|
|
197
|
-
// this.update.emit();
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const sheetId = this._hf.getSheetId(name);
|
|
201
|
-
invariant(sheetId !== undefined);
|
|
202
|
-
|
|
203
|
-
const node = new ComputeNode(this, sheetId);
|
|
204
|
-
await node.open();
|
|
205
|
-
this._nodes.set(sheetId, node);
|
|
206
|
-
return node;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
/**
|
|
210
|
-
* Map bound value to custom function invocation.
|
|
211
|
-
* E.g., "HELLO(...args)" => "EDGE("HELLO", ...args)".
|
|
212
|
-
*/
|
|
213
|
-
mapFormulaToNative(formula: string): string {
|
|
214
|
-
return (
|
|
215
|
-
formula
|
|
216
|
-
// Sheet references.
|
|
217
|
-
// https://hyperformula.handsontable.com/guide/cell-references.html#cell-references
|
|
218
|
-
.replace(/['"]?([ \w]+)['"]?!/, (_match, name) => {
|
|
219
|
-
if (name) {
|
|
220
|
-
// TODO(burdon): What if not loaded?
|
|
221
|
-
const objects = this._hf
|
|
222
|
-
.getSheetNames()
|
|
223
|
-
.map((name) => {
|
|
224
|
-
const id = getSheetId(name);
|
|
225
|
-
return id ? this._space?.db.getObjectById(id) : undefined;
|
|
226
|
-
})
|
|
227
|
-
.filter(nonNullable);
|
|
228
|
-
|
|
229
|
-
for (const obj of objects) {
|
|
230
|
-
if (obj.name === name || obj.title === name) {
|
|
231
|
-
return `${createSheetName(obj.id)}!`;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
return `${name}!`;
|
|
237
|
-
})
|
|
238
|
-
|
|
239
|
-
// Functions.
|
|
240
|
-
.replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
|
|
241
|
-
const fn = this._functions.find((fn) => fn.binding === binding);
|
|
242
|
-
if (!fn) {
|
|
243
|
-
return match;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (args.trim() === '') {
|
|
247
|
-
return `${CUSTOM_FUNCTION}("${binding}")`;
|
|
248
|
-
} else {
|
|
249
|
-
return `${CUSTOM_FUNCTION}("${binding}", ${args})`;
|
|
250
|
-
}
|
|
251
|
-
})
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Map from binding to fully qualified ECHO ID (to store).
|
|
257
|
-
* E.g., HELLO() => spaceId:objectId()
|
|
258
|
-
*/
|
|
259
|
-
mapFunctionBindingToId(formula: string) {
|
|
260
|
-
return formula.replace(/(\w+)\((.*)\)/g, (match, binding, args) => {
|
|
261
|
-
if (binding === CUSTOM_FUNCTION || defaultFunctions.find((fn) => fn.name === binding)) {
|
|
262
|
-
return match;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const fn = this._functions.find((fn) => fn.binding === binding);
|
|
266
|
-
if (fn) {
|
|
267
|
-
const id = fullyQualifiedId(fn);
|
|
268
|
-
return `${id}(${args})`;
|
|
269
|
-
} else {
|
|
270
|
-
return match;
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Map from fully qualified ECHO ID to binding (from store).
|
|
277
|
-
* E.g., spaceId:objectId() => HELLO()
|
|
278
|
-
*/
|
|
279
|
-
mapFunctionBindingFromId(formula: string) {
|
|
280
|
-
return formula.replace(/(\w+):([a-zA-Z0-9]+)\((.*)\)/g, (match, spaceId, objectId, args) => {
|
|
281
|
-
const id = `${spaceId}:${objectId}`;
|
|
282
|
-
if (id.length !== OBJECT_ID_LENGTH) {
|
|
283
|
-
return match;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const fn = this._functions.find((fn) => fullyQualifiedId(fn) === id);
|
|
287
|
-
if (fn?.binding) {
|
|
288
|
-
return `${fn.binding}(${args})`;
|
|
289
|
-
} else {
|
|
290
|
-
return match;
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
protected override async _open() {
|
|
296
|
-
if (this._space) {
|
|
297
|
-
// Subscribe to remote function definitions.
|
|
298
|
-
const query = this._space.db.query(Filter.schema(FunctionType));
|
|
299
|
-
const unsubscribe = query.subscribe(({ objects }) => {
|
|
300
|
-
this._functions = objects.filter(({ binding }) => binding);
|
|
301
|
-
this.update.emit({ type: 'functionsUpdated' });
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
this._ctx.onDispose(unsubscribe);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
protected override async _close() {
|
|
309
|
-
for (const node of this._nodes.values()) {
|
|
310
|
-
await node.close();
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Listeners } from 'hyperformula/typings/Emitter';
|
|
6
|
-
import { type ExportedCellChange } from 'hyperformula/typings/Exporter';
|
|
7
|
-
|
|
8
|
-
import { Event } from '@dxos/async';
|
|
9
|
-
import { Resource } from '@dxos/context';
|
|
10
|
-
|
|
11
|
-
import { DetailedCellError } from '#hyperformula';
|
|
12
|
-
import { type ComputeGraph } from './compute-graph';
|
|
13
|
-
import { type CellAddress } from '../defs';
|
|
14
|
-
import { type CellScalarValue } from '../types';
|
|
15
|
-
|
|
16
|
-
export type ComputeNodeEvent = {
|
|
17
|
-
type: keyof Listeners;
|
|
18
|
-
change?: ExportedCellChange;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Individual "sheet" (typically corresponds to an ECHO object).
|
|
23
|
-
*/
|
|
24
|
-
// TODO(burdon): Factor out common HF wrapper from from SheetModel.
|
|
25
|
-
export class ComputeNode extends Resource {
|
|
26
|
-
public readonly update = new Event<ComputeNodeEvent>();
|
|
27
|
-
|
|
28
|
-
constructor(
|
|
29
|
-
private readonly _graph: ComputeGraph,
|
|
30
|
-
public readonly sheetId: number,
|
|
31
|
-
) {
|
|
32
|
-
super();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get graph() {
|
|
36
|
-
return this._graph;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
clear() {
|
|
40
|
-
this._graph.hf.clearSheet(this.sheetId);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
getValue(cell: CellAddress): CellScalarValue {
|
|
44
|
-
const value = this._graph.hf.getCellValue({ sheet: this.sheetId, row: cell.row, col: cell.col });
|
|
45
|
-
if (value instanceof DetailedCellError) {
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return value;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
setValue(cell: CellAddress, value: CellScalarValue) {
|
|
53
|
-
const mappedValue =
|
|
54
|
-
typeof value === 'string' && value.charAt(0) === '=' ? this._graph.mapFormulaToNative(value) : value;
|
|
55
|
-
this._graph.hf.setCellContents({ sheet: this.sheetId, row: cell.row, col: cell.col }, [[mappedValue]]);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
protected override async _open() {
|
|
59
|
-
// const unsubscribe = this._graph.update.on(this.update.emit);
|
|
60
|
-
// this._ctx.onDispose(unsubscribe);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { describe, test, expect } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import { HyperFormula } from '#hyperformula';
|
|
8
|
-
|
|
9
|
-
describe('hyperformula', () => {
|
|
10
|
-
test('sanity', async () => {
|
|
11
|
-
// TODO(burdon): Throws "Cannot convert undefined or null to object" in vitest (without browser).
|
|
12
|
-
const hf = HyperFormula.buildEmpty({ licenseKey: 'gpl-v3' });
|
|
13
|
-
expect(hf).to.exist;
|
|
14
|
-
});
|
|
15
|
-
});
|
package/src/graph/index.ts
DELETED
package/src/graph/util.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import '@dxos-theme';
|
|
6
|
-
|
|
7
|
-
import React, { useEffect, useState } from 'react';
|
|
8
|
-
|
|
9
|
-
import { useSpace } from '@dxos/react-client/echo';
|
|
10
|
-
import { withClientProvider } from '@dxos/react-client/testing';
|
|
11
|
-
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
12
|
-
import { withTheme } from '@dxos/storybook-utils';
|
|
13
|
-
|
|
14
|
-
import { ComputeGraphContextProvider } from '../components';
|
|
15
|
-
import { createSheet } from '../defs';
|
|
16
|
-
import { useComputeGraph, useSheetModel } from '../hooks';
|
|
17
|
-
import { withComputeGraphDecorator } from '../testing';
|
|
18
|
-
import { SheetType } from '../types';
|
|
19
|
-
|
|
20
|
-
const Story = () => {
|
|
21
|
-
const space = useSpace();
|
|
22
|
-
const graph = useComputeGraph(space);
|
|
23
|
-
const [sheet, setSheet] = useState<SheetType>();
|
|
24
|
-
const model = useSheetModel(graph, sheet);
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
if (space) {
|
|
27
|
-
const sheet = space.db.add(createSheet());
|
|
28
|
-
setSheet(sheet);
|
|
29
|
-
}
|
|
30
|
-
}, [space]);
|
|
31
|
-
|
|
32
|
-
return (
|
|
33
|
-
<SyntaxHighlighter language='json'>
|
|
34
|
-
{JSON.stringify({ space: space?.id, graph: graph?.id, sheet: sheet?.id, model: model?.id }, null, 2)}
|
|
35
|
-
</SyntaxHighlighter>
|
|
36
|
-
);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export default {
|
|
40
|
-
title: 'plugin-sheet/hooks',
|
|
41
|
-
component: ComputeGraphContextProvider,
|
|
42
|
-
decorators: [
|
|
43
|
-
withClientProvider({ types: [SheetType], createIdentity: true, createSpace: true }),
|
|
44
|
-
withComputeGraphDecorator(),
|
|
45
|
-
withTheme,
|
|
46
|
-
],
|
|
47
|
-
render: (args: any) => <Story {...args} />,
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
export const Default = {};
|
package/src/hooks/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { useContext } from 'react';
|
|
6
|
-
|
|
7
|
-
import { raise } from '@dxos/debug';
|
|
8
|
-
import { type Space } from '@dxos/react-client/echo';
|
|
9
|
-
import { useAsyncState } from '@dxos/react-hooks';
|
|
10
|
-
|
|
11
|
-
import { ComputeGraphContext } from '../components';
|
|
12
|
-
import { type ComputeGraph } from '../graph';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Get existing or create new compute graph for the given space.
|
|
16
|
-
*/
|
|
17
|
-
export const useComputeGraph = (space?: Space): ComputeGraph | undefined => {
|
|
18
|
-
const { registry } = useContext(ComputeGraphContext) ?? raise(new Error('Missing ComputeGraphContext'));
|
|
19
|
-
const [graph] = useAsyncState(async () => space && registry.getOrCreateGraph(space), [space, registry]);
|
|
20
|
-
return graph;
|
|
21
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { useMemo } from 'react';
|
|
6
|
-
|
|
7
|
-
import { type SheetModel, FormattingModel } from '../model';
|
|
8
|
-
|
|
9
|
-
export const useFormattingModel = (model: SheetModel | undefined): FormattingModel | undefined => {
|
|
10
|
-
return useMemo(() => model && new FormattingModel(model), [model]);
|
|
11
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { useEffect, useState } from 'react';
|
|
6
|
-
|
|
7
|
-
import { type ComputeGraph } from '../graph';
|
|
8
|
-
import { SheetModel } from '../model';
|
|
9
|
-
import { type SheetType } from '../types';
|
|
10
|
-
|
|
11
|
-
export type UseSheetModelOptions = {
|
|
12
|
-
readonly?: boolean;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
export const useSheetModel = (
|
|
16
|
-
graph?: ComputeGraph,
|
|
17
|
-
sheet?: SheetType,
|
|
18
|
-
{ readonly }: UseSheetModelOptions = {},
|
|
19
|
-
): SheetModel | undefined => {
|
|
20
|
-
const [model, setModel] = useState<SheetModel>();
|
|
21
|
-
useEffect(() => {
|
|
22
|
-
if (!graph || !sheet) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
let model: SheetModel | undefined;
|
|
27
|
-
const t = setTimeout(async () => {
|
|
28
|
-
model = new SheetModel(graph, sheet, { readonly });
|
|
29
|
-
await model.open();
|
|
30
|
-
setModel(model);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
return () => {
|
|
34
|
-
clearTimeout(t);
|
|
35
|
-
void model?.close();
|
|
36
|
-
};
|
|
37
|
-
}, [graph, sheet, readonly]);
|
|
38
|
-
|
|
39
|
-
return model;
|
|
40
|
-
};
|