@homebound/beam 2.313.0 → 2.313.2

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.
@@ -68,8 +68,13 @@ export declare class GridTableApiImpl<R extends Kinded> implements GridTableApi<
68
68
  init(persistCollapse: string | undefined, virtuosoRef: MutableRefObject<VirtuosoHandle | null>): void;
69
69
  scrollToIndex(index: number): void;
70
70
  getSelectedRowIds(kind?: string): string[];
71
+ private getSelectedRowIdsImpl;
71
72
  getSelectedRows(kind?: string): any;
73
+ private getSelectedRowsImpl;
72
74
  getVisibleRows(kind?: string): any;
75
+ private getVisibleRowsImpl;
76
+ getVisibleRowIds(kind?: string): any;
77
+ private getVisibleRowIdsImpl;
73
78
  clearSelections(id?: string): void;
74
79
  setActiveRowId(id: string | undefined): void;
75
80
  setActiveCellId(id: string | undefined): void;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GridTableApiImpl = exports.useGridTableApi = void 0;
4
+ const mobx_1 = require("mobx");
5
+ const mobx_utils_1 = require("mobx-utils");
4
6
  const react_1 = require("react");
5
7
  const index_1 = require("../index");
6
8
  const TableState_1 = require("./utils/TableState");
@@ -31,6 +33,12 @@ class GridTableApiImpl {
31
33
  this.virtuosoRef = { current: null };
32
34
  // This instance gets spread into each row's GridRowApi, so bind the methods up-front
33
35
  bindMethods(this);
36
+ // Memoize these so that if the user is creating new `data` instances on every render, they
37
+ // can use `getSelectedRowIds` to observer a stable list of `[pi:1, pi:2]`, etc.
38
+ this.getVisibleRowsImpl = (0, mobx_utils_1.computedFn)(this.getVisibleRowsImpl, { equals: mobx_1.comparer.shallow });
39
+ this.getVisibleRowIdsImpl = (0, mobx_utils_1.computedFn)(this.getVisibleRowIdsImpl, { equals: mobx_1.comparer.shallow });
40
+ this.getSelectedRowsImpl = (0, mobx_utils_1.computedFn)(this.getSelectedRowsImpl, { equals: mobx_1.comparer.shallow });
41
+ this.getSelectedRowIdsImpl = (0, mobx_utils_1.computedFn)(this.getSelectedRowIdsImpl, { equals: mobx_1.comparer.shallow });
34
42
  }
35
43
  /** Called once by the GridTable when it takes ownership of this api instance. */
36
44
  init(persistCollapse, virtuosoRef) {
@@ -44,15 +52,33 @@ class GridTableApiImpl {
44
52
  this.virtuosoRef.current && this.virtuosoRef.current.scrollToIndex(index);
45
53
  }
46
54
  getSelectedRowIds(kind) {
47
- return this.getSelectedRows(kind).map((row) => row.id);
55
+ return this.getSelectedRowIdsImpl(kind !== null && kind !== void 0 ? kind : undefined);
56
+ }
57
+ // impl with required param for computedFn
58
+ getSelectedRowIdsImpl(kind) {
59
+ return this.tableState.selectedRows.filter((rs) => !kind || rs.kind === kind).map((rs) => rs.row.id);
48
60
  }
49
- // The `any` is not great, but getting the overload to handle the optional kind is annoying
50
61
  getSelectedRows(kind) {
51
- return this.tableState.selectedRows.filter((row) => !kind || row.kind === kind);
62
+ return this.getSelectedRowsImpl(kind !== null && kind !== void 0 ? kind : undefined);
63
+ }
64
+ // impl with required param for computedFn
65
+ getSelectedRowsImpl(kind) {
66
+ return this.tableState.selectedRows.filter((rs) => !kind || rs.kind === kind).map((rs) => rs.row);
52
67
  }
53
68
  // The `any` is not great, but getting the overload to handle the optional kind is annoying
54
69
  getVisibleRows(kind) {
55
- return this.tableState.visibleRows.filter((row) => !kind || row.kind === kind);
70
+ return this.getVisibleRowsImpl(kind !== null && kind !== void 0 ? kind : undefined);
71
+ }
72
+ // impl with required param for computedFn
73
+ getVisibleRowsImpl(kind) {
74
+ return this.tableState.visibleRows.filter((row) => !kind || row.kind === kind).map((rs) => rs.row);
75
+ }
76
+ getVisibleRowIds(kind) {
77
+ return this.getVisibleRowIdsImpl(kind !== null && kind !== void 0 ? kind : undefined);
78
+ }
79
+ // impl with required param for computedFn
80
+ getVisibleRowIdsImpl(kind) {
81
+ return this.tableState.visibleRows.filter((row) => !kind || row.kind === kind).map((rs) => rs.row.id);
56
82
  }
57
83
  clearSelections(id) {
58
84
  this.tableState.selectRow("header", false);
@@ -65,7 +65,7 @@ export declare class TableState<R extends Kinded> {
65
65
  * Returns selected data rows (non-header, non-totals, etc.), ignoring rows that
66
66
  * have `row.selectable !== false`.
67
67
  */
68
- get selectedRows(): GridDataRow<R>[];
68
+ get selectedRows(): RowState<R>[];
69
69
  /** Returns kept group row, with the latest kept children, if any. */
70
70
  get keptRowGroup(): GridDataRow<R>;
71
71
  /** Returns kept rows, i.e. those that were user-selected but then client-side or server-side filtered. */
@@ -179,9 +179,7 @@ class TableState {
179
179
  * have `row.selectable !== false`.
180
180
  */
181
181
  get selectedRows() {
182
- return this.rowStates.allStates
183
- .filter((rs) => rs.isSelected && !utils_1.reservedRowKinds.includes(rs.row.kind))
184
- .map((rs) => rs.row);
182
+ return this.rowStates.allStates.filter((rs) => rs.isSelected && !utils_1.reservedRowKinds.includes(rs.row.kind));
185
183
  }
186
184
  /** Returns kept group row, with the latest kept children, if any. */
187
185
  get keptRowGroup() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.313.0",
3
+ "version": "2.313.2",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -116,6 +116,7 @@
116
116
  "jest-watch-typeahead": "^2.2.2",
117
117
  "mobx": "^6.8.0",
118
118
  "mobx-react": "^7.6.0",
119
+ "mobx-utils": "^6.0.8",
119
120
  "prettier": "^2.8.4",
120
121
  "prettier-plugin-organize-imports": "^3.2.2",
121
122
  "react": "^18.2.0",