@dxos/plugin-sheet 0.6.12-main.15a606f → 0.6.12-main.2d19bf1

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 (266) hide show
  1. package/dist/lib/browser/SheetContainer-NDNIS44E.mjs +265 -0
  2. package/dist/lib/browser/SheetContainer-NDNIS44E.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-AQSGDA4X.mjs +1614 -0
  4. package/dist/lib/browser/chunk-AQSGDA4X.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-QILRZNE5.mjs → chunk-D3QTX46O.mjs} +4 -5
  6. package/dist/lib/browser/chunk-D3QTX46O.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-T3NJFTD4.mjs → chunk-GKI67SEF.mjs} +20 -26
  8. package/dist/lib/browser/chunk-GKI67SEF.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-6ZMQVB4Z.mjs → chunk-GSV5QNLD.mjs} +220 -177
  10. package/dist/lib/browser/chunk-GSV5QNLD.mjs.map +7 -0
  11. package/dist/lib/browser/graph-M4IQ76QX.mjs +33 -0
  12. package/dist/lib/browser/index.mjs +41 -22
  13. package/dist/lib/browser/index.mjs.map +3 -3
  14. package/dist/lib/browser/meta.json +1 -1
  15. package/dist/lib/browser/meta.mjs +1 -1
  16. package/dist/lib/browser/types.mjs +4 -8
  17. package/dist/lib/node/SheetContainer-YSQGJD7K.cjs +276 -0
  18. package/dist/lib/node/SheetContainer-YSQGJD7K.cjs.map +7 -0
  19. package/dist/lib/node/{chunk-DD6FIXWC.cjs → chunk-5XPK2V4A.cjs} +222 -175
  20. package/dist/lib/node/chunk-5XPK2V4A.cjs.map +7 -0
  21. package/dist/lib/node/chunk-6F43RV45.cjs +1610 -0
  22. package/dist/lib/node/chunk-6F43RV45.cjs.map +7 -0
  23. package/dist/lib/node/{chunk-Q3HBHPRL.cjs → chunk-ER3PM7GD.cjs} +26 -34
  24. package/dist/lib/node/chunk-ER3PM7GD.cjs.map +7 -0
  25. package/dist/lib/node/{chunk-BNARJ5GM.cjs → chunk-QIFIGEKV.cjs} +6 -7
  26. package/dist/lib/node/chunk-QIFIGEKV.cjs.map +7 -0
  27. package/dist/lib/node/graph-Q3N2X26H.cjs +55 -0
  28. package/dist/lib/node/graph-Q3N2X26H.cjs.map +7 -0
  29. package/dist/lib/node/index.cjs +61 -44
  30. package/dist/lib/node/index.cjs.map +3 -3
  31. package/dist/lib/node/meta.cjs +3 -3
  32. package/dist/lib/node/meta.cjs.map +1 -1
  33. package/dist/lib/node/meta.json +1 -1
  34. package/dist/lib/node/types.cjs +8 -12
  35. package/dist/lib/node/types.cjs.map +2 -2
  36. package/dist/lib/node-esm/SheetContainer-M7WRMZDU.mjs +266 -0
  37. package/dist/lib/node-esm/SheetContainer-M7WRMZDU.mjs.map +7 -0
  38. package/dist/lib/node-esm/{chunk-D6KU5MI7.mjs → chunk-5WPZCXNS.mjs} +220 -177
  39. package/dist/lib/node-esm/chunk-5WPZCXNS.mjs.map +7 -0
  40. package/dist/lib/node-esm/chunk-ELTFPX5B.mjs +1615 -0
  41. package/dist/lib/node-esm/chunk-ELTFPX5B.mjs.map +7 -0
  42. package/dist/lib/node-esm/{chunk-IU2L277A.mjs → chunk-VCYJWE3O.mjs} +4 -5
  43. package/dist/lib/node-esm/chunk-VCYJWE3O.mjs.map +7 -0
  44. package/dist/lib/node-esm/{chunk-BMNA27EX.mjs → chunk-ZVLLQ2PJ.mjs} +20 -26
  45. package/dist/lib/node-esm/chunk-ZVLLQ2PJ.mjs.map +7 -0
  46. package/dist/lib/node-esm/graph-SMPUMOV2.mjs +34 -0
  47. package/dist/lib/node-esm/index.mjs +41 -22
  48. package/dist/lib/node-esm/index.mjs.map +3 -3
  49. package/dist/lib/node-esm/meta.json +1 -1
  50. package/dist/lib/node-esm/meta.mjs +1 -1
  51. package/dist/lib/node-esm/types.mjs +4 -8
  52. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  53. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts +3 -0
  54. package/dist/types/src/components/FunctionEditor/FunctionEditor.d.ts.map +1 -0
  55. package/dist/types/src/components/FunctionEditor/index.d.ts +2 -0
  56. package/dist/types/src/components/FunctionEditor/index.d.ts.map +1 -0
  57. package/dist/types/src/components/GridSheet/GridSheet.d.ts +1 -8
  58. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
  59. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +1 -1
  60. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -1
  61. package/dist/types/src/components/{CellEditor/CellEditor.stories.d.ts → GridSheet/SheetCellEditor.stories.d.ts} +2 -2
  62. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +1 -0
  63. package/dist/types/src/components/GridSheet/index.d.ts +2 -0
  64. package/dist/types/src/components/GridSheet/index.d.ts.map +1 -0
  65. package/dist/types/src/components/GridSheet/util.d.ts +13 -3
  66. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -1
  67. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +6 -0
  68. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -0
  69. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +11 -0
  70. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -0
  71. package/dist/types/src/components/SheetContainer/index.d.ts +3 -0
  72. package/dist/types/src/components/SheetContainer/index.d.ts.map +1 -0
  73. package/dist/types/src/components/SheetContext/SheetContext.d.ts +27 -0
  74. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -0
  75. package/dist/types/src/components/SheetContext/index.d.ts +2 -0
  76. package/dist/types/src/components/SheetContext/index.d.ts.map +1 -0
  77. package/dist/types/src/components/Toolbar/Toolbar.d.ts +31 -17
  78. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
  79. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +1 -1
  80. package/dist/types/src/components/index.d.ts +3 -2
  81. package/dist/types/src/components/index.d.ts.map +1 -1
  82. package/dist/types/src/defs/types.d.ts.map +1 -1
  83. package/dist/types/src/defs/util.d.ts +1 -1
  84. package/dist/types/src/defs/util.d.ts.map +1 -1
  85. package/dist/types/src/extensions/compute.d.ts +3 -2
  86. package/dist/types/src/extensions/compute.d.ts.map +1 -1
  87. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -1
  88. package/dist/types/src/extensions/editor/extension.d.ts.map +1 -0
  89. package/dist/types/src/extensions/editor/extension.test.d.ts.map +1 -0
  90. package/dist/types/src/extensions/editor/index.d.ts +2 -0
  91. package/dist/types/src/extensions/editor/index.d.ts.map +1 -0
  92. package/dist/types/src/extensions/index.d.ts +1 -0
  93. package/dist/types/src/extensions/index.d.ts.map +1 -1
  94. package/dist/types/src/graph/compute-graph-registry.d.ts +34 -0
  95. package/dist/types/src/graph/compute-graph-registry.d.ts.map +1 -0
  96. package/dist/types/src/graph/compute-graph.d.ts +17 -34
  97. package/dist/types/src/graph/compute-graph.d.ts.map +1 -1
  98. package/dist/types/src/graph/compute-graph.stories.d.ts.map +1 -1
  99. package/dist/types/src/graph/compute-graph.test.d.ts +2 -0
  100. package/dist/types/src/graph/compute-graph.test.d.ts.map +1 -0
  101. package/dist/types/src/graph/compute-node.d.ts +9 -2
  102. package/dist/types/src/graph/compute-node.d.ts.map +1 -1
  103. package/dist/types/src/graph/{async-function.d.ts → functions/async-function.d.ts} +13 -4
  104. package/dist/types/src/graph/functions/async-function.d.ts.map +1 -0
  105. package/dist/types/src/graph/functions/edge-function.d.ts +21 -0
  106. package/dist/types/src/graph/functions/edge-function.d.ts.map +1 -0
  107. package/dist/types/src/graph/functions/function-defs.d.ts.map +1 -0
  108. package/dist/types/src/graph/functions/index.d.ts +4 -0
  109. package/dist/types/src/graph/functions/index.d.ts.map +1 -0
  110. package/dist/types/src/graph/index.d.ts +2 -1
  111. package/dist/types/src/graph/index.d.ts.map +1 -1
  112. package/dist/types/src/graph/testing/index.d.ts +3 -0
  113. package/dist/types/src/graph/testing/index.d.ts.map +1 -0
  114. package/dist/types/src/graph/testing/test-builder.d.ts +15 -0
  115. package/dist/types/src/graph/testing/test-builder.d.ts.map +1 -0
  116. package/dist/types/src/graph/testing/test-plugin.d.ts +36 -0
  117. package/dist/types/src/graph/testing/test-plugin.d.ts.map +1 -0
  118. package/dist/types/src/hooks/index.d.ts +1 -0
  119. package/dist/types/src/hooks/index.d.ts.map +1 -1
  120. package/dist/types/src/hooks/threads.d.ts +8 -0
  121. package/dist/types/src/hooks/threads.d.ts.map +1 -0
  122. package/dist/types/src/hooks/useComputeGraph.d.ts.map +1 -1
  123. package/dist/types/src/hooks/useSheetModel.d.ts +2 -2
  124. package/dist/types/src/hooks/useSheetModel.d.ts.map +1 -1
  125. package/dist/types/src/meta.d.ts +3 -6
  126. package/dist/types/src/meta.d.ts.map +1 -1
  127. package/dist/types/src/{components/Sheet → model}/decorations.d.ts +1 -0
  128. package/dist/types/src/model/decorations.d.ts.map +1 -0
  129. package/dist/types/src/model/formatting-model.d.ts +3 -0
  130. package/dist/types/src/model/formatting-model.d.ts.map +1 -1
  131. package/dist/types/src/model/index.d.ts +1 -0
  132. package/dist/types/src/model/index.d.ts.map +1 -1
  133. package/dist/types/src/model/sheet-model.d.ts +6 -5
  134. package/dist/types/src/model/sheet-model.d.ts.map +1 -1
  135. package/dist/types/src/model/sheet-model.test.d.ts +2 -0
  136. package/dist/types/src/model/sheet-model.test.d.ts.map +1 -0
  137. package/dist/types/src/testing/testing.d.ts +4 -5
  138. package/dist/types/src/testing/testing.d.ts.map +1 -1
  139. package/dist/types/src/types.d.ts +17 -31
  140. package/dist/types/src/types.d.ts.map +1 -1
  141. package/package.json +42 -41
  142. package/src/SheetPlugin.tsx +22 -17
  143. package/src/components/FunctionEditor/FunctionEditor.tsx +45 -0
  144. package/src/components/FunctionEditor/index.ts +5 -0
  145. package/src/components/GridSheet/GridSheet.stories.tsx +11 -5
  146. package/src/components/GridSheet/GridSheet.tsx +78 -70
  147. package/src/components/{CellEditor/CellEditor.stories.tsx → GridSheet/SheetCellEditor.stories.tsx} +4 -5
  148. package/src/components/{Sheet → GridSheet}/index.ts +1 -1
  149. package/src/components/GridSheet/util.ts +94 -39
  150. package/src/components/SheetContainer/SheetContainer.stories.tsx +40 -0
  151. package/src/components/SheetContainer/SheetContainer.tsx +52 -0
  152. package/src/components/SheetContainer/index.ts +7 -0
  153. package/src/components/{Sheet/sheet-context.tsx → SheetContext/SheetContext.tsx} +48 -28
  154. package/src/components/SheetContext/index.ts +5 -0
  155. package/src/components/Toolbar/Toolbar.tsx +127 -86
  156. package/src/components/index.ts +2 -1
  157. package/src/defs/types.ts +1 -0
  158. package/src/defs/util.ts +20 -4
  159. package/src/extensions/compute.stories.tsx +23 -23
  160. package/src/extensions/compute.ts +91 -42
  161. package/src/{components/CellEditor → extensions/editor}/extension.test.ts +0 -1
  162. package/src/{components/CellEditor → extensions/editor}/extension.ts +4 -3
  163. package/src/{components/CellEditor → extensions/editor}/index.ts +0 -1
  164. package/src/extensions/index.ts +1 -0
  165. package/src/graph/compute-graph-registry.ts +90 -0
  166. package/src/graph/compute-graph.stories.tsx +4 -3
  167. package/src/graph/compute-graph.test.ts +87 -0
  168. package/src/graph/compute-graph.ts +73 -121
  169. package/src/graph/compute-node.ts +17 -5
  170. package/src/graph/{async-function.ts → functions/async-function.ts} +23 -15
  171. package/src/graph/{edge-function.ts → functions/edge-function.ts} +14 -13
  172. package/src/graph/functions/index.ts +7 -0
  173. package/src/graph/hyperformula.test.ts +1 -2
  174. package/src/graph/index.ts +2 -1
  175. package/src/graph/testing/index.ts +6 -0
  176. package/src/graph/testing/test-builder.ts +54 -0
  177. package/src/graph/{custom-function.ts → testing/test-plugin.ts} +43 -9
  178. package/src/hooks/hooks.stories.tsx +3 -3
  179. package/src/hooks/index.ts +1 -0
  180. package/src/{components/Sheet/threads.tsx → hooks/threads.ts} +26 -84
  181. package/src/hooks/useComputeGraph.ts +9 -1
  182. package/src/hooks/useSheetModel.ts +4 -7
  183. package/src/{meta.tsx → meta.ts} +3 -3
  184. package/src/{components/Sheet → model}/decorations.ts +2 -0
  185. package/src/model/formatting-model.ts +12 -9
  186. package/src/model/index.ts +1 -0
  187. package/src/model/sheet-model.test.ts +57 -0
  188. package/src/model/sheet-model.ts +60 -41
  189. package/src/testing/testing.tsx +17 -15
  190. package/src/types.ts +12 -38
  191. package/dist/lib/browser/SheetContainer-V4GCCZTX.mjs +0 -261
  192. package/dist/lib/browser/SheetContainer-V4GCCZTX.mjs.map +0 -7
  193. package/dist/lib/browser/chunk-6ZMQVB4Z.mjs.map +0 -7
  194. package/dist/lib/browser/chunk-QILRZNE5.mjs.map +0 -7
  195. package/dist/lib/browser/chunk-T3NJFTD4.mjs.map +0 -7
  196. package/dist/lib/browser/chunk-U2JHW3L6.mjs +0 -2552
  197. package/dist/lib/browser/chunk-U2JHW3L6.mjs.map +0 -7
  198. package/dist/lib/browser/graph-T27BOBOV.mjs +0 -21
  199. package/dist/lib/node/SheetContainer-3ZY7MPWJ.cjs +0 -279
  200. package/dist/lib/node/SheetContainer-3ZY7MPWJ.cjs.map +0 -7
  201. package/dist/lib/node/chunk-BNARJ5GM.cjs.map +0 -7
  202. package/dist/lib/node/chunk-DD6FIXWC.cjs.map +0 -7
  203. package/dist/lib/node/chunk-OTTD7FBK.cjs +0 -2536
  204. package/dist/lib/node/chunk-OTTD7FBK.cjs.map +0 -7
  205. package/dist/lib/node/chunk-Q3HBHPRL.cjs.map +0 -7
  206. package/dist/lib/node/graph-SPKGX7W4.cjs +0 -43
  207. package/dist/lib/node/graph-SPKGX7W4.cjs.map +0 -7
  208. package/dist/lib/node-esm/SheetContainer-PXSJX6XK.mjs +0 -262
  209. package/dist/lib/node-esm/SheetContainer-PXSJX6XK.mjs.map +0 -7
  210. package/dist/lib/node-esm/chunk-7HVSOTGA.mjs +0 -2553
  211. package/dist/lib/node-esm/chunk-7HVSOTGA.mjs.map +0 -7
  212. package/dist/lib/node-esm/chunk-BMNA27EX.mjs.map +0 -7
  213. package/dist/lib/node-esm/chunk-D6KU5MI7.mjs.map +0 -7
  214. package/dist/lib/node-esm/chunk-IU2L277A.mjs.map +0 -7
  215. package/dist/lib/node-esm/graph-U67IO4UC.mjs +0 -22
  216. package/dist/types/src/components/CellEditor/CellEditor.d.ts +0 -34
  217. package/dist/types/src/components/CellEditor/CellEditor.d.ts.map +0 -1
  218. package/dist/types/src/components/CellEditor/CellEditor.stories.d.ts.map +0 -1
  219. package/dist/types/src/components/CellEditor/extension.d.ts.map +0 -1
  220. package/dist/types/src/components/CellEditor/extension.test.d.ts.map +0 -1
  221. package/dist/types/src/components/CellEditor/index.d.ts +0 -3
  222. package/dist/types/src/components/CellEditor/index.d.ts.map +0 -1
  223. package/dist/types/src/components/Sheet/Sheet.d.ts +0 -55
  224. package/dist/types/src/components/Sheet/Sheet.d.ts.map +0 -1
  225. package/dist/types/src/components/Sheet/Sheet.stories.d.ts +0 -53
  226. package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +0 -1
  227. package/dist/types/src/components/Sheet/decorations.d.ts.map +0 -1
  228. package/dist/types/src/components/Sheet/grid.d.ts +0 -52
  229. package/dist/types/src/components/Sheet/grid.d.ts.map +0 -1
  230. package/dist/types/src/components/Sheet/index.d.ts +0 -2
  231. package/dist/types/src/components/Sheet/index.d.ts.map +0 -1
  232. package/dist/types/src/components/Sheet/nav.d.ts +0 -29
  233. package/dist/types/src/components/Sheet/nav.d.ts.map +0 -1
  234. package/dist/types/src/components/Sheet/sheet-context.d.ts +0 -26
  235. package/dist/types/src/components/Sheet/sheet-context.d.ts.map +0 -1
  236. package/dist/types/src/components/Sheet/threads.d.ts +0 -2
  237. package/dist/types/src/components/Sheet/threads.d.ts.map +0 -1
  238. package/dist/types/src/components/Sheet/util.d.ts +0 -18
  239. package/dist/types/src/components/Sheet/util.d.ts.map +0 -1
  240. package/dist/types/src/components/SheetContainer.d.ts +0 -8
  241. package/dist/types/src/components/SheetContainer.d.ts.map +0 -1
  242. package/dist/types/src/components/Toolbar/common.d.ts +0 -20
  243. package/dist/types/src/components/Toolbar/common.d.ts.map +0 -1
  244. package/dist/types/src/graph/async-function.d.ts.map +0 -1
  245. package/dist/types/src/graph/compute-graph.browser.test.d.ts +0 -2
  246. package/dist/types/src/graph/compute-graph.browser.test.d.ts.map +0 -1
  247. package/dist/types/src/graph/custom-function.d.ts +0 -21
  248. package/dist/types/src/graph/custom-function.d.ts.map +0 -1
  249. package/dist/types/src/graph/edge-function.d.ts +0 -20
  250. package/dist/types/src/graph/edge-function.d.ts.map +0 -1
  251. package/dist/types/src/graph/function-defs.d.ts.map +0 -1
  252. package/src/components/CellEditor/CellEditor.tsx +0 -163
  253. package/src/components/Sheet/Sheet.stories.tsx +0 -250
  254. package/src/components/Sheet/Sheet.tsx +0 -1199
  255. package/src/components/Sheet/grid.ts +0 -191
  256. package/src/components/Sheet/nav.ts +0 -157
  257. package/src/components/Sheet/util.ts +0 -56
  258. package/src/components/SheetContainer.tsx +0 -88
  259. package/src/components/Toolbar/common.tsx +0 -72
  260. package/src/graph/compute-graph.browser.test.ts +0 -104
  261. /package/dist/lib/browser/{graph-T27BOBOV.mjs.map → graph-M4IQ76QX.mjs.map} +0 -0
  262. /package/dist/lib/node-esm/{graph-U67IO4UC.mjs.map → graph-SMPUMOV2.mjs.map} +0 -0
  263. /package/dist/types/src/{components/CellEditor → extensions/editor}/extension.d.ts +0 -0
  264. /package/dist/types/src/{components/CellEditor → extensions/editor}/extension.test.d.ts +0 -0
  265. /package/dist/types/src/graph/{function-defs.d.ts → functions/function-defs.d.ts} +0 -0
  266. /package/src/graph/{function-defs.ts → functions/function-defs.ts} +0 -0
