@alaarab/ogrid-core 2.1.7 → 2.1.9

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/esm/index.js CHANGED
@@ -73,6 +73,9 @@ function getCellValue(item, col) {
73
73
  if (col.valueGetter) return col.valueGetter(item);
74
74
  return item[col.columnId];
75
75
  }
76
+ function isColumnEditable(col, item) {
77
+ return col.editable === true || typeof col.editable === "function" && col.editable(item);
78
+ }
76
79
 
77
80
  // src/utils/columnUtils.ts
78
81
  function isColumnGroupDef(c) {
@@ -787,9 +790,9 @@ function getHeaderFilterConfig(col, input) {
787
790
  function getCellRenderDescriptor(item, col, rowIndex, colIdx, input) {
788
791
  const rowId = input.getRowId(item);
789
792
  const globalColIndex = colIdx + input.colOffset;
790
- const colEditable = col.editable === true || typeof col.editable === "function" && col.editable(item);
791
- const canEditInline = input.editable !== false && !!colEditable && !!input.onCellValueChanged && typeof col.cellEditor !== "function";
792
- const canEditPopup = input.editable !== false && !!colEditable && !!input.onCellValueChanged && typeof col.cellEditor === "function" && col.cellEditorPopup !== false;
793
+ const colEditable = isColumnEditable(col, item);
794
+ const canEditInline = input.editable !== false && colEditable && !!input.onCellValueChanged && typeof col.cellEditor !== "function";
795
+ const canEditPopup = input.editable !== false && colEditable && !!input.onCellValueChanged && typeof col.cellEditor === "function" && col.cellEditorPopup !== false;
793
796
  const canEditAny = canEditInline || canEditPopup;
794
797
  const isEditing = input.editingCell?.rowId === rowId && input.editingCell?.columnId === col.columnId;
795
798
  const isActive = !input.isDragging && input.activeCell?.rowIndex === rowIndex && input.activeCell?.columnIndex === globalColIndex;
@@ -925,6 +928,18 @@ function measureRange(container, range, colOffset) {
925
928
  height: brRect.bottom - tlRect.top
926
929
  };
927
930
  }
931
+ function buildCellIndex(container) {
932
+ const index = /* @__PURE__ */ new Map();
933
+ if (!container) return index;
934
+ const cells = container.querySelectorAll("[data-row-index][data-col-index]");
935
+ for (let i = 0; i < cells.length; i++) {
936
+ const el = cells[i];
937
+ const r = el.getAttribute("data-row-index") ?? "";
938
+ const c = el.getAttribute("data-col-index") ?? "";
939
+ index.set(`${r},${c}`, el);
940
+ }
941
+ return index;
942
+ }
928
943
  function injectGlobalStyles(id, css) {
929
944
  if (typeof document === "undefined") return;
930
945
  if (document.getElementById(id)) return;
@@ -1086,8 +1101,7 @@ function applyCellDeletion(range, items, visibleCols) {
1086
1101
  if (r >= items.length || c >= visibleCols.length) continue;
1087
1102
  const item = items[r];
1088
1103
  const col = visibleCols[c];
1089
- const colEditable = col.editable === true || typeof col.editable === "function" && col.editable(item);
1090
- if (!colEditable) continue;
1104
+ if (!isColumnEditable(col, item)) continue;
1091
1105
  const oldValue = getCellValue(item, col);
1092
1106
  const result = parseValue("", oldValue, item, col);
1093
1107
  if (!result.valid) continue;
@@ -1187,8 +1201,7 @@ function applyPastedValues(parsedRows, anchorRow, anchorCol, items, visibleCols)
1187
1201
  if (targetRow >= items.length || targetCol >= visibleCols.length) continue;
1188
1202
  const item = items[targetRow];
1189
1203
  const col = visibleCols[targetCol];
1190
- const colEditable = col.editable === true || typeof col.editable === "function" && col.editable(item);
1191
- if (!colEditable) continue;
1204
+ if (!isColumnEditable(col, item)) continue;
1192
1205
  const rawValue = cells[c] ?? "";
1193
1206
  const oldValue = getCellValue(item, col);
1194
1207
  const result = parseValue(rawValue, oldValue, item, col);
@@ -1211,8 +1224,7 @@ function applyCutClear(cutRange, items, visibleCols) {
1211
1224
  if (r >= items.length || c >= visibleCols.length) continue;
1212
1225
  const item = items[r];
1213
1226
  const col = visibleCols[c];
1214
- const colEditable = col.editable === true || typeof col.editable === "function" && col.editable(item);
1215
- if (!colEditable) continue;
1227
+ if (!isColumnEditable(col, item)) continue;
1216
1228
  const oldValue = getCellValue(item, col);
1217
1229
  const result = parseValue("", oldValue, item, col);
1218
1230
  if (!result.valid) continue;
@@ -1241,8 +1253,7 @@ function applyFillValues(range, sourceRow, sourceCol, items, visibleCols) {
1241
1253
  if (row >= items.length || col >= visibleCols.length) continue;
1242
1254
  const item = items[row];
1243
1255
  const colDef = visibleCols[col];
1244
- const colEditable = colDef.editable === true || typeof colDef.editable === "function" && colDef.editable(item);
1245
- if (!colEditable) continue;
1256
+ if (!isColumnEditable(colDef, item)) continue;
1246
1257
  const oldValue = getCellValue(item, colDef);
1247
1258
  const result = parseValue(startValue, oldValue, item, colDef);
1248
1259
  if (!result.valid) continue;
@@ -1423,4 +1434,4 @@ var Z_INDEX = {
1423
1434
  CONTEXT_MENU: 9999
1424
1435
  };
1425
1436
 
1426
- export { AUTOSIZE_EXTRA_PX, AUTOSIZE_MAX_PX, CELL_PADDING, CHECKBOX_COLUMN_WIDTH, COLUMN_HEADER_MENU_ITEMS, DEFAULT_DEBOUNCE_MS, DEFAULT_MIN_COLUMN_WIDTH, GRID_BORDER_RADIUS, GRID_CONTEXT_MENU_ITEMS, MAX_PAGE_BUTTONS, PAGE_SIZE_OPTIONS, PEOPLE_SEARCH_DEBOUNCE_MS, ROW_NUMBER_COLUMN_WIDTH, SIDEBAR_TRANSITION_MS, UndoRedoStack, Z_INDEX, applyCellDeletion, applyCutClear, applyFillValues, applyPastedValues, applyRangeRowSelection, areGridRowPropsEqual, booleanParser, buildCsvHeader, buildCsvRows, buildHeaderRows, buildInlineEditorProps, buildPopoverEditorProps, calculateDropTarget, clampSelectionToBounds, computeAggregations, computeArrowNavigation, computeAutoScrollSpeed, computeNextSortState, computeRowSelectionState, computeTabNavigation, computeTotalHeight, computeVisibleRange, currencyParser, dateParser, debounce, deriveFilterOptionsFromData, emailParser, escapeCsvValue, exportToCsv, findCtrlArrowTarget, flattenColumns, formatCellValueForTsv, formatSelectionAsTsv, formatShortcut, getCellRenderDescriptor, getCellValue, getColumnHeaderMenuItems, getContextMenuHandlers, getDataGridStatusBarConfig, getFilterField, getHeaderFilterConfig, getMultiSelectFilterFields, getPaginationViewModel, getPinStateForColumn, getScrollTopForRow, getStatusBarParts, injectGlobalStyles, isFilterConfig, isInSelectionRange, isRowInRange, measureColumnContentWidth, measureRange, mergeFilter, normalizeSelectionRange, numberParser, parseTsvClipboard, parseValue, processClientSideData, rangesEqual, reorderColumnArray, resolveCellDisplayContent, resolveCellStyle, toUserLike, triggerCsvDownload, validateColumns, validateRowIds };
1437
+ export { AUTOSIZE_EXTRA_PX, AUTOSIZE_MAX_PX, CELL_PADDING, CHECKBOX_COLUMN_WIDTH, COLUMN_HEADER_MENU_ITEMS, DEFAULT_DEBOUNCE_MS, DEFAULT_MIN_COLUMN_WIDTH, GRID_BORDER_RADIUS, GRID_CONTEXT_MENU_ITEMS, MAX_PAGE_BUTTONS, PAGE_SIZE_OPTIONS, PEOPLE_SEARCH_DEBOUNCE_MS, ROW_NUMBER_COLUMN_WIDTH, SIDEBAR_TRANSITION_MS, UndoRedoStack, Z_INDEX, applyCellDeletion, applyCutClear, applyFillValues, applyPastedValues, applyRangeRowSelection, areGridRowPropsEqual, booleanParser, buildCellIndex, buildCsvHeader, buildCsvRows, buildHeaderRows, buildInlineEditorProps, buildPopoverEditorProps, calculateDropTarget, clampSelectionToBounds, computeAggregations, computeArrowNavigation, computeAutoScrollSpeed, computeNextSortState, computeRowSelectionState, computeTabNavigation, computeTotalHeight, computeVisibleRange, currencyParser, dateParser, debounce, deriveFilterOptionsFromData, emailParser, escapeCsvValue, exportToCsv, findCtrlArrowTarget, flattenColumns, formatCellValueForTsv, formatSelectionAsTsv, formatShortcut, getCellRenderDescriptor, getCellValue, getColumnHeaderMenuItems, getContextMenuHandlers, getDataGridStatusBarConfig, getFilterField, getHeaderFilterConfig, getMultiSelectFilterFields, getPaginationViewModel, getPinStateForColumn, getScrollTopForRow, getStatusBarParts, injectGlobalStyles, isColumnEditable, isFilterConfig, isInSelectionRange, isRowInRange, measureColumnContentWidth, measureRange, mergeFilter, normalizeSelectionRange, numberParser, parseTsvClipboard, parseValue, processClientSideData, rangesEqual, reorderColumnArray, resolveCellDisplayContent, resolveCellStyle, toUserLike, triggerCsvDownload, validateColumns, validateRowIds };
@@ -3,7 +3,7 @@ export type { RowId, UserLike, UserLikeInput, FilterValue, IFilters, IFetchParam
3
3
  export { toUserLike, isInSelectionRange, normalizeSelectionRange, } from './types';
4
4
  export { escapeCsvValue, buildCsvHeader, buildCsvRows, exportToCsv, triggerCsvDownload, } from './utils';
5
5
  export type { CsvColumn } from './utils';
6
- export { getCellValue } from './utils';
6
+ export { getCellValue, isColumnEditable } from './utils';
7
7
  export { flattenColumns, buildHeaderRows } from './utils';
8
8
  export { isFilterConfig, getFilterField, mergeFilter, deriveFilterOptionsFromData, getMultiSelectFilterFields, } from './utils';
9
9
  export { getStatusBarParts } from './utils';
@@ -27,7 +27,7 @@ export type { IVisibleRange } from './utils';
27
27
  export { getHeaderFilterConfig, getCellRenderDescriptor, resolveCellDisplayContent, resolveCellStyle, buildInlineEditorProps, buildPopoverEditorProps, } from './utils';
28
28
  export type { HeaderFilterConfigInput, HeaderFilterConfig, CellRenderDescriptorInput, CellRenderDescriptor, CellRenderMode, } from './utils';
29
29
  export { debounce } from './utils';
30
- export { measureRange, injectGlobalStyles } from './utils';
30
+ export { measureRange, buildCellIndex, injectGlobalStyles } from './utils';
31
31
  export type { OverlayRect } from './utils';
32
32
  export { computeNextSortState } from './utils';
33
33
  export type { ISortState } from './utils';
@@ -9,3 +9,8 @@ import type { IColumnDef } from '../types/columnTypes';
9
9
  * @returns The raw cell value (`unknown`). May be `undefined` if the key does not exist on the item.
10
10
  */
11
11
  export declare function getCellValue<T>(item: T, col: IColumnDef<T>): unknown;
12
+ /**
13
+ * Check whether a column is editable for a given row item.
14
+ * Handles both boolean and function-based `editable` definitions.
15
+ */
16
+ export declare function isColumnEditable<T>(col: IColumnDef<T>, item: T): boolean;
@@ -35,4 +35,9 @@ export declare function measureRange(container: HTMLElement, range: ISelectionRa
35
35
  * );
36
36
  * ```
37
37
  */
38
+ /**
39
+ * Build a Map of `"rowIndex,colIndex"` → HTMLElement for O(1) cell lookups during drag operations.
40
+ * Scans the container once via querySelectorAll instead of per-frame DOM queries.
41
+ */
42
+ export declare function buildCellIndex(container: HTMLElement | null): Map<string, HTMLElement>;
38
43
  export declare function injectGlobalStyles(id: string, css: string): void;
@@ -1,5 +1,5 @@
1
1
  export { escapeCsvValue, buildCsvHeader, buildCsvRows, exportToCsv, triggerCsvDownload, } from './exportToCsv';
2
- export { getCellValue } from './cellValue';
2
+ export { getCellValue, isColumnEditable } 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';
@@ -24,7 +24,7 @@ export type { IVisibleRange } from './virtualScroll';
24
24
  export { getHeaderFilterConfig, getCellRenderDescriptor, resolveCellDisplayContent, resolveCellStyle, buildInlineEditorProps, buildPopoverEditorProps, } from './dataGridViewModel';
25
25
  export type { HeaderFilterConfigInput, HeaderFilterConfig, CellRenderDescriptorInput, CellRenderDescriptor, CellRenderMode, } from './dataGridViewModel';
26
26
  export { debounce } from './debounce';
27
- export { measureRange, injectGlobalStyles } from './dom';
27
+ export { measureRange, buildCellIndex, injectGlobalStyles } from './dom';
28
28
  export type { OverlayRect } from './dom';
29
29
  export { computeNextSortState } from './sortHelpers';
30
30
  export type { ISortState } from './sortHelpers';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alaarab/ogrid-core",
3
- "version": "2.1.7",
3
+ "version": "2.1.9",
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",