@dxos/plugin-sheet 0.8.4-main.72ec0f3 → 0.8.4-main.937b3ca

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 (208) 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-FCQ5OZZK.mjs → anchor-sort-JBRMW6OY.mjs} +7 -7
  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-7VEWYJJN.mjs → chunk-IFLWVS2V.mjs} +5 -5
  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 +68 -78
  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-5GYLVSMR.mjs → react-surface-5BXM6TJ3.mjs} +16 -19
  21. package/dist/lib/browser/react-surface-5BXM6TJ3.mjs.map +7 -0
  22. package/dist/lib/browser/types/index.mjs +5 -2
  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-ZE7IS7SH.mjs → anchor-sort-C3XFPI6S.mjs} +7 -7
  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-4QV4AGWK.mjs → chunk-PPOYR7DK.mjs} +5 -5
  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 +68 -78
  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-RK32YZWR.mjs → react-surface-RLHC6B77.mjs} +16 -19
  43. package/dist/lib/node-esm/react-surface-RLHC6B77.mjs.map +7 -0
  44. package/dist/lib/node-esm/types/index.mjs +5 -2
  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 -6
  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/GridSheet/GridSheet.d.ts.map +1 -1
  70. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts +1 -0
  71. package/dist/types/src/components/GridSheet/GridSheet.stories.d.ts.map +1 -1
  72. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts +1 -1
  73. package/dist/types/src/components/GridSheet/SheetCellEditor.stories.d.ts.map +1 -1
  74. package/dist/types/src/components/RangeList/RangeList.d.ts.map +1 -1
  75. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts +4 -5
  76. package/dist/types/src/components/SheetContainer/SheetContainer.d.ts.map +1 -1
  77. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts +3 -1
  78. package/dist/types/src/components/SheetContainer/SheetContainer.stories.d.ts.map +1 -1
  79. package/dist/types/src/components/SheetToolbar/SheetToolbar.d.ts.map +1 -1
  80. package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts +2 -0
  81. package/dist/types/src/components/SheetToolbar/SheetToolbar.stories.d.ts.map +1 -1
  82. package/dist/types/src/components/SheetToolbar/align.d.ts +12 -19
  83. package/dist/types/src/components/SheetToolbar/align.d.ts.map +1 -1
  84. package/dist/types/src/components/SheetToolbar/style.d.ts +12 -18
  85. package/dist/types/src/components/SheetToolbar/style.d.ts.map +1 -1
  86. package/dist/types/src/components/SheetToolbar/useToolbarState.d.ts +14 -1
  87. package/dist/types/src/components/SheetToolbar/useToolbarState.d.ts.map +1 -1
  88. package/dist/types/src/components/index.d.ts +1 -1
  89. package/dist/types/src/components/index.d.ts.map +1 -1
  90. package/dist/types/src/extensions/compute.stories.d.ts.map +1 -1
  91. package/dist/types/src/extensions/editor/sheet-extension.d.ts.map +1 -1
  92. package/dist/types/src/index.d.ts +1 -1
  93. package/dist/types/src/index.d.ts.map +1 -1
  94. package/dist/types/src/integrations/thread-ranges.d.ts.map +1 -1
  95. package/dist/types/src/meta.d.ts +2 -2
  96. package/dist/types/src/meta.d.ts.map +1 -1
  97. package/dist/types/src/model/sheet-model.d.ts +2 -2
  98. package/dist/types/src/model/sheet-model.d.ts.map +1 -1
  99. package/dist/types/src/serializer.d.ts.map +1 -1
  100. package/dist/types/src/testing/testing.d.ts +8 -8
  101. package/dist/types/src/translations.d.ts +1 -0
  102. package/dist/types/src/translations.d.ts.map +1 -1
  103. package/dist/types/src/types/Sheet.d.ts +34 -28
  104. package/dist/types/src/types/Sheet.d.ts.map +1 -1
  105. package/dist/types/src/types/capabilities.d.ts +6 -0
  106. package/dist/types/src/types/capabilities.d.ts.map +1 -0
  107. package/dist/types/src/types/index.d.ts +1 -0
  108. package/dist/types/src/types/index.d.ts.map +1 -1
  109. package/dist/types/src/types/types.d.ts +91 -65
  110. package/dist/types/src/types/types.d.ts.map +1 -1
  111. package/dist/types/tsconfig.tsbuildinfo +1 -1
  112. package/package.json +75 -69
  113. package/src/SheetPlugin.tsx +40 -62
  114. package/src/capabilities/anchor-sort/anchor-sort.ts +26 -0
  115. package/src/capabilities/anchor-sort/index.ts +7 -0
  116. package/src/capabilities/compute-graph-registry/compute-graph-registry.ts +27 -0
  117. package/src/capabilities/compute-graph-registry/index.ts +7 -0
  118. package/src/capabilities/index.ts +5 -9
  119. package/src/capabilities/markdown/index.ts +7 -0
  120. package/src/capabilities/markdown/markdown.ts +30 -0
  121. package/src/capabilities/operation-resolver/index.ts +7 -0
  122. package/src/capabilities/operation-resolver/operation-resolver.ts +77 -0
  123. package/src/capabilities/react-surface/index.ts +7 -0
  124. package/src/capabilities/react-surface/react-surface.tsx +43 -0
  125. package/src/components/ComputeGraph/compute-graph.stories.tsx +1 -1
  126. package/src/components/GridSheet/GridSheet.stories.tsx +2 -2
  127. package/src/components/GridSheet/GridSheet.tsx +14 -19
  128. package/src/components/GridSheet/SheetCellEditor.stories.tsx +7 -4
  129. package/src/components/GridSheet/util.ts +2 -2
  130. package/src/components/RangeList/RangeList.tsx +5 -2
  131. package/src/components/SheetContainer/SheetContainer.stories.tsx +41 -21
  132. package/src/components/SheetContainer/SheetContainer.tsx +27 -20
  133. package/src/components/SheetContext/SheetContext.tsx +4 -4
  134. package/src/components/SheetToolbar/SheetToolbar.tsx +29 -18
  135. package/src/components/SheetToolbar/align.ts +41 -16
  136. package/src/components/SheetToolbar/style.ts +45 -15
  137. package/src/components/SheetToolbar/useToolbarState.ts +22 -5
  138. package/src/extensions/compute.stories.tsx +15 -6
  139. package/src/extensions/compute.ts +1 -1
  140. package/src/extensions/editor/sheet-extension.ts +7 -4
  141. package/src/index.ts +1 -1
  142. package/src/integrations/thread-ranges.ts +37 -41
  143. package/src/meta.ts +2 -2
  144. package/src/model/sheet-model.ts +75 -45
  145. package/src/playwright/playwright.config.ts +1 -1
  146. package/src/playwright/sheet.spec.ts +1 -0
  147. package/src/sanity.test.ts +1 -1
  148. package/src/serializer.ts +1 -1
  149. package/src/translations.ts +1 -0
  150. package/src/types/Sheet.ts +23 -20
  151. package/src/{capabilities → types}/capabilities.ts +2 -2
  152. package/src/types/index.ts +1 -0
  153. package/src/types/types.ts +81 -37
  154. package/dist/lib/browser/SheetContainer-66BNB3XG.mjs +0 -349
  155. package/dist/lib/browser/SheetContainer-66BNB3XG.mjs.map +0 -7
  156. package/dist/lib/browser/anchor-sort-FCQ5OZZK.mjs.map +0 -7
  157. package/dist/lib/browser/chunk-73AV3NH6.mjs +0 -15
  158. package/dist/lib/browser/chunk-73AV3NH6.mjs.map +0 -7
  159. package/dist/lib/browser/chunk-7VEWYJJN.mjs.map +0 -7
  160. package/dist/lib/browser/chunk-DVJ3QW3F.mjs +0 -907
  161. package/dist/lib/browser/chunk-DVJ3QW3F.mjs.map +0 -7
  162. package/dist/lib/browser/chunk-FWFAAGXL.mjs +0 -28
  163. package/dist/lib/browser/chunk-FWFAAGXL.mjs.map +0 -7
  164. package/dist/lib/browser/chunk-OU5KTWY3.mjs +0 -852
  165. package/dist/lib/browser/chunk-OU5KTWY3.mjs.map +0 -7
  166. package/dist/lib/browser/compute-graph-registry-AP5RA7W3.mjs +0 -21
  167. package/dist/lib/browser/compute-graph-registry-AP5RA7W3.mjs.map +0 -7
  168. package/dist/lib/browser/intent-resolver-66OAYVQF.mjs +0 -56
  169. package/dist/lib/browser/intent-resolver-66OAYVQF.mjs.map +0 -7
  170. package/dist/lib/browser/markdown-B6VKYY2S.mjs +0 -26
  171. package/dist/lib/browser/markdown-B6VKYY2S.mjs.map +0 -7
  172. package/dist/lib/browser/react-surface-5GYLVSMR.mjs.map +0 -7
  173. package/dist/lib/node-esm/SheetContainer-NWEQETAY.mjs +0 -350
  174. package/dist/lib/node-esm/SheetContainer-NWEQETAY.mjs.map +0 -7
  175. package/dist/lib/node-esm/anchor-sort-ZE7IS7SH.mjs.map +0 -7
  176. package/dist/lib/node-esm/chunk-44YTKTMP.mjs +0 -16
  177. package/dist/lib/node-esm/chunk-44YTKTMP.mjs.map +0 -7
  178. package/dist/lib/node-esm/chunk-4H2EHVWE.mjs +0 -908
  179. package/dist/lib/node-esm/chunk-4H2EHVWE.mjs.map +0 -7
  180. package/dist/lib/node-esm/chunk-4MT3JJU2.mjs +0 -853
  181. package/dist/lib/node-esm/chunk-4MT3JJU2.mjs.map +0 -7
  182. package/dist/lib/node-esm/chunk-4QV4AGWK.mjs.map +0 -7
  183. package/dist/lib/node-esm/chunk-HILDMVPL.mjs +0 -29
  184. package/dist/lib/node-esm/chunk-HILDMVPL.mjs.map +0 -7
  185. package/dist/lib/node-esm/compute-graph-registry-UMQ5UYCL.mjs +0 -22
  186. package/dist/lib/node-esm/compute-graph-registry-UMQ5UYCL.mjs.map +0 -7
  187. package/dist/lib/node-esm/intent-resolver-VNKIMQQT.mjs +0 -57
  188. package/dist/lib/node-esm/intent-resolver-VNKIMQQT.mjs.map +0 -7
  189. package/dist/lib/node-esm/markdown-VKY7HXU2.mjs +0 -27
  190. package/dist/lib/node-esm/markdown-VKY7HXU2.mjs.map +0 -7
  191. package/dist/lib/node-esm/react-surface-RK32YZWR.mjs.map +0 -7
  192. package/dist/types/src/capabilities/anchor-sort.d.ts +0 -4
  193. package/dist/types/src/capabilities/anchor-sort.d.ts.map +0 -1
  194. package/dist/types/src/capabilities/capabilities.d.ts +0 -5
  195. package/dist/types/src/capabilities/capabilities.d.ts.map +0 -1
  196. package/dist/types/src/capabilities/compute-graph-registry.d.ts +0 -4
  197. package/dist/types/src/capabilities/compute-graph-registry.d.ts.map +0 -1
  198. package/dist/types/src/capabilities/intent-resolver.d.ts +0 -4
  199. package/dist/types/src/capabilities/intent-resolver.d.ts.map +0 -1
  200. package/dist/types/src/capabilities/markdown.d.ts +0 -4
  201. package/dist/types/src/capabilities/markdown.d.ts.map +0 -1
  202. package/dist/types/src/capabilities/react-surface.d.ts +0 -4
  203. package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
  204. package/src/capabilities/anchor-sort.ts +0 -21
  205. package/src/capabilities/compute-graph-registry.ts +0 -23
  206. package/src/capabilities/intent-resolver.ts +0 -38
  207. package/src/capabilities/markdown.ts +0 -23
  208. package/src/capabilities/react-surface.tsx +0 -41
