@dxos/plugin-sheet 0.7.4 → 0.7.5-main.937ce75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/dist/lib/browser/{SheetContainer-KCLT6PEO.mjs → SheetContainer-S4NCLUYL.mjs} +16 -22
  2. package/dist/lib/browser/SheetContainer-S4NCLUYL.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-E5WQ7U7G.mjs → chunk-A374JPWV.mjs} +72 -705
  4. package/dist/lib/browser/chunk-A374JPWV.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-Q4XS4YWF.mjs +900 -0
  6. package/dist/lib/browser/chunk-Q4XS4YWF.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +74 -180
  8. package/dist/lib/browser/index.mjs.map +3 -3
  9. package/dist/lib/browser/meta.json +1 -1
  10. package/dist/lib/browser/types/index.mjs +62 -0
  11. package/dist/lib/node/{SheetContainer-VVVRYTQG.cjs → SheetContainer-TP4GYXZB.cjs} +41 -43
  12. package/dist/lib/node/SheetContainer-TP4GYXZB.cjs.map +7 -0
  13. package/dist/lib/node/{chunk-45YW2DX2.cjs → chunk-FDEQ2PGJ.cjs} +115 -726
  14. package/dist/lib/node/chunk-FDEQ2PGJ.cjs.map +7 -0
  15. package/dist/lib/node/chunk-TQOJ7DG2.cjs +935 -0
  16. package/dist/lib/node/chunk-TQOJ7DG2.cjs.map +7 -0
  17. package/dist/lib/node/index.cjs +104 -207
  18. package/dist/lib/node/index.cjs.map +3 -3
  19. package/dist/lib/node/meta.json +1 -1
  20. package/dist/lib/node/types/index.cjs +84 -0
  21. package/dist/lib/node/types/index.cjs.map +7 -0
  22. package/dist/lib/node-esm/{SheetContainer-LSBE6Q4X.mjs → SheetContainer-YB3JBVPZ.mjs} +16 -22
  23. package/dist/lib/node-esm/SheetContainer-YB3JBVPZ.mjs.map +7 -0
  24. package/dist/lib/node-esm/{chunk-NYDNXI7L.mjs → chunk-L5PQHVTX.mjs} +72 -705
  25. package/dist/lib/node-esm/chunk-L5PQHVTX.mjs.map +7 -0
  26. package/dist/lib/node-esm/chunk-NYYIDVR7.mjs +901 -0
  27. package/dist/lib/node-esm/chunk-NYYIDVR7.mjs.map +7 -0
  28. package/dist/lib/node-esm/index.mjs +74 -180
  29. package/dist/lib/node-esm/index.mjs.map +3 -3
  30. package/dist/lib/node-esm/meta.json +1 -1
  31. package/dist/lib/node-esm/types/index.mjs +63 -0
  32. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  33. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts +1 -1
  34. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +1 -1
  35. package/dist/types/src/components/ComputeGraph/compute-graph.stories.d.ts.map +1 -0
  36. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +1 -1
  37. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
  38. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +1 -1
  39. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -1
  40. package/dist/types/src/components/RangeList/RangeList.d.ts.map +1 -1
  41. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -1
  42. package/dist/types/src/components/SheetContext/SheetContext.d.ts +1 -2
  43. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -1
  44. package/dist/types/src/components/Toolbar/Toolbar.d.ts +1 -1
  45. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  46. package/dist/types/src/components/index.d.ts +1 -1
  47. package/dist/types/src/extensions/compute.d.ts +1 -1
  48. package/dist/types/src/extensions/compute.d.ts.map +1 -1
  49. package/dist/types/src/extensions/editor/extension.d.ts +1 -1
  50. package/dist/types/src/extensions/editor/extension.d.ts.map +1 -1
  51. package/dist/types/src/index.d.ts +1 -1
  52. package/dist/types/src/index.d.ts.map +1 -1
  53. package/dist/types/src/integrations/thread-ranges.d.ts +1 -1
  54. package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -1
  55. package/dist/types/src/model/sheet-model.d.ts +6 -8
  56. package/dist/types/src/model/sheet-model.d.ts.map +1 -1
  57. package/dist/types/src/model/testing.d.ts +1 -1
  58. package/dist/types/src/model/testing.d.ts.map +1 -1
  59. package/dist/types/src/model/useSheetModel.d.ts +1 -1
  60. package/dist/types/src/model/useSheetModel.d.ts.map +1 -1
  61. package/dist/types/src/testing/testing.d.ts +2 -2
  62. package/dist/types/src/testing/testing.d.ts.map +1 -1
  63. package/dist/types/src/{defs → types}/index.d.ts +1 -0
  64. package/dist/types/src/types/index.d.ts.map +1 -0
  65. package/dist/types/src/types/schema.d.ts +105 -0
  66. package/dist/types/src/types/schema.d.ts.map +1 -0
  67. package/dist/types/src/types/sheet-range-types.d.ts.map +1 -0
  68. package/dist/types/src/types/types.d.ts +82 -0
  69. package/dist/types/src/types/types.d.ts.map +1 -0
  70. package/dist/types/src/{defs → types}/util.d.ts +5 -1
  71. package/dist/types/src/types/util.d.ts.map +1 -0
  72. package/dist/types/tsconfig.tsbuildinfo +1 -0
  73. package/package.json +46 -53
  74. package/src/SheetPlugin.tsx +44 -115
  75. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +1 -2
  76. package/src/{compute-graph → components/ComputeGraph}/compute-graph.stories.tsx +6 -7
  77. package/src/components/FunctionEditor/FunctionEditor.tsx +2 -1
  78. package/src/components/GridSheet/GridSheet.tsx +15 -18
  79. package/src/components/GridSheet/SheetCellEditor.stories.tsx +6 -7
  80. package/src/components/GridSheet/util.ts +3 -2
  81. package/src/components/RangeList/RangeList.tsx +2 -1
  82. package/src/components/SheetContainer/SheetContainer.stories.tsx +11 -12
  83. package/src/components/SheetContext/SheetContext.tsx +1 -2
  84. package/src/components/Toolbar/Toolbar.tsx +18 -20
  85. package/src/extensions/compute.ts +7 -4
  86. package/src/extensions/editor/extension.test.ts +2 -1
  87. package/src/extensions/editor/extension.ts +2 -3
  88. package/src/index.ts +1 -3
  89. package/src/integrations/thread-ranges.ts +28 -24
  90. package/src/model/sheet-model.test.ts +4 -10
  91. package/src/model/sheet-model.ts +30 -22
  92. package/src/model/testing.ts +3 -2
  93. package/src/model/useSheetModel.ts +2 -1
  94. package/src/sanity.test.ts +1 -1
  95. package/src/testing/testing.tsx +2 -3
  96. package/src/{defs → types}/index.ts +1 -0
  97. package/src/types/schema.ts +56 -0
  98. package/src/types/types.ts +93 -0
  99. package/src/{defs → types}/util.ts +13 -13
  100. package/dist/lib/browser/SheetContainer-KCLT6PEO.mjs.map +0 -7
  101. package/dist/lib/browser/chunk-E5WQ7U7G.mjs.map +0 -7
  102. package/dist/lib/browser/chunk-F3HE6D3J.mjs +0 -3269
  103. package/dist/lib/browser/chunk-F3HE6D3J.mjs.map +0 -7
  104. package/dist/lib/browser/chunk-JXFPOYNA.mjs +0 -67
  105. package/dist/lib/browser/chunk-JXFPOYNA.mjs.map +0 -7
  106. package/dist/lib/browser/compute-graph-SNUS7HOH.mjs +0 -35
  107. package/dist/lib/browser/types.mjs +0 -16
  108. package/dist/lib/node/SheetContainer-VVVRYTQG.cjs.map +0 -7
  109. package/dist/lib/node/chunk-45YW2DX2.cjs.map +0 -7
  110. package/dist/lib/node/chunk-KSEEI5VC.cjs +0 -3323
  111. package/dist/lib/node/chunk-KSEEI5VC.cjs.map +0 -7
  112. package/dist/lib/node/chunk-OWH2EUHZ.cjs +0 -90
  113. package/dist/lib/node/chunk-OWH2EUHZ.cjs.map +0 -7
  114. package/dist/lib/node/compute-graph-WILPHO4A.cjs +0 -57
  115. package/dist/lib/node/compute-graph-WILPHO4A.cjs.map +0 -7
  116. package/dist/lib/node/types.cjs +0 -38
  117. package/dist/lib/node/types.cjs.map +0 -7
  118. package/dist/lib/node-esm/SheetContainer-LSBE6Q4X.mjs.map +0 -7
  119. package/dist/lib/node-esm/chunk-6JF2AHKO.mjs +0 -3270
  120. package/dist/lib/node-esm/chunk-6JF2AHKO.mjs.map +0 -7
  121. package/dist/lib/node-esm/chunk-BVS2IQRO.mjs +0 -68
  122. package/dist/lib/node-esm/chunk-BVS2IQRO.mjs.map +0 -7
  123. package/dist/lib/node-esm/chunk-NYDNXI7L.mjs.map +0 -7
  124. package/dist/lib/node-esm/compute-graph-S6CVN7RS.mjs +0 -36
  125. package/dist/lib/node-esm/compute-graph-S6CVN7RS.mjs.map +0 -7
  126. package/dist/lib/node-esm/types.mjs +0 -17
  127. package/dist/lib/node-esm/types.mjs.map +0 -7
  128. package/dist/types/src/compute-graph/compute-graph-registry.d.ts +0 -34
  129. package/dist/types/src/compute-graph/compute-graph-registry.d.ts.map +0 -1
  130. package/dist/types/src/compute-graph/compute-graph.d.ts +0 -64
  131. package/dist/types/src/compute-graph/compute-graph.d.ts.map +0 -1
  132. package/dist/types/src/compute-graph/compute-graph.stories.d.ts.map +0 -1
  133. package/dist/types/src/compute-graph/compute-graph.test.d.ts +0 -2
  134. package/dist/types/src/compute-graph/compute-graph.test.d.ts.map +0 -1
  135. package/dist/types/src/compute-graph/compute-node.d.ts +0 -26
  136. package/dist/types/src/compute-graph/compute-node.d.ts.map +0 -1
  137. package/dist/types/src/compute-graph/functions/async-function.d.ts +0 -66
  138. package/dist/types/src/compute-graph/functions/async-function.d.ts.map +0 -1
  139. package/dist/types/src/compute-graph/functions/edge-function.d.ts +0 -21
  140. package/dist/types/src/compute-graph/functions/edge-function.d.ts.map +0 -1
  141. package/dist/types/src/compute-graph/functions/function-defs.d.ts +0 -11
  142. package/dist/types/src/compute-graph/functions/function-defs.d.ts.map +0 -1
  143. package/dist/types/src/compute-graph/functions/index.d.ts +0 -4
  144. package/dist/types/src/compute-graph/functions/index.d.ts.map +0 -1
  145. package/dist/types/src/compute-graph/hyperformula.test.d.ts +0 -2
  146. package/dist/types/src/compute-graph/hyperformula.test.d.ts.map +0 -1
  147. package/dist/types/src/compute-graph/index.d.ts +0 -5
  148. package/dist/types/src/compute-graph/index.d.ts.map +0 -1
  149. package/dist/types/src/compute-graph/testing/index.d.ts +0 -3
  150. package/dist/types/src/compute-graph/testing/index.d.ts.map +0 -1
  151. package/dist/types/src/compute-graph/testing/test-builder.d.ts +0 -15
  152. package/dist/types/src/compute-graph/testing/test-builder.d.ts.map +0 -1
  153. package/dist/types/src/compute-graph/testing/test-plugin.d.ts +0 -36
  154. package/dist/types/src/compute-graph/testing/test-plugin.d.ts.map +0 -1
  155. package/dist/types/src/compute-graph/util.d.ts +0 -2
  156. package/dist/types/src/compute-graph/util.d.ts.map +0 -1
  157. package/dist/types/src/defs/index.d.ts.map +0 -1
  158. package/dist/types/src/defs/sheet-range-types.d.ts.map +0 -1
  159. package/dist/types/src/defs/types.d.ts +0 -26
  160. package/dist/types/src/defs/types.d.ts.map +0 -1
  161. package/dist/types/src/defs/types.test.d.ts +0 -2
  162. package/dist/types/src/defs/types.test.d.ts.map +0 -1
  163. package/dist/types/src/defs/util.d.ts.map +0 -1
  164. package/dist/types/src/types.d.ts +0 -182
  165. package/dist/types/src/types.d.ts.map +0 -1
  166. package/dist/vendor/hyperformula.mjs +0 -37145
  167. package/src/compute-graph/compute-graph-registry.ts +0 -90
  168. package/src/compute-graph/compute-graph.test.ts +0 -87
  169. package/src/compute-graph/compute-graph.ts +0 -260
  170. package/src/compute-graph/compute-node.ts +0 -62
  171. package/src/compute-graph/functions/async-function.ts +0 -179
  172. package/src/compute-graph/functions/edge-function.ts +0 -102
  173. package/src/compute-graph/functions/function-defs.ts +0 -2427
  174. package/src/compute-graph/functions/index.ts +0 -7
  175. package/src/compute-graph/hyperformula.test.ts +0 -14
  176. package/src/compute-graph/index.ts +0 -8
  177. package/src/compute-graph/testing/index.ts +0 -6
  178. package/src/compute-graph/testing/test-builder.ts +0 -54
  179. package/src/compute-graph/testing/test-plugin.ts +0 -100
  180. package/src/compute-graph/util.ts +0 -8
  181. package/src/defs/types.test.ts +0 -91
  182. package/src/defs/types.ts +0 -88
  183. package/src/types.ts +0 -125
  184. /package/dist/lib/browser/{compute-graph-SNUS7HOH.mjs.map → types/index.mjs.map} +0 -0
  185. /package/dist/lib/{browser/types.mjs.map → node-esm/types/index.mjs.map} +0 -0
  186. /package/dist/types/src/{compute-graph → components/ComputeGraph}/compute-graph.stories.d.ts +0 -0
  187. /package/dist/types/src/{defs → types}/sheet-range-types.d.ts +0 -0
  188. /package/src/{defs → types}/sheet-range-types.ts +0 -0
