@omnigrid/core 0.1.23 → 0.1.25

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/types.d.ts CHANGED
@@ -1,12 +1,33 @@
1
1
  import type { OverlayOptions, OverlayState, OverlayType } from "./overlays";
2
2
  import type { SlotManager } from "./slots";
3
3
  import type { IconRegistry } from "./icons";
4
- import type { FilterCondition, FilterModel, FilterOperator } from "./filtering";
4
+ import type { FilterCondition, FilterModel } from "./filtering";
5
5
  import type { UIPopupAnchor, UIPopupDescriptor } from "./ui";
6
+ import type { StateUpdater } from "./store";
7
+ import type { DataPipeline } from "./pipeline";
8
+ export type { PipelineProcessor, PipelineStage } from "./pipeline";
6
9
  export type RowId = string | number;
7
10
  export type SortDirection = "asc" | "desc";
8
11
  export type CellAlign = "left" | "center" | "right";
9
12
  export type DataProcessor<T> = (data: T[]) => T[];
13
+ /** Scope used when resolving leaf descendants of a composite row. @api */
14
+ export type RowHierarchyScope = "all" | "filtered";
15
+ /**
16
+ * Generic hierarchy capability provided by a row-model plugin.
17
+ * Returns leaf row IDs for composite rows, or `undefined` when the ID is a leaf.
18
+ *
19
+ * @api
20
+ */
21
+ export interface RowHierarchy<T> {
22
+ /**
23
+ * Resolves the leaf rows represented by a row ID.
24
+ * @param rowId - Row or composite-row identifier.
25
+ * @param scope - Whether filtered-out descendants are included.
26
+ * @returns Leaf row IDs, an empty array for an empty composite row, or `undefined` for a leaf.
27
+ * @api
28
+ */
29
+ getLeafRowIds(rowId: RowId, scope: RowHierarchyScope): readonly RowId[] | undefined;
30
+ }
10
31
  /**
11
32
  * Nature of the values stored in a column.
12
33
  *
@@ -45,6 +66,95 @@ export interface RowNode<T> {
45
66
  /** Raw row data object. */
46
67
  data: T;
47
68
  }
