@alaarab/ogrid-core 2.2.0 → 2.4.0

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 (36) hide show
  1. package/dist/esm/index.js +5218 -19
  2. package/dist/types/constants/formulaBar.d.ts +60 -0
  3. package/dist/types/constants/index.d.ts +1 -0
  4. package/dist/types/formula/cellAddressUtils.d.ts +50 -0
  5. package/dist/types/formula/dependencyGraph.d.ts +72 -0
  6. package/dist/types/formula/errors.d.ts +15 -0
  7. package/dist/types/formula/evaluator.d.ts +25 -0
  8. package/dist/types/formula/formulaEngine.d.ts +104 -0
  9. package/dist/types/formula/functions/date.d.ts +2 -0
  10. package/dist/types/formula/functions/financial.d.ts +2 -0
  11. package/dist/types/formula/functions/index.d.ts +2 -0
  12. package/dist/types/formula/functions/info.d.ts +2 -0
  13. package/dist/types/formula/functions/logical.d.ts +2 -0
  14. package/dist/types/formula/functions/lookup.d.ts +2 -0
  15. package/dist/types/formula/functions/math.d.ts +2 -0
  16. package/dist/types/formula/functions/reference.d.ts +2 -0
  17. package/dist/types/formula/functions/statistical-extended.d.ts +2 -0
  18. package/dist/types/formula/functions/stats.d.ts +2 -0
  19. package/dist/types/formula/functions/text.d.ts +2 -0
  20. package/dist/types/formula/index.d.ts +13 -0
  21. package/dist/types/formula/parser.d.ts +26 -0
  22. package/dist/types/formula/tokenizer.d.ts +7 -0
  23. package/dist/types/formula/types.d.ts +141 -0
  24. package/dist/types/index.d.ts +10 -3
  25. package/dist/types/types/columnTypes.d.ts +2 -0
  26. package/dist/types/types/dataGridTypes.d.ts +7 -0
  27. package/dist/types/types/index.d.ts +1 -1
  28. package/dist/types/utils/cellReference.d.ts +21 -0
  29. package/dist/types/utils/cellValue.d.ts +6 -0
  30. package/dist/types/utils/clipboardHelpers.d.ts +18 -2
  31. package/dist/types/utils/dataGridViewModel.d.ts +8 -1
  32. package/dist/types/utils/exportToCsv.d.ts +10 -2
  33. package/dist/types/utils/fillHelpers.d.ts +18 -1
  34. package/dist/types/utils/formulaBarHelpers.d.ts +40 -0
  35. package/dist/types/utils/index.d.ts +6 -2
  36. package/package.json +1 -1
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Excel-style cell reference utilities.
3
+ *
4
+ * Column letters use base-26 encoding: A–Z, AA–AZ, BA–BZ, …
5
+ * Row numbers are 1-based.
6
+ */
7
+ /**
8
+ * Convert a 0-based column index to an Excel-style column letter.
9
+ * @example indexToColumnLetter(0) // 'A'
10
+ * @example indexToColumnLetter(25) // 'Z'
11
+ * @example indexToColumnLetter(26) // 'AA'
12
+ * @example indexToColumnLetter(702) // 'AAA'
13
+ */
14
+ export declare function indexToColumnLetter(index: number): string;
15
+ /**
16
+ * Format a cell reference string from a 0-based column index and a 1-based row number.
17
+ * @example formatCellReference(0, 1) // 'A1'
18
+ * @example formatCellReference(2, 15) // 'C15'
19
+ * @example formatCellReference(26, 100) // 'AA100'
20
+ */
21
+ export declare function formatCellReference(colIndex: number, rowNumber: number): string;
@@ -1,4 +1,5 @@
1
1
  import type { IColumnDef } from '../types/columnTypes';
2
+ import type { IGridDataAccessor } from '../formula/types';
2
3
  /**
3
4
  * Get the cell value for a row/column, using valueGetter when defined otherwise item[columnId].
4
5
  *
@@ -14,3 +15,8 @@ export declare function getCellValue<T>(item: T, col: IColumnDef<T>): unknown;
14
15
  * Handles both boolean and function-based `editable` definitions.
15
16
  */
16
17
  export declare function isColumnEditable<T>(col: IColumnDef<T>, item: T): boolean;
18
+ /**
19
+ * Create an IGridDataAccessor from items and flat columns.
20
+ * Shared factory used by React, Angular, Vue, and JS formula engine integrations.
21
+ */
22
+ export declare function createGridDataAccessor<T>(items: T[], flatColumns: IColumnDef<T>[]): IGridDataAccessor;
@@ -20,9 +20,17 @@ export declare function formatCellValueForTsv(raw: unknown, formatted: unknown):
20
20
  * @param items Flat array of all row data objects.
