@ricsam/formula-engine 0.0.12 → 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.
@@ -152,9 +152,75 @@ export declare class FormulaEngine {
152
152
  */
153
153
  clearCellStyles(range: RangeAddress): void;
154
154
  /**
155
- * Copy cells from source to target
155
+ * Paste cells from source to target
156
156
  */
157
- copyCells(source: CellAddress[], target: CellAddress, options: CopyCellsOptions): void;
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 the fillRange based on the seedRange and the direction.
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
- fillRange: SpreadsheetRange,
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
- * Copy cells from source to target
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
  }
@@ -318,6 +318,18 @@ export interface CellStyle {
318
318
  }
319
319
  export interface CopyCellsOptions {
320
320
  cut: boolean;
321
+ /**
322
+ * all: Copy everything from the source to the target
323
+ * content: Copy only the content from the source to the target
324
+ * style: Copy only the style from the source to the target
325
+ */
326
+ target: 'all' | 'content' | 'style';
327
+ /**
328
+ * The type of the content to copy
329
+ * value: Copy the value from the source to the target,
330
+ * e.g. if the cell has the formula =123 + 123 then the value is 246
331
+ * formula: Copy the formula from the source to the target,
332
+ * e.g. if the cell has the formula =123 + 123 then the formula is =123 + 123 is copied
333
+ */
321
334
  type: "value" | "formula";
322
- formatting: boolean;
323
335
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/formula-engine",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "module": "./dist/mjs/lib.mjs",
5
5
  "scripts": {
6
6
  "test": "bun test",