@alaarab/ogrid-core 2.4.2 → 2.5.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.
@@ -2,15 +2,9 @@
2
2
  * Cell address parsing and formatting utilities for the formula system.
3
3
  * Extends the existing cellReference.ts with reverse parsing and absolute reference support.
4
4
  */
5
+ import { columnLetterToIndex } from '../utils/cellReference';
5
6
  import type { ICellAddress, ICellRange, CellKey } from './types';
6
- /**
7
- * Parse a column letter string to a 0-based index.
8
- * @example columnLetterToIndex('A') // 0
9
- * @example columnLetterToIndex('Z') // 25
10
- * @example columnLetterToIndex('AA') // 26
11
- * @example columnLetterToIndex('AZ') // 51
12
- */
13
- export declare function columnLetterToIndex(letters: string): number;
7
+ export { columnLetterToIndex };
14
8
  /**
15
9
  * Parse a cell reference string like "A1", "$B$2", "$A1", "A$1".
16
10
  * Returns null on invalid input.
@@ -7,7 +7,10 @@ export { REF_ERROR, DIV_ZERO_ERROR, VALUE_ERROR, NAME_ERROR, CIRC_ERROR, GENERAL
7
7
  export { columnLetterToIndex, parseCellRef, parseRange, formatAddress, toCellKey, fromCellKey, adjustFormulaReferences, } from './cellAddressUtils';
8
8
  export { tokenize } from './tokenizer';
9
9
  export { parse } from './parser';
10
- export { FormulaEvaluator, toNumber, toString, toBoolean, flattenArgs, } from './evaluator';
10
+ export { FormulaEvaluator, toNumber, toString, toString as formulaToString, toBoolean, flattenArgs, } from './evaluator';
11
11
  export { DependencyGraph } from './dependencyGraph';
12
12
  export { FormulaEngine } from './formulaEngine';
13
13
  export { createBuiltInFunctions } from './functions';
14
+ export { extractFormulaReferences, processFormulaBarCommit, deriveFormulaBarText, handleFormulaBarKeyDown, canInsertReference, insertReferenceAtCursor, } from '../utils/formulaBarHelpers';
15
+ export type { FormulaReference } from '../utils/formulaBarHelpers';
16
+ export { FORMULA_REF_COLORS, FORMULA_BAR_CSS, FORMULA_BAR_STYLES } from '../constants/formulaBar';
@@ -42,13 +42,12 @@ export { applyFillValues } from './utils';
42
42
  export type { IFillFormulaOptions } from './utils';
43
43
  export { UndoRedoStack } from './utils';
44
44
  export { validateColumns, validateRowIds, validateVirtualScrollConfig } from './utils';
45
- export { indexToColumnLetter, formatCellReference } from './utils';
46
- export { extractFormulaReferences, processFormulaBarCommit, deriveFormulaBarText, handleFormulaBarKeyDown } from './utils';
45
+ export { indexToColumnLetter, columnLetterToIndex, formatCellReference } from './utils';
47
46
  export type { FormulaReference } from './utils';
47
+ export { getResponsiveHiddenColumns, RESPONSIVE_BREAKPOINTS, resolveResponsiveConfig, applyResponsiveHiding } from './utils';
48
+ export type { IResponsiveColumnsConfig } from './utils';
48
49
  export { CHECKBOX_COLUMN_WIDTH, ROW_NUMBER_COLUMN_WIDTH, ROW_NUMBER_COLUMN_MIN_WIDTH, ROW_NUMBER_COLUMN_ID, DEFAULT_MIN_COLUMN_WIDTH, CELL_PADDING, GRID_BORDER_RADIUS, } from './constants';
49
50
  export { DEFAULT_DEBOUNCE_MS, PEOPLE_SEARCH_DEBOUNCE_MS, SIDEBAR_TRANSITION_MS, } from './constants';
50
51
  export { Z_INDEX } from './constants';
51
52
  export type { ZIndexKey } from './constants';
52
- export { FORMULA_REF_COLORS, FORMULA_BAR_CSS, FORMULA_BAR_STYLES } from './constants';
53
- export { FormulaError, FormulaEngine, FormulaEvaluator, DependencyGraph, tokenize, parse, createBuiltInFunctions, columnLetterToIndex, parseCellRef, parseRange, formatAddress, toCellKey, fromCellKey, adjustFormulaReferences, toNumber, toString as formulaToString, toBoolean, flattenArgs, isFormulaError, REF_ERROR, DIV_ZERO_ERROR, VALUE_ERROR, NAME_ERROR, CIRC_ERROR, GENERAL_ERROR, NA_ERROR, } from './formula';
54
53
  export type { ICellAddress, ICellRange, CellKey, FormulaErrorType, TokenType, Token, ASTNode, BinaryOp, IFormulaContext, IFormulaFunction, IEvaluator, IRecalcResult, IFormulaEngineConfig, IGridDataAccessor, INamedRange, IAuditEntry, IAuditTrail, } from './formula';
@@ -21,6 +21,12 @@ export interface IColumnMeta {
21
21
  filterable?: IColumnFilterDef;
22
22
  defaultVisible?: boolean;
23
23
  required?: boolean;
24
+ /**
25
+ * Responsive priority (0 = highest). Columns with higher numbers are hidden
26
+ * first when the container is narrow. Columns without a priority are never
27
+ * auto-hidden. `required` columns are never auto-hidden regardless of priority.
28
+ */
29
+ responsivePriority?: number;
24
30
  minWidth?: number;
