@dxos/plugin-sheet 0.8.4-main.1da679c → 0.8.4-main.21d9917
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-ESCXPI7Y.mjs +397 -0
- package/dist/lib/browser/SheetContainer-ESCXPI7Y.mjs.map +7 -0
- package/dist/lib/browser/anchor-sort-JBRMW6OY.mjs +23 -0
- package/dist/lib/browser/anchor-sort-JBRMW6OY.mjs.map +7 -0
- package/dist/lib/browser/chunk-2SAGT3BB.mjs +397 -0
- package/dist/lib/browser/chunk-2SAGT3BB.mjs.map +7 -0
- package/dist/lib/browser/{chunk-SSN4HYJL.mjs → chunk-IFLWVS2V.mjs} +9 -9
- package/dist/lib/browser/chunk-IFLWVS2V.mjs.map +7 -0
- package/dist/lib/browser/chunk-W6N44ONZ.mjs +1470 -0
- package/dist/lib/browser/chunk-W6N44ONZ.mjs.map +7 -0
- package/dist/lib/browser/compute-graph-registry-DL2PX7TF.mjs +21 -0
- package/dist/lib/browser/compute-graph-registry-DL2PX7TF.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +71 -82
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/markdown-BC4KBDUO.mjs +29 -0
- package/dist/lib/browser/markdown-BC4KBDUO.mjs.map +7 -0
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/operation-resolver-FJ4UWZUM.mjs +79 -0
- package/dist/lib/browser/operation-resolver-FJ4UWZUM.mjs.map +7 -0
- package/dist/lib/browser/react-surface-5BXM6TJ3.mjs +51 -0
- package/dist/lib/browser/react-surface-5BXM6TJ3.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +7 -12
- package/dist/lib/node-esm/SheetContainer-YVIDJKP4.mjs +398 -0
- package/dist/lib/node-esm/SheetContainer-YVIDJKP4.mjs.map +7 -0
- package/dist/lib/node-esm/anchor-sort-C3XFPI6S.mjs +24 -0
- package/dist/lib/node-esm/anchor-sort-C3XFPI6S.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-IMWGSIDG.mjs +398 -0
- package/dist/lib/node-esm/chunk-IMWGSIDG.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-IK4O7FUJ.mjs → chunk-PPOYR7DK.mjs} +9 -9
- package/dist/lib/node-esm/chunk-PPOYR7DK.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-S7RYX7DG.mjs +1471 -0
- package/dist/lib/node-esm/chunk-S7RYX7DG.mjs.map +7 -0
- package/dist/lib/node-esm/compute-graph-registry-VXH55GDI.mjs +22 -0
- package/dist/lib/node-esm/compute-graph-registry-VXH55GDI.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +71 -82
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/markdown-6DGZCJRM.mjs +30 -0
- package/dist/lib/node-esm/markdown-6DGZCJRM.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/operation-resolver-OGXEUWHA.mjs +80 -0
- package/dist/lib/node-esm/operation-resolver-OGXEUWHA.mjs.map +7 -0
- package/dist/lib/node-esm/react-surface-RLHC6B77.mjs +52 -0
- package/dist/lib/node-esm/react-surface-RLHC6B77.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +7 -12
- package/dist/types/src/SheetPlugin.d.ts +2 -1
- package/dist/types/src/SheetPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/anchor-sort/anchor-sort.d.ts +5 -0
- package/dist/types/src/capabilities/anchor-sort/anchor-sort.d.ts.map +1 -0
- package/dist/types/src/capabilities/anchor-sort/index.d.ts +3 -0
- package/dist/types/src/capabilities/anchor-sort/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/compute-graph-registry/compute-graph-registry.d.ts +5 -0
- package/dist/types/src/capabilities/compute-graph-registry/compute-graph-registry.d.ts.map +1 -0
- package/dist/types/src/capabilities/compute-graph-registry/index.d.ts +3 -0
- package/dist/types/src/capabilities/compute-graph-registry/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +5 -9
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/markdown/index.d.ts +3 -0
- package/dist/types/src/capabilities/markdown/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/markdown/markdown.d.ts +5 -0
- package/dist/types/src/capabilities/markdown/markdown.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-resolver/index.d.ts +3 -0
- package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +5 -0
- package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
- package/dist/types/src/components/ComputeGraph/compute-graph.stories.d.ts +0 -1
- package/dist/types/src/components/ComputeGraph/compute-graph.stories.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +4 -3
- package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -1
- package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts +2 -3
- 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 +2 -2
- package/dist/types/src/components/RangeList/RangeList.d.ts.map +1 -1
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +5 -6
- package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -1
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +8 -6
- package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -1
- package/dist/types/src/components/SheetContext/SheetContext.d.ts +2 -2
- package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -1
- package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts +3 -4
- package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts.map +1 -1
- package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts +3 -2
- package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/SheetToolbar/align.d.ts +12 -19
- package/dist/types/src/components/SheetToolbar/align.d.ts.map +1 -1
- package/dist/types/src/components/SheetToolbar/style.d.ts +12 -18
- package/dist/types/src/components/SheetToolbar/style.d.ts.map +1 -1
- package/dist/types/src/components/SheetToolbar/useToolbarState.d.ts +14 -1
- package/dist/types/src/components/SheetToolbar/useToolbarState.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/extensions/compute.stories.d.ts +2 -3
- package/dist/types/src/extensions/compute.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/editor/sheet-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.map +1 -1
- package/dist/types/src/meta.d.ts +2 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/model/sheet-model.d.ts +6 -6
- package/dist/types/src/model/sheet-model.d.ts.map +1 -1
- package/dist/types/src/model/testing.d.ts +2 -2
- package/dist/types/src/model/testing.d.ts.map +1 -1
- package/dist/types/src/model/useSheetModel.d.ts +2 -2
- package/dist/types/src/model/useSheetModel.d.ts.map +1 -1
- package/dist/types/src/serializer.d.ts +2 -2
- package/dist/types/src/serializer.d.ts.map +1 -1
- package/dist/types/src/testing/data.d.ts +2 -2
- package/dist/types/src/testing/data.d.ts.map +1 -1
- package/dist/types/src/testing/testing.d.ts +27 -3
- package/dist/types/src/testing/testing.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +3 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Sheet.d.ts +76 -0
- package/dist/types/src/types/Sheet.d.ts.map +1 -0
- package/dist/types/src/types/capabilities.d.ts +6 -0
- package/dist/types/src/types/capabilities.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +2 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/types/sheet-range-types.d.ts +2 -2
- package/dist/types/src/types/sheet-range-types.d.ts.map +1 -1
- package/dist/types/src/types/types.d.ts +92 -75
- package/dist/types/src/types/types.d.ts.map +1 -1
- package/dist/types/src/types/util.d.ts +9 -10
- package/dist/types/src/types/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +79 -72
- package/src/SheetPlugin.tsx +51 -64
- package/src/capabilities/anchor-sort/anchor-sort.ts +26 -0
- package/src/capabilities/anchor-sort/index.ts +7 -0
- package/src/capabilities/compute-graph-registry/compute-graph-registry.ts +27 -0
- package/src/capabilities/compute-graph-registry/index.ts +7 -0
- package/src/capabilities/index.ts +5 -9
- package/src/capabilities/markdown/index.ts +7 -0
- package/src/capabilities/markdown/markdown.ts +30 -0
- package/src/capabilities/operation-resolver/index.ts +7 -0
- package/src/capabilities/operation-resolver/operation-resolver.ts +77 -0
- package/src/capabilities/react-surface/index.ts +7 -0
- package/src/capabilities/react-surface/react-surface.tsx +43 -0
- package/src/components/ComputeGraph/compute-graph.stories.tsx +10 -12
- package/src/components/FunctionEditor/FunctionEditor.tsx +2 -2
- package/src/components/GridSheet/GridSheet.stories.tsx +14 -11
- package/src/components/GridSheet/GridSheet.tsx +32 -25
- package/src/components/GridSheet/SheetCellEditor.stories.tsx +14 -12
- package/src/components/GridSheet/util.ts +11 -5
- package/src/components/RangeList/RangeList.tsx +13 -10
- package/src/components/SheetContainer/SheetContainer.stories.tsx +68 -47
- package/src/components/SheetContainer/SheetContainer.tsx +30 -18
- package/src/components/SheetContext/SheetContext.tsx +8 -8
- package/src/components/SheetToolbar/SheetToolbar.stories.tsx +9 -6
- package/src/components/SheetToolbar/SheetToolbar.tsx +39 -30
- package/src/components/SheetToolbar/align.ts +44 -19
- package/src/components/SheetToolbar/style.ts +47 -17
- package/src/components/SheetToolbar/useToolbarState.ts +22 -5
- package/src/extensions/compute.stories.tsx +29 -17
- package/src/extensions/compute.ts +1 -1
- package/src/extensions/editor/sheet-extension.ts +7 -4
- package/src/index.ts +1 -1
- package/src/integrations/thread-ranges.ts +40 -49
- package/src/meta.ts +9 -7
- package/src/model/sheet-model.test.ts +4 -4
- package/src/model/sheet-model.ts +78 -48
- package/src/model/testing.ts +4 -4
- package/src/model/useSheetModel.ts +2 -2
- package/src/playwright/playwright.config.ts +1 -1
- package/src/playwright/sheet.spec.ts +1 -0
- package/src/sanity.test.ts +3 -4
- package/src/serializer.ts +4 -4
- package/src/testing/data.ts +2 -2
- package/src/testing/testing.tsx +11 -5
- package/src/translations.ts +3 -2
- package/src/types/Sheet.ts +106 -0
- package/src/types/capabilities.ts +14 -0
- package/src/types/index.ts +2 -1
- package/src/types/sheet-range-types.ts +2 -2
- package/src/types/types.ts +83 -49
- package/src/types/util.ts +10 -38
- package/dist/lib/browser/SheetContainer-OUN6AARA.mjs +0 -350
- package/dist/lib/browser/SheetContainer-OUN6AARA.mjs.map +0 -7
- package/dist/lib/browser/anchor-sort-CAYLDDRF.mjs +0 -24
- package/dist/lib/browser/anchor-sort-CAYLDDRF.mjs.map +0 -7
- package/dist/lib/browser/chunk-6AKBCBL4.mjs +0 -18
- package/dist/lib/browser/chunk-6AKBCBL4.mjs.map +0 -7
- package/dist/lib/browser/chunk-KJWZUQVA.mjs +0 -15
- package/dist/lib/browser/chunk-KJWZUQVA.mjs.map +0 -7
- package/dist/lib/browser/chunk-SSN4HYJL.mjs.map +0 -7
- package/dist/lib/browser/chunk-X4EWLDT3.mjs +0 -851
- package/dist/lib/browser/chunk-X4EWLDT3.mjs.map +0 -7
- package/dist/lib/browser/chunk-XSXUU6FO.mjs +0 -906
- package/dist/lib/browser/chunk-XSXUU6FO.mjs.map +0 -7
- package/dist/lib/browser/compute-graph-registry-WHF3BJTJ.mjs +0 -30
- package/dist/lib/browser/compute-graph-registry-WHF3BJTJ.mjs.map +0 -7
- package/dist/lib/browser/intent-resolver-LKZXAJRJ.mjs +0 -56
- package/dist/lib/browser/intent-resolver-LKZXAJRJ.mjs.map +0 -7
- package/dist/lib/browser/markdown-XKFA4Z2M.mjs +0 -26
- package/dist/lib/browser/markdown-XKFA4Z2M.mjs.map +0 -7
- package/dist/lib/browser/react-surface-N6NYHHT3.mjs +0 -53
- package/dist/lib/browser/react-surface-N6NYHHT3.mjs.map +0 -7
- package/dist/lib/node-esm/SheetContainer-NFLLTGNV.mjs +0 -351
- package/dist/lib/node-esm/SheetContainer-NFLLTGNV.mjs.map +0 -7
- package/dist/lib/node-esm/anchor-sort-4R2ID6GE.mjs +0 -25
- package/dist/lib/node-esm/anchor-sort-4R2ID6GE.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-3K5VNYOF.mjs +0 -20
- package/dist/lib/node-esm/chunk-3K5VNYOF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-6SK5LJ5S.mjs +0 -16
- package/dist/lib/node-esm/chunk-6SK5LJ5S.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-IK4O7FUJ.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-ODP4L4OV.mjs +0 -907
- package/dist/lib/node-esm/chunk-ODP4L4OV.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-PYF4ZJXN.mjs +0 -852
- package/dist/lib/node-esm/chunk-PYF4ZJXN.mjs.map +0 -7
- package/dist/lib/node-esm/compute-graph-registry-3IUZXRXJ.mjs +0 -31
- package/dist/lib/node-esm/compute-graph-registry-3IUZXRXJ.mjs.map +0 -7
- package/dist/lib/node-esm/intent-resolver-JHH6ZVJ4.mjs +0 -57
- package/dist/lib/node-esm/intent-resolver-JHH6ZVJ4.mjs.map +0 -7
- package/dist/lib/node-esm/markdown-NOKROLCG.mjs +0 -27
- package/dist/lib/node-esm/markdown-NOKROLCG.mjs.map +0 -7
- package/dist/lib/node-esm/react-surface-TYBS4DOF.mjs +0 -54
- package/dist/lib/node-esm/react-surface-TYBS4DOF.mjs.map +0 -7
- package/dist/types/src/capabilities/anchor-sort.d.ts +0 -6
- package/dist/types/src/capabilities/anchor-sort.d.ts.map +0 -1
- package/dist/types/src/capabilities/capabilities.d.ts +0 -5
- package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
- package/dist/types/src/capabilities/compute-graph-registry.d.ts +0 -4
- package/dist/types/src/capabilities/compute-graph-registry.d.ts.map +0 -1
- package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
- package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
- package/dist/types/src/capabilities/markdown.d.ts +0 -4
- package/dist/types/src/capabilities/markdown.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface.d.ts +0 -4
- package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
- package/dist/types/src/types/schema.d.ts +0 -37
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/src/capabilities/anchor-sort.ts +0 -22
- package/src/capabilities/capabilities.ts +0 -14
- package/src/capabilities/compute-graph-registry.ts +0 -28
- package/src/capabilities/intent-resolver.ts +0 -38
- package/src/capabilities/markdown.ts +0 -23
- package/src/capabilities/react-surface.tsx +0 -40
- package/src/types/schema.ts +0 -61
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
7
|
+
import { addressFromA1Notation, isFormula } from '@dxos/compute';
|
|
8
|
+
import { Obj, Type } from '@dxos/echo';
|
|
9
|
+
import { FormInputAnnotation } from '@dxos/echo/internal';
|
|
10
|
+
|
|
11
|
+
import { addressToIndex, initialize, mapFormulaRefsToIndices } from './util';
|
|
12
|
+
|
|
13
|
+
export type SheetSize = {
|
|
14
|
+
rows: number;
|
|
15
|
+
columns: number;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const CellValue = Schema.Struct({
|
|
19
|
+
// TODO(burdon): How to store dates (datetime, date, time), percentages, etc.
|
|
20
|
+
// Consider import/export; natural access for other plugins. Special handling for currency (precision).
|
|
21
|
+
// TODO(burdon): Automerge (long string) or short string or number.
|
|
22
|
+
value: Schema.Any,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export type CellValue = Schema.Schema.Type<typeof CellValue>;
|
|
26
|
+
|
|
27
|
+
// TODO(burdon): IMPORTANT: Reconcile with Field definition.
|
|
28
|
+
export const Range = Schema.Struct({
|
|
29
|
+
range: Schema.String,
|
|
30
|
+
key: Schema.String,
|
|
31
|
+
value: Schema.String,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
export type Range = Schema.Schema.Type<typeof Range>;
|
|
35
|
+
|
|
36
|
+
// TODO(burdon): Visibility, locked, frozen, etc.
|
|
37
|
+
export const RowColumnMeta = Schema.Struct({
|
|
38
|
+
size: Schema.optional(Schema.Number),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// TODO(burdon): Reconcile col/column (across packages).
|
|
42
|
+
// TODO(burdon): Index to all updates when rows/columns are inserted/deleted.
|
|
43
|
+
export const Sheet = Schema.Struct({
|
|
44
|
+
name: Schema.optional(Schema.String),
|
|
45
|
+
|
|
46
|
+
// Sparse map of cells referenced by index.
|
|
47
|
+
cells: Schema.Record({ key: Schema.String, value: Schema.mutable(CellValue) }).pipe(
|
|
48
|
+
Schema.mutable,
|
|
49
|
+
FormInputAnnotation.set(false),
|
|
50
|
+
),
|
|
51
|
+
|
|
52
|
+
// Ordered row indices.
|
|
53
|
+
rows: Schema.Array(Schema.String).pipe(Schema.mutable, FormInputAnnotation.set(false)),
|
|
54
|
+
|
|
55
|
+
// Ordered column indices.
|
|
56
|
+
columns: Schema.Array(Schema.String).pipe(Schema.mutable, FormInputAnnotation.set(false)),
|
|
57
|
+
|
|
58
|
+
// Row metadata referenced by index.
|
|
59
|
+
rowMeta: Schema.Record({ key: Schema.String, value: Schema.mutable(RowColumnMeta) }).pipe(
|
|
60
|
+
Schema.mutable,
|
|
61
|
+
FormInputAnnotation.set(false),
|
|
62
|
+
),
|
|
63
|
+
|
|
64
|
+
// Column metadata referenced by index.
|
|
65
|
+
columnMeta: Schema.Record({ key: Schema.String, value: Schema.mutable(RowColumnMeta) }).pipe(
|
|
66
|
+
Schema.mutable,
|
|
67
|
+
FormInputAnnotation.set(false),
|
|
68
|
+
),
|
|
69
|
+
|
|
70
|
+
// Cell formatting referenced by indexed range.
|
|
71
|
+
ranges: Schema.Array(Range).pipe(Schema.mutable, FormInputAnnotation.set(false)),
|
|
72
|
+
}).pipe(
|
|
73
|
+
Type.object({
|
|
74
|
+
typename: 'dxos.org/type/Sheet',
|
|
75
|
+
version: '0.1.0',
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
export interface Sheet extends Schema.Schema.Type<typeof Sheet> {}
|
|
80
|
+
|
|
81
|
+
export type SheetProps = {
|
|
82
|
+
name?: string;
|
|
83
|
+
cells?: Record<string, CellValue>;
|
|
84
|
+
} & Partial<SheetSize>;
|
|
85
|
+
|
|
86
|
+
export const make = ({ name, cells = {}, ...size }: SheetProps = {}) => {
|
|
87
|
+
const sheet = Obj.make(Sheet, { name, cells: {}, rows: [], columns: [], rowMeta: {}, columnMeta: {}, ranges: [] });
|
|
88
|
+
|
|
89
|
+
// Initialize and set cells within Obj.change to satisfy change context requirements.
|
|
90
|
+
Obj.change(sheet, () => {
|
|
91
|
+
initialize(sheet, size);
|
|
92
|
+
|
|
93
|
+
if (cells) {
|
|
94
|
+
Object.entries(cells).forEach(([key, { value }]) => {
|
|
95
|
+
const idx = addressToIndex(sheet, addressFromA1Notation(key));
|
|
96
|
+
if (isFormula(value)) {
|
|
97
|
+
value = mapFormulaRefsToIndices(sheet, value);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
sheet.cells[idx] = { value };
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return sheet;
|
|
106
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Capability } from '@dxos/app-framework';
|
|
6
|
+
import { type ComputeGraphRegistry } from '@dxos/compute';
|
|
7
|
+
|
|
8
|
+
import { meta } from '../meta';
|
|
9
|
+
|
|
10
|
+
export namespace SheetCapabilities {
|
|
11
|
+
export const ComputeGraphRegistry = Capability.make<ComputeGraphRegistry>(
|
|
12
|
+
`${meta.id}/capability/compute-graph-registry`,
|
|
13
|
+
);
|
|
14
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { type ClassNameValue } from '@dxos/react-ui';
|
|
6
6
|
|
|
7
|
-
import { type
|
|
7
|
+
import { type Sheet } from '../types';
|
|
8
8
|
|
|
9
9
|
export const alignKey = 'alignment';
|
|
10
10
|
export type AlignKey = typeof alignKey;
|
|
@@ -19,7 +19,7 @@ export type StyleKey = typeof styleKey;
|
|
|
19
19
|
export type StyleValue = 'highlight' | 'softwrap';
|
|
20
20
|
|
|
21
21
|
// TODO(burdon): Reconcile with plugin-table.
|
|
22
|
-
export const cellClassNameForRange = ({ key, value }:
|
|
22
|
+
export const cellClassNameForRange = ({ key, value }: Sheet.Sheet['ranges'][number]): ClassNameValue => {
|
|
23
23
|
switch (key) {
|
|
24
24
|
case alignKey:
|
|
25
25
|
switch (value) {
|
package/src/types/types.ts
CHANGED
|
@@ -2,67 +2,101 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
5
|
+
import * as Schema from 'effect/Schema';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { Capability } from '@dxos/app-framework';
|
|
8
|
+
import { Operation } from '@dxos/operation';
|
|
9
|
+
import { SpaceSchema } from '@dxos/react-client/echo';
|
|
10
|
+
import { Collection } from '@dxos/schema';
|
|
9
11
|
|
|
10
|
-
import {
|
|
12
|
+
import { meta } from '../meta';
|
|
11
13
|
|
|
12
|
-
|
|
13
|
-
rows: number;
|
|
14
|
-
columns: number;
|
|
15
|
-
};
|
|
14
|
+
import * as Sheet from './Sheet';
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
cells?: Record<string, CellValue>;
|
|
20
|
-
} & Partial<SheetSize>;
|
|
16
|
+
// TODO(wittjosiah): Factor out. This is `DxGridAxis` from `@dxos/react-ui-grid`.
|
|
17
|
+
const ActionAxis = Schema.Union(Schema.Literal('row'), Schema.Literal('col'));
|
|
21
18
|
|
|
22
19
|
export namespace SheetAction {
|
|
23
|
-
const SHEET_ACTION = `${SHEET_PLUGIN}/action`;
|
|
24
|
-
|
|
25
|
-
export class Create extends Schema.TaggedClass<Create>()(`${SHEET_ACTION}/create`, {
|
|
26
|
-
input: Schema.Struct({
|
|
27
|
-
name: Schema.optional(Schema.String),
|
|
28
|
-
}),
|
|
29
|
-
output: Schema.Struct({
|
|
30
|
-
object: SheetType,
|
|
31
|
-
}),
|
|
32
|
-
}) {}
|
|
33
|
-
|
|
34
|
-
// TODO(wittjosiah): Factor out. This is `DxGridAxis` from `@dxos/react-ui-grid`.
|
|
35
|
-
const Axis = Schema.Union(Schema.Literal('row'), Schema.Literal('col'));
|
|
36
|
-
|
|
37
|
-
export class InsertAxis extends Schema.TaggedClass<InsertAxis>()(`${SHEET_ACTION}/axis-insert`, {
|
|
38
|
-
input: Schema.Struct({
|
|
39
|
-
// TODO(wittjosiah): Schema.instanceOf(SheetModel) throws when running tests.
|
|
40
|
-
model: Schema.Any.pipe(Schema.filter((model) => model instanceof SheetModel)) as Schema.Schema<SheetModel>,
|
|
41
|
-
axis: Axis,
|
|
42
|
-
index: Schema.Number,
|
|
43
|
-
count: Schema.optional(Schema.Number),
|
|
44
|
-
}),
|
|
45
|
-
output: Schema.Void,
|
|
46
|
-
}) {}
|
|
47
|
-
|
|
48
20
|
export const RestoreAxis = Schema.Struct({
|
|
49
|
-
axis:
|
|
21
|
+
axis: ActionAxis,
|
|
50
22
|
axisIndex: Schema.String,
|
|
51
23
|
index: Schema.Number,
|
|
52
|
-
axisMeta: RowColumnMeta,
|
|
24
|
+
axisMeta: Sheet.RowColumnMeta,
|
|
53
25
|
values: Schema.Array(Schema.Any),
|
|
54
26
|
});
|
|
55
27
|
|
|
56
28
|
export type RestoreAxis = Schema.Schema.Type<typeof RestoreAxis>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const SHEET_OPERATION = `${meta.id}/operation`;
|
|
32
|
+
|
|
33
|
+
// TODO(wittjosiah): Factor out. This is `DxGridAxis` from `@dxos/react-ui-grid`.
|
|
34
|
+
const Axis = Schema.Union(Schema.Literal('row'), Schema.Literal('col'));
|
|
35
|
+
|
|
36
|
+
export namespace SheetOperation {
|
|
37
|
+
export const OnCreateSpace = Operation.make({
|
|
38
|
+
meta: { key: `${SHEET_OPERATION}/on-create-space`, name: 'On Create Space' },
|
|
39
|
+
services: [Capability.Service],
|
|
40
|
+
schema: {
|
|
41
|
+
input: Schema.Struct({
|
|
42
|
+
space: SpaceSchema,
|
|
43
|
+
rootCollection: Collection.Collection,
|
|
44
|
+
isDefault: Schema.optional(Schema.Boolean),
|
|
45
|
+
}),
|
|
46
|
+
output: Schema.Void,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
57
49
|
|
|
58
|
-
export
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
50
|
+
export const InsertAxis = Operation.make({
|
|
51
|
+
meta: { key: `${SHEET_OPERATION}/axis-insert`, name: 'Insert Axis' },
|
|
52
|
+
schema: {
|
|
53
|
+
input: Schema.Struct({
|
|
54
|
+
model: Schema.Any,
|
|
55
|
+
axis: Axis,
|
|
56
|
+
index: Schema.Number,
|
|
57
|
+
count: Schema.optional(Schema.Number),
|
|
58
|
+
}),
|
|
59
|
+
output: Schema.Void,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
export const DropAxisOutput = Schema.Struct({
|
|
64
|
+
axis: Axis.annotations({ description: 'The axis type (row or col).' }),
|
|
65
|
+
axisIndex: Schema.String.annotations({ description: 'The dropped axis index.' }),
|
|
66
|
+
index: Schema.Number.annotations({ description: 'The position the axis was at.' }),
|
|
67
|
+
axisMeta: Schema.Any.annotations({ description: 'The row/column metadata.' }),
|
|
68
|
+
values: Schema.Array(Schema.Any).annotations({ description: 'The cell values that were dropped.' }),
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
export type DropAxisOutput = Schema.Schema.Type<typeof DropAxisOutput>;
|
|
72
|
+
|
|
73
|
+
export const DropAxis = Operation.make({
|
|
74
|
+
meta: { key: `${SHEET_OPERATION}/axis-drop`, name: 'Drop Axis' },
|
|
75
|
+
schema: {
|
|
76
|
+
input: Schema.Struct({
|
|
77
|
+
model: Schema.Any,
|
|
78
|
+
axis: Axis,
|
|
79
|
+
axisIndex: Schema.String,
|
|
80
|
+
}),
|
|
81
|
+
output: DropAxisOutput,
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Restore a dropped axis (inverse of DropAxis).
|
|
87
|
+
*/
|
|
88
|
+
export const RestoreAxis = Operation.make({
|
|
89
|
+
meta: { key: `${SHEET_OPERATION}/restore-axis`, name: 'Restore Axis' },
|
|
90
|
+
schema: {
|
|
91
|
+
input: Schema.Struct({
|
|
92
|
+
model: Schema.Any.annotations({ description: 'The sheet model.' }),
|
|
93
|
+
axis: Axis.annotations({ description: 'The axis type (row or col).' }),
|
|
94
|
+
axisIndex: Schema.String.annotations({ description: 'The axis index to restore.' }),
|
|
95
|
+
index: Schema.Number.annotations({ description: 'The position to restore at.' }),
|
|
96
|
+
axisMeta: Schema.Any.annotations({ description: 'The row/column metadata.' }),
|
|
97
|
+
values: Schema.Array(Schema.Any).annotations({ description: 'The cell values to restore.' }),
|
|
98
|
+
}),
|
|
99
|
+
output: Schema.Void,
|
|
100
|
+
},
|
|
101
|
+
});
|
|
68
102
|
}
|
package/src/types/util.ts
CHANGED
|
@@ -11,10 +11,9 @@ import {
|
|
|
11
11
|
isFormula,
|
|
12
12
|
} from '@dxos/compute';
|
|
13
13
|
import { randomBytes } from '@dxos/crypto';
|
|
14
|
-
import { Obj } from '@dxos/echo';
|
|
15
14
|
import { invariant } from '@dxos/invariant';
|
|
16
15
|
|
|
17
|
-
import { type
|
|
16
|
+
import { type Sheet } from '../types';
|
|
18
17
|
|
|
19
18
|
export const MAX_ROWS = 500;
|
|
20
19
|
export const MAX_COLS = 676; // 26^2;
|
|
@@ -56,8 +55,8 @@ export const insertIndices = (indices: string[], i: number, n: number, max: numb
|
|
|
56
55
|
};
|
|
57
56
|
|
|
58
57
|
export const initialize = (
|
|
59
|
-
sheet:
|
|
60
|
-
{ rows = DEFAULT_ROWS, columns = DEFAULT_COLS }: Partial<SheetSize> = {},
|
|
58
|
+
sheet: Sheet.Sheet,
|
|
59
|
+
{ rows = DEFAULT_ROWS, columns = DEFAULT_COLS }: Partial<Sheet.SheetSize> = {},
|
|
61
60
|
) => {
|
|
62
61
|
if (!sheet.rows.length) {
|
|
63
62
|
insertIndices(sheet.rows, 0, rows, MAX_ROWS);
|
|
@@ -67,44 +66,17 @@ export const initialize = (
|
|
|
67
66
|
}
|
|
68
67
|
};
|
|
69
68
|
|
|
70
|
-
export const createSheet = ({ name, cells, ...size }: CreateSheetOptions = {}): SheetType => {
|
|
71
|
-
const sheet = Obj.make(SheetType, {
|
|
72
|
-
name,
|
|
73
|
-
cells: {},
|
|
74
|
-
rows: [],
|
|
75
|
-
columns: [],
|
|
76
|
-
rowMeta: {},
|
|
77
|
-
columnMeta: {},
|
|
78
|
-
ranges: [],
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
initialize(sheet, size);
|
|
82
|
-
|
|
83
|
-
if (cells) {
|
|
84
|
-
Object.entries(cells).forEach(([key, { value }]) => {
|
|
85
|
-
const idx = addressToIndex(sheet, addressFromA1Notation(key));
|
|
86
|
-
if (isFormula(value)) {
|
|
87
|
-
value = mapFormulaRefsToIndices(sheet, value);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
sheet.cells[idx] = { value };
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return sheet;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
69
|
/**
|
|
98
70
|
* E.g., "A1" => "CA2@CB3".
|
|
99
71
|
*/
|
|
100
|
-
export const addressToIndex = (sheet:
|
|
72
|
+
export const addressToIndex = (sheet: Sheet.Sheet, cell: CellAddress): string => {
|
|
101
73
|
return `${sheet.columns[cell.col]}@${sheet.rows[cell.row]}`;
|
|
102
74
|
};
|
|
103
75
|
|
|
104
76
|
/**
|
|
105
77
|
* E.g., "CA2@CB3" => "A1".
|
|
106
78
|
*/
|
|
107
|
-
export const addressFromIndex = (sheet:
|
|
79
|
+
export const addressFromIndex = (sheet: Sheet.Sheet, idx: string): CellAddress => {
|
|
108
80
|
const [column, row] = idx.split('@');
|
|
109
81
|
return {
|
|
110
82
|
col: sheet.columns.indexOf(column),
|
|
@@ -115,14 +87,14 @@ export const addressFromIndex = (sheet: SheetType, idx: string): CellAddress =>
|
|
|
115
87
|
/**
|
|
116
88
|
* E.g., "A1:B2" => "CA2@CB3:CC4@CD5".
|
|
117
89
|
*/
|
|
118
|
-
export const rangeToIndex = (sheet:
|
|
90
|
+
export const rangeToIndex = (sheet: Sheet.Sheet, range: CellRange): string => {
|
|
119
91
|
return [range.from, range.to ?? range.from].map((cell) => addressToIndex(sheet, cell)).join(':');
|
|
120
92
|
};
|
|
121
93
|
|
|
122
94
|
/**
|
|
123
95
|
* E.g., "CA2@CB3:CC4@CD5" => "A1:B2".
|
|
124
96
|
*/
|
|
125
|
-
export const rangeFromIndex = (sheet:
|
|
97
|
+
export const rangeFromIndex = (sheet: Sheet.Sheet, idx: string): CompleteCellRange => {
|
|
126
98
|
const [from, to] = idx.split(':').map((index) => addressFromIndex(sheet, index));
|
|
127
99
|
return { from, to };
|
|
128
100
|
};
|
|
@@ -131,7 +103,7 @@ export const rangeFromIndex = (sheet: SheetType, idx: string): CompleteCellRange
|
|
|
131
103
|
* Compares the positions of two cell indexes in a sheet.
|
|
132
104
|
* Sorts primarily by row, then by column if rows are equal.
|
|
133
105
|
*/
|
|
134
|
-
export const compareIndexPositions = (sheet:
|
|
106
|
+
export const compareIndexPositions = (sheet: Sheet.Sheet, indexA: string, indexB: string): number => {
|
|
135
107
|
const { row: rowA, col: columnA } = addressFromIndex(sheet, indexA);
|
|
136
108
|
const { row: rowB, col: columnB } = addressFromIndex(sheet, indexB);
|
|
137
109
|
|
|
@@ -148,7 +120,7 @@ export const compareIndexPositions = (sheet: SheetType, indexA: string, indexB:
|
|
|
148
120
|
/**
|
|
149
121
|
* Map from A1 notation to indices.
|
|
150
122
|
*/
|
|
151
|
-
export const mapFormulaRefsToIndices = (sheet:
|
|
123
|
+
export const mapFormulaRefsToIndices = (sheet: Sheet.Sheet, formula: string): string => {
|
|
152
124
|
invariant(isFormula(formula));
|
|
153
125
|
return formula.replace(/([a-zA-Z]+)([0-9]+)/g, (match) => {
|
|
154
126
|
return addressToIndex(sheet, addressFromA1Notation(match));
|
|
@@ -158,7 +130,7 @@ export const mapFormulaRefsToIndices = (sheet: SheetType, formula: string): stri
|
|
|
158
130
|
/**
|
|
159
131
|
* Map from indices to A1 notation.
|
|
160
132
|
*/
|
|
161
|
-
export const mapFormulaIndicesToRefs = (sheet:
|
|
133
|
+
export const mapFormulaIndicesToRefs = (sheet: Sheet.Sheet, formula: string): string => {
|
|
162
134
|
invariant(isFormula(formula));
|
|
163
135
|
return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
|
|
164
136
|
return addressToA1Notation(addressFromIndex(sheet, idx));
|