@linzjs/step-ag-grid 14.2.0 → 14.3.1
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/src/components/Grid.d.ts +5 -1
- package/dist/src/lui/timeoutHook.d.ts +6 -0
- package/dist/step-ag-grid.esm.js +89 -50
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +48 -10
- package/src/contexts/GridContextProvider.tsx +2 -3
- package/src/lui/timeoutHook.tsx +13 -0
|
@@ -15,6 +15,10 @@ export interface GridProps {
|
|
|
15
15
|
defaultColDef?: GridOptions["defaultColDef"];
|
|
16
16
|
columnDefs: ColDef[];
|
|
17
17
|
rowData: GridOptions["rowData"];
|
|
18
|
+
/**
|
|
19
|
+
* Whether select column is pinned. Defaults to "left".
|
|
20
|
+
*/
|
|
21
|
+
selectColumnPinned?: ColDef["pinned"];
|
|
18
22
|
noRowsOverlayText?: string;
|
|
19
23
|
postSortRows?: GridOptions["postSortRows"];
|
|
20
24
|
animateRows?: boolean;
|
|
@@ -53,4 +57,4 @@ export interface GridProps {
|
|
|
53
57
|
/**
|
|
54
58
|
* Wrapper for AgGrid to add commonly used functionality.
|
|
55
59
|
*/
|
|
56
|
-
export declare const Grid: ({ "data-testid": dataTestId, rowSelection, suppressColumnVirtualization, theme, sizeColumns, ...params }: GridProps) => JSX.Element;
|
|
60
|
+
export declare const Grid: ({ "data-testid": dataTestId, rowSelection, suppressColumnVirtualization, theme, sizeColumns, selectColumnPinned, ...params }: GridProps) => JSX.Element;
|
|
@@ -6,3 +6,9 @@
|
|
|
6
6
|
* but there's no way to enforce that, so it would lead to bugs.
|
|
7
7
|
*/
|
|
8
8
|
export declare const useTimeoutHook: () => (fn: () => void, waitTimeMs: number) => void;
|
|
9
|
+
interface IntervalHookProps {
|
|
10
|
+
timeoutMs: number;
|
|
11
|
+
callback: () => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const useIntervalHook: ({ callback, timeoutMs }: IntervalHookProps) => void;
|
|
14
|
+
export {};
|
package/dist/step-ag-grid.esm.js
CHANGED
|
@@ -3,7 +3,7 @@ import { LuiMiniSpinner, LuiIcon, LuiButton, LuiCheckboxInput, LuiButtonGroup }
|
|
|
3
3
|
import { AgGridReact } from 'ag-grid-react';
|
|
4
4
|
import { negate, isEmpty, xorBy, last, difference, omit, sortBy, findIndex, debounce as debounce$1, delay, partition, pick, groupBy, fromPairs, toPairs, defer as defer$1, sumBy, compact, remove, castArray, flatten, isEqual } from 'lodash-es';
|
|
5
5
|
import * as React from 'react';
|
|
6
|
-
import { createContext, useContext, useRef, useCallback, useState,
|
|
6
|
+
import { createContext, useContext, useEffect, useRef, useCallback, useState, useMemo, forwardRef, useLayoutEffect, memo, useReducer, cloneElement, useImperativeHandle, Fragment as Fragment$1 } from 'react';
|
|
7
7
|
import ReactDOM, { unstable_batchedUpdates, flushSync, createPortal } from 'react-dom';
|
|
8
8
|
import require$$0$1 from 'util';
|
|
9
9
|
import * as testUtils from 'react-dom/test-utils';
|
|
@@ -278,6 +278,50 @@ var GridUpdatingContext = createContext({
|
|
|
278
278
|
updatedDep: 0
|
|
279
279
|
});
|
|
280
280
|
|
|
281
|
+
/**
|
|
282
|
+
* Cancels timeouts on scope being destroyed.
|
|
283
|
+
*
|
|
284
|
+
* This could almost be a debounce, but debounce tracks by function reference, this tracks by hook reference.
|
|
285
|
+
* This could have been implemented using debounce if the callers function was wrapped in useCallback,
|
|
286
|
+
* but there's no way to enforce that, so it would lead to bugs.
|
|
287
|
+
*/
|
|
288
|
+
var useTimeoutHook = function () {
|
|
289
|
+
var timeout = useRef();
|
|
290
|
+
/**
|
|
291
|
+
* Clear any pending timeouts.
|
|
292
|
+
*/
|
|
293
|
+
var clearTimeouts = function () {
|
|
294
|
+
if (timeout.current) {
|
|
295
|
+
var tc = timeout.current;
|
|
296
|
+
timeout.current = undefined;
|
|
297
|
+
clearTimeout(tc);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* Call this when your action has completed.
|
|
302
|
+
*/
|
|
303
|
+
var invoke = useCallback(function (fn, waitTimeMs) {
|
|
304
|
+
clearTimeouts();
|
|
305
|
+
timeout.current = setTimeout(fn, waitTimeMs);
|
|
306
|
+
}, []);
|
|
307
|
+
/**
|
|
308
|
+
* Clear timeout on loss of scope.
|
|
309
|
+
*/
|
|
310
|
+
useEffect(function () {
|
|
311
|
+
return function () { return clearTimeouts(); };
|
|
312
|
+
}, []);
|
|
313
|
+
return invoke;
|
|
314
|
+
};
|
|
315
|
+
var useIntervalHook = function (_a) {
|
|
316
|
+
var callback = _a.callback, timeoutMs = _a.timeoutMs;
|
|
317
|
+
useEffect(function () {
|
|
318
|
+
var interval = setInterval(callback, timeoutMs);
|
|
319
|
+
return function () {
|
|
320
|
+
clearInterval(interval);
|
|
321
|
+
};
|
|
322
|
+
});
|
|
323
|
+
};
|
|
324
|
+
|
|
281
325
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
282
326
|
|
|
283
327
|
function getDefaultExportFromCjs (x) {
|
|
@@ -669,11 +713,12 @@ var GridHeaderSelect = function (_a) {
|
|
|
669
713
|
*/
|
|
670
714
|
var Grid = function (_a) {
|
|
671
715
|
var _b, _c, _d;
|
|
672
|
-
var dataTestId = _a["data-testid"], _e = _a.rowSelection, rowSelection = _e === void 0 ? "multiple" : _e, _f = _a.suppressColumnVirtualization, suppressColumnVirtualization = _f === void 0 ? true : _f, _g = _a.theme, theme = _g === void 0 ? "ag-theme-alpine" : _g, _h = _a.sizeColumns, sizeColumns = _h === void 0 ? "auto
|
|
673
|
-
var
|
|
674
|
-
var
|
|
716
|
+
var dataTestId = _a["data-testid"], _e = _a.rowSelection, rowSelection = _e === void 0 ? "multiple" : _e, _f = _a.suppressColumnVirtualization, suppressColumnVirtualization = _f === void 0 ? true : _f, _g = _a.theme, theme = _g === void 0 ? "ag-theme-alpine" : _g, _h = _a.sizeColumns, sizeColumns = _h === void 0 ? "auto" : _h, _j = _a.selectColumnPinned, selectColumnPinned = _j === void 0 ? null : _j, params = __rest(_a, ["data-testid", "rowSelection", "suppressColumnVirtualization", "theme", "sizeColumns", "selectColumnPinned"]);
|
|
717
|
+
var _k = useContext(GridContext), gridReady = _k.gridReady, setApis = _k.setApis, prePopupOps = _k.prePopupOps, ensureRowVisible = _k.ensureRowVisible, getFirstRowId = _k.getFirstRowId, selectRowsById = _k.selectRowsById, focusByRowById = _k.focusByRowById, ensureSelectedRowIsVisible = _k.ensureSelectedRowIsVisible, autoSizeColumns = _k.autoSizeColumns, sizeColumnsToFit = _k.sizeColumnsToFit, externallySelectedItemsAreInSync = _k.externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync = _k.setExternallySelectedItemsAreInSync, isExternalFilterPresent = _k.isExternalFilterPresent, doesExternalFilterPass = _k.doesExternalFilterPass, setOnCellEditingComplete = _k.setOnCellEditingComplete;
|
|
718
|
+
var _l = useContext(GridUpdatingContext), checkUpdating = _l.checkUpdating, updatedDep = _l.updatedDep, isUpdating = _l.isUpdating;
|
|
719
|
+
var gridDivRef = useRef(null);
|
|
675
720
|
var lastSelectedIds = useRef([]);
|
|
676
|
-
var
|
|
721
|
+
var _m = useState(false), staleGrid = _m[0], setStaleGrid = _m[1];
|
|
677
722
|
var postSortRows = usePostSortRowsHook({ setStaleGrid: setStaleGrid });
|
|
678
723
|
/**
|
|
679
724
|
* onContentSize should only be called at maximum twice.
|
|
@@ -682,30 +727,47 @@ var Grid = function (_a) {
|
|
|
682
727
|
*/
|
|
683
728
|
var hasSetContentSize = useRef(false);
|
|
684
729
|
var hasSetContentSizeEmpty = useRef(false);
|
|
730
|
+
var needsAutoSize = useRef(false);
|
|
685
731
|
var setInitialContentSize = useCallback(function () {
|
|
686
|
-
var
|
|
732
|
+
var _a;
|
|
733
|
+
if (!((_a = gridDivRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth)) {
|
|
734
|
+
// Don't resize grids if they are offscreen as it doesn't work.
|
|
735
|
+
needsAutoSize.current = true;
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
var skipHeader = sizeColumns === "auto-skip-headers" && !isEmpty(params.rowData);
|
|
687
739
|
if (sizeColumns === "auto" || skipHeader) {
|
|
688
740
|
var result = autoSizeColumns({ skipHeader: skipHeader, userSizedColIds: userSizedColIds.current });
|
|
689
741
|
if (isEmpty(params.rowData)) {
|
|
690
|
-
if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
|
|
742
|
+
if (!hasSetContentSizeEmpty.current && result && !hasSetContentSize.current) {
|
|
691
743
|
hasSetContentSizeEmpty.current = true;
|
|
692
|
-
params.onContentSize &&
|
|
744
|
+
params.onContentSize && params.onContentSize(result);
|
|
693
745
|
}
|
|
694
746
|
}
|
|
695
747
|
else {
|
|
696
|
-
if (!hasSetContentSize.current) {
|
|
748
|
+
if (result && !hasSetContentSize.current) {
|
|
697
749
|
hasSetContentSize.current = true;
|
|
698
|
-
params.onContentSize &&
|
|
750
|
+
params.onContentSize && params.onContentSize(result);
|
|
699
751
|
}
|
|
700
752
|
}
|
|
701
753
|
}
|
|
702
754
|
if (sizeColumns !== "none") {
|
|
703
755
|
sizeColumnsToFit();
|
|
704
756
|
}
|
|
757
|
+
needsAutoSize.current = false;
|
|
705
758
|
}, [autoSizeColumns, params, sizeColumns, sizeColumnsToFit]);
|
|
706
759
|
/**
|
|
707
|
-
*
|
|
760
|
+
* Auto-size windows that had deferred auto-size
|
|
708
761
|
*/
|
|
762
|
+
useIntervalHook({
|
|
763
|
+
callback: function () {
|
|
764
|
+
if (needsAutoSize.current) {
|
|
765
|
+
needsAutoSize.current = false;
|
|
766
|
+
setInitialContentSize();
|
|
767
|
+
}
|
|
768
|
+
},
|
|
769
|
+
timeoutMs: 1000
|
|
770
|
+
});
|
|
709
771
|
var previousGridReady = useRef(gridReady);
|
|
710
772
|
useEffect(function () {
|
|
711
773
|
if (!previousGridReady.current && gridReady) {
|
|
@@ -829,6 +891,7 @@ var Grid = function (_a) {
|
|
|
829
891
|
editable: false,
|
|
830
892
|
minWidth: 42,
|
|
831
893
|
maxWidth: 42,
|
|
894
|
+
pinned: selectColumnPinned,
|
|
832
895
|
headerComponentParams: {
|
|
833
896
|
exportable: false
|
|
834
897
|
},
|
|
@@ -854,6 +917,7 @@ var Grid = function (_a) {
|
|
|
854
917
|
params.selectable,
|
|
855
918
|
params.readOnly,
|
|
856
919
|
(_b = params.defaultColDef) === null || _b === void 0 ? void 0 : _b.editable,
|
|
920
|
+
selectColumnPinned,
|
|
857
921
|
rowSelection,
|
|
858
922
|
clickSelectorCheckboxWhenContainingCellClicked,
|
|
859
923
|
]);
|
|
@@ -998,7 +1062,12 @@ var Grid = function (_a) {
|
|
|
998
1062
|
// This auto-sizes based on updatingContext completing
|
|
999
1063
|
colIdsEdited.current.add(colId);
|
|
1000
1064
|
// This auto-sizes immediately in case it was an in place update
|
|
1001
|
-
!isUpdating() &&
|
|
1065
|
+
!isUpdating() &&
|
|
1066
|
+
autoSizeColumns({
|
|
1067
|
+
skipHeader: skipHeader,
|
|
1068
|
+
userSizedColIds: userSizedColIds.current,
|
|
1069
|
+
colIds: [colId]
|
|
1070
|
+
});
|
|
1002
1071
|
}
|
|
1003
1072
|
}
|
|
1004
1073
|
}, [autoSizeColumns, isUpdating, sizeColumns]);
|
|
@@ -1047,7 +1116,12 @@ var Grid = function (_a) {
|
|
|
1047
1116
|
}
|
|
1048
1117
|
}, []);
|
|
1049
1118
|
setOnCellEditingComplete(params.onCellEditingComplete);
|
|
1050
|
-
return (jsx("div", __assign({ "data-testid": dataTestId, className: clsx("Grid-container", theme, staleGrid && "Grid-sortIsStale", gridReady && params.rowData && "Grid-ready") }, { children: jsx("div", __assign({ style: { flex: 1 } }, { children: jsx(AgGridReact, { animateRows: params.animateRows, rowClassRules: params.rowClassRules, getRowId: function (params) { return "".concat(params.data.id); }, suppressRowClickSelection: true, rowSelection: rowSelection, suppressBrowserResizeObserver: true, onGridSizeChanged: onGridSizeChanged, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true,
|
|
1119
|
+
return (jsx("div", __assign({ "data-testid": dataTestId, className: clsx("Grid-container", theme, staleGrid && "Grid-sortIsStale", gridReady && params.rowData && "Grid-ready") }, { children: jsx("div", __assign({ style: { flex: 1 }, ref: gridDivRef }, { children: jsx(AgGridReact, { animateRows: params.animateRows, rowClassRules: params.rowClassRules, getRowId: function (params) { return "".concat(params.data.id); }, suppressRowClickSelection: true, rowSelection: rowSelection, suppressBrowserResizeObserver: true, onGridSizeChanged: onGridSizeChanged, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onColumnVisible: function () {
|
|
1120
|
+
setInitialContentSize();
|
|
1121
|
+
}, onRowDataChanged: onRowDataChanged, onCellKeyPress: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, onCellEditingStarted: refreshSelectedRows, domLayout: params.domLayout, onCellEditingStopped: onCellEditingStopped, onColumnResized: onColumnResized, defaultColDef: __assign({ minWidth: 48 }, omit(params.defaultColDef, ["editable"])), columnDefs: columnDefsAdjusted, rowData: params.rowData, noRowsOverlayComponent: GridNoRowsOverlay, noRowsOverlayComponentParams: {
|
|
1122
|
+
rowData: params.rowData,
|
|
1123
|
+
noRowsOverlayText: params.noRowsOverlayText
|
|
1124
|
+
}, onModelUpdated: onModelUpdated, onGridReady: onGridReady, onSortChanged: ensureSelectedRowIsVisible, postSortRows: (_d = params.postSortRows) !== null && _d !== void 0 ? _d : postSortRows, onSelectionChanged: synchroniseExternalStateToGridSelection, onColumnMoved: params.onColumnMoved, alwaysShowVerticalScroll: params.alwaysShowVerticalScroll, isExternalFilterPresent: isExternalFilterPresent, doesExternalFilterPass: doesExternalFilterPass, maintainColumnOrder: true }) })) })));
|
|
1051
1125
|
};
|
|
1052
1126
|
|
|
1053
1127
|
var GridPopoverContext = createContext({
|
|
@@ -3138,41 +3212,6 @@ var GridFilters = function (_a) {
|
|
|
3138
3212
|
return jsx("div", __assign({ className: "Grid-container-filters" }, { children: children }));
|
|
3139
3213
|
};
|
|
3140
3214
|
|
|
3141
|
-
/**
|
|
3142
|
-
* Cancels timeouts on scope being destroyed.
|
|
3143
|
-
*
|
|
3144
|
-
* This could almost be a debounce, but debounce tracks by function reference, this tracks by hook reference.
|
|
3145
|
-
* This could have been implemented using debounce if the callers function was wrapped in useCallback,
|
|
3146
|
-
* but there's no way to enforce that, so it would lead to bugs.
|
|
3147
|
-
*/
|
|
3148
|
-
var useTimeoutHook = function () {
|
|
3149
|
-
var timeout = useRef();
|
|
3150
|
-
/**
|
|
3151
|
-
* Clear any pending timeouts.
|
|
3152
|
-
*/
|
|
3153
|
-
var clearTimeouts = function () {
|
|
3154
|
-
if (timeout.current) {
|
|
3155
|
-
var tc = timeout.current;
|
|
3156
|
-
timeout.current = undefined;
|
|
3157
|
-
clearTimeout(tc);
|
|
3158
|
-
}
|
|
3159
|
-
};
|
|
3160
|
-
/**
|
|
3161
|
-
* Call this when your action has completed.
|
|
3162
|
-
*/
|
|
3163
|
-
var invoke = useCallback(function (fn, waitTimeMs) {
|
|
3164
|
-
clearTimeouts();
|
|
3165
|
-
timeout.current = setTimeout(fn, waitTimeMs);
|
|
3166
|
-
}, []);
|
|
3167
|
-
/**
|
|
3168
|
-
* Clear timeout on loss of scope.
|
|
3169
|
-
*/
|
|
3170
|
-
useEffect(function () {
|
|
3171
|
-
return function () { return clearTimeouts(); };
|
|
3172
|
-
}, []);
|
|
3173
|
-
return invoke;
|
|
3174
|
-
};
|
|
3175
|
-
|
|
3176
3215
|
/**
|
|
3177
3216
|
* Defers state change up to a minimum time since last state change.
|
|
3178
3217
|
*/
|
|
@@ -5055,11 +5094,11 @@ var GridContextProvider = function (props) {
|
|
|
5055
5094
|
}, [gridApi]);
|
|
5056
5095
|
var addExternalFilter = function (filter) {
|
|
5057
5096
|
externalFilters.current.push(filter);
|
|
5058
|
-
onFilterChanged();
|
|
5097
|
+
onFilterChanged().then();
|
|
5059
5098
|
};
|
|
5060
5099
|
var removeExternalFilter = function (filter) {
|
|
5061
5100
|
remove(externalFilters.current, function (v) { return v === filter; });
|
|
5062
|
-
onFilterChanged();
|
|
5101
|
+
onFilterChanged().then();
|
|
5063
5102
|
};
|
|
5064
5103
|
var isExternalFilterPresent = function () { return externalFilters.current.length > 0; };
|
|
5065
5104
|
var doesExternalFilterPass = function (node) {
|