@dxos/plugin-sheet 0.8.4-main.1da679c → 0.8.4-main.21d9917

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 (245) hide show
  1. package/dist/lib/browser/SheetContainer-ESCXPI7Y.mjs +397 -0
  2. package/dist/lib/browser/SheetContainer-ESCXPI7Y.mjs.map +7 -0
  3. package/dist/lib/browser/anchor-sort-JBRMW6OY.mjs +23 -0
  4. package/dist/lib/browser/anchor-sort-JBRMW6OY.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-2SAGT3BB.mjs +397 -0
  6. package/dist/lib/browser/chunk-2SAGT3BB.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-SSN4HYJL.mjs → chunk-IFLWVS2V.mjs} +9 -9
  8. package/dist/lib/browser/chunk-IFLWVS2V.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-W6N44ONZ.mjs +1470 -0
  10. package/dist/lib/browser/chunk-W6N44ONZ.mjs.map +7 -0
  11. package/dist/lib/browser/compute-graph-registry-DL2PX7TF.mjs +21 -0
  12. package/dist/lib/browser/compute-graph-registry-DL2PX7TF.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +71 -82
  14. package/dist/lib/browser/index.mjs.map +4 -4
  15. package/dist/lib/browser/markdown-BC4KBDUO.mjs +29 -0
  16. package/dist/lib/browser/markdown-BC4KBDUO.mjs.map +7 -0
  17. package/dist/lib/browser/meta.json +1 -1
  18. package/dist/lib/browser/operation-resolver-FJ4UWZUM.mjs +79 -0
  19. package/dist/lib/browser/operation-resolver-FJ4UWZUM.mjs.map +7 -0
  20. package/dist/lib/browser/react-surface-5BXM6TJ3.mjs +51 -0
  21. package/dist/lib/browser/react-surface-5BXM6TJ3.mjs.map +7 -0
  22. package/dist/lib/browser/types/index.mjs +7 -12
  23. package/dist/lib/node-esm/SheetContainer-YVIDJKP4.mjs +398 -0
  24. package/dist/lib/node-esm/SheetContainer-YVIDJKP4.mjs.map +7 -0
  25. package/dist/lib/node-esm/anchor-sort-C3XFPI6S.mjs +24 -0
  26. package/dist/lib/node-esm/anchor-sort-C3XFPI6S.mjs.map +7 -0
  27. package/dist/lib/node-esm/chunk-IMWGSIDG.mjs +398 -0
  28. package/dist/lib/node-esm/chunk-IMWGSIDG.mjs.map +7 -0
  29. package/dist/lib/node-esm/{chunk-IK4O7FUJ.mjs → chunk-PPOYR7DK.mjs} +9 -9
  30. package/dist/lib/node-esm/chunk-PPOYR7DK.mjs.map +7 -0
  31. package/dist/lib/node-esm/chunk-S7RYX7DG.mjs +1471 -0
  32. package/dist/lib/node-esm/chunk-S7RYX7DG.mjs.map +7 -0
  33. package/dist/lib/node-esm/compute-graph-registry-VXH55GDI.mjs +22 -0
  34. package/dist/lib/node-esm/compute-graph-registry-VXH55GDI.mjs.map +7 -0
  35. package/dist/lib/node-esm/index.mjs +71 -82
  36. package/dist/lib/node-esm/index.mjs.map +4 -4
  37. package/dist/lib/node-esm/markdown-6DGZCJRM.mjs +30 -0
  38. package/dist/lib/node-esm/markdown-6DGZCJRM.mjs.map +7 -0
  39. package/dist/lib/node-esm/meta.json +1 -1
  40. package/dist/lib/node-esm/operation-resolver-OGXEUWHA.mjs +80 -0
  41. package/dist/lib/node-esm/operation-resolver-OGXEUWHA.mjs.map +7 -0
  42. package/dist/lib/node-esm/react-surface-RLHC6B77.mjs +52 -0
  43. package/dist/lib/node-esm/react-surface-RLHC6B77.mjs.map +7 -0
  44. package/dist/lib/node-esm/types/index.mjs +7 -12
  45. package/dist/types/src/SheetPlugin.d.ts +2 -1
  46. package/dist/types/src/SheetPlugin.d.ts.map +1 -1
  47. package/dist/types/src/capabilities/anchor-sort/anchor-sort.d.ts +5 -0
  48. package/dist/types/src/capabilities/anchor-sort/anchor-sort.d.ts.map +1 -0
  49. package/dist/types/src/capabilities/anchor-sort/index.d.ts +3 -0
  50. package/dist/types/src/capabilities/anchor-sort/index.d.ts.map +1 -0
  51. package/dist/types/src/capabilities/compute-graph-registry/compute-graph-registry.d.ts +5 -0
  52. package/dist/types/src/capabilities/compute-graph-registry/compute-graph-registry.d.ts.map +1 -0
  53. package/dist/types/src/capabilities/compute-graph-registry/index.d.ts +3 -0
  54. package/dist/types/src/capabilities/compute-graph-registry/index.d.ts.map +1 -0
  55. package/dist/types/src/capabilities/index.d.ts +5 -9
  56. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  57. package/dist/types/src/capabilities/markdown/index.d.ts +3 -0
  58. package/dist/types/src/capabilities/markdown/index.d.ts.map +1 -0
  59. package/dist/types/src/capabilities/markdown/markdown.d.ts +5 -0
  60. package/dist/types/src/capabilities/markdown/markdown.d.ts.map +1 -0
  61. package/dist/types/src/capabilities/operation-resolver/index.d.ts +3 -0
  62. package/dist/types/src/capabilities/operation-resolver/index.d.ts.map +1 -0
  63. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts +5 -0
  64. package/dist/types/src/capabilities/operation-resolver/operation-resolver.d.ts.map +1 -0
  65. package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
  66. package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
  67. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
  68. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
  69. package/dist/types/src/components/ComputeGraph/compute-graph.stories.d.ts +0 -1
  70. package/dist/types/src/components/ComputeGraph/compute-graph.stories.d.ts.map +1 -1
  71. package/dist/types/src/components/GridSheet/GridSheet.d.ts.map +1 -1
  72. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +4 -3
  73. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -1
  74. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts +2 -3
  75. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +1 -1
  76. package/dist/types/src/components/GridSheet/util.d.ts.map +1 -1
  77. package/dist/types/src/components/RangeList/RangeList.d.ts +2 -2
  78. package/dist/types/src/components/RangeList/RangeList.d.ts.map +1 -1
  79. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +5 -6
  80. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -1
  81. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +8 -6
  82. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -1
  83. package/dist/types/src/components/SheetContext/SheetContext.d.ts +2 -2
  84. package/dist/types/src/components/SheetContext/SheetContext.d.ts.map +1 -1
  85. package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts +3 -4
  86. package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts.map +1 -1
  87. package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts +3 -2
  88. package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts.map +1 -1
  89. package/dist/types/src/components/SheetToolbar/align.d.ts +12 -19
  90. package/dist/types/src/components/SheetToolbar/align.d.ts.map +1 -1
  91. package/dist/types/src/components/SheetToolbar/style.d.ts +12 -18
  92. package/dist/types/src/components/SheetToolbar/style.d.ts.map +1 -1
  93. package/dist/types/src/components/SheetToolbar/useToolbarState.d.ts +14 -1
  94. package/dist/types/src/components/SheetToolbar/useToolbarState.d.ts.map +1 -1
  95. package/dist/types/src/components/index.d.ts +1 -1
  96. package/dist/types/src/components/index.d.ts.map +1 -1
  97. package/dist/types/src/extensions/compute.stories.d.ts +2 -3
  98. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -1
  99. package/dist/types/src/extensions/editor/sheet-extension.d.ts.map +1 -1
  100. package/dist/types/src/index.d.ts +1 -1
  101. package/dist/types/src/index.d.ts.map +1 -1
  102. package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -1
  103. package/dist/types/src/meta.d.ts +2 -3
  104. package/dist/types/src/meta.d.ts.map +1 -1
  105. package/dist/types/src/model/sheet-model.d.ts +6 -6
  106. package/dist/types/src/model/sheet-model.d.ts.map +1 -1
  107. package/dist/types/src/model/testing.d.ts +2 -2
  108. package/dist/types/src/model/testing.d.ts.map +1 -1
  109. package/dist/types/src/model/useSheetModel.d.ts +2 -2
  110. package/dist/types/src/model/useSheetModel.d.ts.map +1 -1
  111. package/dist/types/src/serializer.d.ts +2 -2
  112. package/dist/types/src/serializer.d.ts.map +1 -1
  113. package/dist/types/src/testing/data.d.ts +2 -2
  114. package/dist/types/src/testing/data.d.ts.map +1 -1
  115. package/dist/types/src/testing/testing.d.ts +27 -3
  116. package/dist/types/src/testing/testing.d.ts.map +1 -1
  117. package/dist/types/src/translations.d.ts +3 -2
  118. package/dist/types/src/translations.d.ts.map +1 -1
  119. package/dist/types/src/types/Sheet.d.ts +76 -0
  120. package/dist/types/src/types/Sheet.d.ts.map +1 -0
  121. package/dist/types/src/types/capabilities.d.ts +6 -0
  122. package/dist/types/src/types/capabilities.d.ts.map +1 -0
  123. package/dist/types/src/types/index.d.ts +2 -1
  124. package/dist/types/src/types/index.d.ts.map +1 -1
  125. package/dist/types/src/types/sheet-range-types.d.ts +2 -2
  126. package/dist/types/src/types/sheet-range-types.d.ts.map +1 -1
  127. package/dist/types/src/types/types.d.ts +92 -75
  128. package/dist/types/src/types/types.d.ts.map +1 -1
  129. package/dist/types/src/types/util.d.ts +9 -10
  130. package/dist/types/src/types/util.d.ts.map +1 -1
  131. package/dist/types/tsconfig.tsbuildinfo +1 -1
  132. package/package.json +79 -72
  133. package/src/SheetPlugin.tsx +51 -64
  134. package/src/capabilities/anchor-sort/anchor-sort.ts +26 -0
  135. package/src/capabilities/anchor-sort/index.ts +7 -0
  136. package/src/capabilities/compute-graph-registry/compute-graph-registry.ts +27 -0
  137. package/src/capabilities/compute-graph-registry/index.ts +7 -0
  138. package/src/capabilities/index.ts +5 -9
  139. package/src/capabilities/markdown/index.ts +7 -0
  140. package/src/capabilities/markdown/markdown.ts +30 -0
  141. package/src/capabilities/operation-resolver/index.ts +7 -0
  142. package/src/capabilities/operation-resolver/operation-resolver.ts +77 -0
  143. package/src/capabilities/react-surface/index.ts +7 -0
  144. package/src/capabilities/react-surface/react-surface.tsx +43 -0
  145. package/src/components/ComputeGraph/compute-graph.stories.tsx +10 -12
  146. package/src/components/FunctionEditor/FunctionEditor.tsx +2 -2
  147. package/src/components/GridSheet/GridSheet.stories.tsx +14 -11
  148. package/src/components/GridSheet/GridSheet.tsx +32 -25
  149. package/src/components/GridSheet/SheetCellEditor.stories.tsx +14 -12
  150. package/src/components/GridSheet/util.ts +11 -5
  151. package/src/components/RangeList/RangeList.tsx +13 -10
  152. package/src/components/SheetContainer/SheetContainer.stories.tsx +68 -47
  153. package/src/components/SheetContainer/SheetContainer.tsx +30 -18
  154. package/src/components/SheetContext/SheetContext.tsx +8 -8
  155. package/src/components/SheetToolbar/SheetToolbar.stories.tsx +9 -6
  156. package/src/components/SheetToolbar/SheetToolbar.tsx +39 -30
  157. package/src/components/SheetToolbar/align.ts +44 -19
  158. package/src/components/SheetToolbar/style.ts +47 -17
  159. package/src/components/SheetToolbar/useToolbarState.ts +22 -5
  160. package/src/extensions/compute.stories.tsx +29 -17
  161. package/src/extensions/compute.ts +1 -1
  162. package/src/extensions/editor/sheet-extension.ts +7 -4
  163. package/src/index.ts +1 -1
  164. package/src/integrations/thread-ranges.ts +40 -49
  165. package/src/meta.ts +9 -7
  166. package/src/model/sheet-model.test.ts +4 -4
  167. package/src/model/sheet-model.ts +78 -48
  168. package/src/model/testing.ts +4 -4
  169. package/src/model/useSheetModel.ts +2 -2
  170. package/src/playwright/playwright.config.ts +1 -1
  171. package/src/playwright/sheet.spec.ts +1 -0
  172. package/src/sanity.test.ts +3 -4
  173. package/src/serializer.ts +4 -4
  174. package/src/testing/data.ts +2 -2
  175. package/src/testing/testing.tsx +11 -5
  176. package/src/translations.ts +3 -2
  177. package/src/types/Sheet.ts +106 -0
  178. package/src/types/capabilities.ts +14 -0
  179. package/src/types/index.ts +2 -1
  180. package/src/types/sheet-range-types.ts +2 -2
  181. package/src/types/types.ts +83 -49
  182. package/src/types/util.ts +10 -38
  183. package/dist/lib/browser/SheetContainer-OUN6AARA.mjs +0 -350
  184. package/dist/lib/browser/SheetContainer-OUN6AARA.mjs.map +0 -7
  185. package/dist/lib/browser/anchor-sort-CAYLDDRF.mjs +0 -24
  186. package/dist/lib/browser/anchor-sort-CAYLDDRF.mjs.map +0 -7
  187. package/dist/lib/browser/chunk-6AKBCBL4.mjs +0 -18
  188. package/dist/lib/browser/chunk-6AKBCBL4.mjs.map +0 -7
  189. package/dist/lib/browser/chunk-KJWZUQVA.mjs +0 -15
  190. package/dist/lib/browser/chunk-KJWZUQVA.mjs.map +0 -7
  191. package/dist/lib/browser/chunk-SSN4HYJL.mjs.map +0 -7
  192. package/dist/lib/browser/chunk-X4EWLDT3.mjs +0 -851
  193. package/dist/lib/browser/chunk-X4EWLDT3.mjs.map +0 -7
  194. package/dist/lib/browser/chunk-XSXUU6FO.mjs +0 -906
  195. package/dist/lib/browser/chunk-XSXUU6FO.mjs.map +0 -7
  196. package/dist/lib/browser/compute-graph-registry-WHF3BJTJ.mjs +0 -30
  197. package/dist/lib/browser/compute-graph-registry-WHF3BJTJ.mjs.map +0 -7
  198. package/dist/lib/browser/intent-resolver-LKZXAJRJ.mjs +0 -56
  199. package/dist/lib/browser/intent-resolver-LKZXAJRJ.mjs.map +0 -7
  200. package/dist/lib/browser/markdown-XKFA4Z2M.mjs +0 -26
  201. package/dist/lib/browser/markdown-XKFA4Z2M.mjs.map +0 -7
  202. package/dist/lib/browser/react-surface-N6NYHHT3.mjs +0 -53
  203. package/dist/lib/browser/react-surface-N6NYHHT3.mjs.map +0 -7
  204. package/dist/lib/node-esm/SheetContainer-NFLLTGNV.mjs +0 -351
  205. package/dist/lib/node-esm/SheetContainer-NFLLTGNV.mjs.map +0 -7
  206. package/dist/lib/node-esm/anchor-sort-4R2ID6GE.mjs +0 -25
  207. package/dist/lib/node-esm/anchor-sort-4R2ID6GE.mjs.map +0 -7
  208. package/dist/lib/node-esm/chunk-3K5VNYOF.mjs +0 -20
  209. package/dist/lib/node-esm/chunk-3K5VNYOF.mjs.map +0 -7
  210. package/dist/lib/node-esm/chunk-6SK5LJ5S.mjs +0 -16
  211. package/dist/lib/node-esm/chunk-6SK5LJ5S.mjs.map +0 -7
  212. package/dist/lib/node-esm/chunk-IK4O7FUJ.mjs.map +0 -7
  213. package/dist/lib/node-esm/chunk-ODP4L4OV.mjs +0 -907
  214. package/dist/lib/node-esm/chunk-ODP4L4OV.mjs.map +0 -7
  215. package/dist/lib/node-esm/chunk-PYF4ZJXN.mjs +0 -852
  216. package/dist/lib/node-esm/chunk-PYF4ZJXN.mjs.map +0 -7
  217. package/dist/lib/node-esm/compute-graph-registry-3IUZXRXJ.mjs +0 -31
  218. package/dist/lib/node-esm/compute-graph-registry-3IUZXRXJ.mjs.map +0 -7
  219. package/dist/lib/node-esm/intent-resolver-JHH6ZVJ4.mjs +0 -57
  220. package/dist/lib/node-esm/intent-resolver-JHH6ZVJ4.mjs.map +0 -7
  221. package/dist/lib/node-esm/markdown-NOKROLCG.mjs +0 -27
  222. package/dist/lib/node-esm/markdown-NOKROLCG.mjs.map +0 -7
  223. package/dist/lib/node-esm/react-surface-TYBS4DOF.mjs +0 -54
  224. package/dist/lib/node-esm/react-surface-TYBS4DOF.mjs.map +0 -7
  225. package/dist/types/src/capabilities/anchor-sort.d.ts +0 -6
  226. package/dist/types/src/capabilities/anchor-sort.d.ts.map +0 -1
  227. package/dist/types/src/capabilities/capabilities.d.ts +0 -5
  228. package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
  229. package/dist/types/src/capabilities/compute-graph-registry.d.ts +0 -4
  230. package/dist/types/src/capabilities/compute-graph-registry.d.ts.map +0 -1
  231. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  232. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  233. package/dist/types/src/capabilities/markdown.d.ts +0 -4
  234. package/dist/types/src/capabilities/markdown.d.ts.map +0 -1
  235. package/dist/types/src/capabilities/react-surface.d.ts +0 -4
  236. package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
  237. package/dist/types/src/types/schema.d.ts +0 -37
  238. package/dist/types/src/types/schema.d.ts.map +0 -1
  239. package/src/capabilities/anchor-sort.ts +0 -22
  240. package/src/capabilities/capabilities.ts +0 -14
  241. package/src/capabilities/compute-graph-registry.ts +0 -28
  242. package/src/capabilities/intent-resolver.ts +0 -38
  243. package/src/capabilities/markdown.ts +0 -23
  244. package/src/capabilities/react-surface.tsx +0 -40
  245. package/src/types/schema.ts +0 -61
