@ricsam/formula-engine 0.0.16 → 0.0.18

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 (122) hide show
  1. package/dist/cjs/core/api/api-builder.cjs +67 -0
  2. package/dist/cjs/core/api/api-builder.cjs.map +10 -0
  3. package/dist/cjs/core/api/api-helpers.cjs +191 -0
  4. package/dist/cjs/core/api/api-helpers.cjs.map +10 -0
  5. package/dist/cjs/core/api/api.cjs +65 -0
  6. package/dist/cjs/core/api/api.cjs.map +10 -0
  7. package/dist/cjs/core/api/cell-orm.cjs +80 -0
  8. package/dist/cjs/core/api/cell-orm.cjs.map +10 -0
  9. package/dist/cjs/core/api/table-orm.cjs +171 -0
  10. package/dist/cjs/core/api/table-orm.cjs.map +10 -0
  11. package/dist/cjs/core/autofill-utils.cjs +75 -39
  12. package/dist/cjs/core/autofill-utils.cjs.map +3 -3
  13. package/dist/cjs/core/cell-mover.cjs +178 -0
  14. package/dist/cjs/core/cell-mover.cjs.map +10 -0
  15. package/dist/cjs/core/commands/command-executor.cjs +140 -0
  16. package/dist/cjs/core/commands/command-executor.cjs.map +10 -0
  17. package/dist/cjs/core/commands/content-commands.cjs +574 -0
  18. package/dist/cjs/core/commands/content-commands.cjs.map +10 -0
  19. package/dist/cjs/core/commands/index.cjs +95 -0
  20. package/dist/cjs/core/commands/index.cjs.map +10 -0
  21. package/dist/cjs/core/commands/metadata-commands.cjs +150 -0
  22. package/dist/cjs/core/commands/metadata-commands.cjs.map +10 -0
  23. package/dist/cjs/core/commands/named-expression-commands.cjs +238 -0
  24. package/dist/cjs/core/commands/named-expression-commands.cjs.map +10 -0
  25. package/dist/cjs/core/commands/structure-commands.cjs +495 -0
  26. package/dist/cjs/core/commands/structure-commands.cjs.map +10 -0
  27. package/dist/cjs/core/commands/style-commands.cjs +219 -0
  28. package/dist/cjs/core/commands/style-commands.cjs.map +10 -0
  29. package/dist/cjs/core/commands/table-commands.cjs +226 -0
  30. package/dist/cjs/core/commands/table-commands.cjs.map +10 -0
  31. package/dist/cjs/core/commands/types.cjs +72 -0
  32. package/dist/cjs/core/commands/types.cjs.map +10 -0
  33. package/dist/cjs/core/engine.cjs +218 -263
  34. package/dist/cjs/core/engine.cjs.map +3 -3
  35. package/dist/cjs/core/managers/api-schema-manager.cjs +304 -0
  36. package/dist/cjs/core/managers/api-schema-manager.cjs.map +10 -0
  37. package/dist/cjs/core/managers/copy-manager.cjs +336 -82
  38. package/dist/cjs/core/managers/copy-manager.cjs.map +3 -3
  39. package/dist/cjs/core/managers/reference-manager.cjs +124 -0
  40. package/dist/cjs/core/managers/reference-manager.cjs.map +10 -0
  41. package/dist/cjs/core/managers/style-manager.cjs +115 -147
  42. package/dist/cjs/core/managers/style-manager.cjs.map +3 -3
  43. package/dist/cjs/core/managers/workbook-manager.cjs +87 -3
  44. package/dist/cjs/core/managers/workbook-manager.cjs.map +3 -3
  45. package/dist/cjs/core/types.cjs.map +1 -1
  46. package/dist/cjs/lib.cjs +13 -2
  47. package/dist/cjs/lib.cjs.map +3 -3
  48. package/dist/cjs/package.json +1 -1
  49. package/dist/mjs/core/api/api-builder.mjs +37 -0
  50. package/dist/mjs/core/api/api-builder.mjs.map +10 -0
  51. package/dist/mjs/core/api/api-helpers.mjs +161 -0
  52. package/dist/mjs/core/api/api-helpers.mjs.map +10 -0
  53. package/dist/mjs/core/api/api.mjs +35 -0
  54. package/dist/mjs/core/api/api.mjs.map +10 -0
  55. package/dist/mjs/core/api/cell-orm.mjs +49 -0
  56. package/dist/mjs/core/api/cell-orm.mjs.map +10 -0
  57. package/dist/mjs/core/api/table-orm.mjs +148 -0
  58. package/dist/mjs/core/api/table-orm.mjs.map +10 -0
  59. package/dist/mjs/core/autofill-utils.mjs +75 -39
  60. package/dist/mjs/core/autofill-utils.mjs.map +3 -3
  61. package/dist/mjs/core/cell-mover.mjs +148 -0
  62. package/dist/mjs/core/cell-mover.mjs.map +10 -0
  63. package/dist/mjs/core/commands/command-executor.mjs +109 -0
  64. package/dist/mjs/core/commands/command-executor.mjs.map +10 -0
  65. package/dist/mjs/core/commands/content-commands.mjs +544 -0
  66. package/dist/mjs/core/commands/content-commands.mjs.map +10 -0
  67. package/dist/mjs/core/commands/index.mjs +87 -0
  68. package/dist/mjs/core/commands/index.mjs.map +10 -0
  69. package/dist/mjs/core/commands/metadata-commands.mjs +120 -0
  70. package/dist/mjs/core/commands/metadata-commands.mjs.map +10 -0
  71. package/dist/mjs/core/commands/named-expression-commands.mjs +208 -0
  72. package/dist/mjs/core/commands/named-expression-commands.mjs.map +10 -0
  73. package/dist/mjs/core/commands/structure-commands.mjs +465 -0
  74. package/dist/mjs/core/commands/structure-commands.mjs.map +10 -0
  75. package/dist/mjs/core/commands/style-commands.mjs +189 -0
  76. package/dist/mjs/core/commands/style-commands.mjs.map +10 -0
  77. package/dist/mjs/core/commands/table-commands.mjs +196 -0
  78. package/dist/mjs/core/commands/table-commands.mjs.map +10 -0
  79. package/dist/mjs/core/commands/types.mjs +42 -0
  80. package/dist/mjs/core/commands/types.mjs.map +10 -0
  81. package/dist/mjs/core/engine.mjs +253 -263
  82. package/dist/mjs/core/engine.mjs.map +3 -3
  83. package/dist/mjs/core/managers/api-schema-manager.mjs +274 -0
  84. package/dist/mjs/core/managers/api-schema-manager.mjs.map +10 -0
  85. package/dist/mjs/core/managers/copy-manager.mjs +338 -82
  86. package/dist/mjs/core/managers/copy-manager.mjs.map +3 -3
  87. package/dist/mjs/core/managers/reference-manager.mjs +93 -0
  88. package/dist/mjs/core/managers/reference-manager.mjs.map +10 -0
  89. package/dist/mjs/core/managers/style-manager.mjs +115 -147
  90. package/dist/mjs/core/managers/style-manager.mjs.map +3 -3
  91. package/dist/mjs/core/managers/workbook-manager.mjs +87 -3
  92. package/dist/mjs/core/managers/workbook-manager.mjs.map +3 -3
  93. package/dist/mjs/core/types.mjs.map +1 -1
  94. package/dist/mjs/lib.mjs +13 -2
  95. package/dist/mjs/lib.mjs.map +3 -3
  96. package/dist/mjs/package.json +1 -1
  97. package/dist/types/core/api/api-builder.d.ts +16 -0
  98. package/dist/types/core/api/api-helpers.d.ts +37 -0
  99. package/dist/types/core/api/api.d.ts +83 -0
  100. package/dist/types/core/api/api.type-test.d.ts +1 -0
  101. package/dist/types/core/api/cell-orm.d.ts +29 -0
  102. package/dist/types/core/api/table-orm.d.ts +46 -0
  103. package/dist/types/core/autofill-utils.d.ts +6 -9
  104. package/dist/types/core/cell-mover.d.ts +63 -0
  105. package/dist/types/core/commands/command-executor.d.ts +83 -0
  106. package/dist/types/core/commands/content-commands.d.ts +142 -0
  107. package/dist/types/core/commands/index.d.ts +16 -0
  108. package/dist/types/core/commands/metadata-commands.d.ts +55 -0
  109. package/dist/types/core/commands/named-expression-commands.d.ts +115 -0
  110. package/dist/types/core/commands/structure-commands.d.ts +132 -0
  111. package/dist/types/core/commands/style-commands.d.ts +76 -0
  112. package/dist/types/core/commands/table-commands.d.ts +104 -0
  113. package/dist/types/core/commands/types.d.ts +114 -0
  114. package/dist/types/core/engine.d.ts +241 -23
  115. package/dist/types/core/managers/api-schema-manager.d.ts +121 -0
  116. package/dist/types/core/managers/copy-manager.d.ts +47 -2
  117. package/dist/types/core/managers/reference-manager.d.ts +54 -0
  118. package/dist/types/core/managers/style-manager.d.ts +6 -6
  119. package/dist/types/core/managers/workbook-manager.d.ts +39 -1
  120. package/dist/types/core/types.d.ts +52 -11
  121. package/dist/types/lib.d.ts +8 -0
  122. package/package.json +1 -1