25
31
  defaultWidth?: number;
26
32
  idealWidth?: number;
@@ -12,6 +12,14 @@
12
12
  * @example indexToColumnLetter(702) // 'AAA'
13
13
  */
14
14
  export declare function indexToColumnLetter(index: number): string;
15
+ /**
16
+ * Parse a column letter string to a 0-based index.
17
+ * @example columnLetterToIndex('A') // 0
18
+ * @example columnLetterToIndex('Z') // 25
19
+ * @example columnLetterToIndex('AA') // 26
20
+ * @example columnLetterToIndex('AZ') // 51
21
+ */
22
+ export declare function columnLetterToIndex(letters: string): number;
15
23
  /**
16
24
  * Format a cell reference string from a 0-based column index and a 1-based row number.
17
25
  * @example formatCellReference(0, 1) // 'A1'
@@ -79,6 +79,8 @@ export interface CellRenderDescriptorInput<T> {
79
79
  getFormulaValue?: (col: number, row: number) => unknown;
80
80
  /** Check if a cell has a formula at the given coordinate. */
81
81
  hasFormula?: (col: number, row: number) => boolean;
82
+ /** Get the formula string for a cell (e.g. '=SUM(A1:A5)'). Used to populate the editor with the formula instead of the computed value. */
83
+ getFormula?: (col: number, row: number) => string | undefined;
82
84
  /** Monotonic counter incremented on each formula recalculation — used for cache invalidation. */
83
85
  formulaVersion?: number;
84
86
  }
