@alaarab/ogrid-js 2.1.2 → 2.1.4
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/index.js +6343 -32
- package/package.json +7 -5
- package/dist/esm/OGrid.js +0 -578
- package/dist/esm/OGridEventWiring.js +0 -178
- package/dist/esm/OGridRendering.js +0 -269
- package/dist/esm/components/ColumnChooser.js +0 -91
- package/dist/esm/components/ContextMenu.js +0 -125
- package/dist/esm/components/HeaderFilter.js +0 -281
- package/dist/esm/components/InlineCellEditor.js +0 -434
- package/dist/esm/components/MarchingAntsOverlay.js +0 -156
- package/dist/esm/components/PaginationControls.js +0 -85
- package/dist/esm/components/SideBar.js +0 -353
- package/dist/esm/components/StatusBar.js +0 -34
- package/dist/esm/renderer/TableRenderer.js +0 -846
- package/dist/esm/state/ClipboardState.js +0 -111
- package/dist/esm/state/ColumnPinningState.js +0 -82
- package/dist/esm/state/ColumnReorderState.js +0 -135
- package/dist/esm/state/ColumnResizeState.js +0 -55
- package/dist/esm/state/EventEmitter.js +0 -28
- package/dist/esm/state/FillHandleState.js +0 -206
- package/dist/esm/state/GridState.js +0 -324
- package/dist/esm/state/HeaderFilterState.js +0 -213
- package/dist/esm/state/KeyboardNavState.js +0 -216
- package/dist/esm/state/RowSelectionState.js +0 -72
- package/dist/esm/state/SelectionState.js +0 -109
- package/dist/esm/state/SideBarState.js +0 -41
- package/dist/esm/state/TableLayoutState.js +0 -97
- package/dist/esm/state/UndoRedoState.js +0 -71
- package/dist/esm/state/VirtualScrollState.js +0 -128
- package/dist/esm/types/columnTypes.js +0 -1
- package/dist/esm/types/gridTypes.js +0 -1
- package/dist/esm/types/index.js +0 -2
- package/dist/esm/utils/debounce.js +0 -2
- package/dist/esm/utils/getCellCoordinates.js +0 -15
- package/dist/esm/utils/index.js +0 -2
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { computeVisibleRange, computeTotalHeight, getScrollTopForRow } from '@alaarab/ogrid-core';
|
|
2
|
-
import { EventEmitter } from './EventEmitter';
|
|
3
|
-
const DEFAULT_ROW_HEIGHT = 36;
|
|
4
|
-
const DEFAULT_OVERSCAN = 5;
|
|
5
|
-
/**
|
|
6
|
-
* Manages virtual scrolling state for the vanilla JS grid.
|
|
7
|
-
* Follows the EventEmitter + RAF pattern from other state classes.
|
|
8
|
-
*/
|
|
9
|
-
export class VirtualScrollState {
|
|
10
|
-
constructor(config) {
|
|
11
|
-
this.emitter = new EventEmitter();
|
|
12
|
-
this._scrollTop = 0;
|
|
13
|
-
this._containerHeight = 0;
|
|
14
|
-
this._totalRows = 0;
|
|
15
|
-
this.rafId = 0;
|
|
16
|
-
this._ro = null;
|
|
17
|
-
this._cachedRange = { startIndex: 0, endIndex: -1, offsetTop: 0, offsetBottom: 0 };
|
|
18
|
-
this._config = config ?? { enabled: false };
|
|
19
|
-
}
|
|
20
|
-
/** Whether virtual scrolling is active. */
|
|
21
|
-
get enabled() {
|
|
22
|
-
return this._config.enabled === true && this._totalRows > 0;
|
|
23
|
-
}
|
|
24
|
-
get config() {
|
|
25
|
-
return this._config;
|
|
26
|
-
}
|
|
27
|
-
get containerHeight() {
|
|
28
|
-
return this._containerHeight;
|
|
29
|
-
}
|
|
30
|
-
get totalRows() {
|
|
31
|
-
return this._totalRows;
|
|
32
|
-
}
|
|
33
|
-
get scrollTop() {
|
|
34
|
-
return this._scrollTop;
|
|
35
|
-
}
|
|
36
|
-
/** Get the current visible range (computed from scroll position). */
|
|
37
|
-
get visibleRange() {
|
|
38
|
-
return this._cachedRange;
|
|
39
|
-
}
|
|
40
|
-
/** Get the total scrollable height for all rows. */
|
|
41
|
-
get totalHeight() {
|
|
42
|
-
return computeTotalHeight(this._totalRows, this._config.rowHeight ?? DEFAULT_ROW_HEIGHT);
|
|
43
|
-
}
|
|
44
|
-
/** Handle scroll events from the table container. RAF-throttled. */
|
|
45
|
-
handleScroll(scrollTop) {
|
|
46
|
-
if (this.rafId)
|
|
47
|
-
cancelAnimationFrame(this.rafId);
|
|
48
|
-
this.rafId = requestAnimationFrame(() => {
|
|
49
|
-
this.rafId = 0;
|
|
50
|
-
this._scrollTop = scrollTop;
|
|
51
|
-
this.recompute();
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
/** Scroll the container to bring a specific row into view. */
|
|
55
|
-
scrollToRow(index, container, align) {
|
|
56
|
-
const rowHeight = this._config.rowHeight ?? DEFAULT_ROW_HEIGHT;
|
|
57
|
-
const newScrollTop = getScrollTopForRow(index, rowHeight, this._containerHeight, align);
|
|
58
|
-
container.scrollTop = newScrollTop;
|
|
59
|
-
// Also update internal state immediately (don't wait for scroll event)
|
|
60
|
-
this._scrollTop = newScrollTop;
|
|
61
|
-
this.recompute();
|
|
62
|
-
}
|
|
63
|
-
/** Update the virtual scroll configuration. */
|
|
64
|
-
updateConfig(config) {
|
|
65
|
-
this._config = config;
|
|
66
|
-
this.recompute();
|
|
67
|
-
this.emitter.emit('configChanged', { config });
|
|
68
|
-
}
|
|
69
|
-
/** Update the total number of rows. */
|
|
70
|
-
setTotalRows(count) {
|
|
71
|
-
this._totalRows = count;
|
|
72
|
-
this.recompute();
|
|
73
|
-
}
|
|
74
|
-
/** Observe a container element for height changes via ResizeObserver. */
|
|
75
|
-
observeContainer(el) {
|
|
76
|
-
this.disconnectObserver();
|
|
77
|
-
if (typeof ResizeObserver !== 'undefined') {
|
|
78
|
-
this._ro = new ResizeObserver((entries) => {
|
|
79
|
-
for (const entry of entries) {
|
|
80
|
-
const rect = entry.contentRect;
|
|
81
|
-
this._containerHeight = rect.height;
|
|
82
|
-
this.recompute();
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
this._ro.observe(el);
|
|
86
|
-
}
|
|
87
|
-
// Measure initial size
|
|
88
|
-
this._containerHeight = el.clientHeight;
|
|
89
|
-
}
|
|
90
|
-
disconnectObserver() {
|
|
91
|
-
if (this._ro) {
|
|
92
|
-
this._ro.disconnect();
|
|
93
|
-
this._ro = null;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
/** Recompute visible range and emit if changed. */
|
|
97
|
-
recompute() {
|
|
98
|
-
if (!this.enabled)
|
|
99
|
-
return;
|
|
100
|
-
const rowHeight = this._config.rowHeight ?? DEFAULT_ROW_HEIGHT;
|
|
101
|
-
const overscan = this._config.overscan ?? DEFAULT_OVERSCAN;
|
|
102
|
-
const newRange = computeVisibleRange(this._scrollTop, rowHeight, this._containerHeight, this._totalRows, overscan);
|
|
103
|
-
// Only emit if range actually changed
|
|
104
|
-
const prev = this._cachedRange;
|
|
105
|
-
if (prev.startIndex !== newRange.startIndex ||
|
|
106
|
-
prev.endIndex !== newRange.endIndex) {
|
|
107
|
-
this._cachedRange = newRange;
|
|
108
|
-
this.emitter.emit('rangeChanged', { visibleRange: newRange });
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
this._cachedRange = newRange;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
onRangeChanged(handler) {
|
|
115
|
-
this.emitter.on('rangeChanged', handler);
|
|
116
|
-
return () => this.emitter.off('rangeChanged', handler);
|
|
117
|
-
}
|
|
118
|
-
onConfigChanged(handler) {
|
|
119
|
-
this.emitter.on('configChanged', handler);
|
|
120
|
-
return () => this.emitter.off('configChanged', handler);
|
|
121
|
-
}
|
|
122
|
-
destroy() {
|
|
123
|
-
if (this.rafId)
|
|
124
|
-
cancelAnimationFrame(this.rafId);
|
|
125
|
-
this.disconnectObserver();
|
|
126
|
-
this.emitter.removeAllListeners();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm/types/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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 function getCellCoordinates(cell) {
|
|
6
|
-
const rowStr = cell.getAttribute('data-row-index');
|
|
7
|
-
const colStr = cell.getAttribute('data-col-index');
|
|
8
|
-
if (rowStr == null || colStr == null)
|
|
9
|
-
return null;
|
|
10
|
-
const rowIndex = parseInt(rowStr, 10);
|
|
11
|
-
const colIndex = parseInt(colStr, 10);
|
|
12
|
-
if (Number.isNaN(rowIndex) || Number.isNaN(colIndex))
|
|
13
|
-
return null;
|
|
14
|
-
return { rowIndex, colIndex };
|
|
15
|
-
}
|
package/dist/esm/utils/index.js
DELETED