@dxos/plugin-sheet 0.8.4-main.67995b8 → 0.8.4-main.dedc0f3

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 (142) hide show
  1. package/dist/lib/browser/{SheetContainer-KDGD4AVG.mjs → SheetContainer-OUN6AARA.mjs} +20 -21
  2. package/dist/lib/browser/SheetContainer-OUN6AARA.mjs.map +7 -0
  3. package/dist/lib/browser/{anchor-sort-VHURGBOY.mjs → anchor-sort-7WD2VGXW.mjs} +2 -2
  4. package/dist/lib/browser/{anchor-sort-VHURGBOY.mjs.map → anchor-sort-7WD2VGXW.mjs.map} +1 -1
  5. package/dist/lib/browser/{chunk-7HQX4NQP.mjs → chunk-SSN4HYJL.mjs} +6 -6
  6. package/dist/lib/browser/chunk-SSN4HYJL.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-JUOVL3LE.mjs → chunk-X4EWLDT3.mjs} +197 -193
  8. package/dist/lib/browser/chunk-X4EWLDT3.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-SI4X5GUR.mjs → chunk-XSXUU6FO.mjs} +19 -5
  10. package/dist/lib/browser/chunk-XSXUU6FO.mjs.map +7 -0
  11. package/dist/lib/browser/{compute-graph-registry-VG7VP7IV.mjs → compute-graph-registry-6YJHXORG.mjs} +1 -1
  12. package/dist/lib/{node-esm/compute-graph-registry-3K3Q2A5T.mjs.map → browser/compute-graph-registry-6YJHXORG.mjs.map} +2 -2
  13. package/dist/lib/browser/index.mjs +7 -7
  14. package/dist/lib/browser/index.mjs.map +3 -3
  15. package/dist/lib/browser/{intent-resolver-WOJGZMSV.mjs → intent-resolver-ROEY4LHM.mjs} +3 -3
  16. package/dist/lib/browser/{intent-resolver-WOJGZMSV.mjs.map → intent-resolver-ROEY4LHM.mjs.map} +3 -3
  17. package/dist/lib/browser/{markdown-VXMIPUQC.mjs → markdown-VOY636TS.mjs} +2 -2
  18. package/dist/lib/browser/markdown-VOY636TS.mjs.map +7 -0
  19. package/dist/lib/browser/meta.json +1 -1
  20. package/dist/lib/browser/{react-surface-SE4HGAEH.mjs → react-surface-XCNAVF2M.mjs} +4 -4
  21. package/dist/lib/browser/{react-surface-SE4HGAEH.mjs.map → react-surface-XCNAVF2M.mjs.map} +2 -2
  22. package/dist/lib/browser/types/index.mjs +1 -1
  23. package/dist/lib/node-esm/{SheetContainer-RMG24NZC.mjs → SheetContainer-NFLLTGNV.mjs} +20 -21
  24. package/dist/lib/node-esm/SheetContainer-NFLLTGNV.mjs.map +7 -0
  25. package/dist/lib/node-esm/{anchor-sort-CTJGOPET.mjs → anchor-sort-ACQDUIPU.mjs} +2 -2
  26. package/dist/lib/node-esm/{anchor-sort-CTJGOPET.mjs.map → anchor-sort-ACQDUIPU.mjs.map} +1 -1
  27. package/dist/lib/node-esm/{chunk-Q6UYC4G5.mjs → chunk-IK4O7FUJ.mjs} +6 -6
  28. package/dist/lib/node-esm/chunk-IK4O7FUJ.mjs.map +7 -0
  29. package/dist/lib/node-esm/{chunk-CADTJFAS.mjs → chunk-ODP4L4OV.mjs} +19 -5
  30. package/dist/lib/node-esm/chunk-ODP4L4OV.mjs.map +7 -0
  31. package/dist/lib/node-esm/{chunk-IFMIRCZH.mjs → chunk-PYF4ZJXN.mjs} +197 -193
  32. package/dist/lib/node-esm/chunk-PYF4ZJXN.mjs.map +7 -0
  33. package/dist/lib/node-esm/{compute-graph-registry-3K3Q2A5T.mjs → compute-graph-registry-ET5KJNLV.mjs} +1 -1
  34. package/dist/lib/{browser/compute-graph-registry-VG7VP7IV.mjs.map → node-esm/compute-graph-registry-ET5KJNLV.mjs.map} +2 -2
  35. package/dist/lib/node-esm/index.mjs +7 -7
  36. package/dist/lib/node-esm/index.mjs.map +3 -3
  37. package/dist/lib/node-esm/{intent-resolver-PZRXBNIJ.mjs → intent-resolver-HESRI2ML.mjs} +3 -3
  38. package/dist/lib/node-esm/{intent-resolver-PZRXBNIJ.mjs.map → intent-resolver-HESRI2ML.mjs.map} +3 -3
  39. package/dist/lib/node-esm/{markdown-4VPQJZNZ.mjs → markdown-P4CLZ24C.mjs} +2 -2
  40. package/dist/lib/node-esm/markdown-P4CLZ24C.mjs.map +7 -0
  41. package/dist/lib/node-esm/meta.json +1 -1
  42. package/dist/lib/node-esm/{react-surface-LAU23XBH.mjs → react-surface-KE3EEVF4.mjs} +4 -4
  43. package/dist/lib/node-esm/{react-surface-LAU23XBH.mjs.map → react-surface-KE3EEVF4.mjs.map} +2 -2
  44. package/dist/lib/node-esm/types/index.mjs +1 -1
  45. package/dist/types/src/capabilities/anchor-sort.d.ts +2 -2
  46. package/dist/types/src/capabilities/compute-graph-registry.d.ts +1 -1
  47. package/dist/types/src/capabilities/compute-graph-registry.d.ts.map +1 -1
  48. package/dist/types/src/capabilities/index.d.ts +6 -8
  49. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  50. package/dist/types/src/capabilities/intent-resolver.d.ts +1 -1
  51. package/dist/types/src/capabilities/intent-resolver.d.ts.map +1 -1
  52. package/dist/types/src/capabilities/markdown.d.ts +1 -3
  53. package/dist/types/src/capabilities/markdown.d.ts.map +1 -1
  54. package/dist/types/src/capabilities/react-surface.d.ts +1 -1
  55. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  56. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +1 -1
  57. package/dist/types/src/components/ComputeGraph/compute-graph.stories.d.ts +9 -3
  58. package/dist/types/src/components/ComputeGraph/compute-graph.stories.d.ts.map +1 -1
  59. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
  60. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +49 -2
  61. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -1
  62. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts +11 -19
  63. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +1 -1
  64. package/dist/types/src/components/GridSheet/util.d.ts +1 -1
  65. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -1
  66. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -1
  67. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +49 -2
  68. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -1
  69. package/dist/types/src/components/SheetContext/SheetContext.d.ts +1 -1
  70. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -1
  71. package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts.map +1 -1
  72. package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts +86 -3
  73. package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts.map +1 -1
  74. package/dist/types/src/components/SheetToolbar/align.d.ts +2 -2
  75. package/dist/types/src/components/SheetToolbar/align.d.ts.map +1 -1
  76. package/dist/types/src/components/SheetToolbar/style.d.ts.map +1 -1
  77. package/dist/types/src/extensions/compute.d.ts +1 -1
  78. package/dist/types/src/extensions/compute.d.ts.map +1 -1
  79. package/dist/types/src/extensions/compute.stories.d.ts +10 -12
  80. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -1
  81. package/dist/types/src/extensions/editor/index.d.ts +1 -1
  82. package/dist/types/src/extensions/editor/index.d.ts.map +1 -1
  83. package/dist/types/src/extensions/editor/{extension.d.ts → sheet-extension.d.ts} +1 -1
  84. package/dist/types/src/extensions/editor/sheet-extension.d.ts.map +1 -0
  85. package/dist/types/src/extensions/editor/sheet-extension.test.d.ts +2 -0
  86. package/dist/types/src/extensions/editor/sheet-extension.test.d.ts.map +1 -0
  87. package/dist/types/src/model/sheet-model.d.ts +1 -1
  88. package/dist/types/src/model/sheet-model.d.ts.map +1 -1
  89. package/dist/types/src/playwright/sheet-manager.d.ts +1 -1
  90. package/dist/types/src/playwright/sheet-manager.d.ts.map +1 -1
  91. package/dist/types/src/testing/testing.d.ts.map +1 -1
  92. package/dist/types/src/types/types.d.ts +1 -1
  93. package/dist/types/src/types/types.d.ts.map +1 -1
  94. package/dist/types/src/types/util.d.ts.map +1 -1
  95. package/dist/types/tsconfig.tsbuildinfo +1 -1
  96. package/package.json +58 -58
  97. package/src/SheetPlugin.tsx +2 -2
  98. package/src/capabilities/anchor-sort.ts +1 -1
  99. package/src/capabilities/compute-graph-registry.ts +1 -1
  100. package/src/capabilities/intent-resolver.ts +2 -2
  101. package/src/capabilities/markdown.ts +3 -2
  102. package/src/capabilities/react-surface.tsx +2 -1
  103. package/src/components/ComputeGraph/ComputeGraphContextProvider.tsx +1 -1
  104. package/src/components/ComputeGraph/compute-graph.stories.tsx +13 -10
  105. package/src/components/GridSheet/GridSheet.stories.tsx +8 -5
  106. package/src/components/GridSheet/GridSheet.tsx +19 -18
  107. package/src/components/GridSheet/SheetCellEditor.stories.tsx +37 -38
  108. package/src/components/GridSheet/util.ts +6 -6
  109. package/src/components/SheetContainer/SheetContainer.stories.tsx +9 -6
  110. package/src/components/SheetContainer/SheetContainer.tsx +1 -1
  111. package/src/components/SheetContext/SheetContext.tsx +1 -1
  112. package/src/components/SheetToolbar/SheetToolbar.stories.tsx +10 -7
  113. package/src/components/SheetToolbar/SheetToolbar.tsx +16 -15
  114. package/src/components/SheetToolbar/align.ts +4 -3
  115. package/src/components/SheetToolbar/style.ts +2 -2
  116. package/src/extensions/compute.stories.tsx +20 -19
  117. package/src/extensions/compute.ts +2 -3
  118. package/src/extensions/editor/index.ts +1 -1
  119. package/src/extensions/editor/{extension.test.ts → sheet-extension.test.ts} +1 -1
  120. package/src/integrations/thread-ranges.ts +4 -4
  121. package/src/model/sheet-model.test.ts +2 -1
  122. package/src/model/sheet-model.ts +6 -6
  123. package/src/playwright/sheet-manager.ts +1 -1
  124. package/src/playwright/sheet.spec.ts +1 -1
  125. package/src/sanity.test.ts +1 -1
  126. package/src/testing/testing.tsx +1 -1
  127. package/src/types/types.ts +2 -1
  128. package/src/types/util.ts +3 -3
  129. package/dist/lib/browser/SheetContainer-KDGD4AVG.mjs.map +0 -7
  130. package/dist/lib/browser/chunk-7HQX4NQP.mjs.map +0 -7
  131. package/dist/lib/browser/chunk-JUOVL3LE.mjs.map +0 -7
  132. package/dist/lib/browser/chunk-SI4X5GUR.mjs.map +0 -7
  133. package/dist/lib/browser/markdown-VXMIPUQC.mjs.map +0 -7
  134. package/dist/lib/node-esm/SheetContainer-RMG24NZC.mjs.map +0 -7
  135. package/dist/lib/node-esm/chunk-CADTJFAS.mjs.map +0 -7
  136. package/dist/lib/node-esm/chunk-IFMIRCZH.mjs.map +0 -7
  137. package/dist/lib/node-esm/chunk-Q6UYC4G5.mjs.map +0 -7
  138. package/dist/lib/node-esm/markdown-4VPQJZNZ.mjs.map +0 -7
  139. package/dist/types/src/extensions/editor/extension.d.ts.map +0 -1
  140. package/dist/types/src/extensions/editor/extension.test.d.ts +0 -2
  141. package/dist/types/src/extensions/editor/extension.test.d.ts.map +0 -1
  142. /package/src/extensions/editor/{extension.ts → sheet-extension.ts} +0 -0
