@alaarab/ogrid-js 2.4.0 → 2.4.1

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 (2) hide show
  1. package/dist/esm/index.js +92 -16
  2. package/package.json +2 -2
package/dist/esm/index.js CHANGED
@@ -1221,7 +1221,8 @@ function computeCellDescriptor(item, col, rowIndex, colIdx, input) {
1221
1221
  globalColIndex,
1222
1222
  rowId,
1223
1223
  rowIndex,
1224
- displayValue: formulaDisplay !== void 0 ? formulaDisplay : cellValue
1224
+ displayValue: formulaDisplay !== void 0 ? formulaDisplay : cellValue,
1225
+ columnType: col.type
1225
1226
  };
1226
1227
  }
1227
1228
  function resolveCellDisplayContent(col, item, displayValue) {
@@ -1354,6 +1355,8 @@ var CHECKBOX_COLUMN_WIDTH = 48;
1354
1355
  var ROW_NUMBER_COLUMN_WIDTH = 50;
1355
1356
  var DEFAULT_MIN_COLUMN_WIDTH = 80;
1356
1357
  var CELL_PADDING = 16;
1358
+ var ROW_NUMBER_COLUMN_MIN_WIDTH = 30;
1359
+ var ROW_NUMBER_COLUMN_ID = "__row_number__";
1357
1360
  var GRID_BORDER_RADIUS = 6;
1358
1361
  var AUTOSIZE_EXTRA_PX = 16;
1359
1362
  var AUTOSIZE_MAX_PX = 520;
@@ -7579,12 +7582,13 @@ var TableRenderer = class {
7579
7582
  const target = e.target;
7580
7583
  if (target.classList.contains("ogrid-resize-handle")) {
7581
7584
  e.stopPropagation();
7585
+ const handleColumnId = target.getAttribute("data-column-id");
7582
7586
  const th = target.closest("th[data-column-id]");
7583
- if (!th) return;
7584
- const columnId = th.getAttribute("data-column-id");
7587
+ const columnId = handleColumnId ?? th?.getAttribute("data-column-id");
7585
7588
  if (columnId) {
7586
- const rect = th.getBoundingClientRect();
7587
- this.interactionState?.onResizeStart?.(columnId, e.clientX, rect.width);
7589
+ const parentTh = target.closest("th");
7590
+ const rect = parentTh?.getBoundingClientRect();
7591
+ this.interactionState?.onResizeStart?.(columnId, e.clientX, rect?.width ?? ROW_NUMBER_COLUMN_WIDTH);
7588
7592
  }
7589
7593
  return;
7590
7594
  }
@@ -7602,9 +7606,9 @@ var TableRenderer = class {
7602
7606
  const target = e.target;
7603
7607
  if (target.classList.contains("ogrid-resize-handle")) {
7604
7608
  e.stopPropagation();
7609
+ const handleColumnId = target.getAttribute("data-column-id");
7605
7610
  const th = target.closest("th[data-column-id]");
7606
- if (!th) return;
7607
- const columnId = th.getAttribute("data-column-id");
7611
+ const columnId = handleColumnId ?? th?.getAttribute("data-column-id");
7608
7612
  if (columnId) {
7609
7613
  this.interactionState?.onResizeDoubleClick?.(columnId);
7610
7614
  }
@@ -7681,6 +7685,9 @@ var TableRenderer = class {
7681
7685
  parts.push(`allSel:${is?.allSelected ?? ""}`);
7682
7686
  parts.push(`someSel:${is?.someSelected ?? ""}`);
7683
7687
  parts.push(`rn:${is?.showRowNumbers ?? ""}`);
7688
+ if (is?.showRowNumbers) {
7689
+ parts.push(`rnw:${is?.columnWidths[ROW_NUMBER_COLUMN_ID] ?? ""}`);
7690
+ }
7684
7691
  parts.push(`cl:${is?.showColumnLetters ?? ""}`);
7685
7692
  for (const [colId, config] of this.filterConfigs) {
7686
7693
  const hasActive = this.headerFilterState?.hasActiveFilter(config);
@@ -7896,7 +7903,8 @@ var TableRenderer = class {
7896
7903
  if (hasRowNumbers) {
7897
7904
  const th = document.createElement("th");
7898
7905
  th.className = "ogrid-column-letter-cell";
7899
- th.style.width = `${ROW_NUMBER_COLUMN_WIDTH}px`;
7906
+ const rnw = this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID] ?? ROW_NUMBER_COLUMN_WIDTH;
7907
+ th.style.width = `${rnw}px`;
7900
7908
  letterTr.appendChild(th);
7901
7909
  }
7902
7910
  for (let colIdx = 0; colIdx < visibleCols.length; colIdx++) {
@@ -7909,17 +7917,49 @@ var TableRenderer = class {
7909
7917
  }
7910
7918
  const headerRows = buildHeaderRows(this.state.allColumns, this.state.visibleColumns);
7911
7919
  if (headerRows.length > 1) {
7912
- for (const row of headerRows) {
7920
+ for (let rowIdx = 0; rowIdx < headerRows.length; rowIdx++) {
7921
+ const row = headerRows[rowIdx];
7922
+ const isLastRow = rowIdx === headerRows.length - 1;
7913
7923
  const tr = document.createElement("tr");
7914
7924
  if (hasCheckbox) {
7915
7925
  const th = document.createElement("th");
7916
7926
  th.className = "ogrid-header-cell ogrid-checkbox-header";
7917
7927
  th.style.width = `${CHECKBOX_COLUMN_WIDTH}px`;
7918
- if (row === headerRows[headerRows.length - 1]) {
7928
+ if (isLastRow) {
7919
7929
  this.appendSelectAllCheckbox(th);
7920
7930
  }
7921
7931
  tr.appendChild(th);
7922
7932
  }
7933
+ if (hasRowNumbers) {
7934
+ if (isLastRow) {
7935
+ const rnw = this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID] ?? ROW_NUMBER_COLUMN_WIDTH;
7936
+ const th = document.createElement("th");
7937
+ th.className = "ogrid-header-cell ogrid-row-number-header";
7938
+ th.style.width = `${rnw}px`;
7939
+ th.style.minWidth = `${rnw}px`;
7940
+ th.style.maxWidth = `${rnw}px`;
7941
+ th.style.textAlign = "center";
7942
+ th.style.position = th.style.position || "relative";
7943
+ th.textContent = "#";
7944
+ const resizeHandle = document.createElement("div");
7945
+ resizeHandle.className = "ogrid-resize-handle";
7946
+ resizeHandle.style.position = "absolute";
7947
+ resizeHandle.style.right = "0";
7948
+ resizeHandle.style.top = "0";
7949
+ resizeHandle.style.bottom = "0";
7950
+ resizeHandle.style.width = "4px";
7951
+ resizeHandle.style.cursor = "col-resize";
7952
+ resizeHandle.style.userSelect = "none";
7953
+ resizeHandle.setAttribute("data-column-id", ROW_NUMBER_COLUMN_ID);
7954
+ th.appendChild(resizeHandle);
7955
+ tr.appendChild(th);
7956
+ } else if (rowIdx === 0) {
7957
+ const th = document.createElement("th");
7958
+ th.rowSpan = headerRows.length - 1;
7959
+ th.style.padding = "0";
7960
+ tr.appendChild(th);
7961
+ }
7962
+ }
7923
7963
  for (const cell of row) {
7924
7964
  const th = document.createElement("th");
7925
7965
  th.textContent = cell.label;
@@ -7954,11 +7994,26 @@ var TableRenderer = class {
7954
7994
  tr.appendChild(th);
7955
7995
  }
7956
7996
  if (this.hasRowNumbersColumn()) {
7997
+ const rnw = this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID] ?? ROW_NUMBER_COLUMN_WIDTH;
7957
7998
  const th = document.createElement("th");
7958
7999
  th.className = "ogrid-header-cell ogrid-row-number-header";
7959
- th.style.width = `${ROW_NUMBER_COLUMN_WIDTH}px`;
8000
+ th.style.width = `${rnw}px`;
8001
+ th.style.minWidth = `${rnw}px`;
8002
+ th.style.maxWidth = `${rnw}px`;
7960
8003
  th.style.textAlign = "center";
8004
+ th.style.position = th.style.position || "relative";
7961
8005
  th.textContent = "#";
8006
+ const resizeHandle = document.createElement("div");
8007
+ resizeHandle.className = "ogrid-resize-handle";
8008
+ resizeHandle.style.position = "absolute";
8009
+ resizeHandle.style.right = "0";
8010
+ resizeHandle.style.top = "0";
8011
+ resizeHandle.style.bottom = "0";
8012
+ resizeHandle.style.width = "4px";
8013
+ resizeHandle.style.cursor = "col-resize";
8014
+ resizeHandle.style.userSelect = "none";
8015
+ resizeHandle.setAttribute("data-column-id", ROW_NUMBER_COLUMN_ID);
8016
+ th.appendChild(resizeHandle);
7962
8017
  tr.appendChild(th);
7963
8018
  }
7964
8019
  for (let colIdx = 0; colIdx < visibleCols.length; colIdx++) {
@@ -8130,9 +8185,12 @@ var TableRenderer = class {
8130
8185
  tr.appendChild(td);
8131
8186
  }
8132
8187
  if (hasRowNumbers) {
8188
+ const rnw = this.interactionState?.columnWidths[ROW_NUMBER_COLUMN_ID] ?? ROW_NUMBER_COLUMN_WIDTH;
8133
8189
  const td = document.createElement("td");
8134
8190
  td.className = "ogrid-cell ogrid-row-number-cell";
8135
- td.style.width = `${ROW_NUMBER_COLUMN_WIDTH}px`;
8191
+ td.style.width = `${rnw}px`;
8192
+ td.style.minWidth = `${rnw}px`;
8193
+ td.style.maxWidth = `${rnw}px`;
8136
8194
  td.style.textAlign = "center";
8137
8195
  td.style.color = "var(--ogrid-fg-muted, #666)";
8138
8196
  td.style.fontSize = "0.9em";
@@ -8188,7 +8246,16 @@ var TableRenderer = class {
8188
8246
  } else {
8189
8247
  const rawValue = getCellValue(item, col);
8190
8248
  const value = this.formulaEngine?.isEnabled() && this.formulaEngine.hasFormula(colIndex, rowIndex) ? this.formulaEngine.getValue(colIndex, rowIndex) ?? rawValue : rawValue;
8191
- if (col.valueFormatter) {
8249
+ if (col.type === "boolean") {
8250
+ const checkbox = document.createElement("input");
8251
+ checkbox.type = "checkbox";
8252
+ checkbox.checked = Boolean(value);
8253
+ checkbox.disabled = true;
8254
+ checkbox.style.margin = "0";
8255
+ checkbox.style.pointerEvents = "none";
8256
+ checkbox.setAttribute("aria-label", value ? "True" : "False");
8257
+ td.appendChild(checkbox);
8258
+ } else if (col.valueFormatter) {
8192
8259
  td.textContent = col.valueFormatter(value, item);
8193
8260
  } else if (value != null) {
8194
8261
  td.textContent = String(value);
@@ -10329,13 +10396,15 @@ var ColumnResizeState = class {
10329
10396
  updateResize(clientX) {
10330
10397
  if (!this.isResizing || !this.resizeColumnId) return null;
10331
10398
  const delta = clientX - this.resizeStartX;
10332
- const newWidth = Math.max(DEFAULT_MIN_COLUMN_WIDTH, this.resizeStartWidth + delta);
10399
+ const minW = this.resizeColumnId === ROW_NUMBER_COLUMN_ID ? ROW_NUMBER_COLUMN_MIN_WIDTH : DEFAULT_MIN_COLUMN_WIDTH;
10400
+ const newWidth = Math.max(minW, this.resizeStartWidth + delta);
10333
10401
  return newWidth;
10334
10402
  }
10335
10403
  endResize(clientX) {
10336
10404
  if (!this.isResizing || !this.resizeColumnId) return;
10337
10405
  const delta = clientX - this.resizeStartX;
10338
- const newWidth = Math.max(DEFAULT_MIN_COLUMN_WIDTH, this.resizeStartWidth + delta);
10406
+ const minW = this.resizeColumnId === ROW_NUMBER_COLUMN_ID ? ROW_NUMBER_COLUMN_MIN_WIDTH : DEFAULT_MIN_COLUMN_WIDTH;
10407
+ const newWidth = Math.max(minW, this.resizeStartWidth + delta);
10339
10408
  this.columnWidths.set(this.resizeColumnId, newWidth);
10340
10409
  this.emitter.emit("columnWidthChange", { columnId: this.resizeColumnId, widthPx: newWidth });
10341
10410
  this.isResizing = false;
@@ -10928,6 +10997,8 @@ var InlineCellEditor = class {
10928
10997
  e.stopPropagation();
10929
10998
  this.onCancel?.();
10930
10999
  this.closeEditor();
11000
+ } else if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(e.key)) {
11001
+ e.stopPropagation();
10931
11002
  } else if ((e.ctrlKey || e.metaKey) && ["c", "x", "v", "a", "z", "y"].includes(e.key)) {
10932
11003
  e.stopPropagation();
10933
11004
  }
@@ -10972,6 +11043,8 @@ var InlineCellEditor = class {
10972
11043
  e.stopPropagation();
10973
11044
  this.onCancel?.();
10974
11045
  this.closeEditor();
11046
+ } else if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(e.key)) {
11047
+ e.stopPropagation();
10975
11048
  }
10976
11049
  });
10977
11050
  return input;
@@ -11070,6 +11143,7 @@ var InlineCellEditor = class {
11070
11143
  };
11071
11144
  buildOptions();
11072
11145
  wrapper.addEventListener("keydown", (e) => {
11146
+ e.stopPropagation();
11073
11147
  switch (e.key) {
11074
11148
  case "ArrowDown": {
11075
11149
  e.preventDefault();
@@ -11191,6 +11265,8 @@ var InlineCellEditor = class {
11191
11265
  e.stopPropagation();
11192
11266
  this.onCancel?.();
11193
11267
  this.closeEditor();
11268
+ } else if (["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(e.key)) {
11269
+ e.stopPropagation();
11194
11270
  } else if ((e.ctrlKey || e.metaKey) && ["c", "x", "v", "a", "z", "y"].includes(e.key)) {
11195
11271
  e.stopPropagation();
11196
11272
  }
@@ -12756,4 +12832,4 @@ var OGrid = class {
12756
12832
  }
12757
12833
  };
12758
12834
 
12759
- export { AUTOSIZE_EXTRA_PX, AUTOSIZE_MAX_PX, CELL_PADDING, CHECKBOX_COLUMN_WIDTH, CIRC_ERROR, COLUMN_HEADER_MENU_ITEMS, CellDescriptorCache, ClipboardState, ColumnChooser, ColumnPinningState, ColumnReorderState, ColumnResizeState, ContextMenu, DEFAULT_DEBOUNCE_MS, DEFAULT_MIN_COLUMN_WIDTH, DIV_ZERO_ERROR, DependencyGraph, EventEmitter, FORMULA_BAR_CSS, FORMULA_BAR_STYLES, FORMULA_REF_COLORS, FillHandleState, FormulaBar, FormulaEngine, FormulaEngineState, FormulaError, FormulaEvaluator, GENERAL_ERROR, GRID_BORDER_RADIUS, GRID_CONTEXT_MENU_ITEMS, GridState, HeaderFilter, HeaderFilterState, InlineCellEditor, KeyboardNavState, MAX_PAGE_BUTTONS, MarchingAntsOverlay, NAME_ERROR, NA_ERROR, OGrid, OGridEventWiring, OGridRendering, PAGE_SIZE_OPTIONS, PEOPLE_SEARCH_DEBOUNCE_MS, PaginationControls, REF_ERROR, ROW_NUMBER_COLUMN_WIDTH, RowSelectionState, SIDEBAR_TRANSITION_MS, SelectionState, SideBar, SideBarState, StatusBar, TableLayoutState, TableRenderer, UndoRedoStack, UndoRedoState, VALUE_ERROR, VirtualScrollState, Z_INDEX, adjustFormulaReferences, applyCellDeletion, applyCutClear, applyFillValues, applyPastedValues, applyRangeRowSelection, areGridRowPropsEqual, booleanParser, buildCellIndex, buildCsvHeader, buildCsvRows, buildHeaderRows, buildInlineEditorProps, buildPopoverEditorProps, calculateDropTarget, clampSelectionToBounds, columnLetterToIndex, computeAggregations, computeArrowNavigation, computeAutoScrollSpeed, computeNextSortState, computeRowSelectionState, computeTabNavigation, computeTotalHeight, computeVisibleColumnRange, computeVisibleRange, createBuiltInFunctions, createGridDataAccessor, createSortFilterWorker, currencyParser, dateParser, debounce, deriveFilterOptionsFromData, deriveFormulaBarText, emailParser, escapeCsvValue, exportToCsv, extractFormulaReferences, extractValueMatrix, findCtrlArrowTarget, flattenArgs, flattenColumns, formatAddress, formatCellReference, formatCellValueForTsv, formatSelectionAsTsv, formatShortcut, toString as formulaToString, fromCellKey, getCellRenderDescriptor, getCellValue, getColumnHeaderMenuItems, getContextMenuHandlers, getDataGridStatusBarConfig, getFilterField, getHeaderFilterConfig, getMultiSelectFilterFields, getPaginationViewModel, getPinStateForColumn, getScrollTopForRow, getStatusBarParts, handleFormulaBarKeyDown, indexToColumnLetter, injectGlobalStyles, isColumnEditable, isFilterConfig, isFormulaError, isInSelectionRange, isRowInRange, measureColumnContentWidth, measureRange, mergeFilter, normalizeSelectionRange, numberParser, parse, parseCellRef, parseRange, parseTsvClipboard, parseValue, partitionColumnsForVirtualization, processClientSideData, processClientSideDataAsync, processFormulaBarCommit, rangesEqual, reorderColumnArray, resolveCellDisplayContent, resolveCellStyle, terminateSortFilterWorker, toBoolean, toCellKey, toNumber, toUserLike, tokenize, triggerCsvDownload, validateColumns, validateRowIds, validateVirtualScrollConfig };
12835
+ export { AUTOSIZE_EXTRA_PX, AUTOSIZE_MAX_PX, CELL_PADDING, CHECKBOX_COLUMN_WIDTH, CIRC_ERROR, COLUMN_HEADER_MENU_ITEMS, CellDescriptorCache, ClipboardState, ColumnChooser, ColumnPinningState, ColumnReorderState, ColumnResizeState, ContextMenu, DEFAULT_DEBOUNCE_MS, DEFAULT_MIN_COLUMN_WIDTH, DIV_ZERO_ERROR, DependencyGraph, EventEmitter, FORMULA_BAR_CSS, FORMULA_BAR_STYLES, FORMULA_REF_COLORS, FillHandleState, FormulaBar, FormulaEngine, FormulaEngineState, FormulaError, FormulaEvaluator, GENERAL_ERROR, GRID_BORDER_RADIUS, GRID_CONTEXT_MENU_ITEMS, GridState, HeaderFilter, HeaderFilterState, InlineCellEditor, KeyboardNavState, MAX_PAGE_BUTTONS, MarchingAntsOverlay, NAME_ERROR, NA_ERROR, OGrid, OGridEventWiring, OGridRendering, PAGE_SIZE_OPTIONS, PEOPLE_SEARCH_DEBOUNCE_MS, PaginationControls, REF_ERROR, ROW_NUMBER_COLUMN_ID, ROW_NUMBER_COLUMN_MIN_WIDTH, ROW_NUMBER_COLUMN_WIDTH, RowSelectionState, SIDEBAR_TRANSITION_MS, SelectionState, SideBar, SideBarState, StatusBar, TableLayoutState, TableRenderer, UndoRedoStack, UndoRedoState, VALUE_ERROR, VirtualScrollState, Z_INDEX, adjustFormulaReferences, applyCellDeletion, applyCutClear, applyFillValues, applyPastedValues, applyRangeRowSelection, areGridRowPropsEqual, booleanParser, buildCellIndex, buildCsvHeader, buildCsvRows, buildHeaderRows, buildInlineEditorProps, buildPopoverEditorProps, calculateDropTarget, clampSelectionToBounds, columnLetterToIndex, computeAggregations, computeArrowNavigation, computeAutoScrollSpeed, computeNextSortState, computeRowSelectionState, computeTabNavigation, computeTotalHeight, computeVisibleColumnRange, computeVisibleRange, createBuiltInFunctions, createGridDataAccessor, createSortFilterWorker, currencyParser, dateParser, debounce, deriveFilterOptionsFromData, deriveFormulaBarText, emailParser, escapeCsvValue, exportToCsv, extractFormulaReferences, extractValueMatrix, findCtrlArrowTarget, flattenArgs, flattenColumns, formatAddress, formatCellReference, formatCellValueForTsv, formatSelectionAsTsv, formatShortcut, toString as formulaToString, fromCellKey, getCellRenderDescriptor, getCellValue, getColumnHeaderMenuItems, getContextMenuHandlers, getDataGridStatusBarConfig, getFilterField, getHeaderFilterConfig, getMultiSelectFilterFields, getPaginationViewModel, getPinStateForColumn, getScrollTopForRow, getStatusBarParts, handleFormulaBarKeyDown, indexToColumnLetter, injectGlobalStyles, isColumnEditable, isFilterConfig, isFormulaError, isInSelectionRange, isRowInRange, measureColumnContentWidth, measureRange, mergeFilter, normalizeSelectionRange, numberParser, parse, parseCellRef, parseRange, parseTsvClipboard, parseValue, partitionColumnsForVirtualization, processClientSideData, processClientSideDataAsync, processFormulaBarCommit, rangesEqual, reorderColumnArray, resolveCellDisplayContent, resolveCellStyle, terminateSortFilterWorker, toBoolean, toCellKey, toNumber, toUserLike, tokenize, triggerCsvDownload, validateColumns, validateRowIds, validateVirtualScrollConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alaarab/ogrid-js",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "OGrid vanilla JS – framework-free data grid with sorting, filtering, pagination, and spreadsheet-style editing.",
5
5
  "main": "dist/esm/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -36,7 +36,7 @@
36
36
  "node": ">=18"
37
37
  },
38
38
  "dependencies": {
39
- "@alaarab/ogrid-core": "2.4.0"
39
+ "@alaarab/ogrid-core": "2.4.1"
40
40
  },
41
41
  "sideEffects": [
42
42
  "**/*.css"