21
21
  * @param visibleCols Visible column definitions.
22
22
  * @param range The selection range to serialize (will be normalized).
23
+ * @param formulaOptions Optional formula-aware options. When provided, cells with
24
+ * formulas will have their formula string copied instead of
25
+ * the computed value.
23
26
  * @returns TSV string with rows separated by \\r\\n and columns by \\t.
24
27
  */
25
- export declare function formatSelectionAsTsv<T>(items: T[], visibleCols: IColumnDef<T>[], range: ISelectionRange): string;
28
+ export declare function formatSelectionAsTsv<T>(items: T[], visibleCols: IColumnDef<T>[], range: ISelectionRange, formulaOptions?: {
29
+ colOffset: number;
30
+ flatColumns: IColumnDef<T>[];
31
+ getFormula?: (col: number, row: number) => string | undefined;
32
+ hasFormula?: (col: number, row: number) => boolean;
33
+ }): string;
26
34
  /**
27
35
  * Parse a TSV clipboard string into a 2D array of cell strings.
28
36
  * Handles both \\r\\n and \\n line endings. Ignores trailing empty lines.
@@ -36,14 +44,22 @@ export declare function parseTsvClipboard(text: string): string[][];
36
44
  * For each cell in the parsed rows, validates editability, parses the value,
37
45
  * and produces a cell value changed event.
38
46
  *
47
+ * When `formulaOptions` is provided, cells whose pasted text starts with "="
48
+ * are routed through `setFormula` instead of the normal value parse path.
49
+ *
39
50
  * @param parsedRows 2D array of string values (from parseTsvClipboard).
40
51
  * @param anchorRow Target starting row index.
41
52
  * @param anchorCol Target starting column index (data column, not absolute).
42
53
  * @param items Array of all row data objects.
43
54
  * @param visibleCols Visible column definitions.
55
+ * @param formulaOptions Optional formula-aware options.
44
56
  * @returns Array of cell value changed events to apply.
45
57
  */
46
- export declare function applyPastedValues<T>(parsedRows: string[][], anchorRow: number, anchorCol: number, items: T[], visibleCols: IColumnDef<T>[]): ICellValueChangedEvent<T>[];
58
+ export declare function applyPastedValues<T>(parsedRows: string[][], anchorRow: number, anchorCol: number, items: T[], visibleCols: IColumnDef<T>[], formulaOptions?: {
59
+ colOffset: number;
60
+ flatColumns: IColumnDef<T>[];
61
+ setFormula?: (col: number, row: number, formula: string | null) => void;
62
+ }): ICellValueChangedEvent<T>[];
47
63
  /**
48
64
  * Clear cells in a cut range by setting each editable cell to an empty-string-parsed value.
49
65
  * Used after pasting cut content to clear the original cells.
@@ -75,6 +75,12 @@ export interface CellRenderDescriptorInput<T> {
75
75
  onCellValueChanged?: unknown;
76
76
  /** True while user is drag-selecting cells — hides fill handle during drag. */
77
77
  isDragging?: boolean;
78
+ /** Get the formula engine's computed value for a cell (colIdx, rowIndex). */
79
+ getFormulaValue?: (col: number, row: number) => unknown;
80
+ /** Check if a cell has a formula at the given coordinate. */
81
+ hasFormula?: (col: number, row: number) => boolean;
82
+ /** Monotonic counter incremented on each formula recalculation — used for cache invalidation. */
83
+ formulaVersion?: number;
78
84
  }
