@dxos/plugin-sheet 0.8.4-main.406dc2a → 0.8.4-main.548089c

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.
Files changed (151) hide show
  1. package/dist/lib/browser/{SheetContainer-VL34UND4.mjs → SheetContainer-BDLFSILO.mjs} +14 -16
  2. package/dist/lib/browser/SheetContainer-BDLFSILO.mjs.map +7 -0
  3. package/dist/lib/browser/{anchor-sort-3N44DS5F.mjs → anchor-sort-FCQ5OZZK.mjs} +8 -9
  4. package/dist/lib/browser/anchor-sort-FCQ5OZZK.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-ZMPNHFIP.mjs → chunk-73AV3NH6.mjs} +2 -2
  6. package/dist/lib/browser/{chunk-ZJWJMX4E.mjs → chunk-7KRJ2IT5.mjs} +23 -23
  7. package/dist/lib/browser/chunk-7KRJ2IT5.mjs.map +7 -0
  8. package/dist/lib/browser/{chunk-SSN4HYJL.mjs → chunk-7VEWYJJN.mjs} +5 -5
  9. package/dist/lib/browser/{chunk-SSN4HYJL.mjs.map → chunk-7VEWYJJN.mjs.map} +2 -2
  10. package/dist/lib/browser/{chunk-ADK2HW4A.mjs → chunk-DVJ3QW3F.mjs} +217 -216
  11. package/dist/lib/browser/chunk-DVJ3QW3F.mjs.map +7 -0
  12. package/dist/lib/browser/chunk-FWFAAGXL.mjs +28 -0
  13. package/dist/lib/browser/chunk-FWFAAGXL.mjs.map +7 -0
  14. package/dist/lib/browser/{compute-graph-registry-MF65HGGM.mjs → compute-graph-registry-AP5RA7W3.mjs} +3 -3
  15. package/dist/lib/browser/{compute-graph-registry-MF65HGGM.mjs.map → compute-graph-registry-AP5RA7W3.mjs.map} +2 -2
  16. package/dist/lib/browser/index.mjs +16 -16
  17. package/dist/lib/browser/index.mjs.map +3 -3
  18. package/dist/lib/browser/{intent-resolver-BQLV6IAA.mjs → intent-resolver-66OAYVQF.mjs} +5 -5
  19. package/dist/lib/browser/intent-resolver-66OAYVQF.mjs.map +7 -0
  20. package/dist/lib/browser/{markdown-RMTMI237.mjs → markdown-B6VKYY2S.mjs} +4 -4
  21. package/dist/lib/browser/meta.json +1 -1
  22. package/dist/lib/browser/{react-surface-7ZDMQDCT.mjs → react-surface-GXHVZHKU.mjs} +11 -10
  23. package/dist/lib/browser/react-surface-GXHVZHKU.mjs.map +7 -0
  24. package/dist/lib/browser/types/index.mjs +4 -12
  25. package/dist/lib/node-esm/{SheetContainer-NWJ7L6FC.mjs → SheetContainer-CK5HSJPL.mjs} +14 -16
  26. package/dist/lib/node-esm/SheetContainer-CK5HSJPL.mjs.map +7 -0
  27. package/dist/lib/node-esm/{anchor-sort-YL2OZHYM.mjs → anchor-sort-ZE7IS7SH.mjs} +8 -9
  28. package/dist/lib/node-esm/anchor-sort-ZE7IS7SH.mjs.map +7 -0
  29. package/dist/lib/node-esm/{chunk-LN6ZSAII.mjs → chunk-44YTKTMP.mjs} +2 -2
  30. package/dist/lib/node-esm/{chunk-BZAPYBSH.mjs → chunk-4H2EHVWE.mjs} +217 -216
  31. package/dist/lib/node-esm/chunk-4H2EHVWE.mjs.map +7 -0
  32. package/dist/lib/node-esm/{chunk-IK4O7FUJ.mjs → chunk-4QV4AGWK.mjs} +5 -5
  33. package/dist/lib/node-esm/{chunk-IK4O7FUJ.mjs.map → chunk-4QV4AGWK.mjs.map} +2 -2
  34. package/dist/lib/node-esm/chunk-HILDMVPL.mjs +29 -0
  35. package/dist/lib/node-esm/chunk-HILDMVPL.mjs.map +7 -0
  36. package/dist/lib/node-esm/{chunk-YL7BVJPC.mjs → chunk-SMYD6H7Q.mjs} +23 -23
  37. package/dist/lib/node-esm/chunk-SMYD6H7Q.mjs.map +7 -0
  38. package/dist/lib/node-esm/{compute-graph-registry-P2O5LDFZ.mjs → compute-graph-registry-UMQ5UYCL.mjs} +3 -3
  39. package/dist/lib/node-esm/{compute-graph-registry-P2O5LDFZ.mjs.map → compute-graph-registry-UMQ5UYCL.mjs.map} +2 -2
  40. package/dist/lib/node-esm/index.mjs +16 -16
  41. package/dist/lib/node-esm/index.mjs.map +3 -3
  42. package/dist/lib/node-esm/{intent-resolver-MV5ZFXAQ.mjs → intent-resolver-VNKIMQQT.mjs} +5 -5
  43. package/dist/lib/node-esm/intent-resolver-VNKIMQQT.mjs.map +7 -0
  44. package/dist/lib/node-esm/{markdown-EDIWHA3P.mjs → markdown-VKY7HXU2.mjs} +4 -4
  45. package/dist/lib/node-esm/meta.json +1 -1
  46. package/dist/lib/node-esm/{react-surface-TUME5MM2.mjs → react-surface-45L45WN6.mjs} +11 -10
  47. package/dist/lib/node-esm/react-surface-45L45WN6.mjs.map +7 -0
  48. package/dist/lib/node-esm/types/index.mjs +4 -12
  49. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  50. package/dist/types/src/capabilities/anchor-sort.d.ts +2 -4
  51. package/dist/types/src/capabilities/anchor-sort.d.ts.map +1 -1
  52. package/dist/types/src/capabilities/index.d.ts +1 -4
  53. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  54. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  55. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
  56. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +2 -2
  57. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -1
  58. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -1
  59. package/dist/types/src/components/RangeList/RangeList.d.ts +2 -2
  60. package/dist/types/src/components/RangeList/RangeList.d.ts.map +1 -1
  61. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +2 -2
  62. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -1
  63. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +2 -2
  64. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -1
  65. package/dist/types/src/components/SheetContext/SheetContext.d.ts +2 -2
  66. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -1
  67. package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts +3 -4
  68. package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts.map +1 -1
  69. package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -1
  70. package/dist/types/src/meta.d.ts.map +1 -1
  71. package/dist/types/src/model/sheet-model.d.ts +4 -4
  72. package/dist/types/src/model/sheet-model.d.ts.map +1 -1
  73. package/dist/types/src/model/testing.d.ts +2 -2
  74. package/dist/types/src/model/testing.d.ts.map +1 -1
  75. package/dist/types/src/model/useSheetModel.d.ts +2 -2
  76. package/dist/types/src/model/useSheetModel.d.ts.map +1 -1
  77. package/dist/types/src/serializer.d.ts +2 -2
  78. package/dist/types/src/serializer.d.ts.map +1 -1
  79. package/dist/types/src/testing/data.d.ts +2 -2
  80. package/dist/types/src/testing/data.d.ts.map +1 -1
  81. package/dist/types/src/testing/testing.d.ts +26 -2
  82. package/dist/types/src/testing/testing.d.ts.map +1 -1
  83. package/dist/types/src/translations.d.ts +2 -2
  84. package/dist/types/src/translations.d.ts.map +1 -1
  85. package/dist/types/src/types/{schema.d.ts → Sheet.d.ts} +36 -3
  86. package/dist/types/src/types/Sheet.d.ts.map +1 -0
  87. package/dist/types/src/types/index.d.ts +1 -1
  88. package/dist/types/src/types/index.d.ts.map +1 -1
  89. package/dist/types/src/types/sheet-range-types.d.ts +2 -2
  90. package/dist/types/src/types/sheet-range-types.d.ts.map +1 -1
  91. package/dist/types/src/types/types.d.ts +0 -9
  92. package/dist/types/src/types/types.d.ts.map +1 -1
  93. package/dist/types/src/types/util.d.ts +9 -10
  94. package/dist/types/src/types/util.d.ts.map +1 -1
  95. package/dist/types/tsconfig.tsbuildinfo +1 -1
  96. package/package.json +51 -50
  97. package/src/SheetPlugin.tsx +6 -5
  98. package/src/capabilities/anchor-sort.ts +7 -8
  99. package/src/capabilities/compute-graph-registry.ts +1 -1
  100. package/src/capabilities/intent-resolver.ts +2 -2
  101. package/src/capabilities/react-surface.tsx +6 -5
  102. package/src/components/ComputeGraph/compute-graph.stories.tsx +8 -8
  103. package/src/components/FunctionEditor/FunctionEditor.tsx +1 -1
  104. package/src/components/GridSheet/GridSheet.stories.tsx +2 -2
  105. package/src/components/GridSheet/GridSheet.tsx +16 -4
  106. package/src/components/GridSheet/SheetCellEditor.stories.tsx +4 -4
  107. package/src/components/GridSheet/util.ts +9 -3
  108. package/src/components/RangeList/RangeList.tsx +5 -5
  109. package/src/components/SheetContainer/SheetContainer.stories.tsx +9 -6
  110. package/src/components/SheetContainer/SheetContainer.tsx +5 -4
  111. package/src/components/SheetContext/SheetContext.tsx +4 -4
  112. package/src/components/SheetToolbar/SheetToolbar.tsx +14 -16
  113. package/src/extensions/compute.stories.tsx +2 -2
  114. package/src/integrations/thread-ranges.ts +10 -16
  115. package/src/meta.ts +6 -2
  116. package/src/model/sheet-model.test.ts +4 -4
  117. package/src/model/sheet-model.ts +3 -3
  118. package/src/model/testing.ts +4 -4
  119. package/src/model/useSheetModel.ts +2 -2
  120. package/src/sanity.test.ts +3 -4
  121. package/src/serializer.ts +3 -3
  122. package/src/testing/data.ts +2 -2
  123. package/src/testing/testing.tsx +3 -3
  124. package/src/translations.ts +2 -2
  125. package/src/types/Sheet.ts +103 -0
  126. package/src/types/index.ts +1 -1
  127. package/src/types/sheet-range-types.ts +2 -2
  128. package/src/types/types.ts +3 -13
  129. package/src/types/util.ts +10 -38
  130. package/dist/lib/browser/SheetContainer-VL34UND4.mjs.map +0 -7
  131. package/dist/lib/browser/anchor-sort-3N44DS5F.mjs.map +0 -7
  132. package/dist/lib/browser/chunk-ADK2HW4A.mjs.map +0 -7
  133. package/dist/lib/browser/chunk-CSBSADPQ.mjs +0 -16
  134. package/dist/lib/browser/chunk-CSBSADPQ.mjs.map +0 -7
  135. package/dist/lib/browser/chunk-ZJWJMX4E.mjs.map +0 -7
  136. package/dist/lib/browser/intent-resolver-BQLV6IAA.mjs.map +0 -7
  137. package/dist/lib/browser/react-surface-7ZDMQDCT.mjs.map +0 -7
  138. package/dist/lib/node-esm/SheetContainer-NWJ7L6FC.mjs.map +0 -7
  139. package/dist/lib/node-esm/anchor-sort-YL2OZHYM.mjs.map +0 -7
  140. package/dist/lib/node-esm/chunk-BZAPYBSH.mjs.map +0 -7
  141. package/dist/lib/node-esm/chunk-H3GSD33H.mjs +0 -18
  142. package/dist/lib/node-esm/chunk-H3GSD33H.mjs.map +0 -7
  143. package/dist/lib/node-esm/chunk-YL7BVJPC.mjs.map +0 -7
  144. package/dist/lib/node-esm/intent-resolver-MV5ZFXAQ.mjs.map +0 -7
  145. package/dist/lib/node-esm/react-surface-TUME5MM2.mjs.map +0 -7
  146. package/dist/types/src/types/schema.d.ts.map +0 -1
  147. package/src/types/schema.ts +0 -61
  148. /package/dist/lib/browser/{chunk-ZMPNHFIP.mjs.map → chunk-73AV3NH6.mjs.map} +0 -0
  149. /package/dist/lib/browser/{markdown-RMTMI237.mjs.map → markdown-B6VKYY2S.mjs.map} +0 -0
  150. /package/dist/lib/node-esm/{chunk-LN6ZSAII.mjs.map → chunk-44YTKTMP.mjs.map} +0 -0
  151. /package/dist/lib/node-esm/{markdown-EDIWHA3P.mjs.map → markdown-VKY7HXU2.mjs.map} +0 -0
