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