@@ -0,0 +1,106 @@
1
+ //
2
+ // Copyright 2023 DXOS.org
3
+ //
4
+
5
+ import * as Schema from 'effect/Schema';
6
+
7
+ import { addressFromA1Notation, isFormula } from '@dxos/compute';
8
+ import { Obj, Type } from '@dxos/echo';
9
+ import { FormInputAnnotation } from '@dxos/echo/internal';
10
+
11
+ import { addressToIndex, initialize, mapFormulaRefsToIndices } from './util';
12
+
13
+ export type SheetSize = {
14
+ rows: number;
15
+ columns: number;
16
+ };
17
+
18
+ export const CellValue = Schema.Struct({
19
+ // TODO(burdon): How to store dates (datetime, date, time), percentages, etc.
20
+ // Consider import/export; natural access for other plugins. Special handling for currency (precision).
21
+ // TODO(burdon): Automerge (long string) or short string or number.
22
+ value: Schema.Any,
23
+ });
24
+
25
+ export type CellValue = Schema.Schema.Type<typeof CellValue>;
26
+
27
+ // TODO(burdon): IMPORTANT: Reconcile with Field definition.
28
+ export const Range = Schema.Struct({
29
+ range: Schema.String,
30
+ key: Schema.String,
31
+ value: Schema.String,
32
+ });
33
+
34
+ export type Range = Schema.Schema.Type<typeof Range>;
35
+
36
+ // TODO(burdon): Visibility, locked, frozen, etc.
37
+ export const RowColumnMeta = Schema.Struct({
38
+ size: Schema.optional(Schema.Number),
39
+ });
40
+
41
+ // TODO(burdon): Reconcile col/column (across packages).
42
+ // TODO(burdon): Index to all updates when rows/columns are inserted/deleted.
43
+ export const Sheet = Schema.Struct({
44
+ name: Schema.optional(Schema.String),
45
+
46
+ // Sparse map of cells referenced by index.
47
+ cells: Schema.Record({ key: Schema.String, value: Schema.mutable(CellValue) }).pipe(
48
+ Schema.mutable,
49
+ FormInputAnnotation.set(false),
50
+ ),
51
+
52
+ // Ordered row indices.
53
+ rows: Schema.Array(Schema.String).pipe(Schema.mutable, FormInputAnnotation.set(false)),
54
+
55
+ // Ordered column indices.
56
+ columns: Schema.Array(Schema.String).pipe(Schema.mutable, FormInputAnnotation.set(false)),
57
+
58
+ // Row metadata referenced by index.
59
+ rowMeta: Schema.Record({ key: Schema.String, value: Schema.mutable(RowColumnMeta) }).pipe(
60
+ Schema.mutable,
61
+ FormInputAnnotation.set(false),
62
+ ),
63
+
64
+ // Column metadata referenced by index.
65
+ columnMeta: Schema.Record({ key: Schema.String, value: Schema.mutable(RowColumnMeta) }).pipe(
66
+ Schema.mutable,
67
+ FormInputAnnotation.set(false),
68
+ ),
69
+
70
+ // Cell formatting referenced by indexed range.
71
+ ranges: Schema.Array(Range).pipe(Schema.mutable, FormInputAnnotation.set(false)),
72
+ }).pipe(
73
+ Type.object({
74
+ typename: 'dxos.org/type/Sheet',
75
+ version: '0.1.0',
76
+ }),
77
+ );
78
+
79
+ export interface Sheet extends Schema.Schema.Type<typeof Sheet> {}
80
+
81
+ export type SheetProps = {
82
+ name?: string;
83
+ cells?: Record<string, CellValue>;
84
+ } & Partial<SheetSize>;
85
+
86
+ export const make = ({ name, cells = {}, ...size }: SheetProps = {}) => {
87
+ const sheet = Obj.make(Sheet, { name, cells: {}, rows: [], columns: [], rowMeta: {}, columnMeta: {}, ranges: [] });
88
+
89
+ // Initialize and set cells within Obj.change to satisfy change context requirements.
90
+ Obj.change(sheet, () => {
91
+ initialize(sheet, size);
92
+
93
+ if (cells) {
94
+ Object.entries(cells).forEach(([key, { value }]) => {
95
+ const idx = addressToIndex(sheet, addressFromA1Notation(key));
96
+ if (isFormula(value)) {
97
+ value = mapFormulaRefsToIndices(sheet, value);
98
+ }
99
+
100
+ sheet.cells[idx] = { value };
101
+ });
102
+ }
103
+ });
104
+
105
+ return sheet;
106
+ };
@@ -0,0 +1,14 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { Capability } from '@dxos/app-framework';
6
+ import { type ComputeGraphRegistry } from '@dxos/compute';
7
+
8
+ import { meta } from '../meta';
9
+
10
+ export namespace SheetCapabilities {
11
+ export const ComputeGraphRegistry = Capability.make<ComputeGraphRegistry>(
12
+ `${meta.id}/capability/compute-graph-registry`,
13
+ );
14
+ }
@@ -2,7 +2,8 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- export * from './schema';
5
+ export * from './capabilities';
6
+ export * as Sheet from './Sheet';
6
7
  export * from './sheet-range-types';