@@ -2,48 +2,87 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import {
6
- type Icon,
7
- Calendar,
8
- ChatText,
9
- CurrencyDollar,
10
- Eraser,
11
- HighlighterCircle,
12
- TextAlignCenter,
13
- TextAlignLeft,
14
- TextAlignRight,
15
- } from '@phosphor-icons/react';
16
5
  import { createContext } from '@radix-ui/react-context';
17
6
  import React, { type PropsWithChildren } from 'react';
18
7
 
19
8
  import {
20
- DensityProvider,
21
- ElevationProvider,
9
+ Icon,
22
10
  Toolbar as NaturalToolbar,
23
- type ThemedClassName,
24
11
  useTranslation,
12
+ Tooltip,
13
+ type ToolbarToggleGroupItemProps as NaturalToolbarToggleGroupItemProps,
14
+ type ToolbarButtonProps as NaturalToolbarButtonProps,
15
+ type ToolbarToggleProps as NaturalToolbarToggleProps,
16
+ type ThemedClassName,
25
17
  } from '@dxos/react-ui';
18
+ import { useAttention } from '@dxos/react-ui-attention';
26
19
  import { nonNullable } from '@dxos/util';
27
20
 
28
- import { ToolbarButton, ToolbarSeparator, ToolbarToggleButton } from './common';
29
21
  import { addressToIndex } from '../../defs';
