@omnigrid/core 0.1.22 → 0.1.23

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 CHANGED
@@ -2,7 +2,7 @@ import type { FilterCondition, FilterModel } from "./filtering";
2
2
  import type { UIPopupAnchor, UIPopupDescriptor } from "./ui";
3
3
  import { IconRegistry } from "./icons";
4
4
  import { SlotManager } from "./slots";
5
- import type { ColumnLeafDef, DataProcessor, GridApi, GridEvents, GridOptions, GridPlugin, GridState, RowClickEvent, RowHeightUpdateOptions, RowHoverEvent, RowId, RowSpanLayout, ScrollPosition, SlotMount, SlotName, ViewportData, ViewportState } from "./types";
5
+ import type { ColumnLeafDef, DataProcessor, GridApi, GridEvents, GridOptions, GridPlugin, GridState, RowClickEvent, RowHeightUpdateOptions, RowHoverEvent, RowId, RowSpanLayout, ScrollPosition, SlotMount, SlotName, TransactionResult, RowTransaction, ViewportData, ViewportState } from "./types";
6
6
  import type { OverlayOptions, OverlayState } from "./overlays";
7
7
  export declare class Grid<T> implements GridApi<T> {
8
8
  private readonly store;
@@ -190,6 +190,22 @@ export declare class Grid<T> implements GridApi<T> {
190
190
  * missing `rows`.
191
191
  */
192
192
  appendData(rows: T[] | null | undefined): void;
193
+ /**
194
+ * Applies a targeted row transaction (add / update / remove) to the State
195
+ * Store without recreating the whole data array.
196
+ *
197
+ * Rows are matched by their stable id (`getRowId`). The pipeline caches
198
+ * (filtered / processed data) are invalidated and the virtualizer's
199
+ * row-height cache is reset only for the affected rows (or fully when the
200
+ * dataset size changes), avoiding heavy recomputation.
201
+ *
202
+ * Emits a single `dataChange` with the resulting dataset and bumps the
203
+ * grid revision.
204
+ * @param transaction - The rows to add, update and/or remove.
205
+ * @returns The added, updated and removed rows with resolved ids/indexes.
206
+ * @api
207
+ */
208
+ applyTransaction(transaction: RowTransaction<T>): TransactionResult<T>;
193
209
  setViewport(viewport: Partial<ViewportState>): void;
194
210
  /**
195
211
  * Repaints the current viewport: notifies Store subscribers that
package/dist/grid.js CHANGED
@@ -567,6 +567,107 @@ export class Grid {
567
567
  this.events.emit("dataChange", nextData);
568
568
  this.recomputeOverlay();
569
569
  }
570
+ /**
571
+ * Applies a targeted row transaction (add / update / remove) to the State
572
+ * Store without recreating the whole data array.
573
+ *
574
+ * Rows are matched by their stable id (`getRowId`). The pipeline caches
575
+ * (filtered / processed data) are invalidated and the virtualizer's
576
+ * row-height cache is reset only for the affected rows (or fully when the
577
+ * dataset size changes), avoiding heavy recomputation.
578
+ *
579
+ * Emits a single `dataChange` with the resulting dataset and bumps the
580
+ * grid revision.
581
+ * @param transaction - The rows to add, update and/or remove.
582
+ * @returns The added, updated and removed rows with resolved ids/indexes.
583
+ * @api
584
+ */
585
+ applyTransaction(transaction) {
586
+ this.assertActive();
587
+ const currentData = this.store.getState().data;
588
+ const added = [];
589
+ const updated = [];
590
+ const removed = [];
591
+ // Row indexes whose measured height must be discarded because the row
592
+ // content changed (update) or the dataset size changed (add / remove).
593
+ const affectedIndexes = new Set();
594
+ let structuralChange = false;
595
+ // Resolves the id of a row object, preferring its current position so
596
+ // index-based `getRowId` implementations keep matching existing rows.
597
+ const resolveIdOf = (row) => {
598
+ const index = currentData.indexOf(row);
599
+ return this.resolveRowId(row, index >= 0 ? index : -1);
600
+ };
601
+ // ---------- removals ----------
602
+ const removeIds = new Set();
603
+ if (transaction.remove) {
604
+ for (const item of transaction.remove) {
605
+ removeIds.add(typeof item === "object" && item !== null ? resolveIdOf(item) : item);
606
+ }
607
+ }
608
+ const afterRemove = [];
609
+ currentData.forEach((row, index) => {
610
+ const id = this.resolveRowId(row, index);
611
+ if (removeIds.has(id)) {
612
+ removed.push({ id, index, data: row });
613
+ affectedIndexes.add(index);
614
+ }
615
+ else {
616
+ afterRemove.push(row);
617
+ }
618
+ });
619
+ // ---------- updates ----------
620
+ let nextData = afterRemove;
621
+ if (transaction.update) {
622
+ const updateIdToIndex = new Map();
623
+ afterRemove.forEach((row, index) => updateIdToIndex.set(this.resolveRowId(row, index), index));
624
+ nextData = [...afterRemove];
625
+ for (const row of transaction.update) {
626
+ const id = resolveIdOf(row);
627
+ const index = updateIdToIndex.get(id);
628
+ if (index === undefined)
629
+ continue;
630
+ nextData[index] = row;
631
+ updated.push({ id, index, data: row });
632
+ affectedIndexes.add(index);
633
+ }
634
+ }
635
+ // ---------- adds ----------
636
+ const insertAt = Math.min(Math.max(transaction.addIndex ?? nextData.length, 0), nextData.length);
637
+ if (transaction.add) {
638
+ transaction.add.forEach((row, position) => {
639
+ const index = insertAt + position;
640
+ const id = this.resolveRowId(row, index);
641
+ nextData.splice(index, 0, row);
642
+ added.push({ id, index, data: row });
643
+ affectedIndexes.add(index);
644
+ });
645
+ structuralChange = true;
646
+ }
647
+ if (removed.length > 0)
648
+ structuralChange = true;
649
+ const changed = added.length > 0 || updated.length > 0 || removed.length > 0;
650
+ if (!changed) {
651
+ return { added, updated, removed };
652
+ }
653
+ // ---------- invalidate caches & patch the store ----------
654
+ if (structuralChange) {
655
+ // Adding or removing rows shifts every subsequent index, so the
656
+ // index-based row-height registry can no longer be trusted row by row.
657
+ this.virtualizer.resetAllRowHeights();
658
+ }
659
+ else {
660
+ // Pure update: only the affected rows may have changed height.
661
+ affectedIndexes.forEach((index) => this.virtualizer.rowHeights.reset(index));
662
+ }
663
+ this.filteredDataCache = null;
664
+ this.processedDataCache = null;
665
+ this.revision += 1;
666
+ this.store.setState({ data: nextData });
667
+ this.events.emit("dataChange", nextData);
668
+ this.recomputeOverlay();
669
+ return { added, updated, removed };
670
+ }
570
671
  setViewport(viewport) {
571
672
  this.assertActive();
572
673
  const state = this.store.getState();
package/dist/index.d.ts CHANGED
@@ -11,6 +11,6 @@ export { applyFilterModel, applyQuickFilter, isActiveCondition, isFilterModelAct
11
11
  export type { ColumnFilterModel, FilterCondition, FilterModel, FilterOperator } from "./filtering";
12
12
  export type { UIButtonControl, UICheckboxDescriptor, UIControlBase, UIControlDescriptor, UIGroupControl, UIInputControl, UIPopupAnchor, UIPopupDescriptor, UISelectControl, UISelectOption, UITextBlockControl, UIMultiSelectControl, UIMultiSelectOption, } from "./ui";
13
13
  export type { OverlayOptions, OverlayScope, OverlayState, OverlayType } from "./overlays";
14
- export type { BlockConfig, CellAlign, CellRenderParams, CellClassRules, CellSpan, CellSpanningParams, CheckboxControl, CheckboxRenderParams, ColSpanDef, ColumnClassRules, ColumnDataType, ColumnFilterType, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, ColumnStyle, ColumnStyleParams, DataProcessor, DomPoolBindings, DomPoolUpdate, DomPoolUpdateOptions, GridApi, GridEvents, GridOptions, GridPlugin, GridState, HeaderClassRules, HeaderGroupClassRules, HeaderGroupRenderParams, HeaderRenderParams, HeaderStyle, OverlayComponent, OverlayComponentProps, PooledRow, Range, RowClassRules, RowClickEvent, RowHeightUpdateOptions, RowHost, RowHoverEvent, RowId, RowNode, RowRenderParams, RowSpanLayout, RowStyle, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, ViewportData, ViewportState, VirtualItem, } from "./types";
14
+ export type { BlockConfig, CellAlign, CellRenderParams, CellClassRules, CellSpan, CellSpanningParams, CheckboxControl, CheckboxRenderParams, ColSpanDef, ColumnClassRules, ColumnDataType, ColumnFilterType, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, ColumnStyle, ColumnStyleParams, DataProcessor, DomPoolBindings, DomPoolUpdate, DomPoolUpdateOptions, GridApi, GridEvents, GridOptions, GridPlugin, GridState, HeaderClassRules, HeaderGroupClassRules, HeaderGroupRenderParams, HeaderRenderParams, HeaderStyle, OverlayComponent, OverlayComponentProps, PooledRow, Range, RowClassRules, RowClickEvent, RowHeightUpdateOptions, RowHost, RowHoverEvent, RowId, RowNode, RowRenderParams, RowSpanLayout, RowStyle, RowTransaction, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, TransactionResult, ViewportData, ViewportState, VirtualItem, } from "./types";
15
15
  export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans } from "./columns";
16
16
  export { Virtualizer, RowHeightRegistry } from "./virtualizer";
package/dist/types.d.ts CHANGED
@@ -805,6 +805,51 @@ export interface GridPlugin<T> {
805
805
  getRowClass?(params: RowRenderParams<T>): string | undefined;
806
806
  getRowStyle?(params: RowRenderParams<T>): RowStyle | undefined;
807
807
  }
808
+ /**
809
+ * A single targeted row transaction: add, update, or remove rows by their
810
+ * stable identifier (`getRowId`) without recreating the whole data array.
811
+ *
812
+ * Rows are matched against the current dataset by their row id. `add`
813
+ * appends new rows (optionally at `addIndex`), `update` replaces existing
814
+ * rows matched by id, and `remove` drops rows matched by id or by row object
815
+ * reference. Use a stable `getRowId` (a business key, not the row index) so
816
+ * row identity survives reordering and transactions.
817
+ *
818
+ * @api
819
+ */
820
+ export interface RowTransaction<T> {
821
+ /** Rows to add. Each row receives a stable id via `getRowId`. */
822
+ add?: T[];
823
+ /**
824
+ * Zero-based index at which added rows are inserted.
825
+ * Defaults to appending at the end of the dataset.
826
+ * @default dataset length
827
+ * @api
828
+ */
829
+ addIndex?: number;
830
+ /** Rows to update. Each row is matched by id and replaced with the new data. */
831
+ update?: T[];
832
+ /**
833
+ * Rows to remove, given either as row objects (matched by id/reference)
834
+ * or as raw row ids.
835
+ * @api
836
+ */
837
+ remove?: Array<T | RowId>;
838
+ }
839
+ /**
840
+ * Outcome of `Grid.applyTransaction`: the added, updated and removed rows
841
+ * with their resolved ids and indexes in the dataset.
842
+ *
843
+ * @api
844
+ */
845
+ export interface TransactionResult<T> {
846
+ /** Rows that were added, with their resolved id and index. */
847
+ added: RowNode<T>[];
848
+ /** Rows that were updated, with their resolved id and index. */
849
+ updated: RowNode<T>[];
850
+ /** Rows that were removed, with their resolved id and previous index. */
851
+ removed: RowNode<T>[];
852
+ }
808
853
  export type SlotName = "top" | "bottom" | "left" | "right" | "bodyTop" | "bodyBottom" | "down";
809
854
  export type SlotPosition = "start" | "center" | "end";
810
855
  /**
@@ -946,6 +991,22 @@ export interface GridApi<T> {
946
991
  * @api
947
992
  */
948
993
  appendData(rows: T[] | null | undefined): void;
994
+ /**
995
+ * Applies a targeted row transaction (add / update / remove) to the State
996
+ * Store without recreating the whole data array.
997
+ *
998
+ * Rows are matched by their stable id (`getRowId`). The pipeline caches
999
+ * (filtered / processed data) are invalidated and the virtualizer's
1000
+ * row-height cache is reset only for the affected rows (or fully when the
1001
+ * dataset size changes), avoiding heavy recomputation.
1002
+ *
1003
+ * Emits a single `dataChange` with the resulting dataset and bumps the
1004
+ * grid revision.
1005
+ * @param transaction - The rows to add, update and/or remove.
1006
+ * @returns The added, updated and removed rows with resolved ids/indexes.
1007
+ * @api
1008
+ */
1009
+ applyTransaction(transaction: RowTransaction<T>): TransactionResult<T>;
949
1010
  /**
950
1011
  * Records the measured DOM height of a row (variable-height mode).
951
1012
  * Heights below 1px delta are ignored to prevent feedback loops between
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/core",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "description": "Framework-agnostic core engine for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",