@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
@@ -35,7 +35,9 @@ module.exports = __toCommonJS(exports_copy_manager);
35
35
  var import_parser = require("../../parser/parser.cjs");
36
36
  var import_formatter = require("../../parser/formatter.cjs");
37
37
  var import_ast_traverser = require("../ast-traverser.cjs");
38
+ var import_utils = require("../utils.cjs");
38
39
  var import_range_utils = require("../utils/range-utils.cjs");
40
+ var import_cell_mover = require("../cell-mover.cjs");
39
41
 
40
42
  class CopyManager {
41
43
  workbookManager;
@@ -46,30 +48,114 @@ class CopyManager {
46
48
  this.evaluationManager = evaluationManager;
47
49
  this.styleManager = styleManager;
48
50
  }
49
- copyCells(source, target, options) {
51
+ normalizeInclude(include) {
52
+ if (!include || include === "all") {
53
+ return ["content", "style", "metadata"];
54
+ }
55
+ return include;
56
+ }
57
+ shouldInclude(options, part) {
58
+ const normalized = this.normalizeInclude(options.include);
59
+ return normalized.includes(part);
60
+ }
61
+ pasteCells(source, target, options) {
50
62
  if (source.length === 0) {
51
63
  return;
52
64
  }
65
+ if (options.cut === true) {
66
+ return this.cutCells(source, target, options);
67
+ } else {
68
+ return this.copyOnlyCells(source, target, options);
69
+ }
70
+ }
71
+ cutCells(source, target, options) {
72
+ const topLeft = this.findTopLeft(source);
73
+ const rowOffset = target.rowIndex - topLeft.rowIndex;
74
+ const colOffset = target.colIndex - topLeft.colIndex;
75
+ const snapshot = this.snapshotCellsWithStyles(source);
76
+ this.clearSourceCells(source);
77
+ if (this.shouldInclude(options, "style")) {
78
+ for (const cell of source) {
79
+ const cellRange = {
80
+ workbookName: cell.workbookName,
81
+ sheetName: cell.sheetName,
82
+ range: {
83
+ start: { col: cell.colIndex, row: cell.rowIndex },
84
+ end: {
85
+ col: { type: "number", value: cell.colIndex },
86
+ row: { type: "number", value: cell.rowIndex }
87
+ }
88
+ }
89
+ };
90
+ this.styleManager.clearCellStylesInRange(cellRange);
91
+ }
92
+ }
93
+ const movedCellsSet = new Set(source.map((c) => `${c.workbookName}:${c.sheetName}:${c.colIndex}:${c.rowIndex}`));
94
+ const movedCellsInfo = {
95
+ cellsSet: movedCellsSet,
96
+ workbookName: topLeft.workbookName,
97
+ sheetName: topLeft.sheetName,
98
+ rowOffset,
99
+ colOffset
100
+ };
101
+ this.workbookManager.updateFormulasExcluding(movedCellsSet, (formula) => import_cell_mover.updateReferencesForMovedCells(formula, movedCellsInfo));
102
+ for (let i = 0;i < snapshot.length; i++) {
103
+ const snap = snapshot[i];
104
+ const sourceCell = source[i];
105
+ const targetCell = {
106
+ workbookName: target.workbookName,
107
+ sheetName: target.sheetName,
108
+ colIndex: sourceCell.colIndex + colOffset,
109
+ rowIndex: sourceCell.rowIndex + rowOffset
110
+ };
111
+ if (this.shouldInclude(options, "content") && snap.content) {
112
+ let targetContent = snap.content;
113
+ if (typeof snap.content === "string" && snap.content.startsWith("=")) {
114
+ targetContent = this.adjustFormulaReferences(snap.content, {
115
+ colIndex: snap.address.colIndex,
116
+ rowIndex: snap.address.rowIndex
117
+ }, {
118
+ colIndex: targetCell.colIndex,
119
+ rowIndex: targetCell.rowIndex
120
+ });
121
+ }
122
+ this.workbookManager.setCellContent(targetCell, targetContent);
123
+ }
124
+ if (this.shouldInclude(options, "metadata")) {
125
+ if (snap.metadata) {
126
+ this.workbookManager.setCellMetadata(targetCell, {
127
+ ...snap.metadata
128
+ });
129
+ } else {
130
+ this.workbookManager.setCellMetadata(targetCell, undefined);
131
+ }
132
+ }
133
+ if (this.shouldInclude(options, "style")) {
134
+ this.applyStylesFromSnapshot(snap, targetCell);
135
+ }
136
+ }
137
+ }
138
+ copyOnlyCells(source, target, options) {
53
139
  const topLeft = this.findTopLeft(source);
54
140
  const rowOffset = target.rowIndex - topLeft.rowIndex;
55
141
  const colOffset = target.colIndex - topLeft.colIndex;
56
- if (options.target !== "style") {
57
- for (const sourceCell of source) {
142
+ const snapshot = this.snapshotCells(source);
143
+ if (this.shouldInclude(options, "content")) {
144
+ for (let i = 0;i < source.length; i++) {
145
+ const sourceCell = source[i];
146
+ const cellSnapshot = snapshot[i];
58
147
  const targetCell = {
59
148
  workbookName: target.workbookName,
60
149
  sheetName: target.sheetName,
61
150
  colIndex: sourceCell.colIndex + colOffset,
62
151
  rowIndex: sourceCell.rowIndex + rowOffset
63
152
  };
64
- this.copyCellContent(sourceCell, targetCell, topLeft, options);
153
+ this.copyCellContentFromSnapshot(cellSnapshot, targetCell, topLeft, options);
65
154
  }
66
155
  }
67
- if (options.target === "all" || options.target === "style") {
156
+ if (this.shouldInclude(options, "style")) {
68
157
  this.copyFormatting(source, topLeft, target, rowOffset, colOffset);
69
158
  }
70
- if (options.cut) {
71
- this.clearSourceCells(source);
72
- }
73
159
  }
74
160
  findTopLeft(cells) {
75
161
  let minRow = Infinity;
@@ -84,6 +170,141 @@ class CopyManager {
84
170
  }
85
171
  return topLeftCell;
86
172
  }
173
+ snapshotCells(cells) {
174
+ return cells.map((cell) => {
175
+ const sheet = this.workbookManager.getSheet({
176
+ workbookName: cell.workbookName,
177
+ sheetName: cell.sheetName
178
+ });
179
+ const key = `${String.fromCharCode(65 + cell.colIndex)}${cell.rowIndex + 1}`;
180
+ const content = sheet?.content.get(key);
181
+ const metadata = this.workbookManager.getCellMetadata(cell);
182
+ return {
183
+ address: cell,
184
+ content,
185
+ metadata
186
+ };
187
+ });
188
+ }
189
+ snapshotCellsWithStyles(cells) {
190
+ const allCellStyles = this.styleManager.getAllCellStyles();
191
+ const allConditionalStyles = this.styleManager.getAllConditionalStyles();
192
+ return cells.map((cell) => {
193
+ const sheet = this.workbookManager.getSheet({
194
+ workbookName: cell.workbookName,
195
+ sheetName: cell.sheetName
196
+ });
197
+ const key = import_utils.getCellReference(cell);
198
+ const content = sheet?.content.get(key);
199
+ const metadata = this.workbookManager.getCellMetadata(cell);
200
+ const matchingCellStyles = allCellStyles.filter((style) => style.areas.some((area) => area.workbookName === cell.workbookName && area.sheetName === cell.sheetName && import_utils.isCellInRange(cell, area.range)));
201
+ const matchingConditionalStyles = allConditionalStyles.filter((style) => style.areas.some((area) => area.workbookName === cell.workbookName && area.sheetName === cell.sheetName && import_utils.isCellInRange(cell, area.range)));
202
+ return {
203
+ address: cell,
204
+ content,
205
+ metadata,
206
+ matchingCellStyles,
207
+ matchingConditionalStyles
208
+ };
209
+ });
210
+ }
211
+ applyStylesFromSnapshot(snapshot, targetCell) {
212
+ if (snapshot.matchingCellStyles) {
213
+ for (const style of snapshot.matchingCellStyles) {
214
+ const newStyle = {
215
+ areas: [
216
+ {
217
+ workbookName: targetCell.workbookName,
218
+ sheetName: targetCell.sheetName,
219
+ range: {
220
+ start: { col: targetCell.colIndex, row: targetCell.rowIndex },
221
+ end: {
222
+ col: { type: "number", value: targetCell.colIndex },
223
+ row: { type: "number", value: targetCell.rowIndex }
224
+ }
225
+ }
226
+ }
227
+ ],
228
+ style: style.style
229
+ };
230
+ this.styleManager.addCellStyle(newStyle);
231
+ }
232
+ }
233
+ if (snapshot.matchingConditionalStyles) {
234
+ for (const style of snapshot.matchingConditionalStyles) {
235
+ const newStyle = {
236
+ areas: [
237
+ {
238
+ workbookName: targetCell.workbookName,
239
+ sheetName: targetCell.sheetName,
240
+ range: {
241
+ start: { col: targetCell.colIndex, row: targetCell.rowIndex },
242
+ end: {
243
+ col: { type: "number", value: targetCell.colIndex },
244
+ row: { type: "number", value: targetCell.rowIndex }
245
+ }
246
+ }
247
+ }
248
+ ],
249
+ condition: style.condition
250
+ };
251
+ this.styleManager.addConditionalStyle(newStyle);
252
+ }
253
+ }
254
+ }
255
+ copyCellContentFromSnapshot(snapshot, targetCell, sourceTopLeft, options) {
256
+ if (!snapshot.content) {
257
+ return;
258
+ }
259
+ let targetContent;
260
+ const copyType = options.type ?? "formula";
261
+ if (copyType === "value") {
262
+ const evalResult = this.evaluationManager.getCellEvaluationResult(snapshot.address);
263
+ if (!evalResult || evalResult.type !== "value") {
264
+ targetContent = snapshot.content;
265
+ } else {
266
+ const result = evalResult.result;
267
+ if (result.type === "number") {
268
+ targetContent = result.value;
269
+ } else if (result.type === "string") {
270
+ targetContent = result.value;
271
+ } else if (result.type === "boolean") {
272
+ targetContent = result.value;
273
+ } else {
274
+ targetContent = snapshot.content;
275
+ }
276
+ }
277
+ } else {
278
+ if (typeof snapshot.content === "string" && snapshot.content.startsWith("=")) {
279
+ targetContent = this.adjustFormulaReferences(snapshot.content, {
280
+ colIndex: snapshot.address.colIndex,
281
+ rowIndex: snapshot.address.rowIndex
282
+ }, {
283
+ colIndex: targetCell.colIndex,
284
+ rowIndex: targetCell.rowIndex
285
+ });
286
+ } else {
287
+ targetContent = snapshot.content;
288
+ }
289
+ }
290
+ const targetSheet = this.workbookManager.getSheet({
291
+ workbookName: targetCell.workbookName,
292
+ sheetName: targetCell.sheetName
293
+ });
294
+ if (targetSheet) {
295
+ const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${targetCell.rowIndex + 1}`;
296
+ targetSheet.content.set(targetKey, targetContent);
297
+ }
298
+ if (this.shouldInclude(options, "metadata")) {
299
+ if (snapshot.metadata) {
300
+ this.workbookManager.setCellMetadata(targetCell, {
301
+ ...snapshot.metadata
302
+ });
303
+ } else {
304
+ this.workbookManager.setCellMetadata(targetCell, undefined);
305
+ }
306
+ }
307
+ }
87
308
  copyCellContent(sourceCell, targetCell, sourceTopLeft, options) {
88
309
  const sheet = this.workbookManager.getSheet({
89
310
  workbookName: sourceCell.workbookName,
@@ -98,7 +319,8 @@ class CopyManager {
98
319
  return;
99
320
  }
100
321
  let targetContent;
101
- if (options.type === "value") {
322
+ const copyType = options.type ?? "formula";
323
+ if (copyType === "value") {
102
324
  const evalResult = this.evaluationManager.getCellEvaluationResult(sourceCell);
103
325
  if (!evalResult || evalResult.type !== "value") {
104
326
  targetContent = cellContent;
@@ -135,6 +357,14 @@ class CopyManager {
135
357
  const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${targetCell.rowIndex + 1}`;
136
358
  targetSheet.content.set(targetKey, targetContent);
137
359
  }
360
+ if (this.shouldInclude(options, "metadata")) {
361
+ const sourceMetadata = this.workbookManager.getCellMetadata(sourceCell);
362
+ if (sourceMetadata) {
363
+ this.workbookManager.setCellMetadata(targetCell, { ...sourceMetadata });
364
+ } else {
365
+ this.workbookManager.setCellMetadata(targetCell, undefined);
366
+ }
367
+ }
138
368
  }
139
369
  adjustFormulaReferences(formula, sourceAddress, targetAddress) {
140
370
  try {
@@ -192,34 +422,42 @@ class CopyManager {
192
422
  const allConditionalStyles = this.styleManager.getAllConditionalStyles();
193
423
  const allCellStyles = this.styleManager.getAllCellStyles();
194
424
  for (const style of allConditionalStyles) {
195
- if (style.area.workbookName === sourceTopLeft.workbookName && style.area.sheetName === sourceTopLeft.sheetName) {
196
- const intersection = import_range_utils.intersectRanges(style.area.range, sourceRange);
197
- if (intersection) {
198
- const newStyle = {
199
- area: {
200
- workbookName: target.workbookName,
201
- sheetName: target.sheetName,
202
- range: this.adjustRange(intersection, rowOffset, colOffset)
203
- },
204
- condition: style.condition
205
- };
206
- this.styleManager.addConditionalStyle(newStyle);
425
+ for (const area of style.areas) {
426
+ if (area.workbookName === sourceTopLeft.workbookName && area.sheetName === sourceTopLeft.sheetName) {
427
+ const intersection = import_range_utils.intersectRanges(area.range, sourceRange);
428
+ if (intersection) {
429
+ const newStyle = {
430
+ areas: [
431
+ {
432
+ workbookName: target.workbookName,
433
+ sheetName: target.sheetName,
434
+ range: this.adjustRange(intersection, rowOffset, colOffset)
435
+ }
436
+ ],
437
+ condition: style.condition
438
+ };
439
+ this.styleManager.addConditionalStyle(newStyle);
440
+ }
207
441
  }
208
442
  }
209
443
  }
210
444
  for (const style of allCellStyles) {
211
- if (style.area.workbookName === sourceTopLeft.workbookName && style.area.sheetName === sourceTopLeft.sheetName) {
212
- const intersection = import_range_utils.intersectRanges(style.area.range, sourceRange);
213
- if (intersection) {
214
- const newStyle = {
215
- area: {
216
- workbookName: target.workbookName,
217
- sheetName: target.sheetName,
218
- range: this.adjustRange(intersection, rowOffset, colOffset)
219
- },
220
- style: style.style
221
- };
222
- this.styleManager.addCellStyle(newStyle);
445
+ for (const area of style.areas) {
446
+ if (area.workbookName === sourceTopLeft.workbookName && area.sheetName === sourceTopLeft.sheetName) {
447
+ const intersection = import_range_utils.intersectRanges(area.range, sourceRange);
448
+ if (intersection) {
449
+ const newStyle = {
450
+ areas: [
451
+ {
452
+ workbookName: target.workbookName,
453
+ sheetName: target.sheetName,
454
+ range: this.adjustRange(intersection, rowOffset, colOffset)
455
+ }
456
+ ],
457
+ style: style.style
458
+ };
459
+ this.styleManager.addCellStyle(newStyle);
460
+ }
223
461
  }
224
462
  }
225
463
  }
@@ -257,22 +495,15 @@ class CopyManager {
257
495
  }
258
496
  clearSourceCells(cells) {
259
497
  for (const cell of cells) {
260
- const sheet = this.workbookManager.getSheet({
261
- workbookName: cell.workbookName,
262
- sheetName: cell.sheetName
263
- });
264
- if (sheet) {
265
- const key = `${String.fromCharCode(65 + cell.colIndex)}${cell.rowIndex + 1}`;
266
- sheet.content.delete(key);
267
- }
498
+ this.workbookManager.setCellContent(cell, "");
268
499
  }
269
500
  }
270
501
  fillAreas(seedRange, targetRanges, options) {
271
502
  for (const targetRange of targetRanges) {
272
503
  this.fillRangeWithSeed(seedRange, targetRange, {
273
- copyContent: options.target !== "style",
274
- copyStyles: options.target === "all" || options.target === "style",
275
- contentType: options.type,
504
+ copyContent: this.shouldInclude(options, "content"),
505
+ copyStyles: this.shouldInclude(options, "style"),
506
+ contentType: options.type ?? "formula",
276
507
  adjustFormulas: true
277
508
  });
278
509
  }
@@ -308,7 +539,7 @@ class CopyManager {
308
539
  this.copyCellContentWithOffset(seedCell, targetCell, rowDelta, colDelta, {
309
540
  type: options.contentType,
310
541
  cut: false,
311
- target: "content"
542
+ include: ["content"]
312
543
  });
313
544
  }
314
545
  if (options.copyStyles) {
@@ -346,7 +577,7 @@ class CopyManager {
346
577
  this.copyCellContentWithOffset(sourceCell, targetCell, 0, colDelta, {
347
578
  type: options.contentType,
348
579
  cut: false,
349
- target: "content"
580
+ include: ["content"]
350
581
  });
351
582
  }
352
583
  if (options.copyStyles) {
@@ -419,7 +650,8 @@ class CopyManager {
419
650
  return;
420
651
  }
421
652
  let targetContent;
422
- if (options.type === "value") {
653
+ const copyType = options.type ?? "formula";
654
+ if (copyType === "value") {
423
655
  const evalResult = this.evaluationManager.getCellEvaluationResult(sourceCell);
424
656
  if (!evalResult || evalResult.type !== "value") {
425
657
  targetContent = cellContent;
@@ -450,6 +682,14 @@ class CopyManager {
450
682
  const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${targetCell.rowIndex + 1}`;
451
683
  targetSheet.content.set(targetKey, targetContent);
452
684
  }
685
+ if (this.shouldInclude(options, "metadata")) {
686
+ const sourceMetadata = this.workbookManager.getCellMetadata(sourceCell);
687
+ if (sourceMetadata) {
688
+ this.workbookManager.setCellMetadata(targetCell, { ...sourceMetadata });
689
+ } else {
690
+ this.workbookManager.setCellMetadata(targetCell, undefined);
691
+ }
692
+ }
453
693
  }
454
694
  adjustFormulaWithOffset(formula, rowDelta, colDelta) {
455
695
  try {
@@ -517,50 +757,64 @@ class CopyManager {
517
757
  }
518
758
  };
519
759
  for (const style of allConditionalStyles) {
520
- if (style.area.workbookName === sourceCell.workbookName && style.area.sheetName === sourceCell.sheetName) {
521
- const intersection = import_range_utils.intersectRanges(style.area.range, sourceCellRange);
522
- if (intersection) {
523
- const newStyle = {
524
- area: {
525
- workbookName: targetCell.workbookName,
526
- sheetName: targetCell.sheetName,
527
- range: {
528
- start: { col: targetCell.colIndex, row: targetCell.rowIndex },
529
- end: {
530
- col: { type: "number", value: targetCell.colIndex },
531
- row: { type: "number", value: targetCell.rowIndex }
760
+ for (const area of style.areas) {
761
+ if (area.workbookName === sourceCell.workbookName && area.sheetName === sourceCell.sheetName) {
762
+ const intersection = import_range_utils.intersectRanges(area.range, sourceCellRange);
763
+ if (intersection) {
764
+ const newStyle = {
765
+ areas: [
766
+ {
767
+ workbookName: targetCell.workbookName,
768
+ sheetName: targetCell.sheetName,
769
+ range: {
770
+ start: {
771
+ col: targetCell.colIndex,
772
+ row: targetCell.rowIndex
773
+ },
774
+ end: {
775
+ col: { type: "number", value: targetCell.colIndex },
776
+ row: { type: "number", value: targetCell.rowIndex }
777
+ }
778
+ }
532
779
  }
533
- }
534
- },
535
- condition: style.condition
536
- };
537
- this.styleManager.addConditionalStyle(newStyle);
780
+ ],
781
+ condition: style.condition
782
+ };
783
+ this.styleManager.addConditionalStyle(newStyle);
784
+ }
538
785
  }
539
786
  }
540
787
  }
541
788
  for (const style of allCellStyles) {
542
- if (style.area.workbookName === sourceCell.workbookName && style.area.sheetName === sourceCell.sheetName) {
543
- const intersection = import_range_utils.intersectRanges(style.area.range, sourceCellRange);
544
- if (intersection) {
545
- const newStyle = {
546
- area: {
547
- workbookName: targetCell.workbookName,
548
- sheetName: targetCell.sheetName,
549
- range: {
550
- start: { col: targetCell.colIndex, row: targetCell.rowIndex },
551
- end: {
552
- col: { type: "number", value: targetCell.colIndex },
553
- row: { type: "number", value: targetCell.rowIndex }
789
+ for (const area of style.areas) {
790
+ if (area.workbookName === sourceCell.workbookName && area.sheetName === sourceCell.sheetName) {
791
+ const intersection = import_range_utils.intersectRanges(area.range, sourceCellRange);
792
+ if (intersection) {
793
+ const newStyle = {
794
+ areas: [
795
+ {
796
+ workbookName: targetCell.workbookName,
797
+ sheetName: targetCell.sheetName,
798
+ range: {
799
+ start: {
800
+ col: targetCell.colIndex,
801
+ row: targetCell.rowIndex
802
+ },
803
+ end: {
804
+ col: { type: "number", value: targetCell.colIndex },
805
+ row: { type: "number", value: targetCell.rowIndex }
806
+ }
807
+ }
554
808
  }
555
- }
556
- },
557
- style: style.style
558
- };
559
- this.styleManager.addCellStyle(newStyle);
809
+ ],
810
+ style: style.style
811
+ };
812
+ this.styleManager.addCellStyle(newStyle);
813
+ }
560
814
  }
561
815
  }
562
816
  }
563
817
  }
564
818
  }
565
819
 
566
- //# debugId=9442C2DD8C5DC2E064756E2164756E21
820
+ //# debugId=566F5D8EB2A3D66C64756E2164756E21