@homebound/beam 2.308.0 → 2.309.0

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.
@@ -77,8 +77,6 @@ export interface GridTableProps<R extends Kinded, X> {
77
77
  filter?: string;
78
78
  /** Caps the client-side filter to a max number of rows. */
79
79
  filterMaxRows?: number;
80
- /** Accepts the number of filtered rows (based on `filter`), for the caller to observe and display if they want. */
81
- setRowCount?: (rowCount: number) => void;
82
80
  /** A combination of CSS settings to set the static look & feel (vs. rowStyles which is per-row styling). */
83
81
  style?: GridStyle | GridStyleDef;
84
82
  /**
@@ -85,7 +85,7 @@ exports.setGridTableDefaults = setGridTableDefaults;
85
85
  */
86
86
  function GridTable(props) {
87
87
  var _a, _b, _c;
88
- const { id = "gridTable", as = "div", columns: _columns, rows, style: maybeStyle = defaults.style, rowStyles, stickyHeader = defaults.stickyHeader, stickyOffset = 0, xss, filter, filterMaxRows, fallbackMessage = "No rows found.", infoMessage, setRowCount, persistCollapse, resizeTarget, activeRowId, activeCellId, visibleColumnsStorageKey, infiniteScroll, } = props;
88
+ const { id = "gridTable", as = "div", columns: _columns, rows, style: maybeStyle = defaults.style, rowStyles, stickyHeader = defaults.stickyHeader, stickyOffset = 0, xss, filter, filterMaxRows, fallbackMessage = "No rows found.", infoMessage, persistCollapse, resizeTarget, activeRowId, activeCellId, visibleColumnsStorageKey, infiniteScroll, } = props;
89
89
  const columnsWithIds = (0, react_1.useMemo)(() => (0, columns_1.assignDefaultColumnIds)(_columns), [_columns]);
90
90
  // We only use this in as=virtual mode, but keep this here for rowLookup to use
91
91
  const virtuosoRef = (0, react_1.useRef)(null);
@@ -195,10 +195,6 @@ function GridTable(props) {
195
195
  // Refs are cheap to assign to, so we don't bother doing this in a useEffect
196
196
  rowLookup.current = (0, GridRowLookup_1.createRowLookup)(columns, visibleDataRows, virtuosoRef);
197
197
  }
198
- // TODO: Replace setRowCount with clients observing TableState via the API
199
- (0, react_1.useEffect)(() => {
200
- setRowCount && (visibleDataRows === null || visibleDataRows === void 0 ? void 0 : visibleDataRows.length) !== undefined && setRowCount(visibleDataRows.length);
201
- }, [visibleDataRows === null || visibleDataRows === void 0 ? void 0 : visibleDataRows.length, setRowCount]);
202
198
  const noData = visibleDataRows.length === 0;
203
199
  const firstRowMessage = (noData && fallbackMessage) || (tooManyClientSideRows && "Hiding some rows, use filter...") || infoMessage;
204
200
  const borderless = (_a = style === null || style === void 0 ? void 0 : style.presentationSettings) === null || _a === void 0 ? void 0 : _a.borderless;
@@ -24,7 +24,7 @@ class ColumnState {
24
24
  this.expanded = true;
25
25
  this.doExpand();
26
26
  }
27
- (0, mobx_1.makeAutoObservable)(this, { column: mobx_1.observable.ref });
27
+ (0, mobx_1.makeAutoObservable)(this, { column: mobx_1.observable.ref }, { name: `ColumnState@${column.id}` });
28
28
  }
29
29
  setVisible(visible) {
30
30
  const wasVisible = this.visible;
@@ -42,7 +42,7 @@ class RowState {
42
42
  this.row = row;
43
43
  this.selected = !!row.initSelected;
44
44
  this.collapsed = (_a = states.storage.wasCollapsed(row.id)) !== null && _a !== void 0 ? _a : !!row.initCollapsed;
45
- (0, mobx_1.makeAutoObservable)(this, { row: mobx_1.observable.ref });
45
+ (0, mobx_1.makeAutoObservable)(this, { row: mobx_1.observable.ref }, { name: `RowState@${row.id}` });
46
46
  }
47
47
  /**
48
48
  * Whether we match a client-side filter; true if no filter is in place.
@@ -234,9 +234,9 @@ class RowState {
234
234
  .map((c) => (0, utils_1.applyRowFn)(c, this.row, api, 0, false))
235
235
  .some((maybeContent) => (0, utils_1.matchesFilter)(maybeContent, term)));
236
236
  }
237
- /** Pretty toString. */
237
+ /** Used by node when doing `console.log(rs)`. */
238
238
  [Symbol.for("nodejs.util.inspect.custom")]() {
239
- return `RowState ${this.row.kind}-${this.row.id}`;
239
+ return `RowState@${this.row.id}`;
240
240
  }
241
241
  }
242
242
  exports.RowState = RowState;
@@ -41,13 +41,25 @@ class RowStates {
41
41
  * Any missing rows are marked as `wasRemoved` so we can consider them "kept" if they're also selected.
42
42
  */
43
43
  setRows(rows) {
44
- const existing = new Set(this.map.values());
45
44
  const states = this;
46
45
  const map = this.map;
46
+ // Keep track of ids as we add them, to detect duplicates
47
+ const seenIds = new Set();
48
+ // Keep track of existing rows, so we can mark any that are missing as removed
49
+ const maybeKept = new Set(this.map.values());
47
50
  function addRowAndChildren(parent, row) {
48
51
  var _a;
49
- // This should really be kind+id, but a lot of our lookups just use id
52
+ // This should really be kind+id, but nearly all of our existing API uses just ids,
53
+ // b/c we assume our ids are tagged/unique across parent/child kinds anyway. So go
54
+ // ahead and enforce "row.id must be unique across kinds" b/c pragmatically that is
55
+ // baked into the current API signatures.
50
56
  const key = row.id;
57
+ if (seenIds.has(key)) {
58
+ throw new Error(`Duplicate row id ${key}`);
59
+ }
60
+ else {
61
+ seenIds.add(key);
62
+ }
51
63
  let state = map.get(key);
52
64
  if (!state) {
53
65
  state = new RowState_1.RowState(states, parent, row);
@@ -57,7 +69,7 @@ class RowStates {
57
69
  state.parent = parent;
58
70
  state.row = row;
59
71
  state.removed = false;
60
- existing.delete(state);
72
+ maybeKept.delete(state);
61
73
  }
62
74
  state.children = (_a = row.children) === null || _a === void 0 ? void 0 : _a.map((child) => addRowAndChildren(state, child));
63
75
  return state;
@@ -72,7 +84,7 @@ class RowStates {
72
84
  // from messing up "header is all selected" if its hidden/when there are no kept rows.
73
85
  this.header.children = [this.keptGroupRow, ...this.topRows];
74
86
  // Then mark any remaining as removed
75
- for (const state of existing)
87
+ for (const state of maybeKept)
76
88
  state.markRemoved();
77
89
  // After the first load of real data, we detach collapse state, to respect
78
90
  // any incoming initCollapsed.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.308.0",
3
+ "version": "2.309.0",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",