@@ -2,12 +2,11 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { Rx } from '@effect-rx/rx-react';
5
+ import { Atom } from '@effect-atom/atom-react';
6
6
  import React, { type PropsWithChildren, useMemo } from 'react';
7
7
 
8
- import { useAppGraph } from '@dxos/app-framework';
8
+ import { useAppGraph } from '@dxos/app-framework/react';
9
9
  import { type CompleteCellRange } from '@dxos/compute';
10
- import { type ThemedClassName } from '@dxos/react-ui';
11
10
  import {
12
11
  type ActionGraphProps,
13
12
  MenuProvider,
@@ -24,19 +23,13 @@ import { createAlign, useAlignState } from './align';
24
23
  import { createStyle, useStyleState } from './style';
25
24
  import { type ToolbarState, useToolbarState } from './useToolbarState';
26
25
 
27
- //
28
- // Root
29
- //
30
-
31
- export type SheetToolbarProps = ThemedClassName<PropsWithChildren<{ id: string }>>;
32
-
33
26
  const createToolbarActions = (
34
27
  model: SheetModel,
35
28
  state: ToolbarState,
36
29
  cursorFallbackRange?: CompleteCellRange,
37
- customActions?: Rx.Rx<ActionGraphProps>,
38
- ): Rx.Rx<ActionGraphProps> => {
39
- return Rx.make((get) => {
30
+ customActions?: Atom.Atom<ActionGraphProps>,
31
+ ): Atom.Atom<ActionGraphProps> => {
32
+ return Atom.make((get) => {
40
33
  const align = get(rxFromSignal(() => createAlign(model, state, cursorFallbackRange)));
41
34
  const style = get(rxFromSignal(() => createStyle(model, state, cursorFallbackRange)));
42
35
  const gap = createGapSeparator();
@@ -56,7 +49,9 @@ const createToolbarActions = (
56
49
  });
57
50
  };
58
51
 
59
- export const SheetToolbar = ({ id, classNames }: SheetToolbarProps) => {
52
+ export type SheetToolbarProps = PropsWithChildren<{ id: string }>;
53
+
54
+ export const SheetToolbar = ({ id }: SheetToolbarProps) => {
60
55
  const { model, cursorFallbackRange } = useSheetContext();
61
56
  const state = useToolbarState({});
62
57
  useAlignState(state);
@@ -64,10 +59,13 @@ export const SheetToolbar = ({ id, classNames }: SheetToolbarProps) => {
64
59
 
65
60
  const { graph } = useAppGraph();
66
61
  const customActions = useMemo(() => {
67
- return Rx.make((get) => {
62
+ return Atom.make((get) => {
68
63
  const actions = get(graph.actions(id));
69
64
  const nodes = actions.filter((action) => action.properties.disposition === 'toolbar');
70
- return { nodes, edges: nodes.map((node) => ({ source: 'root', target: node.id })) };
65
+ return {
66
+ nodes,
67
+ edges: nodes.map((node) => ({ source: 'root', target: node.id })),
68
+ };
71
69
  });
72
70
  }, [graph]);
73
71
 
@@ -79,7 +77,7 @@ export const SheetToolbar = ({ id, classNames }: SheetToolbarProps) => {
79
77
 
80
78
  return (
81
79
  <MenuProvider {...menu} attendableId={id}>
82
- <ToolbarMenu classNames={classNames} />
80
+ <ToolbarMenu />
83
81
  </MenuProvider>
84
82
  );
85
83
  };
@@ -25,7 +25,7 @@ import { isNonNullable } from '@dxos/util';
25
25
  import { GridSheet, SheetProvider, useComputeGraph } from '../components';
26
26
  import { useSheetModel } from '../model';
27
27
  import { useTestSheet, withComputeGraphDecorator } from '../testing';
28
- import { SheetType } from '../types';
28
+ import { Sheet } from '../types';
29
29
 
30
30
  import { compute, computeGraphFacet } from './compute';
31
31
 
@@ -103,7 +103,7 @@ const meta = {
103
103
  title: 'plugins/plugin-sheet/extensions',
104
104
  decorators: [
105
105
  withTheme,
106
- withClientProvider({ types: [SheetType], createIdentity: true, createSpace: true }),
106
+ withClientProvider({ types: [Sheet.Sheet], createIdentity: true, createSpace: true }),
107
107
  // TODO(wittjosiah): Try to write story which does not depend on plugin manager.
108
108
  withPluginManager({ plugins: [IntentPlugin()] }),
109
109
  withComputeGraphDecorator(),
@@ -6,22 +6,16 @@ import * as Function from 'effect/Function';
6
6
  import * as Schema from 'effect/Schema';
7
7
  import { useCallback, useEffect, useMemo } from 'react';
8
8
 
9
- import {
10
- LayoutAction,
11
- chain,
12
- createIntent,
13
- createResolver,
14
- useIntentDispatcher,
15
- useIntentResolver,
16
- } from '@dxos/app-framework';
9
+ import { LayoutAction, chain, createIntent, createResolver } from '@dxos/app-framework';
10
+ import { useIntentDispatcher, useIntentResolver } from '@dxos/app-framework/react';
17
11
  import { debounce } from '@dxos/async';
18
12
  import { type CellAddress, type CompleteCellRange, inRange } from '@dxos/compute';
19
13
  import { Obj, Relation } from '@dxos/echo';
20
14
  import { ATTENDABLE_PATH_SEPARATOR, DeckAction } from '@dxos/plugin-deck/types';
21
- import { ThreadAction, ThreadType } from '@dxos/plugin-thread/types';
22
- import { Filter, Query, fullyQualifiedId, getSpace, useQuery } from '@dxos/react-client/echo';
15
+ import { Thread, ThreadAction } from '@dxos/plugin-thread/types';
16
+ import { Filter, Query, getSpace, useQuery } from '@dxos/react-client/echo';
23
17
  import { type DxGridElement, type GridContentProps } from '@dxos/react-ui-grid';
24
- import { AnchoredTo } from '@dxos/schema';
18
+ import { AnchoredTo } from '@dxos/types';
25
19
 
26
20
  import { useSheetContext } from '../components';
27
21
  import { meta } from '../meta';
@@ -61,7 +55,7 @@ export const useUpdateFocusedCellOnThreadSelection = (grid: DxGridElement | null
61
55
  return false;
62
56
  }
63
57
 
64
- return data.subject === fullyQualifiedId(model.sheet) && !!data.options?.cursor;
58
+ return data.subject === Obj.getDXN(model.sheet).toString() && !!data.options?.cursor;
65
59
  },
66
60
  resolve: ({ options: { cursor, ref } }) => {
67
61
  setActiveRefs(ref);
@@ -81,7 +75,7 @@ export const useSelectThreadOnCellFocus = () => {
81
75
  const { dispatchPromise: dispatch } = useIntentDispatcher();
82
76
 
83
77
  const space = getSpace(model.sheet);
84
- const anchors = useQuery(space, Query.select(Filter.ids(model.sheet.id)).targetOf(AnchoredTo));
78
+ const anchors = useQuery(space, Query.select(Filter.ids(model.sheet.id)).targetOf(AnchoredTo.AnchoredTo));
85
79
 
86
80
  const selectClosestThread = useCallback(
87
81
  (cellAddress: CellAddress) => {
@@ -91,7 +85,7 @@ export const useSelectThreadOnCellFocus = () => {
91
85
 
92
86
  const closestThread = anchors.find((anchor) => {
93
87
  const source = Relation.getSource(anchor);
94
- if (anchor.anchor && Obj.instanceOf(ThreadType, source)) {
88
+ if (anchor.anchor && Obj.instanceOf(Thread.Thread, source)) {
95
89
  const range = parseThreadAnchorAsCellRange(anchor.anchor);
96
90
  return range ? inRange(range, cellAddress) : false;
97
91
  } else {
@@ -100,9 +94,9 @@ export const useSelectThreadOnCellFocus = () => {
100
94
  });
101
95
 
102
96
  if (closestThread) {
103
- const primary = fullyQualifiedId(model.sheet);
97
+ const primary = Obj.getDXN(model.sheet).toString();
104
98
  const intent = Function.pipe(
105
- createIntent(ThreadAction.Select, { current: fullyQualifiedId(closestThread) }),
99
+ createIntent(ThreadAction.Select, { current: Obj.getDXN(closestThread).toString() }),
106
100
  chain(DeckAction.ChangeCompanion, { primary, companion: `${primary}${ATTENDABLE_PATH_SEPARATOR}comments` }),
107
101
  );
108
102
  void dispatch(intent);
package/src/meta.ts CHANGED
@@ -3,13 +3,17 @@
3
3
  //
4
4
 
5
5
  import { type PluginMeta } from '@dxos/app-framework';
6
+ import { trim } from '@dxos/util';
6
7
 
7
8
  export const meta: PluginMeta = {
8
9
  id: 'dxos.org/plugin/sheet',
9
10
  name: 'Sheet',
10
- description:
11
- 'Sheets in Composer are simple spreadsheets which allow you to leverage custom functions inside of cell grids. Leverage more than 400 pre-built formulas like Sum, Average, Count, Max, Min along with many others. You can also deploy your own custom functions using the Scripts plugin. ',
11
+ description: trim`
12
+ Full-featured spreadsheet application with over 400 built-in formulas for calculations and data analysis.
13
+ Create custom JavaScript functions and integrate with AI agents for advanced automation.
14
+ `,
12
15
  icon: 'ph--grid-nine--regular',
16
+ iconHue: 'indigo',
13
17
  source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/plugin-sheet',
14
18
  screenshots: ['https://dxos.network/plugin-details-sheet-dark.png'],
15
19
  };
@@ -7,10 +7,10 @@ import { afterEach, beforeEach, describe, expect, onTestFinished, test } from 'v
7
7
  import { Trigger } from '@dxos/async';
8
8
  import { type CellScalarValue, addressFromA1Notation, isFormula } from '@dxos/compute';
9
9
  import { TestBuilder, testFunctionPlugins } from '@dxos/compute/testing';
10
- import { FunctionType } from '@dxos/functions';
10
+ import { Function } from '@dxos/functions';
11
11
  import { log } from '@dxos/log';
12
12
 
13
- import { createSheet, mapFormulaIndicesToRefs, mapFormulaRefsToIndices } from '../types';
13
+ import { Sheet, mapFormulaIndicesToRefs, mapFormulaRefsToIndices } from '../types';
14
14
 
15
15
  import { SheetModel } from './sheet-model';
16
16
  import { createTestGrid } from './testing';
@@ -18,7 +18,7 @@ import { createTestGrid } from './testing';
18
18
  describe('SheetModel', () => {
19
19
  let testBuilder: TestBuilder;
20
20
  beforeEach(async () => {
21
- testBuilder = new TestBuilder({ types: [FunctionType], plugins: testFunctionPlugins });
21
+ testBuilder = new TestBuilder({ types: [Function.Function], plugins: testFunctionPlugins });
22
22
  await testBuilder.open();
23
23
  });
24
24
  afterEach(async () => {
@@ -31,7 +31,7 @@ describe('SheetModel', () => {
31
31
  await graph.open();
32
32
 
33
33
  // TODO(burdon): Create via factory.
34
- const sheet = createSheet({ rows: 5, columns: 5 });
34
+ const sheet = Sheet.make({ rows: 5, columns: 5 });
35
35
  const model = new SheetModel(graph, sheet);
36
36
  await model.open();
37
37
  testBuilder.ctx.onDispose(() => model.close());
@@ -39,7 +39,7 @@ import {
39
39
  mapFormulaIndicesToRefs,
40
40
  mapFormulaRefsToIndices,
41
41
  } from '../types';
42
- import { type CellValue, type SheetAction, type SheetType } from '../types';
42
+ import { type Sheet, type SheetAction } from '../types';
43
43
 
44
44
  // TODO(burdon): Move to compute.
45
45
  // Map sheet types to system types.
@@ -92,7 +92,7 @@ export class SheetModel extends Resource {
92
92
 
93
93
  constructor(
94
94
  private readonly _graph: ComputeGraph,
95
- private readonly _sheet: SheetType,
95
+ private readonly _sheet: Sheet.Sheet,
96
96
  private readonly _options: SheetModelOptions = {},
97
97
  ) {
98
98
  super();
@@ -414,7 +414,7 @@ export class SheetModel extends Resource {
414
414
  /**
415
415
  * Sets values from a simple map.
416
416
  */
417
- setValues(values: Record<string, CellValue>): void {
417
+ setValues(values: Record<string, Sheet.CellValue>): void {
418
418
  Object.entries(values).forEach(([key, { value }]) => {
419
419
  this.setValue(addressFromA1Notation(key), value);
420
420
  });
@@ -4,14 +4,14 @@
4
4
 
5
5
  import { addressToA1Notation } from '@dxos/compute';
6
6
 
7
- import { type CellValue, type SheetType, createSheet } from '../types';
7
+ import { Sheet } from '../types';
8
8
 
9
9
  // TODO(burdon): Create testing endpoint.
10
10
  // TODO(burdon): Move to react-ui-sheet.
11
- export const createTestGrid = ({ cols = 4, rows = 10 }: { cols: number; rows: number }): SheetType => {
11
+ export const createTestGrid = ({ cols = 4, rows = 10 }: { cols: number; rows: number }): Sheet.Sheet => {
12
12
  const year = new Date().getFullYear();
13
13
 
14
- const cells: Record<string, CellValue> = {};
14
+ const cells: Record<string, Sheet.CellValue> = {};
15
15
  for (let col = 1; col <= cols; col++) {
16
16
  for (let row = 1; row <= 10; row++) {
17
17
  const cell = addressToA1Notation({ col, row });
@@ -27,7 +27,7 @@ export const createTestGrid = ({ cols = 4, rows = 10 }: { cols: number; rows: nu
27
27
  }
28
28
  }
29
29
 
30
- const sheet = createSheet({
30
+ const sheet = Sheet.make({
31
31
  name: 'Test',
32
32
  cells,
33
33
  });
@@ -7,7 +7,7 @@ import { useEffect, useState } from 'react';
7
7
  import { type ComputeGraph } from '@dxos/compute';
8
8
 
9
9
  import { SheetModel } from '../model';
10
- import { type SheetType } from '../types';
10
+ import { type Sheet } from '../types';
11
11
 
12
12
  export type UseSheetModelOptions = {
13
13
  readonly?: boolean;
@@ -15,7 +15,7 @@ export type UseSheetModelOptions = {
15
15
 
16
16
  export const useSheetModel = (
17
17
  graph?: ComputeGraph,
18
- sheet?: SheetType,
18
+ sheet?: Sheet.Sheet,
19
19
  { readonly }: UseSheetModelOptions = {},
20
20
  ): SheetModel | undefined => {
21
21
  const [model, setModel] = useState<SheetModel>();
@@ -5,8 +5,7 @@
5
5
  import { describe, expect, test } from 'vitest';
6
6
 
7
7
  import { Client } from '@dxos/client';
8
- import { Obj } from '@dxos/echo';
9
- import { FunctionType } from '@dxos/functions';
8
+ import { Function } from '@dxos/functions';
10
9
 
11
10
  // Part 2.
12
11
  // TODO(burdon): Cannot test outside of browser.
@@ -23,7 +22,7 @@ import { FunctionType } from '@dxos/functions';
23
22
  describe('test', () => {
24
23
  test('test', async () => {
25
24
  const client = new Client();
26
- client.addTypes([FunctionType]);
25
+ client.addTypes([Function.Function]);
27
26
  await client.initialize();
28
27
  await client.halo.createIdentity();
29
28
 
@@ -34,7 +33,7 @@ describe('test', () => {
34
33
  // - ERROR "process.nextTick is not a function"
35
34
  // - ERROR "Identifier 'Buffer' has already been declared" if { nodeExternal: true }
36
35
  const space = await client.spaces.create();
37
- const fn = space.db.add(Obj.make(FunctionType, { name: 'test', version: '0.0.1', binding: 'HELLO' }));
36
+ const fn = space.db.add(Function.make({ name: 'test', version: '0.0.1', binding: 'HELLO' }));
38
37
  expect(fn).to.exist;
39
38
  });
40
39
  });
package/src/serializer.ts CHANGED
@@ -6,16 +6,16 @@ import { Obj } from '@dxos/echo';
6
6
  import { type TypedObjectSerializer } from '@dxos/plugin-space/types';
7
7
  import { getObjectCore } from '@dxos/react-client/echo';
8
8
 
9
- import { SheetType } from './types';
9
+ import { Sheet } from './types';
10
10
 
11
- export const serializer: TypedObjectSerializer<SheetType> = {
11
+ export const serializer: TypedObjectSerializer<Sheet.Sheet> = {
12
12
  serialize: async ({ object }): Promise<string> => {
13
13
  return JSON.stringify(object, null, 2);
14
14
  },
15
15
 
16
16
  deserialize: async ({ content, newId }) => {
17
17
  const { id, ...parsed } = JSON.parse(content);
18
- const sheet = Obj.make(SheetType, parsed);
18
+ const sheet = Obj.make(Sheet.Sheet, parsed);
19
19
 
20
20
  if (!newId) {
21
21
  const core = getObjectCore(sheet);
@@ -2,9 +2,9 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import type { CellValue } from '../types';
5
+ import type { Sheet } from '../types';
6
6
 
7
- export const createTestCells = (testSheetName = 'test'): Record<string, CellValue> => ({
7
+ export const createTestCells = (testSheetName = 'test'): Record<string, Sheet.CellValue> => ({
8
8
  B1: { value: 'Qty2' },
9
9
  B3: { value: 1 },
10
10
  B4: { value: 2 },
@@ -11,15 +11,15 @@ import { type Space } from '@dxos/react-client/echo';
11
11
  import { useAsyncState } from '@dxos/react-hooks';
12
12
 
13
13
  import { ComputeGraphContextProvider } from '../components';
14
- import { type CreateSheetOptions, createSheet } from '../types';
14
+ import { Sheet } from '../types';
15
15
 
16
- export const useTestSheet = (space?: Space, graph?: ComputeGraph, options?: CreateSheetOptions) => {
16
+ export const useTestSheet = (space?: Space, graph?: ComputeGraph, options?: Sheet.SheetProps) => {
17
17
  const [sheet] = useAsyncState(async () => {
18
18
  if (!space || !graph) {
19
19
  return;
20
20
  }
21
21
 
22
- const sheet = createSheet(options);
22
+ const sheet = Sheet.make(options);
23
23
  space.db.add(sheet);
24
24
  return sheet;
25
25
  }, [space, graph]);
@@ -5,12 +5,12 @@
5
5
  import { type Resource } from '@dxos/react-ui';
6
6
 
7
7
  import { meta } from './meta';
8
- import { SheetType } from './types';
8
+ import { Sheet } from './types';
9
9
 
10
10
  export const translations = [
11
11
  {
12
12
  'en-US': {
13
- [SheetType.typename]: {
13
+ [Sheet.Sheet.typename]: {
14
14
  'typename label': 'Sheet',
15
15
  'typename label_zero': 'Sheets',
16
16
  'typename label_one': 'Sheet',
@@ -0,0 +1,103 @@
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 { FormAnnotation } 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
+ FormAnnotation.set(false),
50
+ ),
51
+
52
+ // Ordered row indices.
53
+ rows: Schema.Array(Schema.String).pipe(Schema.mutable, FormAnnotation.set(false)),
54
+
55
+ // Ordered column indices.
56
+ columns: Schema.Array(Schema.String).pipe(Schema.mutable, FormAnnotation.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
+ FormAnnotation.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
+ FormAnnotation.set(false),
68
+ ),
69
+
70
+ // Cell formatting referenced by indexed range.
71
+ ranges: Schema.Array(Range).pipe(Schema.mutable, FormAnnotation.set(false)),
72
+ }).pipe(
73
+ Type.Obj({
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(sheet, size);
90
+
91
+ if (cells) {
92
+ Object.entries(cells).forEach(([key, { value }]) => {
93
+ const idx = addressToIndex(sheet, addressFromA1Notation(key));
94
+ if (isFormula(value)) {
95
+ value = mapFormulaRefsToIndices(sheet, value);
96
+ }
97
+
98
+ sheet.cells[idx] = { value };
99
+ });
100
+ }
101
+
102
+ return sheet;
103
+ };
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- export * from './schema';
5
+ export * as Sheet from './Sheet';
6
6
  export * from './sheet-range-types';
7
7
  export * from './types';
8
8
  export * from './util';
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { type ClassNameValue } from '@dxos/react-ui';
6
6
 
7
- import { type SheetType } from '../types';
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 }: SheetType['ranges'][number]): ClassNameValue => {
22
+ export const cellClassNameForRange = ({ key, value }: Sheet.Sheet['ranges'][number]): ClassNameValue => {
23
23
  switch (key) {
24
24
  case alignKey:
25
25
  switch (value) {
@@ -7,17 +7,7 @@ import * as Schema from 'effect/Schema';
7
7
  import { meta } from '../meta';
8
8
  import { SheetModel } from '../model';
9
9
 
10
- import { type CellValue, RowColumnMeta, SheetType } from './schema';
11
-
12
- export type SheetSize = {
13
- rows: number;
14
- columns: number;
15
- };
16
-
17
- export type CreateSheetOptions = {
18
- name?: string;
19
- cells?: Record<string, CellValue>;
20
- } & Partial<SheetSize>;
10
+ import * as Sheet from './Sheet';
21
11
 
22
12
  export namespace SheetAction {
23
13
  const SHEET_ACTION = `${meta.id}/action`;
@@ -27,7 +17,7 @@ export namespace SheetAction {
27
17
  name: Schema.optional(Schema.String),
28
18
  }),
29
19
  output: Schema.Struct({
30
- object: SheetType,
20
+ object: Sheet.Sheet,
31
21
  }),
32
22
  }) {}
33
23
 
@@ -49,7 +39,7 @@ export namespace SheetAction {
49
39
  axis: Axis,
50
40
  axisIndex: Schema.String,
51
41
  index: Schema.Number,
52
- axisMeta: RowColumnMeta,
42
+ axisMeta: Sheet.RowColumnMeta,
53
43
  values: Schema.Array(Schema.Any),
54
44
  });
55
45
 
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 CreateSheetOptions, type SheetSize, SheetType } from '../types';
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: SheetType,
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: SheetType, cell: CellAddress): string => {
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: SheetType, idx: string): CellAddress => {
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: SheetType, range: CellRange): string => {
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: SheetType, idx: string): CompleteCellRange => {
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: SheetType, indexA: string, indexB: string): number => {
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: SheetType, formula: string): string => {
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: SheetType, formula: string): string => {
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));