@alaarab/ogrid-js 2.0.0-beta
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/OGrid.js +654 -0
- package/dist/esm/components/ColumnChooser.js +68 -0
- package/dist/esm/components/ContextMenu.js +122 -0
- package/dist/esm/components/HeaderFilter.js +281 -0
- package/dist/esm/components/InlineCellEditor.js +278 -0
- package/dist/esm/components/MarchingAntsOverlay.js +170 -0
- package/dist/esm/components/PaginationControls.js +85 -0
- package/dist/esm/components/SideBar.js +353 -0
- package/dist/esm/components/StatusBar.js +34 -0
- package/dist/esm/index.js +26 -0
- package/dist/esm/renderer/TableRenderer.js +414 -0
- package/dist/esm/state/ClipboardState.js +171 -0
- package/dist/esm/state/ColumnPinningState.js +78 -0
- package/dist/esm/state/ColumnResizeState.js +55 -0
- package/dist/esm/state/EventEmitter.js +27 -0
- package/dist/esm/state/FillHandleState.js +218 -0
- package/dist/esm/state/GridState.js +261 -0
- package/dist/esm/state/HeaderFilterState.js +205 -0
- package/dist/esm/state/KeyboardNavState.js +374 -0
- package/dist/esm/state/RowSelectionState.js +81 -0
- package/dist/esm/state/SelectionState.js +102 -0
- package/dist/esm/state/SideBarState.js +41 -0
- package/dist/esm/state/TableLayoutState.js +95 -0
- package/dist/esm/state/UndoRedoState.js +82 -0
- package/dist/esm/types/columnTypes.js +1 -0
- package/dist/esm/types/gridTypes.js +1 -0
- package/dist/esm/types/index.js +2 -0
- package/dist/types/OGrid.d.ts +60 -0
- package/dist/types/components/ColumnChooser.d.ts +14 -0
- package/dist/types/components/ContextMenu.d.ts +17 -0
- package/dist/types/components/HeaderFilter.d.ts +24 -0
- package/dist/types/components/InlineCellEditor.d.ts +24 -0
- package/dist/types/components/MarchingAntsOverlay.d.ts +25 -0
- package/dist/types/components/PaginationControls.d.ts +9 -0
- package/dist/types/components/SideBar.d.ts +35 -0
- package/dist/types/components/StatusBar.d.ts +8 -0
- package/dist/types/index.d.ts +26 -0
- package/dist/types/renderer/TableRenderer.d.ts +59 -0
- package/dist/types/state/ClipboardState.d.ts +35 -0
- package/dist/types/state/ColumnPinningState.d.ts +36 -0
- package/dist/types/state/ColumnResizeState.d.ts +23 -0
- package/dist/types/state/EventEmitter.d.ts +9 -0
- package/dist/types/state/FillHandleState.d.ts +51 -0
- package/dist/types/state/GridState.d.ts +68 -0
- package/dist/types/state/HeaderFilterState.d.ts +64 -0
- package/dist/types/state/KeyboardNavState.d.ts +29 -0
- package/dist/types/state/RowSelectionState.d.ts +23 -0
- package/dist/types/state/SelectionState.d.ts +37 -0
- package/dist/types/state/SideBarState.d.ts +19 -0
- package/dist/types/state/TableLayoutState.d.ts +33 -0
- package/dist/types/state/UndoRedoState.d.ts +28 -0
- package/dist/types/types/columnTypes.d.ts +28 -0
- package/dist/types/types/gridTypes.d.ts +69 -0
- package/dist/types/types/index.d.ts +2 -0
- package/package.json +29 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { IActiveCell, ISelectionRange, IColumnDef, ICellValueChangedEvent } from '@alaarab/ogrid-core';
|
|
2
|
+
interface ClipboardStateEvents extends Record<string, unknown> {
|
|
3
|
+
rangesChange: {
|
|
4
|
+
copyRange: ISelectionRange | null;
|
|
5
|
+
cutRange: ISelectionRange | null;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export interface ClipboardParams<T> {
|
|
9
|
+
items: T[];
|
|
10
|
+
visibleCols: IColumnDef<T>[];
|
|
11
|
+
colOffset: number;
|
|
12
|
+
editable?: boolean;
|
|
13
|
+
onCellValueChanged?: (event: ICellValueChangedEvent<T>) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare class ClipboardState<T> {
|
|
16
|
+
private emitter;
|
|
17
|
+
private params;
|
|
18
|
+
private getActiveCell;
|
|
19
|
+
private getSelectionRange;
|
|
20
|
+
private _cutRange;
|
|
21
|
+
private _copyRange;
|
|
22
|
+
private internalClipboard;
|
|
23
|
+
constructor(params: ClipboardParams<T>, getActiveCell: () => IActiveCell | null, getSelectionRange: () => ISelectionRange | null);
|
|
24
|
+
updateParams(params: ClipboardParams<T>): void;
|
|
25
|
+
get cutRange(): ISelectionRange | null;
|
|
26
|
+
get copyRange(): ISelectionRange | null;
|
|
27
|
+
private getEffectiveRange;
|
|
28
|
+
handleCopy(): void;
|
|
29
|
+
handleCut(): void;
|
|
30
|
+
handlePaste(): Promise<void>;
|
|
31
|
+
clearClipboardRanges(): void;
|
|
32
|
+
onRangesChange(handler: (data: ClipboardStateEvents['rangesChange']) => void): () => void;
|
|
33
|
+
destroy(): void;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { IColumnDef } from '@alaarab/ogrid-core';
|
|
2
|
+
interface ColumnPinningEvents extends Record<string, unknown> {
|
|
3
|
+
pinningChange: {
|
|
4
|
+
pinnedColumns: Record<string, 'left' | 'right'>;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Manages column pinning state — tracks which columns are pinned left/right.
|
|
9
|
+
* Computes sticky offsets for the renderer.
|
|
10
|
+
*/
|
|
11
|
+
export declare class ColumnPinningState {
|
|
12
|
+
private emitter;
|
|
13
|
+
private _pinnedColumns;
|
|
14
|
+
constructor(pinnedColumns?: Record<string, 'left' | 'right'>, columns?: IColumnDef[]);
|
|
15
|
+
get pinnedColumns(): Record<string, 'left' | 'right'>;
|
|
16
|
+
pinColumn(columnId: string, side: 'left' | 'right'): void;
|
|
17
|
+
unpinColumn(columnId: string): void;
|
|
18
|
+
isPinned(columnId: string): 'left' | 'right' | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Compute sticky left offsets for left-pinned columns.
|
|
21
|
+
* Returns a map of columnId -> left offset in pixels.
|
|
22
|
+
*/
|
|
23
|
+
computeLeftOffsets(visibleCols: {
|
|
24
|
+
columnId: string;
|
|
25
|
+
}[], columnWidths: Record<string, number>, defaultWidth: number, hasCheckboxColumn: boolean, checkboxColumnWidth: number): Record<string, number>;
|
|
26
|
+
/**
|
|
27
|
+
* Compute sticky right offsets for right-pinned columns.
|
|
28
|
+
* Returns a map of columnId -> right offset in pixels.
|
|
29
|
+
*/
|
|
30
|
+
computeRightOffsets(visibleCols: {
|
|
31
|
+
columnId: string;
|
|
32
|
+
}[], columnWidths: Record<string, number>, defaultWidth: number): Record<string, number>;
|
|
33
|
+
onPinningChange(handler: (data: ColumnPinningEvents['pinningChange']) => void): () => void;
|
|
34
|
+
destroy(): void;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
interface ColumnResizeStateEvents extends Record<string, unknown> {
|
|
2
|
+
columnWidthChange: {
|
|
3
|
+
columnId: string;
|
|
4
|
+
widthPx: number;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export declare class ColumnResizeState {
|
|
8
|
+
private emitter;
|
|
9
|
+
private columnWidths;
|
|
10
|
+
private isResizing;
|
|
11
|
+
private resizeColumnId;
|
|
12
|
+
private resizeStartX;
|
|
13
|
+
private resizeStartWidth;
|
|
14
|
+
get resizingColumnId(): string | null;
|
|
15
|
+
getColumnWidth(columnId: string): number | undefined;
|
|
16
|
+
getAllColumnWidths(): Record<string, number>;
|
|
17
|
+
startResize(columnId: string, clientX: number, currentWidth: number): void;
|
|
18
|
+
updateResize(clientX: number): number | null;
|
|
19
|
+
endResize(clientX: number): void;
|
|
20
|
+
onColumnWidthChange(handler: (data: ColumnResizeStateEvents['columnWidthChange']) => void): () => void;
|
|
21
|
+
destroy(): void;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type EventHandler<T = unknown> = (data: T) => void;
|
|
2
|
+
export declare class EventEmitter<TEvents extends Record<string, unknown> = Record<string, unknown>> {
|
|
3
|
+
private handlers;
|
|
4
|
+
on<K extends keyof TEvents>(event: K, handler: EventHandler<TEvents[K]>): void;
|
|
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;
|
|
7
|
+
removeAllListeners(event?: keyof TEvents): void;
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { IActiveCell, ISelectionRange, IColumnDef, ICellValueChangedEvent } from '@alaarab/ogrid-core';
|
|
2
|
+
interface FillHandleEvents extends Record<string, unknown> {
|
|
3
|
+
fillRangeChange: {
|
|
4
|
+
fillRange: ISelectionRange | null;
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export interface FillHandleParams<T> {
|
|
8
|
+
items: T[];
|
|
9
|
+
visibleCols: IColumnDef<T>[];
|
|
10
|
+
editable?: boolean;
|
|
11
|
+
onCellValueChanged?: (event: ICellValueChangedEvent<T>) => void;
|
|
12
|
+
colOffset: number;
|
|
13
|
+
beginBatch?: () => void;
|
|
14
|
+
endBatch?: () => void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Manages Excel-style fill handle drag-to-fill for cell ranges (vanilla JS).
|
|
18
|
+
* Mirrors the React `useFillHandle` hook as a class-based state.
|
|
19
|
+
*/
|
|
20
|
+
export declare class FillHandleState<T> {
|
|
21
|
+
private emitter;
|
|
22
|
+
private params;
|
|
23
|
+
private getSelectionRange;
|
|
24
|
+
private setSelectionRange;
|
|
25
|
+
private setActiveCell;
|
|
26
|
+
private wrapperRef;
|
|
27
|
+
private _isFillDragging;
|
|
28
|
+
private fillDragStart;
|
|
29
|
+
private fillDragEnd;
|
|
30
|
+
private rafHandle;
|
|
31
|
+
private liveFillRange;
|
|
32
|
+
private lastMousePos;
|
|
33
|
+
private onMoveBound;
|
|
34
|
+
private onUpBound;
|
|
35
|
+
constructor(params: FillHandleParams<T>, getSelectionRange: () => ISelectionRange | null, setSelectionRange: (range: ISelectionRange | null) => void, setActiveCell: (cell: IActiveCell | null) => void);
|
|
36
|
+
get isFillDragging(): boolean;
|
|
37
|
+
get fillRange(): ISelectionRange | null;
|
|
38
|
+
setWrapperRef(ref: HTMLElement | null): void;
|
|
39
|
+
updateParams(params: FillHandleParams<T>): void;
|
|
40
|
+
/** Called when the fill handle square is mousedown'd. */
|
|
41
|
+
startFillDrag(e: MouseEvent): void;
|
|
42
|
+
private onMouseMove;
|
|
43
|
+
private onMouseUp;
|
|
44
|
+
private applyFillValues;
|
|
45
|
+
private resolveRange;
|
|
46
|
+
private applyDragAttrs;
|
|
47
|
+
private clearDragAttrs;
|
|
48
|
+
onFillRangeChange(handler: (data: FillHandleEvents['fillRangeChange']) => void): () => void;
|
|
49
|
+
destroy(): void;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { IColumnDef, IColumnGroupDef } from '../types/columnTypes';
|
|
2
|
+
import type { RowId, IFilters, OGridOptions, IJsOGridApi } from '../types/gridTypes';
|
|
3
|
+
import type { FilterValue } from '@alaarab/ogrid-core';
|
|
4
|
+
interface StateChangeEvent {
|
|
5
|
+
type: 'data' | 'sort' | 'filter' | 'page' | 'columns' | 'loading';
|
|
6
|
+
}
|
|
7
|
+
export declare class GridState<T> {
|
|
8
|
+
private emitter;
|
|
9
|
+
private _data;
|
|
10
|
+
private _page;
|
|
11
|
+
private _pageSize;
|
|
12
|
+
private _sort;
|
|
13
|
+
private _filters;
|
|
14
|
+
private _visibleColumns;
|
|
15
|
+
private _isLoading;
|
|
16
|
+
private _columns;
|
|
17
|
+
private _allColumns;
|
|
18
|
+
private _getRowId;
|
|
19
|
+
private _dataSource;
|
|
20
|
+
private _serverItems;
|
|
21
|
+
private _serverTotalCount;
|
|
22
|
+
private _fetchId;
|
|
23
|
+
private _onError?;
|
|
24
|
+
private _onFirstDataRendered?;
|
|
25
|
+
private _firstDataRendered;
|
|
26
|
+
private _filterOptions;
|
|
27
|
+
constructor(options: OGridOptions<T>);
|
|
28
|
+
get data(): T[];
|
|
29
|
+
get page(): number;
|
|
30
|
+
get pageSize(): number;
|
|
31
|
+
get sort(): {
|
|
32
|
+
field: string;
|
|
33
|
+
direction: 'asc' | 'desc';
|
|
34
|
+
} | undefined;
|
|
35
|
+
get filters(): IFilters;
|
|
36
|
+
get visibleColumns(): Set<string>;
|
|
37
|
+
get isLoading(): boolean;
|
|
38
|
+
get columns(): IColumnDef<T>[];
|
|
39
|
+
get allColumns(): (IColumnDef<T> | IColumnGroupDef<T>)[];
|
|
40
|
+
get getRowId(): (item: T) => RowId;
|
|
41
|
+
get isServerSide(): boolean;
|
|
42
|
+
get filterOptions(): Record<string, string[]>;
|
|
43
|
+
/** Get the visible columns in display order. */
|
|
44
|
+
get visibleColumnDefs(): IColumnDef<T>[];
|
|
45
|
+
/** Get processed (sorted, filtered, paginated) items for current page. */
|
|
46
|
+
getProcessedItems(): {
|
|
47
|
+
items: T[];
|
|
48
|
+
totalCount: number;
|
|
49
|
+
};
|
|
50
|
+
private fetchServerData;
|
|
51
|
+
setData(data: T[]): void;
|
|
52
|
+
setPage(page: number): void;
|
|
53
|
+
setPageSize(pageSize: number): void;
|
|
54
|
+
setSort(sort: {
|
|
55
|
+
field: string;
|
|
56
|
+
direction: 'asc' | 'desc';
|
|
57
|
+
} | undefined): void;
|
|
58
|
+
toggleSort(field: string): void;
|
|
59
|
+
setFilter(key: string, value: FilterValue | undefined): void;
|
|
60
|
+
clearFilters(): void;
|
|
61
|
+
setVisibleColumns(columns: Set<string>): void;
|
|
62
|
+
setLoading(loading: boolean): void;
|
|
63
|
+
refreshData(): void;
|
|
64
|
+
onStateChange(handler: (event: StateChangeEvent) => void): () => void;
|
|
65
|
+
getApi(): IJsOGridApi<T>;
|
|
66
|
+
destroy(): void;
|
|
67
|
+
}
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { IFilters, FilterValue } from '@alaarab/ogrid-core';
|
|
2
|
+
import type { ColumnFilterType } from '@alaarab/ogrid-core';
|
|
3
|
+
export interface HeaderFilterConfig {
|
|
4
|
+
columnId: string;
|
|
5
|
+
filterField: string;
|
|
6
|
+
filterType: ColumnFilterType;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Manages header filter popover state for all columns.
|
|
10
|
+
* Equivalent of React's useColumnHeaderFilterState, but class-based.
|
|
11
|
+
*/
|
|
12
|
+
export declare class HeaderFilterState {
|
|
13
|
+
private emitter;
|
|
14
|
+
private _openColumnId;
|
|
15
|
+
private _tempTextValue;
|
|
16
|
+
private _tempSelected;
|
|
17
|
+
private _tempDateFrom;
|
|
18
|
+
private _tempDateTo;
|
|
19
|
+
private _searchText;
|
|
20
|
+
private _popoverPosition;
|
|
21
|
+
private _filters;
|
|
22
|
+
private _onFilterChange;
|
|
23
|
+
private _filterOptions;
|
|
24
|
+
private _clickOutsideHandler;
|
|
25
|
+
private _escapeHandler;
|
|
26
|
+
private _popoverEl;
|
|
27
|
+
private _headerEl;
|
|
28
|
+
constructor(onFilterChange: (key: string, value: FilterValue | undefined) => void);
|
|
29
|
+
get openColumnId(): string | null;
|
|
30
|
+
get tempTextValue(): string;
|
|
31
|
+
get tempSelected(): Set<string>;
|
|
32
|
+
get tempDateFrom(): string;
|
|
33
|
+
get tempDateTo(): string;
|
|
34
|
+
get searchText(): string;
|
|
35
|
+
get popoverPosition(): {
|
|
36
|
+
top: number;
|
|
37
|
+
left: number;
|
|
38
|
+
} | null;
|
|
39
|
+
setFilters(filters: IFilters): void;
|
|
40
|
+
setFilterOptions(options: Record<string, string[]>): void;
|
|
41
|
+
getFilterOptions(filterField: string): string[];
|
|
42
|
+
getFilteredOptions(filterField: string): string[];
|
|
43
|
+
hasActiveFilter(config: HeaderFilterConfig): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Open a filter popover for a specific column.
|
|
46
|
+
*/
|
|
47
|
+
open(columnId: string, config: HeaderFilterConfig, headerEl: HTMLElement, popoverEl: HTMLElement): void;
|
|
48
|
+
close(): void;
|
|
49
|
+
setTempTextValue(v: string): void;
|
|
50
|
+
setSearchText(v: string): void;
|
|
51
|
+
setTempDateFrom(v: string): void;
|
|
52
|
+
setTempDateTo(v: string): void;
|
|
53
|
+
handleCheckboxChange(option: string, checked: boolean): void;
|
|
54
|
+
handleSelectAll(filterField: string): void;
|
|
55
|
+
handleClearSelection(): void;
|
|
56
|
+
applyTextFilter(filterField: string): void;
|
|
57
|
+
clearTextFilter(filterField: string): void;
|
|
58
|
+
applyMultiSelectFilter(filterField: string): void;
|
|
59
|
+
applyDateFilter(filterField: string): void;
|
|
60
|
+
clearDateFilter(filterField: string): void;
|
|
61
|
+
clearFilter(filterField: string): void;
|
|
62
|
+
onChange(handler: () => void): () => void;
|
|
63
|
+
destroy(): void;
|
|
64
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IActiveCell, ISelectionRange, IColumnDef, ICellValueChangedEvent, RowId } from '@alaarab/ogrid-core';
|
|
2
|
+
export interface KeyboardNavParams<T> {
|
|
3
|
+
items: T[];
|
|
4
|
+
visibleCols: IColumnDef<T>[];
|
|
5
|
+
colOffset: number;
|
|
6
|
+
getRowId: (item: T) => RowId;
|
|
7
|
+
editable?: boolean;
|
|
8
|
+
onCellValueChanged?: (event: ICellValueChangedEvent<T>) => void;
|
|
9
|
+
onCopy?: () => void;
|
|
10
|
+
onCut?: () => void;
|
|
11
|
+
onPaste?: () => Promise<void>;
|
|
12
|
+
onUndo?: () => void;
|
|
13
|
+
onRedo?: () => void;
|
|
14
|
+
onContextMenu?: (x: number, y: number) => void;
|
|
15
|
+
onStartEdit?: (rowId: RowId, columnId: string) => void;
|
|
16
|
+
clearClipboardRanges?: () => void;
|
|
17
|
+
}
|
|
18
|
+
export declare class KeyboardNavState<T> {
|
|
19
|
+
private params;
|
|
20
|
+
private getActiveCell;
|
|
21
|
+
private getSelectionRange;
|
|
22
|
+
private setActiveCell;
|
|
23
|
+
private setSelectionRange;
|
|
24
|
+
private wrapperRef;
|
|
25
|
+
constructor(params: KeyboardNavParams<T>, getActiveCell: () => IActiveCell | null, getSelectionRange: () => ISelectionRange | null, setActiveCell: (cell: IActiveCell | null) => void, setSelectionRange: (range: ISelectionRange | null) => void);
|
|
26
|
+
setWrapperRef(ref: HTMLElement | null): void;
|
|
27
|
+
updateParams(params: KeyboardNavParams<T>): void;
|
|
28
|
+
handleKeyDown: (e: KeyboardEvent) => void;
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { RowId, RowSelectionMode, IRowSelectionChangeEvent } from '@alaarab/ogrid-core';
|
|
2
|
+
/**
|
|
3
|
+
* Manages row selection state for single or multiple selection modes with shift-click range support.
|
|
4
|
+
* Vanilla JS equivalent of React's `useRowSelection` hook.
|
|
5
|
+
*/
|
|
6
|
+
export declare class RowSelectionState<T> {
|
|
7
|
+
private emitter;
|
|
8
|
+
private _selectedRowIds;
|
|
9
|
+
private _rowSelection;
|
|
10
|
+
private _lastClickedRow;
|
|
11
|
+
private _getRowId;
|
|
12
|
+
constructor(rowSelection: RowSelectionMode, getRowId: (item: T) => RowId);
|
|
13
|
+
get selectedRowIds(): Set<RowId>;
|
|
14
|
+
get rowSelection(): RowSelectionMode;
|
|
15
|
+
updateSelection(newSelectedIds: Set<RowId>, items: T[]): void;
|
|
16
|
+
handleRowCheckboxChange(rowId: RowId, checked: boolean, rowIndex: number, shiftKey: boolean, items: T[]): void;
|
|
17
|
+
handleSelectAll(checked: boolean, items: T[]): void;
|
|
18
|
+
isAllSelected(items: T[]): boolean;
|
|
19
|
+
isSomeSelected(items: T[]): boolean;
|
|
20
|
+
getSelectedRows(items: T[]): T[];
|
|
21
|
+
onRowSelectionChange(handler: (data: IRowSelectionChangeEvent<T>) => void): () => void;
|
|
22
|
+
destroy(): void;
|
|
23
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { IActiveCell, ISelectionRange, RowId } from '@alaarab/ogrid-core';
|
|
2
|
+
interface SelectionStateEvents extends Record<string, unknown> {
|
|
3
|
+
selectionChange: {
|
|
4
|
+
activeCell: IActiveCell | null;
|
|
5
|
+
selectionRange: ISelectionRange | null;
|
|
6
|
+
};
|
|
7
|
+
rowSelectionChange: {
|
|
8
|
+
selectedRowIds: Set<RowId>;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare class SelectionState {
|
|
12
|
+
private emitter;
|
|
13
|
+
private _activeCell;
|
|
14
|
+
private _selectionRange;
|
|
15
|
+
private _selectedRowIds;
|
|
16
|
+
private _isDragging;
|
|
17
|
+
private dragStartCell;
|
|
18
|
+
private rafHandle;
|
|
19
|
+
private pendingRange;
|
|
20
|
+
get activeCell(): IActiveCell | null;
|
|
21
|
+
get selectionRange(): ISelectionRange | null;
|
|
22
|
+
get selectedRowIds(): Set<RowId>;
|
|
23
|
+
get isDragging(): boolean;
|
|
24
|
+
/** Get the current drag range (used during drag for DOM attribute updates). */
|
|
25
|
+
getDragRange(): ISelectionRange | null;
|
|
26
|
+
setActiveCell(cell: IActiveCell | null): void;
|
|
27
|
+
setSelectionRange(range: ISelectionRange | null): void;
|
|
28
|
+
clearSelection(): void;
|
|
29
|
+
startDrag(rowIndex: number, colIndex: number): void;
|
|
30
|
+
updateDrag(rowIndex: number, colIndex: number, applyFn: (range: ISelectionRange) => void): void;
|
|
31
|
+
endDrag(): void;
|
|
32
|
+
setSelectedRowIds(ids: Set<RowId>): void;
|
|
33
|
+
onSelectionChange(handler: (data: SelectionStateEvents['selectionChange']) => void): () => void;
|
|
34
|
+
onRowSelectionChange(handler: (data: SelectionStateEvents['rowSelectionChange']) => void): () => void;
|
|
35
|
+
destroy(): void;
|
|
36
|
+
}
|
|
37
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SideBarPanelId, ISideBarDef } from '@alaarab/ogrid-core';
|
|
2
|
+
export declare class SideBarState {
|
|
3
|
+
private emitter;
|
|
4
|
+
private _isEnabled;
|
|
5
|
+
private _panels;
|
|
6
|
+
private _position;
|
|
7
|
+
private _activePanel;
|
|
8
|
+
constructor(config: boolean | ISideBarDef | undefined);
|
|
9
|
+
get isEnabled(): boolean;
|
|
10
|
+
get panels(): SideBarPanelId[];
|
|
11
|
+
get position(): 'left' | 'right';
|
|
12
|
+
get activePanel(): SideBarPanelId | null;
|
|
13
|
+
get isOpen(): boolean;
|
|
14
|
+
setActivePanel(panel: SideBarPanelId | null): void;
|
|
15
|
+
toggle(panel: SideBarPanelId): void;
|
|
16
|
+
close(): void;
|
|
17
|
+
onChange(handler: () => void): () => void;
|
|
18
|
+
destroy(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
interface LayoutChangeEvent {
|
|
2
|
+
type: 'containerResize' | 'columnOverride';
|
|
3
|
+
}
|
|
4
|
+
export declare class TableLayoutState {
|
|
5
|
+
private emitter;
|
|
6
|
+
private _containerWidth;
|
|
7
|
+
private _columnSizingOverrides;
|
|
8
|
+
private _ro;
|
|
9
|
+
/** Start observing a container element for resize. */
|
|
10
|
+
observeContainer(el: HTMLElement): void;
|
|
11
|
+
private disconnectObserver;
|
|
12
|
+
get containerWidth(): number;
|
|
13
|
+
get columnSizingOverrides(): Record<string, number>;
|
|
14
|
+
/** Set a column width override (from resize drag). */
|
|
15
|
+
setColumnOverride(columnId: string, widthPx: number): void;
|
|
16
|
+
/** Compute minimum table width from visible columns. */
|
|
17
|
+
computeMinTableWidth(visibleColumnCount: number, hasCheckboxColumn: boolean): number;
|
|
18
|
+
/** Compute desired table width respecting overrides. */
|
|
19
|
+
computeDesiredTableWidth(visibleColumns: {
|
|
20
|
+
columnId: string;
|
|
21
|
+
minWidth?: number;
|
|
22
|
+
width?: number;
|
|
23
|
+
}[], hasCheckboxColumn: boolean): number;
|
|
24
|
+
/** Get all column widths (overrides only — non-overridden columns use CSS defaults). */
|
|
25
|
+
getAllColumnWidths(): Record<string, number>;
|
|
26
|
+
/** Remove overrides for columns that no longer exist. */
|
|
27
|
+
cleanupOverrides(validColumnIds: Set<string>): void;
|
|
28
|
+
/** Apply initial column widths from options. */
|
|
29
|
+
applyInitialWidths(initialWidths: Record<string, number>): void;
|
|
30
|
+
onLayoutChange(handler: (event: LayoutChangeEvent) => void): () => void;
|
|
31
|
+
destroy(): void;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ICellValueChangedEvent } from '@alaarab/ogrid-core';
|
|
2
|
+
interface UndoRedoStateEvents extends Record<string, unknown> {
|
|
3
|
+
stackChange: {
|
|
4
|
+
canUndo: boolean;
|
|
5
|
+
canRedo: boolean;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export declare class UndoRedoState<T> {
|
|
9
|
+
private onCellValueChanged;
|
|
10
|
+
private emitter;
|
|
11
|
+
private historyStack;
|
|
12
|
+
private redoStack;
|
|
13
|
+
private batch;
|
|
14
|
+
private maxUndoDepth;
|
|
15
|
+
private wrappedCallback;
|
|
16
|
+
constructor(onCellValueChanged: ((event: ICellValueChangedEvent<T>) => void) | undefined, maxUndoDepth?: number);
|
|
17
|
+
get canUndo(): boolean;
|
|
18
|
+
get canRedo(): boolean;
|
|
19
|
+
getWrappedCallback(): ((event: ICellValueChangedEvent<T>) => void) | undefined;
|
|
20
|
+
beginBatch(): void;
|
|
21
|
+
endBatch(): void;
|
|
22
|
+
undo(): void;
|
|
23
|
+
redo(): void;
|
|
24
|
+
private emitStackChange;
|
|
25
|
+
onStackChange(handler: (data: UndoRedoStateEvents['stackChange']) => void): () => void;
|
|
26
|
+
destroy(): void;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { IColumnDef as ICoreColumnDef, CellEditorParams } from '@alaarab/ogrid-core';
|
|
2
|
+
export type { IColumnMeta, ICellValueChangedEvent, CellEditorParams } from '@alaarab/ogrid-core';
|
|
3
|
+
export type { ColumnFilterType, IDateFilterValue, IColumnFilterDef, IValueParserParams, HeaderCell, HeaderRow, IColumnDefinition, } from '@alaarab/ogrid-core';
|
|
4
|
+
/** Vanilla JS column definition — extends core with DOM rendering capabilities. */
|
|
5
|
+
export interface IColumnDef<T = unknown> extends Omit<ICoreColumnDef<T>, 'cellEditor'> {
|
|
6
|
+
/** Render cell content by mutating the cell's DOM. Return void. */
|
|
7
|
+
renderCell?: (cell: HTMLTableCellElement, item: T, value: unknown) => void;
|
|
8
|
+
/** Static or per-row cell inline styles (Partial<CSSStyleDeclaration>). */
|
|
9
|
+
cellStyle?: Partial<CSSStyleDeclaration> | ((item: T) => Partial<CSSStyleDeclaration>);
|
|
10
|
+
/** Built-in editor type or factory function that returns an HTMLElement editor. */
|
|
11
|
+
cellEditor?: 'text' | 'select' | 'checkbox' | 'richSelect' | 'date' | ((params: ICellEditorContext<T>) => HTMLElement);
|
|
12
|
+
}
|
|
13
|
+
/** Context passed to custom cell editor factories. */
|
|
14
|
+
export interface ICellEditorContext<T> {
|
|
15
|
+
value: unknown;
|
|
16
|
+
onValueChange: (value: unknown) => void;
|
|
17
|
+
onCommit: () => void;
|
|
18
|
+
onCancel: () => void;
|
|
19
|
+
item: T;
|
|
20
|
+
column: IColumnDef<T>;
|
|
21
|
+
cell: HTMLTableCellElement;
|
|
22
|
+
cellEditorParams?: CellEditorParams;
|
|
23
|
+
}
|
|
24
|
+
/** Column group (uses vanilla JS IColumnDef). */
|
|
25
|
+
export interface IColumnGroupDef<T = unknown> {
|
|
26
|
+
headerName: string;
|
|
27
|
+
children: (IColumnGroupDef<T> | IColumnDef<T>)[];
|
|
28
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { IColumnDef, IColumnGroupDef, ICellValueChangedEvent } from './columnTypes';
|
|
2
|
+
import type { RowId, IFilters, IDataSource, RowSelectionMode, IRowSelectionChangeEvent, IOGridApi, ISideBarDef } from '@alaarab/ogrid-core';
|
|
3
|
+
export type { RowId, UserLike, UserLikeInput, FilterValue, IFilters, IFetchParams, IPageResult, IDataSource, IGridColumnState, RowSelectionMode, IRowSelectionChangeEvent, StatusBarPanel, IStatusBarProps, IActiveCell, ISelectionRange, SideBarPanelId, ISideBarDef, IOGridApi, } from '@alaarab/ogrid-core';
|
|
4
|
+
/** Extended API for the vanilla JS package (adds methods not in the core IOGridApi). */
|
|
5
|
+
export interface IJsOGridApi<T> extends IOGridApi<T> {
|
|
6
|
+
/** Export displayed rows to CSV and trigger a download. */
|
|
7
|
+
exportToCsv: (filename?: string) => void;
|
|
8
|
+
}
|
|
9
|
+
/** Options for the vanilla JS OGrid constructor. */
|
|
10
|
+
export interface OGridOptions<T> {
|
|
11
|
+
columns: (IColumnDef<T> | IColumnGroupDef<T>)[];
|
|
12
|
+
getRowId: (item: T) => RowId;
|
|
13
|
+
/** Client-side data array. Mutually exclusive with dataSource. */
|
|
14
|
+
data?: T[];
|
|
15
|
+
/** Server-side data source. Mutually exclusive with data. */
|
|
16
|
+
dataSource?: IDataSource<T>;
|
|
17
|
+
/** Initial page (1-based). Default: 1. */
|
|
18
|
+
page?: number;
|
|
19
|
+
/** Rows per page. Default: 20. */
|
|
20
|
+
pageSize?: number;
|
|
21
|
+
/** Initial sort. */
|
|
22
|
+
sort?: {
|
|
23
|
+
field: string;
|
|
24
|
+
direction: 'asc' | 'desc';
|
|
25
|
+
};
|
|
26
|
+
/** Initial filters. */
|
|
27
|
+
filters?: IFilters;
|
|
28
|
+
/** Initially visible columns (all visible if omitted). */
|
|
29
|
+
visibleColumns?: Set<string>;
|
|
30
|
+
editable?: boolean;
|
|
31
|
+
cellSelection?: boolean;
|
|
32
|
+
/** Callback fired when a cell value is changed via editing. */
|
|
33
|
+
onCellValueChanged?: (event: ICellValueChangedEvent<T>) => void;
|
|
34
|
+
rowSelection?: RowSelectionMode;
|
|
35
|
+
/** Callback fired when row selection changes. */
|
|
36
|
+
onSelectionChange?: (event: IRowSelectionChangeEvent<T>) => void;
|
|
37
|
+
/** Controlled selected row IDs. */
|
|
38
|
+
selectedRows?: Set<RowId>;
|
|
39
|
+
/** Pin columns to left/right edges. Keys are columnIds. */
|
|
40
|
+
pinnedColumns?: Record<string, 'left' | 'right'>;
|
|
41
|
+
/** Layout mode: 'content' sizes to content, 'fill' fills container. Default: 'fill'. */
|
|
42
|
+
layoutMode?: 'content' | 'fill';
|
|
43
|
+
suppressHorizontalScroll?: boolean;
|
|
44
|
+
/** Custom empty state message. */
|
|
45
|
+
emptyMessage?: string;
|
|
46
|
+
/** Accessible label for the grid. */
|
|
47
|
+
'aria-label'?: string;
|
|
48
|
+
/** Side bar configuration (columns panel + filters panel). */
|
|
49
|
+
sideBar?: boolean | ISideBarDef;
|
|
50
|
+
/** Error callback for server-side data source failures. */
|
|
51
|
+
onError?: (error: unknown) => void;
|
|
52
|
+
/** Callback fired when first data is rendered. */
|
|
53
|
+
onFirstDataRendered?: () => void;
|
|
54
|
+
}
|
|
55
|
+
/** Events emitted by the OGrid instance. */
|
|
56
|
+
export interface OGridEvents<T> extends Record<string, unknown> {
|
|
57
|
+
cellValueChanged: ICellValueChangedEvent<T>;
|
|
58
|
+
selectionChange: IRowSelectionChangeEvent<T>;
|
|
59
|
+
sortChange: {
|
|
60
|
+
field: string;
|
|
61
|
+
direction: 'asc' | 'desc';
|
|
62
|
+
};
|
|
63
|
+
filterChange: {
|
|
64
|
+
filters: IFilters;
|
|
65
|
+
};
|
|
66
|
+
pageChange: {
|
|
67
|
+
page: number;
|
|
68
|
+
};
|
|
69
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@alaarab/ogrid-js",
|
|
3
|
+
"version": "2.0.0-beta",
|
|
4
|
+
"description": "OGrid vanilla JS – framework-free data grid with sorting, filtering, pagination, and spreadsheet-style editing.",
|
|
5
|
+
"main": "dist/esm/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/types/index.d.ts",
|
|
11
|
+
"import": "./dist/esm/index.js",
|
|
12
|
+
"require": "./dist/esm/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./styles": "./dist/styles/ogrid.css"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "rimraf dist && tsc -p tsconfig.build.json",
|
|
18
|
+
"test": "jest"
|
|
19
|
+
},
|
|
20
|
+
"keywords": ["ogrid", "datagrid", "vanilla", "javascript", "typescript", "grid"],
|
|
21
|
+
"author": "Ala Arab",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"files": ["dist", "README.md", "LICENSE"],
|
|
24
|
+
"engines": { "node": ">=18" },
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@alaarab/ogrid-core": "2.0.0-beta"
|
|
27
|
+
},
|
|
28
|
+
"publishConfig": { "access": "public" }
|
|
29
|
+
}
|