69
+ /** Aggregation function applied to column values within a group. */
70
+ export type AggregationFunc<T = unknown> = (values: unknown[]) => unknown;
71
+ /**
72
+ * A group (aggregated) row produced by the Row Grouping engine.
73
+ *
74
+ * `id` is a stable path such as `"Region:Europe/Country:France"`. `key` is the
75
+ * group value at this level (e.g. `"Europe"`), `level` is the nesting depth
76
+ * (0 = outermost), and `expanded` reflects whether its children are visible in
77
+ * the flattened output. `aggregations` holds pre-computed per-column
78
+ * aggregates (sum, avg, min, max, count, ...).
79
+ *
80
+ * @api
81
+ */
82
+ export interface GroupRowNode<T> {
83
+ type: 'group';
84
+ /** Stable path identifying the group, e.g. "Region:Europe/Country:France". */
85
+ id: string;
86
+ /** Column field this group levels on. */
87
+ field: string;
88
+ /** Group value at this level, e.g. "Europe". */
89
+ key: string;
90
+ /** Nesting depth (0 = outermost group level). */
91
+ level: number;
92
+ /** Whether the group's children are currently visible in the flat output. */
93
+ expanded: boolean;
94
+ /** Total number of descendant leaf rows in this group. */
95
+ childrenCount: number;
96
+ /** Pre-computed per-column aggregates, keyed by column id. */
97
+ aggregations: Record<string, unknown>;
98
+ /** Child nodes (sub-groups and leaf rows). */
99
+ children: TreeRowNode<T>[];
100
+ }
101
+ /**
102
+ * Context passed to a custom group row renderer (`groupRowRenderer`).
103
+ *
104
+ * @api
105
+ */
106
+ export interface GroupRowRenderParams<T> {
107
+ /** The group node being rendered. */
108
+ node: GroupRowNode<T>;
109
+ /** The column the group cell belongs to. */
110
+ column: ColumnLeafDef<T>;
111
+ /** Stable row id of the group. */
112
+ id: RowId;
113
+ /** Zero-based index in the processed dataset. */
114
+ index: number;
115
+ /** The grid API instance. */
116
+ api: GridApi<T>;
117
+ /** Current grid state. */
118
+ state: GridState<T>;
119
+ }
120
+ /**
121
+ * Custom renderer for group rows. May return any headless content accepted by
122
+ * the active UI adapter (string, number, ReactNode, slot node, ...).
123
+ *
124
+ * @api
125
+ */
126
+ export type GroupRowRenderer<T> = (params: GroupRowRenderParams<T>) => unknown;
127
+ /**
128
+ * A leaf (data) row produced by the Row Grouping engine.
129
+ *
130
+ * Wraps a single raw data row together with the group it belongs to and its
131
+ * depth in the group hierarchy.
132
+ *
133
+ * @api
134
+ */
135
+ export interface DataRowNode<T> {
136
+ type: 'leaf';
137
+ /** Stable row identifier (from `getRowId`). */
138
+ id: RowId;
139
+ /** Raw row data object. */
140
+ data: T;
141
+ /** Nesting depth (equals the number of group levels). */
142
+ level: number;
143
+ /** The group this row belongs to. */
144
+ parent: GroupRowNode<T>;
145
+ /**
146
+ * Set when this leaf row is displayed as a collapsed single-child group
147
+ * (`collapseSingleChildGroups: true`). Contains the grouping field, value,
148
+ * and hierarchy level to display instead of the row's own field value.
149
+ */
150
+ collapsedGroup?: {
151
+ field: string;
152
+ key: string;
153
+ level: number;
154
+ };
155
+ }
156
+ /** A row in the flattened grouped output — either a group or a data row. */
157
+ export type TreeRowNode<T> = GroupRowNode<T> | DataRowNode<T>;
48
158
  /**
49
159
  * Context passed to the `colSpan` resolver of a column.
50
160
  *
@@ -143,6 +253,10 @@ export interface CellRenderParams<T> {
143
253
  data: T;
144
254
  column: ColumnLeafDef<T>;
145
255
  value?: unknown;
256
+ /** Whether the cell was recently updated and is currently flashing. */
257
+ isFlashed?: boolean;
258
+ /** Timestamp (ms) when the flash started; used by adapters to restart CSS animation on re-flash. */
259
+ flashTimestamp?: number;
146
260
  }
147
261
  export type CellClassRules<T> = Record<string, (params: CellRenderParams<T>) => boolean>;
148
262
  /**
@@ -270,43 +384,19 @@ export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
270
384
  maxWidth?: number;
271
385
  /** Whether this column can be sorted. */
272
386
  sortable?: boolean;
273
- /**
274
- * Nature of the values in this column. When omitted, the filtering plugin
275
- * infers it by sampling the data.
276
- */
277
- dataType?: ColumnDataType;
278
- /**
279
- * Kind of filter UI rendered for this column. When omitted, it is derived
280
- * from `dataType` (and, failing that, from the sampled data).
281
- */
282
- filterType?: ColumnFilterType;
283
- /**
284
- * Identifier of a custom filter registered with the filtering plugin.
285
- * Required when `filterType` is `"custom"`.
286
- */
287
- filterTypeId?: string;
288
- /**
289
- * Whether this column offers a filter menu. Set to `false` to opt the column out of
290
- * filtering UI (the header filter icon is hidden).
291
- * @default true
292
- */
293
- filterable?: boolean;
294
- /**
295
- * Custom subset of operators allowed for this column's filter menu.
296
- */
297
- allowedOperators?: FilterOperator[];
298
- /**
299
- * Fixed option list used by the `"set"` filter. When provided, the column
300
- * defaults to `filterType: "set"` unless `filterType` is set explicitly.
301
- */
302
- filterOptions?: Array<{
303
- label: string;
304
- value: any;
305
- }>;
306
387
  /** Horizontal alignment of cell content. */
307
388
  align?: CellAlign;
308
389
  /** Enables automatic text wrapping instead of ellipsis truncation. @default false @api */
309
390
  wrapText?: boolean;
391
+ /**
392
+ * Controls whether the cell keeps the theme's internal padding or removes it
393
+ * so custom content can fill the cell.
394
+ * - `"normal"` (default): preserves the theme padding.
395
+ * - `"flush"`: removes the cell padding.
396
+ * @default "normal"
397
+ * @api
398
+ */
399
+ cellLayout?: "normal" | "flush";
310
400
  /** Initial sort direction used by SortingPlugin. */
