@homebound/beam 2.134.1 → 2.135.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.
- package/dist/components/Icon.js +2 -2
- package/dist/components/Table/GridTable.d.ts +2 -0
- package/dist/components/Table/GridTable.js +2 -2
- package/dist/components/Table/GridTableApi.d.ts +1 -1
- package/dist/components/Table/GridTableApi.js +2 -4
- package/dist/components/Table/RowState.d.ts +2 -1
- package/dist/components/Table/RowState.js +57 -4
- package/package.json +1 -1
package/dist/components/Icon.js
CHANGED
|
@@ -44,8 +44,8 @@ exports.Icons = {
|
|
|
44
44
|
eyeball: ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("path", { d: "M12 9C10.358 9 9 10.359 9 12C9 13.642 10.358 15 12 15C13.641 15 15 13.642 15 12C15 10.359 13.641 9 12 9Z" }, void 0), (0, jsx_runtime_1.jsx)("path", { d: "M11.9998 5C4.3668 5 2.0728 11.617 2.0518 11.684L1.9458 12L2.0508 12.316C2.0728 12.383 4.3668 19 11.9998 19C19.6328 19 21.9268 12.383 21.9478 12.316L22.0538 12L21.9488 11.684C21.9268 11.617 19.6328 5 11.9998 5ZM11.9998 17C6.6488 17 4.5758 13.154 4.0738 12C4.5778 10.842 6.6518 7 11.9998 7C17.3508 7 19.4238 10.846 19.9258 12C19.4218 13.158 17.3478 17 11.9998 17Z" }, void 0)] }, void 0)),
|
|
45
45
|
thumbsUp: ((0, jsx_runtime_1.jsx)("path", { d: "M20 8H14.388L15.511 4.633C15.713 4.025 15.611 3.351 15.236 2.831C14.861 2.311 14.253 2 13.612 2H12C11.703 2 11.422 2.132 11.231 2.36L6.531 8H4C2.897 8 2 8.897 2 10V19C2 20.103 2.897 21 4 21H7H17.307C18.136 21 18.888 20.479 19.18 19.702L21.937 12.351C21.979 12.239 22 12.12 22 12V10C22 8.897 21.103 8 20 8ZM4 10H6V19H4V10ZM20 11.819L17.307 19H8V9.362L12.468 4H13.614L12.052 8.683C11.949 8.988 12.001 9.323 12.189 9.584C12.377 9.846 12.679 10 13 10H20V11.819Z" }, void 0)),
|
|
46
46
|
verticalDots: ((0, jsx_runtime_1.jsx)("path", { d: "M12 10C10.9 10 10 10.9 10 12C10 13.1 10.9 14 12 14C13.1 14 14 13.1 14 12C14 10.9 13.1 10 12 10ZM12 4C10.9 4 10 4.9 10 6C10 7.1 10.9 8 12 8C13.1 8 14 7.1 14 6C14 4.9 13.1 4 12 4ZM12 16C10.9 16 10 16.9 10 18C10 19.1 10.9 20 12 20C13.1 20 14 19.1 14 18C14 16.9 13.1 16 12 16Z" }, void 0)),
|
|
47
|
-
star: ((0, jsx_runtime_1.jsx)("path", { d: "M10.
|
|
48
|
-
starFilled: ((0, jsx_runtime_1.jsx)("path", { d: "
|
|
47
|
+
star: ((0, jsx_runtime_1.jsx)("path", { d: "M10.9588 3.75641C11.2866 2.74787 12.7134 2.74786 13.0412 3.75641L14.7202 8.92341L18.1785 8.92354C18.1788 8.92354 18.1792 8.92354 18.1795 8.92354L20.1532 8.92361C21.2137 8.92365 21.6546 10.2806 20.7967 10.904L16.4014 14.0976L17.47 17.3866C17.4701 17.387 17.4702 17.3873 17.4703 17.3876L18.0801 19.2647C18.4078 20.2733 17.2534 21.112 16.3955 20.4887L12 17.2954L9.20214 19.328C9.20179 19.3283 9.20144 19.3285 9.20109 19.3288L7.60452 20.4887C6.74656 21.112 5.59223 20.2733 5.91989 19.2647L7.59858 14.0976L3.20334 10.904C2.34543 10.2807 2.78633 8.92365 3.8468 8.92361L5.82049 8.92354C5.82083 8.92354 5.82118 8.92354 5.82152 8.92354L9.27977 8.92341L10.9588 3.75641ZM6.60321 10.914L8.91787 12.5958C8.91818 12.596 8.91848 12.5962 8.91879 12.5965L9.29502 12.8698C9.67868 13.1486 9.83922 13.6427 9.69269 14.0937L9.54905 14.5359C9.54891 14.5363 9.54878 14.5367 9.54865 14.5371L8.6646 17.2583L11.3566 15.3026C11.7402 15.0239 12.2598 15.0239 12.6434 15.3026L13.0188 15.5753C13.0194 15.5757 13.02 15.5762 13.0206 15.5766L15.3354 17.2583L14.3073 14.0937C14.1608 13.6427 14.3213 13.1486 14.705 12.8698L17.3968 10.914L14.0694 10.9138C13.5952 10.9138 13.1749 10.6084 13.0283 10.1574L12 6.99297L11.1158 9.71405C11.1156 9.7144 11.1155 9.71474 11.1154 9.71508L10.9717 10.1574C10.8251 10.6084 10.4048 10.9138 9.93056 10.9138L6.60321 10.914Z" }, void 0)),
|
|
48
|
+
starFilled: ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("path", { d: "M11.0513 3.69095C11.3506 2.76968 12.654 2.76968 12.9534 3.69095L14.4722 8.36485C14.6061 8.77685 14.99 9.05579 15.4232 9.0558L20.3377 9.05599C21.3064 9.05603 21.7091 10.2956 20.9255 10.865L16.9497 13.7538C16.5992 14.0084 16.4526 14.4598 16.5864 14.8718L18.1049 19.5458C18.4042 20.4671 17.3498 21.2332 16.5661 20.6638L12.5901 17.7753C12.2396 17.5207 11.765 17.5207 11.4146 17.7753L7.43853 20.6638C6.65483 21.2332 5.6004 20.4671 5.89971 19.5458L7.4182 14.8718C7.55205 14.4598 7.4054 14.0084 7.05494 13.7538L3.07914 10.865C2.29548 10.2956 2.69823 9.05603 3.66692 9.05599L8.58142 9.0558C9.01461 9.05579 9.39854 8.77685 9.53242 8.36486L11.0513 3.69095Z" }, void 0), (0, jsx_runtime_1.jsx)("path", { d: "M11.0513 3.69095C11.3506 2.76968 12.654 2.76968 12.9534 3.69095L14.4722 8.36485C14.6061 8.77685 14.99 9.05579 15.4232 9.0558L20.3377 9.05599C21.3064 9.05603 21.7091 10.2956 20.9255 10.865L16.9497 13.7538C16.5992 14.0084 16.4526 14.4598 16.5864 14.8718L18.1049 19.5458C18.4042 20.4671 17.3498 21.2332 16.5661 20.6638L12.5901 17.7753C12.2396 17.5207 11.765 17.5207 11.4146 17.7753L7.43853 20.6638C6.65483 21.2332 5.6004 20.4671 5.89971 19.5458L7.4182 14.8718C7.55205 14.4598 7.4054 14.0084 7.05494 13.7538L3.07914 10.865C2.29548 10.2956 2.69823 9.05603 3.66692 9.05599L8.58142 9.0558C9.01461 9.05579 9.39854 8.77685 9.53242 8.36486L11.0513 3.69095Z" }, void 0)] }, void 0)),
|
|
49
49
|
cloudSave: ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("path", { d: "M9 19H7C4.243 19 2 16.757 2 14C2 11.82 3.609 9.792 5.757 9.15C6.85 6.611 9.244 5 12 5C15.56 5 18.507 7.67 18.944 11.112C20.695 11.538 22 13.12 22 15C22 17.206 20.206 19 18 19H15H9ZM15 17H18C19.103 17 20 16.103 20 15C20 13.897 19.103 13 18 13H17V12C17 9.243 14.757 7 12 7C9.895 7 8.149 8.274 7.446 10.325L7.254 10.883L6.673 10.985C5.199 11.244 4 12.596 4 14C4 15.654 5.346 17 7 17H9H15Z" }, void 0), (0, jsx_runtime_1.jsx)("rect", { x: "9.67139", y: "14.6567", width: "6", height: "1.5", transform: "rotate(-45 9.67139 14.6567)" }, void 0), (0, jsx_runtime_1.jsx)("rect", { x: "9.31787", y: "12.1819", width: "3.5", height: "1.5", transform: "rotate(45 9.31787 12.1819)" }, void 0)] }, void 0)),
|
|
50
50
|
attachment: ((0, jsx_runtime_1.jsx)("path", { d: "M5.70034 11.879L13.2477 4.15188C14.7481 2.61751 17.2048 2.61457 18.7439 4.15187C20.2147 5.69292 20.2456 8.1905 18.7439 9.72637L12.1677 16.4463C11.1677 17.4455 9.53953 17.4417 8.57861 16.4145L8.5763 16.4121C7.61217 15.4147 7.64468 13.8162 8.60983 12.8511L8.6113 12.8496L13.7859 7.56715C13.9307 7.42307 14.1608 7.40384 14.3248 7.56783L15.121 8.36403L15.1269 8.3691C15.2788 8.49929 15.2951 8.72507 15.1451 8.90458L9.9755 14.146C9.84287 14.2789 9.78341 14.4569 9.77747 14.6231C9.77157 14.7885 9.81776 14.9643 9.92515 15.0986L9.93923 15.1162L9.95684 15.1303C10.2011 15.3257 10.5715 15.346 10.8022 15.1153L17.3808 8.39291L17.3829 8.39073C18.1402 7.59359 18.1402 6.28461 17.3829 5.48747L17.3793 5.48379C16.6171 4.72167 15.3745 4.72167 14.6124 5.48379L14.6107 5.48549L7.06489 13.211L7.06402 13.2118C5.72803 14.5488 5.72839 16.7596 7.02689 18.0962C8.32851 19.4362 10.437 19.436 11.7387 18.0962L17.9191 11.7721C18.0556 11.6365 18.2859 11.6367 18.422 11.7728L19.2542 12.605L19.2601 12.6101C19.4197 12.7469 19.4187 12.9691 19.2846 13.1031L19.283 13.1048L13.1015 19.43C11.0256 21.5403 7.70624 21.5062 5.66445 19.4304C3.62176 17.3177 3.65669 13.9573 5.70034 11.879Z" }, void 0)),
|
|
51
51
|
archive: ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("path", { "fill-rule": "evenodd", d: "M19 10H5L5 18H19V10ZM3 8V18C3 19.1046 3.89543 20 5 20H19C20.1046 20 21 19.1046 21 18V8H3Z" }, void 0), (0, jsx_runtime_1.jsx)("path", { "fill-rule": "evenodd", d: "M3.81818 6V8H20.1818V6H3.81818ZM2.90909 4C2.40701 4 2 4.44772 2 5V9C2 9.55228 2.40701 10 2.90909 10H21.0909C21.593 10 22 9.55228 22 9V5C22 4.44772 21.593 4 21.0909 4H2.90909Z" }, void 0), (0, jsx_runtime_1.jsx)("rect", { x: "8", y: "11", width: "8", height: "2", rx: "1" }, void 0)] }, void 0)),
|
|
@@ -331,6 +331,8 @@ export declare type GridDataRow<R extends Kinded> = {
|
|
|
331
331
|
/** Whether to pin this sort to the first/last of its parent's children. */
|
|
332
332
|
pin?: "first" | "last";
|
|
333
333
|
data: unknown;
|
|
334
|
+
/** Whether to have the row collapsed (children not visible) on initial load. This will be ignore in subsequent re-renders of the table */
|
|
335
|
+
initCollapsed?: boolean;
|
|
334
336
|
} & IfAny<R, {}, DiscriminateUnion<R, "kind", R["kind"]>>;
|
|
335
337
|
declare type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
|
|
336
338
|
/** Return the content for a given column def applied to a given row. */
|
|
@@ -97,13 +97,13 @@ function GridTable(props) {
|
|
|
97
97
|
const api = (0, react_1.useMemo)(() => {
|
|
98
98
|
var _a;
|
|
99
99
|
const api = (_a = props.api) !== null && _a !== void 0 ? _a : new GridTableApi_1.GridTableApiImpl();
|
|
100
|
-
api.init(persistCollapse, virtuosoRef);
|
|
100
|
+
api.init(persistCollapse, virtuosoRef, rows);
|
|
101
101
|
api.setActiveRowId(activeRowId);
|
|
102
102
|
return api;
|
|
103
103
|
}, [props.api]);
|
|
104
104
|
const style = resolveStyles(maybeStyle);
|
|
105
105
|
const { rowState } = api;
|
|
106
|
-
rowState.rows
|
|
106
|
+
rowState.setRows(rows);
|
|
107
107
|
(0, react_1.useEffect)(() => {
|
|
108
108
|
rowState.activeRowId = activeRowId;
|
|
109
109
|
}, [rowState, activeRowId]);
|
|
@@ -37,7 +37,7 @@ export declare class GridTableApiImpl<R extends Kinded> implements GridTableApi<
|
|
|
37
37
|
readonly rowState: RowState;
|
|
38
38
|
virtuosoRef: MutableRefObject<VirtuosoHandle | null>;
|
|
39
39
|
/** Called once by the GridTable when it takes ownership of this api instance. */
|
|
40
|
-
init(persistCollapse: string | undefined, virtuosoRef: MutableRefObject<VirtuosoHandle | null>): void;
|
|
40
|
+
init(persistCollapse: string | undefined, virtuosoRef: MutableRefObject<VirtuosoHandle | null>, rows: GridDataRow<R>[]): void;
|
|
41
41
|
scrollToIndex(index: number): void;
|
|
42
42
|
getSelectedRowIds(kind?: string): string[];
|
|
43
43
|
getSelectedRows(kind?: string): any;
|
|
@@ -31,10 +31,8 @@ class GridTableApiImpl {
|
|
|
31
31
|
this.virtuosoRef = { current: null };
|
|
32
32
|
}
|
|
33
33
|
/** Called once by the GridTable when it takes ownership of this api instance. */
|
|
34
|
-
init(persistCollapse, virtuosoRef) {
|
|
35
|
-
|
|
36
|
-
this.rowState.loadPersistedCollapse(persistCollapse);
|
|
37
|
-
}
|
|
34
|
+
init(persistCollapse, virtuosoRef, rows) {
|
|
35
|
+
this.rowState.loadCollapse(persistCollapse, rows);
|
|
38
36
|
this.virtuosoRef = virtuosoRef;
|
|
39
37
|
}
|
|
40
38
|
scrollToIndex(index) {
|
|
@@ -27,7 +27,8 @@ export declare class RowState {
|
|
|
27
27
|
* Creates the `RowState` for a given `GridTable`.
|
|
28
28
|
*/
|
|
29
29
|
constructor();
|
|
30
|
-
|
|
30
|
+
loadCollapse(persistCollapse: string | undefined, rows: GridDataRow<any>[]): void;
|
|
31
|
+
setRows(rows: GridDataRow<any>[]): void;
|
|
31
32
|
setVisibleRows(rowIds: string[]): void;
|
|
32
33
|
get selectedIds(): string[];
|
|
33
34
|
getSelected(id: string): SelectedState;
|
|
@@ -53,9 +53,47 @@ class RowState {
|
|
|
53
53
|
this.selectedRows.merge(map);
|
|
54
54
|
}, { equals: mobx_1.comparer.shallow });
|
|
55
55
|
}
|
|
56
|
-
|
|
56
|
+
loadCollapse(persistCollapse, rows) {
|
|
57
57
|
this.persistCollapse = persistCollapse;
|
|
58
|
-
|
|
58
|
+
const sessionStorageIds = persistCollapse ? sessionStorage.getItem(persistCollapse) : null;
|
|
59
|
+
// Initialize with our collapsed rows based on what is in sessionStorage. Otherwise check if any rows have been defined as collapsed
|
|
60
|
+
const collapsedGridRowIds = sessionStorageIds ? JSON.parse(sessionStorageIds) : getCollapsedIdsFromRows(rows);
|
|
61
|
+
// If we have some initial rows to collapse, then set the internal prop
|
|
62
|
+
if (collapsedGridRowIds.length > 0) {
|
|
63
|
+
this.collapsedRows.replace(collapsedGridRowIds);
|
|
64
|
+
// If `persistCollapse` is set, but sessionStorageIds was not defined, then add them now.
|
|
65
|
+
if (this.persistCollapse && !sessionStorageIds) {
|
|
66
|
+
sessionStorage.setItem(this.persistCollapse, JSON.stringify(collapsedGridRowIds));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
// Updates the list of rows and regenerates the collapsedRows property if needed.
|
|
71
|
+
setRows(rows) {
|
|
72
|
+
// If the set of rows are different, and this is the first time adding "data" rows (non "totals" or "header" rows), then collapsedRows may need to be updated.
|
|
73
|
+
if (rows !== this.rows && this.rows.some((r) => r.kind !== "totals" && r.kind !== "header")) {
|
|
74
|
+
const currentCollapsedIds = this.collapsedIds;
|
|
75
|
+
// Create a list of the (maybe) new rows that should be initially collapsed
|
|
76
|
+
const maybeNewCollapsedRows = flattenRows(rows).filter((r) => r.initCollapsed);
|
|
77
|
+
// If the list of collapsed rows are different, then determine which are net-new rows and should be added to the newCollapsedIds array
|
|
78
|
+
if (currentCollapsedIds.length !== maybeNewCollapsedRows.length ||
|
|
79
|
+
!currentCollapsedIds.every((id) => maybeNewCollapsedRows.some((r) => r.id === id))) {
|
|
80
|
+
// Flatten out the existing rows to make checking for new rows easier
|
|
81
|
+
const flattenedExistingIds = flattenRows(this.rows).map((r) => r.id);
|
|
82
|
+
const newCollapsedIds = maybeNewCollapsedRows
|
|
83
|
+
.filter((maybeNewRow) => !flattenedExistingIds.includes(maybeNewRow.id))
|
|
84
|
+
.map((row) => row.id);
|
|
85
|
+
// If there are new rows that should be collapsed then update the collapsedRows arrays
|
|
86
|
+
if (newCollapsedIds.length > 0) {
|
|
87
|
+
this.collapsedRows.replace(currentCollapsedIds.concat(newCollapsedIds));
|
|
88
|
+
// Also update our persistCollapse if set
|
|
89
|
+
if (this.persistCollapse) {
|
|
90
|
+
sessionStorage.setItem(this.persistCollapse, JSON.stringify(currentCollapsedIds.concat(newCollapsedIds)));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// Finally replace our existing list of rows
|
|
96
|
+
this.rows = rows;
|
|
59
97
|
}
|
|
60
98
|
setVisibleRows(rowIds) {
|
|
61
99
|
// ObservableSet doesn't seem to do a `diff` inside `replace` before firing
|
|
@@ -177,7 +215,7 @@ class RowState {
|
|
|
177
215
|
}
|
|
178
216
|
this.collapsedRows.replace(collapsedIds);
|
|
179
217
|
if (this.persistCollapse) {
|
|
180
|
-
|
|
218
|
+
sessionStorage.setItem(this.persistCollapse, JSON.stringify(collapsedIds));
|
|
181
219
|
}
|
|
182
220
|
}
|
|
183
221
|
getVisibleChildrenStates(children, map) {
|
|
@@ -208,7 +246,7 @@ exports.RowStateContext = react_1.default.createContext({
|
|
|
208
246
|
});
|
|
209
247
|
// Get the rows that are already in the toggled state, so we can keep them toggled
|
|
210
248
|
function readLocalCollapseState(persistCollapse) {
|
|
211
|
-
const collapsedGridRowIds =
|
|
249
|
+
const collapsedGridRowIds = sessionStorage.getItem(persistCollapse);
|
|
212
250
|
return collapsedGridRowIds ? JSON.parse(collapsedGridRowIds) : [];
|
|
213
251
|
}
|
|
214
252
|
/** Finds a row by id, and returns it + any parents. */
|
|
@@ -232,3 +270,18 @@ function deriveParentSelected(children) {
|
|
|
232
270
|
const allUnchecked = children.every((child) => child === "unchecked");
|
|
233
271
|
return children.length === 0 ? "unchecked" : allChecked ? "checked" : allUnchecked ? "unchecked" : "partial";
|
|
234
272
|
}
|
|
273
|
+
function getCollapsedIdsFromRows(rows) {
|
|
274
|
+
return rows.reduce((acc, r) => {
|
|
275
|
+
if (r.initCollapsed) {
|
|
276
|
+
acc.push(r.id);
|
|
277
|
+
}
|
|
278
|
+
if (r.children) {
|
|
279
|
+
acc.push(...getCollapsedIdsFromRows(r.children));
|
|
280
|
+
}
|
|
281
|
+
return acc;
|
|
282
|
+
}, []);
|
|
283
|
+
}
|
|
284
|
+
function flattenRows(rows) {
|
|
285
|
+
const childRows = rows.flatMap((r) => (r.children ? flattenRows(r.children) : []));
|
|
286
|
+
return [...rows, ...childRows];
|
|
287
|
+
}
|