@gridkitjs/core 0.14.0 → 0.14.1

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/index.d.ts CHANGED
@@ -3441,9 +3441,9 @@ declare function toggleColumnSort(sort: ColumnSortState, columnId: string, optio
3441
3441
  }): ColumnSortState;
3442
3442
  /**
3443
3443
  * `rows` ordered by `sort` — each entry read against `columns` for its
3444
- * `field` and `type` — with `rowIndex` renumbered to match the new
3445
- * positions, the invariant the rest of the grid relies on for keyboard
3446
- * navigation and `aria-rowindex`.
3444
+ * `field` and `type` — with `rowIndex` and `datasetIndex` renumbered to
3445
+ * match the new positions, the invariant the rest of the grid relies on for
3446
+ * keyboard navigation and `aria-rowindex`.
3447
3447
  *
3448
3448
  * Stable (`Array.prototype.sort` has been stable since ES2019), so rows
3449
3449
  * equal under every active key keep their relative order. A `null`/
@@ -3493,8 +3493,9 @@ declare function setColumnFilter<Row>(filter: FilterState<Row>, columnId: (Field
3493
3493
  declare function clearAllFilters<Row>(filter: FilterState<Row>): FilterState<Row>;
3494
3494
  /**
3495
3495
  * `rows` reduced to those matching every entry in `filter` (AND at the top
3496
- * level — nest a `GroupFilterEntry` for OR). `rowIndex` is renumbered to
3497
- * match the retained positions — the same invariant `sortRows` keeps,
3496
+ * level — nest a `GroupFilterEntry` for OR). `rowIndex` and `datasetIndex`
3497
+ * are renumbered to match the retained positions — the same invariant
3498
+ * `sortRows` keeps,
3498
3499
  * needed here independently since `filterRows` runs before `sortRows` in
3499
3500
  * the composed pipeline (see `resolveShownRows`).
3500
3501
  *
@@ -3532,10 +3533,11 @@ declare function groupRowId(path: readonly unknown[]): string;
3532
3533
  * this only reshapes their output, and never changes which rows appear or
3533
3534
  * their relative order within a group.
3534
3535
  *
3535
- * `rowIndex` is renumbered across the whole flattened output, header rows
3536
- * included — the same invariant `sortRows`/`filterRows` keep for
3537
- * `ResolvedRow.rowIndex`, extended to `ResolvedGroupRow.rowIndex` since
3538
- * `GridBody` addresses both kinds by the same flat position.
3536
+ * `rowIndex` and `datasetIndex` are renumbered across the whole flattened
3537
+ * output, header rows included — the same invariant `sortRows`/`filterRows`
3538
+ * keep for a `ResolvedRow`, extended to `ResolvedGroupRow` since `GridBody`
3539
+ * addresses both kinds by the same flat position, and `aria-rowindex`
3540
+ * counts both.
3539
3541
  *
3540
3542
  * Returns `rows` itself, untouched, when `groupBy` is empty or names only
3541
3543
  * columns absent from `columns` — a stored grouping tolerates a column
@@ -3640,9 +3642,9 @@ interface PaginatedRows<Row> {
3640
3642
  * state, matching `sortRows`/`filterRows`), and the returned page's
3641
3643
  * `rowIndex` is renumbered to be page-relative — 0-based from the top of the
3642
3644
  * page, header rows included, mirroring `groupRows`'s own renumbering
3643
- * invariant. `datasetIndex` is left untouched: it is assigned once, ahead of
3644
- * filter/sort/group/paginate, and reports each row's position in the whole
3645
- * dataset regardless of which page is showing.
3645
+ * invariant. `datasetIndex` is left untouched: the stages ahead of this one
3646
+ * set it to each row's position in the whole displayed result, which stays
3647
+ * the same whichever page is showing.
3646
3648
  */
3647
3649
  declare function paginateRows<Row>(rows: readonly DisplayRow<Row>[], pagination: PaginationState): PaginatedRows<Row>;
3648
3650
 
package/dist/index.js CHANGED
@@ -102,6 +102,13 @@ function accessDotted(obj, path) {
102
102
  return path.split(".").reduce((value, key) => isNested(value) ? value[key] : void 0, obj);
103
103
  }
104
104
 
105
+ // src/util/position.ts
106
+ function renumberRows(entries) {
107
+ return entries.map(
108
+ (entry, index) => entry.rowIndex === index && entry.datasetIndex === index ? entry : { ...entry, rowIndex: index, datasetIndex: index }
109
+ );
110
+ }
111
+
105
112
  // src/util/sorting.ts
106
113
  function isEmpty(value) {
107
114
  return value === null || value === void 0;
@@ -189,9 +196,7 @@ function sortRows(rows, sort, columns) {
189
196
  }
190
197
  return 0;
191
198
  });
192
- return sorted.map(
193
- (row, index) => row.rowIndex === index ? row : { ...row, rowIndex: index }
194
- );
199
+ return renumberRows(sorted);
195
200
  }
196
201
 
197
202
  // src/util/grouping.ts
@@ -263,9 +268,7 @@ function buildLevel(rows, levels, parentPath, expansion, byId, out) {
263
268
  path,
264
269
  expanded,
265
270
  count: group.rows.length,
266
- // Renumbered globally once `groupRows` has the whole flattened array —
267
- // a header has no row of its own to carry a dataset position, so
268
- // `datasetIndex` takes the same renumbered value `rowIndex` does.
271
+ // Both set by `groupRows` once it has the whole flattened array.
269
272
  rowIndex: -1,
270
273
  datasetIndex: -1,
271
274
  // Set by `withGroupAggregates`, downstream of grouping — empty here
@@ -289,12 +292,7 @@ function groupRows(rows, groupBy, expansion, columns) {
289
292
  }
290
293
  const out = [];
291
294
  buildLevel(rows, active, [], expansion, byId, out);
292
- return out.map((entry, index) => {
293
- if ("kind" in entry) {
294
- return entry.rowIndex === index && entry.datasetIndex === index ? entry : { ...entry, rowIndex: index, datasetIndex: index };
295
- }
296
- return entry.rowIndex === index ? entry : { ...entry, rowIndex: index };
297
- });
295
+ return renumberRows(out);
298
296
  }
299
297
  function toggleGroupExpansion(expansion, groupId) {
300
298
  return expansion.includes(groupId) ? expansion.filter((id) => id !== groupId) : [...expansion, groupId];
@@ -985,12 +983,7 @@ function withGroupAggregates(displayRows, flatRows, groupBy, specs, columns, dis
985
983
  display,
986
984
  out
987
985
  );
988
- return out.map((entry, position) => {
989
- if ("kind" in entry) {
990
- return entry.rowIndex === position && entry.datasetIndex === position ? entry : { ...entry, rowIndex: position, datasetIndex: position };
991
- }
992
- return entry.rowIndex === position ? entry : { ...entry, rowIndex: position };
993
- });
986
+ return renumberRows(out);
994
987
  }
995
988
 
996
989
  // src/util/filtering.ts
@@ -1151,9 +1144,7 @@ function filterRows(rows, filter, columns) {
1151
1144
  return rows;
1152
1145
  }
1153
1146
  const filtered = rows.filter((row) => test(row.row));
1154
- return filtered.map(
1155
- (row, index) => row.rowIndex === index ? row : { ...row, rowIndex: index }
1156
- );
1147
+ return renumberRows(filtered);
1157
1148
  }
1158
1149
 
1159
1150
  // src/util/rows.ts