@linzjs/step-ag-grid 33.0.0 → 34.0.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.
@@ -60977,18 +60977,51 @@ const usePostSortRowsHook = ({ setStaleGrid }) => {
60977
60977
  const previousQuickFilter = useRef("");
60978
60978
  return useCallback(
60979
60979
  ({ api, nodes }) => {
60980
- if (!api) return;
60980
+ if (!api || api.isDestroyed()) {
60981
+ return;
60982
+ }
60981
60983
  const previousRowSortIndex = previousRowSortIndexRef.current;
60982
- const hashNode = (node) => {
60983
- return node ? JSON.stringify(node.data) : "";
60984
+ const copyCurrentSortSettings = () => {
60985
+ return api.getColumnState().map((row) => ({ colId: row.colId, sort: row.sort, sortIndex: row.sortIndex }));
60984
60986
  };
60985
- const copyCurrentSortSettings = () => api.getColumnState().map((row) => ({ colId: row.colId, sort: row.sort, sortIndex: row.sortIndex }));
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) delete previousRowSortIndex[x];
60988
- nodes.forEach((node, index) => previousRowSortIndex[`${node.data.id}`] = { index, hash: hashNode(node) });
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(copyCurrentSortSettings());
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 = copyCurrentSortSettings().find(isFirstSortColumn);
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
- restorePreviousSortColumnState();
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.hash != hashNode(node)) {
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}`] = { index: newIndex, hash: hashNode(lastNewNode) };
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
- hash: hashNode(lastNewNode)
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 if (changedRowCount !== 0 || newRowCount != 0) {
61118
+ } else {
61068
61119
  backupSortOrder();
61069
61120
  }
61070
61121
  if (wasStale) {
@@ -61119,7 +61170,7 @@ const Grid = ({
61119
61170
  // ─── Spread Remaining Params ──────────────────
61120
61171
  ...params
61121
61172
  }) => {
61122
- if (isChromatic()) {
61173
+ if (isChromatic() && sizeColumns !== "fit") {
61123
61174
  sizeColumns = "none";
61124
61175
  }
61125
61176
  const {
@@ -61354,13 +61405,15 @@ const Grid = ({
61354
61405
  ...colDef.cellClassRules,
61355
61406
  "GridCell-readonly": (ccp) => !suppressReadOnlyStyle && !editable(ccp)
61356
61407
  },
61357
- // If chromatic we fix the size to minWidth if set otherwise 120px
61358
- // else whatever user has configured which will probably be undefined
61359
- width: isChromatic() ? colDef.minWidth || 120 : colDef.width
61408
+ // If chromatic we fix the size to minWidth if set otherwise 120px, so non-deterministic
61409
+ // content measurement doesn't affect the snapshot - except under 'fit', which sizes via
61410
+ // flex (proportional to the container) rather than measured content, so it's already
61411
+ // deterministic and must keep the user's configured width.
61412
+ width: isChromatic() && sizeColumns !== "fit" ? colDef.minWidth || 120 : colDef.width
61360
61413
  };
61361
61414
  }
61362
61415
  },
61363
- [params.defaultColDef?.editable, params.loading, params.readOnly, suppressReadOnlyStyle]
61416
+ [params.defaultColDef?.editable, params.loading, params.readOnly, suppressReadOnlyStyle, sizeColumns]
61364
61417
  );
61365
61418
  const columnDefs = useMemo(() => {
61366
61419
  return params.columnDefs.map(mapColDef);
@@ -65117,9 +65170,11 @@ const GridContextProvider = (props) => {
65117
65170
  return ok;
65118
65171
  }
65119
65172
  if (ok) {
65120
- if (!gridApi2.isDestroyed) {
65121
- gridApi2.refreshClientSideRowModel();
65122
- }
65173
+ defer(() => {
65174
+ if (!gridApi2.isDestroyed()) {
65175
+ gridApi2.refreshClientSideRowModel();
65176
+ }
65177
+ });
65123
65178
  }
65124
65179
  void (async () => {
65125
65180
  const postPopupFocusedCell = gridApi2.getFocusedCell();