@dxos/plugin-sheet 0.8.2-main.f11618f → 0.8.2-main.fbd8ed0

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 (139) hide show
  1. package/dist/lib/browser/{SheetContainer-7DK3ZZUT.mjs → SheetContainer-UV7RMPXS.mjs} +88 -86
  2. package/dist/lib/browser/SheetContainer-UV7RMPXS.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-HRTIOTK7.mjs → chunk-N2FOQHUH.mjs} +49 -48
  4. package/dist/lib/browser/chunk-N2FOQHUH.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-IE42HBFC.mjs → chunk-TN7LTDHU.mjs} +86 -75
  6. package/dist/lib/browser/chunk-TN7LTDHU.mjs.map +7 -0
  7. package/dist/lib/browser/{compute-graph-registry-WEJLJJ6T.mjs → compute-graph-registry-MBJKPAHX.mjs} +2 -2
  8. package/dist/lib/browser/compute-graph-registry-MBJKPAHX.mjs.map +7 -0
  9. package/dist/lib/browser/index.mjs +6 -6
  10. package/dist/lib/browser/{intent-resolver-OMXW6BDZ.mjs → intent-resolver-DN7JXDAV.mjs} +2 -2
  11. package/dist/lib/browser/{markdown-DR4RDEEY.mjs → markdown-57MKY5WB.mjs} +2 -2
  12. package/dist/lib/browser/markdown-57MKY5WB.mjs.map +7 -0
  13. package/dist/lib/browser/meta.json +1 -1
  14. package/dist/lib/browser/{react-surface-RTQDRQ4X.mjs → react-surface-NQU63B63.mjs} +3 -3
  15. package/dist/lib/browser/{thread-HV32Z27A.mjs → thread-WU64QL2A.mjs} +2 -2
  16. package/dist/lib/browser/types/index.mjs +1 -1
  17. package/dist/lib/node/{SheetContainer-6RPY4P7E.cjs → SheetContainer-GR2KDOAE.cjs} +106 -102
  18. package/dist/lib/node/SheetContainer-GR2KDOAE.cjs.map +7 -0
  19. package/dist/lib/node/{chunk-UXSU6W7E.cjs → chunk-CN7OBGYV.cjs} +95 -84
  20. package/dist/lib/node/chunk-CN7OBGYV.cjs.map +7 -0
  21. package/dist/lib/node/{chunk-C3Q4GSES.cjs → chunk-HLSQVT3C.cjs} +65 -64
  22. package/dist/lib/node/chunk-HLSQVT3C.cjs.map +7 -0
  23. package/dist/lib/node/{compute-graph-registry-VVSRJUGS.cjs → compute-graph-registry-EBBDN6ZX.cjs} +5 -5
  24. package/dist/lib/node/compute-graph-registry-EBBDN6ZX.cjs.map +7 -0
  25. package/dist/lib/node/index.cjs +12 -12
  26. package/dist/lib/node/{intent-resolver-KI5DG7LR.cjs → intent-resolver-OPF56TAL.cjs} +9 -9
  27. package/dist/lib/node/{markdown-E7OUIMZO.cjs → markdown-Q3RXYPHQ.cjs} +5 -5
  28. package/dist/lib/node/markdown-Q3RXYPHQ.cjs.map +7 -0
  29. package/dist/lib/node/meta.json +1 -1
  30. package/dist/lib/node/{react-surface-ZDOTWZ4Q.cjs → react-surface-7SAA5DX3.cjs} +11 -11
  31. package/dist/lib/node/{thread-NVEWN3H2.cjs → thread-E7YPGR5T.cjs} +7 -7
  32. package/dist/lib/node/types/index.cjs +29 -29
  33. package/dist/lib/node/types/index.cjs.map +1 -1
  34. package/dist/lib/node-esm/{SheetContainer-QQUB22WF.mjs → SheetContainer-XW7B2AJI.mjs} +88 -86
  35. package/dist/lib/node-esm/SheetContainer-XW7B2AJI.mjs.map +7 -0
  36. package/dist/lib/node-esm/{chunk-JSVXC3QP.mjs → chunk-3JJ7ETTJ.mjs} +86 -75
  37. package/dist/lib/node-esm/chunk-3JJ7ETTJ.mjs.map +7 -0
  38. package/dist/lib/node-esm/{chunk-SWRUEW6J.mjs → chunk-LYZV4Q4C.mjs} +49 -48
  39. package/dist/lib/node-esm/chunk-LYZV4Q4C.mjs.map +7 -0
  40. package/dist/lib/node-esm/{compute-graph-registry-PBQ52KH6.mjs → compute-graph-registry-TVG6RN2J.mjs} +2 -2
  41. package/dist/lib/node-esm/compute-graph-registry-TVG6RN2J.mjs.map +7 -0
  42. package/dist/lib/node-esm/index.mjs +6 -6
  43. package/dist/lib/node-esm/{intent-resolver-3FVOBB3K.mjs → intent-resolver-7AN5CN4R.mjs} +2 -2
  44. package/dist/lib/node-esm/{markdown-BPKS2TNG.mjs → markdown-ACHAWUOE.mjs} +2 -2
  45. package/dist/lib/node-esm/markdown-ACHAWUOE.mjs.map +7 -0
  46. package/dist/lib/node-esm/meta.json +1 -1
  47. package/dist/lib/node-esm/{react-surface-T4OVUZY2.mjs → react-surface-BPNN7RSE.mjs} +3 -3
  48. package/dist/lib/node-esm/{thread-DTWGGMW4.mjs → thread-ULESW6IX.mjs} +2 -2
  49. package/dist/lib/node-esm/types/index.mjs +1 -1
  50. package/dist/types/src/capabilities/compute-graph-registry.d.ts +2 -2
  51. package/dist/types/src/capabilities/compute-graph-registry.d.ts.map +1 -1
  52. package/dist/types/src/capabilities/index.d.ts +2 -2
  53. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  54. package/dist/types/src/capabilities/markdown.d.ts +2 -2
  55. package/dist/types/src/capabilities/markdown.d.ts.map +1 -1
  56. package/dist/types/src/components/ComputeGraph/ComputeGraphContextProvider.d.ts.map +1 -1
  57. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
  58. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -1
  59. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -1
  60. package/dist/types/src/components/RangeList/RangeList.d.ts.map +1 -1
  61. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +3 -2
  62. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -1
  63. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -1
  64. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -1
  65. package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts.map +1 -1
  66. package/dist/types/src/components/SheetToolbar/align.d.ts +4 -1
  67. package/dist/types/src/components/SheetToolbar/align.d.ts.map +1 -1
  68. package/dist/types/src/components/SheetToolbar/comment.d.ts +3 -1
  69. package/dist/types/src/components/SheetToolbar/comment.d.ts.map +1 -1
  70. package/dist/types/src/components/SheetToolbar/style.d.ts +3 -1
  71. package/dist/types/src/components/SheetToolbar/style.d.ts.map +1 -1
  72. package/dist/types/src/components/SheetToolbar/useToolbarState.d.ts.map +1 -1
  73. package/dist/types/src/components/index.d.ts +1 -6
  74. package/dist/types/src/components/index.d.ts.map +1 -1
  75. package/dist/types/src/extensions/compute.d.ts.map +1 -1
  76. package/dist/types/src/extensions/editor/extension.d.ts.map +1 -1
  77. package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -1
  78. package/dist/types/src/model/testing.d.ts.map +1 -1
  79. package/dist/types/src/model/useSheetModel.d.ts.map +1 -1
  80. package/dist/types/src/testing/data.d.ts.map +1 -1
  81. package/dist/types/src/testing/testing.d.ts.map +1 -1
  82. package/dist/types/src/translations.d.ts +2 -54
  83. package/dist/types/src/translations.d.ts.map +1 -1
  84. package/dist/types/src/types/schema.d.ts +147 -276
  85. package/dist/types/src/types/schema.d.ts.map +1 -1
  86. package/dist/types/src/types/sheet-range-types.d.ts.map +1 -1
  87. package/dist/types/src/types/types.d.ts +36 -36
  88. package/dist/types/src/types/types.d.ts.map +1 -1
  89. package/dist/types/src/types/util.d.ts.map +1 -1
  90. package/dist/types/tsconfig.tsbuildinfo +1 -1
  91. package/package.json +53 -47
  92. package/src/capabilities/compute-graph-registry.ts +3 -3
  93. package/src/capabilities/markdown.ts +3 -3
  94. package/src/components/ComputeGraph/compute-graph.stories.tsx +2 -2
  95. package/src/components/FunctionEditor/FunctionEditor.tsx +1 -1
  96. package/src/components/GridSheet/GridSheet.stories.tsx +5 -2
  97. package/src/components/GridSheet/GridSheet.tsx +18 -12
  98. package/src/components/GridSheet/SheetCellEditor.stories.tsx +2 -2
  99. package/src/components/GridSheet/util.ts +7 -2
  100. package/src/components/RangeList/RangeList.tsx +2 -2
  101. package/src/components/SheetContainer/SheetContainer.stories.tsx +1 -5
  102. package/src/components/SheetContainer/SheetContainer.tsx +4 -7
  103. package/src/components/SheetToolbar/SheetToolbar.stories.tsx +1 -1
  104. package/src/components/SheetToolbar/SheetToolbar.tsx +33 -8
  105. package/src/components/SheetToolbar/align.ts +44 -14
  106. package/src/components/SheetToolbar/comment.ts +39 -11
  107. package/src/components/SheetToolbar/style.ts +48 -12
  108. package/src/integrations/thread-ranges.ts +2 -3
  109. package/src/model/sheet-model.test.ts +1 -1
  110. package/src/sanity.test.ts +1 -1
  111. package/src/types/schema.ts +21 -19
  112. package/src/types/types.ts +25 -25
  113. package/dist/lib/browser/SheetContainer-7DK3ZZUT.mjs.map +0 -7
  114. package/dist/lib/browser/chunk-HRTIOTK7.mjs.map +0 -7
  115. package/dist/lib/browser/chunk-IE42HBFC.mjs.map +0 -7
  116. package/dist/lib/browser/compute-graph-registry-WEJLJJ6T.mjs.map +0 -7
  117. package/dist/lib/browser/markdown-DR4RDEEY.mjs.map +0 -7
  118. package/dist/lib/node/SheetContainer-6RPY4P7E.cjs.map +0 -7
  119. package/dist/lib/node/chunk-C3Q4GSES.cjs.map +0 -7
  120. package/dist/lib/node/chunk-UXSU6W7E.cjs.map +0 -7
  121. package/dist/lib/node/compute-graph-registry-VVSRJUGS.cjs.map +0 -7
  122. package/dist/lib/node/markdown-E7OUIMZO.cjs.map +0 -7
  123. package/dist/lib/node-esm/SheetContainer-QQUB22WF.mjs.map +0 -7
  124. package/dist/lib/node-esm/chunk-JSVXC3QP.mjs.map +0 -7
  125. package/dist/lib/node-esm/chunk-SWRUEW6J.mjs.map +0 -7
  126. package/dist/lib/node-esm/compute-graph-registry-PBQ52KH6.mjs.map +0 -7
  127. package/dist/lib/node-esm/markdown-BPKS2TNG.mjs.map +0 -7
  128. package/dist/types/src/components/SheetToolbar/useToolbarAction.d.ts +0 -8
  129. package/dist/types/src/components/SheetToolbar/useToolbarAction.d.ts.map +0 -1
  130. package/src/components/SheetToolbar/useToolbarAction.ts +0 -87
  131. /package/dist/lib/browser/{intent-resolver-OMXW6BDZ.mjs.map → intent-resolver-DN7JXDAV.mjs.map} +0 -0
  132. /package/dist/lib/browser/{react-surface-RTQDRQ4X.mjs.map → react-surface-NQU63B63.mjs.map} +0 -0
  133. /package/dist/lib/browser/{thread-HV32Z27A.mjs.map → thread-WU64QL2A.mjs.map} +0 -0
  134. /package/dist/lib/node/{intent-resolver-KI5DG7LR.cjs.map → intent-resolver-OPF56TAL.cjs.map} +0 -0
  135. /package/dist/lib/node/{react-surface-ZDOTWZ4Q.cjs.map → react-surface-7SAA5DX3.cjs.map} +0 -0
  136. /package/dist/lib/node/{thread-NVEWN3H2.cjs.map → thread-E7YPGR5T.cjs.map} +0 -0
  137. /package/dist/lib/node-esm/{intent-resolver-3FVOBB3K.mjs.map → intent-resolver-7AN5CN4R.mjs.map} +0 -0
  138. /package/dist/lib/node-esm/{react-surface-T4OVUZY2.mjs.map → react-surface-BPNN7RSE.mjs.map} +0 -0
  139. /package/dist/lib/node-esm/{thread-DTWGGMW4.mjs.map → thread-ULESW6IX.mjs.map} +0 -0
