@dxos/plugin-sheet 0.7.4 → 0.7.5-main.937ce75
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-KCLT6PEO.mjs → SheetContainer-S4NCLUYL.mjs} +16 -22
- package/dist/lib/browser/SheetContainer-S4NCLUYL.mjs.map +7 -0
- package/dist/lib/browser/{chunk-E5WQ7U7G.mjs → chunk-A374JPWV.mjs} +72 -705
- package/dist/lib/browser/chunk-A374JPWV.mjs.map +7 -0
- package/dist/lib/browser/chunk-Q4XS4YWF.mjs +900 -0
- package/dist/lib/browser/chunk-Q4XS4YWF.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +74 -180
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/types/index.mjs +62 -0
- package/dist/lib/node/{SheetContainer-VVVRYTQG.cjs → SheetContainer-TP4GYXZB.cjs} +41 -43
- package/dist/lib/node/SheetContainer-TP4GYXZB.cjs.map +7 -0
- package/dist/lib/node/{chunk-45YW2DX2.cjs → chunk-FDEQ2PGJ.cjs} +115 -726
- package/dist/lib/node/chunk-FDEQ2PGJ.cjs.map +7 -0
- package/dist/lib/node/chunk-TQOJ7DG2.cjs +935 -0
- package/dist/lib/node/chunk-TQOJ7DG2.cjs.map +7 -0
- package/dist/lib/node/index.cjs +104 -207
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types/index.cjs +84 -0
- package/dist/lib/node/types/index.cjs.map +7 -0
- package/dist/lib/node-esm/{SheetContainer-LSBE6Q4X.mjs → SheetContainer-YB3JBVPZ.mjs} +16 -22
- package/dist/lib/node-esm/SheetContainer-YB3JBVPZ.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-NYDNXI7L.mjs → chunk-L5PQHVTX.mjs} +72 -705
- package/dist/lib/node-esm/chunk-L5PQHVTX.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-NYYIDVR7.mjs +901 -0
- package/dist/lib/node-esm/chunk-NYYIDVR7.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +74 -180
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/types/index.mjs +63 -0
- package/dist/types/src/SheetPlugin.d.ts.map +1 -1
- package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +1 -1
- package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +1 -1
- package/dist/types/src/components/ComputeGraph/compute-graph.stories.d.ts.map +1 -0
- package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -1
- package/dist/types/src/components/SheetContext/SheetContext.d.ts +1 -2
- package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +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/editor/extension.d.ts +1 -1
- package/dist/types/src/extensions/editor/extension.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/integrations/thread-ranges.d.ts +1 -1
- package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -1
- package/dist/types/src/model/sheet-model.d.ts +6 -8
- package/dist/types/src/model/sheet-model.d.ts.map +1 -1
- package/dist/types/src/model/testing.d.ts +1 -1
- package/dist/types/src/model/testing.d.ts.map +1 -1
- package/dist/types/src/model/useSheetModel.d.ts +1 -1
- package/dist/types/src/model/useSheetModel.d.ts.map +1 -1
- package/dist/types/src/testing/testing.d.ts +2 -2
- package/dist/types/src/testing/testing.d.ts.map +1 -1
- package/dist/types/src/{defs → types}/index.d.ts +1 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/types/schema.d.ts +105 -0
- package/dist/types/src/types/schema.d.ts.map +1 -0
- package/dist/types/src/types/sheet-range-types.d.ts.map +1 -0
- package/dist/types/src/types/types.d.ts +82 -0
- package/dist/types/src/types/types.d.ts.map +1 -0
- package/dist/types/src/{defs → types}/util.d.ts +5 -1
- package/dist/types/src/types/util.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -0
- package/package.json +46 -53
- package/src/SheetPlugin.tsx +44 -115
- package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +1 -2
- package/src/{compute-graph → components/ComputeGraph}/compute-graph.stories.tsx +6 -7
- package/src/components/FunctionEditor/FunctionEditor.tsx +2 -1
- package/src/components/GridSheet/GridSheet.tsx +15 -18
- package/src/components/GridSheet/SheetCellEditor.stories.tsx +6 -7
- package/src/components/GridSheet/util.ts +3 -2
- package/src/components/RangeList/RangeList.tsx +2 -1
- package/src/components/SheetContainer/SheetContainer.stories.tsx +11 -12
- package/src/components/SheetContext/SheetContext.tsx +1 -2
- package/src/components/Toolbar/Toolbar.tsx +18 -20
- package/src/extensions/compute.ts +7 -4
- package/src/extensions/editor/extension.test.ts +2 -1
- package/src/extensions/editor/extension.ts +2 -3
- package/src/index.ts +1 -3
- package/src/integrations/thread-ranges.ts +28 -24
- package/src/model/sheet-model.test.ts +4 -10
- package/src/model/sheet-model.ts +30 -22
- package/src/model/testing.ts +3 -2
- package/src/model/useSheetModel.ts +2 -1
- package/src/sanity.test.ts +1 -1
- package/src/testing/testing.tsx +2 -3
- package/src/{defs → types}/index.ts +1 -0
- package/src/types/schema.ts +56 -0
- package/src/types/types.ts +93 -0
- package/src/{defs → types}/util.ts +13 -13
- package/dist/lib/browser/SheetContainer-KCLT6PEO.mjs.map +0 -7
- package/dist/lib/browser/chunk-E5WQ7U7G.mjs.map +0 -7
- package/dist/lib/browser/chunk-F3HE6D3J.mjs +0 -3269
- package/dist/lib/browser/chunk-F3HE6D3J.mjs.map +0 -7
- package/dist/lib/browser/chunk-JXFPOYNA.mjs +0 -67
- package/dist/lib/browser/chunk-JXFPOYNA.mjs.map +0 -7
- package/dist/lib/browser/compute-graph-SNUS7HOH.mjs +0 -35
- package/dist/lib/browser/types.mjs +0 -16
- package/dist/lib/node/SheetContainer-VVVRYTQG.cjs.map +0 -7
- package/dist/lib/node/chunk-45YW2DX2.cjs.map +0 -7
- package/dist/lib/node/chunk-KSEEI5VC.cjs +0 -3323
- package/dist/lib/node/chunk-KSEEI5VC.cjs.map +0 -7
- package/dist/lib/node/chunk-OWH2EUHZ.cjs +0 -90
- package/dist/lib/node/chunk-OWH2EUHZ.cjs.map +0 -7
- package/dist/lib/node/compute-graph-WILPHO4A.cjs +0 -57
- package/dist/lib/node/compute-graph-WILPHO4A.cjs.map +0 -7
- package/dist/lib/node/types.cjs +0 -38
- package/dist/lib/node/types.cjs.map +0 -7
- package/dist/lib/node-esm/SheetContainer-LSBE6Q4X.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-6JF2AHKO.mjs +0 -3270
- package/dist/lib/node-esm/chunk-6JF2AHKO.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-BVS2IQRO.mjs +0 -68
- package/dist/lib/node-esm/chunk-BVS2IQRO.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-NYDNXI7L.mjs.map +0 -7
- package/dist/lib/node-esm/compute-graph-S6CVN7RS.mjs +0 -36
- package/dist/lib/node-esm/compute-graph-S6CVN7RS.mjs.map +0 -7
- package/dist/lib/node-esm/types.mjs +0 -17
- package/dist/lib/node-esm/types.mjs.map +0 -7
- package/dist/types/src/compute-graph/compute-graph-registry.d.ts +0 -34
- package/dist/types/src/compute-graph/compute-graph-registry.d.ts.map +0 -1
- package/dist/types/src/compute-graph/compute-graph.d.ts +0 -64
- package/dist/types/src/compute-graph/compute-graph.d.ts.map +0 -1
- package/dist/types/src/compute-graph/compute-graph.stories.d.ts.map +0 -1
- package/dist/types/src/compute-graph/compute-graph.test.d.ts +0 -2
- package/dist/types/src/compute-graph/compute-graph.test.d.ts.map +0 -1
- package/dist/types/src/compute-graph/compute-node.d.ts +0 -26
- package/dist/types/src/compute-graph/compute-node.d.ts.map +0 -1
- package/dist/types/src/compute-graph/functions/async-function.d.ts +0 -66
- package/dist/types/src/compute-graph/functions/async-function.d.ts.map +0 -1
- package/dist/types/src/compute-graph/functions/edge-function.d.ts +0 -21
- package/dist/types/src/compute-graph/functions/edge-function.d.ts.map +0 -1
- package/dist/types/src/compute-graph/functions/function-defs.d.ts +0 -11
- package/dist/types/src/compute-graph/functions/function-defs.d.ts.map +0 -1
- package/dist/types/src/compute-graph/functions/index.d.ts +0 -4
- package/dist/types/src/compute-graph/functions/index.d.ts.map +0 -1
- package/dist/types/src/compute-graph/hyperformula.test.d.ts +0 -2
- package/dist/types/src/compute-graph/hyperformula.test.d.ts.map +0 -1
- package/dist/types/src/compute-graph/index.d.ts +0 -5
- package/dist/types/src/compute-graph/index.d.ts.map +0 -1
- package/dist/types/src/compute-graph/testing/index.d.ts +0 -3
- package/dist/types/src/compute-graph/testing/index.d.ts.map +0 -1
- package/dist/types/src/compute-graph/testing/test-builder.d.ts +0 -15
- package/dist/types/src/compute-graph/testing/test-builder.d.ts.map +0 -1
- package/dist/types/src/compute-graph/testing/test-plugin.d.ts +0 -36
- package/dist/types/src/compute-graph/testing/test-plugin.d.ts.map +0 -1
- package/dist/types/src/compute-graph/util.d.ts +0 -2
- package/dist/types/src/compute-graph/util.d.ts.map +0 -1
- package/dist/types/src/defs/index.d.ts.map +0 -1
- package/dist/types/src/defs/sheet-range-types.d.ts.map +0 -1
- package/dist/types/src/defs/types.d.ts +0 -26
- package/dist/types/src/defs/types.d.ts.map +0 -1
- package/dist/types/src/defs/types.test.d.ts +0 -2
- package/dist/types/src/defs/types.test.d.ts.map +0 -1
- package/dist/types/src/defs/util.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -182
- package/dist/types/src/types.d.ts.map +0 -1
- package/dist/vendor/hyperformula.mjs +0 -37145
- package/src/compute-graph/compute-graph-registry.ts +0 -90
- package/src/compute-graph/compute-graph.test.ts +0 -87
- package/src/compute-graph/compute-graph.ts +0 -260
- package/src/compute-graph/compute-node.ts +0 -62
- package/src/compute-graph/functions/async-function.ts +0 -179
- package/src/compute-graph/functions/edge-function.ts +0 -102
- package/src/compute-graph/functions/function-defs.ts +0 -2427
- package/src/compute-graph/functions/index.ts +0 -7
- package/src/compute-graph/hyperformula.test.ts +0 -14
- package/src/compute-graph/index.ts +0 -8
- package/src/compute-graph/testing/index.ts +0 -6
- package/src/compute-graph/testing/test-builder.ts +0 -54
- package/src/compute-graph/testing/test-plugin.ts +0 -100
- package/src/compute-graph/util.ts +0 -8
- package/src/defs/types.test.ts +0 -91
- package/src/defs/types.ts +0 -88
- package/src/types.ts +0 -125
- /package/dist/lib/browser/{compute-graph-SNUS7HOH.mjs.map → types/index.mjs.map} +0 -0
- /package/dist/lib/{browser/types.mjs.map → node-esm/types/index.mjs.map} +0 -0
- /package/dist/types/src/{compute-graph → components/ComputeGraph}/compute-graph.stories.d.ts +0 -0
- /package/dist/types/src/{defs → types}/sheet-range-types.d.ts +0 -0
- /package/src/{defs → types}/sheet-range-types.ts +0 -0
|
@@ -1,14 +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 test', async () => {
|
|
11
|
-
const hf = HyperFormula.buildEmpty({ licenseKey: 'gpl-v3' });
|
|
12
|
-
expect(hf).to.exist;
|
|
13
|
-
});
|
|
14
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Client, type ClientOptions } from '@dxos/client';
|
|
6
|
-
import { type Context, Resource } from '@dxos/context';
|
|
7
|
-
import { invariant } from '@dxos/invariant';
|
|
8
|
-
|
|
9
|
-
import { type ComputeGraphOptions, ComputeGraphRegistry } from '../compute-graph-registry';
|
|
10
|
-
|
|
11
|
-
export type TestBuilderOptions = ClientOptions & ComputeGraphOptions;
|
|
12
|
-
|
|
13
|
-
// TODO(burdon): Reconcile with @dxos/client/testing.
|
|
14
|
-
export class TestBuilder extends Resource {
|
|
15
|
-
private _client?: Client;
|
|
16
|
-
private _registry?: ComputeGraphRegistry;
|
|
17
|
-
|
|
18
|
-
constructor(private readonly _options: TestBuilderOptions = {}) {
|
|
19
|
-
super();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get ctx(): Context {
|
|
23
|
-
return this._ctx;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
get client(): Client {
|
|
27
|
-
invariant(this._client);
|
|
28
|
-
return this._client;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
get registry(): ComputeGraphRegistry {
|
|
32
|
-
invariant(this._registry);
|
|
33
|
-
return this._registry;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
override async _open() {
|
|
37
|
-
const client = new Client(this._options);
|
|
38
|
-
await client.initialize();
|
|
39
|
-
await client.halo.createIdentity();
|
|
40
|
-
this._client = client;
|
|
41
|
-
this._ctx.onDispose(async () => {
|
|
42
|
-
await client.destroy();
|
|
43
|
-
this._client = undefined;
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const registry = new ComputeGraphRegistry(this._options);
|
|
47
|
-
await registry.open();
|
|
48
|
-
this._registry = registry;
|
|
49
|
-
this._ctx.onDispose(async () => {
|
|
50
|
-
await registry.close();
|
|
51
|
-
this._registry = undefined;
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';
|
|
6
|
-
import { type ProcedureAst } from 'hyperformula/typings/parser';
|
|
7
|
-
|
|
8
|
-
import { getDeep } from '@dxos/util';
|
|
9
|
-
|
|
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';
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Testing functions run locally (not run via EDGE).
|
|
17
|
-
* https://hyperformula.handsontable.com/guide/custom-functions.html#add-a-simple-custom-function
|
|
18
|
-
*/
|
|
19
|
-
export class TestPlugin extends AsyncFunctionPlugin {
|
|
20
|
-
/**
|
|
21
|
-
* Simple local function returns input value.
|
|
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) {
|
|
35
|
-
const handler: AsyncFunction = async () => {
|
|
36
|
-
return Math.random();
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
return this.runAsyncFunction(ast, state, handler);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Async HTTP function.
|
|
44
|
-
*/
|
|
45
|
-
crypto(ast: ProcedureAst, state: InterpreterState) {
|
|
46
|
-
const handler: AsyncFunction = async (_currency) => {
|
|
47
|
-
const currency = (_currency || 'USD').toUpperCase();
|
|
48
|
-
const result = await fetch(`https://api.coindesk.com/v1/bpi/currentprice/${currency}.json`);
|
|
49
|
-
const data = await result.json();
|
|
50
|
-
const rate = getDeep<string>(data, ['bpi', currency, 'rate']);
|
|
51
|
-
if (!rate) {
|
|
52
|
-
return NaN;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return parseNumberString(rate);
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
return this.runAsyncFunction(ast, state, handler, { ttl: 10_000 });
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
TestPlugin.implementedFunctions = {
|
|
63
|
-
TEST: {
|
|
64
|
-
method: 'test',
|
|
65
|
-
parameters: [{ argumentType: FunctionArgumentType.NUMBER, optionalArg: false }],
|
|
66
|
-
isVolatile: true,
|
|
67
|
-
},
|
|
68
|
-
|
|
69
|
-
RANDOM: {
|
|
70
|
-
method: 'random',
|
|
71
|
-
parameters: [],
|
|
72
|
-
isVolatile: true,
|
|
73
|
-
},
|
|
74
|
-
|
|
75
|
-
CRYPTO: {
|
|
76
|
-
method: 'crypto',
|
|
77
|
-
parameters: [{ argumentType: FunctionArgumentType.STRING, optionalArg: true }],
|
|
78
|
-
isVolatile: true,
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export const TestPluginTranslations = {
|
|
83
|
-
enGB: {
|
|
84
|
-
TEST: 'Returns input value',
|
|
85
|
-
RANDOM: 'Random number',
|
|
86
|
-
CRYPTO: 'Crypto token value',
|
|
87
|
-
},
|
|
88
|
-
enUS: {
|
|
89
|
-
TEST: 'Returns input value',
|
|
90
|
-
RANDOM: 'Random number',
|
|
91
|
-
CRYPTO: 'Crypto token value',
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
export const testFunctionPlugins: ComputeGraphPlugin[] = [
|
|
96
|
-
{
|
|
97
|
-
plugin: TestPlugin,
|
|
98
|
-
translations: TestPluginTranslations,
|
|
99
|
-
},
|
|
100
|
-
];
|
package/src/defs/types.test.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { getIndices, sortByIndex, getIndicesBelow, getIndicesAbove, getIndicesBetween } from '@tldraw/indices';
|
|
6
|
-
import { describe, expect, test } from 'vitest';
|
|
7
|
-
|
|
8
|
-
import { inRange, addressFromA1Notation, addressToA1Notation, rangeFromA1Notation, rangeToA1Notation } from './types';
|
|
9
|
-
|
|
10
|
-
describe('cell', () => {
|
|
11
|
-
test('posToA1Notation', () => {
|
|
12
|
-
expect(addressToA1Notation({ col: 0, row: 0 })).to.eq('A1');
|
|
13
|
-
expect(addressFromA1Notation('C2')).to.deep.eq({ col: 2, row: 1 });
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('rangeToA1Notation', () => {
|
|
17
|
-
expect(rangeToA1Notation({ from: addressFromA1Notation('A1'), to: addressFromA1Notation('A5') })).to.eq('A1:A5');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
test('inRange', () => {
|
|
21
|
-
const range = rangeFromA1Notation('A1:C5');
|
|
22
|
-
expect(inRange(range, addressFromA1Notation('A1'))).to.be.true;
|
|
23
|
-
expect(inRange(range, addressFromA1Notation('C5'))).to.be.true;
|
|
24
|
-
expect(inRange(range, addressFromA1Notation('A6'))).to.be.false;
|
|
25
|
-
expect(inRange(range, addressFromA1Notation('D5'))).to.be.false;
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// TODO(burdon): Move to model.test.ts
|
|
29
|
-
test('index', () => {
|
|
30
|
-
// Pre-allocated grid.
|
|
31
|
-
const n = 5;
|
|
32
|
-
const columns = getIndices(n - 1);
|
|
33
|
-
const rows = getIndices(n - 1);
|
|
34
|
-
|
|
35
|
-
const pickOne = (indices: string[]) => indices[Math.floor(Math.random() * indices.length)];
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Insert an index into the allocated list.
|
|
39
|
-
* Randomly picks from n values between indexes to support probabilistic concurrency.
|
|
40
|
-
*/
|
|
41
|
-
const insertIndex = (indices: string[], i: number, n = 20) => {
|
|
42
|
-
if (i === 0) {
|
|
43
|
-
const idx = pickOne(getIndicesBelow(indices[0], n));
|
|
44
|
-
indices.splice(0, 0, idx);
|
|
45
|
-
} else if (i >= indices.length) {
|
|
46
|
-
// Reallocate if > current bounds.
|
|
47
|
-
// TODO(burdon): Is this OK if this happens concurrently?
|
|
48
|
-
indices.splice(indices.length, 0, ...getIndicesAbove(indices[indices.length - 1], i + 1 - indices.length));
|
|
49
|
-
} else {
|
|
50
|
-
const idx = pickOne(getIndicesBetween(indices[i - 1], indices[i], n));
|
|
51
|
-
indices.splice(i, 0, idx);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// Values.
|
|
56
|
-
const cells: Record<string, any> = {};
|
|
57
|
-
const setCell = (cell: string, value: any) => {
|
|
58
|
-
const { col, row } = addressFromA1Notation(cell);
|
|
59
|
-
// Reallocate if > current bounds.
|
|
60
|
-
if (col >= columns.length) {
|
|
61
|
-
insertIndex(columns, col);
|
|
62
|
-
}
|
|
63
|
-
if (row >= rows.length) {
|
|
64
|
-
insertIndex(rows, row);
|
|
65
|
-
}
|
|
66
|
-
const index = `${columns[col]}@${rows[row]}`;
|
|
67
|
-
cells[index] = value;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
expect(addressFromA1Notation('A1')).to.deep.eq({ col: 0, row: 0 });
|
|
71
|
-
|
|
72
|
-
expect(columns).to.deep.eq(['a1', 'a2', 'a3', 'a4', 'a5']);
|
|
73
|
-
insertIndex(columns, 7);
|
|
74
|
-
expect(columns).to.deep.eq(['a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8']);
|
|
75
|
-
|
|
76
|
-
setCell('A1', 100);
|
|
77
|
-
setCell('B1', 101);
|
|
78
|
-
|
|
79
|
-
insertIndex(columns, 1);
|
|
80
|
-
setCell('B1', 102);
|
|
81
|
-
|
|
82
|
-
setCell('J10', 104);
|
|
83
|
-
expect(columns).to.have.length(10);
|
|
84
|
-
expect(rows).to.have.length(10);
|
|
85
|
-
|
|
86
|
-
const entries = Object.entries(cells).map(([key, value]) => ({ index: key.split('@')[0], value }));
|
|
87
|
-
const sorted = entries.sort(sortByIndex);
|
|
88
|
-
const values = sorted.map(({ value }) => value);
|
|
89
|
-
expect(values).to.deep.eq([100, 102, 101, 104]);
|
|
90
|
-
});
|
|
91
|
-
});
|
package/src/defs/types.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { invariant } from '@dxos/invariant';
|
|
6
|
-
import { type DxGridPlanePosition } from '@dxos/react-ui-grid';
|
|
7
|
-
|
|
8
|
-
export const DEFAULT_ROWS = 50;
|
|
9
|
-
export const DEFAULT_COLUMNS = 26;
|
|
10
|
-
|
|
11
|
-
export const MAX_ROWS = 500;
|
|
12
|
-
export const MAX_COLUMNS = 26 * 2;
|
|
13
|
-
|
|
14
|
-
export type CellAddress = DxGridPlanePosition;
|
|
15
|
-
|
|
16
|
-
export type CellRange = { from: CellAddress; to?: CellAddress };
|
|
17
|
-
export type CompleteCellRange = { from: CellAddress; to: CellAddress };
|
|
18
|
-
|
|
19
|
-
export type CellIndex = string;
|
|
20
|
-
|
|
21
|
-
export type CellContentValue = number | string | boolean | null;
|
|
22
|
-
|
|
23
|
-
export const RANGE_NOTATION = /^[A-Z]+[0-9]+(:[A-Z]+[0-9]+)?$/;
|
|
24
|
-
|
|
25
|
-
export const isFormula = (value: any): value is string => typeof value === 'string' && value.charAt(0) === '=';
|
|
26
|
-
|
|
27
|
-
export const posEquals = (a: CellAddress | undefined, b: CellAddress | undefined) => {
|
|
28
|
-
return a?.col === b?.col && a?.row === b?.row;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export const columnLetter = (col: number): string => {
|
|
32
|
-
invariant(col < MAX_COLUMNS, `Invalid column: ${col}`);
|
|
33
|
-
return (
|
|
34
|
-
(col >= 26 ? String.fromCharCode('A'.charCodeAt(0) + Math.floor(col / 26) - 1) : '') +
|
|
35
|
-
String.fromCharCode('A'.charCodeAt(0) + (col % 26))
|
|
36
|
-
);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export const addressToA1Notation = ({ col, row }: CellAddress): string => {
|
|
40
|
-
return `${columnLetter(col)}${row + 1}`;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// TODO(burdon): See (HF) simpleCellAddressFromString.
|
|
44
|
-
export const addressFromA1Notation = (ref: string): CellAddress => {
|
|
45
|
-
const match = ref.match(/([A-Z]+)(\d+)/);
|
|
46
|
-
invariant(match, `Invalid notation: ${ref}`);
|
|
47
|
-
return {
|
|
48
|
-
row: parseInt(match[2], 10) - 1,
|
|
49
|
-
col: match[1].split('').reduce((acc, c) => acc * 26 + c.charCodeAt(0) - 'A'.charCodeAt(0) + 1, 0) - 1,
|
|
50
|
-
};
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const rangeToA1Notation = (range: CellRange) => {
|
|
54
|
-
return [range?.from && addressToA1Notation(range?.from), range?.to && addressToA1Notation(range?.to)]
|
|
55
|
-
.filter(Boolean)
|
|
56
|
-
.join(':');
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export const rangeFromA1Notation = (ref: string): CellRange => {
|
|
60
|
-
const [from, to] = ref.split(':').map(addressFromA1Notation);
|
|
61
|
-
return { from, to };
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const inRange = (range: CellRange | undefined, cell: CellAddress): boolean => {
|
|
65
|
-
if (!range) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const { from, to } = range;
|
|
70
|
-
if ((from && posEquals(from, cell)) || (to && posEquals(to, cell))) {
|
|
71
|
-
return true;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (!from || !to) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const { col: c1, row: r1 } = from;
|
|
79
|
-
const { col: c2, row: r2 } = to;
|
|
80
|
-
|
|
81
|
-
const cMin = Math.min(c1, c2);
|
|
82
|
-
const cMax = Math.max(c1, c2);
|
|
83
|
-
const rMin = Math.min(r1, r2);
|
|
84
|
-
const rMax = Math.max(r1, r2);
|
|
85
|
-
|
|
86
|
-
const { col, row } = cell;
|
|
87
|
-
return col >= cMin && col <= cMax && row >= rMin && row <= rMax;
|
|
88
|
-
};
|
package/src/types.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
GraphBuilderProvides,
|
|
7
|
-
IntentResolverProvides,
|
|
8
|
-
MetadataRecordsProvides,
|
|
9
|
-
SurfaceProvides,
|
|
10
|
-
TranslationsProvides,
|
|
11
|
-
IntentData,
|
|
12
|
-
} from '@dxos/app-framework';
|
|
13
|
-
import { ref, S, TypedObject } from '@dxos/echo-schema';
|
|
14
|
-
import { type MarkdownExtensionProvides } from '@dxos/plugin-markdown';
|
|
15
|
-
import { type SchemaProvides } from '@dxos/plugin-space';
|
|
16
|
-
import { ThreadType } from '@dxos/plugin-space/types';
|
|
17
|
-
import { type StackProvides } from '@dxos/plugin-stack';
|
|
18
|
-
import { type DxGridAxis } from '@dxos/react-ui-grid';
|
|
19
|
-
|
|
20
|
-
import { SHEET_PLUGIN } from './meta';
|
|
21
|
-
import { type SheetModel } from './model';
|
|
22
|
-
|
|
23
|
-
const SHEET_ACTION = `${SHEET_PLUGIN}/action`;
|
|
24
|
-
|
|
25
|
-
export enum SheetAction {
|
|
26
|
-
CREATE = `${SHEET_ACTION}/create`,
|
|
27
|
-
INSERT_AXIS = `${SHEET_ACTION}/axis-insert`,
|
|
28
|
-
DROP_AXIS = `${SHEET_ACTION}/axis-drop`,
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export type RestoreAxis = {
|
|
32
|
-
axis: DxGridAxis;
|
|
33
|
-
axisIndex: string;
|
|
34
|
-
index: number;
|
|
35
|
-
axisMeta?: S.Schema.Type<typeof RowColumnMeta>;
|
|
36
|
-
values: CellScalarValue[];
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export namespace SheetAction {
|
|
40
|
-
export type Create = IntentData<{ sheet: SheetType }>;
|
|
41
|
-
export type InsertAxis = IntentData<{ model: SheetModel; axis: DxGridAxis; index: number; count?: number }>;
|
|
42
|
-
export type DropAxis = IntentData<{ model: SheetModel; axis: DxGridAxis; axisIndex: string }>;
|
|
43
|
-
export type DropAxisRestore = IntentData<RestoreAxis & { model: SheetModel }>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// TODO(Zan): Move this to the plugin-space plugin or another common location
|
|
47
|
-
// when we implement comments in sheets.
|
|
48
|
-
// This is currently duplicated in a few places.
|
|
49
|
-
type ThreadProvides<T> = {
|
|
50
|
-
thread: {
|
|
51
|
-
predicate: (obj: any) => obj is T;
|
|
52
|
-
createSort: (obj: T) => (anchorA: string | undefined, anchorB: string | undefined) => number;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
export type SheetPluginProvides = SurfaceProvides &
|
|
57
|
-
IntentResolverProvides &
|
|
58
|
-
GraphBuilderProvides &
|
|
59
|
-
MarkdownExtensionProvides &
|
|
60
|
-
MetadataRecordsProvides &
|
|
61
|
-
TranslationsProvides &
|
|
62
|
-
SchemaProvides &
|
|
63
|
-
StackProvides &
|
|
64
|
-
ThreadProvides<SheetType>;
|
|
65
|
-
|
|
66
|
-
export type CellScalarValue = number | string | boolean | null;
|
|
67
|
-
|
|
68
|
-
export const CellValue = S.Struct({
|
|
69
|
-
// TODO(burdon): How to store dates (datetime, date, time), percentages, etc.
|
|
70
|
-
// Consider import/export; natural access for other plugins. Special handling for currency (precision).
|
|
71
|
-
// TODO(burdon): Automerge (long string) or short string or number.
|
|
72
|
-
value: S.Any,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
export type CellValue = S.Schema.Type<typeof CellValue>;
|
|
76
|
-
|
|
77
|
-
// TODO(burdon): IMPORTANT: Reconcile with Field definition.
|
|
78
|
-
export const Range = S.Struct({
|
|
79
|
-
range: S.String,
|
|
80
|
-
key: S.String,
|
|
81
|
-
value: S.String,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
export type Range = S.Schema.Type<typeof Range>;
|
|
85
|
-
|
|
86
|
-
// TODO(burdon): Visibility, locked, frozen, etc.
|
|
87
|
-
export const RowColumnMeta = S.Struct({
|
|
88
|
-
size: S.optional(S.Number),
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// TODO(burdon): Index to all updates when rows/columns are inserted/deleted.
|
|
92
|
-
export class SheetType extends TypedObject({ typename: 'dxos.org/type/Sheet', version: '0.1.0' })({
|
|
93
|
-
name: S.optional(S.String),
|
|
94
|
-
|
|
95
|
-
// Sparse map of cells referenced by index.
|
|
96
|
-
cells: S.mutable(S.Record({ key: S.String, value: S.mutable(CellValue) })),
|
|
97
|
-
|
|
98
|
-
// Ordered row indices.
|
|
99
|
-
rows: S.mutable(S.Array(S.String)),
|
|
100
|
-
|
|
101
|
-
// Ordered column indices.
|
|
102
|
-
columns: S.mutable(S.Array(S.String)),
|
|
103
|
-
|
|
104
|
-
// Row metadata referenced by index.
|
|
105
|
-
rowMeta: S.mutable(S.Record({ key: S.String, value: S.mutable(RowColumnMeta) })),
|
|
106
|
-
|
|
107
|
-
// Column metadata referenced by index.
|
|
108
|
-
columnMeta: S.mutable(S.Record({ key: S.String, value: S.mutable(RowColumnMeta) })),
|
|
109
|
-
|
|
110
|
-
// Cell formatting referenced by indexed range.
|
|
111
|
-
ranges: S.mutable(S.Array(Range)),
|
|
112
|
-
|
|
113
|
-
// Threads associated with the sheet
|
|
114
|
-
threads: S.optional(S.mutable(S.Array(ref(ThreadType)))),
|
|
115
|
-
}) {}
|
|
116
|
-
|
|
117
|
-
export type SheetSize = {
|
|
118
|
-
rows: number;
|
|
119
|
-
columns: number;
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
export type CreateSheetOptions = {
|
|
123
|
-
name?: string;
|
|
124
|
-
cells?: Record<string, CellValue>;
|
|
125
|
-
} & Partial<SheetSize>;
|
|
File without changes
|
|
File without changes
|
/package/dist/types/src/{compute-graph → components/ComputeGraph}/compute-graph.stories.d.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|