@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.
@@ -0,0 +1 @@
1
+ export {};
@@ -1,6 +1,7 @@
1
1
  import { TextInputValidatorProps } from '../../utils/textValidator';
2
2
  import { CellEditorCommon } from '../GridCell';
3
3
  import { GridBaseRow } from '../types';
4
+ import { MaybePromise } from '../../utils/util';
4
5
  export interface GridFormTextInputProps<TData extends GridBaseRow> extends TextInputValidatorProps<TData>, CellEditorCommon {
5
6
  placeholder?: string;
6
7
  units?: string;
@@ -8,7 +9,7 @@ export interface GridFormTextInputProps<TData extends GridBaseRow> extends TextI
8
9
  onSave?: (props: {
9
10
  selectedRows: TData[];
10
11
  value: string;
11
- }) => Promise<boolean>;
12
+ }) => MaybePromise<boolean>;
12
13
  helpText?: string;
13
14
  disableUnicodeCharacterFilter?: boolean;
14
15
  }
@@ -23,7 +23,7 @@ export const clickColumnHeaderToSort = async (colId: string, within: HTMLElement
23
23
  };
24
24
 
25
25
  export const getNumberOfGridRows = (props?: { grid?: HTMLElement }): number => {
26
- return queryAllQuick({ classes: '.ag-row' }, props?.grid).length;
26
+ return queryAllQuick({ classes: '.ag-center-cols-viewport .ag-row' }, props?.grid).length;
27
27
  };
28
28
 
