@homebound/beam 2.118.1 → 2.118.4
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.
|
@@ -240,7 +240,7 @@ function GridTable(props) {
|
|
|
240
240
|
tooManyClientSideRows = true;
|
|
241
241
|
filteredRows = filteredRows.slice(0, filterMaxRows);
|
|
242
242
|
}
|
|
243
|
-
rowState.
|
|
243
|
+
rowState.setVisibleRows(filteredRows.map(([row]) => { var _a; return (_a = row === null || row === void 0 ? void 0 : row.id) !== null && _a !== void 0 ? _a : ""; }));
|
|
244
244
|
// Push back to the caller a way to ask us where a row is.
|
|
245
245
|
const { rowLookup } = props;
|
|
246
246
|
if (rowLookup) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ObservableSet } from "mobx";
|
|
2
1
|
import React, { MutableRefObject } from "react";
|
|
3
2
|
import { GridDataRow } from "./GridTable";
|
|
4
3
|
export declare type SelectedState = "checked" | "unchecked" | "partial";
|
|
@@ -22,12 +21,13 @@ export declare class RowState {
|
|
|
22
21
|
private persistCollapse;
|
|
23
22
|
private readonly collapsedRows;
|
|
24
23
|
private readonly selectedRows;
|
|
25
|
-
visibleRows
|
|
24
|
+
private visibleRows;
|
|
26
25
|
activeRowId: string | undefined;
|
|
27
26
|
/**
|
|
28
27
|
* Creates the `RowState` for a given `GridTable`.
|
|
29
28
|
*/
|
|
30
29
|
constructor(rows: MutableRefObject<GridDataRow<any>[]>, persistCollapse: string | undefined, activeRowId: string | undefined);
|
|
30
|
+
setVisibleRows(rowIds: string[]): void;
|
|
31
31
|
get selectedIds(): string[];
|
|
32
32
|
getSelected(id: string): SelectedState;
|
|
33
33
|
selectRow(id: string, selected: boolean): void;
|
|
@@ -45,6 +45,16 @@ class RowState {
|
|
|
45
45
|
this.selectedRows.merge(map);
|
|
46
46
|
}, { equals: mobx_1.comparer.shallow });
|
|
47
47
|
}
|
|
48
|
+
setVisibleRows(rowIds) {
|
|
49
|
+
// ObservableSet doesn't seem to do a `diff` inside `replace` before firing
|
|
50
|
+
// observers/reactions that watch it, which can lead to render loops with the
|
|
51
|
+
// application page is observing `GridTableApi.getSelectedRows`, and merely
|
|
52
|
+
// the act of rendering GridTable (w/o row changes) causes it's `useComputed`
|
|
53
|
+
// to be triggered.
|
|
54
|
+
if (!mobx_1.comparer.shallow(rowIds, [...this.visibleRows.values()])) {
|
|
55
|
+
this.visibleRows.replace(rowIds);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
48
58
|
get selectedIds() {
|
|
49
59
|
// Return only ids that are fully checked, i.e. not partial
|
|
50
60
|
const ids = [...this.selectedRows.entries()]
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.useComputed = void 0;
|
|
4
7
|
const mobx_1 = require("mobx");
|
|
5
8
|
const react_1 = require("react");
|
|
9
|
+
const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
|
|
6
10
|
/** Evaluates a computed function `fn` to a regular value and triggers a re-render whenever it changes. */
|
|
7
11
|
function useComputed(fn, deps) {
|
|
8
12
|
// We always return the useRef value, and use this just to trigger re-renders
|
|
@@ -33,7 +37,7 @@ function useComputed(fn, deps) {
|
|
|
33
37
|
// Only trigger a re-render if this is not the 1st autorun. Note
|
|
34
38
|
// that if deps has changed, we're inherently in a re-render so also
|
|
35
39
|
// don't need to trigger an additional re-render.
|
|
36
|
-
if (oldHasRun && newValue
|
|
40
|
+
if (oldHasRun && !(0, fast_deep_equal_1.default)(newValue, oldValue)) {
|
|
37
41
|
setTick((tick) => tick + 1);
|
|
38
42
|
}
|
|
39
43
|
});
|
|
@@ -25,15 +25,37 @@ function ListBox(props) {
|
|
|
25
25
|
const isMultiSelect = state.selectionManager.selectionMode === "multiple";
|
|
26
26
|
const firstItem = state.collection.at(0);
|
|
27
27
|
const hasSections = firstItem && firstItem.type === "section";
|
|
28
|
-
|
|
28
|
+
// Create a reference for measuring the MultiSelect's selected list's height. Used for re-evaluating `popoverHeight`.
|
|
29
|
+
const selectedList = (0, react_1.useRef)(null);
|
|
30
|
+
const firstRender = (0, react_1.useRef)(true);
|
|
31
|
+
// Keep track of the virtuoso list height to properly update the ListBox's height.
|
|
32
|
+
// Using a ref, this itself should not trigger a rerender, only `popoverHeight` changes will trigger a rerender.
|
|
33
|
+
const virtuosoListHeight = (0, react_1.useRef)(0);
|
|
34
|
+
const onListHeightChange = (listHeight) => {
|
|
35
|
+
var _a;
|
|
36
|
+
virtuosoListHeight.current = listHeight;
|
|
37
|
+
// The "listHeight" is only the list of options.
|
|
38
|
+
// For multiple selects we need to also account for the height of the list of currently selected elements when re-evaluating.
|
|
39
|
+
// Using `offsetHeight` to account for borders
|
|
40
|
+
const height = (((_a = selectedList.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) || 0) + listHeight;
|
|
29
41
|
// Using Math.min to choose between the smaller height, either the total height of the List (`height` arg), or the maximum height defined by the space allotted on screen or our hard coded max.
|
|
30
42
|
// If there are ListBoxSections, then we assume it is the persistent section with a single item and account for that height.
|
|
31
43
|
setPopoverHeight(Math.min(popoverMaxHeight, hasSections ? height + constants_1.persistentItemHeight + constants_1.sectionSeparatorHeight : height));
|
|
32
44
|
};
|
|
45
|
+
(0, react_1.useEffect)(() => {
|
|
46
|
+
// Reevaluate the list height when introducing or removing the MultiSelect's options list.
|
|
47
|
+
// Do not call `onListHeightChange` on the first render. Only when the selectedKeys size has actually changed between empty and not empty.
|
|
48
|
+
if (!firstRender.current &&
|
|
49
|
+
isMultiSelect &&
|
|
50
|
+
(state.selectionManager.selectedKeys.size === 0 || state.selectionManager.selectedKeys.size === 1)) {
|
|
51
|
+
onListHeightChange(virtuosoListHeight.current);
|
|
52
|
+
}
|
|
53
|
+
firstRender.current = false;
|
|
54
|
+
}, [state.selectionManager.selectedKeys.size]);
|
|
33
55
|
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ css: {
|
|
34
|
-
...Css_1.Css.bgWhite.br4.w100.bshBasic.if(contrast).bgGray700.$,
|
|
56
|
+
...Css_1.Css.bgWhite.br4.w100.bshBasic.hPx(popoverHeight).df.fdc.if(contrast).bgGray700.$,
|
|
35
57
|
"&:hover": Css_1.Css.bshHover.$,
|
|
36
|
-
}, ref: listBoxRef }, listBoxProps, { children: [isMultiSelect && state.selectionManager.selectedKeys.size > 0 && ((0, jsx_runtime_1.jsx)("ul", Object.assign({ css: Css_1.Css.listReset.pt2.pl2.pb1.pr1.df.bb.bGray200.add("flexWrap", "wrap")
|
|
58
|
+
}, ref: listBoxRef }, listBoxProps, { children: [isMultiSelect && state.selectionManager.selectedKeys.size > 0 && ((0, jsx_runtime_1.jsx)("ul", Object.assign({ css: Css_1.Css.listReset.pt2.pl2.pb1.pr1.df.bb.bGray200.add("flexWrap", "wrap").$, ref: selectedList }, { children: selectedOptions.map((o) => ((0, jsx_runtime_1.jsx)(ListBoxToggleChip_1.ListBoxToggleChip, { state: state, option: o, getOptionValue: getOptionValue, getOptionLabel: getOptionLabel, disabled: state.disabledKeys.has(getOptionValue(o)) }, getOptionValue(o)))) }), void 0)), (0, jsx_runtime_1.jsx)("ul", Object.assign({ css: Css_1.Css.listReset.fg1.$ }, { children: hasSections ? ([...state.collection].map((section) => ((0, jsx_runtime_1.jsx)(ListBoxSection_1.ListBoxSection, { section: section, state: state, contrast: contrast, onListHeightChange: onListHeightChange, popoverHeight: popoverHeight,
|
|
37
59
|
// Only scroll on focus if using VirtualFocus (used for ComboBoxState (SelectField), but not SelectState (ChipSelectField))
|
|
38
60
|
scrollOnFocus: props.shouldUseVirtualFocus }, section.key)))) : ((0, jsx_runtime_1.jsx)(VirtualizedOptions_1.VirtualizedOptions, { state: state, items: [...state.collection], onListHeightChange: onListHeightChange, contrast: contrast,
|
|
39
61
|
// Only scroll on focus if using VirtualFocus (used for ComboBoxState (SelectField), but not SelectState (ChipSelectField))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@homebound/beam",
|
|
3
|
-
"version": "2.118.
|
|
3
|
+
"version": "2.118.4",
|
|
4
4
|
"author": "Homebound",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"change-case": "^4.1.2",
|
|
40
40
|
"date-fns": "^2.21.3",
|
|
41
41
|
"dompurify": "^2.3.0",
|
|
42
|
+
"fast-deep-equal": "^3.1.3",
|
|
42
43
|
"framer-motion": "^4.1.11",
|
|
43
44
|
"memoize-one": "^5.2.1",
|
|
44
45
|
"react-aria": "^3.10.0",
|
|
@@ -50,8 +51,8 @@
|
|
|
50
51
|
"react-virtuoso": "^2.4.0",
|
|
51
52
|
"tributejs": "^5.1.3",
|
|
52
53
|
"trix": "^1.3.1",
|
|
53
|
-
"use-
|
|
54
|
-
"use-
|
|
54
|
+
"use-debounce": "^7.0.1",
|
|
55
|
+
"use-query-params": "^1.2.2"
|
|
55
56
|
},
|
|
56
57
|
"peerDependencies": {
|
|
57
58
|
"@emotion/react": ">=11",
|