@omnigrid/core 0.1.34 → 0.1.36

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/README.md CHANGED
@@ -30,7 +30,9 @@ adapter-native scroll adjustment without moving scroll coordinates into the Stor
30
30
  ```ts
31
31
  interface GridOptions<T> {
32
32
  data?: T[] | null; // row data; null/omitted means initial loading
33
- columns: ColumnDef<T>[]; // required
33
+ columns?: ColumnDef<T>[]; // inferred from the first row when omitted
34
+ autoColumnHeaderMode?: "as-is" | "title-case"; // default: "as-is"
35
+ getColumnHeader?: (field: string) => string; // custom formatter; takes precedence over autoColumnHeaderMode
34
36
  getRowId?: (row: T, index: number) => RowId; // default: index-based
35
37
  rowHeight?: number; // fixed px row height; default 32 (offset math is O(1))
36
38
  rowOverscan?: number; // extra rows above/below viewport; default 5
@@ -48,6 +50,14 @@ interface GridOptions<T> {
48
50
  }
49
51
  ```
50
52
 
53
+ When `columns` is omitted, the core infers leaf columns from the first row.
54
+ If the initial dataset is empty or pending, it waits for the first non-empty
55
+ `setData` or `appendData`. The inferred schema stays fixed afterward; call
56
+ `setColumns` when the schema changes. An explicit `columns: []` disables
57
+ inference. Headers default to the field key; set `autoColumnHeaderMode` to
58
+ `"title-case"` to split camel-case keys into capitalized words, or provide
59
+ `getColumnHeader` for a custom formatter.
60
+
51
61
  Row callbacks receive `params.rowType` (`"leaf"` or `"group"`). Group rows are synthetic and have no `data`; checking `rowType` narrows the callback parameters.
52
62
 
53
63
  ### `ColumnDef<T>`
@@ -254,7 +264,7 @@ In a UI framework, use the adapter — e.g. `@omnigrid/react`:
254
264
  data={rows}
255
265
  getRowId={(row) => row.id}
256
266
  plugins={plugins}
257
- style={{ height: 480 }}
267
+ height={480}
258
268
  />