29
29
  export const gridColumnValues = (colId: string, within: HTMLElement): string[] => {
@@ -60979,18 +60979,51 @@ const usePostSortRowsHook = ({ setStaleGrid }) => {
60979
60979
  const previousQuickFilter = React13.useRef("");
60980
60980
  return React13.useCallback(
60981
60981
  ({ api, nodes }) => {
60982
- if (!api) return;
60982
+ if (!api || api.isDestroyed()) {
60983
+ return;
60984
+ }
60983
60985
  const previousRowSortIndex = previousRowSortIndexRef.current;
60984
- const hashNode = (node) => {
60985
- return node ? JSON.stringify(node.data) : "";
60986
+ const copyCurrentSortSettings = () => {
60987
+ return api.getColumnState().map((row) => ({ colId: row.colId, sort: row.sort, sortIndex: row.sortIndex }));
60986
60988
  };
60987
- const copyCurrentSortSettings = () => api.getColumnState().map((row) => ({ colId: row.colId, sort: row.sort, sortIndex: row.sortIndex }));
60989
+ const currentSortState = copyCurrentSortSettings();
60990
+ const sortedColIds = currentSortState.filter((col) => col.sort).sort((a, b) => (a.sortIndex ?? 0) - (b.sortIndex ?? 0)).map((col) => col.colId);
60991
+ const sortColumnEquals = {};
60992
+ sortedColIds.forEach((colId) => {
60993
+ const colDef = api.getColumn(colId)?.getColDef();
60994
+ if (colDef?.equals) {
60995
+ const equals = colDef.equals;
60996
+ sortColumnEquals[colId] = (a, b) => equals(a, b);
60997
+ } else if (colDef?.comparator) {
60998
+ const comparator = colDef.comparator;
60999
+ sortColumnEquals[colId] = (a, b, nodeA, nodeB) => comparator(a, b, nodeA, nodeB, false) === 0;
61000
+ } else {
61001
+ sortColumnEquals[colId] = (a, b) => a === b;
61002
+ }
61003
+ });
61004
+ const getSortValues = (node) => node ? sortedColIds.map((colId) => api.getCellValue({ rowNode: node, colKey: colId })) : [];
61005
+ const snapshotNode = (node) => node ? { data: node.data, id: node.id } : void 0;
61006
+ const sortValuesChanged = (previous, node, currentValues) => !previous || sortedColIds.some(
61007
+ (colId, i) => !sortColumnEquals[colId](previous.values[i], currentValues[i], previous.node, node)
61008
+ );
60988
61009
  const backupSortOrder = () => {
60989
- for (const x in previousRowSortIndex) delete previousRowSortIndex[x];
60990
- nodes.forEach((node, index) => previousRowSortIndex[`${node.data.id}`] = { index, hash: hashNode(node) });
61010
+ for (const x in previousRowSortIndex) {
61011
+ delete previousRowSortIndex[x];
61012
+ }
61013
+ nodes.forEach(
61014
+ (node, index) => previousRowSortIndex[`${node.data.id}`] = {
61015
+ index,
61016
+ values: getSortValues(node),
61017
+ node: snapshotNode(node)
61018
+ }
61019
+ );
61020
+ };
61021
+ const isFirstSortColumn = (row) => {
61022
+ return row.sort && [0, null].includes(row.sortIndex ?? null);
61023
+ };
61024
+ const isSameColumnAndDifferentSort = (col1, col2) => {
61025
+ return col1 && col2 && col1.colId === col2.colId && col1.sort != col2.sort;
60991
61026
  };
60992
- const isFirstSortColumn = (row) => row.sort && [0, null].includes(row.sortIndex ?? null);
60993
- const isSameColumnAndDifferentSort = (col1, col2) => col1 && col2 && col1.colId === col2.colId && col1.sort != col2.sort;
60994
61027
  const restorePreviousSortColumnState = () => api.applyColumnState({ state: previousColSort.current });
60995
61028
  const sortNodesByPreviousSort = () => {
60996
61029
  nodes.sort(
@@ -61001,25 +61034,27 @@ const usePostSortRowsHook = ({ setStaleGrid }) => {
61001
61034
  initialised.current = true;
61002
61035
  previousColSort.current = copyCurrentSortSettings();
61003
61036
  }
61004
- const newSortOrder = JSON.stringify(copyCurrentSortSettings());
61037
+ const newSortOrder = JSON.stringify(currentSortState);
61005
61038
  let sortOrderChanged = newSortOrder != lastSortOrderHash.current;
61006
- const quickFilter = api.getQuickFilter();
61039
+ const quickFilter = api.getQuickFilter() ?? "";
61007
61040
  if (previousQuickFilter.current != quickFilter) {
61008
- previousQuickFilter.current = quickFilter ?? "";
61041
+ previousQuickFilter.current = quickFilter;
61009
61042
  sortOrderChanged = true;
61010
61043
  }
61011
61044
  if (lodashEs.isEmpty(previousRowSortIndex)) {
61012
61045
  backupSortOrder();
61013
61046
  }
61014
61047
  if (sortOrderChanged) {
61015
- const thisFirstCol = copyCurrentSortSettings().find(isFirstSortColumn);
61048
+ const thisFirstCol = currentSortState.find(isFirstSortColumn);
61016
61049
  const previousFirstCol = previousColSort.current.find(isFirstSortColumn);
61017
61050
  const wasSortChangedOnSameColumn = previousFirstCol && (!thisFirstCol || isSameColumnAndDifferentSort(previousFirstCol, thisFirstCol));
61018
61051
  if (sortWasStale.current && wasSortChangedOnSameColumn) {
61019
61052
  sortWasStale.current = false;
61020
61053
  setStaleGrid(false);
61021
61054
  lastSortOrderHash.current = "";
61022
- restorePreviousSortColumnState();
61055
+ lodashEs.defer(() => {
61056
+ restorePreviousSortColumnState();
61057
+ });
61023
61058
  } else {
61024
61059
  if (sortWasStale.current) {
61025
61060
  sortWasStale.current = false;
@@ -61037,7 +61072,7 @@ const usePostSortRowsHook = ({ setStaleGrid }) => {
61037
61072
  for (const node of nodes) {
61038
61073
  const psr = previousRowSortIndex[`${node.data.id}`];
61039
61074
  if (psr) {
61040
- if (psr.hash != hashNode(node)) {
61075
+ if (sortValuesChanged(psr, node, getSortValues(node))) {
61041
61076
  if (firstChangedNodeIndex === -1) firstChangedNodeIndex = index;
61042
61077
  changedRowCount++;
61043
61078
  }
@@ -61050,7 +61085,11 @@ const usePostSortRowsHook = ({ setStaleGrid }) => {
61050
61085
  let wasStale = false;
61051
61086
  if (changedRowCount === 0 && newRowCount === 1) {
61052
61087
  const newIndex = index - 1;
61053
- previousRowSortIndex[`${lastNewNode?.data.id}`] = { index: newIndex, hash: hashNode(lastNewNode) };
61088
+ previousRowSortIndex[`${lastNewNode?.data.id}`] = {
61089
+ index: newIndex,
61090
+ values: getSortValues(lastNewNode),
61091
+ node: snapshotNode(lastNewNode)
61092
+ };
61054
61093
  wasStale = true;
61055
61094
  } else if (changedRowCount === 2 && newRowCount === 0) {
61056
61095
  backupSortOrder();
@@ -61058,15 +61097,27 @@ const usePostSortRowsHook = ({ setStaleGrid }) => {
61058
61097
  } else if (changedRowCount > 1 && newRowCount === 1) {
61059
61098
  previousRowSortIndex[`${lastNewNode?.data.id}`] = {
61060
61099
  index: firstChangedNodeIndex + 0.5,
61061
- hash: hashNode(lastNewNode)
61100
+ values: getSortValues(lastNewNode),
61101
+ node: snapshotNode(lastNewNode)
61062
61102
  };
61063
61103
  wasStale = true;
61064
61104
  if (lastNewNode) {
61065
61105
  redrawRows();
61066
61106
  }
61067
61107
  } else if (changedRowCount == 1 && newRowCount === 0) {
61108
+ const changedNode = nodes[firstChangedNodeIndex];
61109
+ const previousEntry = changedNode && previousRowSortIndex[`${changedNode.data.id}`];
61110
+ if (changedNode && previousEntry) {
61111
+ previousRowSortIndex[`${changedNode.data.id}`] = {
61112
+ index: previousEntry.index,
61113
+ values: getSortValues(changedNode),
61114
+ node: snapshotNode(changedNode)
61115
+ };
61116
+ }
61117
+ wasStale = true;
61118
+ } else if (changedRowCount === 0 && newRowCount === 0 && nodes.length === Object.keys(previousRowSortIndex).length) {
61068
61119
  wasStale = true;
61069
- } else if (changedRowCount !== 0 || newRowCount != 0) {
61120
+ } else {
61070
61121
  backupSortOrder();
61071
61122
  }
61072
61123
  if (wasStale) {
@@ -65119,9 +65170,11 @@ const GridContextProvider = (props) => {
65119
65170
  return ok;
65120
65171
  }
65121
65172
  if (ok) {
65122
- if (!gridApi2.isDestroyed) {
65123
- gridApi2.refreshClientSideRowModel();
65124
- }
65173
+ lodashEs.defer(() => {
65174
+ if (!gridApi2.isDestroyed()) {
65175
+ gridApi2.refreshClientSideRowModel();
65176
+ }
65177
+ });
65125
65178
  }
65126
65179
  void (async () => {
65127
65180
  const postPopupFocusedCell = gridApi2.getFocusedCell();