@omnigrid/core 0.1.24 → 0.1.26

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
  *
@@ -110,12 +220,19 @@ export interface RowSpanLayout {
110
220
  * Context passed to every row-level callback (`getRowStyle`, `getRowClass`,
111
221
  * `rowClassRules`, `checkboxDisabled`, ...).
112
222
  *
113
- * Alias of `RowNode`: the stable row id, the zero-based index in the
114
- * processed dataset, and the raw row data object.
223
+ * `rowType` distinguishes ordinary data rows from synthetic group rows.
224
+ * Group rows do not have raw row data.
115
225
  *
116
226
  * @api
117
227
  */
118
- export type RowRenderParams<T> = RowNode<T>;
228
+ export type RowRenderParams<T> = (RowNode<T> & {
229
+ rowType: "leaf";
230
+ }) | {
231
+ id: RowId;
232
+ index: number;
233
+ rowType: "group";
234
+ data?: never;
235
+ };
119
236
  export interface RowStyle {
120
237
  [property: string]: string | number | undefined;
121
238
  }
@@ -274,43 +391,19 @@ export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
274
391
  maxWidth?: number;
275
392
  /** Whether this column can be sorted. */
276
393
  sortable?: boolean;
277
- /**
278
- * Nature of the values in this column. When omitted, the filtering plugin
279
- * infers it by sampling the data.
280
- */
281
- dataType?: ColumnDataType;
282
- /**
283
- * Kind of filter UI rendered for this column. When omitted, it is derived
284
- * from `dataType` (and, failing that, from the sampled data).
285
- */
286
- filterType?: ColumnFilterType;
287
- /**
288
- * Identifier of a custom filter registered with the filtering plugin.
289
- * Required when `filterType` is `"custom"`.
290
- */
291
- filterTypeId?: string;
292
- /**
293
- * Whether this column offers a filter menu. Set to `false` to opt the column out of
294
- * filtering UI (the header filter icon is hidden).
295
- * @default true
296
- */
297
- filterable?: boolean;
298
- /**
299
- * Custom subset of operators allowed for this column's filter menu.
300
- */
301
- allowedOperators?: FilterOperator[];
302
- /**
303
- * Fixed option list used by the `"set"` filter. When provided, the column
304
- * defaults to `filterType: "set"` unless `filterType` is set explicitly.
305
- */
306
- filterOptions?: Array<{
307
- label: string;
308
- value: any;
309
- }>;
310
394
  /** Horizontal alignment of cell content. */
311
395
  align?: CellAlign;
312
396
  /** Enables automatic text wrapping instead of ellipsis truncation. @default false @api */
313
397
  wrapText?: boolean;
398
+ /**
399
+ * Controls whether the cell keeps the theme's internal padding or removes it
400
+ * so custom content can fill the cell.
401
+ * - `"normal"` (default): preserves the theme padding.
402
+ * - `"flush"`: removes the cell padding.
403
+ * @default "normal"
404
+ * @api
405
+ */
406
+ cellLayout?: "normal" | "flush";
314
407
  /** Initial sort direction used by SortingPlugin. */
315
408
  sortState?: SortDirection;
316
409
  /** 1-based sort priority, set only while multiple columns are sorted. */
@@ -553,9 +646,19 @@ export interface ColumnGroupViewport<T> {
553
646
  export interface ViewportData<T> {
554
647
  rows: Array<{
555
648
  id: RowId;
556
- data: T;
649
+ /** Raw row data for leaf rows; `undefined` for group rows. */
650
+ data: T | undefined;
651
+ /** Zero-based index of the row in the flattened output. */
557
652
  index: number;
653
+ /** Nesting depth (0 = outermost group, equal to groupBy length for leaves). */
654
+ level: number;
655
+ /** `'group'` for a group row, `'leaf'` for a data row. */
656
+ type: 'group' | 'leaf';
657
+ /** The group node when `type === 'group'`, otherwise `undefined`. */
658
+ group: GroupRowNode<T> | undefined;
659
+ /** Absolute vertical offset (px) of the row top. */
558
660
  offset: number;
661
+ /** Row height in pixels. */
559
662
  height?: number;
560
663
  }>;
561
664
  /** Scrollable (virtualized) leaf columns of the current horizontal window. */
@@ -648,7 +751,13 @@ export interface ViewportData<T> {
648
751
  totalWidth: number;
649
752
  totalHeight: number;
650
753
  }
651
- export interface GridState<T> {
754
+ /**
755
+ * Fundamental state owned directly by the Grid Core engine.
756
+ * Contains only rendering, geometry, viewport, and core overlay state.
757
+ *
758
+ * @api
759
+ */
760
+ export interface CoreGridState<T> {
652
761
  data: T[];
653
762
  columns: ColumnDef<T>[];
654
763
  viewport: ViewportState;
@@ -659,10 +768,51 @@ export interface GridState<T> {
659
768
  flashedCells: Map<string, number>;
660
769
  /** Active overlay state — updated automatically by the grid's overlay manager. */
661
770
  overlay: OverlayState;
771
+ }
772
+ /**
773
+ * Open interface for plugin-contributed state slices.
774
+ * Plugins augment this interface via TypeScript module augmentation.
775
+ *
776
+ * @api
777
+ */
778
+ export interface PluginStateExtensions<T> {
779
+ /** Fields the rows are currently grouped by (empty = no grouping). */
780
+ groupBy?: string[];
781
+ /** Expanded state of groups, keyed by group id. */
782
+ expandedGroups?: Record<string, boolean>;
783
+ /** Group column render mode: `'single'` (one Group column) or `'perLevel'` (one column per group level). */
784
+ groupColumnMode?: "single" | "perLevel";
785
+ /** Header text for the Group column in `'single'` mode. */
786
+ groupColumnHeader?: string;
787
+ /** Whether group rows display the number of child rows. */
788
+ showChildCount?: boolean;
789
+ /** Custom renderer for group rows. */
790
+ groupRowRenderer?: GroupRowRenderer<T>;
662
791
  /**
663
792
  * Global quick filter query string. Applied across every column whose
664
793
  * `searchable` property is not `false`. Empty string means no quick filter.
665
794
  */
795
+ quickFilter?: string;
796
+ }
797
+ /**
798
+ * Unified grid state combining core state and modular plugin slices.
799
+ *
800
+ * @api
801
+ */
802
+ export interface GridState<T> extends CoreGridState<T>, PluginStateExtensions<T> {
803
+ /** Fields the rows are currently grouped by (empty = no grouping). */
804
+ groupBy: string[];
805
+ /** Expanded state of groups, keyed by group id. */
806
+ expandedGroups: Record<string, boolean>;
807
+ /** Group column render mode: `'single'` (one Group column) or `'perLevel'` (one column per group level). */
808
+ groupColumnMode: "single" | "perLevel";
809
+ /** Header text for the Group column in `'single'` mode. */
810
+ groupColumnHeader: string;
811
+ /** Whether group rows display the number of child rows. */
812
+ showChildCount: boolean;
813
+ /** Custom renderer for group rows. */
814
+ groupRowRenderer?: GroupRowRenderer<T>;
815
+ /** Global quick filter query string. */
666
816
  quickFilter: string;
667
817
  }
668
818
  export interface GridEvents<T> {
@@ -704,6 +854,10 @@ export interface PooledRow<T> {
704
854
  index: number;
705
855
  rowId: RowId;
706
856
  data: T;
857
+ /** Row kind; omitted only by legacy custom DOM-pool bindings. */
858
+ type?: "group" | "leaf";
859
+ /** Group metadata for synthetic group rows. */
860
+ group?: GroupRowNode<T>;
707
861
  offsetY: number;
708
862
  height: number;
709
863
  /** Pixel width of the row (sum of all column widths) — used to size the row node. */
@@ -808,13 +962,13 @@ export interface DomPoolUpdate<T> {
808
962
  }>;
809
963
  recycled: RowHost<T>[];
810
964
  }
811
- export interface RowClickEvent<T> extends RowRenderParams<T> {
965
+ export type RowClickEvent<T> = RowRenderParams<T> & {
812
966
  ctrlKey: boolean;
813
967
  shiftKey: boolean;
814
- }
815
- export interface RowHoverEvent<T> extends RowRenderParams<T> {
968
+ };
969
+ export type RowHoverEvent<T> = RowRenderParams<T> & {
816
970
  hovered: boolean;
817
- }
971
+ };
818
972
  export interface GridPlugin<T> {
819
973
  name: string;
820
974
  register(api: GridApi<T>): void | (() => void);
@@ -956,8 +1110,39 @@ export interface SlotMount<T> {
956
1110
  position: SlotPosition;
957
1111
  unmount(): void;
958
1112
  }
959
- export interface GridApi<T> {
1113
+ /**
1114
+ * Open interface for plugin-contributed API methods.
1115
+ * Plugins augment this interface via TypeScript module augmentation.
1116
+ *
1117
+ * @api
1118
+ */
1119
+ export interface PluginApiExtensions<T> {
1120
+ }
1121
+ /**
1122
+ * Base grid API surface provided by the core engine.
1123
+ *
1124
+ * @api
1125
+ */
1126
+ export interface CoreGridApi<T> {
960
1127
  getState(): GridState<T>;
1128
+ /**
1129
+ * Updates the grid state via partial patch or reducer.
1130
+ * @param updater - State slice patch or updater function.
1131
+ * @api
1132
+ */
1133
+ setState(updater: StateUpdater<GridState<T>>): void;
1134
+ /**
1135
+ * Registers methods dynamically contributed by plugins.
1136
+ * These methods are attached both to `api.methods` and directly to `api`.
1137
+ * @param methods - Methods to register.
1138
+ * @returns Cleanup callback to unregister the methods.
1139
+ * @api
1140
+ */
1141
+ registerMethods(methods: Record<string, unknown>): () => void;
1142
+ /** Extensible multi-stage data transformation pipeline. */
1143
+ readonly pipeline: DataPipeline<T>;
1144
+ /** Namespace for plugin-contributed methods. */
1145
+ readonly methods: Record<string, unknown>;
961
1146
  getScrollPosition(): ScrollPosition;
962
1147
  /**
963
1148
  * Requests a native scroll position update from the active adapter.
@@ -968,6 +1153,28 @@ export interface GridApi<T> {
968
1153
  getViewportData(): ViewportData<T>;
969
1154
  getColumnWidth(columnId: string): number | undefined;
970
1155
  getProcessedData(): T[];
1156
+ /**
1157
+ * Returns the active dataset consumed by the virtualizer and DOM pool.
1158
+ * When grouping or a custom row model is active, returns the transformed rows;
1159
+ * otherwise returns the processed data rows.
1160
+ * @api
1161
+ */
1162
+ getRows(): unknown[];
1163
+ /**
1164
+ * Returns the rows after core filtering but before plugin processors.
1165
+ * @api
1166
+ */
1167
+ getFilteredData(): T[];
1168
+ /** Returns the registered generic row hierarchy capability, if any. @api */
1169
+ getRowHierarchy(): RowHierarchy<T> | undefined;
1170
+ /**
1171
+ * Registers a generic row hierarchy capability.
1172
+ * Only one active hierarchy provider is supported per grid instance.
1173
+ * @param hierarchy - The active row hierarchy implementation.
1174
+ * @returns Cleanup callback to unregister the provider.
1175
+ * @api
1176
+ */
1177
+ registerRowHierarchy(hierarchy: RowHierarchy<T>): () => void;
971
1178
  getRowId(row: T, index: number): RowId;
972
1179
  /**
973
1180
  * Resolves the normalized horizontal span of a single body cell.
@@ -1193,4 +1400,10 @@ export interface GridApi<T> {
1193
1400
  destroy(): void;
1194
1401
  isDestroyed(): boolean;
1195
1402
  }
1196
- export {};
1403
+ /**
1404
+ * Complete grid API surface combining core methods and modular plugin extensions.
1405
+ *
1406
+ * @api
1407
+ */
1408
+ export interface GridApi<T> extends CoreGridApi<T>, PluginApiExtensions<T> {
1409
+ }
package/package.json CHANGED
@@ -1,44 +1,44 @@
1
1
  {
2
- "name": "@omnigrid/core",
3
- "version": "0.1.24",
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.26",
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
  }