@@ -4,7 +4,7 @@
4
4
 
5
5
  import React from 'react';
6
6
 
7
- import { fullyQualifiedId, type Space } from '@dxos/react-client/echo';
7
+ import { type Space, fullyQualifiedId } from '@dxos/react-client/echo';
8
8
  import { StackItem } from '@dxos/react-ui-stack';
9
9
 
10
10
  import { type SheetType } from '../../types';
@@ -4,7 +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
+ import { type CellAddress, type CellRange, type CompleteCellRange, type ComputeGraph } from '@dxos/compute';
8
8
  import { invariant } from '@dxos/invariant';
9
9
  import { fullyQualifiedId } from '@dxos/react-client/echo';
10
10
  import {
@@ -4,26 +4,29 @@
4
4
 
5
5
  import '@dxos-theme';
6
6
 
7
- import { type Meta } from '@storybook/react-vite';
7
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
8
8
  import React from 'react';
9
9
 
10
10
  import { withLayout, withTheme } from '@dxos/storybook-utils';
11
11
 
12
- import { SheetToolbar } from './SheetToolbar';
13
12
  import { translations } from '../../translations';
14
13
 
14
+ import { SheetToolbar } from './SheetToolbar';
15
+
15
16
  const DefaultStory = () => {
16
17
  return <SheetToolbar id='test' />;
17
18
  };
18
19
 
19
- export const Default = {};
20
-
21
- const meta: Meta = {
20
+ const meta = {
22
21
  title: 'plugins/plugin-sheet/Toolbar',
23
- component: SheetToolbar,
22
+ component: SheetToolbar as any,
24
23
  render: DefaultStory,
25
24
  decorators: [withTheme, withLayout()],
26
25
  parameters: { translations, layout: 'fullscreen' },
27
- };
26
+ } satisfies Meta<typeof DefaultStory>;
28
27
 
29
28
  export default meta;
29
+
30
+ type Story = StoryObj<typeof meta>;
31
+
32
+ export const Default: Story = {};
@@ -9,21 +9,20 @@ import { useAppGraph } from '@dxos/app-framework';
9
9
  import { type CompleteCellRange } from '@dxos/compute';
10
10
  import { type ThemedClassName } from '@dxos/react-ui';
11
11
  import {
12
- type ActionGraphEdges,
13
- type ActionGraphNodes,
14
12
  type ActionGraphProps,
15
- createGapSeparator,
16
13
  MenuProvider,
17
- rxFromSignal,
18
14
  ToolbarMenu,
15
+ createGapSeparator,
16
+ rxFromSignal,
19
17
  useMenuActions,
20
18
  } from '@dxos/react-ui-menu';
21
19
 
20
+ import { type SheetModel } from '../../model';
21
+ import { useSheetContext } from '../SheetContext';
22
+
22
23
  import { createAlign, useAlignState } from './align';
23
24
  import { createStyle, useStyleState } from './style';
24
25
  import { type ToolbarState, useToolbarState } from './useToolbarState';
25
- import { type SheetModel } from '../../model';
26
- import { useSheetContext } from '../SheetContext';
27
26
 
28
27
  //
29
28
  // Root
@@ -36,22 +35,24 @@ const createToolbarActions = (
36
35
  state: ToolbarState,
37
36
  cursorFallbackRange?: CompleteCellRange,
38
37
  customActions?: Rx.Rx<ActionGraphProps>,
39
- ) => {
38
+ ): Rx.Rx<ActionGraphProps> => {
40
39
  return Rx.make((get) => {
41
40
  const align = get(rxFromSignal(() => createAlign(model, state, cursorFallbackRange)));
42
41
  const style = get(rxFromSignal(() => createStyle(model, state, cursorFallbackRange)));
43
42
  const gap = createGapSeparator();
44
- const nodes: ActionGraphNodes = [...align.nodes, ...style.nodes, ...gap.nodes];
45
- const edges: ActionGraphEdges = [...align.edges, ...style.edges, ...gap.edges];
43
+
44
+ const graph: ActionGraphProps = {
45
+ nodes: [...align.nodes, ...style.nodes, ...gap.nodes],
46
+ edges: [...align.edges, ...style.edges, ...gap.edges],
47
+ };
48
+
46
49
  if (customActions) {
47
50
  const custom = get(customActions);
48
- nodes.push(...custom.nodes);
49
- edges.push(...custom.edges);
51
+ graph.nodes.push(...custom.nodes);
52
+ graph.edges.push(...custom.edges);
50
53
  }
51
- return {
52
- nodes,
53
- edges,
54
- };
54
+
55
+ return graph;
55
56
  });
56
57
  };
57
58
 
@@ -5,14 +5,15 @@
5
5
  import { useEffect } from 'react';
6
6
 
7
7
  import { type CompleteCellRange, inRange } from '@dxos/compute';
8
- import { createMenuAction, createMenuItemGroup, type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
8
+ import { type ToolbarMenuActionGroupProperties, createMenuAction, createMenuItemGroup } from '@dxos/react-ui-menu';
9
9
 
10
- import { type ToolbarState } from './useToolbarState';
11
10
  import { SHEET_PLUGIN } from '../../meta';
12
11
  import { type SheetModel } from '../../model';
13
- import { type AlignKey, alignKey, type AlignValue, rangeFromIndex, rangeToIndex } from '../../types';
12
+ import { type AlignKey, type AlignValue, alignKey, rangeFromIndex, rangeToIndex } from '../../types';
14
13
  import { useSheetContext } from '../SheetContext';
15
14
 
15
+ import { type ToolbarState } from './useToolbarState';
16
+
16
17
  export type AlignAction = { key: AlignKey; value: AlignValue };
17
18
 
18
19
  export type AlignState = { [alignKey]: AlignValue | undefined };
@@ -5,11 +5,11 @@
5
5
  import { useEffect } from 'react';
6
6
 
7
7
  import { type CompleteCellRange, inRange } from '@dxos/compute';
8
- import { createMenuAction, createMenuItemGroup, type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
8
+ import { type ToolbarMenuActionGroupProperties, createMenuAction, createMenuItemGroup } from '@dxos/react-ui-menu';
9
9
 
10
10
  import { SHEET_PLUGIN } from '../../meta';
11
11
  import { type SheetModel } from '../../model';
12
- import { rangeFromIndex, rangeToIndex, type StyleKey, type StyleValue } from '../../types';
12
+ import { type StyleKey, type StyleValue, rangeFromIndex, rangeToIndex } from '../../types';
13
13
  import { useSheetContext } from '../SheetContext';
14
14
 
15
15
  export type StyleState = Partial<Record<StyleValue, boolean>>;
@@ -4,7 +4,7 @@
4
4
 
5
5
  import '@dxos-theme';
6
6
 
7
- import { type Meta } from '@storybook/react-vite';
7
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
8
8
  import React, { useEffect, useMemo } from 'react';
9
9
 
10
10
  import { PublicKey } from '@dxos/keys';
@@ -19,15 +19,16 @@ import {
19
19
  documentId,
20
20
  useTextEditor,
21
21
  } from '@dxos/react-ui-editor';
22
- import { withTheme, withLayout } from '@dxos/storybook-utils';
22
+ import { withLayout, withTheme } from '@dxos/storybook-utils';
23
23
  import { isNonNullable } from '@dxos/util';
24
24
 
25
- import { compute, computeGraphFacet } from './compute';
26
25
  import { GridSheet, SheetProvider, useComputeGraph } from '../components';
27
26
  import { useSheetModel } from '../model';
28
27
  import { useTestSheet, withComputeGraphDecorator } from '../testing';
29
28
  import { SheetType } from '../types';
30
29
 
30
+ import { compute, computeGraphFacet } from './compute';
31
+
31
32
  const str = (...lines: string[]) => lines.join('\n');
32
33
 
33
34
  type EditorProps = {
@@ -51,7 +52,7 @@ const EditorStory = ({ text }: EditorProps) => {
51
52
  initialValue: text,
52
53
  extensions: [
53
54
  createBasicExtensions(),
54
- createMarkdownExtensions({ themeMode }),
55
+ createMarkdownExtensions(),
55
56
  createThemeExtensions({ themeMode, syntaxHighlighting: true }),
56
57
  documentId.of(id.toHex()),
57
58
  computeGraph && computeGraphFacet.of(computeGraph),
@@ -98,8 +99,21 @@ const GraphStory = (props: EditorProps) => {
98
99
  );
99
100
  };
100
101
 
102
+ const meta = {
103
+ title: 'plugins/plugin-sheet/extensions',
104
+ decorators: [
105
+ withClientProvider({ types: [SheetType], createIdentity: true, createSpace: true }),
106
+ withComputeGraphDecorator(),
107
+ withTheme,
108
+ withLayout({ fullscreen: true, classNames: 'justify-center' }),
109
+ ],
110
+ parameters: { layout: 'fullscreen' },
111
+ } satisfies Meta;
112
+
113
+ export default meta;
114
+
101
115
  // TODO(burdon): Inline formulae.
102
- export const Default = {
116
+ export const Default: StoryObj<typeof EditorStory> = {
103
117
  render: EditorStory,
104
118
  args: {
105
119
  text: str(
@@ -123,7 +137,7 @@ export const Default = {
123
137
  },
124
138
  };
125
139
 
126
- export const Graph = {
140
+ export const Graph: StoryObj<typeof GraphStory> = {
127
141
  render: GraphStory,
128
142
  args: {
129
143
  text: str(
@@ -140,16 +154,3 @@ export const Graph = {
140
154
  ),
141
155
  },
142
156
  };
143
-
144
- const meta: Meta = {
145
- title: 'plugins/plugin-sheet/extensions',
146
- decorators: [
147
- withClientProvider({ types: [SheetType], createIdentity: true, createSpace: true }),
148
- withComputeGraphDecorator(),
149
- withTheme,
150
- withLayout({ fullscreen: true, classNames: 'justify-center' }),
151
- ],
152
- parameters: { layout: 'fullscreen' },
153
- };
154
-
155
- export default meta;
@@ -16,11 +16,11 @@ import { Decoration, EditorView, ViewPlugin, WidgetType } from '@codemirror/view
16
16
 
17
17
  import { type CleanupFn, debounce } from '@dxos/async';
18
18
  import {
19
- createSheetName,
20
19
  type CellAddress,
21
20
  type CellScalarValue,
22
21
  type ComputeGraph,
23
22
  type ComputeNode,
23
+ createSheetName,
24
24
  } from '@dxos/compute';
25
25
  import { invariant } from '@dxos/invariant';
26
26
  import { documentId, singleValueFacet } from '@dxos/react-ui-editor';
@@ -34,7 +34,7 @@ export const computeGraphFacet = singleValueFacet<ComputeGraph>();
34
34
 
35
35
  export type ComputeOptions = {};
36
36
 
37
- export const compute = (options: ComputeOptions = {}): Extension => {
37
+ export const compute = (_options: ComputeOptions = {}): Extension => {
38
38
  let computeNode: ComputeNode | undefined;
39
39
 
40
40
  const update = (state: EditorState, current?: RangeSet<Decoration>) => {
@@ -53,7 +53,6 @@ export const compute = (options: ComputeOptions = {}): Extension => {
53
53
  const text = node.node.getChild('CodeText');
54
54
  if (type === LANGUAGE_TAG && text) {
55
55
  const formula = state.sliceDoc(text.from, text.to);
56
-
57
56
  const iter = current?.iter(node.node.from);
58
57
  if (iter?.value && iter?.value.spec.formula === formula) {
59
58
  // Add existing widget.
@@ -2,4 +2,4 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- export * from './extension';
5
+ export * from './sheet-extension';
@@ -10,7 +10,7 @@ import { describe, expect, test } from 'vitest';
10
10
 
11
11
  import { defaultFunctions } from '@dxos/compute';
12
12
 
13
- import { sheetExtension } from './extension';
13
+ import { sheetExtension } from './sheet-extension';
14
14
 
15
15
  describe('formula parser', () => {
16
16
  const {
@@ -6,19 +6,19 @@ import { Schema, pipe } from 'effect';
6
6
  import { useCallback, useEffect, useMemo } from 'react';
7
7
 
8
8
  import {
9
+ LayoutAction,
10
+ chain,
9
11
  createIntent,
10
12
  createResolver,
11
- LayoutAction,
12
- useIntentResolver,
13
13
  useIntentDispatcher,
14
- chain,
14
+ useIntentResolver,
15
15
  } from '@dxos/app-framework';
16
16
  import { debounce } from '@dxos/async';
17
17
  import { type CellAddress, type CompleteCellRange, inRange } from '@dxos/compute';
18
18
  import { Obj, Relation } from '@dxos/echo';
19
19
  import { ATTENDABLE_PATH_SEPARATOR, DeckAction } from '@dxos/plugin-deck/types';
20
20
  import { ThreadAction, ThreadType } from '@dxos/plugin-thread/types';
21
- import { Filter, fullyQualifiedId, getSpace, Query, useQuery } from '@dxos/react-client/echo';
21
+ import { Filter, Query, fullyQualifiedId, getSpace, useQuery } from '@dxos/react-client/echo';
22
22
  import { type DxGridElement, type GridContentProps } from '@dxos/react-ui-grid';
23
23
  import { AnchoredTo } from '@dxos/schema';
24
24
 
@@ -10,9 +10,10 @@ import { TestBuilder, testFunctionPlugins } from '@dxos/compute/testing';
10
10
  import { FunctionType } from '@dxos/functions';
11
11
  import { log } from '@dxos/log';
12
12
 
13
+ import { createSheet, mapFormulaIndicesToRefs, mapFormulaRefsToIndices } from '../types';
14
+
13
15
  import { SheetModel } from './sheet-model';
14
16
  import { createTestGrid } from './testing';
15
- import { createSheet, mapFormulaIndicesToRefs, mapFormulaRefsToIndices } from '../types';
16
17
 
17
18
  describe('SheetModel', () => {
18
19
  let testBuilder: TestBuilder;
@@ -4,10 +4,6 @@
4
4
 
5
5
  import { Event } from '@dxos/async';
6
6
  import {
7
- addressFromA1Notation,
8
- addressToA1Notation,
9
- createSheetName,
10
- isFormula,
11
7
  type CellAddress,
12
8
  type CellRange,
13
9
  type CellScalarValue,
@@ -16,10 +12,14 @@ import {
16
12
  type ComputeNodeEvent,
17
13
  DetailedCellError,
18
14
  ExportedCellChange,
19
- type SimpleCellRange,
20
15
  type SimpleCellAddress,
16
+ type SimpleCellRange,
21
17
  type SimpleDate,
22
18
  type SimpleDateTime,
19
+ addressFromA1Notation,
20
+ addressToA1Notation,
21
+ createSheetName,
22
+ isFormula,
23
23
  } from '@dxos/compute';
24
24
  import { Resource } from '@dxos/context';
25
25
  import { Obj } from '@dxos/echo';
@@ -39,7 +39,7 @@ import {
39
39
  mapFormulaIndicesToRefs,
40
40
  mapFormulaRefsToIndices,
41
41
  } from '../types';
42
- import { type SheetAction, type CellValue, type SheetType } from '../types';
42
+ import { type CellValue, type SheetAction, type SheetType } from '../types';
43
43
 
44
44
  // TODO(burdon): Move to compute.
45
45
  // Map sheet types to system types.
@@ -5,7 +5,7 @@
5
5
  import { type Locator, type Page } from '@playwright/test';
6
6
 
7
7
  import { DxGridManager } from '@dxos/lit-grid/testing';
8
- import { type DxGridPosition, type DxGridAxis } from '@dxos/react-ui-grid';
8
+ import { type DxGridAxis, type DxGridPosition } from '@dxos/react-ui-grid';
9
9
 
10
10
  /**
11
11
  * Test helper for managing dx-grid interactions and assertions in Playwright tests.
@@ -2,7 +2,7 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- import { expect, test, type Page } from '@playwright/test';
5
+ import { type Page, expect, test } from '@playwright/test';
6
6
 
7
7
  import { faker } from '@dxos/random';
8
8
  import { setupPage, storybookUrl } from '@dxos/test-utils/playwright';
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { describe, test, expect } from 'vitest';
5
+ import { describe, expect, test } from 'vitest';
6
6
 
7
7
  import { Client } from '@dxos/client';
8
8
  import { Obj } from '@dxos/echo';
@@ -10,7 +10,7 @@ import { type Space } from '@dxos/react-client/echo';
10
10
  import { useAsyncState } from '@dxos/react-hooks';
11
11
 
12
12
  import { ComputeGraphContextProvider } from '../components';
13
- import { createSheet, type CreateSheetOptions } from '../types';
13
+ import { type CreateSheetOptions, createSheet } from '../types';
14
14
 
15
15
  export const useTestSheet = (space?: Space, graph?: ComputeGraph, options?: CreateSheetOptions) => {
16
16
  const [sheet] = useAsyncState(async () => {
@@ -4,10 +4,11 @@
4
4
 
5
5
  import { Schema } from 'effect';
6
6
 
7
- import { type CellValue, RowColumnMeta, SheetType } from './schema';
8
7
  import { SHEET_PLUGIN } from '../meta';
9
8
  import { SheetModel } from '../model';
10
9
 
10
+ import { type CellValue, RowColumnMeta, SheetType } from './schema';
11
+
11
12
  export type SheetSize = {
12
13
  rows: number;
13
14
  columns: number;
package/src/types/util.ts CHANGED
@@ -3,12 +3,12 @@
3
3
  //
4
4
 
5
5
  import {
6
- addressFromA1Notation,
7
- addressToA1Notation,
8
- isFormula,
9
6
  type CellAddress,
10
7
  type CellRange,
11
8
  type CompleteCellRange,
9
+ addressFromA1Notation,
10
+ addressToA1Notation,
11
+ isFormula,
12
12
  } from '@dxos/compute';
13
13
  import { randomBytes } from '@dxos/crypto';
14
14
  import { Obj } from '@dxos/echo';
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/SheetContainer/SheetContainer.tsx", "../../../src/components/FunctionEditor/FunctionEditor.tsx", "../../../src/components/SheetToolbar/SheetToolbar.tsx", "../../../src/components/SheetToolbar/align.ts", "../../../src/components/SheetToolbar/style.ts", "../../../src/components/SheetToolbar/useToolbarState.ts", "../../../src/components/SheetContainer/index.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { fullyQualifiedId, type Space } from '@dxos/react-client/echo';\nimport { StackItem } from '@dxos/react-ui-stack';\n\nimport { type SheetType } from '../../types';\nimport { useComputeGraph } from '../ComputeGraph';\nimport { FunctionEditor } from '../FunctionEditor';\nimport { GridSheet } from '../GridSheet';\nimport { SheetProvider } from '../SheetContext';\nimport { SheetToolbar } from '../SheetToolbar';\n\nexport type SheetContainerProps = {\n space: Space;\n sheet: SheetType;\n role?: string;\n ignoreAttention?: boolean;\n};\n\nexport const SheetContainer = ({ space, sheet, role, ignoreAttention }: SheetContainerProps) => {\n const graph = useComputeGraph(space);\n\n return graph ? (\n <SheetProvider sheet={sheet} graph={graph} ignoreAttention={ignoreAttention}>\n <StackItem.Content toolbar statusbar {...(role === 'section' && { classNames: 'aspect-video' })}>\n <SheetToolbar id={fullyQualifiedId(sheet)} />\n <GridSheet />\n <FunctionEditor />\n </StackItem.Content>\n </SheetProvider>\n ) : null;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React from 'react';\n\nimport { addressToA1Notation, isFormula, rangeToA1Notation } from '@dxos/compute';\nimport { Icon } from '@dxos/react-ui';\n\nimport { mapFormulaIndicesToRefs } from '../../types';\nimport { useSheetContext } from '../SheetContext';\n\nexport const FunctionEditor = () => {\n const { model, cursor, range } = useSheetContext();\n\n let value;\n let formula = false;\n if (cursor) {\n value = model.getCellValue(cursor);\n if (isFormula(value)) {\n value = model.graph.mapFunctionBindingFromId(mapFormulaIndicesToRefs(model.sheet, value));\n formula = true;\n } else if (value != null) {\n value = String(value);\n }\n }\n\n return (\n <div className='flex shrink-0 justify-between items-center px-4 py-1 text-sm bg-toolbarSurface border-bs !border-subduedSeparator'>\n <div className='flex gap-4 items-center'>\n <div className='flex w-16 items-center font-mono'>\n {(range && rangeToA1Notation(range)) || (cursor && addressToA1Notation(cursor))}\n </div>\n <div className='flex gap-2 items-center'>\n <Icon icon='ph--function--regular' classNames={['text-greenText', formula ? 'visible' : 'invisible']} />\n <span className='font-mono'>{value}</span>\n </div>\n </div>\n </div>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Rx } from '@effect-rx/rx-react';\nimport React, { type PropsWithChildren, useMemo } from 'react';\n\nimport { useAppGraph } from '@dxos/app-framework';\nimport { type CompleteCellRange } from '@dxos/compute';\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport {\n type ActionGraphEdges,\n type ActionGraphNodes,\n type ActionGraphProps,\n createGapSeparator,\n MenuProvider,\n rxFromSignal,\n ToolbarMenu,\n useMenuActions,\n} from '@dxos/react-ui-menu';\n\nimport { createAlign, useAlignState } from './align';\nimport { createStyle, useStyleState } from './style';\nimport { type ToolbarState, useToolbarState } from './useToolbarState';\nimport { type SheetModel } from '../../model';\nimport { useSheetContext } from '../SheetContext';\n\n//\n// Root\n//\n\nexport type SheetToolbarProps = ThemedClassName<PropsWithChildren<{ id: string }>>;\n\nconst createToolbarActions = (\n model: SheetModel,\n state: ToolbarState,\n cursorFallbackRange?: CompleteCellRange,\n customActions?: Rx.Rx<ActionGraphProps>,\n) => {\n return Rx.make((get) => {\n const align = get(rxFromSignal(() => createAlign(model, state, cursorFallbackRange)));\n const style = get(rxFromSignal(() => createStyle(model, state, cursorFallbackRange)));\n const gap = createGapSeparator();\n const nodes: ActionGraphNodes = [...align.nodes, ...style.nodes, ...gap.nodes];\n const edges: ActionGraphEdges = [...align.edges, ...style.edges, ...gap.edges];\n if (customActions) {\n const custom = get(customActions);\n nodes.push(...custom.nodes);\n edges.push(...custom.edges);\n }\n return {\n nodes,\n edges,\n };\n });\n};\n\nexport const SheetToolbar = ({ id, classNames }: SheetToolbarProps) => {\n const { model, cursorFallbackRange } = useSheetContext();\n const state = useToolbarState({});\n useAlignState(state);\n useStyleState(state);\n\n const { graph } = useAppGraph();\n const customActions = useMemo(() => {\n return Rx.make((get) => {\n const actions = get(graph.actions(id));\n const nodes = actions.filter((action) => action.properties.disposition === 'toolbar');\n return { nodes, edges: nodes.map((node) => ({ source: 'root', target: node.id })) };\n });\n }, [graph]);\n\n const actionsCreator = useMemo(\n () => createToolbarActions(model, state, cursorFallbackRange, customActions),\n [model, state, cursorFallbackRange, customActions],\n );\n const menu = useMenuActions(actionsCreator);\n\n return (\n <MenuProvider {...menu} attendableId={id}>\n <ToolbarMenu classNames={classNames} />\n </MenuProvider>\n );\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect } from 'react';\n\nimport { type CompleteCellRange, inRange } from '@dxos/compute';\nimport { createMenuAction, createMenuItemGroup, type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';\n\nimport { type ToolbarState } from './useToolbarState';\nimport { SHEET_PLUGIN } from '../../meta';\nimport { type SheetModel } from '../../model';\nimport { type AlignKey, alignKey, type AlignValue, rangeFromIndex, rangeToIndex } from '../../types';\nimport { useSheetContext } from '../SheetContext';\n\nexport type AlignAction = { key: AlignKey; value: AlignValue };\n\nexport type AlignState = { [alignKey]: AlignValue | undefined };\n\nconst aligns: Record<AlignValue, string> = {\n start: 'ph--text-align-left--regular',\n center: 'ph--text-align-center--regular',\n end: 'ph--text-align-right--regular',\n};\n\nexport const useAlignState = (state: Partial<AlignState>) => {\n const { cursor, model } = useSheetContext();\n useEffect(() => {\n // TODO(thure): Can this O(n) call be memoized?\n state[alignKey] = (\n cursor\n ? model.sheet.ranges?.findLast(\n ({ range, key }) => key === alignKey && inRange(rangeFromIndex(model.sheet, range), cursor),\n )?.value\n : undefined\n ) as AlignValue | undefined;\n }, [cursor, model.sheet]);\n};\n\nconst createAlignGroupAction = (value?: AlignValue) =>\n createMenuItemGroup('align', {\n label: ['align label', { ns: SHEET_PLUGIN }],\n variant: 'toggleGroup',\n selectCardinality: 'single',\n value: `${alignKey}--${value}`,\n } as ToolbarMenuActionGroupProperties);\n\nconst createAlignActions = (model: SheetModel, state: ToolbarState, cursorFallbackRange?: CompleteCellRange) =>\n Object.entries(aligns).map(([alignValue, icon]) => {\n return createMenuAction<AlignAction>(\n `${alignKey}--${alignValue}`,\n () => {\n if (!cursorFallbackRange) {\n return;\n }\n const index =\n model.sheet.ranges?.findIndex(\n (range) =>\n range.key === alignKey && inRange(rangeFromIndex(model.sheet, range.range), cursorFallbackRange.from),\n ) ?? -1;\n const nextRangeEntity = {\n range: rangeToIndex(model.sheet, cursorFallbackRange),\n key: alignKey,\n value: alignValue as AlignValue,\n };\n if (index < 0) {\n model.sheet.ranges?.push(nextRangeEntity);\n state[alignKey] = nextRangeEntity.value;\n } else if (model.sheet.ranges![index].value === nextRangeEntity.value) {\n model.sheet.ranges?.splice(index, 1);\n state[alignKey] = undefined;\n } else {\n model.sheet.ranges?.splice(index, 1, nextRangeEntity);\n state[alignKey] = nextRangeEntity.value;\n }\n },\n {\n key: alignKey,\n value: alignValue as AlignValue,\n checked: state[alignKey] === alignValue,\n label: [`range value ${alignValue} label`, { ns: SHEET_PLUGIN }],\n icon,\n testId: `grid.toolbar.${alignKey}.${alignValue}`,\n },\n );\n });\n\nexport const createAlign = (model: SheetModel, state: ToolbarState, cursorFallbackRange?: CompleteCellRange) => {\n const alignGroup = createAlignGroupAction(state[alignKey]);\n const alignActions = createAlignActions(model, state, cursorFallbackRange);\n return {\n nodes: [alignGroup, ...alignActions],\n edges: [\n { source: 'root', target: 'align' },\n ...alignActions.map(({ id }) => ({ source: alignGroup.id, target: id })),\n ],\n };\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect } from 'react';\n\nimport { type CompleteCellRange, inRange } from '@dxos/compute';\nimport { createMenuAction, createMenuItemGroup, type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';\n\nimport { SHEET_PLUGIN } from '../../meta';\nimport { type SheetModel } from '../../model';\nimport { rangeFromIndex, rangeToIndex, type StyleKey, type StyleValue } from '../../types';\nimport { useSheetContext } from '../SheetContext';\n\nexport type StyleState = Partial<Record<StyleValue, boolean>>;\n\nexport type StyleAction = { key: StyleKey; value: StyleValue };\n\nconst styles: Record<StyleValue, string> = {\n highlight: 'ph--highlighter--regular',\n softwrap: 'ph--paragraph--regular',\n};\n\nexport const useStyleState = (state: StyleState) => {\n const { cursorFallbackRange, model } = useSheetContext();\n\n useEffect(() => {\n state.highlight = false;\n state.softwrap = false;\n if (cursorFallbackRange && model.sheet.ranges) {\n model.sheet.ranges\n .filter(\n ({ range, key }) => key === 'style' && inRange(rangeFromIndex(model.sheet, range), cursorFallbackRange.from),\n )\n .forEach(({ value }) => {\n state[value as StyleValue] = true;\n });\n }\n }, [cursorFallbackRange, model.sheet]);\n};\n\nconst createStyleGroup = (state: StyleState) => {\n return createMenuItemGroup('style', {\n variant: 'toggleGroup',\n selectCardinality: 'multiple',\n value: Object.keys(styles)\n .filter((key) => !!state[key as StyleValue])\n .map((styleValue) => `style--${styleValue}`),\n } as ToolbarMenuActionGroupProperties);\n};\n\nconst createStyleActions = (model: SheetModel, state: StyleState, cursorFallbackRange?: CompleteCellRange) =>\n Object.entries(styles).map(([styleValue, icon]) => {\n return createMenuAction<StyleAction>(\n `style--${styleValue}`,\n () => {\n if (!cursorFallbackRange) {\n return;\n }\n const index =\n model.sheet.ranges?.findIndex(\n (range) =>\n range.key === 'style' && inRange(rangeFromIndex(model.sheet, range.range), cursorFallbackRange.from),\n ) ?? -1;\n const nextRangeEntity = {\n range: rangeToIndex(model.sheet, cursorFallbackRange),\n key: 'style',\n value: styleValue as StyleValue,\n };\n if (\n model.sheet.ranges\n .filter(\n ({ range, key: rangeKey }) =>\n rangeKey === 'style' && inRange(rangeFromIndex(model.sheet, range), cursorFallbackRange.from),\n )\n .some(({ value: rangeValue }) => rangeValue === styleValue)\n ) {\n // this value should be unset\n if (index >= 0) {\n model.sheet.ranges?.splice(index, 1);\n }\n state[nextRangeEntity.value] = false;\n } else {\n model.sheet.ranges?.push(nextRangeEntity);\n state[nextRangeEntity.value] = true;\n }\n },\n {\n key: 'style',\n value: styleValue as StyleValue,\n icon,\n label: [`range value ${styleValue} label`, { ns: SHEET_PLUGIN }],\n checked: !!state[styleValue as StyleValue],\n },\n );\n });\n\nexport const createStyle = (model: SheetModel, state: StyleState, cursorFallbackRange?: CompleteCellRange) => {\n const styleGroupAction = createStyleGroup(state);\n const styleActions = createStyleActions(model, state, cursorFallbackRange);\n return {\n nodes: [styleGroupAction, ...styleActions],\n edges: [\n { source: 'root', target: 'style' },\n ...styleActions.map(({ id }) => ({ source: styleGroupAction.id, target: id })),\n ],\n };\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { live } from '@dxos/live-object';\n\nimport { type AlignState } from './align';\nimport { type StyleState } from './style';\n\nexport type ToolbarState = Partial<StyleState & AlignState>;\n\nexport const useToolbarState = (initialState: ToolbarState = {}) => {\n return useMemo(() => live<ToolbarState>(initialState), []);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { SheetContainer } from './SheetContainer';\n\nexport default SheetContainer;\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAIA,OAAOA,YAAW;AAElB,SAASC,wBAAoC;AAC7C,SAASC,iBAAiB;;;;ACH1B,OAAOC,WAAW;AAElB,SAASC,qBAAqBC,WAAWC,yBAAyB;AAClE,SAASC,YAAY;AAKd,IAAMC,iBAAiB,MAAA;;;AAC5B,UAAM,EAAEC,OAAOC,QAAQC,MAAK,IAAKC,gBAAAA;AAEjC,QAAIC;AACJ,QAAIC,UAAU;AACd,QAAIJ,QAAQ;AACVG,cAAQJ,MAAMM,aAAaL,MAAAA;AAC3B,UAAIM,UAAUH,KAAAA,GAAQ;AACpBA,gBAAQJ,MAAMQ,MAAMC,y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AMvB,gBAAgBwB,SAAQ,MAAA;AAC5B,aAAOvB,GAAGC,KAAK,CAACC,QAAAA;AACd,cAAMsB,UAAUtB,IAAImB,MAAMG,QAAQT,EAAAA,CAAAA;AAClC,cAAML,QAAQc,QAAQC,OAAO,CAACC,WAAWA,OAAOC,WAAWC,gBAAgB,SAAA;AAC3E,eAAO;UAAElB;UAAOC,OAAOD,MAAMmB,IAAI,CAACC,UAAU;YAAEC,QAAQ;YAAQC,QAAQF,KAAKf;UAAG,EAAA;QAAI;MACpF,CAAA;IACF,GAAG;MAACM;KAAM;AAEV,UAAMY,iBAAiBV,SACrB,MAAM5B,qBAAqBC,OAAOC,OAAOC,qBAAqBC,aAAAA,GAC9D;MAACH;MAAOC;MAAOC;MAAqBC;KAAc;AAEpD,UAAMmC,OAAOC,eAAeF,cAAAA;AAE5B,WACE,gBAAAG,OAAA,cAACC,cAAAA;MAAc,GAAGH;MAAMI,cAAcvB;OACpC,gBAAAqB,OAAA,cAACG,aAAAA;MAAYvB;;;;;AAGnB;;;AF5DO,IAAMwB,iBAAiB,CAAC,EAAEC,OAAOC,OAAOC,MAAMC,gBAAe,MAAuB;;;AACzF,UAAMC,QAAQC,gBAAgBL,KAAAA;AAE9B,WAAOI,QACL,gBAAAE,OAAA,cAACC,eAAAA;MAAcN;MAAcG;MAAcD;OACzC,gBAAAG,OAAA,cAACE,UAAUC,SAAO;MAACC,SAAAA;MAAQC,WAAAA;MAAW,GAAIT,SAAS,aAAa;QAAEU,YAAY;MAAe;OAC3F,gBAAAN,OAAA,cAACO,cAAAA;MAAaC,IAAIC,iBAAiBd,KAAAA;QACnC,gBAAAK,OAAA,cAACU,WAAAA,IAAAA,GACD,gBAAAV,OAAA,cAACW,gBAAAA,IAAAA,CAAAA,CAAAA,IAGH;;;;AACN;;;AM7BA,IAAA,yBAAeC;",
6
- "names": ["React", "fullyQualifiedId", "StackItem", "React", "addressToA1Notation", "isFormula", "rangeToA1Notation", "Icon", "FunctionEditor", "model", "cursor", "range", "useSheetContext", "value", "formula", "getCellValue", "isFormula", "graph", "mapFunctionBindingFromId", "mapFormulaIndicesToRefs", "sheet", "String", "div", "className", "rangeToA1Notation", "addressToA1Notation", "Icon", "icon", "classNames", "span", "Rx", "React", "useMemo", "useAppGraph", "createGapSeparator", "MenuProvider", "rxFromSignal", "ToolbarMenu", "useMenuActions", "useEffect", "inRange", "createMenuAction", "createMenuItemGroup", "aligns", "start", "center", "end", "useAlignState", "state", "cursor", "model", "useSheetContext", "useEffect", "alignKey", "sheet", "ranges", "findLast", "range", "key", "inRange", "rangeFromIndex", "value", "undefined", "createAlignGroupAction", "createMenuItemGroup", "label", "ns", "SHEET_PLUGIN", "variant", "selectCardinality", "createAlignActions", "cursorFallbackRange", "Object", "entries", "map", "alignValue", "icon", "createMenuAction", "index", "findIndex", "from", "nextRangeEntity", "rangeToIndex", "push", "splice", "checked", "testId", "createAlign", "alignGroup", "alignActions", "nodes", "edges", "source", "target", "id", "useEffect", "inRange", "createMenuAction", "createMenuItemGroup", "styles", "highlight", "softwrap", "useStyleState", "state", "cursorFallbackRange", "model", "useSheetContext", "useEffect", "sheet", "ranges", "filter", "range", "key", "inRange", "rangeFromIndex", "from", "forEach", "value", "createStyleGroup", "createMenuItemGroup", "variant", "selectCardinality", "Object", "keys", "map", "styleValue", "createStyleActions", "entries", "icon", "createMenuAction", "index", "findIndex", "nextRangeEntity", "rangeToIndex", "rangeKey", "some", "rangeValue", "splice", "push", "label", "ns", "SHEET_PLUGIN", "checked", "createStyle", "styleGroupAction", "styleActions", "nodes", "edges", "source", "target", "id", "useMemo", "live", "useToolbarState", "initialState", "useMemo", "live", "createToolbarActions", "model", "state", "cursorFallbackRange", "customActions", "Rx", "make", "get", "align", "rxFromSignal", "createAlign", "style", "createStyle", "gap", "createGapSeparator", "nodes", "edges", "custom", "push", "SheetToolbar", "id", "classNames", "useSheetContext", "useToolbarState", "useAlignState", "useStyleState", "graph", "useAppGraph", "useMemo", "actions", "filter", "action", "properties", "disposition", "map", "node", "source", "target", "actionsCreator", "menu", "useMenuActions", "React", "MenuProvider", "attendableId", "ToolbarMenu", "SheetContainer", "space", "sheet", "role", "ignoreAttention", "graph", "useComputeGraph", "React", "SheetProvider", "StackItem", "Content", "toolbar", "statusbar", "classNames", "SheetToolbar", "id", "fullyQualifiedId", "GridSheet", "FunctionEditor", "SheetContainer"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/extensions/compute.ts", "../../../src/extensions/editor/extension.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { syntaxTree } from '@codemirror/language';\nimport {\n type EditorState,\n type Extension,\n type RangeSet,\n RangeSetBuilder,\n StateEffect,\n StateField,\n type Transaction,\n} from '@codemirror/state';\nimport { Decoration, EditorView, ViewPlugin, WidgetType } from '@codemirror/view';\n\nimport { type CleanupFn, debounce } from '@dxos/async';\nimport {\n createSheetName,\n type CellAddress,\n type CellScalarValue,\n type ComputeGraph,\n type ComputeNode,\n} from '@dxos/compute';\nimport { invariant } from '@dxos/invariant';\nimport { documentId, singleValueFacet } from '@dxos/react-ui-editor';\n\nconst LANGUAGE_TAG = 'dx';\n\n// TODO(burdon): Create marker just for our decorator?\nconst updateAllDecorations = StateEffect.define<void>();\n\nexport const computeGraphFacet = singleValueFacet<ComputeGraph>();\n\nexport type ComputeOptions = {};\n\nexport const compute = (options: ComputeOptions = {}): Extension => {\n let computeNode: ComputeNode | undefined;\n\n const update = (state: EditorState, current?: RangeSet<Decoration>) => {\n const builder = new RangeSetBuilder<Decoration>();\n if (computeNode) {\n computeNode.clear();\n syntaxTree(state).iterate({\n enter: (node) => {\n switch (node.name) {\n case 'FencedCode': {\n const cursor = state.selection.main.head;\n if (state.readOnly || cursor < node.from || cursor > node.to) {\n const info = node.node.getChild('CodeInfo');\n if (info) {\n const type = state.sliceDoc(info.from, info.to);\n const text = node.node.getChild('CodeText');\n if (type === LANGUAGE_TAG && text) {\n const formula = state.sliceDoc(text.from, text.to);\n\n const iter = current?.iter(node.node.from);\n if (iter?.value && iter?.value.spec.formula === formula) {\n // Add existing widget.\n builder.add(node.from, node.to, iter.value);\n } else {\n // TODO(burdon): Create ordered list of cells on each decoration run.\n const cell: CellAddress = { col: node.node.from, row: 0 };\n invariant(computeNode);\n // NOTE: This triggers re-render (below).\n computeNode.setValue(cell, formula);\n const value = computeNode.getValue(cell);\n builder.add(\n node.from,\n node.to,\n Decoration.replace({\n widget: new ComputeWidget(formula, value),\n formula,\n }),\n );\n }\n }\n }\n }\n\n break;\n }\n }\n },\n });\n }\n\n return builder.finish();\n };\n\n return [\n ViewPlugin.fromClass(\n class {\n // Graph subscription.\n private _subscription?: CleanupFn;\n constructor(view: EditorView) {\n const id = view.state.facet(documentId);\n const computeGraph = view.state.facet(computeGraphFacet);\n if (id && computeGraph) {\n queueMicrotask(async () => {\n computeNode = computeGraph.getOrCreateNode(createSheetName({ type: '', id }));\n await computeNode.open();\n\n // Trigger re-render if values updated.\n // TODO(burdon): Trigger only if formula value updated (currently triggered during render).\n this._subscription = computeNode.update.on(\n debounce(({ type, ...rest }) => {\n if (type === 'valuesUpdated') {\n view.dispatch({\n effects: updateAllDecorations.of(),\n });\n }\n }, 250),\n );\n });\n }\n }\n\n destroy() {\n this._subscription?.();\n void computeNode?.close();\n computeNode = undefined;\n }\n },\n ),\n\n StateField.define<RangeSet<Decoration>>({\n create: (state) => update(state),\n update: (rangeSet: RangeSet<Decoration>, tr: Transaction) => update(tr.state, rangeSet),\n provide: (field) => EditorView.decorations.from(field),\n }),\n ];\n};\n\n// TODO(burdon): Click to edit.\nclass ComputeWidget extends WidgetType {\n constructor(\n private readonly formula: string,\n private readonly value: CellScalarValue,\n ) {\n super();\n }\n\n override toDOM(_view: EditorView): HTMLDivElement {\n const div = document.createElement('div');\n div.setAttribute('title', this.formula);\n div.innerText = String(this.value);\n return div;\n }\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport {\n type Completion,\n type CompletionContext,\n type CompletionResult,\n acceptCompletion,\n autocompletion,\n completionStatus,\n startCompletion,\n} from '@codemirror/autocomplete';\nimport { HighlightStyle, type Language, syntaxHighlighting } from '@codemirror/language';\nimport { type Extension } from '@codemirror/state';\nimport { type EditorView, ViewPlugin, type ViewUpdate, keymap } from '@codemirror/view';\nimport { type SyntaxNode } from '@lezer/common';\nimport { tags } from '@lezer/highlight';\nimport { spreadsheet } from 'codemirror-lang-spreadsheet';\n\nimport { type FunctionDefinition } from '@dxos/compute';\nimport { RANGE_NOTATION } from '@dxos/compute';\nimport { singleValueFacet } from '@dxos/react-ui-editor';\nimport { mx } from '@dxos/react-ui-theme';\n\n/**\n * https://codemirror.net/examples/styling\n * https://lezer.codemirror.net/docs/ref/#highlight\n * https://github.com/luizzappa/codemirror-lang-spreadsheet/blob/main/src/index.ts#L28 (mapping)\n */\n// TODO(burdon): Define light/dark.\nconst highlightStyles = HighlightStyle.define([\n // Function.\n {\n tag: tags.name,\n class: 'text-accentText',\n },\n // Range.\n {\n tag: tags.tagName,\n class: 'text-pinkText',\n },\n // Values.\n {\n tag: tags.number,\n class: 'text-tealText',\n },\n {\n tag: tags.bool,\n class: 'text-tealText',\n },\n {\n tag: tags.string,\n class: 'text-tealText',\n },\n // Error.\n {\n tag: tags.invalid,\n class: 'text-unAccent',\n },\n]);\n\nconst languageFacet = singleValueFacet<Language>();\n\nexport type SheetExtensionOptions = {\n debug?: boolean;\n functions?: FunctionDefinition[];\n};\n\n/**\n * Spreadsheet formula extension and parser.\n * https://github.com/luizzappa/codemirror-lang-spreadsheet\n * https://github.com/luizzappa/codemirror-app-spreadsheet/blob/master/src/editor.ts\n * https://github.com/codemirror/lang-example\n * https://hyperformula.handsontable.com/guide/key-concepts.html#grammar\n */\nexport const sheetExtension = ({ debug, functions = [] }: SheetExtensionOptions): Extension => {\n const { extension, language } = spreadsheet({ idiom: 'en-US', decimalSeparator: '.' });\n\n const createCompletion = (name: string) => {\n const { section = 'Custom', description, syntax } = functions.find((value) => value.name === name) ?? {};\n\n return {\n section,\n label: name,\n info: () => {\n if (!description && !syntax) {\n return null;\n }\n\n // TODO(burdon): Standardize color styles.\n const root = document.createElement('div');\n root.className = 'flex flex-col gap-2 text-sm';\n\n const title = document.createElement('h2');\n title.innerText = name;\n title.className = 'text-lg font-mono text-accentText';\n root.appendChild(title);\n\n if (description) {\n const info = document.createElement('p');\n info.innerText = description;\n info.className = 'text-subdued';\n root.appendChild(info);\n }\n\n if (syntax) {\n const detail = document.createElement('pre');\n detail.innerText = syntax;\n detail.className = 'whitespace-pre-wrap text-greenText';\n root.appendChild(detail);\n }\n\n return root;\n },\n apply: (view, completion, from, to) => {\n const insertParens = to === view.state.doc.toString().length;\n view.dispatch(\n view.state.update({\n changes: {\n from,\n to,\n insert: completion.label + (insertParens ? '()' : ''),\n },\n selection: {\n anchor: from + completion.label.length + 1,\n },\n }),\n );\n },\n } satisfies Completion;\n };\n\n return [\n extension,\n languageFacet.of(language),\n language.data.of({\n autocomplete: (context: CompletionContext): CompletionResult | null => {\n if (context.state.doc.toString()[0] !== '=') {\n return null;\n }\n const match = context.matchBefore(/\\w*/);\n if (!match || match.from === match.to) {\n return null;\n }\n\n const text = match.text.toUpperCase();\n if (!context.explicit && match.text.length < 2) {\n return null;\n }\n\n return {\n from: match.from,\n options:\n functions?.filter(({ name }) => name.startsWith(text)).map(({ name }) => createCompletion(name)) ?? [],\n };\n },\n }),\n\n syntaxHighlighting(highlightStyles),\n autocompletion({\n aboveCursor: false,\n defaultKeymap: true,\n activateOnTyping: true,\n closeOnBlur: !debug,\n icons: false,\n tooltipClass: () =>\n mx(\n '!-left-[1px] !top-[33px] !-m-0 border !border-t-0 [&>ul]:!min-w-[198px]',\n '[&>ul>li[aria-selected]]:!bg-accentSurface',\n 'border-separator',\n ),\n }),\n keymap.of([\n {\n key: 'Tab',\n run: (view) => {\n return completionStatus(view.state) === 'active' ? acceptCompletion(view) : startCompletion(view);\n },\n },\n ]),\n\n // Parsing.\n // StateField.define({\n // create: (state) => {},\n // update: (value, tr) => {\n // log.info('update');\n // syntaxTree(tr.state).iterate({\n // enter: ({ type, from, to }) => {\n // log.info('node', { type: type.name, from, to });\n // },\n // });\n // },\n // }),\n ];\n};\n\nexport type SelectionRange = { from: number; to: number };\n\nexport interface RangeController {\n setRange(range: string): void;\n}\n\nexport type RangeExtensionOptions = {\n /**\n * Provides controller callback when extension is initialized.\n */\n onInit?: (controller: RangeController) => void;\n /**\n * Called when the active range changes.\n * @param state The current state.\n * @param state.activeRange undefined if no range is active, otherwise a possibly partially defined range.\n */\n onStateChange?: (state: { activeRange: string | undefined }) => void;\n};\n\n/**\n * Tracks the currently active cell within a formula and provides a callback to modify it.\n */\nexport const rangeExtension = ({ onInit, onStateChange }: RangeExtensionOptions): Extension => {\n let view: EditorView;\n let activeRange: SelectionRange | undefined;\n\n // Called externally to provide current range.\n const notifier: RangeController = {\n setRange: (range: string) => {\n if (activeRange) {\n view.dispatch(\n view.state.update({\n changes: { ...activeRange, insert: range.toString() },\n selection: { anchor: activeRange.from + range.length },\n }),\n );\n }\n\n view.focus();\n },\n };\n\n return ViewPlugin.fromClass(\n class {\n constructor(_view: EditorView) {\n view = _view;\n onInit?.(notifier);\n }\n\n update(view: ViewUpdate) {\n const { anchor } = view.state.selection.ranges[0];\n\n // Find first Range or cell at cursor.\n activeRange = undefined;\n const language = view.state.facet(languageFacet);\n const { topNode } = language.parser.parse(view.state.doc.toString());\n visitTree(topNode, ({ type, from, to }) => {\n if (from <= anchor && to >= anchor) {\n switch (type.name) {\n case 'Function':\n // Mark but keep looking.\n activeRange = { from: to, to };\n break;\n\n case 'CloseParen':\n // Mark but keep looking.\n activeRange = { from, to: from };\n break;\n\n case 'RangeToken':\n case 'CellToken':\n activeRange = { from, to };\n return true;\n }\n }\n\n return false;\n });\n\n // Allow start of formula.\n if (!activeRange && view.state.doc.toString()[0] === '=') {\n const str = view.state.doc.sliceString(1);\n if (RANGE_NOTATION.test(str)) {\n activeRange = { from: 1, to: str.length + 1 };\n } else {\n activeRange = { from: str.length + 1, to: str.length + 1 };\n }\n }\n\n onStateChange?.({\n activeRange: activeRange ? view.state.doc.sliceString(activeRange.from, activeRange.to) : undefined,\n });\n }\n },\n );\n};\n\n/**\n * Lezer parse result visitor.\n */\nconst visitTree = (node: SyntaxNode, callback: (node: SyntaxNode) => boolean): boolean => {\n if (callback(node)) {\n return true;\n }\n\n for (let child = node.firstChild; child !== null; child = child.nextSibling) {\n if (visitTree(child, callback)) {\n return true;\n }\n }\n\n return false;\n};\n"],
5
- "mappings": ";AAIA,SAASA,kBAAkB;AAC3B,SAIEC,iBACAC,aACAC,kBAEK;AACP,SAASC,YAAYC,YAAYC,YAAYC,kBAAkB;AAE/D,SAAyBC,gBAAgB;AACzC,SACEC,uBAKK;AACP,SAASC,iBAAiB;AAC1B,SAASC,YAAYC,wBAAwB;AAK7C,IAAMC,uBAAuBC,YAAYC,OAAM;AAExC,IAAMC,oBAAoBC,iBAAAA;;;AC5BjC,SAIEC,kBACAC,gBACAC,kBACAC,uBACK;AACP,SAASC,gBAA+BC,0BAA0B;AAElE,SAA0BC,cAAAA,aAA6BC,cAAc;AAErE,SAASC,YAAY;AACrB,SAASC,mBAAmB;AAG5B,SAASC,sBAAsB;AAC/B,SAASC,oBAAAA,yBAAwB;AACjC,SAASC,UAAU;AAQnB,IAAMC,kBAAkBC,eAAeC,OAAO;;EAE5C;IACEC,KAAKC,KAAKC;IACVC,OAAO;EACT;;EAEA;IACEH,KAAKC,KAAKG;IACVD,OAAO;EACT;;EAEA;IACEH,KAAKC,KAAKI;IACVF,OAAO;EACT;EACA;IACEH,KAAKC,KAAKK;IACVH,OAAO;EACT;EACA;IACEH,KAAKC,KAAKM;IACVJ,OAAO;EACT;;EAEA;IACEH,KAAKC,KAAKO;IACVL,OAAO;EACT;CACD;AAED,IAAMM,gBAAgBC,kBAAAA;AAcf,IAAMC,iBAAiB,CAAC,EAAEC,OAAOC,YAAY,CAAA,EAAE,MAAyB;AAC7E,QAA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IACF;EACF,CAAA;AAEJ;AAKA,IAAMK,YAAY,CAACM,MAAkBC,aAAAA;AACnC,MAAIA,SAASD,IAAAA,GAAO;AAClB,WAAO;EACT;AAEA,WAASE,QAAQF,KAAKG,YAAYD,UAAU,MAAMA,QAAQA,MAAME,aAAa;AAC3E,QAAIV,UAAUQ,OAAOD,QAAAA,GAAW;AAC9B,aAAO;IACT;EACF;AAEA,SAAO;AACT;",
6
- "names": ["syntaxTree", "RangeSetBuilder", "StateEffect", "StateField", "Decoration", "EditorView", "ViewPlugin", "WidgetType", "debounce", "createSheetName", "invariant", "documentId", "singleValueFacet", "updateAllDecorations", "StateEffect", "define", "computeGraphFacet", "singleValueFacet", "acceptCompletion", "autocompletion", "completionStatus", "startCompletion", "HighlightStyle", "syntaxHighlighting", "ViewPlugin", "keymap", "tags", "spreadsheet", "RANGE_NOTATION", "singleValueFacet", "mx", "highlightStyles", "HighlightStyle", "define", "tag", "tags", "name", "class", "tagName", "number", "bool", "string", "invalid", "languageFacet", "singleValueFacet", "sheetExtension", "debug", "functions", "extension", "language", "spreadsheet", "idiom", "decimalSeparator", "createCompletion", "section", "description", "syntax", "find", "value", "label", "info", "root", "document", "createElement", "className", "title", "innerText", "appendChild", "detail", "apply", "view", "completion", "from", "to", "insertParens", "state", "doc", "toString", "length", "dispatch", "update", "changes", "insert", "selection", "anchor", "of", "data", "autocomplete", "context", "match", "matchBefore", "text", "toUpperCase", "explicit", "options", "filter", "startsWith", "map", "syntaxHighlighting", "autocompletion", "aboveCursor", "defaultKeymap", "activateOnTyping", "closeOnBlur", "icons", "tooltipClass", "mx", "keymap", "key", "run", "completionStatus", "acceptCompletion", "startCompletion", "rangeExtension", "onInit", "onStateChange", "activeRange", "notifier", "setRange", "range", "focus", "ViewPlugin", "fromClass", "_view", "ranges", "undefined", "facet", "topNode", "parser", "parse", "visitTree", "type", "str", "sliceString", "RANGE_NOTATION", "test", "node", "callback", "child", "firstChild", "nextSibling"]
7
- }