@linzjs/step-ag-grid 32.7.1 → 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.
Files changed (66) hide show
  1. package/dist/src/components/PostSortRowsHook.test.d.ts +1 -0
  2. package/dist/src/components/gridFilter/GridFilterColumnsMultiSelect.d.ts +6 -25
  3. package/dist/src/components/gridForm/GridFormTextInput.d.ts +2 -1
  4. package/dist/src/utils/__tests__/storybookTestUtil.ts +1 -1
  5. package/dist/step-ag-grid.cjs +190 -206
  6. package/dist/step-ag-grid.cjs.map +1 -1
  7. package/dist/step-ag-grid.esm.js +190 -206
  8. package/dist/step-ag-grid.esm.js.map +1 -1
  9. package/package.json +17 -17
  10. package/src/components/Grid.tsx +8 -10
  11. package/src/components/PostSortRowsHook.test.ts +300 -0
  12. package/src/components/PostSortRowsHook.ts +127 -24
  13. package/src/components/gridFilter/GridFilterColumnsMultiSelect.tsx +110 -199
  14. package/src/components/gridForm/GridFormTextInput.tsx +2 -1
  15. package/src/components/gridHook/useGridRangeSelection.ts +8 -6
  16. package/src/contexts/GridContextProvider.tsx +5 -9
  17. package/src/react-menu3/components/ControlledMenu.tsx +5 -3
  18. package/src/react-menu3/components/MenuList.tsx +7 -3
  19. package/src/react-menu3/hooks/useItems.ts +1 -1
  20. package/src/stories/components/ActionButton.stories.tsx +12 -11
  21. package/src/stories/decorators/withOpenInPanelDecorator.tsx +35 -0
  22. package/src/stories/grid/GridCopy.stories.tsx +38 -35
  23. package/src/stories/grid/GridDragRow.stories.tsx +41 -36
  24. package/src/stories/grid/GridFilterButtons.stories.tsx +25 -19
  25. package/src/stories/grid/GridFilterColumnsMultiSelect.stories.tsx +42 -37
  26. package/src/stories/grid/GridInlineText.stories.tsx +62 -49
  27. package/src/stories/grid/GridNoRowsOverlay.stories.tsx +28 -23
  28. package/src/stories/grid/GridNonEditableRow.stories.tsx +30 -24
  29. package/src/stories/grid/GridPinnedRow.stories.tsx +37 -31
  30. package/src/stories/grid/GridPopoutContextMenu.stories.tsx +29 -24
  31. package/src/stories/grid/GridPopoutEditBoolean.stories.tsx +89 -82
  32. package/src/stories/grid/GridPopoutEditGeneric.stories.tsx +27 -22
  33. package/src/stories/grid/GridPopoutEditGenericTextArea.stories.tsx +29 -24
  34. package/src/stories/grid/GridPopoverEditBearing.stories.tsx +30 -25
  35. package/src/stories/grid/GridPopoverEditDropDown.stories.tsx +29 -24
  36. package/src/stories/grid/GridPopoverEditMultiSelect.stories.tsx +29 -24
  37. package/src/stories/grid/GridPopoverEditMultiSelectGrid.stories.tsx +28 -24
  38. package/src/stories/grid/GridReadOnly.stories.tsx +56 -52
  39. package/src/stories/grid/GridSorting.stories.tsx +498 -86
  40. package/src/stories/grid/GridViewList.stories.tsx +31 -26
  41. package/src/stories/grid/GridViewSelectableList.stories.tsx +31 -26
  42. package/src/stories/grid/gridAutosize/GridAutoSize.stories.tsx +41 -37
  43. package/src/stories/grid/gridAutosize/GridFitSize.stories.tsx +40 -36
  44. package/src/stories/grid/gridAutosize/GridFitSizeFlex.stories.tsx +40 -36
  45. package/src/stories/grid/gridAutosize/ShowPanelResizingAgGrid/ShowPanelResizingStepAgGrid.tsx +14 -6
  46. package/src/stories/grid/gridFormInteraction/GridFormDropDownInteraction.stories.tsx +74 -74
  47. package/src/stories/grid/gridFormInteraction/GridFormEditBearingCorrectionInteraction.stories.tsx +59 -59
  48. package/src/stories/grid/gridFormInteraction/GridFormEditBearingInteraction.stories.tsx +58 -58
  49. package/src/stories/grid/gridFormInteraction/GridFormMultiSelectGridInteraction.stories.tsx +62 -62
  50. package/src/stories/grid/gridFormInteraction/GridFormMultiSelectInteraction.stories.tsx +118 -118
  51. package/src/stories/grid/gridFormInteraction/GridFormPopoverMenuInteraction.stories.tsx +107 -105
  52. package/src/stories/grid/gridFormInteraction/GridFormTextAreaInteraction.stories.tsx +72 -64
  53. package/src/stories/grid/gridFormInteraction/GridFormTextInputInteraction.stories.tsx +82 -73
  54. package/src/stories/grid/gridFormStatic/GridFormDropDown.stories.tsx +12 -13
  55. package/src/stories/grid/gridFormStatic/GridFormEditBearing.stories.tsx +12 -13
  56. package/src/stories/grid/gridFormStatic/GridFormEditBearingCorrection.stories.tsx +11 -13
  57. package/src/stories/grid/gridFormStatic/GridFormMessage.stories.tsx +11 -13
  58. package/src/stories/grid/gridFormStatic/GridFormMultiSelect.stories.tsx +11 -13
  59. package/src/stories/grid/gridFormStatic/GridFormPopoverMenu.stories.tsx +11 -13
  60. package/src/stories/grid/gridFormStatic/GridFormTextArea.stories.tsx +11 -13
  61. package/src/stories/grid/gridFormStatic/GridFormTextInput.stories.tsx +11 -13
  62. package/src/stories/grid/interactions/GridKeyboardInteractions.stories.tsx +110 -107
  63. package/src/stories/react-menu/ReactMenu.stories.tsx +70 -73
  64. package/src/styles/GridLoadableCell.scss +1 -1
  65. package/src/utils/__tests__/storybookTestUtil.ts +1 -1
  66. package/src/utils/useSharedInterval.ts +3 -3
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,7 @@
1
1
  import './GridFilterColumnsMultiSelect.scss';
