@omnigrid/core 0.1.6 → 0.1.7
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/grid.d.ts +2 -0
- package/dist/grid.js +24 -0
- package/dist/types.d.ts +34 -1
- package/dist/virtualizer.js +8 -2
- package/package.json +1 -1
package/dist/grid.d.ts
CHANGED
|
@@ -23,6 +23,8 @@ export declare class Grid<T> implements GridApi<T> {
|
|
|
23
23
|
*/
|
|
24
24
|
private scrollPosition;
|
|
25
25
|
constructor(options: GridOptions<T>);
|
|
26
|
+
/** Returns the calculated width for a visible column, including off-screen columns. */
|
|
27
|
+
getColumnWidth(columnId: string): number | undefined;
|
|
26
28
|
getState(): GridState<T>;
|
|
27
29
|
/** Returns the current ephemeral scroll position (not part of Store state). */
|
|
28
30
|
getScrollPosition(): ScrollPosition;
|
package/dist/grid.js
CHANGED
|
@@ -46,6 +46,30 @@ export class Grid {
|
|
|
46
46
|
this.store.subscribe(() => this.events.emit("stateChange", this.store.getState()));
|
|
47
47
|
options.plugins?.forEach((plugin) => this.registerPlugin(plugin));
|
|
48
48
|
}
|
|
49
|
+
/** Returns the calculated width for a visible column, including off-screen columns. */
|
|
50
|
+
getColumnWidth(columnId) {
|
|
51
|
+
const state = this.getState();
|
|
52
|
+
const visibleColumns = flattenColumns(state.columns).filter((column) => !column.hidden);
|
|
53
|
+
if (!visibleColumns.some((column) => column.id === columnId))
|
|
54
|
+
return undefined;
|
|
55
|
+
const pinnedLeft = visibleColumns.filter((column) => column.pinned === "left");
|
|
56
|
+
const scrollable = visibleColumns.filter((column) => !column.pinned);
|
|
57
|
+
const pinnedRight = visibleColumns.filter((column) => column.pinned === "right");
|
|
58
|
+
const pinnedLeftOffsets = this.virtualizer.getColumnOffsets(pinnedLeft, state.viewport.width);
|
|
59
|
+
const pinnedRightOffsets = this.virtualizer.getColumnOffsets(pinnedRight, state.viewport.width);
|
|
60
|
+
const pinnedLeftWidth = pinnedLeftOffsets.reduce((sum, item) => sum + item.size, 0);
|
|
61
|
+
const pinnedRightWidth = pinnedRightOffsets.reduce((sum, item) => sum + item.size, 0);
|
|
62
|
+
const scrollableWidth = Math.max(0, state.viewport.width - pinnedLeftWidth - pinnedRightWidth);
|
|
63
|
+
const scrollableOffsets = this.virtualizer.getColumnOffsets(scrollable, scrollableWidth);
|
|
64
|
+
const pinnedLeftIndex = pinnedLeft.findIndex((column) => column.id === columnId);
|
|
65
|
+
if (pinnedLeftIndex >= 0)
|
|
66
|
+
return pinnedLeftOffsets[pinnedLeftIndex].size;
|
|
67
|
+
const pinnedRightIndex = pinnedRight.findIndex((column) => column.id === columnId);
|
|
68
|
+
if (pinnedRightIndex >= 0)
|
|
69
|
+
return pinnedRightOffsets[pinnedRightIndex].size;
|
|
70
|
+
const scrollableIndex = scrollable.findIndex((column) => column.id === columnId);
|
|
71
|
+
return scrollableOffsets[scrollableIndex]?.size;
|
|
72
|
+
}
|
|
49
73
|
getState() {
|
|
50
74
|
return this.store.getState();
|
|
51
75
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -52,41 +52,70 @@ export interface CheckboxControl extends CheckboxRenderParams {
|
|
|
52
52
|
type: "@omnigrid/checkbox";
|
|
53
53
|
}
|
|
54
54
|
interface BaseColumnDef<T> {
|
|
55
|
+
/** Stable identifier used by the grid and plugins. */
|
|
55
56
|
id: string;
|
|
57
|
+
/** Text displayed in the column header. */
|
|
56
58
|
header: string;
|
|
59
|
+
/** Pins the column to a horizontal edge of the grid. */
|
|
57
60
|
pinned?: "left" | "right";
|
|
61
|
+
/** Whether this column may be resized by the resize plugin. */
|
|
62
|
+
resizable?: boolean;
|
|
63
|
+
/** Custom renderer for this column's header. */
|
|
58
64
|
headerRenderer?: (column: ColumnDef<T>) => unknown;
|
|
59
65
|
}
|
|
60
66
|
export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
|
|
67
|
+
/** Row property used as the cell value source. */
|
|
61
68
|
field?: keyof T | string;
|
|
69
|
+
/** Hides this column without removing it from the column definitions. */
|
|
62
70
|
hidden?: boolean;
|
|
71
|
+
/** Relative width factor used to distribute available space. */
|
|
63
72
|
flex?: number;
|
|
73
|
+
/** Fixed column width in pixels. */
|
|
64
74
|
width?: number;
|
|
75
|
+
/** Minimum column width in pixels. */
|
|
65
76
|
minWidth?: number;
|
|
77
|
+
/** Maximum column width in pixels. */
|
|
66
78
|
maxWidth?: number;
|
|
79
|
+
/** Whether this column can be sorted. */
|
|
67
80
|
sortable?: boolean;
|
|
81
|
+
/** Horizontal alignment of cell content. */
|
|
68
82
|
align?: CellAlign;
|
|
83
|
+
/** Initial sort direction used by SortingPlugin. */
|
|
69
84
|
sortState?: SortDirection;
|
|
70
85
|
/** 1-based sort priority, set only while multiple columns are sorted. */
|
|
71
86
|
sortIndex?: number;
|
|
72
87
|
/** Compares values for this column, overriding the sorting plugin default. */
|
|
73
88
|
comparator?: (left: unknown, right: unknown, column: ColumnLeafDef<T>) => number;
|
|
89
|
+
/** Prevents clicks in this column's cells from triggering row-click behavior. */
|
|
74
90
|
stopRowClick?: boolean;
|
|
91
|
+
/** Prevents clicks on this column's header from triggering header-click behavior. */
|
|
75
92
|
stopHeaderClick?: boolean;
|
|
93
|
+
/** Computes the cell value from the row; takes precedence over `field`. */
|
|
76
94
|
valueGetter?: (row: T) => unknown;
|
|
95
|
+
/** Formats the raw cell value for display. */
|
|
77
96
|
valueFormatter?: (value: unknown) => string;
|
|
97
|
+
/** Replaces the default cell content with custom content. */
|
|
78
98
|
cellRenderer?: (params: CellRenderParams<T>) => unknown;
|
|
99
|
+
/** Static inline styles applied to cells in this column. */
|
|
79
100
|
cellStyle?: RowStyle;
|
|
101
|
+
/** Computes inline styles for each rendered cell. */
|
|
80
102
|
getCellStyle?: (params: CellRenderParams<T>) => RowStyle | undefined;
|
|
103
|
+
/** Static CSS class applied to cells in this column. */
|
|
81
104
|
cellClass?: string | ((params: CellRenderParams<T>) => string | undefined);
|
|
105
|
+
/** Computes a CSS class for each rendered cell. */
|
|
82
106
|
getCellClass?: (params: CellRenderParams<T>) => string | undefined;
|
|
107
|
+
/** Maps CSS class names to predicates evaluated for each rendered cell. */
|
|
83
108
|
cellClassRules?: CellClassRules<T>;
|
|
84
109
|
}
|
|
85
110
|
export interface ColumnGroupDef<T> extends BaseColumnDef<T> {
|
|
111
|
+
/** Child column definitions nested under this group. */
|
|
86
112
|
children: ColumnDef<T>[];
|
|
113
|
+
/** Allows users to collapse and expand this group. */
|
|
87
114
|
collapsible?: boolean;
|
|
115
|
+
/** Whether this group starts expanded when it is collapsible. */
|
|
88
116
|
defaultExpanded?: boolean;
|
|
89
117
|
}
|
|
118
|
+
/** Leaf or grouped column definition accepted by the grid. */
|
|
90
119
|
export type ColumnDef<T> = ColumnLeafDef<T> | ColumnGroupDef<T>;
|
|
91
120
|
export interface GridOptions<T> {
|
|
92
121
|
data?: T[];
|
|
@@ -286,10 +315,13 @@ export interface BlockConfig<Name extends string = string> {
|
|
|
286
315
|
position?: SlotPosition;
|
|
287
316
|
priority?: number;
|
|
288
317
|
}
|
|
289
|
-
export type SlotNodeEventName = "click" | "change" | "keydown";
|
|
318
|
+
export type SlotNodeEventName = "click" | "change" | "keydown" | "pointerdown" | "pointermove" | "pointerup" | "dblclick";
|
|
290
319
|
export interface SlotNodeEvent {
|
|
291
320
|
value?: string;
|
|
292
321
|
key?: string;
|
|
322
|
+
clientX?: number;
|
|
323
|
+
clientY?: number;
|
|
324
|
+
button?: number;
|
|
293
325
|
}
|
|
294
326
|
/**
|
|
295
327
|
* Context passed to the slot content provider. Headless: the plugin
|
|
@@ -362,6 +394,7 @@ export interface GridApi<T> {
|
|
|
362
394
|
getState(): GridState<T>;
|
|
363
395
|
getScrollPosition(): ScrollPosition;
|
|
364
396
|
getViewportData(): ViewportData<T>;
|
|
397
|
+
getColumnWidth(columnId: string): number | undefined;
|
|
365
398
|
getProcessedData(): T[];
|
|
366
399
|
getRowId(row: T, index: number): RowId;
|
|
367
400
|
setData(data: T[]): void;
|
package/dist/virtualizer.js
CHANGED
|
@@ -103,7 +103,9 @@ export class Virtualizer {
|
|
|
103
103
|
}
|
|
104
104
|
getColumnWidths(columns, viewportWidth) {
|
|
105
105
|
const widths = columns.map((column) => this.getBaseColumnWidth(column));
|
|
106
|
-
const flexIndexes = columns
|
|
106
|
+
const flexIndexes = columns
|
|
107
|
+
.map((column, index) => (column.flex && column.flex > 0 && column.width === undefined ? index : -1))
|
|
108
|
+
.filter((index) => index >= 0);
|
|
107
109
|
if (flexIndexes.length === 0)
|
|
108
110
|
return widths;
|
|
109
111
|
const fixedWidth = widths.reduce((total, width, index) => (flexIndexes.includes(index) ? total : total + width), 0);
|
|
@@ -168,8 +170,12 @@ export class Virtualizer {
|
|
|
168
170
|
return widths;
|
|
169
171
|
}
|
|
170
172
|
getBaseColumnWidth(column) {
|
|
171
|
-
if (column.flex && column.flex > 0)
|
|
173
|
+
if (column.flex && column.flex > 0) {
|
|
174
|
+
if (column.width !== undefined) {
|
|
175
|
+
return Math.min(this.getMaxColumnWidth(column), Math.max(this.getMinColumnWidth(column), column.width));
|
|
176
|
+
}
|
|
172
177
|
return this.getMinColumnWidth(column);
|
|
178
|
+
}
|
|
173
179
|
const width = column.width ?? 120;
|
|
174
180
|
return Math.min(this.getMaxColumnWidth(column), Math.max(this.getMinColumnWidth(column), width));
|
|
175
181
|
}
|