@dxos/plugin-sheet 0.8.3 → 0.8.4-main.2e9d522

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