@linzjs/step-ag-grid 7.10.1 → 7.11.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/index.js +79 -29
- package/dist/index.js.map +1 -1
- package/dist/src/components/Grid.d.ts +1 -0
- package/dist/src/contexts/GridContext.d.ts +3 -1
- package/dist/step-ag-grid.esm.js +79 -29
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +34 -6
- package/src/contexts/GridContext.tsx +10 -5
- package/src/contexts/GridContextProvider.tsx +22 -17
- package/src/stories/grid/GridPopoutBearing.stories.tsx +1 -0
- package/src/stories/grid/GridReadOnly.stories.tsx +1 -0
- package/src/utils/bearing.ts +2 -2
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { GridApi, RowNode } from "ag-grid-community";
|
|
3
3
|
import { GridBaseRow } from "../components/Grid";
|
|
4
4
|
export interface GridContextType {
|
|
5
|
-
gridReady:
|
|
5
|
+
gridReady: boolean;
|
|
6
6
|
setGridApi: (gridApi: GridApi | undefined) => void;
|
|
7
7
|
setQuickFilter: (quickFilter: string) => void;
|
|
8
8
|
editingCells: () => boolean;
|
|
@@ -23,5 +23,7 @@ export interface GridContextType {
|
|
|
23
23
|
field?: string;
|
|
24
24
|
}, fnUpdate: (selectedRows: any[]) => Promise<boolean>, setSaving?: (saving: boolean) => void, tabDirection?: 1 | 0 | -1) => Promise<boolean>;
|
|
25
25
|
redrawRows: (rowNodes?: RowNode[]) => void;
|
|
26
|
+
setExternallySelectedItemsAreInSync: (inSync: boolean) => void;
|
|
27
|
+
waitForExternallySelectedItemsToBeInSync: () => Promise<void>;
|
|
26
28
|
}
|
|
27
29
|
export declare const GridContext: import("react").Context<GridContextType>;
|
package/dist/step-ag-grid.esm.js
CHANGED
|
@@ -1954,10 +1954,7 @@ var MenuRadioGroupFr = function (_a, externalRef) {
|
|
|
1954
1954
|
var MenuRadioGroup = forwardRef(MenuRadioGroupFr);
|
|
1955
1955
|
|
|
1956
1956
|
var GridContext = createContext({
|
|
1957
|
-
gridReady:
|
|
1958
|
-
console.error("no context provider for gridReady");
|
|
1959
|
-
return false;
|
|
1960
|
-
},
|
|
1957
|
+
gridReady: false,
|
|
1961
1958
|
setGridApi: function () {
|
|
1962
1959
|
console.error("no context provider for setGridApi");
|
|
1963
1960
|
},
|
|
@@ -2024,7 +2021,16 @@ var GridContext = createContext({
|
|
|
2024
2021
|
}); },
|
|
2025
2022
|
redrawRows: function () {
|
|
2026
2023
|
console.error("no context provider for redrawRows");
|
|
2027
|
-
}
|
|
2024
|
+
},
|
|
2025
|
+
setExternallySelectedItemsAreInSync: function () {
|
|
2026
|
+
console.error("no context provider for setExternallySelectedItemsAreInSync");
|
|
2027
|
+
},
|
|
2028
|
+
waitForExternallySelectedItemsToBeInSync: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2029
|
+
return __generator(this, function (_a) {
|
|
2030
|
+
console.error("no context provider for waitForExternallySelectedItemsToBeInSync");
|
|
2031
|
+
return [2 /*return*/];
|
|
2032
|
+
});
|
|
2033
|
+
}); }
|
|
2028
2034
|
});
|
|
2029
2035
|
|
|
2030
2036
|
var GridUpdatingContext = createContext({
|
|
@@ -2048,19 +2054,13 @@ var GridUpdatingContext = createContext({
|
|
|
2048
2054
|
*/
|
|
2049
2055
|
var GridContextProvider = function (props) {
|
|
2050
2056
|
var modifyUpdating = useContext(GridUpdatingContext).modifyUpdating;
|
|
2051
|
-
var
|
|
2057
|
+
var _a = useState(), gridApi = _a[0], _setGridApi = _a[1];
|
|
2058
|
+
var _b = useState(false), gridReady = _b[0], setGridReady = _b[1];
|
|
2052
2059
|
var idsBeforeUpdate = useRef([]);
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
*/
|
|
2058
|
-
var gridReady = function () { return gridApiRef.current != null; };
|
|
2059
|
-
/**
|
|
2060
|
-
* Set current ref to grid api.
|
|
2061
|
-
*/
|
|
2062
|
-
var setGridApi = function (_gridApi) {
|
|
2063
|
-
gridApiRef.current = _gridApi;
|
|
2060
|
+
var externallySelectedItemsAreInSync = useRef(false);
|
|
2061
|
+
var setGridApi = function (gridApi) {
|
|
2062
|
+
_setGridApi(gridApi);
|
|
2063
|
+
setGridReady(!!gridApi);
|
|
2064
2064
|
};
|
|
2065
2065
|
/**
|
|
2066
2066
|
* Wraps things that require gridApi in common handling, for when gridApi not present.
|
|
@@ -2072,7 +2072,6 @@ var GridContextProvider = function (props) {
|
|
|
2072
2072
|
if (!noApiFn) {
|
|
2073
2073
|
noApiFn = (function () { });
|
|
2074
2074
|
}
|
|
2075
|
-
var gridApi = gridApiRef.current;
|
|
2076
2075
|
return gridApi ? hasApiFn(gridApi) : noApiFn();
|
|
2077
2076
|
};
|
|
2078
2077
|
/**
|
|
@@ -2130,7 +2129,7 @@ var GridContextProvider = function (props) {
|
|
|
2130
2129
|
* @param retryCount Table updates may not be present when this is called, so retry is needed.
|
|
2131
2130
|
*/
|
|
2132
2131
|
var _selectRowsWithOptionalFlash = function (rowIds, select, flash, retryCount) {
|
|
2133
|
-
if (retryCount === void 0) { retryCount =
|
|
2132
|
+
if (retryCount === void 0) { retryCount = 15; }
|
|
2134
2133
|
return gridApiOp(function (gridApi) {
|
|
2135
2134
|
var _a;
|
|
2136
2135
|
var rowNodes = rowIds ? _rowIdsToNodes(rowIds) : _getNewNodes();
|
|
@@ -2322,6 +2321,29 @@ var GridContextProvider = function (props) {
|
|
|
2322
2321
|
gridApi.tabToPreviousCell();
|
|
2323
2322
|
});
|
|
2324
2323
|
};
|
|
2324
|
+
var setExternallySelectedItemsAreInSync = function (inSync) {
|
|
2325
|
+
externallySelectedItemsAreInSync.current = inSync;
|
|
2326
|
+
};
|
|
2327
|
+
var waitForExternallySelectedItemsToBeInSync = function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
2328
|
+
var i;
|
|
2329
|
+
return __generator(this, function (_a) {
|
|
2330
|
+
switch (_a.label) {
|
|
2331
|
+
case 0:
|
|
2332
|
+
i = 0;
|
|
2333
|
+
_a.label = 1;
|
|
2334
|
+
case 1:
|
|
2335
|
+
if (!(i < 5000 / 200 && !externallySelectedItemsAreInSync.current)) return [3 /*break*/, 4];
|
|
2336
|
+
return [4 /*yield*/, wait$2(200)];
|
|
2337
|
+
case 2:
|
|
2338
|
+
_a.sent();
|
|
2339
|
+
_a.label = 3;
|
|
2340
|
+
case 3:
|
|
2341
|
+
i++;
|
|
2342
|
+
return [3 /*break*/, 1];
|
|
2343
|
+
case 4: return [2 /*return*/];
|
|
2344
|
+
}
|
|
2345
|
+
});
|
|
2346
|
+
}); };
|
|
2325
2347
|
return (jsx(GridContext.Provider, __assign({ value: {
|
|
2326
2348
|
gridReady: gridReady,
|
|
2327
2349
|
setGridApi: setGridApi,
|
|
@@ -2340,7 +2362,9 @@ var GridContextProvider = function (props) {
|
|
|
2340
2362
|
sizeColumnsToFit: sizeColumnsToFit,
|
|
2341
2363
|
stopEditing: stopEditing,
|
|
2342
2364
|
updatingCells: updatingCells,
|
|
2343
|
-
redrawRows: redrawRows
|
|
2365
|
+
redrawRows: redrawRows,
|
|
2366
|
+
setExternallySelectedItemsAreInSync: setExternallySelectedItemsAreInSync,
|
|
2367
|
+
waitForExternallySelectedItemsToBeInSync: waitForExternallySelectedItemsToBeInSync
|
|
2344
2368
|
} }, { children: props.children })));
|
|
2345
2369
|
};
|
|
2346
2370
|
|
|
@@ -2670,12 +2694,29 @@ var GridHeaderSelect = function (_a) {
|
|
|
2670
2694
|
*/
|
|
2671
2695
|
var Grid = function (params) {
|
|
2672
2696
|
var _a, _b, _c;
|
|
2673
|
-
var _d = useContext(GridContext), gridReady = _d.gridReady, setGridApi = _d.setGridApi, setQuickFilter = _d.setQuickFilter, ensureRowVisible = _d.ensureRowVisible, selectRowsById = _d.selectRowsById, ensureSelectedRowIsVisible = _d.ensureSelectedRowIsVisible, sizeColumnsToFit = _d.sizeColumnsToFit;
|
|
2697
|
+
var _d = useContext(GridContext), gridReady = _d.gridReady, setGridApi = _d.setGridApi, setQuickFilter = _d.setQuickFilter, ensureRowVisible = _d.ensureRowVisible, selectRowsById = _d.selectRowsById, ensureSelectedRowIsVisible = _d.ensureSelectedRowIsVisible, sizeColumnsToFit = _d.sizeColumnsToFit, setExternallySelectedItemsAreInSync = _d.setExternallySelectedItemsAreInSync;
|
|
2674
2698
|
var checkUpdating = useContext(GridUpdatingContext).checkUpdating;
|
|
2675
2699
|
var _e = useState(""), internalQuickFilter = _e[0], setInternalQuickFilter = _e[1];
|
|
2676
2700
|
var lastSelectedIds = useRef([]);
|
|
2677
2701
|
var _f = useState(false), staleGrid = _f[0], setStaleGrid = _f[1];
|
|
2678
2702
|
var postSortRows = usePostSortRowsHook({ setStaleGrid: setStaleGrid });
|
|
2703
|
+
/**
|
|
2704
|
+
* On data load select the first row of the grid if required.
|
|
2705
|
+
*/
|
|
2706
|
+
var hasSelectedFirstItem = useRef(false);
|
|
2707
|
+
useEffect(function () {
|
|
2708
|
+
if (!gridReady || !params.autoSelectFirstRow || hasSelectedFirstItem.current || !params.rowData)
|
|
2709
|
+
return;
|
|
2710
|
+
hasSelectedFirstItem.current = true;
|
|
2711
|
+
if (isNotEmpty(params.rowData)) {
|
|
2712
|
+
if (params.setExternalSelectedItems) {
|
|
2713
|
+
params.setExternalSelectedItems([params.rowData[0]]);
|
|
2714
|
+
}
|
|
2715
|
+
else {
|
|
2716
|
+
selectRowsById([params.rowData[0].id]);
|
|
2717
|
+
}
|
|
2718
|
+
}
|
|
2719
|
+
}, [gridReady, params, params.autoSelectFirstRow, params.rowData, selectRowsById]);
|
|
2679
2720
|
/**
|
|
2680
2721
|
* AgGrid checkbox select does not pass clicks within cell but not on the checkbox to checkbox.
|
|
2681
2722
|
* This passes the event to the checkbox when you click anywhere in the cell.
|
|
@@ -2692,36 +2733,45 @@ var Grid = function (params) {
|
|
|
2692
2733
|
*/
|
|
2693
2734
|
var synchroniseExternalStateToGridSelection = useCallback(function (_a) {
|
|
2694
2735
|
var api = _a.api;
|
|
2695
|
-
if (!params.externalSelectedItems || !params.setExternalSelectedItems)
|
|
2736
|
+
if (!params.externalSelectedItems || !params.setExternalSelectedItems) {
|
|
2737
|
+
setExternallySelectedItemsAreInSync(true);
|
|
2696
2738
|
return;
|
|
2739
|
+
}
|
|
2697
2740
|
var selectedRows = api.getSelectedRows();
|
|
2698
2741
|
// We don't want to update selected Items if it hasn't changed to prevent excess renders
|
|
2699
2742
|
if (params.externalSelectedItems.length != selectedRows.length ||
|
|
2700
2743
|
isNotEmpty(xorBy(selectedRows, params.externalSelectedItems, function (row) { return row.id; }))) {
|
|
2744
|
+
setExternallySelectedItemsAreInSync(false);
|
|
2701
2745
|
params.setExternalSelectedItems(__spreadArray([], selectedRows, true));
|
|
2702
2746
|
}
|
|
2703
|
-
|
|
2747
|
+
else {
|
|
2748
|
+
setExternallySelectedItemsAreInSync(true);
|
|
2749
|
+
}
|
|
2750
|
+
}, [params, setExternallySelectedItemsAreInSync]);
|
|
2704
2751
|
/**
|
|
2705
2752
|
* Synchronise externally selected items to grid.
|
|
2706
2753
|
* If new ids are selected scroll them into view.
|
|
2707
2754
|
*/
|
|
2708
2755
|
var synchroniseExternallySelectedItemsToGrid = useCallback(function () {
|
|
2709
|
-
if (!gridReady
|
|
2756
|
+
if (!gridReady)
|
|
2710
2757
|
return;
|
|
2711
|
-
if (!params.externalSelectedItems)
|
|
2758
|
+
if (!params.externalSelectedItems) {
|
|
2759
|
+
setExternallySelectedItemsAreInSync(true);
|
|
2712
2760
|
return;
|
|
2761
|
+
}
|
|
2713
2762
|
var selectedIds = params.externalSelectedItems.map(function (row) { return row.id; });
|
|
2714
2763
|
var lastNewId = last(difference(selectedIds, lastSelectedIds.current));
|
|
2715
2764
|
if (lastNewId != null)
|
|
2716
2765
|
ensureRowVisible(lastNewId);
|
|
2717
2766
|
lastSelectedIds.current = selectedIds;
|
|
2718
2767
|
selectRowsById(selectedIds);
|
|
2719
|
-
|
|
2768
|
+
setExternallySelectedItemsAreInSync(true);
|
|
2769
|
+
}, [gridReady, params.externalSelectedItems, ensureRowVisible, selectRowsById, setExternallySelectedItemsAreInSync]);
|
|
2720
2770
|
/**
|
|
2721
2771
|
* Synchronise quick filter to grid
|
|
2722
2772
|
*/
|
|
2723
2773
|
var updateQuickFilter = useCallback(function () {
|
|
2724
|
-
if (!gridReady
|
|
2774
|
+
if (!gridReady)
|
|
2725
2775
|
return;
|
|
2726
2776
|
if (params.quickFilter) {
|
|
2727
2777
|
setQuickFilter(internalQuickFilter);
|
|
@@ -3921,9 +3971,9 @@ var bearingCorrectionValueFormatter = function (params) {
|
|
|
3921
3971
|
return "–";
|
|
3922
3972
|
}
|
|
3923
3973
|
if (typeof value === "string") {
|
|
3924
|
-
return convertDDToDMS(bearingNumberParser(value), true,
|
|
3974
|
+
return convertDDToDMS(bearingNumberParser(value), true, true);
|
|
3925
3975
|
}
|
|
3926
|
-
return convertDDToDMS(value, true,
|
|
3976
|
+
return convertDDToDMS(value, true, true);
|
|
3927
3977
|
};
|
|
3928
3978
|
var bearingNumberParser = function (value) {
|
|
3929
3979
|
if (value === "")
|