30
22
  import { SHEET_PLUGIN } from '../../meta';
31
23
  import { type Formatting } from '../../types';
32
- import { useSheetContext } from '../Sheet/sheet-context';
24
+ import { useSheetContext } from '../SheetContext';
25
+
26
+ //
27
+ // Buttons
28
+ //
29
+
30
+ const buttonStyles = 'min-bs-0 p-2';
31
+ const tooltipProps = { side: 'bottom' as const, classNames: 'z-10' };
32
+
33
+ const ToolbarSeparator = () => <div role='separator' className='grow' />;
34
+
35
+ //
36
+ // ToolbarItem
37
+ //
38
+
39
+ type ToolbarItemProps =
40
+ | (NaturalToolbarButtonProps & { itemType: 'button'; icon: string })
41
+ | (NaturalToolbarToggleGroupItemProps & { itemType: 'toggleGroupItem'; icon: string })
42
+ | (NaturalToolbarToggleProps & { itemType: 'toggle'; icon: string });
43
+
44
+ export const ToolbarItem = ({ itemType, icon, children, ...props }: ToolbarItemProps) => {
45
+ const Invoker =
46
+ itemType === 'toggleGroupItem'
47
+ ? NaturalToolbar.ToggleGroupItem
48
+ : itemType === 'toggle'
49
+ ? NaturalToolbar.Toggle
50
+ : NaturalToolbar.Button;
51
+ return (
52
+ <Tooltip.Root>
53
+ <Tooltip.Trigger asChild>
54
+ {/* TODO(thure): type the props spread better. */}
55
+ <Invoker variant='ghost' {...(props as any)} classNames={buttonStyles}>
56
+ <Icon icon={icon} size={5} />
57
+ <span className='sr-only'>{children}</span>
58
+ </Invoker>
59
+ </Tooltip.Trigger>
60
+ <Tooltip.Portal>
61
+ <Tooltip.Content {...tooltipProps}>
62
+ {children}
63
+ <Tooltip.Arrow />
64
+ </Tooltip.Content>
65
+ </Tooltip.Portal>
66
+ </Tooltip.Root>
67
+ );
68
+ };
33
69
 
