@homebound/beam 2.315.1 → 2.316.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.
|
@@ -32,6 +32,7 @@ const memoize_one_1 = __importDefault(require("memoize-one"));
|
|
|
32
32
|
const mobx_1 = require("mobx");
|
|
33
33
|
const react_1 = __importStar(require("react"));
|
|
34
34
|
const react_virtuoso_1 = require("react-virtuoso");
|
|
35
|
+
const components_1 = require("..");
|
|
35
36
|
const PresentationContext_1 = require("../PresentationContext");
|
|
36
37
|
const GridTableApi_1 = require("./GridTableApi");
|
|
37
38
|
const useSetupColumnSizes_1 = require("./hooks/useSetupColumnSizes");
|
|
@@ -42,6 +43,7 @@ const utils_1 = require("./utils/utils");
|
|
|
42
43
|
const Css_1 = require("../../Css");
|
|
43
44
|
const hooks_1 = require("../../hooks");
|
|
44
45
|
const useRenderCount_1 = require("../../hooks/useRenderCount");
|
|
46
|
+
const utils_2 = require("../../utils");
|
|
45
47
|
const Row_1 = require("./components/Row");
|
|
46
48
|
let runningInJest = false;
|
|
47
49
|
/** Tells GridTable we're running in Jest, which forces as=virtual to be as=div, to work in jsdom. */
|
|
@@ -276,11 +278,15 @@ function renderVirtual(style, id, columns, visibleDataRows, keptSelectedRows, fi
|
|
|
276
278
|
const { paddingBottom, ...otherRootStyles } = (_a = style.rootCss) !== null && _a !== void 0 ? _a : {};
|
|
277
279
|
return { footerStyle: { paddingBottom }, listStyle: { ...style, rootCss: otherRootStyles } };
|
|
278
280
|
}, [style]);
|
|
281
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
282
|
+
const [fetchMoreInProgress, setFetchMoreInProgress] = (0, react_1.useState)(false);
|
|
279
283
|
return ((0, jsx_runtime_1.jsx)(react_virtuoso_1.Virtuoso, { overscan: 5, ref: virtuosoRef, components: {
|
|
280
284
|
// Applying a zIndex: 2 to ensure it stays on top of sticky columns
|
|
281
285
|
TopItemList: react_1.default.forwardRef((props, ref) => ((0, jsx_runtime_1.jsx)("div", { ...props, ref: ref, style: { ...props.style, ...{ zIndex: utils_1.zIndices.stickyHeader } } }))),
|
|
282
286
|
List: VirtualRoot(listStyle, columns, id, xss),
|
|
283
|
-
Footer: () =>
|
|
287
|
+
Footer: () => {
|
|
288
|
+
return ((0, jsx_runtime_1.jsx)("div", { css: footerStyle, children: fetchMoreInProgress && ((0, jsx_runtime_1.jsx)("div", { css: Css_1.Css.h5.df.aic.jcc.$, children: (0, jsx_runtime_1.jsx)(components_1.Loader, { size: "xs" }) })) }));
|
|
289
|
+
},
|
|
284
290
|
},
|
|
285
291
|
// Pin/sticky both the header row(s) + firstRowMessage to the top
|
|
286
292
|
topItemCount: stickyHeader ? tableHeadRows.length : 0, itemContent: (index) => {
|
|
@@ -316,7 +322,15 @@ function renderVirtual(style, id, columns, visibleDataRows, keptSelectedRows, fi
|
|
|
316
322
|
// Add a `index > 0` check b/c Virtuoso is calling this in storybook
|
|
317
323
|
// with `endReached(0)` at odd times, like on page unload/story load,
|
|
318
324
|
// which then causes our test data to have duplicate ids in it.
|
|
319
|
-
endReached: (index) =>
|
|
325
|
+
endReached: (index) => {
|
|
326
|
+
if (index === 0)
|
|
327
|
+
return;
|
|
328
|
+
const result = infiniteScroll.onEndReached(index);
|
|
329
|
+
if ((0, utils_2.isPromise)(result)) {
|
|
330
|
+
setFetchMoreInProgress(true);
|
|
331
|
+
result.finally(() => setFetchMoreInProgress(false));
|
|
332
|
+
}
|
|
333
|
+
},
|
|
320
334
|
}
|
|
321
335
|
: {}) }));
|
|
322
336
|
}
|
|
@@ -104,8 +104,8 @@ export type Pin = {
|
|
|
104
104
|
};
|
|
105
105
|
export type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
|
|
106
106
|
export type InfiniteScroll = {
|
|
107
|
-
/** will be called when the user scrolls to the end of the list with the last item index as an argument. */
|
|
108
|
-
onEndReached: (index: number) => void
|
|
107
|
+
/** will be called when the user scrolls to the end of the list with the last item index as an argument. Return a promise to automatically show a loading spinner. */
|
|
108
|
+
onEndReached: (index: number) => void | Promise<void>;
|
|
109
109
|
/** The number of pixels from the bottom of the list to eagerly trigger `onEndReached`. The default is 500px. */
|
|
110
110
|
endOffsetPx?: number;
|
|
111
111
|
};
|
package/dist/utils/rtl.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "type", { enumerable: true, get: function () { re
|
|
|
17
17
|
Object.defineProperty(exports, "typeAndWait", { enumerable: true, get: function () { return rtl_utils_1.typeAndWait; } });
|
|
18
18
|
Object.defineProperty(exports, "wait", { enumerable: true, get: function () { return rtl_utils_1.wait; } });
|
|
19
19
|
const react_1 = require("@testing-library/react");
|
|
20
|
+
const mobx_utils_1 = require("mobx-utils");
|
|
20
21
|
const components_1 = require("../components");
|
|
21
22
|
function render(component, wrapperOrOpts, ...otherWrappers) {
|
|
22
23
|
let wrappers;
|
|
@@ -49,7 +50,7 @@ function cellOf(r, tableTestId, rowNum, column) {
|
|
|
49
50
|
exports.cellOf = cellOf;
|
|
50
51
|
function cellAnd(r, row, column, testId) {
|
|
51
52
|
return (cell(r, row, column).querySelector(`[data-testid="${testId}"]`) ||
|
|
52
|
-
fail(`Element not found ${(0, react_1.prettyDOM)(cell(r, row, column))}`));
|
|
53
|
+
(0, mobx_utils_1.fail)(`Element not found ${(0, react_1.prettyDOM)(cell(r, row, column))}`));
|
|
53
54
|
}
|
|
54
55
|
exports.cellAnd = cellAnd;
|
|
55
56
|
function row(r, row, tableTestId = "gridTable") {
|
|
@@ -59,7 +60,7 @@ function row(r, row, tableTestId = "gridTable") {
|
|
|
59
60
|
exports.row = row;
|
|
60
61
|
function rowAnd(r, rowNum, testId) {
|
|
61
62
|
const e = row(r, rowNum);
|
|
62
|
-
return e.querySelector(`[data-testid="${testId}"]`) || fail(`Element not found ${(0, react_1.prettyDOM)(e)}`);
|
|
63
|
+
return e.querySelector(`[data-testid="${testId}"]`) || (0, mobx_utils_1.fail)(`Element not found ${(0, react_1.prettyDOM)(e)}`);
|
|
63
64
|
}
|
|
64
65
|
exports.rowAnd = rowAnd;
|
|
65
66
|
/** Intended to be used to generate a human-readable text
|
|
@@ -168,9 +169,7 @@ function ensureListBoxOpen(select) {
|
|
|
168
169
|
}
|
|
169
170
|
}
|
|
170
171
|
function selectOption(select, optionValue) {
|
|
171
|
-
const
|
|
172
|
-
const listboxId = select.getAttribute("aria-controls");
|
|
173
|
-
const listbox = body.querySelector(`#${listboxId}`);
|
|
172
|
+
const listbox = findListBox(select);
|
|
174
173
|
const options = listbox.querySelectorAll("[role=option]");
|
|
175
174
|
// Allow searching for options by their data-key (value) or textContent (label)
|
|
176
175
|
const optionToSelect = Array.from(options).find((o) => o.dataset.key === optionValue || o.dataset.label === optionValue);
|
|
@@ -190,9 +189,7 @@ function getSelected(element) {
|
|
|
190
189
|
return (_a = select.textContent) !== null && _a !== void 0 ? _a : undefined;
|
|
191
190
|
}
|
|
192
191
|
ensureListBoxOpen(select);
|
|
193
|
-
const
|
|
194
|
-
const listboxId = select.getAttribute("aria-controls");
|
|
195
|
-
const listbox = body.querySelector(`#${listboxId}`);
|
|
192
|
+
const listbox = findListBox(select);
|
|
196
193
|
const options = listbox.querySelectorAll("[role=option]");
|
|
197
194
|
const selections = Array.from(options)
|
|
198
195
|
.filter((o) => o.getAttribute("aria-selected") === "true")
|
|
@@ -206,15 +203,17 @@ function getOptions(element) {
|
|
|
206
203
|
const select = resolveIfNeeded(element);
|
|
207
204
|
assertListBoxInput(select);
|
|
208
205
|
ensureListBoxOpen(select);
|
|
209
|
-
const
|
|
210
|
-
const listboxId = select.getAttribute("aria-controls");
|
|
211
|
-
const listbox = body.querySelector(`#${listboxId}`);
|
|
206
|
+
const listbox = findListBox(select);
|
|
212
207
|
const options = listbox.querySelectorAll("[role=option]");
|
|
213
208
|
return Array.from(options)
|
|
214
209
|
.map((o) => { var _a, _b; return (_b = (_a = o.dataset.label) !== null && _a !== void 0 ? _a : o.dataset.key) !== null && _b !== void 0 ? _b : ""; })
|
|
215
210
|
.filter((o) => !!o);
|
|
216
211
|
}
|
|
217
212
|
exports.getOptions = getOptions;
|
|
213
|
+
function findListBox(select) {
|
|
214
|
+
const listboxId = select.getAttribute("aria-controls") || (0, mobx_utils_1.fail)("aria-controls attribute not found");
|
|
215
|
+
return document.getElementById(listboxId) || (0, mobx_utils_1.fail)("listbox not found");
|
|
216
|
+
}
|
|
218
217
|
function assertListBoxInput(select) {
|
|
219
218
|
if (isSelectElement(select)) {
|
|
220
219
|
throw new Error("Beam getOptions helper does not support <select> elements");
|