@@ -37,4 +37,21 @@ export declare function processFormulaBarCommit(text: string, col: number, row:
37
37
  * otherwise the stringified raw value.
38
38
  */
39
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
+ /**
41
+ * Check whether a formula text is in a position where a cell reference can be inserted
42
+ * at the cursor. Returns true when the text starts with '=' and the character before the
43
+ * cursor is an operator, paren, comma, colon, whitespace, or the cursor is right after '='.
44
+ */
45
+ export declare function canInsertReference(text: string, cursorPos: number): boolean;
46
+ /**
47
+ * Insert a cell reference into formula text at the given cursor position.
48
+ * If `canInsertReference` returns false (cursor is adjacent to a token), the reference
49
+ * replaces the preceding token back to the last operator/delimiter.
50
+ *
51
+ * @returns Updated text and new cursor position after the inserted reference.
52
+ */
53
+ export declare function insertReferenceAtCursor(text: string, cursorPos: number, reference: string): {
54
+ text: string;
55
+ cursorPos: number;
56
+ };
40
57
  export declare function extractFormulaReferences(formula: string): FormulaReference[];
@@ -39,6 +39,8 @@ export { applyFillValues } from './fillHelpers';
39
39
  export type { IFillFormulaOptions } from './fillHelpers';
40
40
  export { UndoRedoStack } from './undoRedoStack';
41
41
  export { validateColumns, validateRowIds, validateVirtualScrollConfig } from './validation';
42
- export { indexToColumnLetter, formatCellReference } from './cellReference';
43
- export { extractFormulaReferences, processFormulaBarCommit, deriveFormulaBarText, handleFormulaBarKeyDown } from './formulaBarHelpers';
42
+ export { indexToColumnLetter, columnLetterToIndex, formatCellReference } from './cellReference';
43
+ export { extractFormulaReferences, processFormulaBarCommit, deriveFormulaBarText, handleFormulaBarKeyDown, canInsertReference, insertReferenceAtCursor } from './formulaBarHelpers';
44
44
  export type { FormulaReference } from './formulaBarHelpers';
45
+ export { getResponsiveHiddenColumns, RESPONSIVE_BREAKPOINTS, resolveResponsiveConfig, applyResponsiveHiding } from './responsiveColumns';
46
+ export type { IResponsiveColumnsConfig } from './responsiveColumns';
@@ -0,0 +1,46 @@
1
+ import type { IColumnMeta } from '../types/columnTypes';
2
+ /**
3
+ * Default breakpoints for responsive column hiding.
4
+ * Each threshold maps a minimum container width (px) to how many responsive
5
+ * priority levels are visible. At 0px all priority-0 columns are shown;
6
+ * wider containers show progressively more columns.
7
+ *
8
+ * Example with default thresholds:
9
+ * container < 576px → show only priority 0
10
+ * container < 768px → show priority 0–1
11
+ * container < 992px → show priority 0–2
12
+ * container < 1200px → show priority 0–3
13
+ * container ≥ 1200px → show all (no limit)
14
+ */
15
+ export declare const RESPONSIVE_BREAKPOINTS: readonly {
16
+ minWidth: number;
17
+ maxPriority: number;
18
+ }[];
19
+ export interface IResponsiveColumnsConfig {
20
+ /** Custom breakpoints (ascending by minWidth). When omitted, uses RESPONSIVE_BREAKPOINTS. */
21
+ breakpoints?: readonly {
22
+ minWidth: number;
23
+ maxPriority: number;
24
+ }[];
25
+ }
26
+ /**
27
+ * Pure function: given a container width and column definitions, returns the set
28
+ * of column IDs that should be hidden due to responsive priority.
29
+ *
30
+ * Columns WITHOUT `responsivePriority` are never hidden.
31
+ * Columns with `required: true` are never hidden.
32
+ *
33
+ * @returns Set of columnIds to hide. Empty set means no responsive hiding.
34
+ */
35
+ export declare function getResponsiveHiddenColumns<T extends IColumnMeta>(containerWidth: number, columns: readonly T[], config?: IResponsiveColumnsConfig): Set<string>;
36
+ /**
37
+ * Normalize the `responsiveColumns` prop value (boolean | config | undefined)
38
+ * into a config object or undefined. Used by all framework packages so they
39
+ * don't each duplicate the `true → {}` coercion.
40
+ */
41
+ export declare function resolveResponsiveConfig(value: boolean | IResponsiveColumnsConfig | undefined): IResponsiveColumnsConfig | undefined;
42
+ /**
43
+ * Apply responsive column hiding to an already-filtered column list.
44
+ * Returns the input array unchanged when no columns need hiding (avoids allocation).
45
+ */
46
+ export declare function applyResponsiveHiding<T extends IColumnMeta>(columns: readonly T[], containerWidth: number, config: IResponsiveColumnsConfig | undefined): readonly T[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alaarab/ogrid-core",
3
- "version": "2.4.2",
3
+ "version": "2.5.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",
@@ -10,6 +10,11 @@
10
10
  "types": "./dist/types/index.d.ts",
11
11
  "import": "./dist/esm/index.js",
12
12
  "default": "./dist/esm/index.js"
13
+ },
14
+ "./formula": {
15
+ "types": "./dist/types/formula/index.d.ts",
16
+ "import": "./dist/esm/formula/index.js",
17
+ "default": "./dist/esm/formula/index.js"
13
18
  }
14
19
  },
15
20
  "scripts": {