2
- import type { IDoesFilterPassParams, IFilterComp, IFilterParams } from 'ag-grid-community';
2
+ import type { IFilterParams } from 'ag-grid-community';
3
+ import { CustomFilterProps } from 'ag-grid-react';
4
+ import React from 'react';
3
5
  export interface CheckboxMultiFilterParams extends IFilterParams {
4
6
  labels?: Record<string, string>;
5
7
  labelFormatter?: (value: string) => string;
@@ -8,28 +10,7 @@ export interface CheckboxMultiFilterParams extends IFilterParams {
8
10
  export interface CheckboxMultiFilterModel {
9
11
  values: string[];
10
12
  }
11
- export declare class GridFilterColumnsMultiSelect implements IFilterComp {
12
- private params;
13
- private selectedValues;
14
- private labels;
15
- private allValues;
16
- private gui;
17
- private labelFormatter?;
18
- private reactRoot;
19
- private filterButtonClickListener;
20
- private filterButton;
21
- private normalizeCellValue;
22
- private loadFieldValues;
23
- init(params: CheckboxMultiFilterParams): void;
24
- private setupFilterButtonListener;
25
- private render;
26
- private handleToggleAll;
27
- private handleToggleOne;
28
- getGui(): HTMLElement;
29
- isFilterActive(): boolean;
30
- doesFilterPass(p: IDoesFilterPassParams): boolean;
31
- getModel(): CheckboxMultiFilterModel | null;
32
- setModel(model: CheckboxMultiFilterModel | null): void;
33
- destroy(): void;
34
- }
13
+ type GridFilterColumnsMultiSelectProps = CustomFilterProps<any, any, CheckboxMultiFilterModel> & CheckboxMultiFilterParams;
14
+ export declare const GridFilterColumnsMultiSelect: (props: GridFilterColumnsMultiSelectProps) => React.JSX.Element;
35
15
  export declare const createCheckboxMultiFilterParams: (labels?: Record<string, string>, labelFormatter?: (value: string) => string, customOrder?: string[]) => Partial<CheckboxMultiFilterParams>;
16
+ 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[] => {
@@ -5,7 +5,6 @@ var lui = require('@linzjs/lui');
5
5
  var React13 = require('react');
6
6
  var ReactDOM = require('react-dom');
7
7
  var lodashEs = require('lodash-es');
8
- var client = require('react-dom/client');
9
8
 
10
9
  const ComponentLoadingWrapper = (props) => {
11
10
  return props.loading ? /* @__PURE__ */ jsxRuntime.jsx(lui.LuiMiniSpinner, { size: 22, divProps: { role: "status", ["aria-label"]: "Loading", style: { padding: 16 } } }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { pointerEvents: props.saving ? "none" : "inherit" }, className: props.className, children: [
@@ -57823,6 +57822,13 @@ var AgGridReact = class extends React13.Component {
57823
57822
  return /* @__PURE__ */ React13.createElement(AgGridReactUi, { ...this.props, passGridApi: this.setGridApi });
57824
57823
  }
57825
57824
  };
57825
+ function useGridCustomComponent(methods) {
57826
+ const { setMethods } = React13.useContext(CustomContext);
57827
+ setMethods(methods);
57828
+ }
57829
+ function useGridFilter$1(callbacks) {
57830
+ return useGridCustomComponent(callbacks);
57831
+ }
57826
57832
 
57827
57833
  function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
57828
57834
 
@@ -58562,7 +58568,7 @@ const useItems = (menuRef, focusRef) => {
58562
58568
  const index = items.indexOf(item);
58563
58569
  if (index > -1) {
58564
58570
  items.splice(index, 1);
58565
- if (item.contains(document.activeElement)) {
58571
+ if (item.contains(item.ownerDocument.activeElement)) {
58566
58572
  focusRef?.current?.focus();
58567
58573
  setHoverItem(void 0);
58568
58574
  }
@@ -59257,7 +59263,8 @@ const MenuList = ({
59257
59263
  return;
59258
59264
  }
59259
59265
  if (!scrollNodes.menu) {
59260
- scrollNodes.menu = (boundingBoxRef ? boundingBoxRef.current : getScrollAncestor(rootMenuRef?.current)) || window;
59266
+ const thisWindow = containerRef.current.ownerDocument.defaultView ?? window;
59267
+ scrollNodes.menu = (boundingBoxRef ? boundingBoxRef.current : getScrollAncestor(rootMenuRef?.current)) || thisWindow;
59261
59268
  }
59262
59269
  const positionHelpers = getPositionHelpers(containerRef, menuRef, scrollNodes.menu, boundingBoxPadding);
59263
59270
  const { menuRect } = positionHelpers;
@@ -59349,7 +59356,8 @@ const MenuList = ({
59349
59356
  React13.useEffect(() => {
59350
59357
  let { menu: menuScroll } = scrollNodes;
59351
59358
  if (!isOpen || !menuScroll) return;
59352
- menuScroll = menuScroll.addEventListener ? menuScroll : window;
59359
+ const thisWindow = containerRef?.current?.ownerDocument.defaultView ?? window;
59360
+ menuScroll = menuScroll.addEventListener ? menuScroll : thisWindow;
59353
59361
  if (!scrollNodes.anchors) {
59354
59362
  scrollNodes.anchors = [];
59355
59363
  let anchorScroll = getScrollAncestor(rootAnchorRef && rootAnchorRef.current);
@@ -59455,7 +59463,7 @@ const MenuList = ({
59455
59463
  } else if (captureFocus) {
59456
59464
  const id = setTimeout(
59457
59465
  () => {
59458
- if (menuRef.current && !menuRef.current.contains(document.activeElement)) {
59466
+ if (menuRef.current && !menuRef.current.contains(menuRef.current.ownerDocument.activeElement)) {
59459
59467
  const popupElement = focusRef.current?.nextSibling;
59460
59468
  if (!focusFirstInput(popupElement)) {
59461
59469
  focusRef.current?.focus();
@@ -59807,7 +59815,7 @@ const ControlledMenuFr = ({
59807
59815
  }
59808
59816
  };
59809
59817
  const onBlur = (e) => {
59810
- if (isMenuOpen(state) && !e.currentTarget.contains(e.relatedTarget || document.activeElement) && !isWithinMenu(e.relatedTarget)) {
59818
+ if (isMenuOpen(state) && !e.currentTarget.contains(e.relatedTarget || e.currentTarget.ownerDocument.activeElement) && !isWithinMenu(e.relatedTarget)) {
59811
59819
  safeCall(onClose, { reason: CloseReason.BLUR });
59812
59820
  if (skipOpen) {
59813
59821
  skipOpen.current = true;
@@ -59849,8 +59857,9 @@ const ControlledMenuFr = ({
59849
59857
  }
59850
59858
  if (portal) {
59851
59859
  if (typeof portal === "boolean") {
59852
- if (portal && typeof document !== "undefined") {
59853
- return ReactDOM.createPortal(menuList, document.body);
59860
+ const thisDocument = containerRef.current?.ownerDocument ?? (typeof document !== "undefined" ? document : void 0);
59861
+ if (portal && thisDocument) {
59862
+ return ReactDOM.createPortal(menuList, thisDocument.body);
59854
59863
  }
59855
59864
  } else {
59856
59865
  return portal.target ? ReactDOM.createPortal(menuList, portal.target) : portal.stablePosition ? null : menuList;
@@ -60865,13 +60874,14 @@ const useGridRangeSelection = ({
60865
60874
  [rangeEndRef]
60866
60875
  );
60867
60876
  React13.useEffect(() => {
60868
- document.addEventListener("mousedown", trackMouseDown, { capture: true });
60869
- document.addEventListener("mouseup", trackMouseUp, { capture: true });
60877
+ const doc = gridDivRef.current?.ownerDocument;
60878
+ doc?.addEventListener("mousedown", trackMouseDown, { capture: true });
60879
+ doc?.addEventListener("mouseup", trackMouseUp, { capture: true });
60870
60880
  return () => {
60871
- document.removeEventListener("mousemove", trackMouseDown, { capture: true });
60872
- document.removeEventListener("mouseup", trackMouseUp, { capture: true });
60881
+ doc?.removeEventListener("mousemove", trackMouseDown, { capture: true });
60882
+ doc?.removeEventListener("mouseup", trackMouseUp, { capture: true });
60873
60883
  };
60874
- }, [trackMouseDown, trackMouseUp]);
60884
+ }, [trackMouseDown, trackMouseUp, gridDivRef]);
60875
60885
  const onCellMouseOver = React13.useCallback(
60876
60886
  (e, mouseDown) => {
60877
60887
  if (!enableRangeSelection) {
@@ -60896,7 +60906,7 @@ const useGridRangeSelection = ({
60896
60906
  if (rangeStartRef.current && rangeEndRef.current && (rangeStartRef.current.rowId !== rangeEndRef.current.rowId || rangeStartRef.current.colId !== rangeEndRef.current.colId)) {
60897
60907
  e.api.stopEditing();
60898
60908
  hasSelectedMoreThanOneCellRef.current = true;
60899
- window.getSelection()?.removeAllRanges();
60909
+ gridDivRef.current?.ownerDocument.defaultView?.getSelection()?.removeAllRanges();
60900
60910
  }
60901
60911
  updateRangeSelectionCellClasses();
60902
60912
  },
@@ -60906,7 +60916,8 @@ const useGridRangeSelection = ({
60906
60916
  hasSelectedMoreThanOneCellRef,
60907
60917
  rangeEndRef,
60908
60918
  rangeSortedNodesRef,
60909
- rangeStartRef
60919
+ rangeStartRef,
60920
+ gridDivRef
60910
60921
  ]
60911
60922
  );
60912
60923
  const onCellMouseDown = React13.useCallback(
@@ -60968,18 +60979,51 @@ const usePostSortRowsHook = ({ setStaleGrid }) => {
60968
60979
  const previousQuickFilter = React13.useRef("");
60969
60980
  return React13.useCallback(
60970
60981
  ({ api, nodes }) => {
60971
- if (!api) return;
60982
+ if (!api || api.isDestroyed()) {
60983
+ return;
60984
+ }
60972
60985
  const previousRowSortIndex = previousRowSortIndexRef.current;
60973
- const hashNode = (node) => {
60974
- return node ? JSON.stringify(node.data) : "";
60986
+ const copyCurrentSortSettings = () => {
60987
+ return api.getColumnState().map((row) => ({ colId: row.colId, sort: row.sort, sortIndex: row.sortIndex }));
60975
60988
  };
60976
- 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
+ );
60977
61009
  const backupSortOrder = () => {
60978
- for (const x in previousRowSortIndex) delete previousRowSortIndex[x];
60979
- 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;
60980
61026
  };
60981
- const isFirstSortColumn = (row) => row.sort && [0, null].includes(row.sortIndex ?? null);
60982
- const isSameColumnAndDifferentSort = (col1, col2) => col1 && col2 && col1.colId === col2.colId && col1.sort != col2.sort;
60983
61027
  const restorePreviousSortColumnState = () => api.applyColumnState({ state: previousColSort.current });
60984
61028
  const sortNodesByPreviousSort = () => {
60985
61029
  nodes.sort(
@@ -60990,25 +61034,27 @@ const usePostSortRowsHook = ({ setStaleGrid }) => {
60990
61034
  initialised.current = true;
60991
61035
  previousColSort.current = copyCurrentSortSettings();
60992
61036
  }
60993
- const newSortOrder = JSON.stringify(copyCurrentSortSettings());
61037
+ const newSortOrder = JSON.stringify(currentSortState);
60994
61038
  let sortOrderChanged = newSortOrder != lastSortOrderHash.current;
60995
- const quickFilter = api.getQuickFilter();
61039
+ const quickFilter = api.getQuickFilter() ?? "";
60996
61040
  if (previousQuickFilter.current != quickFilter) {
60997
- previousQuickFilter.current = quickFilter ?? "";
61041
+ previousQuickFilter.current = quickFilter;
60998
61042
  sortOrderChanged = true;
60999
61043
  }
61000
61044
  if (lodashEs.isEmpty(previousRowSortIndex)) {
61001
61045
  backupSortOrder();
61002
61046
  }
61003
61047
  if (sortOrderChanged) {
61004
- const thisFirstCol = copyCurrentSortSettings().find(isFirstSortColumn);
61048
+ const thisFirstCol = currentSortState.find(isFirstSortColumn);
61005
61049
  const previousFirstCol = previousColSort.current.find(isFirstSortColumn);
61006
61050
  const wasSortChangedOnSameColumn = previousFirstCol && (!thisFirstCol || isSameColumnAndDifferentSort(previousFirstCol, thisFirstCol));
61007
61051
  if (sortWasStale.current && wasSortChangedOnSameColumn) {
61008
61052
  sortWasStale.current = false;
61009
61053
  setStaleGrid(false);
61010
61054
  lastSortOrderHash.current = "";
61011
- restorePreviousSortColumnState();
61055
+ lodashEs.defer(() => {
61056
+ restorePreviousSortColumnState();
61057
+ });
61012
61058
  } else {
61013
61059
  if (sortWasStale.current) {
61014
61060
  sortWasStale.current = false;
@@ -61026,7 +61072,7 @@ const usePostSortRowsHook = ({ setStaleGrid }) => {
61026
61072
  for (const node of nodes) {
61027
61073
  const psr = previousRowSortIndex[`${node.data.id}`];
61028
61074
  if (psr) {
61029
- if (psr.hash != hashNode(node)) {
61075
+ if (sortValuesChanged(psr, node, getSortValues(node))) {
61030
61076
  if (firstChangedNodeIndex === -1) firstChangedNodeIndex = index;
61031
61077
  changedRowCount++;
61032
61078
  }
@@ -61039,7 +61085,11 @@ const usePostSortRowsHook = ({ setStaleGrid }) => {
61039
61085
  let wasStale = false;
61040
61086
  if (changedRowCount === 0 && newRowCount === 1) {
61041
61087
  const newIndex = index - 1;
61042
- 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
+ };
61043
61093
  wasStale = true;
61044
61094
  } else if (changedRowCount === 2 && newRowCount === 0) {
61045
61095
  backupSortOrder();
@@ -61047,15 +61097,27 @@ const usePostSortRowsHook = ({ setStaleGrid }) => {
61047
61097
  } else if (changedRowCount > 1 && newRowCount === 1) {
61048
61098
  previousRowSortIndex[`${lastNewNode?.data.id}`] = {
61049
61099
  index: firstChangedNodeIndex + 0.5,
61050
- hash: hashNode(lastNewNode)
61100
+ values: getSortValues(lastNewNode),
61101
+ node: snapshotNode(lastNewNode)
61051
61102
  };
61052
61103
  wasStale = true;
61053
61104
  if (lastNewNode) {
61054
61105
  redrawRows();
61055
61106
  }
61056
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
+ }
61057
61117
  wasStale = true;
61058
- } else if (changedRowCount !== 0 || newRowCount != 0) {
61118
+ } else if (changedRowCount === 0 && newRowCount === 0 && nodes.length === Object.keys(previousRowSortIndex).length) {
61119
+ wasStale = true;
61120
+ } else {
61059
61121
  backupSortOrder();
61060
61122
  }
61061
61123
  if (wasStale) {
@@ -61422,7 +61484,7 @@ const Grid = ({
61422
61484
  const api = event.api;
61423
61485
  if (sizeColumns === "fit") {
61424
61486
  lodashEs.delay(() => {
61425
- if (!anyUpdating() && document.querySelectorAll(".szh-menu--state-open").length === 0) {
61487
+ if (!anyUpdating() && !gridDivRef.current?.ownerDocument.querySelectorAll(".szh-menu--state-open").length) {
61426
61488
  if (!api.isDestroyed()) {
61427
61489
  api.redrawRows();
61428
61490
  }
@@ -61630,22 +61692,21 @@ const Grid = ({
61630
61692
  prevLoading.current = newLoading;
61631
61693
  }, [params.loading, rowData, showNoRowsOverlay]);
61632
61694
  const startDragYRef = React13.useRef(null);
61633
- const getGridRoot = React13.useCallback(() => gridDivRef.current ?? document, []);
61634
61695
  const clearHighlightRowClasses = React13.useCallback(() => {
61635
- const gridRoot = getGridRoot();
61636
- gridRoot.querySelectorAll(`.ag-row-highlight-above`)?.forEach((el) => {
61696
+ const gridRoot = gridDivRef.current;
61697
+ gridRoot?.querySelectorAll(`.ag-row-highlight-above`)?.forEach((el) => {
61637
61698
  el.classList.remove("ag-row-highlight-above");
61638
61699
  });
61639
- gridRoot.querySelectorAll(`.ag-row-highlight-below`)?.forEach((el) => {
61700
+ gridRoot?.querySelectorAll(`.ag-row-highlight-below`)?.forEach((el) => {
61640
61701
  el.classList.remove("ag-row-highlight-below");
61641
61702
  });
61642
- }, [getGridRoot]);
61703
+ }, []);
61643
61704
  const clearDragRowClasses = React13.useCallback(() => {
61644
- const gridRoot = getGridRoot();
61645
- gridRoot.querySelectorAll(`.ag-row-dragging`)?.forEach((el) => {
61705
+ const gridRoot = gridDivRef.current;
61706
+ gridRoot?.querySelectorAll(`.ag-row-dragging`)?.forEach((el) => {
61646
61707
  el.classList.remove("ag-row-dragging");
61647
61708
  });
61648
- }, [getGridRoot]);
61709
+ }, []);
61649
61710
  const gridElementRef = React13.useRef(void 0);
61650
61711
  const multiDragAppliedRef = React13.useRef(false);
61651
61712
  const multiDragCountRef = React13.useRef(0);
@@ -62220,20 +62281,87 @@ const EMPTY_KEY = "__EMPTY__";
62220
62281
  const DEFAULT_EMPTY_LABEL = "-";
62221
62282
  const filterStateMap = /* @__PURE__ */ new Map();
62222
62283
  const filterClickCountMap = /* @__PURE__ */ new Map();
62223
- const FilterUI = ({
62224
- allValues,
62225
- selected,
62226
- labels,
62227
- labelFormatter,
62228
- onToggleAll,
62229
- onToggleOne
62230
- }) => {
62284
+ const normalizeCellValue = (value) => {
62285
+ if (typeof value === "string") return value.trim() === "" ? EMPTY_KEY : value;
62286
+ return EMPTY_KEY;
62287
+ };
62288
+ const loadFieldValues = (params) => {
62289
+ const field = params.colDef.field;
62290
+ const values = /* @__PURE__ */ new Set();
62291
+ params.api.forEachNode((node) => {
62292
+ const data = node.data ?? {};
62293
+ values.add(normalizeCellValue(data[field]));
62294
+ });
62295
+ const { customOrder } = params;
62296
+ const orderMap = customOrder?.length ? new Map(customOrder.map((val, idx) => [val, idx])) : null;
62297
+ return Array.from(values).sort((a, b) => {
62298
+ if (orderMap) {
62299
+ const aIdx = orderMap.get(a) ?? Infinity;
62300
+ const bIdx = orderMap.get(b) ?? Infinity;
62301
+ if (aIdx !== bIdx) return aIdx - bIdx;
62302
+ }
62303
+ if (a === EMPTY_KEY) return b === EMPTY_KEY ? 0 : -1;
62304
+ if (b === EMPTY_KEY) return 1;
62305
+ return a.localeCompare(b);
62306
+ });
62307
+ };
62308
+ const GridFilterColumnsMultiSelect = (props) => {
62309
+ const { model, onModelChange, colDef, column, labels: labelsParam, labelFormatter } = props;
62310
+ const containerRef = React13.useRef(null);
62311
+ const allValues = React13.useMemo(() => loadFieldValues(props), []);
62312
+ const labels = React13.useMemo(
62313
+ () => ({ [EMPTY_KEY]: DEFAULT_EMPTY_LABEL, ...labelsParam }),
62314
+ [labelsParam]
62315
+ );
62316
+ const selected = React13.useMemo(() => new Set(model?.values ?? allValues), [model, allValues]);
62317
+ useGridFilter$1({
62318
+ doesFilterPass: (p) => {
62319
+ if (selected.size === 0) return false;
62320
+ const field = colDef.field;
62321
+ if (!p.data || typeof p.data !== "object") return selected.has(EMPTY_KEY);
62322
+ const raw = p.data[field];
62323
+ return selected.has(normalizeCellValue(raw));
62324
+ }
62325
+ });
62326
+ React13.useEffect(() => {
62327
+ const ownerDocument = containerRef.current?.ownerDocument;
62328
+ const columnId = column.getColId();
62329
+ const filterButton = ownerDocument?.querySelector(`[col-id="${columnId}"] .ag-header-cell-filter-button`);
62330
+ if (!filterButton) {
62331
+ return;
62332
+ }
62333
+ const listener = (e) => {
62334
+ const clickCount = filterClickCountMap.get(columnId) || 0;
62335
+ filterClickCountMap.set(columnId, clickCount + 1);
62336
+ if (clickCount === 0) {
62337
+ e.stopImmediatePropagation();
62338
+ e.preventDefault();
62339
+ props.api.hidePopupMenu();
62340
+ filterStateMap.set(columnId, false);
62341
+ return;
62342
+ }
62343
+ const isOpen = filterStateMap.get(columnId) || false;
62344
+ if (isOpen) {
62345
+ e.stopImmediatePropagation();
62346
+ e.preventDefault();
62347
+ props.api.hidePopupMenu();
62348
+ filterStateMap.set(columnId, false);
62349
+ } else {
62350
+ filterStateMap.set(columnId, true);
62351
+ }
62352
+ };
62353
+ filterButton.addEventListener("click", listener, true);
62354
+ return () => filterButton.removeEventListener("click", listener, true);
62355
+ }, [column, props.api]);
62231
62356
  const allChecked = allValues.length > 0 && selected.size === allValues.length;
62232
62357
  const getDisplayLabel = (raw) => {
62233
62358
  const base = raw === EMPTY_KEY ? labels[EMPTY_KEY] ?? DEFAULT_EMPTY_LABEL : labels[raw] ?? raw;
62234
62359
  return labelFormatter ? labelFormatter(base) : base;
62235
62360
  };
62236
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "GridFilterColsMultiSelect", children: [
62361
+ const applySelection = (next) => {
62362
+ onModelChange(next.size === allValues.length ? null : { values: Array.from(next) });
62363
+ };
62364
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "GridFilterColsMultiSelect", ref: containerRef, children: [
62237
62365
  /* @__PURE__ */ jsxRuntime.jsx("span", { className: "LuiSelect-label-text", children: "Filter column" }),
62238
62366
  /* @__PURE__ */ jsxRuntime.jsx(
62239
62367
  lui.LuiCheckboxInput,
@@ -62242,7 +62370,7 @@ const FilterUI = ({
62242
62370
  label: "Select All",
62243
62371
  value: "true",
62244
62372
  isChecked: allChecked,
62245
- onChange: (e) => onToggleAll(e.target.checked)
62373
+ onChange: (e) => applySelection(e.target.checked ? new Set(allValues) : /* @__PURE__ */ new Set())
62246
62374
  }
62247
62375
  ),
62248
62376
  allValues.map((val) => /* @__PURE__ */ jsxRuntime.jsx(
@@ -62252,163 +62380,17 @@ const FilterUI = ({
62252
62380
  label: getDisplayLabel(val),
62253
62381
  value: val,
62254
62382
  isChecked: selected.has(val),
62255
- onChange: (e) => onToggleOne(val, e.target.checked)
62383
+ onChange: (e) => {
62384
+ const next = new Set(selected);
62385
+ if (e.target.checked) next.add(val);
62386
+ else next.delete(val);
62387
+ applySelection(next);
62388
+ }
62256
62389
  },
62257
62390
  val
62258
62391
  ))
62259
62392
  ] });
62260
62393
  };
62261
- class GridFilterColumnsMultiSelect {
62262
- params;
62263
- selectedValues = /* @__PURE__ */ new Set();
62264
- labels = {};
62265
- allValues = [];
62266
- gui;
62267
- labelFormatter;
62268
- reactRoot = null;
62269
- filterButtonClickListener = null;
62270
- filterButton = null;
62271
- normalizeCellValue(value) {
62272
- if (typeof value === "string") return value.trim() === "" ? EMPTY_KEY : value;
62273
- return EMPTY_KEY;
62274
- }
62275
- loadFieldValues() {
62276
- const field = this.params.colDef.field;
62277
- const values = /* @__PURE__ */ new Set();
62278
- this.params.api.forEachNode((node) => {
62279
- const data = node.data ?? {};
62280
- const raw = data[field];
62281
- const norm = this.normalizeCellValue(raw);
62282
- values.add(norm);
62283
- });
62284
- const { customOrder } = this.params;
62285
- const orderMap = customOrder?.length ? new Map(customOrder.map((val, idx) => [val, idx])) : null;
62286
- return Array.from(values).sort((a, b) => {
62287
- if (orderMap) {
62288
- const aIdx = orderMap.get(a) ?? Infinity;
62289
- const bIdx = orderMap.get(b) ?? Infinity;
62290
- if (aIdx !== bIdx) return aIdx - bIdx;
62291
- }
62292
- if (a === EMPTY_KEY) return b === EMPTY_KEY ? 0 : -1;
62293
- if (b === EMPTY_KEY) return 1;
62294
- return a.localeCompare(b);
62295
- });
62296
- }
62297
- init(params) {
62298
- this.params = params;
62299
- this.labels = { ...params.labels };
62300
- this.labelFormatter = params.labelFormatter;
62301
- if (!(EMPTY_KEY in this.labels)) {
62302
- this.labels[EMPTY_KEY] = DEFAULT_EMPTY_LABEL;
62303
- }
62304
- this.allValues = this.loadFieldValues();
62305
- this.selectedValues = new Set(this.allValues);
62306
- this.gui = document.createElement("div");
62307
- this.reactRoot = client.createRoot(this.gui);
62308
- this.render();
62309
- this.setupFilterButtonListener();
62310
- }
62311
- setupFilterButtonListener() {
62312
- const columnId = this.params.column.getColId();
62313
- this.filterButton = document.querySelector(`[col-id="${columnId}"] .ag-header-cell-filter-button`);
62314
- if (this.filterButton) {
62315
- this.filterButtonClickListener = (e) => {
62316
- const clickCount = filterClickCountMap.get(columnId) || 0;
62317
- filterClickCountMap.set(columnId, clickCount + 1);
62318
- if (clickCount === 0) {
62319
- e.stopImmediatePropagation();
62320
- e.preventDefault();
62321
- this.params.api.hidePopupMenu();
62322
- filterStateMap.set(columnId, false);
62323
- return;
62324
- }
62325
- const isOpen = filterStateMap.get(columnId) || false;
62326
- if (isOpen) {
62327
- e.stopImmediatePropagation();
62328
- e.preventDefault();
62329
- this.params.api.hidePopupMenu();
62330
- filterStateMap.set(columnId, false);
62331
- } else {
62332
- filterStateMap.set(columnId, true);
62333
- }
62334
- };
62335
- this.filterButton.addEventListener("click", this.filterButtonClickListener, true);
62336
- }
62337
- }
62338
- render() {
62339
- if (!this.reactRoot) return;
62340
- this.reactRoot.render(
62341
- /* @__PURE__ */ jsxRuntime.jsx(
62342
- FilterUI,
62343
- {
62344
- allValues: this.allValues,
62345
- selected: this.selectedValues,
62346
- labels: this.labels,
62347
- labelFormatter: this.labelFormatter,
62348
- onToggleAll: this.handleToggleAll.bind(this),
62349
- onToggleOne: this.handleToggleOne.bind(this)
62350
- }
62351
- )
62352
- );
62353
- }
62354
- handleToggleAll(checked) {
62355
- if (checked) {
62356
- this.allValues.forEach((val) => this.selectedValues.add(val));
62357
- } else {
62358
- this.selectedValues.clear();
62359
- }
62360
- this.render();
62361
- this.params.filterChangedCallback();
62362
- }
62363
- handleToggleOne(value, checked) {
62364
- if (checked) {
62365
- this.selectedValues.add(value);
62366
- } else {
62367
- this.selectedValues.delete(value);
62368
- }
62369
- this.render();
62370
- this.params.filterChangedCallback();
62371
- }
62372
- getGui() {
62373
- return this.gui;
62374
- }
62375
- isFilterActive() {
62376
- return this.selectedValues.size !== this.allValues.length;
62377
- }
62378
- doesFilterPass(p) {
62379
- if (this.selectedValues.size === 0) {
62380
- return false;
62381
- }
62382
- const field = this.params.colDef.field;
62383
- if (!p.data || typeof p.data !== "object") {
62384
- return this.selectedValues.has(EMPTY_KEY);
62385
- }
62386
- const raw = p.data[field];
62387
- const norm = this.normalizeCellValue(raw);
62388
- return this.selectedValues.has(norm);
62389
- }
62390
- getModel() {
62391
- if (this.selectedValues.size !== this.allValues.length) {
62392
- return { values: Array.from(this.selectedValues) };
62393
- }
62394
- return null;
62395
- }
62396
- setModel(model) {
62397
- this.selectedValues = new Set(model?.values || []);
62398
- this.render();
62399
- }
62400
- destroy() {
62401
- if (this.filterButtonClickListener && this.filterButton) {
62402
- this.filterButton.removeEventListener("click", this.filterButtonClickListener, true);
62403
- this.filterButtonClickListener = null;
62404
- this.filterButton = null;
62405
- }
62406
- if (this.reactRoot) {
62407
- this.reactRoot.unmount();
62408
- this.reactRoot = null;
62409
- }
62410
- }
62411
- }
62412
62394
  const createCheckboxMultiFilterParams = (labels = {}, labelFormatter, customOrder) => ({
62413
62395
  labels: { [EMPTY_KEY]: DEFAULT_EMPTY_LABEL, ...labels },
62414
62396
  labelFormatter,
@@ -65188,9 +65170,11 @@ const GridContextProvider = (props) => {
65188
65170
  return ok;
65189
65171
  }
65190
65172
  if (ok) {
65191
- if (!gridApi2.isDestroyed) {
65192
- gridApi2.refreshClientSideRowModel();
65193
- }
65173
+ lodashEs.defer(() => {
65174
+ if (!gridApi2.isDestroyed()) {
65175
+ gridApi2.refreshClientSideRowModel();
65176
+ }
65177
+ });
65194
65178
  }
65195
65179
  void (async () => {
65196
65180
  const postPopupFocusedCell = gridApi2.getFocusedCell();