311
401
  sortState?: SortDirection;
312
402
  /** 1-based sort priority, set only while multiple columns are sorted. */
@@ -465,6 +555,16 @@ export interface GridOptions<T> {
465
555
  /** Columns to render beyond the visible viewport (left + right buffer). @default 2 */
466
556
  columnOverscan?: number;
467
557
  suppressRowHoverHighlight?: boolean;
558
+ /**
559
+ * Enables automatic cell flashing when data is mutated via
560
+ * `grid.applyTransaction()`. Cells whose values changed are highlighted
561
+ * with a CSS transition that fades out automatically. Pass `true` for the
562
+ * default duration (1000ms), or a number for a custom duration in
563
+ * milliseconds. `false` / `0` / `undefined` disables the feature.
564
+ * @default false
565
+ * @api
566
+ */
567
+ cellFlash?: boolean | number;
468
568
  rowStyle?: RowStyle;
469
569
  getRowStyle?: (params: RowRenderParams<T>) => RowStyle | undefined;
470
570
  rowClass?: string | ((params: RowRenderParams<T>) => string | undefined);
@@ -539,9 +639,19 @@ export interface ColumnGroupViewport<T> {
539
639
  export interface ViewportData<T> {
540
640
  rows: Array<{
541
641
  id: RowId;
542
- data: T;
642
+ /** Raw row data for leaf rows; `undefined` for group rows. */
643
+ data: T | undefined;
644
+ /** Zero-based index of the row in the flattened output. */
543
645
  index: number;
646
+ /** Nesting depth (0 = outermost group, equal to groupBy length for leaves). */
647
+ level: number;
648
+ /** `'group'` for a group row, `'leaf'` for a data row. */
649
+ type: 'group' | 'leaf';
650
+ /** The group node when `type === 'group'`, otherwise `undefined`. */
651
+ group: GroupRowNode<T> | undefined;
652
+ /** Absolute vertical offset (px) of the row top. */
544
653
  offset: number;
654
+ /** Row height in pixels. */
545
655
  height?: number;
546
656
  }>;
547
657
  /** Scrollable (virtualized) leaf columns of the current horizontal window. */
@@ -634,19 +744,68 @@ export interface ViewportData<T> {
634
744
  totalWidth: number;
635
745
  totalHeight: number;
636
746
  }
637
- export interface GridState<T> {
747
+ /**
748
+ * Fundamental state owned directly by the Grid Core engine.
749
+ * Contains only rendering, geometry, viewport, and core overlay state.
750
+ *
751
+ * @api
752
+ */
753
+ export interface CoreGridState<T> {
638
754
  data: T[];
639
755
  columns: ColumnDef<T>[];
640
756
  viewport: ViewportState;
641
757
  rowHeight: number;
642
758
  rowOverscan: number;
643
759
  columnOverscan: number;
760
+ /** Cells currently flashed, keyed by `${rowId}:${columnId}` → expiry timestamp. */
761
+ flashedCells: Map<string, number>;
644
762
  /** Active overlay state — updated automatically by the grid's overlay manager. */
645
763
  overlay: OverlayState;
764
+ }
765
+ /**
766
+ * Open interface for plugin-contributed state slices.
767
+ * Plugins augment this interface via TypeScript module augmentation.
768
+ *
769
+ * @api
770
+ */
771
+ export interface PluginStateExtensions<T> {
772
+ /** Fields the rows are currently grouped by (empty = no grouping). */
773
+ groupBy?: string[];
774
+ /** Expanded state of groups, keyed by group id. */
775
+ expandedGroups?: Record<string, boolean>;
776
+ /** Group column render mode: `'single'` (one Group column) or `'perLevel'` (one column per group level). */
777
+ groupColumnMode?: "single" | "perLevel";
778
+ /** Header text for the Group column in `'single'` mode. */
779
+ groupColumnHeader?: string;
780
+ /** Whether group rows display the number of child rows. */
781
+ showChildCount?: boolean;
782
+ /** Custom renderer for group rows. */
783
+ groupRowRenderer?: GroupRowRenderer<T>;
646
784
  /**
647
785
  * Global quick filter query string. Applied across every column whose
648
786
  * `searchable` property is not `false`. Empty string means no quick filter.
649
787
  */
788
+ quickFilter?: string;
789
+ }
790
+ /**
791
+ * Unified grid state combining core state and modular plugin slices.
792
+ *
793
+ * @api
794
+ */
795
+ export interface GridState<T> extends CoreGridState<T>, PluginStateExtensions<T> {
796
+ /** Fields the rows are currently grouped by (empty = no grouping). */
797
+ groupBy: string[];
798
+ /** Expanded state of groups, keyed by group id. */
799
+ expandedGroups: Record<string, boolean>;
800
+ /** Group column render mode: `'single'` (one Group column) or `'perLevel'` (one column per group level). */
801
+ groupColumnMode: "single" | "perLevel";
802
+ /** Header text for the Group column in `'single'` mode. */
803
+ groupColumnHeader: string;
804
+ /** Whether group rows display the number of child rows. */
805
+ showChildCount: boolean;
806
+ /** Custom renderer for group rows. */
807
+ groupRowRenderer?: GroupRowRenderer<T>;
808
+ /** Global quick filter query string. */
650
809
  quickFilter: string;
651
810
  }
652
811
  export interface GridEvents<T> {
@@ -940,8 +1099,39 @@ export interface SlotMount<T> {
940
1099
  position: SlotPosition;
941
1100
  unmount(): void;
942
1101
  }
943
- export interface GridApi<T> {
1102
+ /**
1103
+ * Open interface for plugin-contributed API methods.
1104
+ * Plugins augment this interface via TypeScript module augmentation.
1105
+ *
1106
+ * @api
1107
+ */
1108
+ export interface PluginApiExtensions<T> {
1109
+ }
1110
+ /**
1111
+ * Base grid API surface provided by the core engine.
1112
+ *
1113
+ * @api
1114
+ */
1115
+ export interface CoreGridApi<T> {
944
1116
  getState(): GridState<T>;
1117
+ /**
1118
+ * Updates the grid state via partial patch or reducer.
1119
+ * @param updater - State slice patch or updater function.
1120
+ * @api
1121
+ */
1122
+ setState(updater: StateUpdater<GridState<T>>): void;
1123
+ /**
1124
+ * Registers methods dynamically contributed by plugins.
1125
+ * These methods are attached both to `api.methods` and directly to `api`.
1126
+ * @param methods - Methods to register.
1127
+ * @returns Cleanup callback to unregister the methods.
1128
+ * @api
1129
+ */
1130
+ registerMethods(methods: Record<string, unknown>): () => void;
1131
+ /** Extensible multi-stage data transformation pipeline. */
1132
+ readonly pipeline: DataPipeline<T>;
1133
+ /** Namespace for plugin-contributed methods. */
1134
+ readonly methods: Record<string, unknown>;
945
1135
  getScrollPosition(): ScrollPosition;
946
1136
  /**
947
1137
  * Requests a native scroll position update from the active adapter.
@@ -952,6 +1142,28 @@ export interface GridApi<T> {
952
1142
  getViewportData(): ViewportData<T>;
953
1143
  getColumnWidth(columnId: string): number | undefined;
954
1144
  getProcessedData(): T[];
1145
+ /**
1146
+ * Returns the active dataset consumed by the virtualizer and DOM pool.
1147
+ * When grouping or a custom row model is active, returns the transformed rows;
1148
+ * otherwise returns the processed data rows.
1149
+ * @api
1150
+ */
1151
+ getRows(): unknown[];
1152
+ /**
1153
+ * Returns the rows after core filtering but before plugin processors.
1154
+ * @api
1155
+ */
1156
+ getFilteredData(): T[];
1157
+ /** Returns the registered generic row hierarchy capability, if any. @api */
1158
+ getRowHierarchy(): RowHierarchy<T> | undefined;
1159
+ /**
1160
+ * Registers a generic row hierarchy capability.
1161
+ * Only one active hierarchy provider is supported per grid instance.
1162
+ * @param hierarchy - The active row hierarchy implementation.
1163
+ * @returns Cleanup callback to unregister the provider.
1164
+ * @api
1165
+ */
1166
+ registerRowHierarchy(hierarchy: RowHierarchy<T>): () => void;
955
1167
  getRowId(row: T, index: number): RowId;
956
1168
  /**
957
1169
  * Resolves the normalized horizontal span of a single body cell.
@@ -1177,4 +1389,10 @@ export interface GridApi<T> {
1177
1389
  destroy(): void;
1178
1390
  isDestroyed(): boolean;
1179
1391
  }
1180
- export {};
1392
+ /**
1393
+ * Complete grid API surface combining core methods and modular plugin extensions.
1394
+ *
1395
+ * @api
1396
+ */
1397
+ export interface GridApi<T> extends CoreGridApi<T>, PluginApiExtensions<T> {
1398
+ }
@@ -463,7 +463,13 @@ export class Virtualizer {
463
463
  getColumnRange(columns, scrollLeft, viewportWidth, offsets) {
464
464
  const computed = offsets ?? this.getColumnOffsets(columns, viewportWidth);
465
465
  const start = this.findStart(computed, scrollLeft);
466
- const end = this.findEnd(computed, scrollLeft + viewportWidth);
466
+ // When the viewport width is unknown (0 on first paint), we cannot
467
+ // determine how many columns fit. Return all columns so none are
468
+ // missing from the initial render — they will be resized correctly
469
+ // once measureViewport() sets the real width.
470
+ const end = viewportWidth === 0
471
+ ? columns.length
472
+ : this.findEnd(computed, scrollLeft + viewportWidth);
467
473
  return {
468
474
  start: Math.max(0, start - this.options.columnOverscan),
469
475
  end: Math.min(columns.length, end + 1 + this.options.columnOverscan),
package/package.json CHANGED
@@ -1,44 +1,44 @@
1
1
  {
2
- "name": "@omnigrid/core",
3
- "version": "0.1.23",
4
- "description": "Framework-agnostic core engine for OmniGrid",
5
- "keywords": [
6
- "omnigrid",
7
- "grid",
8
- "table",
9
- "datatable",
10
- "core",
11
- "typescript"
12
- ],
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/KRZK-Apps/omnigrid.git",
16
- "directory": "core"
17
- },
18
- "homepage": "https://github.com/KRZK-Apps/omnigrid/tree/main/core#readme",
19
- "bugs": {
20
- "url": "https://github.com/KRZK-Apps/omnigrid/issues"
21
- },
22
- "license": "MIT",
23
- "type": "module",
24
- "main": "dist/index.js",
25
- "types": "dist/index.d.ts",
26
- "exports": {
27
- ".": {
28
- "types": "./dist/index.d.ts",
29
- "import": "./dist/index.js"
2
+ "name": "@omnigrid/core",
3
+ "version": "0.1.25",
4
+ "description": "Framework-agnostic core engine for OmniGrid",
5
+ "keywords": [
6
+ "omnigrid",
7
+ "grid",
8
+ "table",
9
+ "datatable",
10
+ "core",
11
+ "typescript"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/KRZK-Apps/omnigrid.git",
16
+ "directory": "core"
17
+ },
18
+ "homepage": "https://github.com/KRZK-Apps/omnigrid/tree/main/core#readme",
19
+ "bugs": {
20
+ "url": "https://github.com/KRZK-Apps/omnigrid/issues"
21
+ },
22
+ "license": "MIT",
23
+ "type": "module",
24
+ "main": "dist/index.js",
25
+ "types": "dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js"
30
+ }
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "scripts": {
36
+ "build": "npx tsc -p tsconfig.json",
37
+ "lint": "npx tsc --noEmit -p tsconfig.json",
38
+ "test": "vitest run",
39
+ "prepublishOnly": "npm run build"
40
+ },
41
+ "devDependencies": {
42
+ "vitest": "^5.0.2"
30
43
  }
31
- },
32
- "files": [
33
- "dist"
34
- ],
35
- "scripts": {
36
- "build": "npx tsc -p tsconfig.json",
37
- "lint": "npx tsc --noEmit -p tsconfig.json",
38
- "test": "vitest run",
39
- "prepublishOnly": "npm run build"
40
- },
41
- "devDependencies": {
42
- "vitest": "^5.0.2"
43
- }
44
44
  }