@ricsam/formula-engine 0.0.13 → 0.0.14
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.
- package/dist/cjs/core/autofill-utils.cjs +95 -3
- package/dist/cjs/core/autofill-utils.cjs.map +3 -3
- package/dist/cjs/core/engine.cjs +76 -5
- package/dist/cjs/core/engine.cjs.map +3 -3
- package/dist/cjs/core/managers/copy-manager.cjs +280 -1
- package/dist/cjs/core/managers/copy-manager.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/core/autofill-utils.mjs +95 -3
- package/dist/mjs/core/autofill-utils.mjs.map +3 -3
- package/dist/mjs/core/engine.mjs +76 -5
- package/dist/mjs/core/engine.mjs.map +3 -3
- package/dist/mjs/core/managers/copy-manager.mjs +280 -1
- package/dist/mjs/core/managers/copy-manager.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/types/core/autofill-utils.d.ts +12 -2
- package/dist/types/core/engine.d.ts +72 -5
- package/dist/types/core/managers/copy-manager.d.ts +39 -2
- package/package.json +1 -1
|
@@ -228,9 +228,288 @@ class CopyManager {
|
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
|
+
fillAreas(seedRange, targetRanges, options) {
|
|
232
|
+
for (const targetRange of targetRanges) {
|
|
233
|
+
this.fillRangeWithSeed(seedRange, targetRange, {
|
|
234
|
+
copyContent: options.target !== "style",
|
|
235
|
+
copyStyles: options.target === "all" || options.target === "style",
|
|
236
|
+
contentType: options.type,
|
|
237
|
+
adjustFormulas: true
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
if (options.cut) {
|
|
241
|
+
const seedCells = this.expandRangeToCells(seedRange);
|
|
242
|
+
this.clearSourceCells(seedCells);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
fillRangeWithSeed(seedRange, targetRange, options) {
|
|
246
|
+
const seedCells = this.expandRangeToCells(seedRange);
|
|
247
|
+
const seedWidth = this.getRangeWidth(seedRange);
|
|
248
|
+
const seedHeight = this.getRangeHeight(seedRange);
|
|
249
|
+
const targetWidth = this.getRangeWidth(targetRange);
|
|
250
|
+
const targetHeight = this.getRangeHeight(targetRange);
|
|
251
|
+
const filledColumns = new Map;
|
|
252
|
+
for (let col = 0;col < seedWidth; col++) {
|
|
253
|
+
for (let row = 0;row < targetHeight; row++) {
|
|
254
|
+
const seedRow = row % seedHeight;
|
|
255
|
+
const seedCell = seedCells.find((c) => c.colIndex === seedRange.range.start.col + col && c.rowIndex === seedRange.range.start.row + seedRow);
|
|
256
|
+
if (seedCell) {
|
|
257
|
+
const targetCell = {
|
|
258
|
+
workbookName: targetRange.workbookName,
|
|
259
|
+
sheetName: targetRange.sheetName,
|
|
260
|
+
colIndex: targetRange.range.start.col + col,
|
|
261
|
+
rowIndex: targetRange.range.start.row + row
|
|
262
|
+
};
|
|
263
|
+
const rowDelta = targetCell.rowIndex - seedCell.rowIndex;
|
|
264
|
+
const colDelta = targetCell.colIndex - seedCell.colIndex;
|
|
265
|
+
if (options.copyContent) {
|
|
266
|
+
this.copyCellContentWithOffset(seedCell, targetCell, rowDelta, colDelta, {
|
|
267
|
+
type: options.contentType,
|
|
268
|
+
cut: false,
|
|
269
|
+
target: "content"
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
if (options.copyStyles) {
|
|
273
|
+
this.copyCellFormatting(seedCell, targetCell);
|
|
274
|
+
}
|
|
275
|
+
const key = `${targetCell.colIndex}-${targetCell.rowIndex}`;
|
|
276
|
+
const sheet = this.workbookManager.getSheet({
|
|
277
|
+
workbookName: targetCell.workbookName,
|
|
278
|
+
sheetName: targetCell.sheetName
|
|
279
|
+
});
|
|
280
|
+
const cellKey = `${String.fromCharCode(65 + targetCell.colIndex)}${targetCell.rowIndex + 1}`;
|
|
281
|
+
const content = sheet?.content.get(cellKey) || "";
|
|
282
|
+
filledColumns.set(key, { cell: targetCell, content });
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (targetWidth > seedWidth) {
|
|
287
|
+
for (let col = seedWidth;col < targetWidth; col++) {
|
|
288
|
+
const sourceCol = col % seedWidth;
|
|
289
|
+
for (let row = 0;row < targetHeight; row++) {
|
|
290
|
+
const sourceCell = {
|
|
291
|
+
workbookName: targetRange.workbookName,
|
|
292
|
+
sheetName: targetRange.sheetName,
|
|
293
|
+
colIndex: targetRange.range.start.col + sourceCol,
|
|
294
|
+
rowIndex: targetRange.range.start.row + row
|
|
295
|
+
};
|
|
296
|
+
const targetCell = {
|
|
297
|
+
workbookName: targetRange.workbookName,
|
|
298
|
+
sheetName: targetRange.sheetName,
|
|
299
|
+
colIndex: targetRange.range.start.col + col,
|
|
300
|
+
rowIndex: targetRange.range.start.row + row
|
|
301
|
+
};
|
|
302
|
+
const colDelta = targetCell.colIndex - sourceCell.colIndex;
|
|
303
|
+
if (options.copyContent) {
|
|
304
|
+
this.copyCellContentWithOffset(sourceCell, targetCell, 0, colDelta, {
|
|
305
|
+
type: options.contentType,
|
|
306
|
+
cut: false,
|
|
307
|
+
target: "content"
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
if (options.copyStyles) {
|
|
311
|
+
this.copyCellFormatting(sourceCell, targetCell);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
getRangeWidth(range) {
|
|
318
|
+
if (range.range.end.col.type === "infinity") {
|
|
319
|
+
return 100;
|
|
320
|
+
}
|
|
321
|
+
return range.range.end.col.value - range.range.start.col + 1;
|
|
322
|
+
}
|
|
323
|
+
getRangeHeight(range) {
|
|
324
|
+
if (range.range.end.row.type === "infinity") {
|
|
325
|
+
return 100;
|
|
326
|
+
}
|
|
327
|
+
return range.range.end.row.value - range.range.start.row + 1;
|
|
328
|
+
}
|
|
329
|
+
expandRangeToCells(rangeAddress) {
|
|
330
|
+
const { workbookName, sheetName, range } = rangeAddress;
|
|
331
|
+
const cells = [];
|
|
332
|
+
const startCol = range.start.col;
|
|
333
|
+
const startRow = range.start.row;
|
|
334
|
+
let endCol;
|
|
335
|
+
if (range.end.col.type === "infinity") {
|
|
336
|
+
endCol = startCol + 99;
|
|
337
|
+
} else {
|
|
338
|
+
endCol = range.end.col.value;
|
|
339
|
+
}
|
|
340
|
+
let endRow;
|
|
341
|
+
if (range.end.row.type === "infinity") {
|
|
342
|
+
endRow = startRow + 99;
|
|
343
|
+
} else {
|
|
344
|
+
endRow = range.end.row.value;
|
|
345
|
+
}
|
|
346
|
+
for (let row = startRow;row <= endRow; row++) {
|
|
347
|
+
for (let col = startCol;col <= endCol; col++) {
|
|
348
|
+
cells.push({
|
|
349
|
+
workbookName,
|
|
350
|
+
sheetName,
|
|
351
|
+
colIndex: col,
|
|
352
|
+
rowIndex: row
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return cells;
|
|
357
|
+
}
|
|
358
|
+
copyCellContentWithOffset(sourceCell, targetCell, rowDelta, colDelta, options) {
|
|
359
|
+
const sheet = this.workbookManager.getSheet({
|
|
360
|
+
workbookName: sourceCell.workbookName,
|
|
361
|
+
sheetName: sourceCell.sheetName
|
|
362
|
+
});
|
|
363
|
+
if (!sheet) {
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const key = `${String.fromCharCode(65 + sourceCell.colIndex)}${sourceCell.rowIndex + 1}`;
|
|
367
|
+
const cellContent = sheet.content.get(key);
|
|
368
|
+
if (!cellContent) {
|
|
369
|
+
const targetSheet2 = this.workbookManager.getSheet({
|
|
370
|
+
workbookName: targetCell.workbookName,
|
|
371
|
+
sheetName: targetCell.sheetName
|
|
372
|
+
});
|
|
373
|
+
if (targetSheet2) {
|
|
374
|
+
const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${targetCell.rowIndex + 1}`;
|
|
375
|
+
targetSheet2.content.delete(targetKey);
|
|
376
|
+
}
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
let targetContent;
|
|
380
|
+
if (options.type === "value") {
|
|
381
|
+
const evalResult = this.evaluationManager.getCellEvaluationResult(sourceCell);
|
|
382
|
+
if (!evalResult || evalResult.type !== "value") {
|
|
383
|
+
targetContent = cellContent;
|
|
384
|
+
} else {
|
|
385
|
+
const result = evalResult.result;
|
|
386
|
+
if (result.type === "number") {
|
|
387
|
+
targetContent = result.value;
|
|
388
|
+
} else if (result.type === "string") {
|
|
389
|
+
targetContent = result.value;
|
|
390
|
+
} else if (result.type === "boolean") {
|
|
391
|
+
targetContent = result.value;
|
|
392
|
+
} else {
|
|
393
|
+
targetContent = cellContent;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
} else {
|
|
397
|
+
if (typeof cellContent === "string" && cellContent.startsWith("=")) {
|
|
398
|
+
targetContent = this.adjustFormulaWithOffset(cellContent, rowDelta, colDelta);
|
|
399
|
+
} else {
|
|
400
|
+
targetContent = cellContent;
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
const targetSheet = this.workbookManager.getSheet({
|
|
404
|
+
workbookName: targetCell.workbookName,
|
|
405
|
+
sheetName: targetCell.sheetName
|
|
406
|
+
});
|
|
407
|
+
if (targetSheet) {
|
|
408
|
+
const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${targetCell.rowIndex + 1}`;
|
|
409
|
+
targetSheet.content.set(targetKey, targetContent);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
adjustFormulaWithOffset(formula, rowDelta, colDelta) {
|
|
413
|
+
try {
|
|
414
|
+
const ast = parseFormula(formula.slice(1));
|
|
415
|
+
const adjustedAst = transformAST(ast, (node) => {
|
|
416
|
+
if (node.type === "reference") {
|
|
417
|
+
const refNode = node;
|
|
418
|
+
return {
|
|
419
|
+
...refNode,
|
|
420
|
+
address: {
|
|
421
|
+
colIndex: refNode.isAbsolute.col ? refNode.address.colIndex : refNode.address.colIndex + colDelta,
|
|
422
|
+
rowIndex: refNode.isAbsolute.row ? refNode.address.rowIndex : refNode.address.rowIndex + rowDelta
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
} else if (node.type === "range") {
|
|
426
|
+
const rangeNode = node;
|
|
427
|
+
return {
|
|
428
|
+
...rangeNode,
|
|
429
|
+
range: {
|
|
430
|
+
start: {
|
|
431
|
+
col: rangeNode.isAbsolute.start.col ? rangeNode.range.start.col : rangeNode.range.start.col + colDelta,
|
|
432
|
+
row: rangeNode.isAbsolute.start.row ? rangeNode.range.start.row : rangeNode.range.start.row + rowDelta
|
|
433
|
+
},
|
|
434
|
+
end: {
|
|
435
|
+
col: rangeNode.range.end.col.type === "number" ? rangeNode.isAbsolute.end.col ? rangeNode.range.end.col : {
|
|
436
|
+
type: "number",
|
|
437
|
+
value: rangeNode.range.end.col.value + colDelta
|
|
438
|
+
} : rangeNode.range.end.col,
|
|
439
|
+
row: rangeNode.range.end.row.type === "number" ? rangeNode.isAbsolute.end.row ? rangeNode.range.end.row : {
|
|
440
|
+
type: "number",
|
|
441
|
+
value: rangeNode.range.end.row.value + rowDelta
|
|
442
|
+
} : rangeNode.range.end.row
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
return node;
|
|
448
|
+
});
|
|
449
|
+
return `=${astToString(adjustedAst)}`;
|
|
450
|
+
} catch (error) {
|
|
451
|
+
console.warn("Failed to adjust formula with offset:", error);
|
|
452
|
+
return formula;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
copyCellFormatting(sourceCell, targetCell) {
|
|
456
|
+
const allConditionalStyles = this.styleManager.getAllConditionalStyles();
|
|
457
|
+
const allCellStyles = this.styleManager.getAllCellStyles();
|
|
458
|
+
const sourceCellRange = {
|
|
459
|
+
start: { col: sourceCell.colIndex, row: sourceCell.rowIndex },
|
|
460
|
+
end: {
|
|
461
|
+
col: { type: "number", value: sourceCell.colIndex },
|
|
462
|
+
row: { type: "number", value: sourceCell.rowIndex }
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
for (const style of allConditionalStyles) {
|
|
466
|
+
if (style.area.workbookName === sourceCell.workbookName && style.area.sheetName === sourceCell.sheetName) {
|
|
467
|
+
const intersection = intersectRanges(style.area.range, sourceCellRange);
|
|
468
|
+
if (intersection) {
|
|
469
|
+
const newStyle = {
|
|
470
|
+
area: {
|
|
471
|
+
workbookName: targetCell.workbookName,
|
|
472
|
+
sheetName: targetCell.sheetName,
|
|
473
|
+
range: {
|
|
474
|
+
start: { col: targetCell.colIndex, row: targetCell.rowIndex },
|
|
475
|
+
end: {
|
|
476
|
+
col: { type: "number", value: targetCell.colIndex },
|
|
477
|
+
row: { type: "number", value: targetCell.rowIndex }
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
},
|
|
481
|
+
condition: style.condition
|
|
482
|
+
};
|
|
483
|
+
this.styleManager.addConditionalStyle(newStyle);
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
for (const style of allCellStyles) {
|
|
488
|
+
if (style.area.workbookName === sourceCell.workbookName && style.area.sheetName === sourceCell.sheetName) {
|
|
489
|
+
const intersection = intersectRanges(style.area.range, sourceCellRange);
|
|
490
|
+
if (intersection) {
|
|
491
|
+
const newStyle = {
|
|
492
|
+
area: {
|
|
493
|
+
workbookName: targetCell.workbookName,
|
|
494
|
+
sheetName: targetCell.sheetName,
|
|
495
|
+
range: {
|
|
496
|
+
start: { col: targetCell.colIndex, row: targetCell.rowIndex },
|
|
497
|
+
end: {
|
|
498
|
+
col: { type: "number", value: targetCell.colIndex },
|
|
499
|
+
row: { type: "number", value: targetCell.rowIndex }
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
},
|
|
503
|
+
style: style.style
|
|
504
|
+
};
|
|
505
|
+
this.styleManager.addCellStyle(newStyle);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
231
510
|
}
|
|
232
511
|
export {
|
|
233
512
|
CopyManager
|
|
234
513
|
};
|
|
235
514
|
|
|
236
|
-
//# debugId=
|
|
515
|
+
//# debugId=D487B5F6392E0DE264756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/core/managers/copy-manager.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * CopyManager - Manages cell copy/paste operations\n */\n\nimport type {\n CellAddress,\n CopyCellsOptions,\n ConditionalStyle,\n DirectCellStyle,\n LocalCellAddress,\n SerializedCellValue,\n SpreadsheetRange,\n} from \"../types.mjs\";\nimport type { WorkbookManager } from \"./workbook-manager.mjs\";\nimport type { EvaluationManager } from \"./evaluation-manager.mjs\";\nimport type { StyleManager } from \"./style-manager.mjs\";\nimport { parseFormula } from \"../../parser/parser.mjs\";\nimport { astToString } from \"../../parser/formatter.mjs\";\nimport { transformAST } from \"../ast-traverser.mjs\";\nimport type { ReferenceNode, RangeNode } from \"../../parser/ast.mjs\";\nimport { isCellInRange } from \"../utils.mjs\";\nimport { intersectRanges } from \"../utils/range-utils.mjs\";\n\nexport class CopyManager {\n constructor(\n private workbookManager: WorkbookManager,\n private evaluationManager: EvaluationManager,\n private styleManager: StyleManager\n ) {}\n\n /**\n * Copy cells from source to target\n */\n copyCells(\n source: CellAddress[],\n target: CellAddress,\n options: CopyCellsOptions\n ): void {\n if (source.length === 0) {\n return;\n }\n\n // Find top-left cell of source (minimum row/col indices)\n const topLeft = this.findTopLeft(source);\n\n // Calculate offset from source top-left to target\n const rowOffset = target.rowIndex - topLeft.rowIndex;\n const colOffset = target.colIndex - topLeft.colIndex;\n\n // Copy cell contents (skip if only copying style)\n if (options.target !== 'style') {\n for (const sourceCell of source) {\n const targetCell: CellAddress = {\n workbookName: target.workbookName,\n sheetName: target.sheetName,\n colIndex: sourceCell.colIndex + colOffset,\n rowIndex: sourceCell.rowIndex + rowOffset,\n };\n\n this.copyCellContent(sourceCell, targetCell, topLeft, options);\n }\n }\n\n // Copy formatting if requested\n if (options.target === 'all' || options.target === 'style') {\n this.copyFormatting(source, topLeft, target, rowOffset, colOffset);\n }\n\n // Clear source cells if cut\n if (options.cut) {\n this.clearSourceCells(source);\n }\n }\n\n /**\n * Find the top-left cell (minimum row/col indices)\n */\n private findTopLeft(cells: CellAddress[]): CellAddress {\n let minRow = Infinity;\n let minCol = Infinity;\n let topLeftCell = cells[0]!;\n\n for (const cell of cells) {\n if (\n cell.rowIndex < minRow ||\n (cell.rowIndex === minRow && cell.colIndex < minCol)\n ) {\n minRow = cell.rowIndex;\n minCol = cell.colIndex;\n topLeftCell = cell;\n }\n }\n\n return topLeftCell;\n }\n\n /**\n * Copy content from one cell to another\n */\n private copyCellContent(\n sourceCell: CellAddress,\n targetCell: CellAddress,\n sourceTopLeft: CellAddress,\n options: CopyCellsOptions\n ): void {\n const sheet = this.workbookManager.getSheet({\n workbookName: sourceCell.workbookName,\n sheetName: sourceCell.sheetName,\n });\n\n if (!sheet) {\n return;\n }\n\n const key = `${String.fromCharCode(65 + sourceCell.colIndex)}${\n sourceCell.rowIndex + 1\n }`;\n const cellContent = sheet.content.get(key);\n\n if (!cellContent) {\n // Source cell is empty\n return;\n }\n\n let targetContent: SerializedCellValue;\n\n if (options.type === \"value\") {\n // Copy evaluated value\n const evalResult = this.evaluationManager.getCellEvaluationResult(sourceCell);\n \n if (!evalResult || evalResult.type !== \"value\") {\n // If evaluation failed or is not a value, copy as-is\n targetContent = cellContent;\n } else {\n // Convert to literal value\n const result = evalResult.result;\n if (result.type === \"number\") {\n targetContent = result.value;\n } else if (result.type === \"string\") {\n targetContent = result.value;\n } else if (result.type === \"boolean\") {\n targetContent = result.value;\n } else {\n // Error or other type, copy as-is\n targetContent = cellContent;\n }\n }\n } else {\n // Copy formula\n if (typeof cellContent === \"string\" && cellContent.startsWith(\"=\")) {\n // Adjust formula references\n targetContent = this.adjustFormulaReferences(\n cellContent,\n {\n colIndex: sourceCell.colIndex,\n rowIndex: sourceCell.rowIndex,\n },\n {\n colIndex: targetCell.colIndex,\n rowIndex: targetCell.rowIndex,\n }\n );\n } else {\n // Not a formula, copy as-is\n targetContent = cellContent;\n }\n }\n\n // Set target cell content (using the engine's method through workbook manager)\n const targetSheet = this.workbookManager.getSheet({\n workbookName: targetCell.workbookName,\n sheetName: targetCell.sheetName,\n });\n\n if (targetSheet) {\n const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${\n targetCell.rowIndex + 1\n }`;\n targetSheet.content.set(targetKey, targetContent);\n }\n }\n\n /**\n * Adjust formula references when copying\n * Based on autofill-utils.ts adjustFormulaReferences\n */\n private adjustFormulaReferences(\n formula: string,\n sourceAddress: LocalCellAddress,\n targetAddress: LocalCellAddress\n ): string {\n try {\n const ast = parseFormula(formula.slice(1)); // Remove the \"=\" sign\n\n const rowDelta = targetAddress.rowIndex - sourceAddress.rowIndex;\n const colDelta = targetAddress.colIndex - sourceAddress.colIndex;\n\n const adjustedAst = transformAST(ast, (node) => {\n if (node.type === \"reference\") {\n const refNode = node as ReferenceNode;\n return {\n ...refNode,\n address: {\n colIndex: refNode.isAbsolute.col\n ? refNode.address.colIndex\n : refNode.address.colIndex + colDelta,\n rowIndex: refNode.isAbsolute.row\n ? refNode.address.rowIndex\n : refNode.address.rowIndex + rowDelta,\n },\n };\n } else if (node.type === \"range\") {\n const rangeNode = node as RangeNode;\n return {\n ...rangeNode,\n range: {\n start: {\n col: rangeNode.isAbsolute.start.col\n ? rangeNode.range.start.col\n : rangeNode.range.start.col + colDelta,\n row: rangeNode.isAbsolute.start.row\n ? rangeNode.range.start.row\n : rangeNode.range.start.row + rowDelta,\n },\n end: {\n col:\n rangeNode.range.end.col.type === \"number\"\n ? rangeNode.isAbsolute.end.col\n ? rangeNode.range.end.col\n : {\n type: \"number\" as const,\n value: rangeNode.range.end.col.value + colDelta,\n }\n : rangeNode.range.end.col,\n row:\n rangeNode.range.end.row.type === \"number\"\n ? rangeNode.isAbsolute.end.row\n ? rangeNode.range.end.row\n : {\n type: \"number\" as const,\n value: rangeNode.range.end.row.value + rowDelta,\n }\n : rangeNode.range.end.row,\n },\n },\n };\n }\n return node;\n });\n\n return `=${astToString(adjustedAst)}`;\n } catch (error) {\n // If parsing fails, return the original formula\n console.warn(\"Failed to adjust formula references:\", error);\n return formula;\n }\n }\n\n /**\n * Copy formatting (cellStyles and conditionalStyles) from source to target\n */\n private copyFormatting(\n sourceCells: CellAddress[],\n sourceTopLeft: CellAddress,\n target: CellAddress,\n rowOffset: number,\n colOffset: number\n ): void {\n // Get all styles for the source workbook\n const allConditionalStyles = this.styleManager.getAllConditionalStyles();\n const allCellStyles = this.styleManager.getAllCellStyles();\n\n // Find styles that intersect with source cells\n const sourceRange = this.getBoundingBox(sourceCells);\n\n // Copy conditional styles\n for (const style of allConditionalStyles) {\n if (\n style.area.workbookName === sourceTopLeft.workbookName &&\n style.area.sheetName === sourceTopLeft.sheetName\n ) {\n // Calculate intersection of style range with source bounding box\n const intersection = intersectRanges(style.area.range, sourceRange);\n if (intersection) {\n // Copy only the intersection, offset to target\n const newStyle: ConditionalStyle = {\n area: {\n workbookName: target.workbookName,\n sheetName: target.sheetName,\n range: this.adjustRange(intersection, rowOffset, colOffset),\n },\n condition: style.condition,\n };\n this.styleManager.addConditionalStyle(newStyle);\n }\n }\n }\n\n // Copy cell styles\n for (const style of allCellStyles) {\n if (\n style.area.workbookName === sourceTopLeft.workbookName &&\n style.area.sheetName === sourceTopLeft.sheetName\n ) {\n // Calculate intersection of style range with source bounding box\n const intersection = intersectRanges(style.area.range, sourceRange);\n if (intersection) {\n // Copy only the intersection, offset to target\n const newStyle: DirectCellStyle = {\n area: {\n workbookName: target.workbookName,\n sheetName: target.sheetName,\n range: this.adjustRange(intersection, rowOffset, colOffset),\n },\n style: style.style,\n };\n this.styleManager.addCellStyle(newStyle);\n }\n }\n }\n }\n\n /**\n * Get bounding box for a set of cells\n */\n private getBoundingBox(cells: CellAddress[]): SpreadsheetRange {\n let minRow = Infinity;\n let maxRow = -Infinity;\n let minCol = Infinity;\n let maxCol = -Infinity;\n\n for (const cell of cells) {\n minRow = Math.min(minRow, cell.rowIndex);\n maxRow = Math.max(maxRow, cell.rowIndex);\n minCol = Math.min(minCol, cell.colIndex);\n maxCol = Math.max(maxCol, cell.colIndex);\n }\n\n return {\n start: { col: minCol, row: minRow },\n end: {\n col: { type: \"number\", value: maxCol },\n row: { type: \"number\", value: maxRow },\n },\n };\n }\n\n\n /**\n * Adjust a range by row and column offsets\n */\n private adjustRange(\n range: SpreadsheetRange,\n rowOffset: number,\n colOffset: number\n ): SpreadsheetRange {\n return {\n start: {\n col: range.start.col + colOffset,\n row: range.start.row + rowOffset,\n },\n end: {\n col:\n range.end.col.type === \"number\"\n ? { type: \"number\", value: range.end.col.value + colOffset }\n : range.end.col,\n row:\n range.end.row.type === \"number\"\n ? { type: \"number\", value: range.end.row.value + rowOffset }\n : range.end.row,\n },\n };\n }\n\n /**\n * Clear source cells (for cut operation)\n */\n private clearSourceCells(cells: CellAddress[]): void {\n for (const cell of cells) {\n const sheet = this.workbookManager.getSheet({\n workbookName: cell.workbookName,\n sheetName: cell.sheetName,\n });\n\n if (sheet) {\n const key = `${String.fromCharCode(65 + cell.colIndex)}${\n cell.rowIndex + 1\n }`;\n sheet.content.delete(key);\n }\n }\n }\n}\n\n"
|
|
5
|
+
"/**\n * CopyManager - Manages cell copy/paste operations\n */\n\nimport type {\n CellAddress,\n CopyCellsOptions,\n ConditionalStyle,\n DirectCellStyle,\n LocalCellAddress,\n RangeAddress,\n SerializedCellValue,\n SpreadsheetRange,\n} from \"../types.mjs\";\nimport type { WorkbookManager } from \"./workbook-manager.mjs\";\nimport type { EvaluationManager } from \"./evaluation-manager.mjs\";\nimport type { StyleManager } from \"./style-manager.mjs\";\nimport { parseFormula } from \"../../parser/parser.mjs\";\nimport { astToString } from \"../../parser/formatter.mjs\";\nimport { transformAST } from \"../ast-traverser.mjs\";\nimport type { ReferenceNode, RangeNode } from \"../../parser/ast.mjs\";\nimport { isCellInRange } from \"../utils.mjs\";\nimport { intersectRanges } from \"../utils/range-utils.mjs\";\n\nexport class CopyManager {\n constructor(\n private workbookManager: WorkbookManager,\n private evaluationManager: EvaluationManager,\n private styleManager: StyleManager\n ) {}\n\n /**\n * Paste cells from source to target\n */\n copyCells(\n source: CellAddress[],\n target: CellAddress,\n options: CopyCellsOptions\n ): void {\n if (source.length === 0) {\n return;\n }\n\n // Find top-left cell of source (minimum row/col indices)\n const topLeft = this.findTopLeft(source);\n\n // Calculate offset from source top-left to target\n const rowOffset = target.rowIndex - topLeft.rowIndex;\n const colOffset = target.colIndex - topLeft.colIndex;\n\n // Copy cell contents (skip if only copying style)\n if (options.target !== 'style') {\n for (const sourceCell of source) {\n const targetCell: CellAddress = {\n workbookName: target.workbookName,\n sheetName: target.sheetName,\n colIndex: sourceCell.colIndex + colOffset,\n rowIndex: sourceCell.rowIndex + rowOffset,\n };\n\n this.copyCellContent(sourceCell, targetCell, topLeft, options);\n }\n }\n\n // Copy formatting if requested\n if (options.target === 'all' || options.target === 'style') {\n this.copyFormatting(source, topLeft, target, rowOffset, colOffset);\n }\n\n // Clear source cells if cut\n if (options.cut) {\n this.clearSourceCells(source);\n }\n }\n\n /**\n * Find the top-left cell (minimum row/col indices)\n */\n private findTopLeft(cells: CellAddress[]): CellAddress {\n let minRow = Infinity;\n let minCol = Infinity;\n let topLeftCell = cells[0]!;\n\n for (const cell of cells) {\n if (\n cell.rowIndex < minRow ||\n (cell.rowIndex === minRow && cell.colIndex < minCol)\n ) {\n minRow = cell.rowIndex;\n minCol = cell.colIndex;\n topLeftCell = cell;\n }\n }\n\n return topLeftCell;\n }\n\n /**\n * Copy content from one cell to another\n */\n private copyCellContent(\n sourceCell: CellAddress,\n targetCell: CellAddress,\n sourceTopLeft: CellAddress,\n options: CopyCellsOptions\n ): void {\n const sheet = this.workbookManager.getSheet({\n workbookName: sourceCell.workbookName,\n sheetName: sourceCell.sheetName,\n });\n\n if (!sheet) {\n return;\n }\n\n const key = `${String.fromCharCode(65 + sourceCell.colIndex)}${\n sourceCell.rowIndex + 1\n }`;\n const cellContent = sheet.content.get(key);\n\n if (!cellContent) {\n // Source cell is empty\n return;\n }\n\n let targetContent: SerializedCellValue;\n\n if (options.type === \"value\") {\n // Copy evaluated value\n const evalResult = this.evaluationManager.getCellEvaluationResult(sourceCell);\n \n if (!evalResult || evalResult.type !== \"value\") {\n // If evaluation failed or is not a value, copy as-is\n targetContent = cellContent;\n } else {\n // Convert to literal value\n const result = evalResult.result;\n if (result.type === \"number\") {\n targetContent = result.value;\n } else if (result.type === \"string\") {\n targetContent = result.value;\n } else if (result.type === \"boolean\") {\n targetContent = result.value;\n } else {\n // Error or other type, copy as-is\n targetContent = cellContent;\n }\n }\n } else {\n // Copy formula\n if (typeof cellContent === \"string\" && cellContent.startsWith(\"=\")) {\n // Adjust formula references\n targetContent = this.adjustFormulaReferences(\n cellContent,\n {\n colIndex: sourceCell.colIndex,\n rowIndex: sourceCell.rowIndex,\n },\n {\n colIndex: targetCell.colIndex,\n rowIndex: targetCell.rowIndex,\n }\n );\n } else {\n // Not a formula, copy as-is\n targetContent = cellContent;\n }\n }\n\n // Set target cell content (using the engine's method through workbook manager)\n const targetSheet = this.workbookManager.getSheet({\n workbookName: targetCell.workbookName,\n sheetName: targetCell.sheetName,\n });\n\n if (targetSheet) {\n const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${\n targetCell.rowIndex + 1\n }`;\n targetSheet.content.set(targetKey, targetContent);\n }\n }\n\n /**\n * Adjust formula references when copying\n * Based on autofill-utils.ts adjustFormulaReferences\n */\n private adjustFormulaReferences(\n formula: string,\n sourceAddress: LocalCellAddress,\n targetAddress: LocalCellAddress\n ): string {\n try {\n const ast = parseFormula(formula.slice(1)); // Remove the \"=\" sign\n\n const rowDelta = targetAddress.rowIndex - sourceAddress.rowIndex;\n const colDelta = targetAddress.colIndex - sourceAddress.colIndex;\n\n const adjustedAst = transformAST(ast, (node) => {\n if (node.type === \"reference\") {\n const refNode = node as ReferenceNode;\n return {\n ...refNode,\n address: {\n colIndex: refNode.isAbsolute.col\n ? refNode.address.colIndex\n : refNode.address.colIndex + colDelta,\n rowIndex: refNode.isAbsolute.row\n ? refNode.address.rowIndex\n : refNode.address.rowIndex + rowDelta,\n },\n };\n } else if (node.type === \"range\") {\n const rangeNode = node as RangeNode;\n return {\n ...rangeNode,\n range: {\n start: {\n col: rangeNode.isAbsolute.start.col\n ? rangeNode.range.start.col\n : rangeNode.range.start.col + colDelta,\n row: rangeNode.isAbsolute.start.row\n ? rangeNode.range.start.row\n : rangeNode.range.start.row + rowDelta,\n },\n end: {\n col:\n rangeNode.range.end.col.type === \"number\"\n ? rangeNode.isAbsolute.end.col\n ? rangeNode.range.end.col\n : {\n type: \"number\" as const,\n value: rangeNode.range.end.col.value + colDelta,\n }\n : rangeNode.range.end.col,\n row:\n rangeNode.range.end.row.type === \"number\"\n ? rangeNode.isAbsolute.end.row\n ? rangeNode.range.end.row\n : {\n type: \"number\" as const,\n value: rangeNode.range.end.row.value + rowDelta,\n }\n : rangeNode.range.end.row,\n },\n },\n };\n }\n return node;\n });\n\n return `=${astToString(adjustedAst)}`;\n } catch (error) {\n // If parsing fails, return the original formula\n console.warn(\"Failed to adjust formula references:\", error);\n return formula;\n }\n }\n\n /**\n * Copy formatting (cellStyles and conditionalStyles) from source to target\n */\n private copyFormatting(\n sourceCells: CellAddress[],\n sourceTopLeft: CellAddress,\n target: CellAddress,\n rowOffset: number,\n colOffset: number\n ): void {\n // Get all styles for the source workbook\n const allConditionalStyles = this.styleManager.getAllConditionalStyles();\n const allCellStyles = this.styleManager.getAllCellStyles();\n\n // Find styles that intersect with source cells\n const sourceRange = this.getBoundingBox(sourceCells);\n\n // Copy conditional styles\n for (const style of allConditionalStyles) {\n if (\n style.area.workbookName === sourceTopLeft.workbookName &&\n style.area.sheetName === sourceTopLeft.sheetName\n ) {\n // Calculate intersection of style range with source bounding box\n const intersection = intersectRanges(style.area.range, sourceRange);\n if (intersection) {\n // Copy only the intersection, offset to target\n const newStyle: ConditionalStyle = {\n area: {\n workbookName: target.workbookName,\n sheetName: target.sheetName,\n range: this.adjustRange(intersection, rowOffset, colOffset),\n },\n condition: style.condition,\n };\n this.styleManager.addConditionalStyle(newStyle);\n }\n }\n }\n\n // Copy cell styles\n for (const style of allCellStyles) {\n if (\n style.area.workbookName === sourceTopLeft.workbookName &&\n style.area.sheetName === sourceTopLeft.sheetName\n ) {\n // Calculate intersection of style range with source bounding box\n const intersection = intersectRanges(style.area.range, sourceRange);\n if (intersection) {\n // Copy only the intersection, offset to target\n const newStyle: DirectCellStyle = {\n area: {\n workbookName: target.workbookName,\n sheetName: target.sheetName,\n range: this.adjustRange(intersection, rowOffset, colOffset),\n },\n style: style.style,\n };\n this.styleManager.addCellStyle(newStyle);\n }\n }\n }\n }\n\n /**\n * Get bounding box for a set of cells\n */\n private getBoundingBox(cells: CellAddress[]): SpreadsheetRange {\n let minRow = Infinity;\n let maxRow = -Infinity;\n let minCol = Infinity;\n let maxCol = -Infinity;\n\n for (const cell of cells) {\n minRow = Math.min(minRow, cell.rowIndex);\n maxRow = Math.max(maxRow, cell.rowIndex);\n minCol = Math.min(minCol, cell.colIndex);\n maxCol = Math.max(maxCol, cell.colIndex);\n }\n\n return {\n start: { col: minCol, row: minRow },\n end: {\n col: { type: \"number\", value: maxCol },\n row: { type: \"number\", value: maxRow },\n },\n };\n }\n\n\n /**\n * Adjust a range by row and column offsets\n */\n private adjustRange(\n range: SpreadsheetRange,\n rowOffset: number,\n colOffset: number\n ): SpreadsheetRange {\n return {\n start: {\n col: range.start.col + colOffset,\n row: range.start.row + rowOffset,\n },\n end: {\n col:\n range.end.col.type === \"number\"\n ? { type: \"number\", value: range.end.col.value + colOffset }\n : range.end.col,\n row:\n range.end.row.type === \"number\"\n ? { type: \"number\", value: range.end.row.value + rowOffset }\n : range.end.row,\n },\n };\n }\n\n /**\n * Clear source cells (for cut operation)\n */\n private clearSourceCells(cells: CellAddress[]): void {\n for (const cell of cells) {\n const sheet = this.workbookManager.getSheet({\n workbookName: cell.workbookName,\n sheetName: cell.sheetName,\n });\n\n if (sheet) {\n const key = `${String.fromCharCode(65 + cell.colIndex)}${\n cell.rowIndex + 1\n }`;\n sheet.content.delete(key);\n }\n }\n }\n\n /**\n * Fill one or more areas with a seed range's content/style\n * Uses column-first strategy: fills down, then replicates right\n * Formulas are adjusted based on each target cell's offset from the seed\n */\n fillAreas(\n seedRange: RangeAddress,\n targetRanges: RangeAddress[],\n options: CopyCellsOptions\n ): void {\n for (const targetRange of targetRanges) {\n this.fillRangeWithSeed(seedRange, targetRange, {\n copyContent: options.target !== 'style',\n copyStyles: options.target === 'all' || options.target === 'style',\n contentType: options.type,\n adjustFormulas: true,\n });\n }\n\n // Clear seed range if cut operation\n if (options.cut) {\n const seedCells = this.expandRangeToCells(seedRange);\n this.clearSourceCells(seedCells);\n }\n }\n\n /**\n * Fill a target range with a seed range using column-first strategy\n * Step 1: Fill down - extend seed pattern vertically to match target height\n * Step 2: Replicate right - copy filled columns horizontally\n */\n private fillRangeWithSeed(\n seedRange: RangeAddress,\n targetRange: RangeAddress,\n options: {\n copyContent: boolean;\n copyStyles: boolean;\n contentType: \"value\" | \"formula\";\n adjustFormulas: boolean;\n }\n ): void {\n const seedCells = this.expandRangeToCells(seedRange);\n const seedWidth = this.getRangeWidth(seedRange);\n const seedHeight = this.getRangeHeight(seedRange);\n const targetWidth = this.getRangeWidth(targetRange);\n const targetHeight = this.getRangeHeight(targetRange);\n\n // Step 1: Fill down - replicate seed pattern vertically\n const filledColumns: Map<string, { cell: CellAddress; content: SerializedCellValue }> = new Map();\n \n for (let col = 0; col < seedWidth; col++) {\n for (let row = 0; row < targetHeight; row++) {\n const seedRow = row % seedHeight;\n const seedCell = seedCells.find(\n (c) => \n c.colIndex === seedRange.range.start.col + col &&\n c.rowIndex === seedRange.range.start.row + seedRow\n );\n\n if (seedCell) {\n const targetCell: CellAddress = {\n workbookName: targetRange.workbookName,\n sheetName: targetRange.sheetName,\n colIndex: targetRange.range.start.col + col,\n rowIndex: targetRange.range.start.row + row,\n };\n\n const rowDelta = targetCell.rowIndex - seedCell.rowIndex;\n const colDelta = targetCell.colIndex - seedCell.colIndex;\n\n if (options.copyContent) {\n this.copyCellContentWithOffset(seedCell, targetCell, rowDelta, colDelta, {\n type: options.contentType,\n cut: false,\n target: 'content',\n });\n }\n\n if (options.copyStyles) {\n this.copyCellFormatting(seedCell, targetCell);\n }\n\n // Store filled column for horizontal replication\n const key = `${targetCell.colIndex}-${targetCell.rowIndex}`;\n const sheet = this.workbookManager.getSheet({\n workbookName: targetCell.workbookName,\n sheetName: targetCell.sheetName,\n });\n const cellKey = `${String.fromCharCode(65 + targetCell.colIndex)}${targetCell.rowIndex + 1}`;\n const content = sheet?.content.get(cellKey) || \"\";\n filledColumns.set(key, { cell: targetCell, content });\n }\n }\n }\n\n // Step 2: Replicate right - copy filled columns horizontally\n if (targetWidth > seedWidth) {\n for (let col = seedWidth; col < targetWidth; col++) {\n const sourceCol = col % seedWidth;\n \n for (let row = 0; row < targetHeight; row++) {\n const sourceCell: CellAddress = {\n workbookName: targetRange.workbookName,\n sheetName: targetRange.sheetName,\n colIndex: targetRange.range.start.col + sourceCol,\n rowIndex: targetRange.range.start.row + row,\n };\n\n const targetCell: CellAddress = {\n workbookName: targetRange.workbookName,\n sheetName: targetRange.sheetName,\n colIndex: targetRange.range.start.col + col,\n rowIndex: targetRange.range.start.row + row,\n };\n\n const colDelta = targetCell.colIndex - sourceCell.colIndex;\n\n if (options.copyContent) {\n this.copyCellContentWithOffset(sourceCell, targetCell, 0, colDelta, {\n type: options.contentType,\n cut: false,\n target: 'content',\n });\n }\n\n if (options.copyStyles) {\n this.copyCellFormatting(sourceCell, targetCell);\n }\n }\n }\n }\n }\n\n /**\n * Get the width of a range (number of columns)\n */\n private getRangeWidth(range: RangeAddress): number {\n if (range.range.end.col.type === \"infinity\") {\n return 100; // Default for infinite\n }\n return range.range.end.col.value - range.range.start.col + 1;\n }\n\n /**\n * Get the height of a range (number of rows)\n */\n private getRangeHeight(range: RangeAddress): number {\n if (range.range.end.row.type === \"infinity\") {\n return 100; // Default for infinite\n }\n return range.range.end.row.value - range.range.start.row + 1;\n }\n\n /**\n * Expand a RangeAddress into an array of CellAddress\n * Handles finite ranges, row-bounded, and column-bounded ranges\n */\n private expandRangeToCells(rangeAddress: RangeAddress): CellAddress[] {\n const { workbookName, sheetName, range } = rangeAddress;\n const cells: CellAddress[] = [];\n\n const startCol = range.start.col;\n const startRow = range.start.row;\n\n // Determine end column\n let endCol: number;\n if (range.end.col.type === \"infinity\") {\n // Limit infinite column ranges to a reasonable size (e.g., 100 columns)\n endCol = startCol + 99;\n } else {\n endCol = range.end.col.value;\n }\n\n // Determine end row\n let endRow: number;\n if (range.end.row.type === \"infinity\") {\n // Limit infinite row ranges to a reasonable size (e.g., 100 rows)\n endRow = startRow + 99;\n } else {\n endRow = range.end.row.value;\n }\n\n // Generate all cells in the range\n for (let row = startRow; row <= endRow; row++) {\n for (let col = startCol; col <= endCol; col++) {\n cells.push({\n workbookName,\n sheetName,\n colIndex: col,\n rowIndex: row,\n });\n }\n }\n\n return cells;\n }\n\n /**\n * Copy cell content with explicit row/column offset for fill operations\n */\n private copyCellContentWithOffset(\n sourceCell: CellAddress,\n targetCell: CellAddress,\n rowDelta: number,\n colDelta: number,\n options: CopyCellsOptions\n ): void {\n const sheet = this.workbookManager.getSheet({\n workbookName: sourceCell.workbookName,\n sheetName: sourceCell.sheetName,\n });\n\n if (!sheet) {\n return;\n }\n\n const key = `${String.fromCharCode(65 + sourceCell.colIndex)}${\n sourceCell.rowIndex + 1\n }`;\n const cellContent = sheet.content.get(key);\n\n if (!cellContent) {\n // Source cell is empty - clear target\n const targetSheet = this.workbookManager.getSheet({\n workbookName: targetCell.workbookName,\n sheetName: targetCell.sheetName,\n });\n if (targetSheet) {\n const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${\n targetCell.rowIndex + 1\n }`;\n targetSheet.content.delete(targetKey);\n }\n return;\n }\n\n let targetContent: SerializedCellValue;\n\n if (options.type === \"value\") {\n // Copy evaluated value\n const evalResult = this.evaluationManager.getCellEvaluationResult(sourceCell);\n \n if (!evalResult || evalResult.type !== \"value\") {\n // If evaluation failed or is not a value, copy as-is\n targetContent = cellContent;\n } else {\n // Convert to literal value\n const result = evalResult.result;\n if (result.type === \"number\") {\n targetContent = result.value;\n } else if (result.type === \"string\") {\n targetContent = result.value;\n } else if (result.type === \"boolean\") {\n targetContent = result.value;\n } else {\n // Error or other type, copy as-is\n targetContent = cellContent;\n }\n }\n } else {\n // Copy formula with offset adjustment\n if (typeof cellContent === \"string\" && cellContent.startsWith(\"=\")) {\n // Adjust formula references based on offset\n targetContent = this.adjustFormulaWithOffset(\n cellContent,\n rowDelta,\n colDelta\n );\n } else {\n // Not a formula, copy as-is\n targetContent = cellContent;\n }\n }\n\n // Set target cell content\n const targetSheet = this.workbookManager.getSheet({\n workbookName: targetCell.workbookName,\n sheetName: targetCell.sheetName,\n });\n\n if (targetSheet) {\n const targetKey = `${String.fromCharCode(65 + targetCell.colIndex)}${\n targetCell.rowIndex + 1\n }`;\n targetSheet.content.set(targetKey, targetContent);\n }\n }\n\n /**\n * Adjust formula references by a specific row/column offset\n */\n private adjustFormulaWithOffset(\n formula: string,\n rowDelta: number,\n colDelta: number\n ): string {\n try {\n const ast = parseFormula(formula.slice(1)); // Remove the \"=\" sign\n\n const adjustedAst = transformAST(ast, (node) => {\n if (node.type === \"reference\") {\n const refNode = node as ReferenceNode;\n return {\n ...refNode,\n address: {\n colIndex: refNode.isAbsolute.col\n ? refNode.address.colIndex\n : refNode.address.colIndex + colDelta,\n rowIndex: refNode.isAbsolute.row\n ? refNode.address.rowIndex\n : refNode.address.rowIndex + rowDelta,\n },\n };\n } else if (node.type === \"range\") {\n const rangeNode = node as RangeNode;\n return {\n ...rangeNode,\n range: {\n start: {\n col: rangeNode.isAbsolute.start.col\n ? rangeNode.range.start.col\n : rangeNode.range.start.col + colDelta,\n row: rangeNode.isAbsolute.start.row\n ? rangeNode.range.start.row\n : rangeNode.range.start.row + rowDelta,\n },\n end: {\n col:\n rangeNode.range.end.col.type === \"number\"\n ? rangeNode.isAbsolute.end.col\n ? rangeNode.range.end.col\n : {\n type: \"number\" as const,\n value: rangeNode.range.end.col.value + colDelta,\n }\n : rangeNode.range.end.col,\n row:\n rangeNode.range.end.row.type === \"number\"\n ? rangeNode.isAbsolute.end.row\n ? rangeNode.range.end.row\n : {\n type: \"number\" as const,\n value: rangeNode.range.end.row.value + rowDelta,\n }\n : rangeNode.range.end.row,\n },\n },\n };\n }\n return node;\n });\n\n return `=${astToString(adjustedAst)}`;\n } catch (error) {\n // If parsing fails, return the original formula\n console.warn(\"Failed to adjust formula with offset:\", error);\n return formula;\n }\n }\n\n /**\n * Copy formatting from one cell to another\n */\n private copyCellFormatting(\n sourceCell: CellAddress,\n targetCell: CellAddress\n ): void {\n // Get all styles that intersect with the source cell\n const allConditionalStyles = this.styleManager.getAllConditionalStyles();\n const allCellStyles = this.styleManager.getAllCellStyles();\n\n const sourceCellRange: SpreadsheetRange = {\n start: { col: sourceCell.colIndex, row: sourceCell.rowIndex },\n end: {\n col: { type: \"number\", value: sourceCell.colIndex },\n row: { type: \"number\", value: sourceCell.rowIndex },\n },\n };\n\n // Copy conditional styles that apply to source cell\n for (const style of allConditionalStyles) {\n if (\n style.area.workbookName === sourceCell.workbookName &&\n style.area.sheetName === sourceCell.sheetName\n ) {\n const intersection = intersectRanges(style.area.range, sourceCellRange);\n if (intersection) {\n // Apply style to target cell\n const newStyle: ConditionalStyle = {\n area: {\n workbookName: targetCell.workbookName,\n sheetName: targetCell.sheetName,\n range: {\n start: { col: targetCell.colIndex, row: targetCell.rowIndex },\n end: {\n col: { type: \"number\", value: targetCell.colIndex },\n row: { type: \"number\", value: targetCell.rowIndex },\n },\n },\n },\n condition: style.condition,\n };\n this.styleManager.addConditionalStyle(newStyle);\n }\n }\n }\n\n // Copy cell styles that apply to source cell\n for (const style of allCellStyles) {\n if (\n style.area.workbookName === sourceCell.workbookName &&\n style.area.sheetName === sourceCell.sheetName\n ) {\n const intersection = intersectRanges(style.area.range, sourceCellRange);\n if (intersection) {\n // Apply style to target cell\n const newStyle: DirectCellStyle = {\n area: {\n workbookName: targetCell.workbookName,\n sheetName: targetCell.sheetName,\n range: {\n start: { col: targetCell.colIndex, row: targetCell.rowIndex },\n end: {\n col: { type: \"number\", value: targetCell.colIndex },\n row: { type: \"number\", value: targetCell.rowIndex },\n },\n },\n },\n style: style.style,\n };\n this.styleManager.addCellStyle(newStyle);\n }\n }\n }\n }\n}\n\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";AAgBA;AACA;AACA;AAGA;AAAA;AAEO,MAAM,YAAY;AAAA,EAEb;AAAA,EACA;AAAA,EACA;AAAA,EAHV,WAAW,CACD,iBACA,mBACA,cACR;AAAA,IAHQ;AAAA,IACA;AAAA,IACA;AAAA;AAAA,EAMV,SAAS,CACP,QACA,QACA,SACM;AAAA,IACN,IAAI,OAAO,WAAW,GAAG;AAAA,MACvB;AAAA,IACF;AAAA,IAGA,MAAM,UAAU,KAAK,YAAY,MAAM;AAAA,IAGvC,MAAM,YAAY,OAAO,WAAW,QAAQ;AAAA,IAC5C,MAAM,YAAY,OAAO,WAAW,QAAQ;AAAA,IAG5C,IAAI,QAAQ,WAAW,SAAS;AAAA,MAC9B,WAAW,cAAc,QAAQ;AAAA,QAC/B,MAAM,aAA0B;AAAA,UAC9B,cAAc,OAAO;AAAA,UACrB,WAAW,OAAO;AAAA,UAClB,UAAU,WAAW,WAAW;AAAA,UAChC,UAAU,WAAW,WAAW;AAAA,QAClC;AAAA,QAEA,KAAK,gBAAgB,YAAY,YAAY,SAAS,OAAO;AAAA,MAC/D;AAAA,IACF;AAAA,IAGA,IAAI,QAAQ,WAAW,SAAS,QAAQ,WAAW,SAAS;AAAA,MAC1D,KAAK,eAAe,QAAQ,SAAS,QAAQ,WAAW,SAAS;AAAA,IACnE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8
|
+
"debugId": "D487B5F6392E0DE264756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/mjs/package.json
CHANGED
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
import type { CellAddress, SerializedCellValue, SpreadsheetRange } from "./types";
|
|
5
5
|
import type { FillDirection } from "@ricsam/selection-manager";
|
|
6
6
|
import type { WorkbookManager } from "./managers/workbook-manager";
|
|
7
|
+
import type { StyleManager } from "./managers/style-manager";
|
|
7
8
|
export declare class AutoFill {
|
|
8
9
|
private workbookManager;
|
|
10
|
+
private styleManager;
|
|
9
11
|
private engine;
|
|
10
|
-
constructor(workbookManager: WorkbookManager, engine: {
|
|
12
|
+
constructor(workbookManager: WorkbookManager, styleManager: StyleManager, engine: {
|
|
11
13
|
setCellContent: (address: CellAddress, content: SerializedCellValue) => void;
|
|
12
14
|
setSheetContent: (opts: {
|
|
13
15
|
sheetName: string;
|
|
@@ -22,11 +24,19 @@ export declare class AutoFill {
|
|
|
22
24
|
fill(opts: {
|
|
23
25
|
sheetName: string;
|
|
24
26
|
workbookName: string;
|
|
25
|
-
}, seedRange: SpreadsheetRange,
|
|
27
|
+
}, seedRange: SpreadsheetRange, fillRanges: SpreadsheetRange[], direction: FillDirection): void;
|
|
28
|
+
/**
|
|
29
|
+
* Fill a single range with seed data and styles
|
|
30
|
+
*/
|
|
31
|
+
private fillSingleRange;
|
|
26
32
|
private getSeedCells;
|
|
27
33
|
private collectSingleCellPattern;
|
|
28
34
|
private collectMultiCellPattern;
|
|
29
35
|
private inferLinearStep;
|
|
30
36
|
private applyLinearStep;
|
|
31
37
|
private adjustFormulaReferences;
|
|
38
|
+
/**
|
|
39
|
+
* Fill styles from seed range to fill range based on direction
|
|
40
|
+
*/
|
|
41
|
+
private fillStyles;
|
|
32
42
|
}
|
|
@@ -152,9 +152,75 @@ export declare class FormulaEngine {
|
|
|
152
152
|
*/
|
|
153
153
|
clearCellStyles(range: RangeAddress): void;
|
|
154
154
|
/**
|
|
155
|
-
*
|
|
155
|
+
* Paste cells from source to target
|
|
156
156
|
*/
|
|
157
|
-
|
|
157
|
+
pasteCells(source: CellAddress[], target: CellAddress, options: CopyCellsOptions): void;
|
|
158
|
+
/**
|
|
159
|
+
* Fill one or more areas with a seed range's content/style
|
|
160
|
+
* Uses column-first strategy: fills down, then replicates right
|
|
161
|
+
* Formulas are adjusted based on each target cell's offset from the seed
|
|
162
|
+
*
|
|
163
|
+
* @param seedRange - The range to use as a template/pattern
|
|
164
|
+
* @param targetRanges - One or more range addresses to fill
|
|
165
|
+
* @param options - Copy options (target: 'all'|'content'|'style', type: 'value'|'formula', cut: boolean)
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* // Fill F6:J10 with A1:B2 seed (2x2 pattern fills 5x5 area)
|
|
169
|
+
* engine.fillAreas(
|
|
170
|
+
* {
|
|
171
|
+
* workbookName,
|
|
172
|
+
* sheetName,
|
|
173
|
+
* range: {
|
|
174
|
+
* start: { col: 0, row: 0 },
|
|
175
|
+
* end: { col: { type: "number", value: 1 }, row: { type: "number", value: 1 } }
|
|
176
|
+
* }
|
|
177
|
+
* },
|
|
178
|
+
* [{
|
|
179
|
+
* workbookName,
|
|
180
|
+
* sheetName,
|
|
181
|
+
* range: {
|
|
182
|
+
* start: { col: 5, row: 5 },
|
|
183
|
+
* end: { col: { type: "number", value: 9 }, row: { type: "number", value: 9 } }
|
|
184
|
+
* }
|
|
185
|
+
* }],
|
|
186
|
+
* { cut: false, type: "formula", target: "all" }
|
|
187
|
+
* );
|
|
188
|
+
*/
|
|
189
|
+
fillAreas(seedRange: RangeAddress, targetRanges: RangeAddress[], options: CopyCellsOptions): void;
|
|
190
|
+
/**
|
|
191
|
+
* Smart paste that automatically determines whether to paste or fill
|
|
192
|
+
* Handles multiple selection areas - each area is independently pasted or filled
|
|
193
|
+
* - If area is larger than source, uses fillAreas() to fill the area
|
|
194
|
+
* - If area is same size or smaller, uses pasteCells() for normal paste
|
|
195
|
+
*
|
|
196
|
+
* @param sourceCells - The copied cells
|
|
197
|
+
* @param pasteSelection - One or more selection areas where user is pasting
|
|
198
|
+
* @param options - Copy options
|
|
199
|
+
*
|
|
200
|
+
* @example
|
|
201
|
+
* // Copy A1, paste into two areas B1:C2 and E5:F6 - both get filled
|
|
202
|
+
* engine.smartPaste(
|
|
203
|
+
* [{ workbookName, sheetName, colIndex: 0, rowIndex: 0 }],
|
|
204
|
+
* {
|
|
205
|
+
* workbookName,
|
|
206
|
+
* sheetName,
|
|
207
|
+
* areas: [
|
|
208
|
+
* { start: { col: 1, row: 0 }, end: { col: { type: "number", value: 2 }, row: { type: "number", value: 1 } } },
|
|
209
|
+
* { start: { col: 4, row: 4 }, end: { col: { type: "number", value: 5 }, row: { type: "number", value: 5 } } }
|
|
210
|
+
* ]
|
|
211
|
+
* },
|
|
212
|
+
* { cut: false, type: "formula", target: "all" }
|
|
213
|
+
* );
|
|
214
|
+
*/
|
|
215
|
+
smartPaste(sourceCells: CellAddress[], pasteSelection: {
|
|
216
|
+
workbookName: string;
|
|
217
|
+
sheetName: string;
|
|
218
|
+
areas: SpreadsheetRange[];
|
|
219
|
+
}, options: CopyCellsOptions): void;
|
|
220
|
+
/**
|
|
221
|
+
* Get bounds (min/max row/col) from an array of cell addresses
|
|
222
|
+
*/
|
|
223
|
+
private getBoundsFromCells;
|
|
158
224
|
addSheet(opts: {
|
|
159
225
|
workbookName: string;
|
|
160
226
|
sheetName: string;
|
|
@@ -203,7 +269,8 @@ export declare class FormulaEngine {
|
|
|
203
269
|
*/
|
|
204
270
|
reevaluate(): void;
|
|
205
271
|
/**
|
|
206
|
-
* Auto-fills
|
|
272
|
+
* Auto-fills one or more ranges based on the seedRange and the direction.
|
|
273
|
+
* Supports pattern detection and style copying.
|
|
207
274
|
*/
|
|
208
275
|
autoFill(opts: {
|
|
209
276
|
sheetName: string;
|
|
@@ -214,9 +281,9 @@ export declare class FormulaEngine {
|
|
|
214
281
|
*/
|
|
215
282
|
seedRange: SpreadsheetRange,
|
|
216
283
|
/**
|
|
217
|
-
* the new cells populated by the drag, excluding the seed
|
|
284
|
+
* One or more ranges to fill (the new cells populated by the drag, excluding the seed)
|
|
218
285
|
*/
|
|
219
|
-
|
|
286
|
+
fillRanges: SpreadsheetRange[],
|
|
220
287
|
/**
|
|
221
288
|
* The direction of the fill.
|
|
222
289
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* CopyManager - Manages cell copy/paste operations
|
|
3
3
|
*/
|
|
4
|
-
import type { CellAddress, CopyCellsOptions } from "../types";
|
|
4
|
+
import type { CellAddress, CopyCellsOptions, RangeAddress } from "../types";
|
|
5
5
|
import type { WorkbookManager } from "./workbook-manager";
|
|
6
6
|
import type { EvaluationManager } from "./evaluation-manager";
|
|
7
7
|
import type { StyleManager } from "./style-manager";
|
|
@@ -11,7 +11,7 @@ export declare class CopyManager {
|
|
|
11
11
|
private styleManager;
|
|
12
12
|
constructor(workbookManager: WorkbookManager, evaluationManager: EvaluationManager, styleManager: StyleManager);
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Paste cells from source to target
|
|
15
15
|
*/
|
|
16
16
|
copyCells(source: CellAddress[], target: CellAddress, options: CopyCellsOptions): void;
|
|
17
17
|
/**
|
|
@@ -43,4 +43,41 @@ export declare class CopyManager {
|
|
|
43
43
|
* Clear source cells (for cut operation)
|
|
44
44
|
*/
|
|
45
45
|
private clearSourceCells;
|
|
46
|
+
/**
|
|
47
|
+
* Fill one or more areas with a seed range's content/style
|
|
48
|
+
* Uses column-first strategy: fills down, then replicates right
|
|
49
|
+
* Formulas are adjusted based on each target cell's offset from the seed
|
|
50
|
+
*/
|
|
51
|
+
fillAreas(seedRange: RangeAddress, targetRanges: RangeAddress[], options: CopyCellsOptions): void;
|
|
52
|
+
/**
|
|
53
|
+
* Fill a target range with a seed range using column-first strategy
|
|
54
|
+
* Step 1: Fill down - extend seed pattern vertically to match target height
|
|
55
|
+
* Step 2: Replicate right - copy filled columns horizontally
|
|
56
|
+
*/
|
|
57
|
+
private fillRangeWithSeed;
|
|
58
|
+
/**
|
|
59
|
+
* Get the width of a range (number of columns)
|
|
60
|
+
*/
|
|
61
|
+
private getRangeWidth;
|
|
62
|
+
/**
|
|
63
|
+
* Get the height of a range (number of rows)
|
|
64
|
+
*/
|
|
65
|
+
private getRangeHeight;
|
|
66
|
+
/**
|
|
67
|
+
* Expand a RangeAddress into an array of CellAddress
|
|
68
|
+
* Handles finite ranges, row-bounded, and column-bounded ranges
|
|
69
|
+
*/
|
|
70
|
+
private expandRangeToCells;
|
|
71
|
+
/**
|
|
72
|
+
* Copy cell content with explicit row/column offset for fill operations
|
|
73
|
+
*/
|
|
74
|
+
private copyCellContentWithOffset;
|
|
75
|
+
/**
|
|
76
|
+
* Adjust formula references by a specific row/column offset
|
|
77
|
+
*/
|
|
78
|
+
private adjustFormulaWithOffset;
|
|
79
|
+
/**
|
|
80
|
+
* Copy formatting from one cell to another
|
|
81
|
+
*/
|
|
82
|
+
private copyCellFormatting;
|
|
46
83
|
}
|