@@ -2,7 +2,11 @@
2
2
  import { parseFormula } from "../../parser/parser.mjs";
3
3
  import { astToString } from "../../parser/formatter.mjs";
4
4
  import { transformAST } from "../ast-traverser.mjs";
5
+ import { getCellReference, isCellInRange } from "../utils.mjs";
5
6
  import { intersectRanges } from "../utils/range-utils.mjs";
7
+ import {
8
+ updateReferencesForMovedCells
9
+ } from "../cell-mover.mjs";
6
10
 
7
11
  class CopyManager {
8
12
  workbookManager;
@@ -13,30 +17,114 @@ class CopyManager {
13
17
  this.evaluationManager = evaluationManager;
14
18
  this.styleManager = styleManager;
15
19
  }
16
- copyCells(source, target, options) {
20
+ normalizeInclude(include) {
21
+ if (!include || include === "all") {
22
+ return ["content", "style", "metadata"];
23
+ }
24
+ return include;
25
+ }
26
+ shouldInclude(options, part) {
27
+ const normalized = this.normalizeInclude(options.include);
28
+ return normalized.includes(part);
29
+ }
30
+ pasteCells(source, target, options) {
17
31
  if (source.length === 0) {
18
32
  return;
19
33
  }
34
+ if (options.cut === true) {
35
+ return this.cutCells(source, target, options);
36
+ } else {
37
+ return this.copyOnlyCells(source, target, options);
38
+ }
39
+ }
40
+ cutCells(source, target, options) {
41
+ const topLeft = this.findTopLeft(source);
42
+ const rowOffset = target.rowIndex - topLeft.rowIndex;
43
+ const colOffset = target.colIndex - topLeft.colIndex;
44
+ const snapshot = this.snapshotCellsWithStyles(source);
45
+ this.clearSourceCells(source);
46
+ if (this.shouldInclude(options, "style")) {
47
+ for (const cell of source) {
48
+ const cellRange = {
49
+ workbookName: cell.workbookName,
50
+ sheetName: cell.sheetName,
51
+ range: {
52
+ start: { col: cell.colIndex, row: cell.rowIndex },
53
+ end: {
54
+ col: { type: "number", value: cell.colIndex },
55
+ row: { type: "number", value: cell.rowIndex }
56
+ }
57
+ }
58
+ };
59
+ this.styleManager.clearCellStylesInRange(cellRange);
60
+ }
61
+ }
62
+ const movedCellsSet = new Set(source.map((c) => `${c.workbookName}:${c.sheetName}:${c.colIndex}:${c.rowIndex}`));
63
+ const movedCellsInfo = {
64
+ cellsSet: movedCellsSet,
65
+ workbookName: topLeft.workbookName,
66
+ sheetName: topLeft.sheetName,
67
+ rowOffset,
68
+ colOffset
69
+ };
70
+ this.workbookManager.updateFormulasExcluding(movedCellsSet, (formula) => updateReferencesForMovedCells(formula, movedCellsInfo));
71
+ for (let i = 0;i < snapshot.length; i++) {
72
+ const snap = snapshot[i];
73
+ const sourceCell = source[i];
74
+ const targetCell = {
75
+ workbookName: target.workbookName,
76
+ sheetName: target.sheetName,
77
+ colIndex: sourceCell.colIndex + colOffset,
78
+ rowIndex: sourceCell.rowIndex + rowOffset
79
+ };
80
+ if (this.shouldInclude(options, "content") && snap.content) {
81
+ let targetContent = snap.content;
82
+ if (typeof snap.content === "string" && snap.content.startsWith("=")) {
83
+ targetContent = this.adjustFormulaReferences(snap.content, {
84
+ colIndex: snap.address.colIndex,
85
+ rowIndex: snap.address.rowIndex
86
+ }, {
87
+ colIndex: targetCell.colIndex,
88
+ rowIndex: targetCell.rowIndex
89
+ });
90
+ }
91
+ this.workbookManager.setCellContent(targetCell, targetContent);
92
+ }
93
+ if (this.shouldInclude(options, "metadata")) {
94
+ if (snap.metadata) {
95
+ this.workbookManager.setCellMetadata(targetCell, {
96
+ ...snap.metadata
97
+ });
98
+ } else {
99
+ this.workbookManager.setCellMetadata(targetCell, undefined);
100
+ }
101
+ }
102
+ if (this.shouldInclude(options, "style")) {
103
+ this.applyStylesFromSnapshot(snap, targetCell);
104
+ }
105
+ }
106
+ }
107
+ copyOnlyCells(source, target, options) {
20
108
  const topLeft = this.findTopLeft(source);
21
109
  const rowOffset = target.rowIndex - topLeft.rowIndex;
22
110
  const colOffset = target.colIndex - topLeft.colIndex;
23
- if (options.target !== "style") {
24
- for (const sourceCell of source) {
111
+ const snapshot = this.snapshotCells(source);
112
+ if (this.shouldInclude(options, "content")) {
113
+ for (let i = 0;i < source.length; i++) {
114
+ const sourceCell = source[i];
115
+ const cellSnapshot = snapshot[i];
25
116
  const targetCell = {
26
117
  workbookName: target.workbookName,
27
118
  sheetName: target.sheetName,
28
119
  colIndex: sourceCell.colIndex + colOffset,
29
120
  rowIndex: sourceCell.rowIndex + rowOffset
30
121
  };
31
- this.copyCellContent(sourceCell, targetCell, topLeft, options);
122
+ this.copyCellContentFromSnapshot(cellSnapshot, targetCell, topLeft, options);
32
123
  }
33
124
  }
34
- if (options.target === "all" || options.target === "style") {
125
+ if (this.shouldInclude(options, "style")) {
35
126
  this.copyFormatting(source, topLeft, target, rowOffset, colOffset);
36
127
  }
37
- if (options.cut) {
38
- this.clearSourceCells(source);
39
- }
40
128
  }
41
129
  findTopLeft(cells) {
42
130
  let minRow = Infinity;
@@ -51,6 +139,141 @@ class CopyManager {
51
139
  }
52
140
  return topLeftCell;
53
141
  }
142
+ snapshotCells(cells) {
143
+ return cells.map((cell) => {
144
+ const sheet = this.workbookManager.getSheet({
145
+ workbookName: cell.workbookName,
146
+ sheetName: cell.sheetName
147
+ });
148
+ const key = `${String.fromCharCode(65 + cell.colIndex)}${cell.rowIndex + 1}`;
149
+ const content = sheet?.content.get(key);
150
+ const metadata = this.workbookManager.getCellMetadata(cell);
151
+ return {
152
+ address: cell,
153
+ content,
154
+ metadata
155
+ };
156
+ });
157
+ }
158
+ snapshotCellsWithStyles(cells) {
159
+ const allCellStyles = this.styleManager.getAllCellStyles();
160
+ const allConditionalStyles = this.styleManager.getAllConditionalStyles();
161
+ return cells.map((cell) => {
162
+ const sheet = this.workbookManager.getSheet({
163
+ workbookName: cell.workbookName,
164
+ sheetName: cell.sheetName
165
+ });
166
+ const key = getCellReference(cell);
167
+ const content = sheet?.content.get(key);
168
+ const metadata = this.workbookManager.getCellMetadata(cell);
169
+ const matchingCellStyles = allCellStyles.filter((style) => style.areas.some((area) => area.workbookName === cell.workbookName && area.sheetName === cell.sheetName && isCellInRange(cell, area.range)));
170
+ const matchingConditionalStyles = allConditionalStyles.filter((style) => style.areas.some((area) => area.workbookName === cell.workbookName && area.sheetName === cell.sheetName && isCellInRange(cell, area.range)));
171
+ return {
172
+ address: cell,
173
+ content,
174
+ metadata,
175
+ matchingCellStyles,
176
+ matchingConditionalStyles
177
+ };
178
+ });
179
+ }
180
+ applyStylesFromSnapshot(snapshot, targetCell) {
181
+ if (snapshot.matchingCellStyles) {
182
+ for (const style of snapshot.matchingCellStyles) {
183
+ const newStyle = {
184
+ areas: [
185
+ {
186
+ workbookName: targetCell.workbookName,
187
+ sheetName: targetCell.sheetName,
188
+ range: {
189
+ start: { col: targetCell.colIndex, row: targetCell.rowIndex },
190
+ end: {
191
+ col: { type: "number", value: targetCell.colIndex },
192
+ row: { type: "number", value: targetCell.rowIndex }
193
+ }
194
+ }
195
+ }
196
+ ],
197
+ style: style.style
198
+ };
199
+ this.styleManager.addCellStyle(newStyle);
200
+ }
201
+ }
202
+ if (snapshot.matchingConditionalStyles) {
203
+ for (const style of snapshot.matchingConditionalStyles) {
204
+ const newStyle = {
205
+ areas: [
206
+ {
207
+ workbookName: targetCell.workbookName,
208
+ sheetName: targetCell.sheetName,
209
+ range: {
210
+ start: { col: targetCell.colIndex, row: targetCell.rowIndex },
211
+ end: {
212
+ col: { type: "number", value: targetCell.colIndex },
213
+ row: { type: "number", value: targetCell.rowIndex }
214
+ }
215
+ }
216
+ }
217
+ ],
218
+ condition: style.condition
219
+ };
220
+ this.styleManager.addConditionalStyle(newStyle);
221
+ }
222
+ }
223
+ }
224
+ copyCellContentFromSnapshot(snapshot, targetCell, sourceTopLeft, options) {
225
+ if (!snapshot.content) {
226
+ return;
227
+ }
228
+ let targetContent;
229
+ const copyType = options.type ?? "formula";
230
+ if (copyType === "value") {
231
+ const evalResult = this.evaluationManager.getCellEvaluationResult(snapshot.address);
232
+ if (!evalResult || evalResult.type !== "value") {
233
+ targetContent = snapshot.content;
234
+ } else {
235
+ const result = evalResult.result;
236
+ if (result.type === "number") {
237
+ targetContent = result.value;
238
+ } else if (result.type === "string") {
239
+ targetContent = result.value;
240
+ } else if (result.type === "boolean") {
241
+ targetContent = result.value;
242
+ } else {
243
+ targetContent = snapshot.content;
244
+ }
245
+ }
246
+ } else {
247
+ if (typeof snapshot.content === "string" && snapshot.content.startsWith("=")) {
248
+ targetContent = this.adjustFormulaReferences(snapshot.content, {
249
+ colIndex: snapshot.address.colIndex,
250
+ rowIndex: snapshot.address.rowIndex
251
+ }, {
252
+ colIndex: targetCell.colIndex,
253
+ rowIndex: targetCell.rowIndex
254
+ });
255
+ } else {
256
+ targetContent = snapshot.content;
257
+ }
258
+ }
259
+ const targetSheet = this.workbookManager.getSheet({
260
+ workbookName: targetCell.workbookName,
261
+ sheetName: targetCell.sheetName
262
+ });
263
+ if (targetSheet) {
264
+ const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${targetCell.rowIndex + 1}`;
265
+ targetSheet.content.set(targetKey, targetContent);
266
+ }
267
+ if (this.shouldInclude(options, "metadata")) {
268
+ if (snapshot.metadata) {
269
+ this.workbookManager.setCellMetadata(targetCell, {
270
+ ...snapshot.metadata
271
+ });
272
+ } else {
273
+ this.workbookManager.setCellMetadata(targetCell, undefined);
274
+ }
275
+ }
276
+ }
54
277
  copyCellContent(sourceCell, targetCell, sourceTopLeft, options) {
55
278
  const sheet = this.workbookManager.getSheet({
56
279
  workbookName: sourceCell.workbookName,
@@ -65,7 +288,8 @@ class CopyManager {
65
288
  return;
66
289
  }
67
290
  let targetContent;
68
- if (options.type === "value") {
291
+ const copyType = options.type ?? "formula";
292
+ if (copyType === "value") {
69
293
  const evalResult = this.evaluationManager.getCellEvaluationResult(sourceCell);
70
294
  if (!evalResult || evalResult.type !== "value") {
71
295
  targetContent = cellContent;
@@ -102,6 +326,14 @@ class CopyManager {
102
326
  const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${targetCell.rowIndex + 1}`;
103
327
  targetSheet.content.set(targetKey, targetContent);
104
328
  }
329
+ if (this.shouldInclude(options, "metadata")) {
330
+ const sourceMetadata = this.workbookManager.getCellMetadata(sourceCell);
331
+ if (sourceMetadata) {
332
+ this.workbookManager.setCellMetadata(targetCell, { ...sourceMetadata });
333
+ } else {
334
+ this.workbookManager.setCellMetadata(targetCell, undefined);
335
+ }
336
+ }
105
337
  }
106
338
  adjustFormulaReferences(formula, sourceAddress, targetAddress) {
107
339
  try {
@@ -159,34 +391,42 @@ class CopyManager {
159
391
  const allConditionalStyles = this.styleManager.getAllConditionalStyles();
160
392
  const allCellStyles = this.styleManager.getAllCellStyles();
161
393
  for (const style of allConditionalStyles) {
162
- if (style.area.workbookName === sourceTopLeft.workbookName && style.area.sheetName === sourceTopLeft.sheetName) {
163
- const intersection = intersectRanges(style.area.range, sourceRange);
164
- if (intersection) {
165
- const newStyle = {
166
- area: {
167
- workbookName: target.workbookName,
168
- sheetName: target.sheetName,
169
- range: this.adjustRange(intersection, rowOffset, colOffset)
170
- },
171
- condition: style.condition
172
- };
173
- this.styleManager.addConditionalStyle(newStyle);
394
+ for (const area of style.areas) {
395
+ if (area.workbookName === sourceTopLeft.workbookName && area.sheetName === sourceTopLeft.sheetName) {
396
+ const intersection = intersectRanges(area.range, sourceRange);
397
+ if (intersection) {
398
+ const newStyle = {
399
+ areas: [
400
+ {
401
+ workbookName: target.workbookName,
402
+ sheetName: target.sheetName,
403
+ range: this.adjustRange(intersection, rowOffset, colOffset)
404
+ }
405
+ ],
406
+ condition: style.condition
407
+ };
408
+ this.styleManager.addConditionalStyle(newStyle);
409
+ }
174
410
  }
175
411
  }
176
412
  }
177
413
  for (const style of allCellStyles) {
178
- if (style.area.workbookName === sourceTopLeft.workbookName && style.area.sheetName === sourceTopLeft.sheetName) {
179
- const intersection = intersectRanges(style.area.range, sourceRange);
180
- if (intersection) {
181
- const newStyle = {
182
- area: {
183
- workbookName: target.workbookName,
184
- sheetName: target.sheetName,
185
- range: this.adjustRange(intersection, rowOffset, colOffset)
186
- },
187
- style: style.style
188
- };
189
- this.styleManager.addCellStyle(newStyle);
414
+ for (const area of style.areas) {
415
+ if (area.workbookName === sourceTopLeft.workbookName && area.sheetName === sourceTopLeft.sheetName) {
416
+ const intersection = intersectRanges(area.range, sourceRange);
417
+ if (intersection) {
418
+ const newStyle = {
419
+ areas: [
420
+ {
421
+ workbookName: target.workbookName,
422
+ sheetName: target.sheetName,
423
+ range: this.adjustRange(intersection, rowOffset, colOffset)
424
+ }
425
+ ],
426
+ style: style.style
427
+ };
428
+ this.styleManager.addCellStyle(newStyle);
429
+ }
190
430
  }
191
431
  }
192
432
  }
@@ -224,22 +464,15 @@ class CopyManager {
224
464
  }
225
465
  clearSourceCells(cells) {
226
466
  for (const cell of cells) {
227
- const sheet = this.workbookManager.getSheet({
228
- workbookName: cell.workbookName,
229
- sheetName: cell.sheetName
230
- });
231
- if (sheet) {
232
- const key = `${String.fromCharCode(65 + cell.colIndex)}${cell.rowIndex + 1}`;
233
- sheet.content.delete(key);
234
- }
467
+ this.workbookManager.setCellContent(cell, "");
235
468
  }
236
469
  }
237
470
  fillAreas(seedRange, targetRanges, options) {
238
471
  for (const targetRange of targetRanges) {
239
472
  this.fillRangeWithSeed(seedRange, targetRange, {
240
- copyContent: options.target !== "style",
241
- copyStyles: options.target === "all" || options.target === "style",
242
- contentType: options.type,
473
+ copyContent: this.shouldInclude(options, "content"),
474
+ copyStyles: this.shouldInclude(options, "style"),
475
+ contentType: options.type ?? "formula",
243
476
  adjustFormulas: true
244
477
  });
245
478
  }
@@ -275,7 +508,7 @@ class CopyManager {
275
508
  this.copyCellContentWithOffset(seedCell, targetCell, rowDelta, colDelta, {
276
509
  type: options.contentType,
277
510
  cut: false,
278
- target: "content"
511
+ include: ["content"]
279
512
  });
280
513
  }
281
514
  if (options.copyStyles) {
@@ -313,7 +546,7 @@ class CopyManager {
313
546
  this.copyCellContentWithOffset(sourceCell, targetCell, 0, colDelta, {
314
547
  type: options.contentType,
315
548
  cut: false,
316
- target: "content"
549
+ include: ["content"]
317
550
  });
318
551
  }
319
552
  if (options.copyStyles) {
@@ -386,7 +619,8 @@ class CopyManager {
386
619
  return;
387
620
  }
388
621
  let targetContent;
389
- if (options.type === "value") {
622
+ const copyType = options.type ?? "formula";
623
+ if (copyType === "value") {
390
624
  const evalResult = this.evaluationManager.getCellEvaluationResult(sourceCell);
391
625
  if (!evalResult || evalResult.type !== "value") {
392
626
  targetContent = cellContent;
@@ -417,6 +651,14 @@ class CopyManager {
417
651
  const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${targetCell.rowIndex + 1}`;
418
652
  targetSheet.content.set(targetKey, targetContent);
419
653
  }
654
+ if (this.shouldInclude(options, "metadata")) {
655
+ const sourceMetadata = this.workbookManager.getCellMetadata(sourceCell);
656
+ if (sourceMetadata) {
657
+ this.workbookManager.setCellMetadata(targetCell, { ...sourceMetadata });
658
+ } else {
659
+ this.workbookManager.setCellMetadata(targetCell, undefined);
660
+ }
661
+ }
420
662
  }
421
663
  adjustFormulaWithOffset(formula, rowDelta, colDelta) {
422
664
  try {
@@ -484,46 +726,60 @@ class CopyManager {
484
726
  }
485
727
  };
486
728
  for (const style of allConditionalStyles) {
487
- if (style.area.workbookName === sourceCell.workbookName && style.area.sheetName === sourceCell.sheetName) {
488
- const intersection = intersectRanges(style.area.range, sourceCellRange);
489
- if (intersection) {
490
- const newStyle = {
491
- area: {
492
- workbookName: targetCell.workbookName,
493
- sheetName: targetCell.sheetName,
494
- range: {
495
- start: { col: targetCell.colIndex, row: targetCell.rowIndex },
496
- end: {
497
- col: { type: "number", value: targetCell.colIndex },
498
- row: { type: "number", value: targetCell.rowIndex }
729
+ for (const area of style.areas) {
730
+ if (area.workbookName === sourceCell.workbookName && area.sheetName === sourceCell.sheetName) {
731
+ const intersection = intersectRanges(area.range, sourceCellRange);
732
+ if (intersection) {
733
+ const newStyle = {
734
+ areas: [
735
+ {
736
+ workbookName: targetCell.workbookName,
737
+ sheetName: targetCell.sheetName,
738
+ range: {
739
+ start: {
740
+ col: targetCell.colIndex,
741
+ row: targetCell.rowIndex
742
+ },
743
+ end: {
744
+ col: { type: "number", value: targetCell.colIndex },
745
+ row: { type: "number", value: targetCell.rowIndex }
746
+ }
747
+ }
499
748
  }
500
- }
501
- },
502
- condition: style.condition
503
- };
504
- this.styleManager.addConditionalStyle(newStyle);
749
+ ],
750
+ condition: style.condition
751
+ };
752
+ this.styleManager.addConditionalStyle(newStyle);
753
+ }
505
754
  }
506
755
  }
507
756
  }
508
757
  for (const style of allCellStyles) {
509
- if (style.area.workbookName === sourceCell.workbookName && style.area.sheetName === sourceCell.sheetName) {
510
- const intersection = intersectRanges(style.area.range, sourceCellRange);
511
- if (intersection) {
512
- const newStyle = {
513
- area: {
514
- workbookName: targetCell.workbookName,
515
- sheetName: targetCell.sheetName,
516
- range: {
517
- start: { col: targetCell.colIndex, row: targetCell.rowIndex },
518
- end: {
519
- col: { type: "number", value: targetCell.colIndex },
520
- row: { type: "number", value: targetCell.rowIndex }
758
+ for (const area of style.areas) {
759
+ if (area.workbookName === sourceCell.workbookName && area.sheetName === sourceCell.sheetName) {
760
+ const intersection = intersectRanges(area.range, sourceCellRange);
761
+ if (intersection) {
762
+ const newStyle = {
763
+ areas: [
764
+ {
765
+ workbookName: targetCell.workbookName,
766
+ sheetName: targetCell.sheetName,
767
+ range: {
768
+ start: {
769
+ col: targetCell.colIndex,
770
+ row: targetCell.rowIndex
771
+ },
772
+ end: {
773
+ col: { type: "number", value: targetCell.colIndex },
774
+ row: { type: "number", value: targetCell.rowIndex }
775
+ }
776
+ }
521
777
  }
522
- }
523
- },
524
- style: style.style
525
- };
526
- this.styleManager.addCellStyle(newStyle);
778
+ ],
779
+ style: style.style
780
+ };
781
+ this.styleManager.addCellStyle(newStyle);
782
+ }
527
783
  }
528
784
  }
529
785
  }
@@ -533,4 +789,4 @@ export {
533
789
  CopyManager
534
790
  };
535
791
 
536
- //# debugId=F29FAECECAA9837C64756E2164756E21
792
+ //# debugId=9E025649C6A89F3564756E2164756E21