@alaarab/ogrid-core 2.0.9 → 2.0.11

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,53 @@
1
+ /**
2
+ * DOM utility functions for OGrid components.
3
+ * These utilities are framework-agnostic and can be used across React, Angular, Vue, and vanilla JS implementations.
4
+ */
5
+ /**
6
+ * Measure the bounding rect of a cell range within a container.
7
+ *
8
+ * @param container - The grid container element with position: relative
9
+ * @param range - The selection range to measure
10
+ * @param colOffset - Column offset (1 when checkbox column is present, else 0)
11
+ * @returns Rectangle describing the range position and size, or null if cells not found
12
+ */
13
+ export function measureRange(container, range, colOffset) {
14
+ const startGlobalCol = range.startCol + colOffset;
15
+ const endGlobalCol = range.endCol + colOffset;
16
+ const topLeft = container.querySelector(`[data-row-index="${range.startRow}"][data-col-index="${startGlobalCol}"]`);
17
+ const bottomRight = container.querySelector(`[data-row-index="${range.endRow}"][data-col-index="${endGlobalCol}"]`);
18
+ if (!topLeft || !bottomRight)
19
+ return null;
20
+ const cRect = container.getBoundingClientRect();
21
+ const tlRect = topLeft.getBoundingClientRect();
22
+ const brRect = bottomRight.getBoundingClientRect();
23
+ return {
24
+ top: tlRect.top - cRect.top,
25
+ left: tlRect.left - cRect.left,
26
+ width: brRect.right - tlRect.left,
27
+ height: brRect.bottom - tlRect.top,
28
+ };
29
+ }
30
+ /**
31
+ * Inject a global CSS rule into the document head (once per page, deduplicated by ID).
32
+ *
33
+ * @param id - Unique ID for the style element (prevents duplicates)
34
+ * @param css - CSS content to inject
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * injectGlobalStyles(
39
+ * 'ogrid-marching-ants-keyframes',
40
+ * '@keyframes ogrid-marching-ants{to{stroke-dashoffset:-8}}'
41
+ * );
42
+ * ```
43
+ */
44
+ export function injectGlobalStyles(id, css) {
45
+ if (typeof document === 'undefined')
46
+ return;
47
+ if (document.getElementById(id))
48
+ return;
49
+ const style = document.createElement('style');
50
+ style.id = id;
51
+ style.textContent = css;
52
+ document.head.appendChild(style);
53
+ }
@@ -50,3 +50,31 @@ export const COLUMN_HEADER_MENU_ITEMS = [
50
50
  { id: 'pinRight', label: 'Pin right' },
51
51
  { id: 'unpin', label: 'Unpin' },
52
52
  ];