7
8
  export * from './types';
8
9
  export * from './util';
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { type ClassNameValue } from '@dxos/react-ui';
6
6
 
7
- import { type SheetType } from '../types';
7
+ import { type Sheet } from '../types';
8
8
 
9
9
  export const alignKey = 'alignment';
10
10
  export type AlignKey = typeof alignKey;
@@ -19,7 +19,7 @@ export type StyleKey = typeof styleKey;
19
19
  export type StyleValue = 'highlight' | 'softwrap';
20
20
 
21
21
  // TODO(burdon): Reconcile with plugin-table.
22
- export const cellClassNameForRange = ({ key, value }: SheetType['ranges'][number]): ClassNameValue => {
22
+ export const cellClassNameForRange = ({ key, value }: Sheet.Sheet['ranges'][number]): ClassNameValue => {
23
23
  switch (key) {
24
24
  case alignKey:
25
25
  switch (value) {
@@ -2,67 +2,101 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
5
+ import * as Schema from 'effect/Schema';
6
6
 
7
- import { SHEET_PLUGIN } from '../meta';
8
- import { SheetModel } from '../model';
7
+ import { Capability } from '@dxos/app-framework';
8
+ import { Operation } from '@dxos/operation';
9
+ import { SpaceSchema } from '@dxos/react-client/echo';
10
+ import { Collection } from '@dxos/schema';
9
11
 
10
- import { type CellValue, RowColumnMeta, SheetType } from './schema';
12
+ import { meta } from '../meta';
11
13
 
12
- export type SheetSize = {
13
- rows: number;
14
- columns: number;
15
- };
14
+ import * as Sheet from './Sheet';
16
15
 
17
- export type CreateSheetOptions = {
18
- name?: string;
19
- cells?: Record<string, CellValue>;
20
- } & Partial<SheetSize>;
16
+ // TODO(wittjosiah): Factor out. This is `DxGridAxis` from `@dxos/react-ui-grid`.
17
+ const ActionAxis = Schema.Union(Schema.Literal('row'), Schema.Literal('col'));
21
18
 
22
19
  export namespace SheetAction {
23
- const SHEET_ACTION = `${SHEET_PLUGIN}/action`;
24
-
25
- export class Create extends Schema.TaggedClass<Create>()(`${SHEET_ACTION}/create`, {
26
- input: Schema.Struct({
27
- name: Schema.optional(Schema.String),
28
- }),
29
- output: Schema.Struct({
30
- object: SheetType,
31
- }),
32
- }) {}
33
-
34
- // TODO(wittjosiah): Factor out. This is `DxGridAxis` from `@dxos/react-ui-grid`.
35
- const Axis = Schema.Union(Schema.Literal('row'), Schema.Literal('col'));
36
-
37
- export class InsertAxis extends Schema.TaggedClass<InsertAxis>()(`${SHEET_ACTION}/axis-insert`, {
38
- input: Schema.Struct({
39
- // TODO(wittjosiah): Schema.instanceOf(SheetModel) throws when running tests.
40
- model: Schema.Any.pipe(Schema.filter((model) => model instanceof SheetModel)) as Schema.Schema<SheetModel>,
41
- axis: Axis,
42
- index: Schema.Number,
43
- count: Schema.optional(Schema.Number),
44
- }),
45
- output: Schema.Void,
46
- }) {}
47
-
48
20
  export const RestoreAxis = Schema.Struct({
49
- axis: Axis,
21
+ axis: ActionAxis,
50
22
  axisIndex: Schema.String,
51
23
  index: Schema.Number,
52
- axisMeta: RowColumnMeta,
24
+ axisMeta: Sheet.RowColumnMeta,
53
25
  values: Schema.Array(Schema.Any),
54
26
  });
55
27
 
56
28
  export type RestoreAxis = Schema.Schema.Type<typeof RestoreAxis>;
29
+ }
30
+
31
+ const SHEET_OPERATION = `${meta.id}/operation`;
32
+
33
+ // TODO(wittjosiah): Factor out. This is `DxGridAxis` from `@dxos/react-ui-grid`.
34
+ const Axis = Schema.Union(Schema.Literal('row'), Schema.Literal('col'));
35
+
36
+ export namespace SheetOperation {
37
+ export const OnCreateSpace = Operation.make({
38
+ meta: { key: `${SHEET_OPERATION}/on-create-space`, name: 'On Create Space' },
39
+ services: [Capability.Service],
40
+ schema: {
41
+ input: Schema.Struct({
42
+ space: SpaceSchema,
43
+ rootCollection: Collection.Collection,
44
+ isDefault: Schema.optional(Schema.Boolean),
45
+ }),
46
+ output: Schema.Void,
47
+ },
48
+ });
57
49
 
58
- export class DropAxis extends Schema.TaggedClass<DropAxis>()(`${SHEET_ACTION}/axis-drop`, {
59
- input: Schema.Struct({
60
- // TODO(wittjosiah): Schema.instanceOf(SheetModel) throws when running tests.
61
- model: Schema.Any.pipe(Schema.filter((model) => model instanceof SheetModel)) as Schema.Schema<SheetModel>,
62
- axis: Axis,
63
- axisIndex: Schema.String,
64
- deletionData: Schema.optional(RestoreAxis),
65
- }),
66
- output: Schema.Void,
67
- }) {}
50
+ export const InsertAxis = Operation.make({
51
+ meta: { key: `${SHEET_OPERATION}/axis-insert`, name: 'Insert Axis' },
52
+ schema: {
53
+ input: Schema.Struct({
54
+ model: Schema.Any,
55
+ axis: Axis,
56
+ index: Schema.Number,
57
+ count: Schema.optional(Schema.Number),
58
+ }),
59
+ output: Schema.Void,
60
+ },
61
+ });
62
+
63
+ export const DropAxisOutput = Schema.Struct({
64
+ axis: Axis.annotations({ description: 'The axis type (row or col).' }),
65
+ axisIndex: Schema.String.annotations({ description: 'The dropped axis index.' }),
66
+ index: Schema.Number.annotations({ description: 'The position the axis was at.' }),
67
+ axisMeta: Schema.Any.annotations({ description: 'The row/column metadata.' }),
68
+ values: Schema.Array(Schema.Any).annotations({ description: 'The cell values that were dropped.' }),
69
+ });
70
+
71
+ export type DropAxisOutput = Schema.Schema.Type<typeof DropAxisOutput>;
72
+
73
+ export const DropAxis = Operation.make({
74
+ meta: { key: `${SHEET_OPERATION}/axis-drop`, name: 'Drop Axis' },
75
+ schema: {
76
+ input: Schema.Struct({
77
+ model: Schema.Any,
78
+ axis: Axis,
79
+ axisIndex: Schema.String,
80
+ }),
81
+ output: DropAxisOutput,
82
+ },
83
+ });
84
+
85
+ /**
86
+ * Restore a dropped axis (inverse of DropAxis).
87
+ */
88
+ export const RestoreAxis = Operation.make({
89
+ meta: { key: `${SHEET_OPERATION}/restore-axis`, name: 'Restore Axis' },
90
+ schema: {
91
+ input: Schema.Struct({
92
+ model: Schema.Any.annotations({ description: 'The sheet model.' }),
93
+ axis: Axis.annotations({ description: 'The axis type (row or col).' }),
94
+ axisIndex: Schema.String.annotations({ description: 'The axis index to restore.' }),
95
+ index: Schema.Number.annotations({ description: 'The position to restore at.' }),
96
+ axisMeta: Schema.Any.annotations({ description: 'The row/column metadata.' }),
97
+ values: Schema.Array(Schema.Any).annotations({ description: 'The cell values to restore.' }),
98
+ }),
99
+ output: Schema.Void,
100
+ },
101
+ });
68
102
  }
package/src/types/util.ts CHANGED
@@ -11,10 +11,9 @@ import {
11
11
  isFormula,
12
12
  } from '@dxos/compute';
13
13
  import { randomBytes } from '@dxos/crypto';
14
- import { Obj } from '@dxos/echo';
15
14
  import { invariant } from '@dxos/invariant';
16
15
 
17
- import { type CreateSheetOptions, type SheetSize, SheetType } from '../types';
16
+ import { type Sheet } from '../types';
18
17
 
19
18
  export const MAX_ROWS = 500;
20
19
  export const MAX_COLS = 676; // 26^2;
@@ -56,8 +55,8 @@ export const insertIndices = (indices: string[], i: number, n: number, max: numb
56
55
  };
57
56
 
58
57
  export const initialize = (
59
- sheet: SheetType,
60
- { rows = DEFAULT_ROWS, columns = DEFAULT_COLS }: Partial<SheetSize> = {},
58
+ sheet: Sheet.Sheet,
59
+ { rows = DEFAULT_ROWS, columns = DEFAULT_COLS }: Partial<Sheet.SheetSize> = {},
61
60
  ) => {
62
61
  if (!sheet.rows.length) {
63
62
  insertIndices(sheet.rows, 0, rows, MAX_ROWS);
@@ -67,44 +66,17 @@ export const initialize = (
67
66
  }
68
67
  };
69
68
 
70
- export const createSheet = ({ name, cells, ...size }: CreateSheetOptions = {}): SheetType => {
71
- const sheet = Obj.make(SheetType, {
72
- name,
73
- cells: {},
74
- rows: [],
75
- columns: [],
76
- rowMeta: {},
77
- columnMeta: {},
78
- ranges: [],
79
- });
80
-
81
- initialize(sheet, size);
82
-
83
- if (cells) {
84
- Object.entries(cells).forEach(([key, { value }]) => {
85
- const idx = addressToIndex(sheet, addressFromA1Notation(key));
86
- if (isFormula(value)) {
87
- value = mapFormulaRefsToIndices(sheet, value);
88
- }
89
-
90
- sheet.cells[idx] = { value };
91
- });
92
- }
93
-
94
- return sheet;
95
- };
96
-
97
69
  /**
98
70
  * E.g., "A1" => "CA2@CB3".
99
71
  */
100
- export const addressToIndex = (sheet: SheetType, cell: CellAddress): string => {
72
+ export const addressToIndex = (sheet: Sheet.Sheet, cell: CellAddress): string => {
101
73
  return `${sheet.columns[cell.col]}@${sheet.rows[cell.row]}`;
102
74
  };
103
75
 
104
76
  /**
105
77
  * E.g., "CA2@CB3" => "A1".
106
78
  */
107
- export const addressFromIndex = (sheet: SheetType, idx: string): CellAddress => {
79
+ export const addressFromIndex = (sheet: Sheet.Sheet, idx: string): CellAddress => {
108
80
  const [column, row] = idx.split('@');
109
81
  return {
110
82
  col: sheet.columns.indexOf(column),
@@ -115,14 +87,14 @@ export const addressFromIndex = (sheet: SheetType, idx: string): CellAddress =>
115
87
  /**
116
88
  * E.g., "A1:B2" => "CA2@CB3:CC4@CD5".
117
89
  */
118
- export const rangeToIndex = (sheet: SheetType, range: CellRange): string => {
90
+ export const rangeToIndex = (sheet: Sheet.Sheet, range: CellRange): string => {
119
91
  return [range.from, range.to ?? range.from].map((cell) => addressToIndex(sheet, cell)).join(':');
120
92
  };
121
93
 
122
94
  /**
123
95
  * E.g., "CA2@CB3:CC4@CD5" => "A1:B2".
124
96
  */
125
- export const rangeFromIndex = (sheet: SheetType, idx: string): CompleteCellRange => {
97
+ export const rangeFromIndex = (sheet: Sheet.Sheet, idx: string): CompleteCellRange => {
126
98
  const [from, to] = idx.split(':').map((index) => addressFromIndex(sheet, index));
127
99
  return { from, to };
128
100
  };
@@ -131,7 +103,7 @@ export const rangeFromIndex = (sheet: SheetType, idx: string): CompleteCellRange
131
103
  * Compares the positions of two cell indexes in a sheet.
132
104
  * Sorts primarily by row, then by column if rows are equal.
133
105
  */
134
- export const compareIndexPositions = (sheet: SheetType, indexA: string, indexB: string): number => {
106
+ export const compareIndexPositions = (sheet: Sheet.Sheet, indexA: string, indexB: string): number => {
135
107
  const { row: rowA, col: columnA } = addressFromIndex(sheet, indexA);
136
108
  const { row: rowB, col: columnB } = addressFromIndex(sheet, indexB);
137
109
 
@@ -148,7 +120,7 @@ export const compareIndexPositions = (sheet: SheetType, indexA: string, indexB:
148
120
  /**
149
121
  * Map from A1 notation to indices.
150
122
  */
151
- export const mapFormulaRefsToIndices = (sheet: SheetType, formula: string): string => {
123
+ export const mapFormulaRefsToIndices = (sheet: Sheet.Sheet, formula: string): string => {
152
124
  invariant(isFormula(formula));
153
125
  return formula.replace(/([a-zA-Z]+)([0-9]+)/g, (match) => {
154
126
  return addressToIndex(sheet, addressFromA1Notation(match));
@@ -158,7 +130,7 @@ export const mapFormulaRefsToIndices = (sheet: SheetType, formula: string): stri
158
130
  /**
159
131
  * Map from indices to A1 notation.
160
132
  */
161
- export const mapFormulaIndicesToRefs = (sheet: SheetType, formula: string): string => {
133
+ export const mapFormulaIndicesToRefs = (sheet: Sheet.Sheet, formula: string): string => {
162
134
  invariant(isFormula(formula));
163
135
  return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
164
136
  return addressToA1Notation(addressFromIndex(sheet, idx));