79
85
  export interface CellRenderDescriptor {
80
86
  mode: CellRenderMode;
@@ -181,8 +187,9 @@ export declare function getCellRenderDescriptor<T>(item: T, col: IColumnDef<T>,
181
187
  export declare function resolveCellDisplayContent<T>(col: IColumnDef<T>, item: T, displayValue: unknown): unknown;
182
188
  /**
183
189
  * Resolves the cellStyle from a column def, handling both function and static values.
190
+ * When displayValue is a FormulaError, merges red error color styling.
184
191
  */
185
- export declare function resolveCellStyle<T>(col: IColumnDef<T>, item: T): Record<string, string> | undefined;
192
+ export declare function resolveCellStyle<T>(col: IColumnDef<T>, item: T, displayValue?: unknown): Record<string, string> | undefined;
186
193
  /**
187
194
  * Builds props for InlineCellEditor. Shared across all UI packages.
188
195
  */
@@ -4,8 +4,16 @@ export interface CsvColumn {
4
4
  }
5
5
  export declare function escapeCsvValue(value: unknown): string;
6
6
  export declare function buildCsvHeader(columns: CsvColumn[]): string;
7
- export declare function buildCsvRows<T>(items: T[], columns: CsvColumn[], getValue: (item: T, columnId: string) => string): string[];
8
- export declare function exportToCsv<T>(items: T[], columns: CsvColumn[], getValue: (item: T, columnId: string) => string, filename?: string): void;
7
+ export interface FormulaExportOptions {
8
+ getFormula?: (col: number, row: number) => string | undefined;
9
+ hasFormula?: (col: number, row: number) => boolean;
10
+ /** Map from columnId to flat column index */
11
+ columnIdToIndex?: Map<string, number>;
12
+ /** Export mode: 'values' (default) exports computed results, 'formulas' exports formula strings */
13
+ exportMode?: 'values' | 'formulas';
14
+ }
15
+ export declare function buildCsvRows<T>(items: T[], columns: CsvColumn[], getValue: (item: T, columnId: string) => unknown, formulaOptions?: FormulaExportOptions): string[];
16
+ export declare function exportToCsv<T>(items: T[], columns: CsvColumn[], getValue: (item: T, columnId: string) => unknown, filename?: string, formulaOptions?: FormulaExportOptions): void;
9
17
  /**
10
18
  * Triggers a browser CSV file download.
11
19
  *
@@ -4,15 +4,32 @@
4
4
  */
5
5
  import type { IColumnDef, ICellValueChangedEvent } from '../types/columnTypes';
6
6
  import type { ISelectionRange } from '../types/dataGridTypes';
7
+ /**
8
+ * Options for formula-aware fill. When provided, source cells with formulas will
9
+ * have their relative references adjusted instead of copying raw values.
10
+ */
11
+ export interface IFillFormulaOptions<T> {
12
+ /** Flat (unfiltered) column list used to map visible col indices to formula storage indices. */
13
+ flatColumns: IColumnDef<T>[];
14
+ /** Returns the formula string for a given (flatColIndex, rowIndex), or undefined if none. */
15
+ getFormula?: (col: number, row: number) => string | undefined;
16
+ /** Returns true if the cell at (flatColIndex, rowIndex) has a formula. */
17
+ hasFormula?: (col: number, row: number) => boolean;
18
+ /** Sets or clears the formula at (flatColIndex, rowIndex). Pass null to clear. */
19
+ setFormula?: (col: number, row: number, formula: string | null) => void;
20
+ }
7
21
  /**
8
22
  * Apply fill values from a source cell across a normalized selection range.
9
23
  * Copies the value from the start cell of the range to every other editable cell.
24
+ * If formulaOptions is provided and the source cell has a formula, relative references
25
+ * in the formula are adjusted for each target cell instead of copying the raw value.
10
26
  *
11
27
  * @param range The normalized fill range (startRow/startCol is the source).
12
28
  * @param sourceRow The original source row index (skipped during fill).
13
29
  * @param sourceCol The original source col index (skipped during fill).
14
30
  * @param items Array of all row data objects.
15
31
  * @param visibleCols Visible column definitions.
32
+ * @param formulaOptions Optional formula-aware fill configuration.
16
33
  * @returns Array of cell value changed events to apply. Empty if source cell is out of bounds.
17
34
  */
18
- export declare function applyFillValues<T>(range: ISelectionRange, sourceRow: number, sourceCol: number, items: T[], visibleCols: IColumnDef<T>[]): ICellValueChangedEvent<T>[];
35
+ export declare function applyFillValues<T>(range: ISelectionRange, sourceRow: number, sourceCol: number, items: T[], visibleCols: IColumnDef<T>[], formulaOptions?: IFillFormulaOptions<T>): ICellValueChangedEvent<T>[];
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Formula bar helper utilities.
3
+ *
4
+ * Extracts cell/range references from a formula string for highlighting.
5
+ * Uses the formula tokenizer to parse CELL_REF and range tokens.
6
+ */
7
+ /** A parsed reference from a formula — either a single cell or a range. */
8
+ export interface FormulaReference {
9
+ type: 'cell' | 'range';
10
+ col: number;
11
+ row: number;
12
+ endCol?: number;
13
+ endRow?: number;
14
+ /** Color palette index (cycles through 0-5). */
15
+ colorIndex: number;
16
+ }
17
+ /**
18
+ * Extract all cell and range references from a formula string.
19
+ * Each reference gets a cycling colorIndex for UI highlighting.
20
+ *
21
+ * @param formula - The formula string including the leading '='.
22
+ * @returns Array of references found in the formula.
23
+ */
24
+ /**
25
+ * Handle Enter/Escape key events in the formula bar input.
26
+ * Shared across React, Angular, Vue, and JS.
27
+ */
28
+ export declare function handleFormulaBarKeyDown(key: string, preventDefault: () => void, onCommit: () => void, onCancel: () => void): void;
29
+ /**
30
+ * Process a formula bar commit: if the text starts with '=', set as formula;
31
+ * otherwise clear any existing formula and commit as a plain value.
32
+ */
33
+ export declare function processFormulaBarCommit(text: string, col: number, row: number, setFormula: (col: number, row: number, formula: string | null) => void, onCellValueChanged?: (col: number, row: number, value: unknown) => void): void;
34
+ /**
35
+ * Derive the display text for a formula bar from the active cell.
36
+ * Returns the formula string (with '=' prefix) if the cell has a formula,
37
+ * otherwise the stringified raw value.
38
+ */
39
+ export declare function deriveFormulaBarText(col: number | null, row: number | null, getFormula?: (col: number, row: number) => string | undefined, getRawValue?: (col: number, row: number) => unknown): string;
40
+ export declare function extractFormulaReferences(formula: string): FormulaReference[];
@@ -1,5 +1,5 @@
1
1
  export { escapeCsvValue, buildCsvHeader, buildCsvRows, exportToCsv, triggerCsvDownload, } from './exportToCsv';
2
- export { getCellValue, isColumnEditable } from './cellValue';
2
+ export { getCellValue, isColumnEditable, createGridDataAccessor } from './cellValue';
3
3
  export { flattenColumns, buildHeaderRows } from './columnUtils';
4
4
  export { isFilterConfig, getFilterField, mergeFilter, deriveFilterOptionsFromData, getMultiSelectFilterFields, } from './ogridHelpers';
5
5
  export { getStatusBarParts } from './statusBarHelpers';
@@ -7,7 +7,7 @@ export { getDataGridStatusBarConfig } from './dataGridStatusBar';
7
7
  export { getPaginationViewModel, PAGE_SIZE_OPTIONS, MAX_PAGE_BUTTONS, } from './paginationHelpers';
8
8
  export type { PaginationViewModel } from './paginationHelpers';
9
9
  export { GRID_CONTEXT_MENU_ITEMS, COLUMN_HEADER_MENU_ITEMS, getContextMenuHandlers, getColumnHeaderMenuItems, formatShortcut } from './gridContextMenuHelpers';
10
- export type { CsvColumn } from './exportToCsv';
10
+ export type { CsvColumn, FormulaExportOptions } from './exportToCsv';
11
11
  export type { StatusBarPart, StatusBarPartsInput } from './statusBarHelpers';
12
12
  export type { GridContextMenuItem, IColumnHeaderMenuItem, GridContextMenuHandlerProps, ColumnHeaderMenuInput, ColumnHeaderMenuHandlers } from './gridContextMenuHelpers';
13
13
  export { parseValue, numberParser, currencyParser, dateParser, emailParser, booleanParser, } from './valueParsers';
@@ -36,5 +36,9 @@ export type { ArrowNavigationContext, ArrowNavigationResult } from './keyboardNa
36
36
  export { rangesEqual, clampSelectionToBounds, computeAutoScrollSpeed, applyRangeRowSelection, computeRowSelectionState } from './selectionHelpers';
37
37
  export { formatCellValueForTsv, formatSelectionAsTsv, parseTsvClipboard, applyPastedValues, applyCutClear, } from './clipboardHelpers';
38
38
  export { applyFillValues } from './fillHelpers';
39
+ export type { IFillFormulaOptions } from './fillHelpers';
39
40
  export { UndoRedoStack } from './undoRedoStack';
40
41
  export { validateColumns, validateRowIds, validateVirtualScrollConfig } from './validation';
42
+ export { indexToColumnLetter, formatCellReference } from './cellReference';
43
+ export { extractFormulaReferences, processFormulaBarCommit, deriveFormulaBarText, handleFormulaBarKeyDown } from './formulaBarHelpers';
44
+ export type { FormulaReference } from './formulaBarHelpers';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alaarab/ogrid-core",
3
- "version": "2.2.0",
3
+ "version": "2.4.0",
4
4
  "description": "OGrid core – framework-agnostic types, algorithms, and utilities for OGrid data grids.",
5
5
  "main": "dist/esm/index.js",
6
6
  "module": "dist/esm/index.js",