@@ -4,14 +4,18 @@
4
4
 
5
5
  import React, { type PropsWithChildren, useCallback } from 'react';
6
6
 
7
+ import { createIntent, useIntentDispatcher } from '@dxos/app-framework';
8
+ import { type CompleteCellRange } from '@dxos/compute';
9
+ import { ThreadAction } from '@dxos/plugin-thread/types';
7
10
  import { type ThemedClassName } from '@dxos/react-ui';
8
11
  import { createGapSeparator, MenuProvider, ToolbarMenu, useMenuActions } from '@dxos/react-ui-menu';
9
12
 
10
13
  import { createAlign, useAlignState } from './align';
11
14
  import { createComment, useCommentState } from './comment';
12
15
  import { createStyle, useStyleState } from './style';
13
- import { useToolbarAction } from './useToolbarAction';
14
16
  import { type ToolbarState, useToolbarState } from './useToolbarState';
17
+ import { type SheetModel } from '../../model';
18
+ import { useSheetContext } from '../SheetContext';
15
19
 
16
20
  //
17
21
  // Root
@@ -19,11 +23,16 @@ import { type ToolbarState, useToolbarState } from './useToolbarState';
19
23
 
20
24
  export type SheetToolbarProps = ThemedClassName<PropsWithChildren<{ attendableId?: string }>>;
