@alaarab/ogrid-core 2.0.11 → 2.0.13

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.
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Column autosize DOM measurement utilities shared across all frameworks.
3
+ */
4
+ import { DEFAULT_MIN_COLUMN_WIDTH } from '../constants/layout';
5
+ /** Extra pixels added to header label width to account for sort/filter icons + padding. */
6
+ export const AUTOSIZE_EXTRA_PX = 44;
7
+ /** Maximum column width from autosize. */
8
+ export const AUTOSIZE_MAX_PX = 520;
9
+ /**
10
+ * Measure the ideal width for a column by scanning all DOM cells with
11
+ * `[data-column-id="<columnId>"]` and computing the maximum scrollWidth.
12
+ *
13
+ * Header cells with a `[data-header-label]` child get extra padding for icons.
14
+ *
15
+ * @param columnId - Column to measure
16
+ * @param minWidth - Minimum width (defaults to DEFAULT_MIN_COLUMN_WIDTH)
17
+ * @param container - Optional container element to scope the query (defaults to `document`)
18
+ * @returns The ideal column width in pixels, clamped between minWidth and AUTOSIZE_MAX_PX
19
+ */
20
+ export function measureColumnContentWidth(columnId, minWidth, container) {
21
+ const minW = minWidth ?? DEFAULT_MIN_COLUMN_WIDTH;
22
+ const root = container ?? document;
23
+ const cells = root.querySelectorAll(`[data-column-id="${columnId}"]`);
24
+ if (cells.length === 0)
25
+ return minW;
26
+ let maxWidth = minW;
27
+ cells.forEach((cell) => {
28
+ const el = cell;
29
+ const label = el.querySelector?.('[data-header-label]');
30
+ if (label) {
31
+ maxWidth = Math.max(maxWidth, label.scrollWidth + AUTOSIZE_EXTRA_PX);
32
+ }
33
+ else {
34
+ maxWidth = Math.max(maxWidth, el.scrollWidth);
35
+ }
36
+ });
37
+ return Math.min(AUTOSIZE_MAX_PX, Math.max(minW, Math.ceil(maxWidth)));
38
+ }
@@ -76,7 +76,8 @@ export function getCellRenderDescriptor(item, col, rowIndex, colIdx, input) {
76
76
  const canEditAny = canEditInline || canEditPopup;
77
77
  const isEditing = input.editingCell?.rowId === rowId &&
78
78
  input.editingCell?.columnId === col.columnId;
79
- const isActive = input.activeCell?.rowIndex === rowIndex &&
79
+ const isActive = !input.isDragging &&
80
+ input.activeCell?.rowIndex === rowIndex &&
80
81
  input.activeCell?.columnIndex === globalColIndex;
81
82
  const isInRange = input.selectionRange != null &&
82
83
  isInSelectionRange(input.selectionRange, rowIndex, colIdx);
@@ -15,3 +15,5 @@ export { computeVisibleRange, computeTotalHeight, getScrollTopForRow, } from './
15
15
  export { getHeaderFilterConfig, getCellRenderDescriptor, resolveCellDisplayContent, resolveCellStyle, buildInlineEditorProps, buildPopoverEditorProps, } from './dataGridViewModel';
16
16
  export { debounce } from './debounce';
17
17
  export { measureRange, injectGlobalStyles } from './dom';
18
+ export { computeNextSortState } from './sortHelpers';
19
+ export { measureColumnContentWidth, AUTOSIZE_EXTRA_PX, AUTOSIZE_MAX_PX } from './columnAutosize';
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Sort state computation helpers shared across all frameworks.
3
+ */
4
+ /**
5
+ * Compute the next sort state given the current state and a sort request.
6
+ *
7
+ * @param current - Current sort state
8
+ * @param columnKey - Column being sorted
9
+ * @param direction - Explicit direction, `null` to clear, or `undefined` to toggle
10
+ * @returns New sort state
11
+ */
12
+ export function computeNextSortState(current, columnKey, direction) {
13
+ if (direction === null) {
14
+ // Clear sort
15
+ return { field: '', direction: 'asc' };
16
+ }
17
+ else if (direction) {
18
+ // Explicit direction (from column menu)
19
+ return { field: columnKey, direction };
20
+ }
21
+ else {
22
+ // Toggle (existing behavior for header click)
23
+ return {
24
+ field: columnKey,
25
+ direction: current.field === columnKey && current.direction === 'asc' ? 'desc' : 'asc',
26
+ };
27
+ }
28
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Column autosize DOM measurement utilities shared across all frameworks.
3
+ */
4
+ /** Extra pixels added to header label width to account for sort/filter icons + padding. */
5
+ export declare const AUTOSIZE_EXTRA_PX = 44;
6
+ /** Maximum column width from autosize. */
7
+ export declare const AUTOSIZE_MAX_PX = 520;
8
+ /**
9
+ * Measure the ideal width for a column by scanning all DOM cells with
10
+ * `[data-column-id="<columnId>"]` and computing the maximum scrollWidth.
11
+ *
12
+ * Header cells with a `[data-header-label]` child get extra padding for icons.
13
+ *
14
+ * @param columnId - Column to measure
15
+ * @param minWidth - Minimum width (defaults to DEFAULT_MIN_COLUMN_WIDTH)
16
+ * @param container - Optional container element to scope the query (defaults to `document`)
17
+ * @returns The ideal column width in pixels, clamped between minWidth and AUTOSIZE_MAX_PX
18
+ */
19
+ export declare function measureColumnContentWidth(columnId: string, minWidth?: number, container?: {
20
+ querySelectorAll: (selector: string) => NodeListOf<Element>;
21
+ }): number;
@@ -9,7 +9,7 @@ import type { RowId, UserLike, IFilters, FilterValue } from '../types/dataGridTy
9
9
  export interface HeaderFilterConfigInput {
10
10
  sortBy?: string;
11
11
  sortDirection: 'asc' | 'desc';
12
- onColumnSort: (columnKey: string) => void;
12
+ onColumnSort: (columnKey: string, direction?: 'asc' | 'desc' | null) => void;
13
13
  filters: IFilters;
14
14
  onFilterChange: (key: string, value: FilterValue | undefined) => void;
15
15
  filterOptions: Record<string, string[]>;
@@ -26,3 +26,6 @@ export type { HeaderFilterConfigInput, HeaderFilterConfig, CellRenderDescriptorI
26
26
  export { debounce } from './debounce';
27
27
  export { measureRange, injectGlobalStyles } from './dom';
28
28
  export type { OverlayRect } from './dom';
29
+ export { computeNextSortState } from './sortHelpers';
30
+ export type { ISortState } from './sortHelpers';
31
+ export { measureColumnContentWidth, AUTOSIZE_EXTRA_PX, AUTOSIZE_MAX_PX } from './columnAutosize';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Sort state computation helpers shared across all frameworks.
3
+ */
4
+ export interface ISortState {
5
+ field: string;
6
+ direction: 'asc' | 'desc';
7
+ }
8
+ /**
9
+ * Compute the next sort state given the current state and a sort request.
10
+ *
11
+ * @param current - Current sort state
12
+ * @param columnKey - Column being sorted
13
+ * @param direction - Explicit direction, `null` to clear, or `undefined` to toggle
14
+ * @returns New sort state
15
+ */
16
+ export declare function computeNextSortState(current: ISortState, columnKey: string, direction?: 'asc' | 'desc' | null): ISortState;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alaarab/ogrid-core",
3
- "version": "2.0.11",
3
+ "version": "2.0.13",
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",