@dxos/plugin-sheet 0.6.11 → 0.6.12-main.568932b
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-T2QWJOFD.mjs +262 -0
- package/dist/lib/browser/SheetContainer-T2QWJOFD.mjs.map +7 -0
- package/dist/lib/browser/{chunk-FUAGSXA4.mjs → chunk-5ZMVZYGB.mjs} +24 -19
- package/dist/lib/browser/chunk-5ZMVZYGB.mjs.map +7 -0
- package/dist/lib/browser/chunk-GSV5QNLD.mjs +2966 -0
- package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +7 -0
- package/dist/lib/browser/{chunk-JRL5LGCE.mjs → chunk-QILRZNE5.mjs} +2 -5
- package/dist/lib/browser/chunk-QILRZNE5.mjs.map +7 -0
- package/dist/lib/browser/{SheetContainer-U4H5D34A.mjs → chunk-ZL2V5UJR.mjs} +1182 -249
- package/dist/lib/browser/chunk-ZL2V5UJR.mjs.map +7 -0
- package/dist/lib/browser/graph-M4IQ76QX.mjs +33 -0
- package/dist/lib/browser/graph-M4IQ76QX.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +96 -60
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/meta.mjs +1 -1
- package/dist/lib/browser/types.mjs +4 -6
- package/dist/lib/node/SheetContainer-PV5ET4UJ.cjs +280 -0
- package/dist/lib/node/SheetContainer-PV5ET4UJ.cjs.map +7 -0
- package/dist/lib/node/{SheetContainer-AXQV3ZT5.cjs → chunk-2K53Z2TU.cjs} +1212 -287
- package/dist/lib/node/chunk-2K53Z2TU.cjs.map +7 -0
- package/dist/lib/node/{chunk-5KKJ4NPP.cjs → chunk-5XPK2V4A.cjs} +418 -678
- package/dist/lib/node/chunk-5XPK2V4A.cjs.map +7 -0
- package/dist/lib/node/{chunk-BJ6ZD7MN.cjs → chunk-BNARJ5GM.cjs} +5 -18
- package/dist/lib/node/chunk-BNARJ5GM.cjs.map +7 -0
- package/dist/lib/node/{chunk-DSYKOI4E.cjs → chunk-STAVQ2JE.cjs} +28 -24
- package/dist/lib/node/chunk-STAVQ2JE.cjs.map +7 -0
- package/dist/lib/node/graph-Q3N2X26H.cjs +55 -0
- package/dist/lib/node/graph-Q3N2X26H.cjs.map +7 -0
- package/dist/lib/node/index.cjs +106 -66
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.cjs +3 -3
- package/dist/lib/node/meta.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types.cjs +10 -12
- package/dist/lib/node/types.cjs.map +2 -2
- package/dist/lib/node-esm/SheetContainer-FOZD2WLT.mjs +263 -0
- package/dist/lib/node-esm/SheetContainer-FOZD2WLT.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-2HAM45RC.mjs +88 -0
- package/dist/lib/node-esm/chunk-2HAM45RC.mjs.map +7 -0
- package/dist/lib/{browser/chunk-D5AGLXJP.mjs → node-esm/chunk-5WPZCXNS.mjs} +411 -678
- package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-IU2L277A.mjs +17 -0
- package/dist/lib/node-esm/chunk-IU2L277A.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-QEUCIHIN.mjs +2706 -0
- package/dist/lib/node-esm/chunk-QEUCIHIN.mjs.map +7 -0
- package/dist/lib/node-esm/graph-SMPUMOV2.mjs +34 -0
- package/dist/lib/node-esm/graph-SMPUMOV2.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +285 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/meta.mjs +10 -0
- package/dist/lib/node-esm/meta.mjs.map +7 -0
- package/dist/lib/node-esm/types.mjs +21 -0
- package/dist/lib/node-esm/types.mjs.map +7 -0
- package/dist/types/src/SheetPlugin.d.ts.map +1 -1
- package/dist/types/src/components/CellEditor/CellEditor.d.ts +23 -3
- 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/components/ComputeGraph/ComputeGraphContextProvider.d.ts +11 -0
- package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/index.d.ts +1 -3
- package/dist/types/src/components/ComputeGraph/index.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/GridSheet.d.ts +10 -0
- package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -0
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +9 -0
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -0
- package/dist/types/src/components/GridSheet/util.d.ts +16 -0
- package/dist/types/src/components/GridSheet/util.d.ts.map +1 -0
- 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 +5 -6
- package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -1
- package/dist/types/src/components/Sheet/decorations.d.ts +24 -0
- package/dist/types/src/components/Sheet/decorations.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 +8 -7
- package/dist/types/src/components/Sheet/sheet-context.d.ts.map +1 -1
- package/dist/types/src/components/Sheet/threads.d.ts +2 -0
- package/dist/types/src/components/Sheet/threads.d.ts.map +1 -0
- package/dist/types/src/components/SheetContainer.d.ts +2 -3
- package/dist/types/src/components/SheetContainer.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +19 -3
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +18 -13
- 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/defs/index.d.ts +3 -0
- package/dist/types/src/defs/index.d.ts.map +1 -0
- package/dist/types/src/{model → defs}/types.d.ts +8 -3
- package/dist/types/src/defs/types.d.ts.map +1 -0
- package/dist/types/src/defs/types.test.d.ts.map +1 -0
- package/dist/types/src/defs/util.d.ts +43 -0
- package/dist/types/src/defs/util.d.ts.map +1 -0
- package/dist/types/src/extensions/compute.d.ts +6 -0
- package/dist/types/src/extensions/compute.d.ts.map +1 -0
- package/dist/types/src/extensions/compute.stories.d.ts +26 -0
- package/dist/types/src/extensions/compute.stories.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +2 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -0
- package/dist/types/src/graph/compute-graph-registry.d.ts +34 -0
- package/dist/types/src/graph/compute-graph-registry.d.ts.map +1 -0
- package/dist/types/src/graph/compute-graph.d.ts +64 -0
- package/dist/types/src/graph/compute-graph.d.ts.map +1 -0
- package/dist/types/src/graph/compute-graph.stories.d.ts +10 -0
- package/dist/types/src/graph/compute-graph.stories.d.ts.map +1 -0
- package/dist/types/src/graph/compute-graph.test.d.ts +2 -0
- package/dist/types/src/graph/compute-graph.test.d.ts.map +1 -0
- package/dist/types/src/graph/compute-node.d.ts +26 -0
- package/dist/types/src/graph/compute-node.d.ts.map +1 -0
- package/dist/types/src/{components/ComputeGraph → graph/functions}/async-function.d.ts +14 -5
- package/dist/types/src/graph/functions/async-function.d.ts.map +1 -0
- package/dist/types/src/graph/functions/edge-function.d.ts +21 -0
- package/dist/types/src/graph/functions/edge-function.d.ts.map +1 -0
- package/dist/types/src/{model/functions.d.ts → graph/functions/function-defs.d.ts} +1 -1
- package/dist/types/src/graph/functions/function-defs.d.ts.map +1 -0
- package/dist/types/src/graph/functions/index.d.ts +4 -0
- package/dist/types/src/graph/functions/index.d.ts.map +1 -0
- package/dist/types/src/graph/hyperformula.test.d.ts +2 -0
- package/dist/types/src/graph/hyperformula.test.d.ts.map +1 -0
- package/dist/types/src/graph/index.d.ts +5 -0
- package/dist/types/src/graph/index.d.ts.map +1 -0
- package/dist/types/src/graph/testing/index.d.ts +3 -0
- package/dist/types/src/graph/testing/index.d.ts.map +1 -0
- package/dist/types/src/graph/testing/test-builder.d.ts +15 -0
- package/dist/types/src/graph/testing/test-builder.d.ts.map +1 -0
- package/dist/types/src/graph/testing/test-plugin.d.ts +36 -0
- package/dist/types/src/graph/testing/test-plugin.d.ts.map +1 -0
- package/dist/types/src/graph/util.d.ts +2 -0
- package/dist/types/src/graph/util.d.ts.map +1 -0
- package/dist/types/src/hooks/hooks.stories.d.ts +11 -0
- package/dist/types/src/hooks/hooks.stories.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +4 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -0
- package/dist/types/src/hooks/useComputeGraph.d.ts +7 -0
- package/dist/types/src/hooks/useComputeGraph.d.ts.map +1 -0
- package/dist/types/src/hooks/useFormattingModel.d.ts +3 -0
- package/dist/types/src/hooks/useFormattingModel.d.ts.map +1 -0
- package/dist/types/src/hooks/useSheetModel.d.ts +8 -0
- package/dist/types/src/hooks/useSheetModel.d.ts.map +1 -0
- package/dist/types/src/meta.d.ts +1 -4
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/model/formatting-model.d.ts +16 -0
- package/dist/types/src/model/formatting-model.d.ts.map +1 -0
- package/dist/types/src/model/index.d.ts +2 -3
- package/dist/types/src/model/index.d.ts.map +1 -1
- package/dist/types/src/model/{model.d.ts → sheet-model.d.ts} +10 -65
- package/dist/types/src/model/sheet-model.d.ts.map +1 -0
- package/dist/types/src/model/sheet-model.test.d.ts +2 -0
- package/dist/types/src/model/sheet-model.test.d.ts.map +1 -0
- package/dist/types/src/sanity.test.d.ts +2 -0
- package/dist/types/src/sanity.test.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +2 -0
- package/dist/types/src/testing/index.d.ts.map +1 -0
- package/dist/types/src/testing/testing.d.ts +8 -0
- package/dist/types/src/testing/testing.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +17 -12
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +86 -5
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/vendor/hyperformula.mjs +37145 -0
- package/package.json +55 -47
- package/src/SheetPlugin.tsx +50 -73
- package/src/components/CellEditor/CellEditor.stories.tsx +6 -6
- package/src/components/CellEditor/CellEditor.tsx +59 -9
- package/src/components/CellEditor/extension.test.ts +4 -6
- package/src/components/CellEditor/extension.ts +5 -6
- package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +20 -0
- package/src/components/ComputeGraph/index.ts +1 -3
- package/src/components/GridSheet/GridSheet.stories.tsx +36 -0
- package/src/components/GridSheet/GridSheet.tsx +171 -0
- package/src/components/GridSheet/util.ts +148 -0
- package/src/components/Sheet/Sheet.stories.tsx +52 -88
- package/src/components/Sheet/Sheet.tsx +87 -32
- package/src/components/Sheet/decorations.ts +62 -0
- package/src/components/Sheet/grid.ts +3 -3
- package/src/components/Sheet/nav.ts +19 -19
- package/src/components/Sheet/sheet-context.tsx +18 -80
- package/src/components/Sheet/threads.tsx +205 -0
- package/src/components/SheetContainer.tsx +68 -16
- package/src/components/Toolbar/Toolbar.tsx +53 -12
- package/src/components/index.ts +1 -0
- package/src/defs/index.ts +6 -0
- package/src/{model → defs}/types.test.ts +8 -9
- package/src/{model → defs}/types.ts +24 -14
- package/src/defs/util.ts +151 -0
- package/src/extensions/compute.stories.tsx +151 -0
- package/src/extensions/compute.ts +147 -0
- package/src/extensions/index.ts +5 -0
- package/src/graph/compute-graph-registry.ts +90 -0
- package/src/graph/compute-graph.stories.tsx +93 -0
- package/src/graph/compute-graph.test.ts +87 -0
- package/src/graph/compute-graph.ts +242 -0
- package/src/graph/compute-node.ts +63 -0
- package/src/{components/ComputeGraph → graph/functions}/async-function.ts +25 -15
- package/src/{components/ComputeGraph → graph/functions}/edge-function.ts +16 -14
- package/src/graph/functions/index.ts +7 -0
- package/src/graph/hyperformula.test.ts +14 -0
- package/src/graph/index.ts +8 -0
- package/src/graph/testing/index.ts +6 -0
- package/src/graph/testing/test-builder.ts +54 -0
- package/src/{components/ComputeGraph/custom.ts → graph/testing/test-plugin.ts} +44 -14
- package/src/graph/util.ts +8 -0
- package/src/hooks/hooks.stories.tsx +50 -0
- package/src/hooks/index.ts +7 -0
- package/src/hooks/useComputeGraph.ts +28 -0
- package/src/hooks/useFormattingModel.ts +11 -0
- package/src/hooks/useSheetModel.ts +40 -0
- package/src/meta.tsx +1 -5
- package/src/{components/Sheet/formatting.ts → model/formatting-model.ts} +20 -13
- package/src/model/index.ts +2 -3
- package/src/model/sheet-model.test.ts +57 -0
- package/src/model/sheet-model.ts +416 -0
- package/src/sanity.test.ts +40 -0
- package/src/testing/index.ts +5 -0
- package/src/testing/testing.tsx +68 -0
- package/src/translations.ts +6 -1
- package/src/types.ts +35 -10
- package/dist/lib/browser/SheetContainer-U4H5D34A.mjs.map +0 -7
- package/dist/lib/browser/chunk-APHOLYUB.mjs +0 -175
- package/dist/lib/browser/chunk-APHOLYUB.mjs.map +0 -7
- package/dist/lib/browser/chunk-D5AGLXJP.mjs.map +0 -7
- package/dist/lib/browser/chunk-FUAGSXA4.mjs.map +0 -7
- package/dist/lib/browser/chunk-JRL5LGCE.mjs.map +0 -7
- package/dist/lib/browser/chunk-NU4PBN33.mjs +0 -8
- package/dist/lib/browser/chunk-NU4PBN33.mjs.map +0 -7
- package/dist/lib/browser/testing.mjs +0 -92
- package/dist/lib/browser/testing.mjs.map +0 -7
- package/dist/lib/node/SheetContainer-AXQV3ZT5.cjs.map +0 -7
- package/dist/lib/node/chunk-5KKJ4NPP.cjs.map +0 -7
- package/dist/lib/node/chunk-BJ6ZD7MN.cjs.map +0 -7
- package/dist/lib/node/chunk-CN3RPESU.cjs +0 -202
- package/dist/lib/node/chunk-CN3RPESU.cjs.map +0 -7
- package/dist/lib/node/chunk-DSYKOI4E.cjs.map +0 -7
- package/dist/lib/node/chunk-PYXHNAAK.cjs +0 -40
- package/dist/lib/node/chunk-PYXHNAAK.cjs.map +0 -7
- package/dist/lib/node/testing.cjs +0 -111
- package/dist/lib/node/testing.cjs.map +0 -7
- package/dist/types/src/components/ComputeGraph/async-function.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/custom.d.ts +0 -21
- package/dist/types/src/components/ComputeGraph/custom.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/edge-function.d.ts +0 -20
- package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/graph-context.d.ts +0 -12
- package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts +0 -2
- package/dist/types/src/components/ComputeGraph/graph.browser.test.d.ts.map +0 -1
- package/dist/types/src/components/ComputeGraph/graph.d.ts +0 -26
- package/dist/types/src/components/ComputeGraph/graph.d.ts.map +0 -1
- package/dist/types/src/components/Sheet/formatting.d.ts +0 -14
- package/dist/types/src/components/Sheet/formatting.d.ts.map +0 -1
- package/dist/types/src/model/functions.d.ts.map +0 -1
- package/dist/types/src/model/model.browser.test.d.ts +0 -2
- package/dist/types/src/model/model.browser.test.d.ts.map +0 -1
- package/dist/types/src/model/model.d.ts.map +0 -1
- package/dist/types/src/model/types.d.ts.map +0 -1
- package/dist/types/src/model/types.test.d.ts.map +0 -1
- package/dist/types/src/model/util.d.ts +0 -15
- package/dist/types/src/model/util.d.ts.map +0 -1
- package/dist/types/src/testing.d.ts +0 -9
- package/dist/types/src/testing.d.ts.map +0 -1
- package/src/components/ComputeGraph/graph-context.tsx +0 -50
- package/src/components/ComputeGraph/graph.browser.test.ts +0 -50
- package/src/components/ComputeGraph/graph.ts +0 -62
- package/src/model/model.browser.test.ts +0 -100
- package/src/model/model.ts +0 -550
- package/src/model/util.ts +0 -36
- package/src/testing.ts +0 -50
- /package/dist/types/src/{model → defs}/types.test.d.ts +0 -0
- /package/src/{model/functions.ts → graph/functions/function-defs.ts} +0 -0
|
@@ -2,24 +2,36 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { FunctionArgumentType } from 'hyperformula';
|
|
6
5
|
import { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';
|
|
7
6
|
import { type ProcedureAst } from 'hyperformula/typings/parser';
|
|
8
7
|
|
|
9
8
|
import { getDeep } from '@dxos/util';
|
|
10
9
|
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return parseFloat(str.replace(/[^\d.]/g, ''));
|
|
16
|
-
};
|
|
10
|
+
import { FunctionArgumentType } from '#hyperformula';
|
|
11
|
+
import { type ComputeGraphPlugin } from '../compute-graph-registry';
|
|
12
|
+
import { type AsyncFunction, AsyncFunctionPlugin } from '../functions';
|
|
13
|
+
import { parseNumberString } from '../util';
|
|
17
14
|
|
|
18
15
|
/**
|
|
16
|
+
* Testing functions run locally (not run via EDGE).
|
|
19
17
|
* https://hyperformula.handsontable.com/guide/custom-functions.html#add-a-simple-custom-function
|
|
20
18
|
*/
|
|
21
|
-
export class
|
|
19
|
+
export class TestPlugin extends AsyncFunctionPlugin {
|
|
20
|
+
/**
|
|
21
|
+
* Simple local function returns input value.
|
|
22
|
+
*/
|
|
22
23
|
test(ast: ProcedureAst, state: InterpreterState) {
|
|
24
|
+
const handler: AsyncFunction = async (_value) => {
|
|
25
|
+
return _value;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return this.runAsyncFunction(ast, state, handler);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Simple local function returns random number.
|
|
33
|
+
*/
|
|
34
|
+
random(ast: ProcedureAst, state: InterpreterState) {
|
|
23
35
|
const handler: AsyncFunction = async () => {
|
|
24
36
|
return Math.random();
|
|
25
37
|
};
|
|
@@ -27,6 +39,9 @@ export class CustomPlugin extends FunctionPluginAsync {
|
|
|
27
39
|
return this.runAsyncFunction(ast, state, handler);
|
|
28
40
|
}
|
|
29
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Async HTTP function.
|
|
44
|
+
*/
|
|
30
45
|
crypto(ast: ProcedureAst, state: InterpreterState) {
|
|
31
46
|
const handler: AsyncFunction = async (_currency) => {
|
|
32
47
|
const currency = (_currency || 'USD').toUpperCase();
|
|
@@ -44,9 +59,15 @@ export class CustomPlugin extends FunctionPluginAsync {
|
|
|
44
59
|
}
|
|
45
60
|
}
|
|
46
61
|
|
|
47
|
-
|
|
62
|
+
TestPlugin.implementedFunctions = {
|
|
48
63
|
TEST: {
|
|
49
64
|
method: 'test',
|
|
65
|
+
parameters: [{ argumentType: FunctionArgumentType.NUMBER, optionalArg: false }],
|
|
66
|
+
isVolatile: true,
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
RANDOM: {
|
|
70
|
+
method: 'random',
|
|
50
71
|
parameters: [],
|
|
51
72
|
isVolatile: true,
|
|
52
73
|
},
|
|
@@ -58,13 +79,22 @@ CustomPlugin.implementedFunctions = {
|
|
|
58
79
|
},
|
|
59
80
|
};
|
|
60
81
|
|
|
61
|
-
export const
|
|
82
|
+
export const TestPluginTranslations = {
|
|
62
83
|
enGB: {
|
|
63
|
-
TEST: '
|
|
64
|
-
|
|
84
|
+
TEST: 'Returns input value',
|
|
85
|
+
RANDOM: 'Random number',
|
|
86
|
+
CRYPTO: 'Crypto token value',
|
|
65
87
|
},
|
|
66
88
|
enUS: {
|
|
67
|
-
TEST: '
|
|
68
|
-
|
|
89
|
+
TEST: 'Returns input value',
|
|
90
|
+
RANDOM: 'Random number',
|
|
91
|
+
CRYPTO: 'Crypto token value',
|
|
69
92
|
},
|
|
70
93
|
};
|
|
94
|
+
|
|
95
|
+
export const testFunctionPlugins: ComputeGraphPlugin[] = [
|
|
96
|
+
{
|
|
97
|
+
plugin: TestPlugin,
|
|
98
|
+
translations: TestPluginTranslations,
|
|
99
|
+
},
|
|
100
|
+
];
|
|
@@ -0,0 +1,50 @@
|
|
|
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 = {};
|
|
@@ -0,0 +1,28 @@
|
|
|
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 () => {
|
|
20
|
+
if (space) {
|
|
21
|
+
const graph = registry.getOrCreateGraph(space);
|
|
22
|
+
await graph.open();
|
|
23
|
+
return graph;
|
|
24
|
+
}
|
|
25
|
+
}, [space, registry]);
|
|
26
|
+
|
|
27
|
+
return graph;
|
|
28
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
};
|
package/src/meta.tsx
CHANGED
|
@@ -2,9 +2,6 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { GridNine, type IconProps } from '@phosphor-icons/react';
|
|
6
|
-
import React from 'react';
|
|
7
|
-
|
|
8
5
|
import { pluginMeta } from '@dxos/app-framework';
|
|
9
6
|
|
|
10
7
|
export const SHEET_PLUGIN = 'dxos.org/plugin/sheet';
|
|
@@ -13,6 +10,5 @@ export default pluginMeta({
|
|
|
13
10
|
id: SHEET_PLUGIN,
|
|
14
11
|
name: 'Sheet',
|
|
15
12
|
description: 'A simple spreadsheet plugin.',
|
|
16
|
-
|
|
17
|
-
iconSymbol: 'ph--grid-nine--regular',
|
|
13
|
+
icon: 'ph--grid-nine--regular',
|
|
18
14
|
});
|
|
@@ -4,17 +4,24 @@
|
|
|
4
4
|
|
|
5
5
|
import { type ClassNameValue } from '@dxos/react-ui-types';
|
|
6
6
|
|
|
7
|
-
import { type SheetModel
|
|
8
|
-
import {
|
|
7
|
+
import { type SheetModel } from './sheet-model';
|
|
8
|
+
import { type CellAddress, inRange } from '../defs';
|
|
9
|
+
import { addressToIndex, rangeFromIndex } from '../defs';
|
|
10
|
+
import { ValueTypeEnum } from '../types';
|
|
11
|
+
|
|
12
|
+
export type CellFormat = {
|
|
13
|
+
value?: string;
|
|
14
|
+
classNames?: ClassNameValue;
|
|
15
|
+
};
|
|
9
16
|
|
|
10
17
|
export class FormattingModel {
|
|
11
|
-
constructor(private readonly
|
|
18
|
+
constructor(private readonly _model: SheetModel) {}
|
|
12
19
|
|
|
13
20
|
/**
|
|
14
21
|
* Get formatted string value and className for cell.
|
|
15
22
|
*/
|
|
16
|
-
getFormatting(cell: CellAddress):
|
|
17
|
-
const value = this.
|
|
23
|
+
getFormatting(cell: CellAddress): CellFormat {
|
|
24
|
+
const value = this._model.getValue(cell);
|
|
18
25
|
if (value === undefined || value === null) {
|
|
19
26
|
return {};
|
|
20
27
|
}
|
|
@@ -23,15 +30,15 @@ export class FormattingModel {
|
|
|
23
30
|
const locales = undefined;
|
|
24
31
|
|
|
25
32
|
// Cell-specific formatting.
|
|
26
|
-
const idx = this.
|
|
27
|
-
let formatting = this.
|
|
33
|
+
const idx = addressToIndex(this._model.sheet, cell);
|
|
34
|
+
let formatting = this._model.sheet.formatting?.[idx] ?? {};
|
|
28
35
|
const classNames = [...(formatting?.classNames ?? [])];
|
|
29
36
|
|
|
30
37
|
// Range formatting.
|
|
31
38
|
// TODO(burdon): NOTE: D0 means the D column.
|
|
32
39
|
// TODO(burdon): Cache model formatting (e.g., for ranges). Create class out of this function.
|
|
33
|
-
for (const [idx, _formatting] of Object.entries(this.
|
|
34
|
-
const range = this.
|
|
40
|
+
for (const [idx, _formatting] of Object.entries(this._model.sheet.formatting)) {
|
|
41
|
+
const range = rangeFromIndex(this._model.sheet, idx);
|
|
35
42
|
if (inRange(range, cell)) {
|
|
36
43
|
if (_formatting.classNames) {
|
|
37
44
|
classNames.push(..._formatting.classNames);
|
|
@@ -46,7 +53,7 @@ export class FormattingModel {
|
|
|
46
53
|
|
|
47
54
|
const defaultNumber = 'justify-end font-mono';
|
|
48
55
|
|
|
49
|
-
const type = formatting?.type ?? this.
|
|
56
|
+
const type = formatting?.type ?? this._model.getValueType(cell);
|
|
50
57
|
switch (type) {
|
|
51
58
|
case ValueTypeEnum.Boolean: {
|
|
52
59
|
return {
|
|
@@ -84,17 +91,17 @@ export class FormattingModel {
|
|
|
84
91
|
//
|
|
85
92
|
|
|
86
93
|
case ValueTypeEnum.DateTime: {
|
|
87
|
-
const date = this.
|
|
94
|
+
const date = this._model.toLocalDate(value as number);
|
|
88
95
|
return { value: date.toLocaleString(locales), classNames };
|
|
89
96
|
}
|
|
90
97
|
|
|
91
98
|
case ValueTypeEnum.Date: {
|
|
92
|
-
const date = this.
|
|
99
|
+
const date = this._model.toLocalDate(value as number);
|
|
93
100
|
return { value: date.toLocaleDateString(locales), classNames };
|
|
94
101
|
}
|
|
95
102
|
|
|
96
103
|
case ValueTypeEnum.Time: {
|
|
97
|
-
const date = this.
|
|
104
|
+
const date = this._model.toLocalDate(value as number);
|
|
98
105
|
return { value: date.toLocaleTimeString(locales), classNames };
|
|
99
106
|
}
|
|
100
107
|
|
package/src/model/index.ts
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { Trigger } from '@dxos/async';
|
|
8
|
+
import { FunctionType } from '@dxos/plugin-script/types';
|
|
9
|
+
|
|
10
|
+
import { SheetModel } from './sheet-model';
|
|
11
|
+
import { addressFromA1Notation, createSheet } from '../defs';
|
|
12
|
+
import { TestBuilder, testFunctionPlugins } from '../graph/testing';
|
|
13
|
+
import { type CellScalarValue } from '../types';
|
|
14
|
+
|
|
15
|
+
describe('SheetModel', () => {
|
|
16
|
+
let testBuilder: TestBuilder;
|
|
17
|
+
beforeEach(async () => {
|
|
18
|
+
testBuilder = new TestBuilder({ types: [FunctionType], plugins: testFunctionPlugins });
|
|
19
|
+
await testBuilder.open();
|
|
20
|
+
});
|
|
21
|
+
afterEach(async () => {
|
|
22
|
+
await testBuilder.close();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test('async function', async () => {
|
|
26
|
+
const space = await testBuilder.client.spaces.create();
|
|
27
|
+
const graph = testBuilder.registry.createGraph(space);
|
|
28
|
+
await graph.open();
|
|
29
|
+
|
|
30
|
+
// TODO(burdon): Create via factory.
|
|
31
|
+
const sheet = createSheet({ rows: 5, columns: 5 });
|
|
32
|
+
const model = new SheetModel(graph, sheet);
|
|
33
|
+
await model.open();
|
|
34
|
+
testBuilder.ctx.onDispose(() => model.close());
|
|
35
|
+
|
|
36
|
+
// Trigger waits for function invocation.
|
|
37
|
+
const trigger = new Trigger<CellScalarValue>();
|
|
38
|
+
model.setValue(addressFromA1Notation('A1'), '=TEST(100)');
|
|
39
|
+
model.update.once((update) => {
|
|
40
|
+
const { type } = update;
|
|
41
|
+
if (type === 'valuesUpdated') {
|
|
42
|
+
const value = model.getValue(addressFromA1Notation('A1'));
|
|
43
|
+
trigger.wake(value);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Initial value will be null.
|
|
48
|
+
const v1 = model.getValue(addressFromA1Notation('A1'));
|
|
49
|
+
expect(v1).to.be.null;
|
|
50
|
+
expect(graph.context.info.invocations.TEST).not.to.exist;
|
|
51
|
+
|
|
52
|
+
// Wait until async update triggered.
|
|
53
|
+
const v2 = await trigger.wait();
|
|
54
|
+
expect(v2).to.eq(100);
|
|
55
|
+
expect(graph.context.info.invocations.TEST).to.eq(1);
|
|
56
|
+
});
|
|
57
|
+
});
|