@@ -7,19 +7,18 @@ import '@dxos-theme';
7
7
  import { type Meta } from '@storybook/react';
8
8
  import React, { useEffect, useRef, useState } from 'react';
9
9
 
10
- import { FunctionType } from '@dxos/plugin-script/types';
10
+ import { testFunctionPlugins } from '@dxos/compute/testing';
11
+ import { FunctionType } from '@dxos/functions';
11
12
  import { create, useSpace, Filter } from '@dxos/react-client/echo';
12
13
  import { withClientProvider } from '@dxos/react-client/testing';
13
14
  import { Toolbar, Button, Input } from '@dxos/react-ui';
14
15
  import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
15
16
  import { withTheme } from '@dxos/storybook-utils';
16
17
 
17
- import { testFunctionPlugins } from './testing';
18
- import { useComputeGraph } from '../components';
19
- import { createSheet } from '../defs';
20
- import { useSheetModel } from '../model';
21
- import { withComputeGraphDecorator } from '../testing';
22
- import { SheetType } from '../types';
18
+ import { useComputeGraph } from './ComputeGraphContextProvider';
19
+ import { useSheetModel } from '../../model';
20
+ import { withComputeGraphDecorator } from '../../testing';
21
+ import { createSheet, SheetType } from '../../types';
23
22
 