259
269
  ```
260
270
 
package/dist/columns.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { CellSpanningParams, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, DefaultColumnDef, RowId, RowSpanLayout } from "./types.js";
1
+ import type { AutoColumnHeaderMode, CellSpanningParams, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, DefaultColumnDef, RowId, RowSpanLayout } from "./types.js";
2
2
  /**
3
3
  * Runtime narrowing: does the column definition describe a GROUP
4
4
  * (it carries `children`) rather than a leaf column?
@@ -6,6 +6,16 @@ import type { CellSpanningParams, ColumnDef, ColumnGroupDef, ColumnGroupViewport
6
6
  export declare function isColumnGroup<T>(column: ColumnDef<T>): column is ColumnGroupDef<T>;
7
7
  /** Inverse of `isColumnGroup` — handy for filters over the flat working set. */
8
8
  export declare function isColumnLeaf<T>(column: ColumnDef<T>): column is ColumnLeafDef<T>;
9
+ /**
10
+ * Infers flat leaf columns from the own enumerable string keys of the first data row.
11
+ *
12
+ * @param data - Rows used to infer the columns.
13
+ * @param getColumnHeader - Optional formatter for each inferred field key.
14
+ * @param autoColumnHeaderMode - Built-in formatting mode used when no custom formatter is provided.
15
+ * @returns Inferred columns, or an empty array when no object row is available.
16
+ * @api
17
+ */
18
+ export declare function inferColumns<T>(data: T[] | null | undefined, getColumnHeader?: (field: string) => string, autoColumnHeaderMode?: AutoColumnHeaderMode): ColumnLeafDef<T>[];
9
19
  /**
10
20
  * Applies shared defaults to leaf columns while preserving column-level overrides.
11
21
  *
package/dist/columns.js CHANGED
@@ -9,6 +9,35 @@ export function isColumnGroup(column) {
9
9
  export function isColumnLeaf(column) {
10
10
  return !isColumnGroup(column);
11
11
  }
12
+ /**
13
+ * Infers flat leaf columns from the own enumerable string keys of the first data row.
14
+ *
15
+ * @param data - Rows used to infer the columns.
16
+ * @param getColumnHeader - Optional formatter for each inferred field key.
17
+ * @param autoColumnHeaderMode - Built-in formatting mode used when no custom formatter is provided.
18
+ * @returns Inferred columns, or an empty array when no object row is available.
19
+ * @api
20
+ */
21
+ export function inferColumns(data, getColumnHeader, autoColumnHeaderMode = "as-is") {
22
+ const firstRow = data?.[0];
23
+ if (firstRow === null || typeof firstRow !== "object")
24
+ return [];
25
+ return Object.keys(firstRow).map((field) => {
26
+ const header = getColumnHeader
27
+ ? getColumnHeader(field)
28
+ : autoColumnHeaderMode === "title-case"
29
+ ? formatAutoColumnHeader(field)
30
+ : field;
31
+ return { id: field, field, header };
32
+ });
33
+ }
34
+ function formatAutoColumnHeader(field) {
35
+ const words = field
36
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
37
+ .replace(/([A-Z])([A-Z][a-z])/g, "$1 $2")
38
+ .split(" ");
39
+ return words.map((word) => `${word.charAt(0).toUpperCase()}${word.slice(1).toLowerCase()}`).join(" ");
40
+ }
12
41
  /**
13
42
  * Applies shared defaults to leaf columns while preserving column-level overrides.
14
43
  *
package/dist/grid.d.ts CHANGED
@@ -33,6 +33,8 @@ export declare class Grid<T> implements GridApi<T> {
33
33
  private readonly popups;
34
34
  private revision;
35
35
  private destroyed;
36
+ /** Guards the coalesced `stateChange` microtask so one synchronous tick emits at most one event. */
37
+ private stateChangeScheduled;
36
38
  /**
37
39
  * Overlay management state:
38
40
  * - `loading`: whether the grid is fetching data (set via setLoading / options.loading)
@@ -47,6 +49,9 @@ export declare class Grid<T> implements GridApi<T> {
47
49
  private loadError;
48
50
  private overlayState;
49
51
  private overlayManual;
52
+ private autoColumnsPending;
53
+ private readonly autoColumnHeaderMode;
54
+ private readonly getColumnHeader;
50
55
  /** Grid-level `wrapText` flag — applied to every column without an explicit one. */
51
56
  private wrapTextAll;
52
57
  /** Normalized cell flash configuration. `false` when disabled. */
@@ -218,6 +223,12 @@ export declare class Grid<T> implements GridApi<T> {
218
223
  setGroupRowRenderer(): void;
219
224
  getFilteredData(): T[];
220
225
  private static cloneFilterModel;
226
+ /**
227
+ * Shallow structural comparison of two filter models. Conditions are
228
+ * compared by operator and operands so an equivalent re-applied model is
229
+ * detected without allocating a canonical string form.
230
+ */
231
+ private static filterModelsEqual;
221
232
  setFilterModel(model: FilterModel): void;
222
233
  getFilterModel(): FilterModel;
223
234
  setColumnFilter(field: string, condition: FilterCondition | null): void;
@@ -284,6 +295,7 @@ export declare class Grid<T> implements GridApi<T> {
284
295
  * @api
285
296
  */
286
297
  getRowHeight(rowIndex: number): number;
298
+ private resolvePendingAutoColumns;
287
299
  setData(data: T[] | null | undefined): void;
288
300
  /**
289
301
  * Chunk-append API for incremental data loading (infinite scroll, live
@@ -310,6 +322,16 @@ export declare class Grid<T> implements GridApi<T> {
310
322
  */
311
323
  applyTransaction(transaction: RowTransaction<T>): TransactionResult<T>;
312
324
  setViewport(viewport: Partial<ViewportState>): void;
325
+ /**
326
+ * Coalesces `stateChange` into a single microtask per synchronous tick.
327
+ *
328
+ * A burst of synchronous state updates (e.g. a page change that writes both
329
+ * the pagination slice and the dataset) collapses into ONE `stateChange`
330
+ * carrying the final snapshot, instead of a stream of intermediate events.
331
+ * Domain events (`dataChange`, `viewportChange`, `overlayChange`) stay
332
+ * synchronous and precise.
333
+ */
334
+ private scheduleStateChange;
313
335
  /**
314
336
  * Repaints the current viewport: notifies Store subscribers that
315
337
  * visible rows and row classes (rowClassRules) may need rebinding
package/dist/grid.js CHANGED
@@ -1,4 +1,4 @@
1
- import { applyDefaultColumnDef, applyWrapText, flattenColumns, getCellValue, getColumnGroups, getRowSpans, resolveColSpan, } from "./columns.js";
1
+ import { applyDefaultColumnDef, applyWrapText, flattenColumns, getCellValue, getColumnGroups, getRowSpans, inferColumns, isColumnGroup, resolveColSpan, } from "./columns.js";
2
2
  import { EventBus } from "./events.js";
3
3
  import { applyFilterModel, applyQuickFilter, isActiveCondition } from "./filtering.js";
4
4
  import { buildGroupTree, computeAggregations, flattenTree } from "./groupingPipeline.js";
@@ -31,10 +31,13 @@ export class Grid {
31
31
  this.popups = new PopupManager((popup) => this.events.emit("popupChange", popup));
32
32
  this.revision = 0;
33
33
  this.destroyed = false;
34
+ /** Guards the coalesced `stateChange` microtask so one synchronous tick emits at most one event. */
35
+ this.stateChangeScheduled = false;
34
36
  this.loading = false;
35
37
  this.hasData = true;
36
38
  this.overlayState = { type: null };
37
39
  this.overlayManual = false;
40
+ this.autoColumnsPending = false;
38
41
  /** Normalized cell flash configuration. `false` when disabled. */
39
42
  this.cellFlash = false;
40
43
  /** Cells currently flashed: key `${rowId}:${columnId}` → expiry timestamp. */
@@ -48,9 +51,13 @@ export class Grid {
48
51
  * (width / height) still go through the Store and DO trigger re-renders.
49
52
  */
50
53
  this.scrollPosition = { scrollTop: 0, scrollLeft: 0 };
54
+ this.autoColumnsPending = options.columns === undefined && (options.data?.length ?? 0) === 0;
55
+ this.autoColumnHeaderMode = options.autoColumnHeaderMode;
56
+ this.getColumnHeader = options.getColumnHeader;
51
57
  const state = {
52
58
  data: options.data ?? [],
53
- columns: applyWrapText(applyDefaultColumnDef(options.columns, options.defaultColumnDef), options.wrapText),
59
+ columns: applyWrapText(applyDefaultColumnDef(options.columns ??
60
+ inferColumns(options.data, options.getColumnHeader, options.autoColumnHeaderMode), options.defaultColumnDef), options.wrapText),
54
61
  viewport: { width: 0, height: 0, scrollTop: 0, scrollLeft: 0 },
55
62
  rowHeight: options.rowHeight ?? 32,
56
63
  groupBy: [],
@@ -96,7 +103,7 @@ export class Grid {
96
103
  });
97
104
  this.slots = new SlotManager({
98
105
  onChange: (slot, mounts) => {
99
- this.store.setState({});
106
+ this.store.setState({}, { force: true });
100
107
  this.events.emit("slotsChange", { slot, mounts });
101
108
  },
102
109
  });
@@ -107,7 +114,7 @@ export class Grid {
107
114
  if (!this.destroyed)
108
115
  this.recomputeOverlay();
109
116
  });
110
- this.store.subscribe(() => this.events.emit("stateChange", this.store.getState()));
117
+ this.store.subscribe(() => this.scheduleStateChange());
111
118
  options.plugins?.forEach((plugin) => this.registerPlugin(plugin));
112
119
  this.recomputeOverlay();
113
120
  }
@@ -678,6 +685,40 @@ export class Grid {
678
685
  }
679
686
  return clone;
680
687
  }
688
+ /**
689
+ * Shallow structural comparison of two filter models. Conditions are
690
+ * compared by operator and operands so an equivalent re-applied model is
691
+ * detected without allocating a canonical string form.
692
+ */
693
+ static filterModelsEqual(left, right) {
694
+ const leftKeys = Object.keys(left);
695
+ const rightKeys = Object.keys(right);
696
+ if (leftKeys.length !== rightKeys.length)
697
+ return false;
698
+ for (const key of leftKeys) {
699
+ const a = left[key];
700
+ const b = right[key];
701
+ if (!a || !b)
702
+ return false;
703
+ if (a.logic !== b.logic)
704
+ return false;
705
+ if (a.conditions.length !== b.conditions.length)
706
+ return false;
707
+ for (let index = 0; index < a.conditions.length; index += 1) {
708
+ const ca = a.conditions[index];
709
+ const cb = b.conditions[index];
710
+ if (ca.operator !== cb.operator)
711
+ return false;
712
+ if (!Object.is(ca.value, cb.value))
713
+ return false;
714
+ if (!Object.is(ca.valueTo, cb.valueTo))
715
+ return false;
716
+ if (!Object.is(ca.caseSensitive, cb.caseSensitive))
717
+ return false;
718
+ }
719
+ }
720
+ return true;
721
+ }
681
722
  setFilterModel(model) {
682
723
  this.assertActive();
683
724
  const next = {};
@@ -685,6 +726,10 @@ export class Grid {
685
726
  if (entry.conditions.length > 0)
686
727
  next[key] = entry;
687
728
  }
729
+ // Repeated writes of an equivalent model (e.g. a controlled prop
730
+ // re-applied on every render) must not trigger stateChange/filterChanged.
731
+ if (Grid.filterModelsEqual(this.filterModel, next))
732
+ return;
688
733
  this.filterModel = next;
689
734
  this.filteredDataCache = null;
690
735
  this.processedDataCache = null;
@@ -692,7 +737,8 @@ export class Grid {
692
737
  this.groupedRowsRevision = -1;
693
738
  this.revision += 1;
694
739
  this.scrollTo({ scrollTop: 0 });
695
- this.store.setState({});
740
+ // The filter model lives outside the Store, so force a repaint notification.
741
+ this.store.setState({}, { force: true });
696
742
  this.recomputeOverlay();
697
743
  this.events.emit("filterChanged", this.getFilterModel());
698
744
  }
@@ -808,7 +854,7 @@ export class Grid {
808
854
  if (this.virtualizer.getRowHeight(rowIndex) === previousHeight)
809
855
  return 0;
810
856
  if (options?.notify !== false)
811
- this.store.setState({});
857
+ this.store.setState({}, { force: true });
812
858
  if (correction !== 0 && options?.anchor !== false) {
813
859
  this.scrollTo({ scrollTop: scrollTop + correction });
814
860
  }
@@ -828,7 +874,7 @@ export class Grid {
828
874
  const scrollTop = this.scrollPosition.scrollTop;
829
875
  const correction = this.virtualizer.resetRowHeight(rowIndex, scrollTop, count);
830
876
  if (options?.notify !== false)
831
- this.store.setState({});
877
+ this.store.setState({}, { force: true });
832
878
  if (correction !== 0 && options?.anchor !== false) {
833
879
  this.scrollTo({ scrollTop: scrollTop + correction });
834
880
  }
@@ -839,7 +885,7 @@ export class Grid {
839
885
  this.assertActive();
840
886
  this.virtualizer.resetAllRowHeights();
841
887
  this.revision += 1;
842
- this.store.setState({});
888
+ this.store.setState({}, { force: true });
843
889
  }
844
890
  /**
845
891
  * Returns the absolute vertical offset (px) of the top of a row,
@@ -860,18 +906,54 @@ export class Grid {
860
906
  getRowHeight(rowIndex) {
861
907
  return this.virtualizer.getRowHeight(rowIndex);
862
908
  }
909
+ resolvePendingAutoColumns(data) {
910
+ if (!this.autoColumnsPending || data.length === 0)
911
+ return undefined;
912
+ const inferredColumns = inferColumns(data, this.getColumnHeader, this.autoColumnHeaderMode);
913
+ const inferredById = new Map(inferredColumns.map((column) => [column.id, column]));
914
+ const currentColumns = this.store.getState().columns;
915
+ const currentIds = new Set();
916
+ const mergedColumns = [];
917
+ currentColumns.forEach((currentColumn) => {
918
+ const inferredColumn = inferredById.get(currentColumn.id);
919
+ if (inferredColumn && !isColumnGroup(currentColumn)) {
920
+ mergedColumns.push({
921
+ ...inferredColumn,
922
+ ...currentColumn,
923
+ id: inferredColumn.id,
924
+ field: inferredColumn.field,
925
+ header: inferredColumn.header,
926
+ });
927
+ }
928
+ else {
929
+ mergedColumns.push(currentColumn);
930
+ }
931
+ currentIds.add(currentColumn.id);
932
+ });
933
+ inferredColumns.forEach((column) => {
934
+ if (!currentIds.has(column.id))
935
+ mergedColumns.push(column);
936
+ });
937
+ this.autoColumnsPending = false;
938
+ return mergedColumns;
939
+ }
863
940
  setData(data) {
864
941
  this.assertActive();
865
942
  this.loadError = undefined;
866
943
  this.hasData = data !== undefined && data !== null;
867
944
  const nextData = data ?? [];
945
+ const inferredColumns = this.resolvePendingAutoColumns(nextData);
868
946
  this.filteredDataCache = null;
869
947
  this.processedDataCache = null;
870
948
  this.groupedRowsCache = null;
871
949
  this.groupedRowsRevision = -1;
872
950
  this.virtualizer.resetAllRowHeights();
873
951
  this.revision += 1;
874
- this.store.setState({ data: nextData });
952
+ const nextState = { data: nextData };
953
+ if (inferredColumns !== undefined) {
954
+ nextState.columns = applyWrapText(applyDefaultColumnDef(inferredColumns, this.defaultColumnDef), this.wrapTextAll);
955
+ }
956
+ this.store.setState(nextState);
875
957
  this.events.emit("dataChange", nextData);
876
958
  this.recomputeOverlay();
877
959
  }
@@ -888,13 +970,18 @@ export class Grid {
888
970
  return;
889
971
  const currentData = this.store.getState().data;
890
972
  const nextData = [...currentData, ...rows];
973
+ const inferredColumns = this.resolvePendingAutoColumns(nextData);
891
974
  this.hasData = true;
892
975
  this.filteredDataCache = null;
893
976
  this.processedDataCache = null;
894
977
  this.groupedRowsCache = null;
895
978
  this.groupedRowsRevision = -1;
896
979
  this.revision += 1;
897
- this.store.setState({ data: nextData });
980
+ const nextState = { data: nextData };
981
+ if (inferredColumns !== undefined) {
982
+ nextState.columns = applyWrapText(applyDefaultColumnDef(inferredColumns, this.defaultColumnDef), this.wrapTextAll);
983
+ }
984
+ this.store.setState(nextState);
898
985
  this.events.emit("dataChange", nextData);
899
986
  this.recomputeOverlay();
900
987
  }
@@ -1072,6 +1159,26 @@ export class Grid {
1072
1159
  }
1073
1160
  this.events.emit("viewportChange", nextViewport);
1074
1161
  }
1162
+ /**
1163
+ * Coalesces `stateChange` into a single microtask per synchronous tick.
1164
+ *
1165
+ * A burst of synchronous state updates (e.g. a page change that writes both
1166
+ * the pagination slice and the dataset) collapses into ONE `stateChange`
1167
+ * carrying the final snapshot, instead of a stream of intermediate events.
1168
+ * Domain events (`dataChange`, `viewportChange`, `overlayChange`) stay
1169
+ * synchronous and precise.
1170
+ */
1171
+ scheduleStateChange() {
1172
+ if (this.stateChangeScheduled)
1173
+ return;
1174
+ this.stateChangeScheduled = true;
1175
+ queueMicrotask(() => {
1176
+ this.stateChangeScheduled = false;
1177
+ if (this.destroyed)
1178
+ return;
1179
+ this.events.emit("stateChange", this.store.getState());
1180
+ });
1181
+ }
1075
1182
  /**
1076
1183
  * Repaints the current viewport: notifies Store subscribers that
1077
1184
  * visible rows and row classes (rowClassRules) may need rebinding
@@ -1081,7 +1188,7 @@ export class Grid {
1081
1188
  refresh() {
1082
1189
  this.assertActive();
1083
1190
  this.revision += 1;
1084
- this.store.setState({});
1191
+ this.store.setState({}, { force: true });
1085
1192
  }
1086
1193
  /**
1087
1194
  * Replaces the column definitions and optionally updates shared leaf-column defaults.
@@ -1171,13 +1278,13 @@ export class Grid {
1171
1278
  this.assertActive();
1172
1279
  const registered = { ...extension };
1173
1280
  this.headerExtensions.set(extension.id, registered);
1174
- this.store.setState({});
1281
+ this.store.setState({}, { force: true });
1175
1282
  return () => {
1176
1283
  if (this.headerExtensions.get(extension.id) !== registered)
1177
1284
  return;
1178
1285
  this.headerExtensions.delete(extension.id);
1179
1286
  if (!this.destroyed)
1180
- this.store.setState({});
1287
+ this.store.setState({}, { force: true });
1181
1288
  };
1182
1289
  }
1183
1290
  /**
package/dist/index.d.ts CHANGED
@@ -7,13 +7,13 @@ export { Grid } from "./grid.js";
7
7
  export { Grid as GridCore } from "./grid.js";
8
8
  export { SlotManager } from "./slots.js";
9
9
  export { Store } from "./store.js";
10
- export type { StateUpdater } from "./store.js";
10
+ export type { SetStateOptions, StateUpdater } from "./store.js";
11
11
  export { DataPipeline, PIPELINE_STAGE_ORDER } from "./pipeline.js";
12
12
  export type { PipelineProcessor, PipelineStage } from "./pipeline.js";
13
13
  export { applyFilterModel, applyQuickFilter, isActiveCondition, isFilterModelActive, matchesColumnFilter, } from "./filtering.js";
14
14
  export type { ColumnFilterModel, FilterCondition, FilterModel, FilterOperator } from "./filtering.js";
15
15
  export type { UIButtonControl, UICheckboxDescriptor, UIControlBase, UIControlDescriptor, UIGroupControl, UIInputControl, UIPopupAnchor, UIPopupDescriptor, UISelectControl, UISelectOption, UITextBlockControl, UIMultiSelectControl, UIMultiSelectOption, } from "./ui.js";
16
16
  export type { OverlayOptions, OverlayScope, OverlayState, OverlayType } from "./overlays.js";
17
- export type { BlockConfig, CellAlign, AggregationFunc, ColumnHeaderExtension, ColumnHeaderExtensionPosition, CellRenderParams, CellClassRules, CellSpan, CellSpanningParams, CheckboxControl, CheckboxRenderParams, ColSpanDef, ColumnClassRules, ColumnDataType, ColumnDropPosition, DefaultColumnDef, ColumnFilterType, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, ColumnStyle, ColumnStyleParams, DataProcessor, DataRowNode, DomPoolBindings, DomPoolUpdate, DomPoolUpdateOptions, GroupRowNode, GroupRowRenderParams, GroupRowRenderer, CoreGridApi, CoreGridState, GridApi, GridEvents, GridOptions, GridPlugin, GridState, PluginApiExtensions, PluginStateExtensions, ResolvedAggregationFunc, HeaderClassRules, HeaderGroupClassRules, HeaderGroupRenderParams, HeaderRenderParams, HeaderStyle, OverlayComponent, OverlayComponentProps, PooledRow, Range, RowClassRules, RowClickEvent, RowHeightUpdateOptions, RowHost, RowHoverEvent, RowId, RowHierarchy, RowHierarchyScope, RowGroupContext, RowGroupContextChild, RowNode, RowRenderParams, RowSpanLayout, RowStyle, RowTransaction, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, TransactionResult, TreeRowNode, ViewportData, ViewportState, VirtualItem, } from "./types.js";
18
- export { applyDefaultColumnDef, getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans, } from "./columns.js";
17
+ export type { BlockConfig, CellAlign, AggregationFunc, AutoColumnHeaderMode, ColumnHeaderExtension, ColumnHeaderExtensionPosition, CellRenderParams, CellClassRules, CellSpan, CellSpanningParams, CheckboxControl, CheckboxRenderParams, ColSpanDef, ColumnClassRules, ColumnDataType, ColumnDropPosition, DefaultColumnDef, ColumnFilterType, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, ColumnStyle, ColumnStyleParams, DataProcessor, DataRowNode, DomPoolBindings, DomPoolUpdate, DomPoolUpdateOptions, GroupRowNode, GroupRowRenderParams, GroupRowRenderer, CoreGridApi, CoreGridState, GridApi, GridEvents, GridOptions, GridPlugin, GridState, PluginApiExtensions, PluginStateExtensions, ResolvedAggregationFunc, HeaderClassRules, HeaderGroupClassRules, HeaderGroupRenderParams, HeaderRenderParams, HeaderStyle, OverlayComponent, OverlayComponentProps, PooledRow, Range, RowClassRules, RowClickEvent, RowHeightUpdateOptions, RowHost, RowHoverEvent, RowId, RowHierarchy, RowHierarchyScope, RowGroupContext, RowGroupContextChild, RowNode, RowRenderParams, RowSpanLayout, RowStyle, RowTransaction, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, TransactionResult, TreeRowNode, ViewportData, ViewportState, VirtualItem, } from "./types.js";
18
+ export { applyDefaultColumnDef, getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans, inferColumns, } from "./columns.js";
19
19
  export { Virtualizer, RowHeightRegistry } from "./virtualizer.js";
package/dist/index.js CHANGED
@@ -8,5 +8,5 @@ export { SlotManager } from "./slots.js";
8
8
  export { Store } from "./store.js";
9
9
  export { DataPipeline, PIPELINE_STAGE_ORDER } from "./pipeline.js";
10
10
  export { applyFilterModel, applyQuickFilter, isActiveCondition, isFilterModelActive, matchesColumnFilter, } from "./filtering.js";
11
- export { applyDefaultColumnDef, getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans, } from "./columns.js";
11
+ export { applyDefaultColumnDef, getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans, inferColumns, } from "./columns.js";
12
12
  export { Virtualizer, RowHeightRegistry } from "./virtualizer.js";
package/dist/store.d.ts CHANGED
@@ -1,10 +1,43 @@
1
+ /**
2
+ * A partial state patch, or a reducer that derives one from the current state.
3
+ *
4
+ * @api
5
+ */
1
6
  export type StateUpdater<State> = Partial<State> | ((state: State) => Partial<State>);
7
+ /**
8
+ * Options for {@link Store.setState}.
9
+ *
10
+ * @api
11
+ */
12
+ export interface SetStateOptions {
13
+ /**
14
+ * Notify subscribers even when the patch does not change any field.
15
+ *
16
+ * Used for forced repaints — e.g. a geometry refresh or a slot/header
17
+ * change — where the Store state itself is unchanged but subscribers must
18
+ * re-read it to repaint.
19
+ * @default false
20
+ */
21
+ force?: boolean;
22
+ }
23
+ /**
24
+ * Minimal observable state container.
25
+ *
26
+ * `setState` performs a shallow, per-key equality check and only notifies
27
+ * subscribers when at least one field actually changes (by reference). This
28
+ * suppresses the redundant notifications caused by empty patches
29
+ * (`setState({})`) and repeated writes of the same value. Callers that need an
30
+ * unconditional notification pass `{ force: true }`.
31
+ *
32
+ * @api
33
+ */
2
34
  export declare class Store<State extends object> {
3
35
  private state;
4
36
  private readonly listeners;
5
37
  constructor(initialState: State);
6
38
  getState(): State;
7
- setState(updater: StateUpdater<State>): void;
39
+ setState(updater: StateUpdater<State>, options?: SetStateOptions): void;
8
40
  subscribe(listener: () => void): () => void;
9
41
  clear(): void;
42
+ private static hasChanges;
10
43
  }
package/dist/store.js CHANGED
@@ -1,3 +1,14 @@
1
+ /**
2
+ * Minimal observable state container.
3
+ *
4
+ * `setState` performs a shallow, per-key equality check and only notifies
5
+ * subscribers when at least one field actually changes (by reference). This
6
+ * suppresses the redundant notifications caused by empty patches
7
+ * (`setState({})`) and repeated writes of the same value. Callers that need an
8
+ * unconditional notification pass `{ force: true }`.
9
+ *
10
+ * @api
11
+ */
1
12
  export class Store {
2
13
  constructor(initialState) {
3
14
  this.listeners = new Set();
@@ -6,8 +17,11 @@ export class Store {
6
17
  getState() {
7
18
  return this.state;
8
19
  }
9
- setState(updater) {
10
- const update = typeof updater === 'function' ? updater(this.state) : updater;
20
+ setState(updater, options) {
21
+ const update = typeof updater === "function" ? updater(this.state) : updater;
22
+ if (options?.force !== true && !Store.hasChanges(this.state, update)) {
23
+ return;
24
+ }
11
25
  this.state = { ...this.state, ...update };
12
26
  this.listeners.forEach((listener) => listener());
13
27
  }
@@ -18,4 +32,11 @@ export class Store {
18
32
  clear() {
19
33
  this.listeners.clear();
20
34
  }
35
+ static hasChanges(previous, patch) {
36
+ for (const key of Object.keys(patch)) {
37
+ if (!Object.is(previous[key], patch[key]))
38
+ return true;
39
+ }
40
+ return false;
41
+ }
21
42
  }
package/dist/types.d.ts CHANGED
@@ -613,10 +613,36 @@ export interface RowHeightUpdateOptions {
613
613
  */
614
614
  notify?: boolean;
615
615
  }
616
+ /**
617
+ * Built-in formatting modes for headers inferred from row fields.
618
+ * @api
619
+ */
620
+ export type AutoColumnHeaderMode = "as-is" | "title-case";
616
621
  export interface GridOptions<T> {
617
622
  /** Row data; omitted or null means an initial load is pending. */
618
623
  data?: T[] | null;
619
- columns: ColumnDef<T>[];
624
+ /**
625
+ * Column definitions. When omitted, the core infers columns from the first
626
+ * row and waits for data if the initial dataset is empty. The inferred
627
+ * schema stays fixed; call `setColumns` to change it afterward. Pass `[]`
628
+ * to explicitly disable inference.
629
+ * @api
630
+ */
631
+ columns?: ColumnDef<T>[];
632
+ /**
633
+ * Formatting mode for headers of columns inferred by the core. Defaults
634
+ * to `as-is`; `title-case` splits camel-case field names into words and
635
+ * capitalizes each word. Ignored when `columns` is provided.
636
+ * @default as-is
637
+ * @api
638
+ */
639
+ autoColumnHeaderMode?: AutoColumnHeaderMode;
640
+ /**
641
+ * Custom formatter for headers of inferred columns. Takes precedence over
642
+ * `autoColumnHeaderMode` when provided. Ignored when `columns` is provided.
643
+ * @api
644
+ */
645
+ getColumnHeader?: (field: string) => string;
620
646
  /** Properties applied to every leaf column unless overridden. @api */
621
647
  defaultColumnDef?: DefaultColumnDef<T>;
622
648
  /** Returns a stable row ID; defaults to the row's current index. Use a stable ID to preserve row identity when rows are reordered. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/core",
3
- "version": "0.1.34",
3
+ "version": "0.1.36",
4
4
  "description": "Framework-agnostic core engine for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",