34
70
  //
35
71
  // Root
36
72
  //
37
73
 
38
- export type ToolbarAction =
39
- | { type: 'clear' }
40
- | { type: 'highlight' }
41
- | { type: 'left' }
42
- | { type: 'center' }
43
- | { type: 'right' }
44
- | { type: 'date' }
45
- | { type: 'currency' }
46
- | { type: 'comment'; anchor: string; cellContent?: string };
74
+ type AlignValue = 'left' | 'center' | 'right' | 'unset';
75
+ type AlignAction = { type: 'align'; value: AlignValue };
76
+
77
+ type CommentAction = { type: 'comment'; anchor: string; cellContent?: string };
78
+
79
+ type FormatValue = 'date' | 'currency' | 'unset';
80
+ type FormatAction = { type: 'format'; value: FormatValue };
81
+
82
+ type StyleValue = 'highlight' | 'unset';
83
+ type StyleAction = { type: 'style'; value: StyleValue };
84
+
85
+ export type ToolbarAction = StyleAction | AlignAction | FormatAction | CommentAction;
47
86
 
48
87
  export type ToolbarActionType = ToolbarAction['type'];
49
88
 
@@ -52,30 +91,41 @@ export type ToolbarActionHandler = (action: ToolbarAction) => void;
52
91
  export type ToolbarProps = ThemedClassName<