24
23
  const FUNCTION_NAME = 'TEST';
25
24
 
@@ -4,9 +4,10 @@
4
4
 
5
5
  import React from 'react';
6
6
 
7
+ import { addressToA1Notation, isFormula, rangeToA1Notation } from '@dxos/compute';
7
8
  import { Icon } from '@dxos/react-ui';
8
9
 
9
- import { addressToA1Notation, isFormula, mapFormulaIndicesToRefs, rangeToA1Notation } from '../../defs';
10
+ import { mapFormulaIndicesToRefs } from '../../types';
10
11
  import { useSheetContext } from '../SheetContext';
11
12
 
12
13
  export const FunctionEditor = () => {
@@ -13,7 +13,8 @@ import React, {
13
13
  useState,
14
14
  } from 'react';
15
15
 
16
- import { useIntentDispatcher } from '@dxos/app-framework';
16
+ import { createIntent, useIntentDispatcher } from '@dxos/app-framework';
17
+ import { rangeToA1Notation, type CellRange } from '@dxos/compute';
17
18
  import { DropdownMenu, Icon, useTranslation } from '@dxos/react-ui';
18
19
  import { useAttention } from '@dxos/react-ui-attention';
19
20
  import {
@@ -23,20 +24,19 @@ import {
23
24
  Grid,
24
25
  GridCellEditor,
25
26
  type DxGridElement,
27
+ type DxGridPosition,
28
+ type DxGridCellIndex,
26
29
  type EditorKeyHandler,
27
30
  type EditorBlurHandler,
28
31
  type GridContentProps,
29
- type DxGridPosition,
30
- type DxGridCellIndex,
31
32
  parseCellIndex,
32
33
  } from '@dxos/react-ui-grid';
33
34
 
34
35
  import { colLabelCell, rowLabelCell, useSheetModelDxGridProps } from './util';
35
- import { DEFAULT_COLUMNS, DEFAULT_ROWS, rangeToA1Notation, type CellRange } from '../../defs';
36
36
  import { rangeExtension, sheetExtension, type RangeController } from '../../extensions';
37
37
  import { useSelectThreadOnCellFocus, useUpdateFocusedCellOnThreadSelection } from '../../integrations';
38
38
  import { SHEET_PLUGIN } from '../../meta';
39
- import { SheetAction } from '../../types';
39
+ import { DEFAULT_COLS, DEFAULT_ROWS, SheetAction } from '../../types';
40
40
  import { useSheetContext } from '../SheetContext';
41
41
 
42
42
  const inertPosition: DxGridPosition = { plane: 'grid', col: 0, row: 0 };
@@ -72,7 +72,7 @@ export const GridSheet = () => {
72
72
  // a reliable dependency for `useEffect` whereas `useLayoutEffect` does not guarantee the element will be defined.
73
73
  const [dxGrid, setDxGrid] = useState<DxGridElement | null>(null);
74
74
  const [extraplanarFocus, setExtraplanarFocus] = useState<DxGridPosition | null>(null);
75
- const dispatch = useIntentDispatcher();
75
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
76
76
  const rangeController = useRef<RangeController>();
77
77
  const { hasAttention } = useAttention(id);
78
78
 
@@ -252,24 +252,21 @@ export const GridSheet = () => {
252
252
  switch (operation) {
253
253
  case 'insert-before':
254
254
  case 'insert-after':
255
- return dispatch({
256
- action: SheetAction.INSERT_AXIS,
257
- data: {
255
+ return dispatch(
256
+ createIntent(SheetAction.InsertAxis, {
258
257
  model,
259
258
  axis: contextMenuAxis,
260
259
  index: contextMenuOpen![contextMenuAxis] + (operation === 'insert-before' ? 0 : 1),
261
- } satisfies SheetAction.InsertAxis,
262
- });
263
- break;
260
+ }),
261
+ );
264
262
  case 'drop':
265
- return dispatch({
266
- action: SheetAction.DROP_AXIS,
267
- data: {
263
+ return dispatch(
264
+ createIntent(SheetAction.DropAxis, {
268
265
  model,
269
266
  axis: contextMenuAxis,
270
267
  axisIndex: model.sheet[contextMenuAxis === 'row' ? 'rows' : 'columns'][contextMenuOpen![contextMenuAxis]],
271
- } satisfies SheetAction.DropAxis,
272
- });
268
+ }),
269
+ );
273
270
  }
274
271
  },
275
272
  [contextMenuAxis, contextMenuOpen, model, dispatch],
@@ -309,7 +306,7 @@ export const GridSheet = () => {
309
306
  <GridCellEditor getCellContent={getCellContent} extension={extension} onBlur={handleBlur} />
310
307
  <Grid.Content
311
308
  initialCells={initialCells}
312
- limitColumns={DEFAULT_COLUMNS}
309
+ limitColumns={DEFAULT_COLS}
313
310
  limitRows={DEFAULT_ROWS}
314
311
  columns={columns}
315
312
  rows={rows}
@@ -9,21 +9,20 @@ import React, { useEffect, useMemo, useState } from 'react';
9
9
 
10
10
  import { Client } from '@dxos/client';
11
11
  import { createDocAccessor, type ReactiveEchoObject } from '@dxos/client/echo';
12
+ import { defaultFunctions } from '@dxos/compute';
13
+ import { getRegisteredFunctionNames } from '@dxos/compute/testing';
12
14
  import { automerge } from '@dxos/react-ui-editor';
13
15
  import { CellEditor, type CellEditorProps } from '@dxos/react-ui-grid';
14
16
  import { withTheme } from '@dxos/storybook-utils';
15
17
 
16
- import { HyperFormula } from '#hyperformula';
17
- import { defaultFunctions } from '../../compute-graph';
18
- import { createSheet } from '../../defs';
19
18
  import { sheetExtension } from '../../extensions';
20
- import { SheetType } from '../../types';
19
+ import { createSheet, SheetType } from '../../types';
21
20
 
22
21
  type StoryProps = CellEditorProps;
23
22
 
24
23
  const Story = ({ value, ...props }: StoryProps) => {
25
24
  const extension = useMemo(() => {
26
- const functionNames = HyperFormula.buildEmpty({ licenseKey: 'gpl-v3' }).getRegisteredFunctionNames();
25
+ const functionNames = getRegisteredFunctionNames();
27
26
  const functions = defaultFunctions.filter(({ name }) => functionNames.includes(name));
28
27
  return [sheetExtension({ functions })];
29
28
  }, []);
@@ -54,7 +53,7 @@ const AutomergeStory = ({ value, ...props }: StoryProps) => {
54
53
  return [];
55
54
  }
56
55
 
57
- const functionNames = HyperFormula.buildEmpty({ licenseKey: 'gpl-v3' }).getRegisteredFunctionNames();
56
+ const functionNames = getRegisteredFunctionNames();
58
57
  const functions = defaultFunctions.filter(({ name }) => functionNames.includes(name));
59
58
  const accessor = createDocAccessor(object, ['cells', cell, 'value']);
60
59
  return [automerge(accessor), sheetExtension({ functions })];
@@ -87,8 +86,8 @@ export const Automerge = {
87
86
  const meta: Meta = {
88
87
  title: 'plugins/plugin-sheet/CellEditor',
89
88
  component: CellEditor,
90
- render: (args: StoryProps) => <Story {...args} />,
91
89
  decorators: [withTheme],
90
+ render: (args: StoryProps) => <Story {...args} />,
92
91
  };
93
92
 
94
93
  export default meta;
@@ -4,6 +4,7 @@
4
4
 
5
5
  import { useEffect, useState } from 'react';
6
6
 
7
+ import { inRange } from '@dxos/compute';
7
8
  import { createDocAccessor, fullyQualifiedId } from '@dxos/react-client/echo';
8
9
  import { parseValue, cellClassesForFieldType } from '@dxos/react-ui-form';
9
10
  import {
@@ -20,9 +21,9 @@ import {
20
21
  } from '@dxos/react-ui-grid';
21
22
  import { mx } from '@dxos/react-ui-theme';
22
23
 
23
- import { inRange, cellClassNameForRange, rangeFromIndex } from '../../defs';
24
24
  import { parseThreadAnchorAsCellRange } from '../../integrations';
25
25
  import { type SheetModel } from '../../model';
26
+ import { cellClassNameForRange, rangeFromIndex } from '../../types';
26
27
 
27
28
  const createDxGridColumns = (model: SheetModel): DxGridAxisMeta => {
28
29
  return model.sheet.columns.reduce(
@@ -54,7 +55,7 @@ const projectCellProps = (model: SheetModel, col: number, row: number): DxGridCe
54
55
  const ranges = model.sheet.ranges?.filter(({ range }) => inRange(rangeFromIndex(model.sheet, range), address));
55
56
  const threadRefs = model.sheet.threads
56
57
  ?.filter((thread) => {
57
- const range = thread?.anchor && parseThreadAnchorAsCellRange(thread!.anchor);
58
+ const range = thread.target?.anchor && parseThreadAnchorAsCellRange(thread.target!.anchor);
58
59
  return thread && range ? inRange(range, address) : false;
59
60
  })
60
61
  .map((thread) => fullyQualifiedId(thread!))
@@ -4,13 +4,14 @@
4
4
 
5
5
  import React, { useCallback } from 'react';
6
6
 
7
+ import { rangeToA1Notation } from '@dxos/compute';
7
8
  import { S } from '@dxos/echo-schema';
8
9
  import { useTranslation } from '@dxos/react-ui';
9
10
  import { List } from '@dxos/react-ui-list';
10
11
  import { ghostHover } from '@dxos/react-ui-theme';
11
12
 
12
- import { rangeFromIndex, rangeToA1Notation } from '../../defs';
13
13
  import { SHEET_PLUGIN } from '../../meta';
14
+ import { rangeFromIndex } from '../../types';
14
15
  import { Range, type SheetType } from '../../types';
15
16
 
16
17
  export type RangeListProps = {
@@ -7,7 +7,8 @@ import '@dxos-theme';
7
7
  import { type Meta } from '@storybook/react';
8
8
  import React from 'react';
9
9
 
10
- import { type Intent, IntentProvider } from '@dxos/app-framework';
10
+ import { type AnyIntentChain, type IntentContext, IntentProvider } from '@dxos/app-framework';
11
+ import { todo } from '@dxos/debug';
11
12
  import { useSpace, create } from '@dxos/react-client/echo';
12
13
  import { withClientProvider } from '@dxos/react-client/testing';
13
14
  import { withTheme, withLayout } from '@dxos/storybook-utils';
@@ -20,20 +21,18 @@ import { useComputeGraph } from '../ComputeGraph';
20
21
  import { RangeList } from '../RangeList';
21
22
 
22
23
  // TODO(thure via wittjosiah): stories/components should be written such that the dependency on intents is external and provided via callback and then the story can implement it differently.
23
- const storybookIntentValue = create({
24
- dispatch: async (intents: Intent | Intent[]) => {
25
- const intent = Array.isArray(intents) ? intents[0] : intents;
26
- switch (intent.action) {
27
- case SheetAction.DROP_AXIS: {
28
- if (!intent.undo) {
29
- const { model, axis, axisIndex } = intent.data as SheetAction.DropAxis;
30
- model[axis === 'col' ? 'dropColumn' : 'dropRow'](axisIndex);
31
- }
24
+ const storybookIntentValue = create<IntentContext>({
25
+ dispatch: () => todo(),
26
+ dispatchPromise: async (intentChain: AnyIntentChain): Promise<any> => {
27
+ switch (intentChain.first.action) {
28
+ case SheetAction.DropAxis._tag: {
29
+ const { model, axis, axisIndex } = intentChain.first.data as SheetAction.DropAxis['input'];
30
+ model[axis === 'col' ? 'dropColumn' : 'dropRow'](axisIndex);
32
31
  }
33
32
  }
34
33
  },
35
- undo: async () => ({}),
36
- history: [],
34
+ undo: () => todo(),
35
+ undoPromise: () => todo(),
37
36
  registerResolver: () => () => {},
38
37
  });
39
38
 
@@ -4,6 +4,7 @@
4
4
 
5
5
  import React, { type PropsWithChildren, createContext, useCallback, useContext, useState } from 'react';
6
6
 
7
+ import { type ComputeGraph, type CellAddress, type CellRange, type CompleteCellRange } from '@dxos/compute';
7
8
  import { invariant } from '@dxos/invariant';
8
9
  import { fullyQualifiedId } from '@dxos/react-client/echo';
9
10
  import {
@@ -14,8 +15,6 @@ import {
14
15
  useGridContext,
15
16
  } from '@dxos/react-ui-grid';
16
17
 
17
- import { type ComputeGraph } from '../../compute-graph';
18
- import { type CellAddress, type CellRange, type CompleteCellRange } from '../../defs';
19
18
  import { type SheetModel, useSheetModel } from '../../model';
20
19
  import { type SheetType } from '../../types';
21
20
 
@@ -5,7 +5,10 @@
5
5
  import { createContext } from '@radix-ui/react-context';
6
6
  import React, { type PropsWithChildren, useCallback } from 'react';
7
7
 
8
- import { useIntentDispatcher } from '@dxos/app-framework';
8
+ import { createIntent, useIntentDispatcher } from '@dxos/app-framework';
9
+ import { inRange } from '@dxos/compute';
10
+ import { RefArray } from '@dxos/live-object';
11
+ import { ThreadAction } from '@dxos/plugin-thread/types';
9
12
  import {
10
13
  Icon,
11
14
  type ThemedClassName,
@@ -17,24 +20,22 @@ import {
17
20
  useTranslation,
18
21
  } from '@dxos/react-ui';
19
22
  import { useAttention } from '@dxos/react-ui-attention';
20
- import { nonNullable } from '@dxos/util';
21
23
 
24
+ import { completeCellRangeToThreadCursor } from '../../integrations';
25
+ import { SHEET_PLUGIN } from '../../meta';
22
26
  import {
23
27
  alignKey,
28
+ rangeFromIndex,
29
+ rangeToIndex,
30
+ styleKey,
24
31
  type AlignKey,
25
32
  type AlignValue,
26
33
  type CommentKey,
27
34
  type CommentValue,
28
- inRange,
29
- rangeFromIndex,
30
- rangeToIndex,
31
- styleKey,
32
35
  type StyleKey,
33
36
  type StyleValue,
34
- } from '../../defs';
35
- import { completeCellRangeToThreadCursor } from '../../integrations';
36
- import { SHEET_PLUGIN } from '../../meta';
37
- import { type SheetType } from '../../types';
37
+ type SheetType,
38
+ } from '../../types';
38
39
  import { useSheetContext } from '../SheetContext';
39
40
 
40
41
  //
@@ -42,7 +43,7 @@ import { useSheetContext } from '../SheetContext';
42
43
  //
43
44
 
44
45
  const buttonStyles = 'min-bs-0 p-2';
45
- const tooltipProps = { side: 'bottom' as const, classNames: 'z-10' };
46
+ const tooltipProps = { side: 'bottom' as const };
46
47
 
47
48
  const ToolbarSeparator = () => <div role='separator' className='grow' />;
48
49
 
@@ -111,7 +112,7 @@ type Range = SheetType['ranges'][number];
111
112
  const ToolbarRoot = ({ children, role, classNames }: ToolbarProps) => {
112
113
  const { id, model, cursorFallbackRange, cursor } = useSheetContext();
113
114
  const { hasAttention } = useAttention(id);
114
- const dispatch = useIntentDispatcher();
115
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
115
116
 
116
117
  // TODO(Zan): Externalize the toolbar action handler. E.g., Toolbar/keys should both fire events.
117
118
  const handleAction = useCallback(
@@ -159,16 +160,14 @@ const ToolbarRoot = ({ children, role, classNames }: ToolbarProps) => {
159
160
  }
160
161
  break;
161
162
  case 'comment': {
162
- // TODO(Zan): We shouldn't hardcode the action ID.
163
163
  if (cursorFallbackRange) {
164
- void dispatch({
165
- action: 'dxos.org/plugin/thread/action/create',
166
- data: {
164
+ void dispatch(
165
+ createIntent(ThreadAction.Create, {
167
166
  cursor: completeCellRangeToThreadCursor(cursorFallbackRange),
168
167
  name: action.cellContent,
169
168
  subject: model.sheet,
170
- },
171
- });
169
+ }),
170
+ );
172
171
  }
173
172
  }
174
173
  }
@@ -296,8 +295,7 @@ const Actions = () => {
296
295
  const { t } = useTranslation(SHEET_PLUGIN);
297
296
 
298
297
  // TODO(thure): Can this O(n) call be memoized?
299
- const overlapsCommentAnchor = (model.sheet.threads ?? [])
300
- .filter(nonNullable)
298
+ const overlapsCommentAnchor = RefArray.allResolvedTargets(model.sheet.threads ?? [])
301
299
  .filter((thread) => thread.status !== 'resolved')
302
300
  .some((thread) => {
303
301
  if (!cursorFallbackRange) {
@@ -15,13 +15,16 @@ import {
15
15
  import { Decoration, EditorView, ViewPlugin, WidgetType } from '@codemirror/view';
16
16
 
17
17
  import { type UnsubscribeCallback, debounce } from '@dxos/async';
18
+ import {
19
+ createSheetName,
20
+ type CellAddress,
21
+ type CellScalarValue,
22
+ type ComputeGraph,
23
+ type ComputeNode,
24
+ } from '@dxos/compute';
18
25
  import { invariant } from '@dxos/invariant';
19
26
  import { documentId, singleValueFacet } from '@dxos/react-ui-editor';
20
27
 
21
- import { type ComputeGraph, type ComputeNode, createSheetName } from '../compute-graph';
22
- import { type CellAddress } from '../defs';
23
- import { type CellScalarValue } from '../types';
24
-
25
28
  const LANGUAGE_TAG = 'dx';
26
29
 
27
30
  // TODO(burdon): Create marker just for our decorator?
@@ -8,8 +8,9 @@ import { testTree } from '@lezer/generator/test';
8
8
  import { spreadsheet } from 'codemirror-lang-spreadsheet';
9
9
  import { describe, expect, test } from 'vitest';
10
10
 
11
+ import { defaultFunctions } from '@dxos/compute';
12
+
11
13
  import { sheetExtension } from './extension';
12
- import { defaultFunctions } from '../../compute-graph';
13
14
 
14
15
  describe('formula parser', () => {
15
16
  const {
@@ -18,12 +18,11 @@ import { type SyntaxNode } from '@lezer/common';
18
18
  import { tags } from '@lezer/highlight';
19
19
  import { spreadsheet } from 'codemirror-lang-spreadsheet';
20
20
 
21
+ import { type FunctionDefinition } from '@dxos/compute';
22
+ import { RANGE_NOTATION } from '@dxos/compute';
21
23
  import { singleValueFacet } from '@dxos/react-ui-editor';
22
24
  import { mx } from '@dxos/react-ui-theme';
23
25
 
24
- import { type FunctionDefinition } from '../../compute-graph';
25
- import { RANGE_NOTATION } from '../../defs';
26
-
27
26
  /**
28
27
  * https://codemirror.net/examples/styling
29
28
  * https://lezer.codemirror.net/docs/ref/#highlight
package/src/index.ts CHANGED
@@ -4,9 +4,7 @@
4
4
 
5
5
  import { SheetPlugin } from './SheetPlugin';
6
6
 
7
+ export * from './types';
7
8
  export * from './SheetPlugin';
8
9
 
9
- // TODO(burdon): Move to types entrypoint or create a new one.
10
- export * from './defs';
11
-
12
10
  export default SheetPlugin;
@@ -4,13 +4,20 @@
4
4
 
5
5
  import { useCallback, useEffect, useMemo } from 'react';
6
6
 
7
- import { type IntentResolver, LayoutAction, useIntentDispatcher, useIntentResolver } from '@dxos/app-framework';
7
+ import {
8
+ createIntent,
9
+ createResolver,
10
+ LayoutAction,
11
+ useIntentDispatcher,
12
+ useIntentResolver,
13
+ } from '@dxos/app-framework';
8
14
  import { debounce } from '@dxos/async';
15
+ import { type CellAddress, type CompleteCellRange, inRange } from '@dxos/compute';
16
+ import { ThreadAction } from '@dxos/plugin-thread/types';
9
17
  import { fullyQualifiedId } from '@dxos/react-client/echo';
10
18
  import { type DxGridElement, type DxGridPosition } from '@dxos/react-ui-grid';
11
19
 
12
20
  import { useSheetContext } from '../components';
13
- import { type CellAddress, type CompleteCellRange, inRange } from '../defs';
14
21
  import { SHEET_PLUGIN } from '../meta';
15
22
 
16
23
  export const completeCellRangeToThreadCursor = (range: CompleteCellRange): string => {
@@ -32,31 +39,30 @@ export const parseThreadAnchorAsCellRange = (cursor: string): CompleteCellRange
32
39
 
33
40
  export const useUpdateFocusedCellOnThreadSelection = (grid: DxGridElement | null) => {
34
41
  const { model, setActiveRefs } = useSheetContext();
35
- const handleScrollIntoView: IntentResolver = useCallback(
36
- ({ action, data }) => {
37
- switch (action) {
38
- case LayoutAction.SCROLL_INTO_VIEW: {
39
- if (!data?.id || data?.cursor === undefined || data?.id !== fullyQualifiedId(model.sheet)) {
40
- return;
41
- }
42
- setActiveRefs(data.thread);
42
+ const scrollIntoViewResolver = useMemo(
43
+ () =>
44
+ createResolver(
45
+ LayoutAction.ScrollIntoView,
46
+ ({ cursor, ref }) => {
47
+ setActiveRefs(ref);
43
48
  // TODO(Zan): Everywhere we refer to the cursor in a thread context should change to `anchor`.
44
- const range = parseThreadAnchorAsCellRange(data.cursor);
49
+ const range = parseThreadAnchorAsCellRange(cursor!);
45
50
  range && grid?.setFocus({ ...range.to, plane: 'grid' }, true);
46
-
47
- return { data: true };
48
- }
49
- }
50
- },
51
+ },
52
+ {
53
+ disposition: 'hoist',
54
+ filter: (data) => data.id === fullyQualifiedId(model.sheet) && !!data.cursor,
55
+ },
56
+ ),
51
57
  [model.sheet, setActiveRefs],
52
58
  );
53
59
 
54
- useIntentResolver(SHEET_PLUGIN, handleScrollIntoView);
60
+ useIntentResolver(SHEET_PLUGIN, scrollIntoViewResolver);
55
61
  };
56
62
 
57
63
  export const useSelectThreadOnCellFocus = () => {
58
64
  const { model, cursor } = useSheetContext();
59
- const dispatch = useIntentDispatcher();
65
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
60
66
 
61
67
  const threads = useMemo(
62
68
  () => model.sheet.threads?.filter((thread): thread is NonNullable<typeof thread> => !!thread) ?? [],
@@ -72,9 +78,9 @@ export const useSelectThreadOnCellFocus = () => {
72
78
  return;
73
79
  }
74
80
 
75
- const closestThread = threads?.find(({ anchor }) => {
76
- if (anchor) {
77
- const range = parseThreadAnchorAsCellRange(anchor);
81
+ const closestThread = threads?.find((ref) => {
82
+ if (ref.target?.anchor) {
83
+ const range = parseThreadAnchorAsCellRange(ref.target!.anchor);
78
84
  return range ? inRange(range, cellAddress) : false;
79
85
  } else {
80
86
  return false;
@@ -82,9 +88,7 @@ export const useSelectThreadOnCellFocus = () => {
82
88
  });
83
89
 
84
90
  if (closestThread) {
85
- void dispatch([
86
- { action: 'dxos.org/plugin/thread/action/select', data: { current: fullyQualifiedId(closestThread) } },
87
- ]);
91
+ void dispatch(createIntent(ThreadAction.Select, { current: fullyQualifiedId(closestThread) }));
88
92
  }
89
93
  },
90
94
  [dispatch, threads],
@@ -5,20 +5,14 @@
5
5
  import { afterEach, beforeEach, describe, expect, onTestFinished, test } from 'vitest';
6
6
 
7
7
  import { Trigger } from '@dxos/async';
8
+ import { type CellScalarValue, addressFromA1Notation, isFormula } from '@dxos/compute';
9
+ import { TestBuilder, testFunctionPlugins } from '@dxos/compute/testing';
10
+ import { FunctionType } from '@dxos/functions';
8
11
  import { log } from '@dxos/log';
9
- import { FunctionType } from '@dxos/plugin-script/types';
10
12
 
11
13
  import { SheetModel } from './sheet-model';
12
14
  import { createTestGrid } from './testing';
13
- import { TestBuilder, testFunctionPlugins } from '../compute-graph/testing';
14
- import {
15
- addressFromA1Notation,
16
- createSheet,
17
- isFormula,
18
- mapFormulaIndicesToRefs,
19
- mapFormulaRefsToIndices,
20
- } from '../defs';
21
- import { type CellScalarValue } from '../types';
15
+ import { createSheet, mapFormulaIndicesToRefs, mapFormulaRefsToIndices } from '../types';
22
16
 
23
17
  describe('SheetModel', () => {
24
18
  let testBuilder: TestBuilder;
@@ -2,37 +2,45 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { type SimpleCellRange } from 'hyperformula/typings/AbsoluteCellRange';
6
- import { type SimpleCellAddress } from 'hyperformula/typings/Cell';
7
- import { type SimpleDate, type SimpleDateTime } from 'hyperformula/typings/DateTimeHelper';
8
-
9
5
  import { Event } from '@dxos/async';
6
+ import {
7
+ addressFromA1Notation,
8
+ addressToA1Notation,
9
+ createSheetName,
10
+ isFormula,
11
+ type CellAddress,
12
+ type CellRange,
13
+ type CellScalarValue,
14
+ type ComputeGraph,
15
+ type ComputeNode,
16
+ type ComputeNodeEvent,
17
+ DetailedCellError,
18
+ ExportedCellChange,
19
+ type SimpleCellRange,
20
+ type SimpleCellAddress,
21
+ type SimpleDate,
22
+ type SimpleDateTime,
23
+ } from '@dxos/compute';
10
24
  import { Resource } from '@dxos/context';
11
25
  import { getTypename, FormatEnum, TypeEnum } from '@dxos/echo-schema';
12
26
  import { invariant } from '@dxos/invariant';
13
27
  import { PublicKey } from '@dxos/keys';
14
28
  import { log } from '@dxos/log';
15
29
 
16
- import { DetailedCellError, ExportedCellChange } from '#hyperformula';
17
- import { type ComputeGraph, type ComputeNode, type ComputeNodeEvent, createSheetName } from '../compute-graph';
18
30
  import {
19
- addressFromA1Notation,
31
+ ReadonlyException,
20
32
  addressFromIndex,
21
- addressToA1Notation,
22
33
  addressToIndex,
23
34
  initialize,
24
35
  insertIndices,
25
- isFormula,
26
- type CellAddress,
27
- type CellRange,
28
- ReadonlyException,
29
- MAX_COLUMNS,
30
- MAX_ROWS,
31
36
  mapFormulaIndicesToRefs,
32
37
  mapFormulaRefsToIndices,
33
- } from '../defs';
34
- import { type CellScalarValue, type CellValue, type SheetType, type RestoreAxis } from '../types';
38
+ MAX_ROWS,
39
+ MAX_COLS,
40
+ } from '../types';
41
+ import { type SheetAction, type CellValue, type SheetType } from '../types';
35
42
 
43
+ // TODO(burdon): Move to compute.
36
44
  // Map sheet types to system types.
37
45
  // https://hyperformula.handsontable.com/guide/types-of-values.html
38
46
  // - https://github.com/handsontable/hyperformula/blob/master/src/Cell.ts (CellValueType)
@@ -176,12 +184,12 @@ export class SheetModel extends Resource {
176
184
  }
177
185
 
178
186
  insertColumns(i: number, n = 1) {
179
- const idx = insertIndices(this._sheet.columns, i, n, MAX_COLUMNS);
187
+ const idx = insertIndices(this._sheet.columns, i, n, MAX_COLS);
180
188
  this.reset();
181
189
  return idx;
182
190
  }
183
191
 
184
- dropRow(rowIndex: string): RestoreAxis {
192
+ dropRow(rowIndex: string): SheetAction.RestoreAxis {
185
193
  const range = {
186
194
  from: addressFromIndex(this._sheet, `${this._sheet.columns[0]}@${rowIndex}`),
187
195
  to: addressFromIndex(this._sheet, `${this._sheet.columns[this._sheet.columns.length - 1]}@${rowIndex}`),
@@ -195,7 +203,7 @@ export class SheetModel extends Resource {
195
203
  return { axis: 'row', index, axisIndex: rowIndex, axisMeta: this._sheet.rowMeta[rowIndex], values };
196
204
  }
197
205
 
198
- dropColumn(colIndex: string): RestoreAxis {
206
+ dropColumn(colIndex: string): SheetAction.RestoreAxis {
199
207
  const range = {
200
208
  from: addressFromIndex(this._sheet, `${colIndex}@${this._sheet.rows[0]}`),
201
209
  to: addressFromIndex(this._sheet, `${colIndex}@${this._sheet.rows[this._sheet.rows.length - 1]}`),
@@ -209,7 +217,7 @@ export class SheetModel extends Resource {
209
217
  return { axis: 'col', index, axisIndex: colIndex, axisMeta: this._sheet.rowMeta[colIndex], values };
210
218
  }
211
219
 
212
- restoreRow({ index, axisIndex, axisMeta, values }: RestoreAxis) {
220
+ restoreRow({ index, axisIndex, axisMeta, values }: SheetAction.RestoreAxis) {
213
221
  this._sheet.rows.splice(index, 0, axisIndex);
214
222
  values.forEach((value, col) => {
215
223
  if (value) {
@@ -222,7 +230,7 @@ export class SheetModel extends Resource {
222
230
  this.reset();
223
231
  }
224
232
 
225
- restoreColumn({ index, axisIndex, axisMeta, values }: RestoreAxis) {
233
+ restoreColumn({ index, axisIndex, axisMeta, values }: SheetAction.RestoreAxis) {
226
234
  this._sheet.columns.splice(index, 0, axisIndex);
227
235
  values.forEach((value, row) => {
228
236
  if (value) {
@@ -373,7 +381,7 @@ export class SheetModel extends Resource {
373
381
  refresh = true;
374
382
  }
375
383
  if (cell.col >= this._sheet.columns.length) {
376
- insertIndices(this._sheet.columns, cell.col, 1, MAX_COLUMNS);
384
+ insertIndices(this._sheet.columns, cell.col, 1, MAX_COLS);
377
385
  refresh = true;
378
386
  }
379
387