@@ -1,907 +0,0 @@
1
- import {
2
- __export,
3
- meta
4
- } from "./chunk-FWFAAGXL.mjs";
5
-
6
- // src/types/Sheet.ts
7
- var Sheet_exports = {};
8
- __export(Sheet_exports, {
9
- CellValue: () => CellValue,
10
- Range: () => Range,
11
- RowColumnMeta: () => RowColumnMeta,
12
- Sheet: () => Sheet,
13
- make: () => make
14
- });
15
- import * as Schema from "effect/Schema";
16
- import { addressFromA1Notation as addressFromA1Notation2, isFormula as isFormula2 } from "@dxos/compute";
17
- import { Obj, Type } from "@dxos/echo";
18
- import { FormAnnotation } from "@dxos/echo/internal";
19
-
20
- // src/types/util.ts
21
- import { addressFromA1Notation, addressToA1Notation, isFormula } from "@dxos/compute";
22
- import { randomBytes } from "@dxos/crypto";
23
- import { invariant } from "@dxos/invariant";
24
- var __dxlog_file = "/__w/dxos/dxos/packages/plugins/plugin-sheet/src/types/util.ts";
25
- var MAX_ROWS = 500;
26
- var MAX_COLS = 676;
27
- var DEFAULT_ROWS = 50;
28
- var DEFAULT_COLS = 26;
29
- var ApiError = class extends Error {
30
- };
31
- var ReadonlyException = class extends ApiError {
32
- };
33
- var RangeException = class extends ApiError {
34
- constructor(n) {
35
- super();
36
- }
37
- };
38
- var createIndex = (length = 8) => {
39
- const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
40
- const charactersLength = characters.length;
41
- const randomBuffer = randomBytes(length);
42
- return Array.from(randomBuffer, (byte) => characters[byte % charactersLength]).join("");
43
- };
44
- var createIndices = (length) => Array.from({
45
- length
46
- }).map(() => createIndex());
47
- var insertIndices = (indices, i, n, max) => {
48
- if (i + n > max) {
49
- throw new RangeException(i + n);
50
- }
51
- const idx = createIndices(n);
52
- indices.splice(i, 0, ...idx);
53
- return idx;
54
- };
55
- var initialize = (sheet, { rows = DEFAULT_ROWS, columns = DEFAULT_COLS } = {}) => {
56
- if (!sheet.rows.length) {
57
- insertIndices(sheet.rows, 0, rows, MAX_ROWS);
58
- }
59
- if (!sheet.columns.length) {
60
- insertIndices(sheet.columns, 0, columns, MAX_COLS);
61
- }
62
- };
63
- var addressToIndex = (sheet, cell) => {
64
- return `${sheet.columns[cell.col]}@${sheet.rows[cell.row]}`;
65
- };
66
- var addressFromIndex = (sheet, idx) => {
67
- const [column, row] = idx.split("@");
68
- return {
69
- col: sheet.columns.indexOf(column),
70
- row: sheet.rows.indexOf(row)
71
- };
72
- };
73
- var rangeToIndex = (sheet, range) => {
74
- return [
75
- range.from,
76
- range.to ?? range.from
77
- ].map((cell) => addressToIndex(sheet, cell)).join(":");
78
- };
79
- var rangeFromIndex = (sheet, idx) => {
80
- const [from, to] = idx.split(":").map((index) => addressFromIndex(sheet, index));
81
- return {
82
- from,
83
- to
84
- };
85
- };
86
- var compareIndexPositions = (sheet, indexA, indexB) => {
87
- const { row: rowA, col: columnA } = addressFromIndex(sheet, indexA);
88
- const { row: rowB, col: columnB } = addressFromIndex(sheet, indexB);
89
- if (rowA !== rowB) {
90
- return rowA - rowB;
91
- } else {
92
- return columnA - columnB;
93
- }
94
- };
95
- var mapFormulaRefsToIndices = (sheet, formula) => {
96
- invariant(isFormula(formula), void 0, {
97
- F: __dxlog_file,
98
- L: 124,
99
- S: void 0,
100
- A: [
101
- "isFormula(formula)",
102
- ""
103
- ]
104
- });
105
- return formula.replace(/([a-zA-Z]+)([0-9]+)/g, (match) => {
106
- return addressToIndex(sheet, addressFromA1Notation(match));
107
- });
108
- };
109
- var mapFormulaIndicesToRefs = (sheet, formula) => {
110
- invariant(isFormula(formula), void 0, {
111
- F: __dxlog_file,
112
- L: 134,
113
- S: void 0,
114
- A: [
115
- "isFormula(formula)",
116
- ""
117
- ]
118
- });
119
- return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
120
- return addressToA1Notation(addressFromIndex(sheet, idx));
121
- });
122
- };
123
-
124
- // src/types/Sheet.ts
125
- var CellValue = Schema.Struct({
126
- // TODO(burdon): How to store dates (datetime, date, time), percentages, etc.
127
- // Consider import/export; natural access for other plugins. Special handling for currency (precision).
128
- // TODO(burdon): Automerge (long string) or short string or number.
129
- value: Schema.Any
130
- });
131
- var Range = Schema.Struct({
132
- range: Schema.String,
133
- key: Schema.String,
134
- value: Schema.String
135
- });
136
- var RowColumnMeta = Schema.Struct({
137
- size: Schema.optional(Schema.Number)
138
- });
139
- var Sheet = Schema.Struct({
140
- name: Schema.optional(Schema.String),
141
- // Sparse map of cells referenced by index.
142
- cells: Schema.Record({
143
- key: Schema.String,
144
- value: Schema.mutable(CellValue)
145
- }).pipe(Schema.mutable, FormAnnotation.set(false)),
146
- // Ordered row indices.
147
- rows: Schema.Array(Schema.String).pipe(Schema.mutable, FormAnnotation.set(false)),
148
- // Ordered column indices.
149
- columns: Schema.Array(Schema.String).pipe(Schema.mutable, FormAnnotation.set(false)),
150
- // Row metadata referenced by index.
151
- rowMeta: Schema.Record({
152
- key: Schema.String,
153
- value: Schema.mutable(RowColumnMeta)
154
- }).pipe(Schema.mutable, FormAnnotation.set(false)),
155
- // Column metadata referenced by index.
156
- columnMeta: Schema.Record({
157
- key: Schema.String,
158
- value: Schema.mutable(RowColumnMeta)
159
- }).pipe(Schema.mutable, FormAnnotation.set(false)),
160
- // Cell formatting referenced by indexed range.
161
- ranges: Schema.Array(Range).pipe(Schema.mutable, FormAnnotation.set(false))
162
- }).pipe(Type.Obj({
163
- typename: "dxos.org/type/Sheet",
164
- version: "0.1.0"
165
- }));
166
- var make = ({ name, cells = {}, ...size } = {}) => {
167
- const sheet = Obj.make(Sheet, {
168
- name,
169
- cells: {},
170
- rows: [],
171
- columns: [],
172
- rowMeta: {},
173
- columnMeta: {},
174
- ranges: []
175
- });
176
- initialize(sheet, size);
177
- if (cells) {
178
- Object.entries(cells).forEach(([key, { value }]) => {
179
- const idx = addressToIndex(sheet, addressFromA1Notation2(key));
180
- if (isFormula2(value)) {
181
- value = mapFormulaRefsToIndices(sheet, value);
182
- }
183
- sheet.cells[idx] = {
184
- value
185
- };
186
- });
187
- }
188
- return sheet;
189
- };
190
-
191
- // src/types/sheet-range-types.ts
192
- var alignKey = "alignment";
193
- var commentKey = "comment";
194
- var styleKey = "style";
195
- var cellClassNameForRange = ({ key, value }) => {
196
- switch (key) {
197
- case alignKey:
198
- switch (value) {
199
- case "start":
200
- return "text-start";
201
- case "center":
202
- return "text-center";
203
- case "end":
204
- return "text-end";
205
- default:
206
- return void 0;
207
- }
208
- case commentKey:
209
- return "bg-gridComment";
210
- case styleKey:
211
- switch (value) {
212
- case "highlight":
213
- return "!bg-gridHighlight";
214
- case "softwrap":
215
- return "!whitespace-normal";
216
- default:
217
- return void 0;
218
- }
219
- default:
220
- return void 0;
221
- }
222
- };
223
-
224
- // src/types/types.ts
225
- import * as Schema2 from "effect/Schema";
226
-
227
- // src/model/sheet-model.ts
228
- import { Event } from "@dxos/async";
229
- import { DetailedCellError, ExportedCellChange, addressFromA1Notation as addressFromA1Notation3, addressToA1Notation as addressToA1Notation2, createSheetName, isFormula as isFormula3 } from "@dxos/compute";
230
- import { Resource } from "@dxos/context";
231
- import { Obj as Obj2 } from "@dxos/echo";
232
- import { FormatEnum, TypeEnum } from "@dxos/echo/internal";
233
- import { invariant as invariant2 } from "@dxos/invariant";
234
- import { PublicKey } from "@dxos/keys";
235
- import { log } from "@dxos/log";
236
- var __dxlog_file2 = "/__w/dxos/dxos/packages/plugins/plugin-sheet/src/model/sheet-model.ts";
237
- var typeMap = {
238
- BOOLEAN: {
239
- type: TypeEnum.Boolean
240
- },
241
- NUMBER_RAW: {
242
- type: TypeEnum.Number
243
- },
244
- NUMBER_PERCENT: {
245
- type: TypeEnum.Number,
246
- format: FormatEnum.Percent
247
- },
248
- NUMBER_CURRENCY: {
249
- type: TypeEnum.Number,
250
- format: FormatEnum.Currency
251
- },
252
- NUMBER_DATETIME: {
253
- type: TypeEnum.String,
254
- format: FormatEnum.DateTime
255
- },
256
- NUMBER_DATE: {
257
- type: TypeEnum.String,
258
- format: FormatEnum.Date
259
- },
260
- NUMBER_TIME: {
261
- type: TypeEnum.String,
262
- format: FormatEnum.Time
263
- }
264
- };
265
- var getTopLeft = (range) => {
266
- const to = range.to ?? range.from;
267
- return {
268
- row: Math.min(range.from.row, to.row),
269
- col: Math.min(range.from.col, to.col)
270
- };
271
- };
272
- var toSimpleCellAddress = (sheet, cell) => ({
273
- sheet,
274
- row: cell.row,
275
- col: cell.col
276
- });
277
- var toModelRange = (sheet, range) => ({
278
- start: toSimpleCellAddress(sheet, range.from),
279
- end: toSimpleCellAddress(sheet, range.to ?? range.from)
280
- });
281
- var SheetModel = class extends Resource {
282
- _graph;
283
- _sheet;
284
- _options;
285
- id = `model-${PublicKey.random().truncate()}`;
286
- // Wraps compute node.
287
- update = new Event();
288
- _node;
289
- constructor(_graph, _sheet, _options = {}) {
290
- super(), this._graph = _graph, this._sheet = _sheet, this._options = _options;
291
- }
292
- get graph() {
293
- return this._graph;
294
- }
295
- get sheet() {
296
- return this._sheet;
297
- }
298
- get readonly() {
299
- return this._options.readonly;
300
- }
301
- get bounds() {
302
- return {
303
- rows: this._sheet.rows.length,
304
- columns: this._sheet.columns.length
305
- };
306
- }
307
- /**
308
- * Initialize sheet and engine.
309
- */
310
- async _open() {
311
- log("initialize", {
312
- id: this.id
313
- }, {
314
- F: __dxlog_file2,
315
- L: 124,
316
- S: this,
317
- C: (f, a) => f(...a)
318
- });
319
- initialize(this._sheet);
320
- this._graph.update.on((event) => {
321
- if (event.type === "functionsUpdated") {
322
- this.reset();
323
- }
324
- });
325
- this._node = this._graph.getOrCreateNode(createSheetName({
326
- type: Obj2.getTypename(this._sheet),
327
- id: this._sheet.id
328
- }));
329
- await this._node.open();
330
- const unsubscribe = this._node.update.on((event) => this.update.emit(event));
331
- this._ctx.onDispose(unsubscribe);
332
- this.reset();
333
- }
334
- /**
335
- * Update engine.
336
- * NOTE: This resets the undo history.
337
- * @deprecated
338
- */
339
- reset() {
340
- invariant2(this._node, void 0, {
341
- F: __dxlog_file2,
342
- L: 152,
343
- S: this,
344
- A: [
345
- "this._node",
346
- ""
347
- ]
348
- });
349
- this._node.graph.hf.clearSheet(this._node.sheetId);
350
- Object.entries(this._sheet.cells).forEach(([key, { value }]) => {
351
- invariant2(this._node, void 0, {
352
- F: __dxlog_file2,
353
- L: 155,
354
- S: this,
355
- A: [
356
- "this._node",
357
- ""
358
- ]
359
- });
360
- const { col, row } = addressFromIndex(this._sheet, key);
361
- if (isFormula3(value)) {
362
- const binding = this._graph.mapFunctionBindingFromId(mapFormulaIndicesToRefs(this._sheet, value));
363
- if (binding) {
364
- value = this._graph.mapFormulaToNative(binding);
365
- } else {
366
- value = "";
367
- }
368
- }
369
- this._node.graph.hf.setCellContents({
370
- sheet: this._node.sheetId,
371
- row,
372
- col
373
- }, value);
374
- });
375
- }
376
- /**
377
- * Recalculate formulas.
378
- * NOTE: This resets the undo history.
379
- * https://hyperformula.handsontable.com/guide/volatile-functions.html#volatile-actions
380
- * @deprecated
381
- */
382
- // TODO(burdon): Remove.
383
- recalculate() {
384
- this._node?.graph.hf.rebuildAndRecalculate();
385
- }
386
- insertRows(i, n = 1) {
387
- const idx = insertIndices(this._sheet.rows, i, n, MAX_ROWS);
388
- this.reset();
389
- return idx;
390
- }
391
- insertColumns(i, n = 1) {
392
- const idx = insertIndices(this._sheet.columns, i, n, MAX_COLS);
393
- this.reset();
394
- return idx;
395
- }
396
- dropRow(rowIndex) {
397
- const range = {
398
- from: addressFromIndex(this._sheet, `${this._sheet.columns[0]}@${rowIndex}`),
399
- to: addressFromIndex(this._sheet, `${this._sheet.columns[this._sheet.columns.length - 1]}@${rowIndex}`)
400
- };
401
- const values = this.getCellValues(range).flat();
402
- const index = this._sheet.rows.indexOf(rowIndex);
403
- this.clear(range);
404
- this._sheet.rows.splice(index, 1);
405
- delete this._sheet.rowMeta[rowIndex];
406
- this.reset();
407
- return {
408
- axis: "row",
409
- index,
410
- axisIndex: rowIndex,
411
- axisMeta: this._sheet.rowMeta[rowIndex],
412
- values
413
- };
414
- }
415
- dropColumn(colIndex) {
416
- const range = {
417
- from: addressFromIndex(this._sheet, `${colIndex}@${this._sheet.rows[0]}`),
418
- to: addressFromIndex(this._sheet, `${colIndex}@${this._sheet.rows[this._sheet.rows.length - 1]}`)
419
- };
420
- const values = this.getCellValues(range).flat();
421
- const index = this._sheet.columns.indexOf(colIndex);
422
- this.clear(range);
423
- this._sheet.columns.splice(index, 1);
424
- delete this._sheet.columnMeta[colIndex];
425
- this.reset();
426
- return {
427
- axis: "col",
428
- index,
429
- axisIndex: colIndex,
430
- axisMeta: this._sheet.rowMeta[colIndex],
431
- values
432
- };
433
- }
434
- restoreRow({ index, axisIndex, axisMeta, values }) {
435
- this._sheet.rows.splice(index, 0, axisIndex);
436
- values.forEach((value, col) => {
437
- if (value) {
438
- this._sheet.cells[`${this._sheet.columns[col]}@${axisIndex}`] = {
439
- value
440
- };
441
- }
442
- });
443
- if (axisMeta) {
444
- this._sheet.rowMeta[axisIndex] = axisMeta;
445
- }
446
- this.reset();
447
- }
448
- restoreColumn({ index, axisIndex, axisMeta, values }) {
449
- this._sheet.columns.splice(index, 0, axisIndex);
450
- values.forEach((value, row) => {
451
- if (value) {
452
- this._sheet.cells[`${axisIndex}@${this._sheet.rows[row]}`] = {
453
- value
454
- };
455
- }
456
- });
457
- if (axisMeta) {
458
- this._sheet.columnMeta[axisIndex] = axisMeta;
459
- }
460
- this.reset();
461
- }
462
- //
463
- // Undoable actions.
464
- // TODO(burdon): Group undoable methods; consistently update hf/sheet.
465
- //
466
- /**
467
- * Clear range of values.
468
- */
469
- clear(range) {
470
- invariant2(this._node, void 0, {
471
- F: __dxlog_file2,
472
- L: 258,
473
- S: this,
474
- A: [
475
- "this._node",
476
- ""
477
- ]
478
- });
479
- const topLeft = getTopLeft(range);
480
- const values = this._iterRange(range, () => null);
481
- this._node.graph.hf.setCellContents(toSimpleCellAddress(this._node.sheetId, topLeft), values);
482
- this._iterRange(range, (cell) => {
483
- const idx = addressToIndex(this._sheet, cell);
484
- delete this._sheet.cells[idx];
485
- });
486
- }
487
- cut(range) {
488
- invariant2(this._node, void 0, {
489
- F: __dxlog_file2,
490
- L: 269,
491
- S: this,
492
- A: [
493
- "this._node",
494
- ""
495
- ]
496
- });
497
- this._node.graph.hf.cut(toModelRange(this._node.sheetId, range));
498
- this._iterRange(range, (cell) => {
499
- const idx = addressToIndex(this._sheet, cell);
500
- delete this._sheet.cells[idx];
501
- });
502
- }
503
- copy(range) {
504
- invariant2(this._node, void 0, {
505
- F: __dxlog_file2,
506
- L: 278,
507
- S: this,
508
- A: [
509
- "this._node",
510
- ""
511
- ]
512
- });
513
- this._node.graph.hf.copy(toModelRange(this._node.sheetId, range));
514
- }
515
- paste(cell) {
516
- invariant2(this._node, void 0, {
517
- F: __dxlog_file2,
518
- L: 283,
519
- S: this,
520
- A: [
521
- "this._node",
522
- ""
523
- ]
524
- });
525
- if (!this._node.graph.hf.isClipboardEmpty()) {
526
- const changes = this._node.graph.hf.paste(toSimpleCellAddress(this._node.sheetId, cell));
527
- for (const change of changes) {
528
- if (change instanceof ExportedCellChange) {
529
- const { address, newValue } = change;
530
- const idx = addressToIndex(this._sheet, {
531
- row: address.row,
532
- col: address.col
533
- });
534
- this._sheet.cells[idx] = {
535
- value: newValue
536
- };
537
- }
538
- }
539
- }
540
- }
541
- // TODO(burdon): Display undo/redo state.
542
- undo() {
543
- invariant2(this._node, void 0, {
544
- F: __dxlog_file2,
545
- L: 298,
546
- S: this,
547
- A: [
548
- "this._node",
549
- ""
550
- ]
551
- });
552
- if (this._node.graph.hf.isThereSomethingToUndo()) {
553
- this._node.graph.hf.undo();
554
- }
555
- }
556
- redo() {
557
- invariant2(this._node, void 0, {
558
- F: __dxlog_file2,
559
- L: 306,
560
- S: this,
561
- A: [
562
- "this._node",
563
- ""
564
- ]
565
- });
566
- if (this._node.graph.hf.isThereSomethingToRedo()) {
567
- this._node.graph.hf.redo();
568
- }
569
- }
570
- /**
571
- * Get value from sheet.
572
- */
573
- getCellValue(cell) {
574
- const idx = addressToIndex(this._sheet, cell);
575
- return this._sheet.cells[idx]?.value ?? null;
576
- }
577
- /**
578
- * Get value as a string for editing.
579
- */
580
- getCellText(cell) {
581
- const value = this.getCellValue(cell);
582
- if (value == null) {
583
- return void 0;
584
- }
585
- if (isFormula3(value)) {
586
- return this._graph.mapFunctionBindingFromId(mapFormulaIndicesToRefs(this._sheet, value));
587
- } else {
588
- return String(value);
589
- }
590
- }
591
- /**
592
- * Get array of raw values from sheet.
593
- */
594
- getCellValues(range) {
595
- return this._iterRange(range, (cell) => this.getCellValue(cell));
596
- }
597
- /**
598
- * Gets the regular or computed value from the engine.
599
- */
600
- getValue(cell) {
601
- invariant2(this._node, void 0, {
602
- F: __dxlog_file2,
603
- L: 349,
604
- S: this,
605
- A: [
606
- "this._node",
607
- ""
608
- ]
609
- });
610
- const address = toSimpleCellAddress(this._node.sheetId, cell);
611
- const value = this._node.graph.hf.getCellValue(address);
612
- if (value instanceof DetailedCellError) {
613
- log.warn("cell error", {
614
- cell,
615
- error: value
616
- }, {
617
- F: __dxlog_file2,
618
- L: 354,
619
- S: this,
620
- C: (f, a) => f(...a)
621
- });
622
- return value.toString();
623
- }
624
- return value;
625
- }
626
- /**
627
- * Get value type.
628
- */
629
- getValueDescription(cell) {
630
- invariant2(this._node, void 0, {
631
- F: __dxlog_file2,
632
- L: 365,
633
- S: this,
634
- A: [
635
- "this._node",
636
- ""
637
- ]
638
- });
639
- const addr = toSimpleCellAddress(this._node.sheetId, cell);
640
- const type = this._node.graph.hf.getCellValueDetailedType(addr);
641
- return typeMap[type];
642
- }
643
- /**
644
- * Sets the value, updating the sheet and engine.
645
- */
646
- setValue(cell, value) {
647
- invariant2(this._node, void 0, {
648
- F: __dxlog_file2,
649
- L: 375,
650
- S: this,
651
- A: [
652
- "this._node",
653
- ""
654
- ]
655
- });
656
- if (this._options.readonly) {
657
- throw new ReadonlyException();
658
- }
659
- let refresh = false;
660
- if (cell.row >= this._sheet.rows.length) {
661
- insertIndices(this._sheet.rows, cell.row, 1, MAX_ROWS);
662
- refresh = true;
663
- }
664
- if (cell.col >= this._sheet.columns.length) {
665
- insertIndices(this._sheet.columns, cell.col, 1, MAX_COLS);
666
- refresh = true;
667
- }
668
- if (refresh) {
669
- this.reset();
670
- }
671
- this._node.graph.hf.setCellContents({
672
- sheet: this._node.sheetId,
673
- row: cell.row,
674
- col: cell.col
675
- }, [
676
- [
677
- isFormula3(value) ? this._graph.mapFormulaToNative(value) : value
678
- ]
679
- ]);
680
- const idx = addressToIndex(this._sheet, cell);
681
- if (value === void 0 || value === null) {
682
- delete this._sheet.cells[idx];
683
- } else {
684
- if (isFormula3(value)) {
685
- value = this._graph.mapFunctionBindingToId(mapFormulaRefsToIndices(this._sheet, value));
686
- }
687
- this._sheet.cells[idx] = {
688
- value
689
- };
690
- }
691
- }
692
- /**
693
- * Sets values from a simple map.
694
- */
695
- setValues(values) {
696
- Object.entries(values).forEach(([key, { value }]) => {
697
- this.setValue(addressFromA1Notation3(key), value);
698
- });
699
- }
700
- /**
701
- * Iterate range.
702
- */
703
- _iterRange(range, cb) {
704
- const to = range.to ?? range.from;
705
- const rowRange = [
706
- Math.min(range.from.row, to.row),
707
- Math.max(range.from.row, to.row)
708
- ];
709
- const columnRange = [
710
- Math.min(range.from.col, to.col),
711
- Math.max(range.from.col, to.col)
712
- ];
713
- const rows = [];
714
- for (let row = rowRange[0]; row <= rowRange[1]; row++) {
715
- const rowCells = [];
716
- for (let column = columnRange[0]; column <= columnRange[1]; column++) {
717
- const value = cb({
718
- row,
719
- col: column
720
- });
721
- if (value !== void 0) {
722
- rowCells.push(value);
723
- }
724
- }
725
- rows.push(rowCells);
726
- }
727
- return rows;
728
- }
729
- // TODO(burdon): Delete index.
730
- _deleteIndices(indices, i, n) {
731
- throw new Error("Not implemented");
732
- }
733
- // TODO(burdon): Move. Cannot use fractional without changing. Switch back to using unique IDs?
734
- _moveIndices(indices, i, j, n) {
735
- throw new Error("Not implemented");
736
- }
737
- /**
738
- * Map from indices to A1 notation.
739
- */
740
- mapFormulaIndicesToRefs(formula) {
741
- invariant2(isFormula3(formula), void 0, {
742
- F: __dxlog_file2,
743
- L: 460,
744
- S: this,
745
- A: [
746
- "isFormula(formula)",
747
- ""
748
- ]
749
- });
750
- return formula.replace(/([a-zA-Z0-9]+)@([a-zA-Z0-9]+)/g, (idx) => {
751
- return addressToA1Notation2(addressFromIndex(this._sheet, idx));
752
- });
753
- }
754
- //
755
- // Values
756
- //
757
- /**
758
- * https://hyperformula.handsontable.com/guide/date-and-time-handling.html#example
759
- * https://hyperformula.handsontable.com/api/interfaces/configparams.html#nulldate
760
- * NOTE: TODAY() is number of FULL days since nullDate. It will typically be -1 days from NOW().
761
- */
762
- toLocalDate(num) {
763
- const { year, month, day, hours, minutes, seconds } = this.toDateTime(num);
764
- return new Date(year, month - 1, day, hours, minutes, seconds);
765
- }
766
- toDateTime(num) {
767
- invariant2(this._node, void 0, {
768
- F: __dxlog_file2,
769
- L: 481,
770
- S: this,
771
- A: [
772
- "this._node",
773
- ""
774
- ]
775
- });
776
- return this._node.graph.hf.numberToDateTime(num);
777
- }
778
- toDate(num) {
779
- invariant2(this._node, void 0, {
780
- F: __dxlog_file2,
781
- L: 486,
782
- S: this,
783
- A: [
784
- "this._node",
785
- ""
786
- ]
787
- });
788
- return this._node.graph.hf.numberToDate(num);
789
- }
790
- toTime(num) {
791
- invariant2(this._node, void 0, {
792
- F: __dxlog_file2,
793
- L: 491,
794
- S: this,
795
- A: [
796
- "this._node",
797
- ""
798
- ]
799
- });
800
- return this._node.graph.hf.numberToTime(num);
801
- }
802
- };
803
-
804
- // src/model/useSheetModel.ts
805
- import { useEffect, useState } from "react";
806
- var useSheetModel = (graph, sheet, { readonly } = {}) => {
807
- const [model, setModel] = useState();
808
- useEffect(() => {
809
- if (!graph || !sheet) {
810
- return;
811
- }
812
- let model2;
813
- const t = setTimeout(async () => {
814
- model2 = new SheetModel(graph, sheet, {
815
- readonly
816
- });
817
- await model2.open();
818
- setModel(model2);
819
- });
820
- return () => {
821
- clearTimeout(t);
822
- void model2?.close();
823
- };
824
- }, [
825
- graph,
826
- sheet,
827
- readonly
828
- ]);
829
- return model;
830
- };
831
-
832
- // src/types/types.ts
833
- (function(SheetAction2) {
834
- const SHEET_ACTION = `${meta.id}/action`;
835
- class Create extends Schema2.TaggedClass()(`${SHEET_ACTION}/create`, {
836
- input: Schema2.Struct({
837
- name: Schema2.optional(Schema2.String)
838
- }),
839
- output: Schema2.Struct({
840
- object: Sheet
841
- })
842
- }) {
843
- }
844
- SheetAction2.Create = Create;
845
- const Axis = Schema2.Union(Schema2.Literal("row"), Schema2.Literal("col"));
846
- class InsertAxis extends Schema2.TaggedClass()(`${SHEET_ACTION}/axis-insert`, {
847
- input: Schema2.Struct({
848
- // TODO(wittjosiah): Schema.instanceOf(SheetModel) throws when running tests.
849
- model: Schema2.Any.pipe(Schema2.filter((model) => model instanceof SheetModel)),
850
- axis: Axis,
851
- index: Schema2.Number,
852
- count: Schema2.optional(Schema2.Number)
853
- }),
854
- output: Schema2.Void
855
- }) {
856
- }
857
- SheetAction2.InsertAxis = InsertAxis;
858
- SheetAction2.RestoreAxis = Schema2.Struct({
859
- axis: Axis,
860
- axisIndex: Schema2.String,
861
- index: Schema2.Number,
862
- axisMeta: RowColumnMeta,
863
- values: Schema2.Array(Schema2.Any)
864
- });
865
- class DropAxis extends Schema2.TaggedClass()(`${SHEET_ACTION}/axis-drop`, {
866
- input: Schema2.Struct({
867
- // TODO(wittjosiah): Schema.instanceOf(SheetModel) throws when running tests.
868
- model: Schema2.Any.pipe(Schema2.filter((model) => model instanceof SheetModel)),
869
- axis: Axis,
870
- axisIndex: Schema2.String,
871
- deletionData: Schema2.optional(SheetAction2.RestoreAxis)
872
- }),
873
- output: Schema2.Void
874
- }) {
875
- }
876
- SheetAction2.DropAxis = DropAxis;
877
- })(SheetAction || (SheetAction = {}));
878
- var SheetAction;
879
-
880
- export {
881
- MAX_ROWS,
882
- MAX_COLS,
883
- DEFAULT_ROWS,
884
- DEFAULT_COLS,
885
- ApiError,
886
- ReadonlyException,
887
- RangeException,
888
- createIndex,
889
- createIndices,
890
- insertIndices,
891
- initialize,
892
- addressToIndex,
893
- addressFromIndex,
894
- rangeToIndex,
895
- rangeFromIndex,
896
- compareIndexPositions,
897
- mapFormulaRefsToIndices,
898
- mapFormulaIndicesToRefs,
899
- Sheet_exports,
900
- alignKey,
901
- commentKey,
902
- styleKey,
903
- cellClassNameForRange,
904
- useSheetModel,
905
- SheetAction
906
- };
907
- //# sourceMappingURL=chunk-DVJ3QW3F.mjs.map