53
92
  PropsWithChildren<{
54
93
  onAction?: ToolbarActionHandler;
94
+ role?: string;
55
95
  }>
56
96
  >;
57
97
 
58
98
  const [ToolbarContextProvider, useToolbarContext] = createContext<ToolbarProps>('Toolbar');
59
99
 
60
- const ToolbarRoot = ({ children, onAction, classNames }: ToolbarProps) => {
100
+ // TODO(Zan): Factor out, copied this from MarkdownPlugin.
101
+ const sectionToolbarLayout =
102
+ 'bs-[--rail-action] bg-[--sticky-bg] sticky block-start-0 __-block-start-px transition-opacity';
103
+
104
+ const ToolbarRoot = ({ children, onAction, role, classNames }: ToolbarProps) => {
105
+ const { id } = useSheetContext();
106
+ const { hasAttention } = useAttention(id);
107
+
61
108
  return (
62
109
  <ToolbarContextProvider onAction={onAction}>
63
- <DensityProvider density='fine'>
64
- <ElevationProvider elevation='chrome'>
65
- <NaturalToolbar.Root classNames={['is-full shrink-0 overflow-x-auto overflow-y-hidden p-1', classNames]}>
66
- {children}
67
- </NaturalToolbar.Root>
68
- </ElevationProvider>
69
- </DensityProvider>
110
+ <NaturalToolbar.Root
111
+ classNames={[
112
+ ...(role === 'section'
113
+ ? ['z-[2] group-focus-within/section:visible', !hasAttention && 'invisible', sectionToolbarLayout]
114
+ : ['attention-surface']),
115
+ classNames,
116
+ ]}
117
+ >
118
+ {children}
119
+ </NaturalToolbar.Root>
70
120
  </ToolbarContextProvider>
71
121
  );
72
122
  };
73
123
 
74
124
  // TODO(burdon): Generalize.
75
125
  // TODO(burdon): Detect and display current state.
76
- type ButtonProps = {
77
- type: ToolbarActionType;
78
- Icon: Icon;
126
+ type ButtonProps<T> = {
127
+ value: T;
128
+ icon: string;
79
129
  getState: (state: Formatting) => boolean;
80
130
  disabled?: (state: Formatting) => boolean;
81
131
  };
@@ -84,9 +134,9 @@ type ButtonProps = {
84
134
  // Alignment
85
135
  //
86
136
 
87
- const formatOptions: ButtonProps[] = [
88
- { type: 'date', Icon: Calendar, getState: (state) => false },
89
- { type: 'currency', Icon: CurrencyDollar, getState: (state) => false },
137
+ const formatOptions: ButtonProps<FormatValue>[] = [
138
+ { value: 'date', icon: 'ph--calendar--regular', getState: (state) => false },
139
+ { value: 'currency', icon: 'ph--currency-dollar--regular', getState: (state) => false },
90
140
  ];
91
141
 
92
142
  const Format = () => {
@@ -98,26 +148,25 @@ const Format = () => {
98
148
  type='single'
99
149
  // value={cellStyles.filter(({ getState }) => state && getState(state)).map(({ type }) => type)}
100
150
  >
101
- {formatOptions.map(({ type, getState, Icon }) => (
102
- <ToolbarToggleButton
103
- key={type}
104
- value={type}
105
- Icon={Icon}
106
- // disabled={state?.blockType === 'codeblock'}
107
- // onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
108
- onClick={() => onAction?.({ type: type as Exclude<typeof type, 'comment'> })}
151
+ {formatOptions.map(({ value, getState, icon }) => (
152
+ <ToolbarItem
153
+ itemType='toggleGroupItem'
154
+ key={value}
155
+ value={value}
156
+ icon={icon}
157
+ onClick={() => onAction?.({ type: 'format', value })}
109
158
  >
110
- {t(`toolbar ${type} label`)}
111
- </ToolbarToggleButton>
159
+ {t(`toolbar ${value} label`)}
160
+ </ToolbarItem>
112
161
  ))}
113
162
  </NaturalToolbar.ToggleGroup>
114
163
  );
115
164
  };
116
165
 
117
- const alignmentOptions: ButtonProps[] = [
118
- { type: 'left', Icon: TextAlignLeft, getState: (state) => false },
119
- { type: 'center', Icon: TextAlignCenter, getState: (state) => false },
120
- { type: 'right', Icon: TextAlignRight, getState: (state) => false },
166
+ const alignmentOptions: ButtonProps<AlignValue>[] = [
167
+ { value: 'left', icon: 'ph--text-align-left--regular', getState: (state) => false },
168
+ { value: 'center', icon: 'ph--text-align-center--regular', getState: (state) => false },
169
+ { value: 'right', icon: 'ph--text-align-right--regular', getState: (state) => false },
121
170
  ];
122
171
 
123
172
  const Alignment = () => {
@@ -128,50 +177,41 @@ const Alignment = () => {
128
177
  <NaturalToolbar.ToggleGroup
129
178
  type='single'
130
179
  // value={cellStyles.filter(({ getState }) => state && getState(state)).map(({ type }) => type)}
180
+ // disabled={state?.blockType === 'codeblock'}
181
+ onValueChange={(value: AlignValue) => onAction?.({ type: 'align', value })}
131
182
  >
132
- {alignmentOptions.map(({ type, getState, Icon }) => (
133
- <ToolbarToggleButton
134
- key={type}
135
- value={type}
136
- Icon={Icon}
137
- // disabled={state?.blockType === 'codeblock'}
138
- // onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
139
- onClick={() => onAction?.({ type: type as Exclude<typeof type, 'comment'> })}
140
- >
141
- {t(`toolbar ${type} label`)}
142
- </ToolbarToggleButton>
183
+ {alignmentOptions.map(({ value, getState, icon }) => (
184
+ <ToolbarItem itemType='toggleGroupItem' key={value} value={value} icon={icon}>
185
+ {t(`toolbar ${value} label`)}
186
+ </ToolbarItem>
143
187
  ))}
144
188
  </NaturalToolbar.ToggleGroup>
145
189
  );
146
190
  };
147
191
 
148
- const styleOptions: ButtonProps[] = [
149
- { type: 'clear', Icon: Eraser, getState: (state) => false },
150
- { type: 'highlight', Icon: HighlighterCircle, getState: (state) => false },
192
+ const styleOptions: ButtonProps<StyleValue>[] = [
193
+ { value: 'highlight', icon: 'ph--highlighter--regular', getState: (state) => false },
151
194
  ];
152
195
 
153
196
  const Styles = () => {
154
- const { onAction } = useToolbarContext('Alignment');
197
+ const { onAction } = useToolbarContext('Styles');
155
198
  const { t } = useTranslation(SHEET_PLUGIN);
156
199
 
157
200
  return (
158
- <NaturalToolbar.ToggleGroup
159
- type='single'
160
- // value={cellStyles.filter(({ getState }) => state && getState(state)).map(({ type }) => type)}
161
- >
162
- {styleOptions.map(({ type, getState, Icon }) => (
163
- <ToolbarToggleButton
164
- key={type}
165
- value={type}
166
- Icon={Icon}
167
- // disabled={state?.blockType === 'codeblock'}
168
- // onClick={state ? () => onAction?.({ type, data: !getState(state) }) : undefined}
169
- onClick={() => onAction?.({ type: type as Exclude<typeof type, 'comment'> })}
201
+ <>
202
+ {styleOptions.map(({ value, getState, icon }) => (
203
+ <ToolbarItem
204
+ itemType='toggle'
205
+ key={value}
206
+ onPressedChange={(nextPressed: boolean) =>
207
+ onAction?.({ type: 'style', value: nextPressed ? 'highlight' : 'unset' })
208
+ }
209
+ icon={icon}
170
210
  >
171
- {t(`toolbar ${type} label`)}
172
- </ToolbarToggleButton>
211
+ {t(`toolbar ${value} label`)}
212
+ </ToolbarItem>
173
213
  ))}
174
- </NaturalToolbar.ToggleGroup>
214
+ </>
175
215
  );
176
216
  };
177
217
 
@@ -206,9 +246,10 @@ const Actions = () => {
206
246
  : 'comment label';
207
247
 
208
248
  return (
209
- <ToolbarButton
249
+ <ToolbarItem
250
+ itemType='button'
210
251
  value='comment'
211
- Icon={ChatText}
252
+ icon='ph--chat-text--regular'
212
253
  data-testid='editor.toolbar.comment'
213
254
  onClick={() => {
214
255
  if (!cursor) {
@@ -223,7 +264,7 @@ const Actions = () => {
223
264
  disabled={!cursorOnly || overlapsCommentAnchor}
224
265
  >
225
266
  {t(tooltipLabelKey)}
226
- </ToolbarButton>
267
+ </ToolbarItem>
227
268
  );
228
269
  };
229
270
 
@@ -5,7 +5,8 @@
5
5
  import React from 'react';
6
6
 
7
7
  export * from './ComputeGraph';
8
- export * from './Sheet';
8
+ export * from './GridSheet';
9
+ export * from './SheetContext';
9
10
 
10
11
  // Lazily load components for content surfaces.
11
12
  export const SheetContainer = React.lazy(() => import('./SheetContainer'));
package/src/defs/types.ts CHANGED
@@ -34,6 +34,7 @@ export const addressToA1Notation = ({ col, row }: CellAddress): string => {
34
34
  return `${columnLetter(col)}${row + 1}`;
35
35
  };
36
36
 
37
+ // TODO(burdon): See simpleCellAddressFromString
37
38
  export const addressFromA1Notation = (ref: string): CellAddress => {
38
39
  const match = ref.match(/([A-Z]+)(\d+)/);
39
40
  invariant(match, `Invalid notation: ${ref}`);
package/src/defs/util.ts CHANGED
@@ -5,7 +5,15 @@
5
5
  import { randomBytes } from '@dxos/crypto';
6
6
  import { create } from '@dxos/echo-schema';
7
7
 
8
- import { type CellAddress, type CellRange, DEFAULT_COLUMNS, DEFAULT_ROWS, MAX_COLUMNS, MAX_ROWS } from './types';
8
+ import {
9
+ addressFromA1Notation,
10
+ type CellAddress,
11
+ type CellRange,
12
+ DEFAULT_COLUMNS,
13
+ DEFAULT_ROWS,
14
+ MAX_COLUMNS,
15
+ MAX_ROWS,
16
+ } from './types';
9
17
  import { type CreateSheetOptions, type SheetSize, SheetType } from '../types';
10
18
 
11
19
  // TODO(burdon): Factor out from dxos/protocols to new common package.
@@ -52,18 +60,26 @@ export const initialize = (
52
60
  }
53
61
  };
54
62
 
55
- export const createSheet = ({ title, ...size }: CreateSheetOptions = {}): SheetType => {
63
+ export const createSheet = ({ name, cells, ...size }: CreateSheetOptions = {}): SheetType => {
56
64
  const sheet = create(SheetType, {
57
- title,
65
+ name,
58
66
  cells: {},
59
67
  rows: [],
60
68
  columns: [],
61
69
  rowMeta: {},
62
70
  columnMeta: {},
63
- formatting: {},
71
+ formatting: [],
64
72
  });
65
73
 
66
74
  initialize(sheet, size);
75
+
76
+ if (cells) {
77
+ Object.entries(cells).forEach(([key, { value }]) => {
78
+ const idx = addressToIndex(sheet, addressFromA1Notation(key));
79
+ sheet.cells[idx] = { value };
80
+ });
81
+ }
82
+
67
83
  return sheet;
68
84
  };
69
85
 
@@ -3,8 +3,9 @@
3
3
  //
4
4
 
5
5
  import '@dxos-theme';
6
- import React, { useEffect, useState } from 'react';
6
+ import React, { useEffect, useMemo } from 'react';
7
7
 
8
+ import { PublicKey } from '@dxos/keys';
8
9
  import { useSpace } from '@dxos/react-client/echo';
9
10
  import { withClientProvider } from '@dxos/react-client/testing';
10
11
  import { useThemeContext } from '@dxos/react-ui';
@@ -13,16 +14,16 @@ import {
13
14
  createMarkdownExtensions,
14
15
  createThemeExtensions,
15
16
  decorateMarkdown,
17
+ documentId,
16
18
  useTextEditor,
17
19
  } from '@dxos/react-ui-editor';
18
20
  import { withTheme, withLayout } from '@dxos/storybook-utils';
19
21
  import { nonNullable } from '@dxos/util';
20
22
 
21
- import { compute } from './compute';
22
- import { Sheet } from '../components';
23
- import { type ComputeNode } from '../graph';
23
+ import { compute, computeGraphFacet } from './compute';
24
+ import { GridSheet, SheetProvider } from '../components';
24
25
  import { useComputeGraph, useSheetModel } from '../hooks';
25
- import { useTestSheet, withGraphDecorator } from '../testing';
26
+ import { useTestSheet, withComputeGraphDecorator } from '../testing';
26
27
  import { SheetType } from '../types';
27
28
 
28
29
  const str = (...lines: string[]) => lines.join('\n');
@@ -34,20 +35,15 @@ type EditorProps = {
34
35
  // TODO(burdon): Implement named expressions.
35
36
  // https://hyperformula.handsontable.com/guide/cell-references.html
36
37
 
37
- const DOC_NAME = 'Test Doc';
38
+ // TODO(burdon): Inline Adobe eCharts.
39
+
38
40
  const SHEET_NAME = 'Test Sheet';
39
41
 
40
42
  const Editor = ({ text }: EditorProps) => {
43
+ const id = useMemo(() => PublicKey.random(), []);
41
44
  const { themeMode } = useThemeContext();
42
45
  const space = useSpace();
43
- const graph = useComputeGraph(space);
44
- const [node, setNode] = useState<ComputeNode>();
45
- // TODO(burdon): Virtualize SheetModel.
46
- useEffect(() => {
47
- if (graph) {
48
- setNode(graph.getOrCreateNode(DOC_NAME));
49
- }
50
- }, [graph]);
46
+ const computeGraph = useComputeGraph(space);
51
47
  const { parentRef, focusAttributes } = useTextEditor(
52
48
  () => ({
53
49
  initialValue: text,
@@ -55,11 +51,13 @@ const Editor = ({ text }: EditorProps) => {
55
51
  createBasicExtensions(),
56
52
  createMarkdownExtensions({ themeMode }),
57
53
  createThemeExtensions({ themeMode, syntaxHighlighting: true }),
58
- node && compute(node),
54
+ documentId.of(id.toHex()),
55
+ computeGraph && computeGraphFacet.of(computeGraph),
56
+ compute(),
59
57
  decorateMarkdown(),
60
58
  ].filter(nonNullable),
61
59
  }),
62
- [node, themeMode],
60
+ [computeGraph, themeMode],
63
61
  );
64
62
 
65
63
  return <div className='w-[40rem] overflow-hidden' ref={parentRef} {...focusAttributes} />;
@@ -68,23 +66,23 @@ const Editor = ({ text }: EditorProps) => {
68
66
  const Grid = () => {
69
67
  const space = useSpace();
70
68
  const graph = useComputeGraph(space);
71
- const sheet = useTestSheet(space, graph, { title: SHEET_NAME });
72
- const model = useSheetModel(space, sheet);
69
+ const sheet = useTestSheet(space, graph, { name: SHEET_NAME });
70
+ const model = useSheetModel(graph, sheet);
73
71
  useEffect(() => {
74
72
  if (model) {
75
73
  model.setValues({ A1: { value: 100 }, A2: { value: 200 }, A3: { value: 300 }, A5: { value: '=SUM(A1:A3)' } });
76
74
  }
77
75
  }, [model]);
78
76
 
79
- if (!space || !sheet) {
77
+ if (!graph || !sheet) {
80
78
  return null;
81
79
  }
82
80
 
83
81
  return (
84
82
  <div className='flex w-[40rem] overflow-hidden'>
85
- <Sheet.Root space={space} sheet={sheet}>
86
- <Sheet.Main classNames='border border-separator' />
87
- </Sheet.Root>
83
+ <SheetProvider graph={graph} sheet={sheet}>
84
+ <GridSheet />
85
+ </SheetProvider>
88
86
  </div>
89
87
  );
90
88
  };
@@ -102,13 +100,14 @@ export default {
102
100
  title: 'plugin-sheet/extensions',
103
101
  decorators: [
104
102
  withClientProvider({ types: [SheetType], createIdentity: true, createSpace: true }),
105
- withGraphDecorator,
103
+ withComputeGraphDecorator(),
106
104
  withTheme,
107
105
  withLayout({ fullscreen: true, classNames: 'justify-center' }),
108
106
  ],
109
107
  parameters: { layout: 'fullscreen' },
110
108
  };
111
109
 
110
+ // TODO(burdon): Inline formulae.
112
111
  export const Default = {
113
112
  render: Editor,
114
113
  args: {
@@ -146,6 +145,7 @@ export const Graph = {
146
145
  `="${SHEET_NAME}"!A5`,
147
146
  '```',
148
147
  '',
148
+ '',
149
149
  ),
150
150
  },
151
151
  };