@dxos/plugin-sheet 0.6.14-main.8b352a0 → 0.6.14-staging.54a8bab
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-R65IDJHN.mjs → SheetContainer-JZEKRM4Z.mjs} +41 -30
- package/dist/lib/browser/SheetContainer-JZEKRM4Z.mjs.map +7 -0
- package/dist/lib/browser/{chunk-5KVQ5IPW.mjs → chunk-BVUN7SHF.mjs} +4 -2
- package/dist/lib/browser/chunk-BVUN7SHF.mjs.map +7 -0
- package/dist/lib/browser/{chunk-I2DKJ72A.mjs → chunk-G2FUL6PK.mjs} +257 -57
- package/dist/lib/browser/chunk-G2FUL6PK.mjs.map +7 -0
- package/dist/lib/browser/{chunk-D3QTX46O.mjs → chunk-RABELMEQ.mjs} +3 -2
- package/dist/lib/browser/{chunk-D3QTX46O.mjs.map → chunk-RABELMEQ.mjs.map} +3 -3
- package/dist/lib/browser/{chunk-KCYJSOFB.mjs → chunk-VMSX6Z4X.mjs} +51 -17
- package/dist/lib/browser/chunk-VMSX6Z4X.mjs.map +7 -0
- package/dist/lib/browser/{compute-graph-SJT67236.mjs → compute-graph-GGWUX644.mjs} +4 -4
- package/dist/lib/browser/index.mjs +38 -10
- 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/types.mjs +2 -2
- package/dist/lib/node/{SheetContainer-6BO4C5X2.cjs → SheetContainer-PJE74VO4.cjs} +60 -50
- package/dist/lib/node/SheetContainer-PJE74VO4.cjs.map +7 -0
- package/dist/lib/node/{chunk-QIFIGEKV.cjs → chunk-2ZVZI2KJ.cjs} +6 -5
- package/dist/lib/node/{chunk-QIFIGEKV.cjs.map → chunk-2ZVZI2KJ.cjs.map} +3 -3
- package/dist/lib/node/{chunk-2XJ5I4UF.cjs → chunk-AWKOWDMI.cjs} +8 -6
- package/dist/lib/node/chunk-AWKOWDMI.cjs.map +7 -0
- package/dist/lib/node/{chunk-JF5XNTF3.cjs → chunk-O7XR4R7Y.cjs} +61 -26
- package/dist/lib/node/chunk-O7XR4R7Y.cjs.map +7 -0
- package/dist/lib/node/{chunk-DEPJHN47.cjs → chunk-STZ7S7RF.cjs} +293 -94
- package/dist/lib/node/chunk-STZ7S7RF.cjs.map +7 -0
- package/dist/lib/node/{compute-graph-AQBDL7HO.cjs → compute-graph-KGWA2QLE.cjs} +21 -21
- package/dist/lib/node/{compute-graph-AQBDL7HO.cjs.map → compute-graph-KGWA2QLE.cjs.map} +2 -2
- package/dist/lib/node/index.cjs +66 -38
- 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/types.cjs +7 -7
- package/dist/lib/node/types.cjs.map +1 -1
- package/dist/lib/node-esm/{SheetContainer-MJXC5E3P.mjs → SheetContainer-R73XEXHU.mjs} +41 -30
- package/dist/lib/node-esm/SheetContainer-R73XEXHU.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-VCYJWE3O.mjs → chunk-BM2Q3FFC.mjs} +3 -2
- package/dist/lib/node-esm/{chunk-VCYJWE3O.mjs.map → chunk-BM2Q3FFC.mjs.map} +3 -3
- package/dist/lib/node-esm/{chunk-XBEHKYO7.mjs → chunk-CR4K75EL.mjs} +51 -17
- package/dist/lib/node-esm/chunk-CR4K75EL.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-5TXLF6PL.mjs → chunk-UIBWRHW7.mjs} +4 -2
- package/dist/lib/node-esm/chunk-UIBWRHW7.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-25V7WY4R.mjs → chunk-V5N3Y2O5.mjs} +257 -57
- package/dist/lib/node-esm/chunk-V5N3Y2O5.mjs.map +7 -0
- package/dist/lib/node-esm/{compute-graph-FRCKXEYK.mjs → compute-graph-2SCZT7N5.mjs} +4 -4
- package/dist/lib/node-esm/index.mjs +38 -10
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/meta.mjs +1 -1
- package/dist/lib/node-esm/types.mjs +2 -2
- package/dist/types/src/SheetPlugin.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/util.d.ts.map +1 -1
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +5 -2
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/compute-graph/compute-graph.d.ts +2 -2
- package/dist/types/src/compute-graph/compute-graph.d.ts.map +1 -1
- package/dist/types/src/compute-graph/functions/async-function.d.ts.map +1 -1
- package/dist/types/src/compute-graph/functions/edge-function.d.ts.map +1 -1
- package/dist/types/src/defs/sheet-range-types.d.ts +1 -1
- package/dist/types/src/defs/sheet-range-types.d.ts.map +1 -1
- package/dist/types/src/defs/util.d.ts +1 -1
- package/dist/types/src/defs/util.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +1 -0
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/model/sheet-model.d.ts +12 -5
- package/dist/types/src/model/sheet-model.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +10 -5
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +33 -3
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +36 -36
- package/src/SheetPlugin.tsx +20 -0
- package/src/components/GridSheet/GridSheet.tsx +77 -16
- package/src/components/GridSheet/util.ts +12 -6
- package/src/components/SheetContainer/SheetContainer.stories.tsx +2 -0
- package/src/components/Toolbar/Toolbar.tsx +62 -41
- package/src/compute-graph/compute-graph.ts +22 -7
- package/src/compute-graph/functions/async-function.ts +1 -0
- package/src/compute-graph/functions/edge-function.ts +5 -3
- package/src/defs/sheet-range-types.ts +4 -2
- package/src/defs/util.ts +1 -0
- package/src/meta.ts +1 -0
- package/src/model/sheet-model.test.ts +5 -3
- package/src/model/sheet-model.ts +93 -21
- package/src/translations.ts +10 -5
- package/src/types.ts +20 -0
- package/dist/lib/browser/SheetContainer-R65IDJHN.mjs.map +0 -7
- package/dist/lib/browser/chunk-5KVQ5IPW.mjs.map +0 -7
- package/dist/lib/browser/chunk-I2DKJ72A.mjs.map +0 -7
- package/dist/lib/browser/chunk-KCYJSOFB.mjs.map +0 -7
- package/dist/lib/node/SheetContainer-6BO4C5X2.cjs.map +0 -7
- package/dist/lib/node/chunk-2XJ5I4UF.cjs.map +0 -7
- package/dist/lib/node/chunk-DEPJHN47.cjs.map +0 -7
- package/dist/lib/node/chunk-JF5XNTF3.cjs.map +0 -7
- package/dist/lib/node-esm/SheetContainer-MJXC5E3P.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-25V7WY4R.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-5TXLF6PL.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-XBEHKYO7.mjs.map +0 -7
- /package/dist/lib/browser/{compute-graph-SJT67236.mjs.map → compute-graph-GGWUX644.mjs.map} +0 -0
- /package/dist/lib/node-esm/{compute-graph-FRCKXEYK.mjs.map → compute-graph-2SCZT7N5.mjs.map} +0 -0
|
@@ -6,6 +6,7 @@ import { type Listeners } from 'hyperformula/typings/Emitter';
|
|
|
6
6
|
|
|
7
7
|
import { Event } from '@dxos/async';
|
|
8
8
|
import { type Space, Filter, fullyQualifiedId } from '@dxos/client/echo';
|
|
9
|
+
import { FQ_ID_LENGTH } from '@dxos/client/echo';
|
|
9
10
|
import { Resource } from '@dxos/context';
|
|
10
11
|
import { getTypename } from '@dxos/echo-schema';
|
|
11
12
|
import { invariant } from '@dxos/invariant';
|
|
@@ -26,8 +27,7 @@ import {
|
|
|
26
27
|
|
|
27
28
|
// TODO(burdon): Factor out compute-graph.
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
const OBJECT_ID_LENGTH = 60; // 33 (space id) + 1 (separator) + 26 (object id).
|
|
30
|
+
const UNKNOWN_BINDING = '__UNKNOWN__';
|
|
31
31
|
|
|
32
32
|
// TODO(burdon): Factory.
|
|
33
33
|
// export type ComputeNodeGenerator = <T>(obj: T) => ComputeNode;
|
|
@@ -44,7 +44,7 @@ export const parseSheetName = (name: string): Partial<ObjectRef> => {
|
|
|
44
44
|
return id ? { type, id } : { id: type };
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
export type ComputeGraphEvent = 'functionsUpdated';
|
|
47
|
+
export type ComputeGraphEvent = 'functionsUpdated' | 'valuesUpdated';
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
50
|
* Per-space compute and dependency graph.
|
|
@@ -64,7 +64,7 @@ export class ComputeGraph extends Resource {
|
|
|
64
64
|
public readonly update = new Event<{ type: ComputeGraphEvent }>();
|
|
65
65
|
|
|
66
66
|
// The context is passed to all functions.
|
|
67
|
-
public readonly context
|
|
67
|
+
public readonly context: FunctionContext;
|
|
68
68
|
|
|
69
69
|
constructor(
|
|
70
70
|
private readonly _hf: HyperFormula,
|
|
@@ -72,6 +72,15 @@ export class ComputeGraph extends Resource {
|
|
|
72
72
|
private readonly _options?: Partial<FunctionContextOptions>,
|
|
73
73
|
) {
|
|
74
74
|
super();
|
|
75
|
+
|
|
76
|
+
const contextOptions = {
|
|
77
|
+
...this._options,
|
|
78
|
+
onUpdate: (update) => {
|
|
79
|
+
this._options?.onUpdate?.(update);
|
|
80
|
+
this.update.emit({ type: 'valuesUpdated' });
|
|
81
|
+
},
|
|
82
|
+
} satisfies Partial<FunctionContextOptions>;
|
|
83
|
+
this.context = new FunctionContext(this._hf, this._space, contextOptions);
|
|
75
84
|
this._hf.updateConfig({ context: this.context });
|
|
76
85
|
|
|
77
86
|
// TODO(burdon): If debounce then aggregate changes.
|
|
@@ -209,9 +218,9 @@ export class ComputeGraph extends Resource {
|
|
|
209
218
|
* E.g., spaceId:objectId() => HELLO()
|
|
210
219
|
*/
|
|
211
220
|
mapFunctionBindingFromId(formula: string) {
|
|
212
|
-
|
|
221
|
+
const binding = formula.replace(/(\w+):([a-zA-Z0-9]+)\((.*)\)/g, (match, spaceId, objectId, args) => {
|
|
213
222
|
const id = `${spaceId}:${objectId}`;
|
|
214
|
-
if (id.length !==
|
|
223
|
+
if (id.length !== FQ_ID_LENGTH) {
|
|
215
224
|
return match;
|
|
216
225
|
}
|
|
217
226
|
|
|
@@ -219,9 +228,15 @@ export class ComputeGraph extends Resource {
|
|
|
219
228
|
if (fn?.binding) {
|
|
220
229
|
return `${fn.binding}(${args})`;
|
|
221
230
|
} else {
|
|
222
|
-
return
|
|
231
|
+
return UNKNOWN_BINDING;
|
|
223
232
|
}
|
|
224
233
|
});
|
|
234
|
+
|
|
235
|
+
if (binding.startsWith(`=${UNKNOWN_BINDING}`)) {
|
|
236
|
+
return undefined;
|
|
237
|
+
} else {
|
|
238
|
+
return binding;
|
|
239
|
+
}
|
|
225
240
|
}
|
|
226
241
|
|
|
227
242
|
protected override async _open() {
|
|
@@ -83,6 +83,7 @@ export class FunctionContext {
|
|
|
83
83
|
) {
|
|
84
84
|
this._options = defaultsDeep(_options ?? {}, defaultFunctionContextOptions);
|
|
85
85
|
this._onUpdate = debounce((update) => {
|
|
86
|
+
log('update', update);
|
|
86
87
|
// TODO(burdon): Better way to trigger recalculation? (NOTE: rebuildAndRecalculate resets the undo history.)
|
|
87
88
|
this._hf.resumeEvaluation();
|
|
88
89
|
this._options.onUpdate?.(update);
|
|
@@ -44,7 +44,7 @@ export class EdgeFunctionPlugin extends AsyncFunctionPlugin {
|
|
|
44
44
|
|
|
45
45
|
if (subscribe) {
|
|
46
46
|
const unsubscribe = effect(() => {
|
|
47
|
-
log
|
|
47
|
+
log('function changed', { fn });
|
|
48
48
|
const _ = fn?.version;
|
|
49
49
|
|
|
50
50
|
// TODO(wittjosiah): `ttl` should be 0 to force a recalculation when a new version is deployed.
|
|
@@ -56,13 +56,15 @@ export class EdgeFunctionPlugin extends AsyncFunctionPlugin {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
const path = getUserFunctionUrlInMetadata(getMeta(fn));
|
|
59
|
-
const
|
|
59
|
+
const response = await fetch(`${this.context.remoteFunctionUrl}${path}`, {
|
|
60
60
|
method: 'POST',
|
|
61
61
|
headers: { 'Content-Type': 'application/json' },
|
|
62
62
|
body: JSON.stringify({ args: args.filter(nonNullable) }),
|
|
63
63
|
});
|
|
64
|
+
const result = await response.text();
|
|
65
|
+
log('function executed', { result });
|
|
64
66
|
|
|
65
|
-
return
|
|
67
|
+
return result;
|
|
66
68
|
};
|
|
67
69
|
|
|
68
70
|
return this.runAsyncFunction(ast, state, handler(true), { ttl: FUNCTION_TTL });
|
|
@@ -16,7 +16,7 @@ export type CommentValue = string;
|
|
|
16
16
|
|
|
17
17
|
export const styleKey = 'style';
|
|
18
18
|
export type StyleKey = typeof styleKey;
|
|
19
|
-
export type StyleValue = 'highlight' | '
|
|
19
|
+
export type StyleValue = 'highlight' | 'softwrap';
|
|
20
20
|
|
|
21
21
|
// TODO(burdon): Reconcile with plugin-table.
|
|
22
22
|
export const cellClassNameForRange = ({ key, value }: SheetType['ranges'][number]): ClassNameValue => {
|
|
@@ -37,7 +37,9 @@ export const cellClassNameForRange = ({ key, value }: SheetType['ranges'][number
|
|
|
37
37
|
case styleKey:
|
|
38
38
|
switch (value) {
|
|
39
39
|
case 'highlight':
|
|
40
|
-
return 'bg-gridHighlight';
|
|
40
|
+
return '!bg-gridHighlight';
|
|
41
|
+
case 'softwrap':
|
|
42
|
+
return '!whitespace-normal';
|
|
41
43
|
default:
|
|
42
44
|
return undefined;
|
|
43
45
|
}
|
package/src/defs/util.ts
CHANGED
package/src/meta.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { afterEach, beforeEach, describe, expect, test } from 'vitest';
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { Trigger } from '@dxos/async';
|
|
8
8
|
import { FunctionType } from '@dxos/plugin-script/types';
|
|
@@ -36,13 +36,15 @@ describe('SheetModel', () => {
|
|
|
36
36
|
// Trigger waits for function invocation.
|
|
37
37
|
const trigger = new Trigger<CellScalarValue>();
|
|
38
38
|
model.setValue(addressFromA1Notation('A1'), '=TEST(100)');
|
|
39
|
-
|
|
39
|
+
// TODO(wittjosiah): Currently this fires twice, once for the binding loading & once for the function invocation.
|
|
40
|
+
const unsubscribe = model.update.on((update) => {
|
|
40
41
|
const { type } = update;
|
|
41
42
|
if (type === 'valuesUpdated') {
|
|
42
43
|
const value = model.getValue(addressFromA1Notation('A1'));
|
|
43
|
-
trigger.wake(value);
|
|
44
|
+
value && trigger.wake(value);
|
|
44
45
|
}
|
|
45
46
|
});
|
|
47
|
+
onTestFinished(() => unsubscribe());
|
|
46
48
|
|
|
47
49
|
// Initial value will be null.
|
|
48
50
|
const v1 = model.getValue(addressFromA1Notation('A1'));
|
package/src/model/sheet-model.ts
CHANGED
|
@@ -8,11 +8,10 @@ import { type SimpleDate, type SimpleDateTime } from 'hyperformula/typings/DateT
|
|
|
8
8
|
|
|
9
9
|
import { Event } from '@dxos/async';
|
|
10
10
|
import { Resource } from '@dxos/context';
|
|
11
|
-
import { getTypename } from '@dxos/echo-schema';
|
|
11
|
+
import { getTypename, FormatEnum, TypeEnum } from '@dxos/echo-schema';
|
|
12
12
|
import { invariant } from '@dxos/invariant';
|
|
13
13
|
import { PublicKey } from '@dxos/keys';
|
|
14
14
|
import { log } from '@dxos/log';
|
|
15
|
-
import { FieldValueType } from '@dxos/schema';
|
|
16
15
|
|
|
17
16
|
import { DetailedCellError, ExportedCellChange } from '#hyperformula';
|
|
18
17
|
import { type ComputeGraph, type ComputeNode, type ComputeNodeEvent, createSheetName } from '../compute-graph';
|
|
@@ -21,26 +20,29 @@ import {
|
|
|
21
20
|
addressFromIndex,
|
|
22
21
|
addressToA1Notation,
|
|
23
22
|
addressToIndex,
|
|
24
|
-
type CellAddress,
|
|
25
|
-
type CellRange,
|
|
26
23
|
initialize,
|
|
27
24
|
insertIndices,
|
|
28
25
|
isFormula,
|
|
26
|
+
type CellAddress,
|
|
27
|
+
type CellRange,
|
|
28
|
+
ReadonlyException,
|
|
29
29
|
MAX_COLUMNS,
|
|
30
30
|
MAX_ROWS,
|
|
31
|
-
ReadonlyException,
|
|
32
31
|
} from '../defs';
|
|
33
|
-
import { type CellScalarValue, type CellValue, type SheetType } from '../types';
|
|
32
|
+
import { type CellScalarValue, type CellValue, type SheetType, type RestoreAxis } from '../types';
|
|
34
33
|
|
|
35
34
|
// Map sheet types to system types.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
// https://hyperformula.handsontable.com/guide/types-of-values.html
|
|
36
|
+
// - https://github.com/handsontable/hyperformula/blob/master/src/Cell.ts (CellValueType)
|
|
37
|
+
// - https://github.com/handsontable/hyperformula/blob/master/src/interpreter/InterpreterValue.ts (NumberType)
|
|
38
|
+
const typeMap: Record<string, { type: TypeEnum; format?: FormatEnum }> = {
|
|
39
|
+
BOOLEAN: { type: TypeEnum.Boolean },
|
|
40
|
+
NUMBER_RAW: { type: TypeEnum.Number },
|
|
41
|
+
NUMBER_PERCENT: { type: TypeEnum.Number, format: FormatEnum.Percent },
|
|
42
|
+
NUMBER_CURRENCY: { type: TypeEnum.Number, format: FormatEnum.Currency },
|
|
43
|
+
NUMBER_DATETIME: { type: TypeEnum.String, format: FormatEnum.DateTime },
|
|
44
|
+
NUMBER_DATE: { type: TypeEnum.String, format: FormatEnum.Date },
|
|
45
|
+
NUMBER_TIME: { type: TypeEnum.String, format: FormatEnum.Time },
|
|
44
46
|
};
|
|
45
47
|
|
|
46
48
|
const getTopLeft = (range: CellRange): CellAddress => {
|
|
@@ -111,6 +113,12 @@ export class SheetModel extends Resource {
|
|
|
111
113
|
log('initialize', { id: this.id });
|
|
112
114
|
initialize(this._sheet);
|
|
113
115
|
|
|
116
|
+
this._graph.update.on((event) => {
|
|
117
|
+
if (event.type === 'functionsUpdated') {
|
|
118
|
+
this.reset();
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
114
122
|
// TODO(burdon): SheetModel should extend ComputeNode and be constructed via the graph.
|
|
115
123
|
this._node = this._graph.getOrCreateNode(createSheetName({ type: getTypename(this._sheet)!, id: this._sheet.id }));
|
|
116
124
|
await this._node.open();
|
|
@@ -134,9 +142,14 @@ export class SheetModel extends Resource {
|
|
|
134
142
|
invariant(this._node);
|
|
135
143
|
const { col, row } = addressFromIndex(this._sheet, key);
|
|
136
144
|
if (isFormula(value)) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
145
|
+
const binding = this._graph.mapFunctionBindingFromId(this.mapFormulaIndicesToRefs(value));
|
|
146
|
+
if (binding) {
|
|
147
|
+
value = this._graph.mapFormulaToNative(binding);
|
|
148
|
+
} else {
|
|
149
|
+
// If binding is not found, render the cell as empty.
|
|
150
|
+
// This prevents the cell from momentarily rendering an error while the binding is being loaded.
|
|
151
|
+
value = '';
|
|
152
|
+
}
|
|
140
153
|
}
|
|
141
154
|
|
|
142
155
|
this._node.graph.hf.setCellContents({ sheet: this._node.sheetId, row, col }, value);
|
|
@@ -155,12 +168,68 @@ export class SheetModel extends Resource {
|
|
|
155
168
|
}
|
|
156
169
|
|
|
157
170
|
insertRows(i: number, n = 1) {
|
|
158
|
-
insertIndices(this._sheet.rows, i, n, MAX_ROWS);
|
|
171
|
+
const idx = insertIndices(this._sheet.rows, i, n, MAX_ROWS);
|
|
159
172
|
this.reset();
|
|
173
|
+
return idx;
|
|
160
174
|
}
|
|
161
175
|
|
|
162
176
|
insertColumns(i: number, n = 1) {
|
|
163
|
-
insertIndices(this._sheet.columns, i, n, MAX_COLUMNS);
|
|
177
|
+
const idx = insertIndices(this._sheet.columns, i, n, MAX_COLUMNS);
|
|
178
|
+
this.reset();
|
|
179
|
+
return idx;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
dropRow(rowIndex: string): RestoreAxis {
|
|
183
|
+
const range = {
|
|
184
|
+
from: addressFromIndex(this._sheet, `${this._sheet.columns[0]}@${rowIndex}`),
|
|
185
|
+
to: addressFromIndex(this._sheet, `${this._sheet.columns[this._sheet.columns.length - 1]}@${rowIndex}`),
|
|
186
|
+
};
|
|
187
|
+
const values = this.getCellValues(range).flat();
|
|
188
|
+
const index = this._sheet.rows.indexOf(rowIndex);
|
|
189
|
+
this.clear(range);
|
|
190
|
+
this._sheet.rows.splice(index, 1);
|
|
191
|
+
delete this._sheet.rowMeta[rowIndex];
|
|
192
|
+
this.reset();
|
|
193
|
+
return { axis: 'row', index, axisIndex: rowIndex, axisMeta: this._sheet.rowMeta[rowIndex], values };
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
dropColumn(colIndex: string): RestoreAxis {
|
|
197
|
+
const range = {
|
|
198
|
+
from: addressFromIndex(this._sheet, `${colIndex}@${this._sheet.rows[0]}`),
|
|
199
|
+
to: addressFromIndex(this._sheet, `${colIndex}@${this._sheet.rows[this._sheet.rows.length - 1]}`),
|
|
200
|
+
};
|
|
201
|
+
const values = this.getCellValues(range).flat();
|
|
202
|
+
const index = this._sheet.columns.indexOf(colIndex);
|
|
203
|
+
this.clear(range);
|
|
204
|
+
this._sheet.columns.splice(index, 1);
|
|
205
|
+
delete this._sheet.columnMeta[colIndex];
|
|
206
|
+
this.reset();
|
|
207
|
+
return { axis: 'col', index, axisIndex: colIndex, axisMeta: this._sheet.rowMeta[colIndex], values };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
restoreRow({ index, axisIndex, axisMeta, values }: RestoreAxis) {
|
|
211
|
+
this._sheet.rows.splice(index, 0, axisIndex);
|
|
212
|
+
values.forEach((value, col) => {
|
|
213
|
+
if (value) {
|
|
214
|
+
this._sheet.cells[`${this._sheet.columns[col]}@${axisIndex}`] = { value };
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
if (axisMeta) {
|
|
218
|
+
this._sheet.rowMeta[axisIndex] = axisMeta;
|
|
219
|
+
}
|
|
220
|
+
this.reset();
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
restoreColumn({ index, axisIndex, axisMeta, values }: RestoreAxis) {
|
|
224
|
+
this._sheet.columns.splice(index, 0, axisIndex);
|
|
225
|
+
values.forEach((value, row) => {
|
|
226
|
+
if (value) {
|
|
227
|
+
this._sheet.cells[`${axisIndex}@${this._sheet.rows[row]}`] = { value };
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
if (axisMeta) {
|
|
231
|
+
this._sheet.columnMeta[axisIndex] = axisMeta;
|
|
232
|
+
}
|
|
164
233
|
this.reset();
|
|
165
234
|
}
|
|
166
235
|
|
|
@@ -265,8 +334,11 @@ export class SheetModel extends Resource {
|
|
|
265
334
|
getValue(cell: CellAddress): CellScalarValue {
|
|
266
335
|
// Applies rounding and post-processing.
|
|
267
336
|
invariant(this._node);
|
|
268
|
-
const
|
|
337
|
+
const address = toSimpleCellAddress(this._node.sheetId, cell);
|
|
338
|
+
const value = this._node.graph.hf.getCellValue(address);
|
|
269
339
|
if (value instanceof DetailedCellError) {
|
|
340
|
+
// TODO(wittjosiah): Error details should be shown in cell `title`.
|
|
341
|
+
log.info('cell error', { cell, error: value });
|
|
270
342
|
return value.toString();
|
|
271
343
|
}
|
|
272
344
|
|
|
@@ -276,7 +348,7 @@ export class SheetModel extends Resource {
|
|
|
276
348
|
/**
|
|
277
349
|
* Get value type.
|
|
278
350
|
*/
|
|
279
|
-
|
|
351
|
+
getValueDescription(cell: CellAddress): { type: TypeEnum; format?: FormatEnum } | undefined {
|
|
280
352
|
invariant(this._node);
|
|
281
353
|
const addr = toSimpleCellAddress(this._node.sheetId, cell);
|
|
282
354
|
const type = this._node.graph.hf.getCellValueDetailedType(addr);
|
package/src/translations.ts
CHANGED
|
@@ -14,10 +14,13 @@ export default [
|
|
|
14
14
|
'create sheet section label': 'Create sheet',
|
|
15
15
|
'cell placeholder': 'Cell value...',
|
|
16
16
|
'range key alignment label': 'Align',
|
|
17
|
-
'range
|
|
18
|
-
'range value
|
|
19
|
-
'range value
|
|
20
|
-
'
|
|
17
|
+
'range key style label': 'Style',
|
|
18
|
+
'range value start label': 'Align left',
|
|
19
|
+
'range value center label': 'Align center',
|
|
20
|
+
'range value end label': 'Align right',
|
|
21
|
+
'range value softwrap label': 'Wrap text',
|
|
22
|
+
'range value highlight label': 'Highlight',
|
|
23
|
+
'toolbar action label': '{{value}}',
|
|
21
24
|
'selection overlaps existing comment label': 'Selected cell already has a comment',
|
|
22
25
|
'comment label': 'Add comment',
|
|
23
26
|
'comment ranges not supported label': 'Commenting on ranges is not yet supported',
|
|
@@ -30,7 +33,9 @@ export default [
|
|
|
30
33
|
'add row after label': 'Add row after',
|
|
31
34
|
'delete row label': 'Delete row',
|
|
32
35
|
'range list heading': 'Ranges',
|
|
33
|
-
'range title': '{{position}} — {{
|
|
36
|
+
'range title': '{{position}} — {{value}}',
|
|
37
|
+
'col dropped label': 'Deleted a column',
|
|
38
|
+
'row dropped label': 'Deleted a row',
|
|
34
39
|
},
|
|
35
40
|
},
|
|
36
41
|
},
|
package/src/types.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
MetadataRecordsProvides,
|
|
9
9
|
SurfaceProvides,
|
|
10
10
|
TranslationsProvides,
|
|
11
|
+
IntentData,
|
|
11
12
|
} from '@dxos/app-framework';
|
|
12
13
|
import { ref, S, TypedObject } from '@dxos/echo-schema';
|
|
13
14
|
import { type SchemaProvides } from '@dxos/plugin-client';
|
|
@@ -15,13 +16,32 @@ import { type MarkdownExtensionProvides } from '@dxos/plugin-markdown';
|
|
|
15
16
|
import { type SpaceInitProvides } from '@dxos/plugin-space';
|
|
16
17
|
import { ThreadType } from '@dxos/plugin-space/types';
|
|
17
18
|
import { type StackProvides } from '@dxos/plugin-stack';
|
|
19
|
+
import { type DxGridAxis } from '@dxos/react-ui-grid';
|
|
18
20
|
|
|
19
21
|
import { SHEET_PLUGIN } from './meta';
|
|
22
|
+
import { type SheetModel } from './model';
|
|
20
23
|
|
|
21
24
|
const SHEET_ACTION = `${SHEET_PLUGIN}/action`;
|
|
22
25
|
|
|
23
26
|
export enum SheetAction {
|
|
24
27
|
CREATE = `${SHEET_ACTION}/create`,
|
|
28
|
+
INSERT_AXIS = `${SHEET_ACTION}/axis-insert`,
|
|
29
|
+
DROP_AXIS = `${SHEET_ACTION}/axis-drop`,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type RestoreAxis = {
|
|
33
|
+
axis: DxGridAxis;
|
|
34
|
+
axisIndex: string;
|
|
35
|
+
index: number;
|
|
36
|
+
axisMeta?: S.Schema.Type<typeof RowColumnMeta>;
|
|
37
|
+
values: CellScalarValue[];
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export namespace SheetAction {
|
|
41
|
+
export type Create = IntentData<{ sheet: SheetType }>;
|
|
42
|
+
export type InsertAxis = IntentData<{ model: SheetModel; axis: DxGridAxis; index: number; count?: number }>;
|
|
43
|
+
export type DropAxis = IntentData<{ model: SheetModel; axis: DxGridAxis; axisIndex: string }>;
|
|
44
|
+
export type DropAxisRestore = IntentData<RestoreAxis & { model: SheetModel }>;
|
|
25
45
|
}
|
|
26
46
|
|
|
27
47
|
// TODO(Zan): Move this to the plugin-space plugin or another common location
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/SheetContainer/SheetContainer.tsx", "../../../src/components/FunctionEditor/FunctionEditor.tsx", "../../../src/components/Toolbar/Toolbar.tsx", "../../../src/components/SheetContainer/index.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { type Space } from '@dxos/react-client/echo';\n\nimport { type SheetType } from '../../types';\nimport { useComputeGraph } from '../ComputeGraph';\nimport { FunctionEditor } from '../FunctionEditor';\nimport { GridSheet } from '../GridSheet';\nimport { SheetProvider } from '../SheetContext';\nimport { Toolbar } from '../Toolbar';\n\nexport const SheetContainer = ({ space, sheet, role }: { space: Space; sheet: SheetType; role?: string }) => {\n const graph = useComputeGraph(space);\n\n return graph ? (\n <SheetProvider sheet={sheet} graph={graph}>\n <Toolbar.Root role={role}>\n <Toolbar.Styles />\n <Toolbar.Alignment />\n <Toolbar.Separator />\n <Toolbar.Actions />\n </Toolbar.Root>\n <div role='none' className='border-bs border-separator grid cols-1 rows-[1fr_min-content] min-bs-0'>\n <GridSheet />\n <FunctionEditor />\n </div>\n </SheetProvider>\n ) : null;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\n\nimport { Icon } from '@dxos/react-ui';\nimport { mx } from '@dxos/react-ui-theme';\n\nimport { addressToA1Notation, isFormula, rangeToA1Notation } from '../../defs';\nimport { useSheetContext } from '../SheetContext';\n\nexport const FunctionEditor = () => {\n const { model, cursor, range } = useSheetContext();\n\n let value;\n let formula = false;\n if (cursor) {\n value = model.getCellValue(cursor);\n if (isFormula(value)) {\n value = model.graph.mapFunctionBindingFromId(model.mapFormulaIndicesToRefs(value));\n formula = true;\n } else if (value != null) {\n value = String(value);\n }\n }\n\n return (\n <div\n className={mx(\n 'flex shrink-0 justify-between items-center px-4 py-1 text-sm border-bs !border-separator attention-surface',\n )}\n >\n <div className='flex gap-4 items-center'>\n <div className='flex w-16 items-center font-mono'>\n {(range && rangeToA1Notation(range)) || (cursor && addressToA1Notation(cursor))}\n </div>\n <div className='flex gap-2 items-center'>\n <Icon icon='ph--function--regular' classNames={['text-greenText', formula ? 'visible' : 'invisible']} />\n <span className='font-mono'>{value}</span>\n </div>\n </div>\n </div>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { createContext } from '@radix-ui/react-context';\nimport React, { type PropsWithChildren, useCallback, useMemo } from 'react';\n\nimport { useIntentDispatcher } from '@dxos/app-framework';\nimport {\n Icon,\n type ThemedClassName,\n Toolbar as NaturalToolbar,\n type ToolbarButtonProps as NaturalToolbarButtonProps,\n type ToolbarToggleGroupItemProps as NaturalToolbarToggleGroupItemProps,\n type ToolbarToggleProps as NaturalToolbarToggleProps,\n Tooltip,\n useTranslation,\n} from '@dxos/react-ui';\nimport { useAttention } from '@dxos/react-ui-attention';\nimport { nonNullable } from '@dxos/util';\n\nimport {\n alignKey,\n type AlignKey,\n type AlignValue,\n type CommentKey,\n type CommentValue,\n inRange,\n rangeFromIndex,\n rangeToIndex,\n type StyleKey,\n type StyleValue,\n} from '../../defs';\nimport { completeCellRangeToThreadCursor } from '../../integrations';\nimport { SHEET_PLUGIN } from '../../meta';\nimport { type SheetType } from '../../types';\nimport { useSheetContext } from '../SheetContext';\n\n//\n// Buttons\n//\n\nconst buttonStyles = 'min-bs-0 p-2';\nconst tooltipProps = { side: 'bottom' as const, classNames: 'z-10' };\n\nconst ToolbarSeparator = () => <div role='separator' className='grow' />;\n\n//\n// ToolbarItem\n//\n\ntype ToolbarItemProps =\n | (NaturalToolbarButtonProps & { itemType: 'button'; icon: string })\n | (NaturalToolbarToggleGroupItemProps & { itemType: 'toggleGroupItem'; icon: string })\n | (NaturalToolbarToggleProps & { itemType: 'toggle'; icon: string });\n\nexport const ToolbarItem = ({ itemType, icon, children, ...props }: ToolbarItemProps) => {\n const Invoker =\n itemType === 'toggleGroupItem'\n ? NaturalToolbar.ToggleGroupItem\n : itemType === 'toggle'\n ? NaturalToolbar.Toggle\n : NaturalToolbar.Button;\n return (\n <Tooltip.Root>\n <Tooltip.Trigger asChild>\n {/* TODO(thure): type the props spread better. */}\n <Invoker variant='ghost' {...(props as any)} classNames={buttonStyles}>\n <Icon icon={icon} size={5} />\n <span className='sr-only'>{children}</span>\n </Invoker>\n </Tooltip.Trigger>\n <Tooltip.Portal>\n <Tooltip.Content {...tooltipProps}>\n {children}\n <Tooltip.Arrow />\n </Tooltip.Content>\n </Tooltip.Portal>\n </Tooltip.Root>\n );\n};\n\n//\n// Root\n//\n\ntype AlignAction = { key: AlignKey; value: AlignValue };\ntype CommentAction = { key: CommentKey; value: CommentValue; cellContent?: string };\ntype StyleAction = { key: StyleKey; value: StyleValue };\n\nexport type ToolbarAction = StyleAction | AlignAction | CommentAction;\n\nexport type ToolbarActionType = ToolbarAction['key'];\n\nexport type ToolbarActionHandler = (action: ToolbarAction) => void;\n\nexport type ToolbarProps = ThemedClassName<\n PropsWithChildren<{\n role?: string;\n }>\n>;\n\nconst [ToolbarContextProvider, useToolbarContext] = createContext<{ onAction: (action: ToolbarAction) => void }>(\n 'Toolbar',\n);\n\n// TODO(Zan): Factor out, copied this from MarkdownPlugin.\nconst sectionToolbarLayout =\n 'bs-[--rail-action] bg-[--sticky-bg] sticky block-start-0 __-block-start-px transition-opacity';\n\ntype Range = SheetType['ranges'][number];\n\nconst ToolbarRoot = ({ children, role, classNames }: ToolbarProps) => {\n const { id, model, cursorFallbackRange, cursor } = useSheetContext();\n const { hasAttention } = useAttention(id);\n const dispatch = useIntentDispatcher();\n\n // TODO(Zan): Externalize the toolbar action handler. E.g., Toolbar/keys should both fire events.\n const handleAction = useCallback(\n (action: ToolbarAction) => {\n switch (action.key) {\n case 'alignment':\n if (cursor && cursorFallbackRange) {\n const index = model.sheet.ranges?.findIndex(\n (range) => range.key === action.key && inRange(rangeFromIndex(model.sheet, range.range), cursor),\n );\n const nextRangeEntity = {\n range: rangeToIndex(model.sheet, cursorFallbackRange),\n key: action.key,\n value: action.value,\n };\n if (index < 0) {\n model.sheet.ranges?.push(nextRangeEntity);\n } else {\n model.sheet.ranges?.splice(index, 1, nextRangeEntity);\n }\n }\n break;\n case 'style':\n if (action.value === 'unset') {\n const index = model.sheet.ranges?.findIndex((range) => range.key === action.key);\n if (index >= 0) {\n model.sheet.ranges?.splice(index, 1);\n }\n } else if (cursorFallbackRange) {\n model.sheet.ranges?.push({\n range: rangeToIndex(model.sheet, cursorFallbackRange),\n key: action.key,\n value: action.value,\n });\n }\n break;\n case 'comment': {\n // TODO(Zan): We shouldn't hardcode the action ID.\n if (cursorFallbackRange) {\n void dispatch({\n action: 'dxos.org/plugin/thread/action/create',\n data: {\n cursor: completeCellRangeToThreadCursor(cursorFallbackRange),\n name: action.cellContent,\n subject: model.sheet,\n },\n });\n }\n }\n }\n },\n [model.sheet, cursorFallbackRange, cursor, dispatch],\n );\n\n return (\n <ToolbarContextProvider onAction={handleAction}>\n <NaturalToolbar.Root\n classNames={[\n ...(role === 'section'\n ? ['z-[2] group-focus-within/section:visible', !hasAttention && 'invisible', sectionToolbarLayout]\n : ['attention-surface']),\n classNames,\n ]}\n >\n {children}\n </NaturalToolbar.Root>\n </ToolbarContextProvider>\n );\n};\n\n// TODO(burdon): Generalize.\n// TODO(burdon): Detect and display current state.\ntype ButtonProps<T> = {\n value: T;\n icon: string;\n disabled?: (state: Range) => boolean;\n};\n\n//\n// Alignment\n//\n\nconst alignmentOptions: ButtonProps<AlignValue>[] = [\n { value: 'start', icon: 'ph--text-align-left--regular' },\n { value: 'center', icon: 'ph--text-align-center--regular' },\n { value: 'end', icon: 'ph--text-align-right--regular' },\n];\n\nconst Alignment = () => {\n const { cursor, model } = useSheetContext();\n const { onAction } = useToolbarContext('Alignment');\n const { t } = useTranslation(SHEET_PLUGIN);\n\n const value = useMemo(\n () =>\n cursor\n ? model.sheet.ranges?.find(\n ({ range, key }) => key === alignKey && inRange(rangeFromIndex(model.sheet, range), cursor),\n )?.value\n : undefined,\n [cursor, model.sheet.ranges],\n );\n\n return (\n <NaturalToolbar.ToggleGroup\n type='single'\n value={value}\n onValueChange={(value: AlignValue) => onAction?.({ key: alignKey, value })}\n >\n {alignmentOptions.map(({ value, icon }) => (\n <ToolbarItem itemType='toggleGroupItem' key={value} value={value} icon={icon}>\n {t('toolbar action label', {\n key: t(`range key ${alignKey} label`),\n value: t(`range value ${value} label`),\n })}\n </ToolbarItem>\n ))}\n </NaturalToolbar.ToggleGroup>\n );\n};\n\nconst styleOptions: ButtonProps<StyleValue>[] = [{ value: 'highlight', icon: 'ph--highlighter--regular' }];\n\nconst Styles = () => {\n const { cursor, model } = useSheetContext();\n const { onAction } = useToolbarContext('Styles');\n const { t } = useTranslation(SHEET_PLUGIN);\n\n const activeValues = useMemo(\n () =>\n cursor\n ? model.sheet.ranges\n ?.filter(({ range, key }) => key === 'style' && inRange(rangeFromIndex(model.sheet, range), cursor))\n .reduce((acc, { value }) => {\n acc.add(value);\n return acc;\n }, new Set())\n : undefined,\n [cursor, model.sheet.ranges],\n );\n\n return (\n <>\n {styleOptions.map(({ value, icon }) => (\n <ToolbarItem\n itemType='toggle'\n key={value}\n pressed={activeValues?.has(value)}\n onPressedChange={(nextPressed: boolean) => onAction?.({ key: 'style', value: nextPressed ? value : 'unset' })}\n icon={icon}\n >\n {t(`toolbar ${value} label`)}\n </ToolbarItem>\n ))}\n </>\n );\n};\n\n//\n// Actions\n//\n\nconst Actions = () => {\n const { onAction } = useToolbarContext('Actions');\n const { cursorFallbackRange, cursor, model } = useSheetContext();\n const { t } = useTranslation(SHEET_PLUGIN);\n\n const overlapsCommentAnchor = (model.sheet.threads ?? [])\n .filter(nonNullable)\n .filter((thread) => thread.status !== 'resolved')\n .some((thread) => {\n if (!cursorFallbackRange) {\n return false;\n }\n return rangeToIndex(model.sheet, cursorFallbackRange) === thread.anchor;\n });\n\n const tooltipLabelKey = !cursor\n ? 'no cursor label'\n : overlapsCommentAnchor\n ? 'selection overlaps existing comment label'\n : 'comment label';\n\n return (\n <ToolbarItem\n itemType='button'\n value='comment'\n icon='ph--chat-text--regular'\n data-testid='editor.toolbar.comment'\n onClick={() => {\n if (!(cursorFallbackRange && cursor)) {\n return;\n }\n return onAction?.({\n key: 'comment',\n value: rangeToIndex(model.sheet, cursorFallbackRange),\n cellContent: model.getCellText(cursor),\n });\n }}\n disabled={!cursor || overlapsCommentAnchor}\n >\n {t(tooltipLabelKey)}\n </ToolbarItem>\n );\n};\n\nexport const Toolbar = {\n Root: ToolbarRoot,\n Separator: ToolbarSeparator,\n Alignment,\n Styles,\n Actions,\n};\n\nexport { useToolbarContext };\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { SheetContainer } from './SheetContainer';\n\nexport default SheetContainer;\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAIA,OAAOA,YAAW;;;ACAlB,OAAOC,WAAW;AAElB,SAASC,YAAY;AACrB,SAASC,UAAU;AAKZ,IAAMC,iBAAiB,MAAA;AAC5B,QAAM,EAAEC,OAAOC,QAAQC,MAAK,IAAKC,gBAAAA;AAEjC,MAAIC;AACJ,MAAIC,UAAU;AACd,MAAIJ,QAAQ;AACVG,YAAQJ,MAAMM,aAAaL,MAAAA;AAC3B,QAAIM,UAAUH,KAAAA,GAAQ;AACpBA,cAAQJ,MAAMQ,MAAMC,yBAAyBT,MAAMU,wBAAwBN,KAAAA,CAAAA;AAC3EC,gBAAU;IACZ,WAAWD,SAAS,MAAM;AACxBA,cAAQO,OAAOP,KAAAA;IACjB;EACF;AAEA,SACE,sBAAA,cAACQ,OAAAA;IACCC,WAAWC,GACT,4GAAA;KAGF,sBAAA,cAACF,OAAAA;IAAIC,WAAU;KACb,sBAAA,cAACD,OAAAA;IAAIC,WAAU;KACXX,SAASa,kBAAkBb,KAAAA,KAAYD,UAAUe,oBAAoBf,MAAAA,CAAAA,GAEzE,sBAAA,cAACW,OAAAA;IAAIC,WAAU;KACb,sBAAA,cAACI,MAAAA;IAAKC,MAAK;IAAwBC,YAAY;MAAC;MAAkBd,UAAU,YAAY;;MACxF,sBAAA,cAACe,QAAAA;IAAKP,WAAU;KAAaT,KAAAA,CAAAA,CAAAA,CAAAA;AAKvC;;;ACxCA,SAASiB,qBAAqB;AAC9B,OAAOC,UAAiCC,aAAaC,eAAe;AAEpE,SAASC,2BAA2B;AACpC,SACEC,QAAAA,OAEAC,W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AAMC,kBAAkB,CAAC7D,SACrB,oBACAsD,wBACE,8CACA;AAEN,SACE,gBAAAvF,OAAA,cAACI,aAAAA;IACCC,UAAS;IACT+C,OAAM;IACN9C,MAAK;IACLyF,eAAY;IACZC,SAAS,MAAA;AACP,UAAI,EAAEhE,uBAAuBC,SAAS;AACpC;MACF;AACA,aAAO2B,WAAW;QAChBlB,KAAK;QACLU,OAAOD,aAAapB,MAAMa,OAAOZ,mBAAAA;QACjC0B,aAAa3B,MAAMkE,YAAYhE,MAAAA;MACjC,CAAA;IACF;IACAiE,UAAU,CAACjE,UAAUsD;KAEpBxB,EAAE+B,eAAAA,CAAAA;AAGT;AAEO,IAAMK,UAAU;EACrBpF,MAAMc;EACNuE,WAAWrG;EACX+D;EACAa;EACAW;AACF;;;AFzTO,IAAMe,iBAAiB,CAAC,EAAEC,OAAOC,OAAOC,KAAI,MAAqD;AACtG,QAAMC,QAAQC,gBAAgBJ,KAAAA;AAE9B,SAAOG,QACL,gBAAAE,OAAA,cAACC,eAAAA;IAAcL;IAAcE;KAC3B,gBAAAE,OAAA,cAACE,QAAQC,MAAI;IAACN;KACZ,gBAAAG,OAAA,cAACE,QAAQE,QAAM,IAAA,GACf,gBAAAJ,OAAA,cAACE,QAAQG,WAAS,IAAA,GAClB,gBAAAL,OAAA,cAACE,QAAQI,WAAS,IAAA,GAClB,gBAAAN,OAAA,cAACE,QAAQK,SAAO,IAAA,CAAA,GAElB,gBAAAP,OAAA,cAACQ,OAAAA;IAAIX,MAAK;IAAOY,WAAU;KACzB,gBAAAT,OAAA,cAACU,WAAAA,IAAAA,GACD,gBAAAV,OAAA,cAACW,gBAAAA,IAAAA,CAAAA,CAAAA,IAGH;AACN;;;AG1BA,IAAA,yBAAeC;",
|
|
6
|
-
"names": ["React", "React", "Icon", "mx", "FunctionEditor", "model", "cursor", "range", "useSheetContext", "value", "formula", "getCellValue", "isFormula", "graph", "mapFunctionBindingFromId", "mapFormulaIndicesToRefs", "String", "div", "className", "mx", "rangeToA1Notation", "addressToA1Notation", "Icon", "icon", "classNames", "span", "createContext", "React", "useCallback", "useMemo", "useIntentDispatcher", "Icon", "Toolbar", "NaturalToolbar", "Tooltip", "useTranslation", "useAttention", "nonNullable", "buttonStyles", "tooltipProps", "side", "classNames", "ToolbarSeparator", "React", "div", "role", "className", "ToolbarItem", "itemType", "icon", "children", "props", "Invoker", "NaturalToolbar", "ToggleGroupItem", "Toggle", "Button", "Tooltip", "Root", "Trigger", "asChild", "variant", "Icon", "size", "span", "Portal", "Content", "Arrow", "ToolbarContextProvider", "useToolbarContext", "createContext", "sectionToolbarLayout", "ToolbarRoot", "id", "model", "cursorFallbackRange", "cursor", "useSheetContext", "hasAttention", "useAttention", "dispatch", "useIntentDispatcher", "handleAction", "useCallback", "action", "key", "index", "sheet", "ranges", "findIndex", "range", "inRange", "rangeFromIndex", "nextRangeEntity", "rangeToIndex", "value", "push", "splice", "data", "completeCellRangeToThreadCursor", "name", "cellContent", "subject", "onAction", "alignmentOptions", "Alignment", "t", "useTranslation", "SHEET_PLUGIN", "useMemo", "find", "alignKey", "undefined", "ToggleGroup", "type", "onValueChange", "map", "styleOptions", "Styles", "activeValues", "filter", "reduce", "acc", "add", "Set", "pressed", "has", "onPressedChange", "nextPressed", "Actions", "overlapsCommentAnchor", "threads", "nonNullable", "thread", "status", "some", "anchor", "tooltipLabelKey", "data-testid", "onClick", "getCellText", "disabled", "Toolbar", "Separator", "SheetContainer", "space", "sheet", "role", "graph", "useComputeGraph", "React", "SheetProvider", "Toolbar", "Root", "Styles", "Alignment", "Separator", "Actions", "div", "className", "GridSheet", "FunctionEditor", "SheetContainer"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/types.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport type {\n GraphBuilderProvides,\n IntentResolverProvides,\n MetadataRecordsProvides,\n SurfaceProvides,\n TranslationsProvides,\n} from '@dxos/app-framework';\nimport { ref, S, TypedObject } from '@dxos/echo-schema';\nimport { type SchemaProvides } from '@dxos/plugin-client';\nimport { type MarkdownExtensionProvides } from '@dxos/plugin-markdown';\nimport { type SpaceInitProvides } from '@dxos/plugin-space';\nimport { ThreadType } from '@dxos/plugin-space/types';\nimport { type StackProvides } from '@dxos/plugin-stack';\n\nimport { SHEET_PLUGIN } from './meta';\n\nconst SHEET_ACTION = `${SHEET_PLUGIN}/action`;\n\nexport enum SheetAction {\n CREATE = `${SHEET_ACTION}/create`,\n}\n\n// TODO(Zan): Move this to the plugin-space plugin or another common location\n// when we implement comments in sheets.\n// This is currently duplicated in a few places.\ntype ThreadProvides<T> = {\n thread: {\n predicate: (obj: any) => obj is T;\n createSort: (obj: T) => (anchorA: string | undefined, anchorB: string | undefined) => number;\n };\n};\n\nexport type SheetPluginProvides = SurfaceProvides &\n IntentResolverProvides &\n GraphBuilderProvides &\n MarkdownExtensionProvides &\n MetadataRecordsProvides &\n TranslationsProvides &\n SchemaProvides &\n SpaceInitProvides &\n StackProvides &\n ThreadProvides<SheetType>;\n\nexport type CellScalarValue = number | string | boolean | null;\n\nexport const CellValue = S.Struct({\n // TODO(burdon): How to store dates (datetime, date, time), percentages, etc.\n // Consider import/export; natural access for other plugins. Special handling for currency (precision).\n // TODO(burdon): Automerge (long string) or short string or number.\n value: S.Any,\n});\n\nexport type CellValue = S.Schema.Type<typeof CellValue>;\n\n// TODO(burdon): IMPORTANT: Reconcile with Field definition.\nexport const Range = S.Struct({\n range: S.String,\n key: S.String,\n value: S.String,\n});\n\nexport type Range = S.Schema.Type<typeof Range>;\n\n// TODO(burdon): Visibility, locked, frozen, etc.\nexport const RowColumnMeta = S.Struct({\n size: S.optional(S.Number),\n});\n\n// TODO(burdon): Index to all updates when rows/columns are inserted/deleted.\nexport class SheetType extends TypedObject({ typename: 'dxos.org/type/Sheet', version: '0.1.0' })({\n name: S.optional(S.String),\n\n // Sparse map of cells referenced by index.\n cells: S.mutable(S.Record({ key: S.String, value: S.mutable(CellValue) })),\n\n // Ordered row indices.\n rows: S.mutable(S.Array(S.String)),\n\n // Ordered column indices.\n columns: S.mutable(S.Array(S.String)),\n\n // Row metadata referenced by index.\n rowMeta: S.mutable(S.Record({ key: S.String, value: S.mutable(RowColumnMeta) })),\n\n // Column metadata referenced by index.\n columnMeta: S.mutable(S.Record({ key: S.String, value: S.mutable(RowColumnMeta) })),\n\n // Cell formatting referenced by indexed range.\n ranges: S.mutable(S.Array(Range)),\n\n // Threads associated with the sheet\n threads: S.optional(S.mutable(S.Array(ref(ThreadType)))),\n}) {}\n\nexport type SheetSize = {\n rows: number;\n columns: number;\n};\n\nexport type CreateSheetOptions = {\n name?: string;\n cells?: Record<string, CellValue>;\n} & Partial<SheetSize>;\n"],
|
|
5
|
-
"mappings": ";;;;;AAWA,SAASA,KAAKC,GAAGC,mBAAmB;AAIpC,SAASC,kBAAkB;AAK3B,IAAMC,eAAe,GAAGC,YAAAA;;UAEZC,cAAAA;wCACD,GAAGF,YAAAA,SAAqB,IAAA;GADvBE,gBAAAA,cAAAA,CAAAA,EAAAA;AA2BL,IAAMC,YAAYC,EAAEC,OAAO;;;;EAIhCC,OAAOF,EAAEG;AACX,CAAA;AAKO,IAAMC,QAAQJ,EAAEC,OAAO;EAC5BI,OAAOL,EAAEM;EACTC,KAAKP,EAAEM;EACPJ,OAAOF,EAAEM;AACX,CAAA;AAKO,IAAME,gBAAgBR,EAAEC,OAAO;EACpCQ,MAAMT,EAAEU,SAASV,EAAEW,MAAM;AAC3B,CAAA;AAGO,IAAMC,YAAN,cAAwBC,YAAY;EAAEC,UAAU;EAAuBC,SAAS;AAAQ,CAAA,EAAG;EAChGC,MAAMhB,EAAEU,SAASV,EAAEM,MAAM;;EAGzBW,OAAOjB,EAAEkB,QAAQlB,EAAEmB,OAAO;IAAEZ,KAAKP,EAAEM;IAAQJ,OAAOF,EAAEkB,QAAQnB,SAAAA;EAAW,CAAA,CAAA;;EAGvEqB,MAAMpB,EAAEkB,QAAQlB,EAAEqB,MAAMrB,EAAEM,MAAM,CAAA;;EAGhCgB,SAAStB,EAAEkB,QAAQlB,EAAEqB,MAAMrB,EAAEM,MAAM,CAAA;;EAGnCiB,SAASvB,EAAEkB,QAAQlB,EAAEmB,OAAO;IAAEZ,KAAKP,EAAEM;IAAQJ,OAAOF,EAAEkB,QAAQV,aAAAA;EAAe,CAAA,CAAA;;EAG7EgB,YAAYxB,EAAEkB,QAAQlB,EAAEmB,OAAO;IAAEZ,KAAKP,EAAEM;IAAQJ,OAAOF,EAAEkB,QAAQV,aAAAA;EAAe,CAAA,CAAA;;EAGhFiB,QAAQzB,EAAEkB,QAAQlB,EAAEqB,MAAMjB,KAAAA,CAAAA;;EAG1BsB,SAAS1B,EAAEU,SAASV,EAAEkB,QAAQlB,EAAEqB,MAAMM,IAAIC,UAAAA,CAAAA,CAAAA,CAAAA;AAC5C,CAAA,EAAA;AAAI;",
|
|
6
|
-
"names": ["ref", "S", "TypedObject", "ThreadType", "SHEET_ACTION", "SHEET_PLUGIN", "SheetAction", "CellValue", "S", "Struct", "value", "Any", "Range", "range", "String", "key", "RowColumnMeta", "size", "optional", "Number", "SheetType", "TypedObject", "typename", "version", "name", "cells", "mutable", "Record", "rows", "Array", "columns", "rowMeta", "columnMeta", "ranges", "threads", "ref", "ThreadType"]
|
|
7
|
-
}
|