53
+ /**
54
+ * Builds the complete column header menu items based on current state.
55
+ * Returns pinning, sorting, and sizing options.
56
+ */
57
+ export function getColumnHeaderMenuItems(input) {
58
+ const { canPinLeft, canPinRight, canUnpin, currentSort, isSortable = true, isResizable = true } = input;
59
+ const items = [];
60
+ // Pinning section
61
+ items.push({ id: 'pinLeft', label: 'Pin left', disabled: !canPinLeft }, { id: 'pinRight', label: 'Pin right', disabled: !canPinRight }, { id: 'unpin', label: 'Unpin', disabled: !canUnpin, divider: isSortable || isResizable });
62
+ // Sorting section
63
+ if (isSortable) {
64
+ if (!currentSort) {
65
+ // No sort applied - show both options
66
+ items.push({ id: 'sortAsc', label: 'Sort ascending' }, { id: 'sortDesc', label: 'Sort descending', divider: isResizable });
67
+ }
68
+ else {
69
+ // Sort applied - show opposite + clear
70
+ const oppositeSort = currentSort === 'asc' ? 'desc' : 'asc';
71
+ const oppositeLabel = currentSort === 'asc' ? 'Sort descending' : 'Sort ascending';
72
+ items.push({ id: `sort${oppositeSort === 'asc' ? 'Asc' : 'Desc'}`, label: oppositeLabel }, { id: 'clearSort', label: 'Clear sort', divider: isResizable });
73
+ }
74
+ }
75
+ // Autosize section
76
+ if (isResizable) {
77
+ items.push({ id: 'autosizeThis', label: 'Autosize this column' }, { id: 'autosizeAll', label: 'Autosize all columns' });
78
+ }
79
+ return items;
80
+ }
@@ -5,7 +5,7 @@ export { getFilterField, mergeFilter, deriveFilterOptionsFromData, getMultiSelec
5
5
  export { getStatusBarParts } from './statusBarHelpers';
6
6
  export { getDataGridStatusBarConfig } from './dataGridStatusBar';
7
7
  export { getPaginationViewModel, PAGE_SIZE_OPTIONS, MAX_PAGE_BUTTONS, } from './paginationHelpers';
8
- export { GRID_CONTEXT_MENU_ITEMS, COLUMN_HEADER_MENU_ITEMS, getContextMenuHandlers, formatShortcut } from './gridContextMenuHelpers';
8
+ export { GRID_CONTEXT_MENU_ITEMS, COLUMN_HEADER_MENU_ITEMS, getContextMenuHandlers, getColumnHeaderMenuItems, formatShortcut } from './gridContextMenuHelpers';
9
9
  export { parseValue, numberParser, currencyParser, dateParser, emailParser, booleanParser, } from './valueParsers';
10
10
  export { computeAggregations } from './aggregationUtils';
11
11
  export { processClientSideData } from './clientSideData';
@@ -14,3 +14,4 @@ export { getPinStateForColumn, reorderColumnArray, calculateDropTarget, } from '
14
14
  export { computeVisibleRange, computeTotalHeight, getScrollTopForRow, } from './virtualScroll';
15
15
  export { getHeaderFilterConfig, getCellRenderDescriptor, resolveCellDisplayContent, resolveCellStyle, buildInlineEditorProps, buildPopoverEditorProps, } from './dataGridViewModel';
16
16
  export { debounce } from './debounce';
17
+ export { measureRange, injectGlobalStyles } from './dom';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * DOM utility functions for OGrid components.
3
+ * These utilities are framework-agnostic and can be used across React, Angular, Vue, and vanilla JS implementations.
4
+ */
5
+ import type { ISelectionRange } from '../types';
6
+ /**
7
+ * Rectangle describing position and dimensions of a DOM element.
8
+ */
9
+ export interface OverlayRect {
10
+ top: number;
11
+ left: number;
12
+ width: number;
13
+ height: number;
14
+ }
15
+ /**
16
+ * Measure the bounding rect of a cell range within a container.
17
+ *
18
+ * @param container - The grid container element with position: relative
19
+ * @param range - The selection range to measure
20
+ * @param colOffset - Column offset (1 when checkbox column is present, else 0)
21
+ * @returns Rectangle describing the range position and size, or null if cells not found
22
+ */
23
+ export declare function measureRange(container: HTMLElement, range: ISelectionRange, colOffset: number): OverlayRect | null;
24
+ /**
25
+ * Inject a global CSS rule into the document head (once per page, deduplicated by ID).
26
+ *
27
+ * @param id - Unique ID for the style element (prevents duplicates)
28
+ * @param css - CSS content to inject
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * injectGlobalStyles(
33
+ * 'ogrid-marching-ants-keyframes',
34
+ * '@keyframes ogrid-marching-ants{to{stroke-dashoffset:-8}}'
35
+ * );
36
+ * ```
37
+ */
38
+ export declare function injectGlobalStyles(id: string, css: string): void;
@@ -34,6 +34,34 @@ export interface IColumnHeaderMenuItem {
34
34
  id: string;
35
35
  label: string;
36
36
  icon?: string;
37
+ disabled?: boolean;
38
+ divider?: boolean;
37
39
  }
38
40
  /** Column header menu items for pin/unpin actions. */
39
41
  export declare const COLUMN_HEADER_MENU_ITEMS: IColumnHeaderMenuItem[];
42
+ /** Input for building column header menu items. */
43
+ export interface ColumnHeaderMenuInput {
44
+ canPinLeft: boolean;
45
+ canPinRight: boolean;
46
+ canUnpin: boolean;
47
+ currentSort?: 'asc' | 'desc' | null;
48
+ isSortable?: boolean;
49
+ isResizable?: boolean;
50
+ }
51
+ /**
52
+ * Builds the complete column header menu items based on current state.
53
+ * Returns pinning, sorting, and sizing options.
54
+ */
55
+ export declare function getColumnHeaderMenuItems(input: ColumnHeaderMenuInput): IColumnHeaderMenuItem[];
56
+ /** Handlers for column header menu actions. */
57
+ export interface ColumnHeaderMenuHandlers {
58
+ onPinLeft: () => void;
59
+ onPinRight: () => void;
60
+ onUnpin: () => void;
61
+ onSortAsc: () => void;
62
+ onSortDesc: () => void;
63
+ onClearSort: () => void;
64
+ onAutosizeThis: () => void;
65
+ onAutosizeAll: () => void;
66
+ onClose: () => void;
67
+ }
@@ -6,10 +6,10 @@ export { getStatusBarParts } from './statusBarHelpers';
6
6
  export { getDataGridStatusBarConfig } from './dataGridStatusBar';
7
7
  export { getPaginationViewModel, PAGE_SIZE_OPTIONS, MAX_PAGE_BUTTONS, } from './paginationHelpers';
8
8
  export type { PaginationViewModel } from './paginationHelpers';
9
- export { GRID_CONTEXT_MENU_ITEMS, COLUMN_HEADER_MENU_ITEMS, getContextMenuHandlers, formatShortcut } from './gridContextMenuHelpers';
9
+ export { GRID_CONTEXT_MENU_ITEMS, COLUMN_HEADER_MENU_ITEMS, getContextMenuHandlers, getColumnHeaderMenuItems, formatShortcut } from './gridContextMenuHelpers';
10
10
  export type { CsvColumn } from './exportToCsv';
11
11
  export type { StatusBarPart, StatusBarPartsInput } from './statusBarHelpers';
12
- export type { GridContextMenuItem, IColumnHeaderMenuItem, GridContextMenuHandlerProps } from './gridContextMenuHelpers';
12
+ export type { GridContextMenuItem, IColumnHeaderMenuItem, GridContextMenuHandlerProps, ColumnHeaderMenuInput, ColumnHeaderMenuHandlers } from './gridContextMenuHelpers';
13
13
  export { parseValue, numberParser, currencyParser, dateParser, emailParser, booleanParser, } from './valueParsers';
14
14
  export type { ParseValueResult } from './valueParsers';
15
15
  export { computeAggregations } from './aggregationUtils';
@@ -24,3 +24,5 @@ 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';
28
+ export type { OverlayRect } from './dom';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alaarab/ogrid-core",
3
- "version": "2.0.9",
3
+ "version": "2.0.11",
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",