@alaarab/ogrid-js 2.0.22 → 2.1.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.
Files changed (35) hide show
  1. package/dist/esm/OGrid.js +189 -503
  2. package/dist/esm/OGridEventWiring.js +178 -0
  3. package/dist/esm/OGridRendering.js +269 -0
  4. package/dist/esm/components/ColumnChooser.js +26 -3
  5. package/dist/esm/components/InlineCellEditor.js +18 -36
  6. package/dist/esm/index.js +2 -0
  7. package/dist/esm/renderer/TableRenderer.js +102 -61
  8. package/dist/esm/state/ClipboardState.js +8 -54
  9. package/dist/esm/state/ColumnPinningState.js +1 -2
  10. package/dist/esm/state/ColumnReorderState.js +8 -1
  11. package/dist/esm/state/EventEmitter.js +3 -2
  12. package/dist/esm/state/FillHandleState.js +27 -41
  13. package/dist/esm/state/GridState.js +36 -10
  14. package/dist/esm/state/HeaderFilterState.js +19 -11
  15. package/dist/esm/state/KeyboardNavState.js +19 -132
  16. package/dist/esm/state/RowSelectionState.js +6 -15
  17. package/dist/esm/state/SideBarState.js +1 -1
  18. package/dist/esm/state/TableLayoutState.js +6 -4
  19. package/dist/esm/utils/getCellCoordinates.js +15 -0
  20. package/dist/esm/utils/index.js +1 -0
  21. package/dist/types/OGrid.d.ts +97 -9
  22. package/dist/types/OGridEventWiring.d.ts +60 -0
  23. package/dist/types/OGridRendering.d.ts +93 -0
  24. package/dist/types/components/ColumnChooser.d.ts +5 -0
  25. package/dist/types/components/InlineCellEditor.d.ts +5 -0
  26. package/dist/types/index.d.ts +6 -1
  27. package/dist/types/renderer/TableRenderer.d.ts +12 -5
  28. package/dist/types/state/EventEmitter.d.ts +1 -1
  29. package/dist/types/state/FillHandleState.d.ts +1 -1
  30. package/dist/types/state/GridState.d.ts +7 -1
  31. package/dist/types/state/HeaderFilterState.d.ts +2 -0
  32. package/dist/types/types/gridTypes.d.ts +15 -0
  33. package/dist/types/utils/getCellCoordinates.d.ts +8 -0
  34. package/dist/types/utils/index.d.ts +1 -0
  35. package/package.json +11 -4
@@ -1,8 +1,12 @@
1
1
  export * from '@alaarab/ogrid-core';
2
2
  export type { IColumnDef, IColumnGroupDef, ICellEditorContext } from './types/columnTypes';
3
- export type { OGridOptions, OGridEvents, IJsOGridApi } from './types/gridTypes';
3
+ export type { OGridOptions, OGridEvents, IJsOGridApi, CellEvent } from './types/gridTypes';
4
4
  export { debounce } from './utils';
5
5
  export { OGrid } from './OGrid';
6
+ export { OGridEventWiring } from './OGridEventWiring';
7
+ export type { InteractionResult, EventWiringCallbacks } from './OGridEventWiring';
8
+ export { OGridRendering } from './OGridRendering';
9
+ export type { OGridRenderingContext } from './OGridRendering';
6
10
  export { GridState } from './state/GridState';
7
11
  export { EventEmitter } from './state/EventEmitter';
8
12
  export { SelectionState } from './state/SelectionState';
@@ -12,6 +16,7 @@ export { UndoRedoState } from './state/UndoRedoState';
12
16
  export { ColumnResizeState } from './state/ColumnResizeState';
13
17
  export { TableLayoutState } from './state/TableLayoutState';
14
18
  export { TableRenderer } from './renderer/TableRenderer';
19
+ export type { TableRendererInteractionState } from './renderer/TableRenderer';
15
20
  export { PaginationControls } from './components/PaginationControls';
16
21
  export { StatusBar } from './components/StatusBar';
17
22
  export { ColumnChooser } from './components/ColumnChooser';
@@ -1,4 +1,4 @@
1
- import type { RowId } from '../types/gridTypes';
1
+ import type { RowId, CellEvent } from '../types/gridTypes';
2
2
  import type { IActiveCell, ISelectionRange } from '@alaarab/ogrid-core';
3
3
  import type { GridState } from '../state/GridState';
4
4
  import type { HeaderFilterState, HeaderFilterConfig } from '../state/HeaderFilterState';