21
25
 
22
- const createToolbarActions = (state: ToolbarState) => {
23
- const align = createAlign(state);
24
- const style = createStyle(state);
26
+ const createToolbarActions = (
27
+ model: SheetModel,
28
+ state: ToolbarState,
29
+ onComment: (cellContent: string, cursor: string) => void,
30
+ cursorFallbackRange?: CompleteCellRange,
31
+ ) => {
32
+ const align = createAlign(model, state, cursorFallbackRange);
33
+ const style = createStyle(model, state, cursorFallbackRange);
25
34
  const gap = createGapSeparator();
26
- const comment = createComment(state);
35
+ const comment = createComment(model, state, onComment, cursorFallbackRange);
27
36
  return {
28
37
  nodes: [...align.nodes, ...style.nodes, ...gap.nodes, ...comment.nodes],
29
38
  edges: [...align.edges, ...style.edges, ...gap.edges, ...comment.edges],
@@ -31,17 +40,33 @@ const createToolbarActions = (state: ToolbarState) => {
31
40
  };
32
41
 
33
42
  export const SheetToolbar = ({ attendableId, classNames }: SheetToolbarProps) => {
43
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
44
+ const { model, cursorFallbackRange } = useSheetContext();
34
45
  const state = useToolbarState({});
35
46
  useAlignState(state);
36
47
  useStyleState(state);
37
48
  useCommentState(state);
38
49
 
39
- const actionsCreator = useCallback(() => createToolbarActions(state), [state]);
50
+ const handleComment = useCallback(
51
+ (name: string, cursor: string) =>
52
+ dispatch(
53
+ createIntent(ThreadAction.Create, {
54
+ cursor,
55
+ name,
56
+ subject: model.sheet,
57
+ }),
58
+ ),
59
+ [model.sheet, dispatch],
60
+ );
61
+
62
+ const actionsCreator = useCallback(
63
+ () => createToolbarActions(model, state, handleComment, cursorFallbackRange),
64
+ [model, state, handleComment, cursorFallbackRange],
65
+ );
40
66
  const menu = useMenuActions(actionsCreator);
41
- const handleAction = useToolbarAction(state);
42
67
 
43
68
  return (
44
- <MenuProvider {...menu} attendableId={attendableId} onAction={handleAction}>
69
+ <MenuProvider {...menu} attendableId={attendableId}>
45
70
  <ToolbarMenu classNames={classNames} />
46
71
  </MenuProvider>
47
72
  );
@@ -4,11 +4,13 @@
4
4
 
5
5
  import { useEffect } from 'react';
6
6
 
7
- import { inRange } from '@dxos/compute';
7
+ import { type CompleteCellRange, inRange } from '@dxos/compute';
8
8
  import { createMenuAction, createMenuItemGroup, type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
9
9
 
10
+ import { type ToolbarState } from './useToolbarState';
10
11
  import { SHEET_PLUGIN } from '../../meta';
11
- import { type AlignKey, alignKey, type AlignValue, rangeFromIndex } from '../../types';
12
+ import { type SheetModel } from '../../model';
13
+ import { type AlignKey, alignKey, type AlignValue, rangeFromIndex, rangeToIndex } from '../../types';
12
14
  import { useSheetContext } from '../SheetContext';
13
15
 
14
16
  export type AlignAction = { key: AlignKey; value: AlignValue };
@@ -43,21 +45,49 @@ const createAlignGroupAction = (value?: AlignValue) =>
43
45
  value: `${alignKey}--${value}`,
44
46
  } as ToolbarMenuActionGroupProperties);
45
47
 
46
- const createAlignActions = (value?: AlignValue) =>
48
+ const createAlignActions = (model: SheetModel, state: ToolbarState, cursorFallbackRange?: CompleteCellRange) =>
47
49
  Object.entries(aligns).map(([alignValue, icon]) => {
48
- return createMenuAction<AlignAction>(`${alignKey}--${alignValue}`, {
49
- key: alignKey,
50
- value: alignValue as AlignValue,
51
- checked: value === alignValue,
52
- label: [`range value ${alignValue} label`, { ns: SHEET_PLUGIN }],
53
- icon,
54
- testId: `grid.toolbar.${alignKey}.${alignValue}`,
55
- });
50
+ return createMenuAction<AlignAction>(
51
+ `${alignKey}--${alignValue}`,
52
+ () => {
53
+ if (!cursorFallbackRange) {
54
+ return;
55
+ }
56
+ const index =
57
+ model.sheet.ranges?.findIndex(
58
+ (range) =>
59
+ range.key === alignKey && inRange(rangeFromIndex(model.sheet, range.range), cursorFallbackRange.from),
60
+ ) ?? -1;
61
+ const nextRangeEntity = {
62
+ range: rangeToIndex(model.sheet, cursorFallbackRange),
63
+ key: alignKey,
64
+ value: alignValue as AlignValue,
65
+ };
66
+ if (index < 0) {
67
+ model.sheet.ranges?.push(nextRangeEntity);
68
+ state[alignKey] = nextRangeEntity.value;
69
+ } else if (model.sheet.ranges![index].value === nextRangeEntity.value) {
70
+ model.sheet.ranges?.splice(index, 1);
71
+ state[alignKey] = undefined;
72
+ } else {
73
+ model.sheet.ranges?.splice(index, 1, nextRangeEntity);
74
+ state[alignKey] = nextRangeEntity.value;
75
+ }
76
+ },
77
+ {
78
+ key: alignKey,
79
+ value: alignValue as AlignValue,
80
+ checked: state[alignKey] === alignValue,
81
+ label: [`range value ${alignValue} label`, { ns: SHEET_PLUGIN }],
82
+ icon,
83
+ testId: `grid.toolbar.${alignKey}.${alignValue}`,
84
+ },
85
+ );
56
86
  });
57
87
 
58
- export const createAlign = ({ [alignKey]: alignValue }: Partial<AlignState>) => {
59
- const alignGroup = createAlignGroupAction(alignValue);
60
- const alignActions = createAlignActions(alignValue);
88
+ export const createAlign = (model: SheetModel, state: ToolbarState, cursorFallbackRange?: CompleteCellRange) => {
89
+ const alignGroup = createAlignGroupAction(state[alignKey]);
90
+ const alignActions = createAlignActions(model, state, cursorFallbackRange);
61
91
  return {
62
92
  nodes: [alignGroup, ...alignActions],
63
93
  edges: [
@@ -4,10 +4,13 @@
4
4
 
5
5
  import { useEffect, useMemo } from 'react';
6
6
 
7
+ import { type CompleteCellRange } from '@dxos/compute';
7
8
  import { RefArray } from '@dxos/live-object';
8
9
  import { createMenuAction } from '@dxos/react-ui-menu';
9
10
 
11
+ import { completeCellRangeToThreadCursor } from '../../integrations/thread-ranges';
10
12
  import { SHEET_PLUGIN } from '../../meta';
13
+ import { type SheetModel } from '../../model';
11
14
  import { commentKey, type CommentKey, type CommentValue, rangeToIndex } from '../../types';
12
15
  import { useSheetContext } from '../SheetContext';
13
16
 
@@ -41,16 +44,41 @@ export const useCommentState = (state: Partial<CommentState>) => {
41
44
  }, [overlapsCommentAnchor, cursorFallbackRange]);
42
45
  };
43
46
 
44
- const createCommentAction = (state: Partial<CommentState>) =>
45
- createMenuAction<Pick<CommentAction, 'key'>>('comment', {
46
- key: commentKey,
47
- testId: 'editor.toolbar.comment',
48
- icon: 'ph--chat-text--regular',
49
- label: [`${state.commentEnabled} label`, { ns: SHEET_PLUGIN }],
50
- disabled: state.commentEnabled !== 'comment',
51
- });
52
-
53
- export const createComment = (state: Partial<CommentState>) => ({
54
- nodes: [createCommentAction(state)],
47
+ const createCommentAction = (
48
+ model: SheetModel,
49
+ state: Partial<CommentState>,
50
+ onComment: (cellContent: string, cursor: string) => void,
51
+ cursorFallbackRange?: CompleteCellRange,
52
+ ) =>
53
+ createMenuAction<Pick<CommentAction, 'key'>>(
54
+ 'comment',
55
+ () => {
56
+ if (!cursorFallbackRange) {
57
+ return;
58
+ }
59
+
60
+ const cellContent = model.getCellText(cursorFallbackRange.from);
61
+ if (!cellContent) {
62
+ return;
63
+ }
64
+
65
+ onComment(cellContent, completeCellRangeToThreadCursor(cursorFallbackRange));
66
+ },
67
+ {
68
+ key: commentKey,
69
+ testId: 'editor.toolbar.comment',
70
+ icon: 'ph--chat-text--regular',
71
+ label: [`${state.commentEnabled} label`, { ns: SHEET_PLUGIN }],
72
+ disabled: state.commentEnabled !== 'comment',
73
+ },
74
+ );
75
+
76
+ export const createComment = (
77
+ model: SheetModel,
78
+ state: Partial<CommentState>,
79
+ onComment: (cellContent: string, cursor: string) => void,
80
+ cursorFallbackRange?: CompleteCellRange,
81
+ ) => ({
82
+ nodes: [createCommentAction(model, state, onComment, cursorFallbackRange)],
55
83
  edges: [{ source: 'root', target: 'comment' }],
56
84
  });
@@ -4,11 +4,12 @@
4
4
 
5
5
  import { useEffect } from 'react';
6
6
 
7
- import { inRange } from '@dxos/compute';
7
+ import { type CompleteCellRange, inRange } from '@dxos/compute';
8
8
  import { createMenuAction, createMenuItemGroup, type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';
9
9
 
10
10
  import { SHEET_PLUGIN } from '../../meta';
11
- import { rangeFromIndex, type StyleKey, type StyleValue } from '../../types';
11
+ import { type SheetModel } from '../../model';
12
+ import { rangeFromIndex, rangeToIndex, type StyleKey, type StyleValue } from '../../types';
12
13
  import { useSheetContext } from '../SheetContext';
13
14
 
14
15
  export type StyleState = Partial<Record<StyleValue, boolean>>;
@@ -48,20 +49,55 @@ const createStyleGroup = (state: StyleState) => {
48
49
  } as ToolbarMenuActionGroupProperties);
49
50
  };
50
51
 
51
- const createStyleActions = (state: StyleState) =>
52
+ const createStyleActions = (model: SheetModel, state: StyleState, cursorFallbackRange?: CompleteCellRange) =>
52
53
  Object.entries(styles).map(([styleValue, icon]) => {
53
- return createMenuAction<StyleAction>(`style--${styleValue}`, {
54
- key: 'style',
55
- value: styleValue as StyleValue,
56
- icon,
57
- label: [`range value ${styleValue} label`, { ns: SHEET_PLUGIN }],
58
- checked: !!state[styleValue as StyleValue],
59
- });
54
+ return createMenuAction<StyleAction>(
55
+ `style--${styleValue}`,
56
+ () => {
57
+ if (!cursorFallbackRange) {
58
+ return;
59
+ }
60
+ const index =
61
+ model.sheet.ranges?.findIndex(
62
+ (range) =>
63
+ range.key === 'style' && inRange(rangeFromIndex(model.sheet, range.range), cursorFallbackRange.from),
64
+ ) ?? -1;
65
+ const nextRangeEntity = {
66
+ range: rangeToIndex(model.sheet, cursorFallbackRange),
67
+ key: 'style',
68
+ value: styleValue as StyleValue,
69
+ };
70
+ if (
71
+ model.sheet.ranges
72
+ .filter(
73
+ ({ range, key: rangeKey }) =>
74
+ rangeKey === 'style' && inRange(rangeFromIndex(model.sheet, range), cursorFallbackRange.from),
75
+ )
76
+ .some(({ value: rangeValue }) => rangeValue === styleValue)
77
+ ) {
78
+ // this value should be unset
79
+ if (index >= 0) {
80
+ model.sheet.ranges?.splice(index, 1);
81
+ }
82
+ state[nextRangeEntity.value] = false;
83
+ } else {
84
+ model.sheet.ranges?.push(nextRangeEntity);
85
+ state[nextRangeEntity.value] = true;
86
+ }
87
+ },
88
+ {
89
+ key: 'style',
90
+ value: styleValue as StyleValue,
91
+ icon,
92
+ label: [`range value ${styleValue} label`, { ns: SHEET_PLUGIN }],
93
+ checked: !!state[styleValue as StyleValue],
94
+ },
95
+ );
60
96
  });
61
97
 
62
- export const createStyle = (state: StyleState) => {
98
+ export const createStyle = (model: SheetModel, state: StyleState, cursorFallbackRange?: CompleteCellRange) => {
63
99
  const styleGroupAction = createStyleGroup(state);
64
- const styleActions = createStyleActions(state);
100
+ const styleActions = createStyleActions(model, state, cursorFallbackRange);
65
101
  return {
66
102
  nodes: [styleGroupAction, ...styleActions],
67
103
  edges: [
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { pipe } from 'effect';
5
+ import { Schema, pipe } from 'effect';
6
6
  import { useCallback, useEffect, useMemo } from 'react';
7
7
 
8
8
  import {
@@ -15,7 +15,6 @@ import {
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
- import { S } from '@dxos/echo-schema';
19
18
  import { ATTENDABLE_PATH_SEPARATOR, DeckAction } from '@dxos/plugin-deck/types';
20
19
  import { ThreadAction } from '@dxos/plugin-thread/types';
21
20
  import { fullyQualifiedId } from '@dxos/react-client/echo';
@@ -55,7 +54,7 @@ export const useUpdateFocusedCellOnThreadSelection = (grid: DxGridElement | null
55
54
  subject: string;
56
55
  options: { cursor: string; ref: GridContentProps['activeRefs'] };
57
56
  } => {
58
- if (!S.is(LayoutAction.ScrollIntoView.fields.input)(data)) {
57
+ if (!Schema.is(LayoutAction.ScrollIntoView.fields.input)(data)) {
59
58
  return false;
60
59
  }
61
60
 
@@ -7,7 +7,7 @@ import { afterEach, beforeEach, describe, expect, onTestFinished, test } from 'v
7
7
  import { Trigger } from '@dxos/async';
8
8
  import { type CellScalarValue, addressFromA1Notation, isFormula } from '@dxos/compute';
9
9
  import { TestBuilder, testFunctionPlugins } from '@dxos/compute/testing';
10
- import { FunctionType } from '@dxos/functions/types';
10
+ import { FunctionType } from '@dxos/functions';
11
11
  import { log } from '@dxos/log';
12
12
 
13
13
  import { SheetModel } from './sheet-model';
@@ -12,7 +12,7 @@ import { describe, test, expect } from 'vitest';
12
12
 
13
13
  import { Client } from '@dxos/client';
14
14
  import { live } from '@dxos/client/echo';
15
- import { FunctionType } from '@dxos/functions/types';
15
+ import { FunctionType } from '@dxos/functions';
16
16
 
17
17
  // TODO(burdon): Fix test infrastructure:
18
18
  // - Need docs? esp. needed for config. need pristine example package?
@@ -2,55 +2,57 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { Ref, S, TypedObject } from '@dxos/echo-schema';
5
+ import { Schema } from 'effect';
6
+
7
+ import { Ref, TypedObject } from '@dxos/echo-schema';
6
8
  import { ThreadType } from '@dxos/plugin-space/types';
7
9
 
8
- export const CellValue = S.Struct({
10
+ export const CellValue = Schema.Struct({
9
11
  // TODO(burdon): How to store dates (datetime, date, time), percentages, etc.
10
12
  // Consider import/export; natural access for other plugins. Special handling for currency (precision).
11
13
  // TODO(burdon): Automerge (long string) or short string or number.
12
- value: S.Any,
14
+ value: Schema.Any,
13
15
  });
14
16
 
15
- export type CellValue = S.Schema.Type<typeof CellValue>;
17
+ export type CellValue = Schema.Schema.Type<typeof CellValue>;
16
18
 
17
19
  // TODO(burdon): IMPORTANT: Reconcile with Field definition.
18
- export const Range = S.Struct({
19
- range: S.String,
20
- key: S.String,
21
- value: S.String,
20
+ export const Range = Schema.Struct({
21
+ range: Schema.String,
22
+ key: Schema.String,
23
+ value: Schema.String,
22
24
  });
23
25
 
24
- export type Range = S.Schema.Type<typeof Range>;
26
+ export type Range = Schema.Schema.Type<typeof Range>;
25
27
 
26
28
  // TODO(burdon): Visibility, locked, frozen, etc.
27
- export const RowColumnMeta = S.Struct({
28
- size: S.optional(S.Number),
29
+ export const RowColumnMeta = Schema.Struct({
30
+ size: Schema.optional(Schema.Number),
29
31
  });
30
32
 
31
33
  // TODO(burdon): Reconcile col/column (across packages).
32
34
  // TODO(burdon): Index to all updates when rows/columns are inserted/deleted.
33
35
  export class SheetType extends TypedObject({ typename: 'dxos.org/type/Sheet', version: '0.1.0' })({
34
- name: S.optional(S.String),
36
+ name: Schema.optional(Schema.String),
35
37
 
36
38
  // Sparse map of cells referenced by index.
37
- cells: S.mutable(S.Record({ key: S.String, value: S.mutable(CellValue) })),
39
+ cells: Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.mutable(CellValue) })),
38
40
 
39
41
  // Ordered row indices.
40
- rows: S.mutable(S.Array(S.String)),
42
+ rows: Schema.mutable(Schema.Array(Schema.String)),
41
43
 
42
44
  // Ordered column indices.
43
- columns: S.mutable(S.Array(S.String)),
45
+ columns: Schema.mutable(Schema.Array(Schema.String)),
44
46
 
45
47
  // Row metadata referenced by index.
46
- rowMeta: S.mutable(S.Record({ key: S.String, value: S.mutable(RowColumnMeta) })),
48
+ rowMeta: Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.mutable(RowColumnMeta) })),
47
49
 
48
50
  // Column metadata referenced by index.
49
- columnMeta: S.mutable(S.Record({ key: S.String, value: S.mutable(RowColumnMeta) })),
51
+ columnMeta: Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.mutable(RowColumnMeta) })),
50
52
 
51
53
  // Cell formatting referenced by indexed range.
52
- ranges: S.mutable(S.Array(Range)),
54
+ ranges: Schema.mutable(Schema.Array(Range)),
53
55
 
54
56
  // Threads associated with the sheet
55
- threads: S.optional(S.mutable(S.Array(Ref(ThreadType)))),
57
+ threads: Schema.optional(Schema.mutable(Schema.Array(Ref(ThreadType)))),
56
58
  }) {}
@@ -2,7 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { S } from '@dxos/echo-schema';
5
+ import { Schema } from 'effect';
6
6
 
7
7
  import { type CellValue, RowColumnMeta, SheetType } from './schema';
8
8
  import { SHEET_PLUGIN } from '../meta';
@@ -21,47 +21,47 @@ export type CreateSheetOptions = {
21
21
  export namespace SheetAction {
22
22
  const SHEET_ACTION = `${SHEET_PLUGIN}/action`;
23
23
 
24
- export class Create extends S.TaggedClass<Create>()(`${SHEET_ACTION}/create`, {
25
- input: S.Struct({
26
- name: S.optional(S.String),
24
+ export class Create extends Schema.TaggedClass<Create>()(`${SHEET_ACTION}/create`, {
25
+ input: Schema.Struct({
26
+ name: Schema.optional(Schema.String),
27
27
  }),
28
- output: S.Struct({
28
+ output: Schema.Struct({
29
29
  object: SheetType,
30
30
  }),
31
31
  }) {}
32
32
 
33
33
  // TODO(wittjosiah): Factor out. This is `DxGridAxis` from `@dxos/react-ui-grid`.
34
- const Axis = S.Union(S.Literal('row'), S.Literal('col'));
34
+ const Axis = Schema.Union(Schema.Literal('row'), Schema.Literal('col'));
35
35
 
36
- export class InsertAxis extends S.TaggedClass<InsertAxis>()(`${SHEET_ACTION}/axis-insert`, {
37
- input: S.Struct({
38
- // TODO(wittjosiah): S.instanceOf(SheetModel) throws when running tests.
39
- model: S.Any.pipe(S.filter((model) => model instanceof SheetModel)) as S.Schema<SheetModel>,
36
+ export class InsertAxis extends Schema.TaggedClass<InsertAxis>()(`${SHEET_ACTION}/axis-insert`, {
37
+ input: Schema.Struct({
38
+ // TODO(wittjosiah): Schema.instanceOf(SheetModel) throws when running tests.
39
+ model: Schema.Any.pipe(Schema.filter((model) => model instanceof SheetModel)) as Schema.Schema<SheetModel>,
40
40
  axis: Axis,
41
- index: S.Number,
42
- count: S.optional(S.Number),
41
+ index: Schema.Number,
42
+ count: Schema.optional(Schema.Number),
43
43
  }),
44
- output: S.Void,
44
+ output: Schema.Void,
45
45
  }) {}
46
46
 
47
- export const RestoreAxis = S.Struct({
47
+ export const RestoreAxis = Schema.Struct({
48
48
  axis: Axis,
49
- axisIndex: S.String,
50
- index: S.Number,
49
+ axisIndex: Schema.String,
50
+ index: Schema.Number,
51
51
  axisMeta: RowColumnMeta,
52
- values: S.Array(S.Any),
52
+ values: Schema.Array(Schema.Any),
53
53
  });
54
54
 
55
- export type RestoreAxis = S.Schema.Type<typeof RestoreAxis>;
55
+ export type RestoreAxis = Schema.Schema.Type<typeof RestoreAxis>;
56
56
 
57
- export class DropAxis extends S.TaggedClass<DropAxis>()(`${SHEET_ACTION}/axis-drop`, {
58
- input: S.Struct({
59
- // TODO(wittjosiah): S.instanceOf(SheetModel) throws when running tests.
60
- model: S.Any.pipe(S.filter((model) => model instanceof SheetModel)) as S.Schema<SheetModel>,
57
+ export class DropAxis extends Schema.TaggedClass<DropAxis>()(`${SHEET_ACTION}/axis-drop`, {
58
+ input: Schema.Struct({
59
+ // TODO(wittjosiah): Schema.instanceOf(SheetModel) throws when running tests.
60
+ model: Schema.Any.pipe(Schema.filter((model) => model instanceof SheetModel)) as Schema.Schema<SheetModel>,
61
61
  axis: Axis,
62
- axisIndex: S.String,
63
- deletionData: S.optional(RestoreAxis),
62
+ axisIndex: Schema.String,
63
+ deletionData: Schema.optional(RestoreAxis),
64
64
  }),
65
- output: S.Void,
65
+ output: Schema.Void,
66
66
  }) {}
67
67
  }
@@ -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/comment.ts", "../../../src/components/SheetToolbar/style.ts", "../../../src/components/SheetToolbar/useToolbarAction.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 const SheetContainer = ({\n space,\n sheet,\n role,\n ignoreAttention,\n}: {\n space: Space;\n sheet: SheetType;\n role?: string;\n ignoreAttention?: boolean;\n}) => {\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 attendableId={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 attention-surface border-bs !border-separator'>\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 React, { type PropsWithChildren, useCallback } from 'react';\n\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport { createGapSeparator, MenuProvider, ToolbarMenu, useMenuActions } from '@dxos/react-ui-menu';\n\nimport { createAlign, useAlignState } from './align';\nimport { createComment, useCommentState } from './comment';\nimport { createStyle, useStyleState } from './style';\nimport { useToolbarAction } from './useToolbarAction';\nimport { type ToolbarState, useToolbarState } from './useToolbarState';\n\n//\n// Root\n//\n\nexport type SheetToolbarProps = ThemedClassName<PropsWithChildren<{ attendableId?: string }>>;\n\nconst createToolbarActions = (state: ToolbarState) => {\n const align = createAlign(state);\n const style = createStyle(state);\n const gap = createGapSeparator();\n const comment = createComment(state);\n return {\n nodes: [...align.nodes, ...style.nodes, ...gap.nodes, ...comment.nodes],\n edges: [...align.edges, ...style.edges, ...gap.edges, ...comment.edges],\n };\n};\n\nexport const SheetToolbar = ({ attendableId, classNames }: SheetToolbarProps) => {\n const state = useToolbarState({});\n useAlignState(state);\n useStyleState(state);\n useCommentState(state);\n\n const actionsCreator = useCallback(() => createToolbarActions(state), [state]);\n const menu = useMenuActions(actionsCreator);\n const handleAction = useToolbarAction(state);\n\n return (\n <MenuProvider {...menu} attendableId={attendableId} onAction={handleAction}>\n <ToolbarMenu classNames={classNames} />\n </MenuProvider>\n );\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect } from 'react';\n\nimport { inRange } from '@dxos/compute';\nimport { createMenuAction, createMenuItemGroup, type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';\n\nimport { SHEET_PLUGIN } from '../../meta';\nimport { type AlignKey, alignKey, type AlignValue, rangeFromIndex } 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 = (value?: AlignValue) =>\n Object.entries(aligns).map(([alignValue, icon]) => {\n return createMenuAction<AlignAction>(`${alignKey}--${alignValue}`, {\n key: alignKey,\n value: alignValue as AlignValue,\n checked: value === alignValue,\n label: [`range value ${alignValue} label`, { ns: SHEET_PLUGIN }],\n icon,\n testId: `grid.toolbar.${alignKey}.${alignValue}`,\n });\n });\n\nexport const createAlign = ({ [alignKey]: alignValue }: Partial<AlignState>) => {\n const alignGroup = createAlignGroupAction(alignValue);\n const alignActions = createAlignActions(alignValue);\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, useMemo } from 'react';\n\nimport { RefArray } from '@dxos/live-object';\nimport { createMenuAction } from '@dxos/react-ui-menu';\n\nimport { SHEET_PLUGIN } from '../../meta';\nimport { commentKey, type CommentKey, type CommentValue, rangeToIndex } from '../../types';\nimport { useSheetContext } from '../SheetContext';\n\nexport type CommentAction = { key: CommentKey; value: CommentValue; cellContent?: string };\n\nexport type CommentState = { commentEnabled: 'comment' | 'no cursor' | 'selection overlaps existing comment' };\n\nexport const useCommentState = (state: Partial<CommentState>) => {\n const { cursorFallbackRange, model } = useSheetContext();\n\n // TODO(thure): Can this O(n) call be memoized?\n const overlapsCommentAnchor = useMemo(\n () =>\n RefArray.targets(model.sheet.threads ?? [])\n .filter((thread) => thread.status !== 'resolved')\n .some((thread) => {\n if (!cursorFallbackRange) {\n return false;\n }\n return rangeToIndex(model.sheet, cursorFallbackRange) === thread.anchor;\n }),\n [cursorFallbackRange, model.sheet],\n );\n\n useEffect(() => {\n state.commentEnabled = !cursorFallbackRange\n ? 'no cursor'\n : overlapsCommentAnchor\n ? 'selection overlaps existing comment'\n : 'comment';\n }, [overlapsCommentAnchor, cursorFallbackRange]);\n};\n\nconst createCommentAction = (state: Partial<CommentState>) =>\n createMenuAction<Pick<CommentAction, 'key'>>('comment', {\n key: commentKey,\n testId: 'editor.toolbar.comment',\n icon: 'ph--chat-text--regular',\n label: [`${state.commentEnabled} label`, { ns: SHEET_PLUGIN }],\n disabled: state.commentEnabled !== 'comment',\n });\n\nexport const createComment = (state: Partial<CommentState>) => ({\n nodes: [createCommentAction(state)],\n edges: [{ source: 'root', target: 'comment' }],\n});\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { useEffect } from 'react';\n\nimport { inRange } from '@dxos/compute';\nimport { createMenuAction, createMenuItemGroup, type ToolbarMenuActionGroupProperties } from '@dxos/react-ui-menu';\n\nimport { SHEET_PLUGIN } from '../../meta';\nimport { rangeFromIndex, 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 = (state: StyleState) =>\n Object.entries(styles).map(([styleValue, icon]) => {\n return createMenuAction<StyleAction>(`style--${styleValue}`, {\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\nexport const createStyle = (state: StyleState) => {\n const styleGroupAction = createStyleGroup(state);\n const styleActions = createStyleActions(state);\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 { useCallback } from 'react';\n\nimport { createIntent, useIntentDispatcher } from '@dxos/app-framework';\nimport { inRange } from '@dxos/compute';\nimport { ThreadAction } from '@dxos/plugin-thread/types';\nimport type { MenuAction, MenuActionHandler } from '@dxos/react-ui-menu';\n\nimport { type AlignAction } from './align';\nimport { type CommentAction } from './comment';\nimport { type StyleAction } from './style';\nimport { type ToolbarState } from './useToolbarState';\nimport { completeCellRangeToThreadCursor } from '../../integrations';\nimport { alignKey, rangeFromIndex, rangeToIndex } from '../../types';\nimport { useSheetContext } from '../SheetContext';\n\nexport type ToolbarAction = StyleAction | AlignAction | CommentAction;\n\nexport const useToolbarAction = (state: ToolbarState) => {\n const { model, cursorFallbackRange, cursor } = useSheetContext();\n const { dispatchPromise: dispatch } = useIntentDispatcher();\n\n // TODO(Zan): Externalize the toolbar action handler. E.g., Toolbar/keys should both fire events.\n return useCallback(\n (action: MenuAction<ToolbarAction>) => {\n const { key, value } = action.properties;\n if (cursorFallbackRange) {\n const index =\n model.sheet.ranges?.findIndex(\n (range) => range.key === key && inRange(rangeFromIndex(model.sheet, range.range), cursorFallbackRange.from),\n ) ?? -1;\n const nextRangeEntity = {\n range: rangeToIndex(model.sheet, cursorFallbackRange),\n key,\n value,\n };\n switch (key) {\n case 'alignment':\n if (index < 0) {\n model.sheet.ranges?.push(nextRangeEntity);\n state[alignKey] = value;\n } else if (model.sheet.ranges![index].value === 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] = value;\n }\n break;\n case 'style':\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 === value)\n ) {\n // this value should be unset\n if (index >= 0) {\n model.sheet.ranges?.splice(index, 1);\n }\n state[value] = false;\n } else {\n model.sheet.ranges?.push(nextRangeEntity);\n state[value] = true;\n }\n break;\n case 'comment': {\n const cellContent = model.getCellText(cursorFallbackRange.from);\n void dispatch(\n createIntent(ThreadAction.Create, {\n cursor: completeCellRangeToThreadCursor(cursorFallbackRange),\n name: cellContent,\n subject: model.sheet,\n }),\n );\n }\n }\n }\n },\n [model.sheet, cursorFallbackRange, cursor, dispatch],\n ) as MenuActionHandler;\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 CommentState } from './comment';\nimport { type StyleState } from './style';\n\nexport type ToolbarState = Partial<StyleState & AlignState & CommentState>;\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,MA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BC,OACAC,OACAC,MACAC,gBAAe,MAMhB;AACC,QAAMC,QAAQC,gBAAgBL,KAAAA;AAE9B,SAAOI,QACL,gBAAAE,OAAA,cAACC,eAAAA;IAAcN;IAAcG;IAAcD;KACzC,gBAAAG,OAAA,cAACE,UAAUC,SAAO;IAACC,SAAAA;IAAQC,WAAAA;IAAW,GAAIT,SAAS,aAAa;MAAEU,YAAY;IAAe;KAC3F,gBAAAN,OAAA,cAACO,cAAAA;IAAaC,cAAcC,iBAAiBd,KAAAA;MAC7C,gBAAAK,OAAA,cAACU,WAAAA,IAAAA,GACD,gBAAAV,OAAA,cAACW,gBAAAA,IAAAA,CAAAA,CAAAA,IAGH;AACN;;;AQhCA,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", "React", "useCallback", "createGapSeparator", "MenuProvider", "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", "Object", "entries", "map", "alignValue", "icon", "createMenuAction", "checked", "testId", "createAlign", "alignGroup", "alignActions", "nodes", "edges", "source", "target", "id", "useEffect", "useMemo", "RefArray", "createMenuAction", "useCommentState", "state", "cursorFallbackRange", "model", "useSheetContext", "overlapsCommentAnchor", "useMemo", "RefArray", "targets", "sheet", "threads", "filter", "thread", "status", "some", "rangeToIndex", "anchor", "useEffect", "commentEnabled", "createCommentAction", "createMenuAction", "key", "commentKey", "testId", "icon", "label", "ns", "SHEET_PLUGIN", "disabled", "createComment", "nodes", "edges", "source", "target", "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", "label", "ns", "SHEET_PLUGIN", "checked", "createStyle", "styleGroupAction", "styleActions", "nodes", "edges", "source", "target", "id", "useCallback", "createIntent", "useIntentDispatcher", "inRange", "ThreadAction", "useToolbarAction", "state", "model", "cursorFallbackRange", "cursor", "useSheetContext", "dispatchPromise", "dispatch", "useIntentDispatcher", "useCallback", "action", "key", "value", "properties", "index", "sheet", "ranges", "findIndex", "range", "inRange", "rangeFromIndex", "from", "nextRangeEntity", "rangeToIndex", "push", "alignKey", "splice", "undefined", "filter", "rangeKey", "some", "rangeValue", "cellContent", "getCellText", "createIntent", "ThreadAction", "Create", "completeCellRangeToThreadCursor", "name", "subject", "useMemo", "live", "useToolbarState", "initialState", "useMemo", "live", "createToolbarActions", "state", "align", "createAlign", "style", "createStyle", "gap", "createGapSeparator", "comment", "createComment", "nodes", "edges", "SheetToolbar", "attendableId", "classNames", "useToolbarState", "useAlignState", "useStyleState", "useCommentState", "actionsCreator", "useCallback", "menu", "useMenuActions", "handleAction", "useToolbarAction", "React", "MenuProvider", "onAction", "ToolbarMenu", "SheetContainer", "space", "sheet", "role", "ignoreAttention", "graph", "useComputeGraph", "React", "SheetProvider", "StackItem", "Content", "toolbar", "statusbar", "classNames", "SheetToolbar", "attendableId", "fullyQualifiedId", "GridSheet", "FunctionEditor", "SheetContainer"]
7
- }