@linzjs/step-ag-grid 33.0.0 → 34.0.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/src/components/PostSortRowsHook.test.d.ts +1 -0
- package/dist/src/components/gridForm/GridFormTextInput.d.ts +2 -1
- package/dist/src/utils/__tests__/storybookTestUtil.ts +1 -1
- package/dist/step-ag-grid.cjs +73 -20
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +73 -20
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/PostSortRowsHook.test.ts +300 -0
- package/src/components/PostSortRowsHook.ts +127 -24
- package/src/components/gridForm/GridFormTextInput.tsx +2 -1
- package/src/contexts/GridContextProvider.tsx +5 -9
- package/src/react-menu3/components/MenuList.tsx +1 -0
- package/src/stories/grid/GridInlineText.stories.tsx +20 -14
- package/src/stories/grid/GridSorting.stories.tsx +413 -3
- package/src/utils/__tests__/storybookTestUtil.ts +1 -1
package/dist/step-ag-grid.esm.js
CHANGED
|
@@ -60977,18 +60977,51 @@ const usePostSortRowsHook = ({ setStaleGrid }) => {
|
|
|
60977
60977
|
const previousQuickFilter = useRef("");
|
|
60978
60978
|
return useCallback(
|
|
60979
60979
|
({ api, nodes }) => {
|
|
60980
|
-
if (!api)
|
|
60980
|
+
if (!api || api.isDestroyed()) {
|
|
60981
|
+
return;
|
|
60982
|
+
}
|
|
60981
60983
|
const previousRowSortIndex = previousRowSortIndexRef.current;
|
|
60982
|
-
const
|
|
60983
|
-
return
|
|
60984
|
+
const copyCurrentSortSettings = () => {
|
|
60985
|
+
return api.getColumnState().map((row) => ({ colId: row.colId, sort: row.sort, sortIndex: row.sortIndex }));
|
|
60984
60986
|
};
|
|
60985
|
-
const
|
|
60987
|
+
const currentSortState = copyCurrentSortSettings();
|
|
60988
|
+
const sortedColIds = currentSortState.filter((col) => col.sort).sort((a, b) => (a.sortIndex ?? 0) - (b.sortIndex ?? 0)).map((col) => col.colId);
|
|
60989
|
+
const sortColumnEquals = {};
|
|
60990
|
+
sortedColIds.forEach((colId) => {
|
|
60991
|
+
const colDef = api.getColumn(colId)?.getColDef();
|
|
60992
|
+
if (colDef?.equals) {
|
|
60993
|
+
const equals = colDef.equals;
|
|
60994
|
+
sortColumnEquals[colId] = (a, b) => equals(a, b);
|
|
60995
|
+
} else if (colDef?.comparator) {
|
|
60996
|
+
const comparator = colDef.comparator;
|
|
60997
|
+
sortColumnEquals[colId] = (a, b, nodeA, nodeB) => comparator(a, b, nodeA, nodeB, false) === 0;
|
|
60998
|
+
} else {
|
|
60999
|
+
sortColumnEquals[colId] = (a, b) => a === b;
|
|
61000
|
+
}
|
|
61001
|
+
});
|
|
61002
|
+
const getSortValues = (node) => node ? sortedColIds.map((colId) => api.getCellValue({ rowNode: node, colKey: colId })) : [];
|
|
61003
|
+
const snapshotNode = (node) => node ? { data: node.data, id: node.id } : void 0;
|
|
61004
|
+
const sortValuesChanged = (previous, node, currentValues) => !previous || sortedColIds.some(
|
|
61005
|
+
(colId, i) => !sortColumnEquals[colId](previous.values[i], currentValues[i], previous.node, node)
|
|
61006
|
+
);
|
|
60986
61007
|
const backupSortOrder = () => {
|
|
60987
|
-
for (const x in previousRowSortIndex)
|
|
60988
|
-
|
|
61008
|
+
for (const x in previousRowSortIndex) {
|
|
61009
|
+
delete previousRowSortIndex[x];
|
|
61010
|
+
}
|
|
61011
|
+
nodes.forEach(
|
|
61012
|
+
(node, index) => previousRowSortIndex[`${node.data.id}`] = {
|
|
61013
|
+
index,
|
|
61014
|
+
values: getSortValues(node),
|
|
61015
|
+
node: snapshotNode(node)
|
|
61016
|
+
}
|
|
61017
|
+
);
|
|
61018
|
+
};
|
|
61019
|
+
const isFirstSortColumn = (row) => {
|
|
61020
|
+
return row.sort && [0, null].includes(row.sortIndex ?? null);
|
|
61021
|
+
};
|
|
61022
|
+
const isSameColumnAndDifferentSort = (col1, col2) => {
|
|
61023
|
+
return col1 && col2 && col1.colId === col2.colId && col1.sort != col2.sort;
|
|
60989
61024
|
};
|
|
60990
|
-
const isFirstSortColumn = (row) => row.sort && [0, null].includes(row.sortIndex ?? null);
|
|
60991
|
-
const isSameColumnAndDifferentSort = (col1, col2) => col1 && col2 && col1.colId === col2.colId && col1.sort != col2.sort;
|
|
60992
61025
|
const restorePreviousSortColumnState = () => api.applyColumnState({ state: previousColSort.current });
|
|
60993
61026
|
const sortNodesByPreviousSort = () => {
|
|
60994
61027
|
nodes.sort(
|
|
@@ -60999,25 +61032,27 @@ const usePostSortRowsHook = ({ setStaleGrid }) => {
|
|
|
60999
61032
|
initialised.current = true;
|
|
61000
61033
|
previousColSort.current = copyCurrentSortSettings();
|
|
61001
61034
|
}
|
|
61002
|
-
const newSortOrder = JSON.stringify(
|
|
61035
|
+
const newSortOrder = JSON.stringify(currentSortState);
|
|
61003
61036
|
let sortOrderChanged = newSortOrder != lastSortOrderHash.current;
|
|
61004
|
-
const quickFilter = api.getQuickFilter();
|
|
61037
|
+
const quickFilter = api.getQuickFilter() ?? "";
|
|
61005
61038
|
if (previousQuickFilter.current != quickFilter) {
|
|
61006
|
-
previousQuickFilter.current = quickFilter
|
|
61039
|
+
previousQuickFilter.current = quickFilter;
|
|
61007
61040
|
sortOrderChanged = true;
|
|
61008
61041
|
}
|
|
61009
61042
|
if (isEmpty(previousRowSortIndex)) {
|
|
61010
61043
|
backupSortOrder();
|
|
61011
61044
|
}
|
|
61012
61045
|
if (sortOrderChanged) {
|
|
61013
|
-
const thisFirstCol =
|
|
61046
|
+
const thisFirstCol = currentSortState.find(isFirstSortColumn);
|
|
61014
61047
|
const previousFirstCol = previousColSort.current.find(isFirstSortColumn);
|
|
61015
61048
|
const wasSortChangedOnSameColumn = previousFirstCol && (!thisFirstCol || isSameColumnAndDifferentSort(previousFirstCol, thisFirstCol));
|
|
61016
61049
|
if (sortWasStale.current && wasSortChangedOnSameColumn) {
|
|
61017
61050
|
sortWasStale.current = false;
|
|
61018
61051
|
setStaleGrid(false);
|
|
61019
61052
|
lastSortOrderHash.current = "";
|
|
61020
|
-
|
|
61053
|
+
defer(() => {
|
|
61054
|
+
restorePreviousSortColumnState();
|
|
61055
|
+
});
|
|
61021
61056
|
} else {
|
|
61022
61057
|
if (sortWasStale.current) {
|
|
61023
61058
|
sortWasStale.current = false;
|
|
@@ -61035,7 +61070,7 @@ const usePostSortRowsHook = ({ setStaleGrid }) => {
|
|
|
61035
61070
|
for (const node of nodes) {
|
|
61036
61071
|
const psr = previousRowSortIndex[`${node.data.id}`];
|
|
61037
61072
|
if (psr) {
|
|
61038
|
-
if (psr
|
|
61073
|
+
if (sortValuesChanged(psr, node, getSortValues(node))) {
|
|
61039
61074
|
if (firstChangedNodeIndex === -1) firstChangedNodeIndex = index;
|
|
61040
61075
|
changedRowCount++;
|
|
61041
61076
|
}
|
|
@@ -61048,7 +61083,11 @@ const usePostSortRowsHook = ({ setStaleGrid }) => {
|
|
|
61048
61083
|
let wasStale = false;
|
|
61049
61084
|
if (changedRowCount === 0 && newRowCount === 1) {
|
|
61050
61085
|
const newIndex = index - 1;
|
|
61051
|
-
previousRowSortIndex[`${lastNewNode?.data.id}`] = {
|
|
61086
|
+
previousRowSortIndex[`${lastNewNode?.data.id}`] = {
|
|
61087
|
+
index: newIndex,
|
|
61088
|
+
values: getSortValues(lastNewNode),
|
|
61089
|
+
node: snapshotNode(lastNewNode)
|
|
61090
|
+
};
|
|
61052
61091
|
wasStale = true;
|
|
61053
61092
|
} else if (changedRowCount === 2 && newRowCount === 0) {
|
|
61054
61093
|
backupSortOrder();
|
|
@@ -61056,15 +61095,27 @@ const usePostSortRowsHook = ({ setStaleGrid }) => {
|
|
|
61056
61095
|
} else if (changedRowCount > 1 && newRowCount === 1) {
|
|
61057
61096
|
previousRowSortIndex[`${lastNewNode?.data.id}`] = {
|
|
61058
61097
|
index: firstChangedNodeIndex + 0.5,
|
|
61059
|
-
|
|
61098
|
+
values: getSortValues(lastNewNode),
|
|
61099
|
+
node: snapshotNode(lastNewNode)
|
|
61060
61100
|
};
|
|
61061
61101
|
wasStale = true;
|
|
61062
61102
|
if (lastNewNode) {
|
|
61063
61103
|
redrawRows();
|
|
61064
61104
|
}
|
|
61065
61105
|
} else if (changedRowCount == 1 && newRowCount === 0) {
|
|
61106
|
+
const changedNode = nodes[firstChangedNodeIndex];
|
|
61107
|
+
const previousEntry = changedNode && previousRowSortIndex[`${changedNode.data.id}`];
|
|
61108
|
+
if (changedNode && previousEntry) {
|
|
61109
|
+
previousRowSortIndex[`${changedNode.data.id}`] = {
|
|
61110
|
+
index: previousEntry.index,
|
|
61111
|
+
values: getSortValues(changedNode),
|
|
61112
|
+
node: snapshotNode(changedNode)
|
|
61113
|
+
};
|
|
61114
|
+
}
|
|
61115
|
+
wasStale = true;
|
|
61116
|
+
} else if (changedRowCount === 0 && newRowCount === 0 && nodes.length === Object.keys(previousRowSortIndex).length) {
|
|
61066
61117
|
wasStale = true;
|
|
61067
|
-
} else
|
|
61118
|
+
} else {
|
|
61068
61119
|
backupSortOrder();
|
|
61069
61120
|
}
|
|
61070
61121
|
if (wasStale) {
|
|
@@ -65117,9 +65168,11 @@ const GridContextProvider = (props) => {
|
|
|
65117
65168
|
return ok;
|
|
65118
65169
|
}
|
|
65119
65170
|
if (ok) {
|
|
65120
|
-
|
|
65121
|
-
gridApi2.
|
|
65122
|
-
|
|
65171
|
+
defer(() => {
|
|
65172
|
+
if (!gridApi2.isDestroyed()) {
|
|
65173
|
+
gridApi2.refreshClientSideRowModel();
|
|
65174
|
+
}
|
|
65175
|
+
});
|
|
65123
65176
|
}
|
|
65124
65177
|
void (async () => {
|
|
65125
65178
|
const postPopupFocusedCell = gridApi2.getFocusedCell();
|