@@ -13,10 +13,10 @@ export interface TableRendererInteractionState {
13
13
  columnId: string;
14
14
  } | null;
15
15
  columnWidths: Record<string, number>;
16
- onCellClick?: (rowIndex: number, colIndex: number, e: MouseEvent) => void;
17
- onCellMouseDown?: (rowIndex: number, colIndex: number, e: MouseEvent) => void;
18
- onCellDoubleClick?: (rowIndex: number, colIndex: number, rowId: RowId, columnId: string) => void;
19
- onCellContextMenu?: (rowIndex: number, colIndex: number, e: MouseEvent) => void;
16
+ onCellClick?: (cellEvent: CellEvent) => void;
17
+ onCellMouseDown?: (cellEvent: CellEvent) => void;
18
+ onCellDoubleClick?: (cellEvent: CellEvent) => void;
19
+ onCellContextMenu?: (cellEvent: CellEvent) => void;
20
20
  onResizeStart?: (columnId: string, clientX: number, currentWidth: number) => void;
21
21
  onFillHandleMouseDown?: (e: MouseEvent) => void;
22
22
  rowSelectionMode?: 'single' | 'multiple' | 'none';
@@ -48,6 +48,8 @@ export declare class TableRenderer<T> {
48
48
  private _tbodyMousedownHandler;
49
49
  private _tbodyDblclickHandler;
50
50
  private _tbodyContextmenuHandler;
51
+ private _theadClickHandler;
52
+ private _theadMousedownHandler;
51
53
  private lastActiveCell;
52
54
  private lastSelectionRange;
53
55
  private lastCopyRange;
@@ -70,6 +72,9 @@ export declare class TableRenderer<T> {
70
72
  private getCellFromEvent;
71
73
  private attachBodyDelegation;
72
74
  private detachBodyDelegation;
75
+ /** Attach delegated event listeners to <thead> for sort clicks, resize, reorder, and filter icon clicks. */
76
+ private attachHeaderDelegation;
77
+ private detachHeaderDelegation;
73
78
  getWrapperElement(): HTMLDivElement | null;
74
79
  /** Full render — creates the table structure from scratch. */
75
80
  render(): void;
@@ -93,6 +98,8 @@ export declare class TableRenderer<T> {
93
98
  private renderBody;
94
99
  /** Get the table element (used by ColumnReorderState for header cell queries). */
95
100
  getTableElement(): HTMLTableElement | null;
101
+ /** Get the current onResizeStart handler from interaction state (avoids bracket notation access). */
102
+ getOnResizeStart(): ((columnId: string, clientX: number, currentWidth: number) => void) | undefined;
96
103
  /** Update the drop indicator position during column reorder. */
97
104
  updateDropIndicator(x: number | null, isDragging: boolean): void;
98
105
  destroy(): void;
@@ -3,7 +3,7 @@ export declare class EventEmitter<TEvents extends Record<string, unknown> = Reco
3
3
  private handlers;
4
4
  on<K extends keyof TEvents>(event: K, handler: EventHandler<TEvents[K]>): void;
5
5
  off<K extends keyof TEvents>(event: K, handler: EventHandler<TEvents[K]>): void;
6
- emit<K extends keyof TEvents>(event: K, data: TEvents[K]): void;
6
+ emit<K extends keyof TEvents>(event: K, ...args: TEvents[K] extends undefined ? [] : [TEvents[K]]): void;
7
7
  removeAllListeners(event?: keyof TEvents): void;
8
8
  }
9
9
  export {};
@@ -42,7 +42,7 @@ export declare class FillHandleState<T> {
42
42
  startFillDrag(e: MouseEvent): void;
43
43
  private onMouseMove;
44
44
  private onMouseUp;
45
- private applyFillValues;
45
+ private applyFillValuesFromCore;
46
46
  private resolveRange;
47
47
  private applyDragAttrs;
48
48
  private clearDragAttrs;
@@ -24,8 +24,12 @@ export declare class GridState<T> {
24
24
  private _onError?;
25
25
  private _onFirstDataRendered?;
26
26
  private _firstDataRendered;
27
+ private _rowHeight?;
28
+ private _ariaLabel?;
27
29
  private _filterOptions;
28
30
  private _columnOrder;
31
+ private _visibleColsCache;
32
+ private _visibleColsDirty;
29
33
  constructor(options: OGridOptions<T>);
30
34
  get data(): T[];
31
35
  get page(): number;
@@ -43,7 +47,9 @@ export declare class GridState<T> {
43
47
  get isServerSide(): boolean;
44
48
  get filterOptions(): Record<string, string[]>;
45
49
  get columnOrder(): string[];
46
- /** Get the visible columns in display order (respects column reorder). */
50
+ get rowHeight(): number | undefined;
51
+ get ariaLabel(): string | undefined;
52
+ /** Get the visible columns in display order (respects column reorder). Memoized via dirty flag. */
47
53
  get visibleColumnDefs(): IColumnDef<T>[];
48
54
  /** Get processed (sorted, filtered, paginated) items for current page. */
49
55
  getProcessedItems(): {
@@ -38,6 +38,8 @@ export declare class HeaderFilterState {
38
38
  } | null;
39
39
  setFilters(filters: IFilters): void;
40
40
  setFilterOptions(options: Record<string, string[]>): void;
41
+ /** Allow OGrid to update the popover element reference after rendering (for click-outside detection). */
42
+ setPopoverEl(el: HTMLElement | null): void;
41
43
  getFilterOptions(filterField: string): string[];
42
44
  getFilteredOptions(filterField: string): string[];
43
45
  hasActiveFilter(config: HeaderFilterConfig): boolean;
@@ -1,6 +1,19 @@
1
1
  import type { IColumnDef, IColumnGroupDef, ICellValueChangedEvent } from './columnTypes';
2
2
  import type { RowId, IFilters, IDataSource, RowSelectionMode, IRowSelectionChangeEvent, IOGridApi, ISideBarDef, IStatusBarProps, IVirtualScrollConfig } from '@alaarab/ogrid-core';
3
3
  export type { RowId, UserLike, UserLikeInput, FilterValue, IFilters, IFetchParams, IPageResult, IDataSource, IGridColumnState, RowSelectionMode, IRowSelectionChangeEvent, StatusBarPanel, IStatusBarProps, IActiveCell, ISelectionRange, SideBarPanelId, ISideBarDef, IVirtualScrollConfig, IOGridApi, } from '@alaarab/ogrid-core';
4
+ /** Standardized cell event parameter for cell interaction callbacks. */
5
+ export interface CellEvent {
6
+ /** Zero-based row index within the current page. */
7
+ rowIndex: number;
8
+ /** Zero-based column index among visible columns. */
9
+ colIndex: number;
10
+ /** The original DOM mouse event, when available. */
11
+ event?: MouseEvent;
12
+ /** Typed row identifier (string or number). Present for double-click events. */
13
+ rowId?: RowId;
14
+ /** Column identifier string. Present for double-click events. */
15
+ columnId?: string;
16
+ }
4
17
  /** Extended API for the vanilla JS package (adds methods not in the core IOGridApi). */
5
18
  export interface IJsOGridApi<T> extends IOGridApi<T> {
6
19
  /** Export displayed rows to CSV and trigger a download. */
@@ -93,6 +106,8 @@ export interface OGridOptions<T> {
93
106
  pageSizeOptions?: number[];
94
107
  /** Initial column display order (array of column ids). */
95
108
  columnOrder?: string[];
109
+ /** Accessible label for the grid wrapper element. */
110
+ ariaLabel?: string;
96
111
  /** Callback fired when column order changes. */
97
112
  onColumnOrderChange?: (order: string[]) => void;
98
113
  /** Callback fired when a column is resized. */
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Extracts row and column indices from a cell element's data attributes.
3
+ * Returns null if the element lacks the attributes or they are not valid numbers.
4
+ */
5
+ export declare function getCellCoordinates(cell: Element): {
6
+ rowIndex: number;
7
+ colIndex: number;
8
+ } | null;
@@ -1 +1,2 @@
1
1
  export { debounce } from './debounce';
2
+ export { getCellCoordinates } from './getCellCoordinates';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alaarab/ogrid-js",
3
- "version": "2.0.22",
3
+ "version": "2.1.0",
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,10 +36,17 @@
36
36
  "node": ">=18"
37
37
  },
38
38
  "dependencies": {
39
- "@alaarab/ogrid-core": "2.0.22"
39
+ "@alaarab/ogrid-core": "2.1.0"
40
40
  },
41
- "sideEffects": false,
41
+ "sideEffects": ["**/*.css"],
42
42
  "publishConfig": {
43
43
  "access": "public"
44
- }
44
+ },
45
+ "repository": {
46
+ "type": "git",
47
+ "url": "https://github.com/alaarab/ogrid.git",
48
+ "directory": "packages/js"
49
+ },
50
+ "homepage": "https://ogrid.dev",
51
+ "bugs": "https://github.com/alaarab/ogrid/issues"
45
52
  }