@linzjs/step-ag-grid 29.11.3 → 29.12.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.
@@ -507,9 +507,9 @@ const GridContext = createContext({
507
507
  console.error('no context provider for getFirstRowId');
508
508
  return -1;
509
509
  },
510
- autoSizeColumns: () => {
510
+ autoSizeColumns: async () => {
511
511
  console.error('no context provider for autoSizeColumns');
512
- return null;
512
+ return Promise.resolve(null);
513
513
  },
514
514
  sizeColumnsToFit: () => {
515
515
  console.error('no context provider for autoSizeAllColumns');
@@ -590,6 +590,131 @@ const GridUpdatingContext = createContext({
590
590
  updatedDep: 0,
591
591
  });
592
592
 
593
+ var lib = {};
594
+
595
+ var hasRequiredLib;
596
+
597
+ function requireLib () {
598
+ if (hasRequiredLib) return lib;
599
+ hasRequiredLib = 1;
600
+ Object.defineProperty(lib, "__esModule", { value: true });
601
+ function natsort(options) {
602
+ if (options === void 0) { options = {}; }
603
+ var ore = /^0/;
604
+ var sre = /\s+/g;
605
+ var tre = /^\s+|\s+$/g;
606
+ // unicode
607
+ var ure = /[^\x00-\x80]/;
608
+ // hex
609
+ var hre = /^0x[0-9a-f]+$/i;
610
+ // numeric
611
+ var nre = /(0x[\da-fA-F]+|(^[\+\-]?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?(?=\D|\s|$))|\d+)/g;
612
+ // datetime
613
+ var dre = /(^([\w ]+,?[\w ]+)?[\w ]+,?[\w ]+\d+:\d+(:\d+)?[\w ]?|^\d{1,4}[\/\-]\d{1,4}[\/\-]\d{1,4}|^\w+, \w+ \d+, \d{4})/; // tslint:disable-line
614
+ var toLowerCase = String.prototype.toLocaleLowerCase || String.prototype.toLowerCase;
615
+ var GREATER = options.desc ? -1 : 1;
616
+ var SMALLER = -GREATER;
617
+ var normalize = options.insensitive
618
+ ? function (s) { return toLowerCase.call("" + s).replace(tre, ''); }
619
+ : function (s) { return ("" + s).replace(tre, ''); };
620
+ function tokenize(s) {
621
+ return s.replace(nre, '\0$1\0')
622
+ .replace(/\0$/, '')
623
+ .replace(/^\0/, '')
624
+ .split('\0');
625
+ }
626
+ function parse(s, l) {
627
+ // normalize spaces; find floats not starting with '0',
628
+ // string or 0 if not defined (Clint Priest)
629
+ return (!s.match(ore) || l === 1)
630
+ && parseFloat(s)
631
+ || s.replace(sre, ' ').replace(tre, '')
632
+ || 0;
633
+ }
634
+ return function (a, b) {
635
+ // trim pre-post whitespace
636
+ var aa = normalize(a);
637
+ var bb = normalize(b);
638
+ // return immediately if at least one of the values is empty.
639
+ // empty string < any others
640
+ if (!aa && !bb) {
641
+ return 0;
642
+ }
643
+ if (!aa && bb) {
644
+ return SMALLER;
645
+ }
646
+ if (aa && !bb) {
647
+ return GREATER;
648
+ }
649
+ // tokenize: split numeric strings and default strings
650
+ var aArr = tokenize(aa);
651
+ var bArr = tokenize(bb);
652
+ // hex or date detection
653
+ var aHex = aa.match(hre);
654
+ var bHex = bb.match(hre);
655
+ var av = (aHex && bHex) ? parseInt(aHex[0], 16) : (aArr.length !== 1 && Date.parse(aa));
656
+ var bv = (aHex && bHex)
657
+ ? parseInt(bHex[0], 16)
658
+ : av && bb.match(dre) && Date.parse(bb) || null;
659
+ // try and sort Hex codes or Dates
660
+ if (bv) {
661
+ if (av === bv) {
662
+ return 0;
663
+ }
664
+ if (av < bv) {
665
+ return SMALLER;
666
+ }
667
+ if (av > bv) {
668
+ return GREATER;
669
+ }
670
+ }
671
+ var al = aArr.length;
672
+ var bl = bArr.length;
673
+ // handle numeric strings and default strings
674
+ for (var i = 0, l = Math.max(al, bl); i < l; i += 1) {
675
+ var af = parse(aArr[i] || '', al);
676
+ var bf = parse(bArr[i] || '', bl);
677
+ // handle numeric vs string comparison.
678
+ // numeric < string
679
+ if (isNaN(af) !== isNaN(bf)) {
680
+ return isNaN(af) ? GREATER : SMALLER;
681
+ }
682
+ // if unicode use locale comparison
683
+ if (ure.test(af + bf) && af.localeCompare) {
684
+ var comp = af.localeCompare(bf);
685
+ if (comp > 0) {
686
+ return GREATER;
687
+ }
688
+ if (comp < 0) {
689
+ return SMALLER;
690
+ }
691
+ if (i === l - 1) {
692
+ return 0;
693
+ }
694
+ }
695
+ if (af < bf) {
696
+ return SMALLER;
697
+ }
698
+ if (af > bf) {
699
+ return GREATER;
700
+ }
701
+ if ("" + af < "" + bf) {
702
+ return SMALLER;
703
+ }
704
+ if ("" + af > "" + bf) {
705
+ return GREATER;
706
+ }
707
+ }
708
+ return 0;
709
+ };
710
+ }
711
+ lib.default = natsort;
712
+ return lib;
713
+ }
714
+
715
+ var libExports = requireLib();
716
+ var natsort = /*@__PURE__*/getDefaultExportFromCjs(libExports);
717
+
593
718
  const isNotEmpty = negate(isEmpty);
594
719
  const wait = (timeoutMs) => new Promise((resolve) => {
595
720
  setTimeout(resolve, timeoutMs);
@@ -641,6 +766,20 @@ const sanitiseFileName = (filename) => {
641
766
  return valid.slice().slice(0, 64);
642
767
  return valid.slice(0, -fileExt.length - 1).slice(0, 64) + '.' + fileExt;
643
768
  };
769
+ const naturalSortInsensitive = natsort({ insensitive: true });
770
+ const santitizeNaturalValue = (v) => {
771
+ if (v === '–' || v === '-' || v == null) {
772
+ return '';
773
+ }
774
+ return String(v);
775
+ };
776
+ const compareNaturalInsensitive = (a, b) => {
777
+ if ((a !== null && typeof a === 'object') || (b !== null && typeof b === 'object')) {
778
+ // We can't compare objects
779
+ return 0;
780
+ }
781
+ return naturalSortInsensitive(santitizeNaturalValue(a), santitizeNaturalValue(b));
782
+ };
644
783
 
645
784
  /**
646
785
  * AgGrid checkbox select does not pass clicks within cell but not on the checkbox to checkbox.
@@ -2785,66 +2924,77 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2785
2924
  const needsAutoSize = useRef(true);
2786
2925
  const autoSizeResultRef = useRef(null);
2787
2926
  const prevRowsVisibleRef = useRef(false);
2788
- const setInitialContentSize = useCallback(() => {
2789
- if (!gridDivRef.current?.clientWidth || rowData == null) {
2790
- // Don't resize grids if they are offscreen as it doesn't work.
2791
- needsAutoSize.current = true;
2792
- return;
2793
- }
2794
- const gridRendered = gridRenderState();
2795
- if (gridRendered === null) {
2796
- // Don't resize until grid has rendered, or it has 0 rows.
2797
- needsAutoSize.current = true;
2927
+ const initialContentSizeInProgressRef = useRef(false);
2928
+ const setInitialContentSize = useCallback(async () => {
2929
+ if (initialContentSizeInProgressRef.current) {
2798
2930
  return;
2799
2931
  }
2800
- // 1. First we autosize to get the size of the columns on an infinite grid.
2801
- if (sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') {
2802
- // You can't skip headers until the grid has content
2803
- const rowsVisible = gridRendered === 'rows-visible';
2804
- const skipHeader = sizeColumns === 'auto-skip-headers' && rowsVisible;
2805
- // If grid was empty and now has content we need to autosize
2806
- if (rowsVisible !== prevRowsVisibleRef.current && rowsVisible) {
2807
- prevRowsVisibleRef.current = rowsVisible;
2808
- autoSizeResultRef.current = null;
2932
+ initialContentSizeInProgressRef.current = true;
2933
+ try {
2934
+ needsAutoSize.current = false;
2935
+ if (!gridDivRef.current?.clientWidth || rowData == null) {
2936
+ // Don't resize grids if they are offscreen as it doesn't work.
2937
+ needsAutoSize.current = true;
2938
+ return;
2809
2939
  }
2810
- const autoSizeResult = autoSizeResultRef.current ??
2811
- autoSizeColumns({
2812
- skipHeader,
2813
- userSizedColIds: new Set(userSizedColIds.current.keys()),
2814
- });
2815
- // Auto-size failed retry later
2816
- if (!autoSizeResult) {
2940
+ const gridRendered = gridRenderState();
2941
+ if (gridRendered === null) {
2942
+ // Don't resize until grid has rendered, or it has 0 rows.
2817
2943
  needsAutoSize.current = true;
2818
2944
  return;
2819
2945
  }
2820
- autoSizeResultRef.current = autoSizeResult;
2821
- // Calculate the auto-sized width, limit it to maxInitialWidth
2822
- autoSizeResult.width = maxInitialWidth ? Math.min(autoSizeResult.width, maxInitialWidth) : autoSizeResult.width;
2823
- if (gridRendered === 'empty') {
2824
- // If the grid is empty we still do an onContentSize callback, we will do another callback when grid has data
2825
- // We don't do this callback if we have previously had row data, or have already called back for empty
2826
- if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
2827
- hasSetContentSizeEmpty.current = true;
2828
- params.onContentSize?.(autoSizeResult);
2946
+ // 1. First we autosize to get the size of the columns on an infinite grid.
2947
+ if (sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') {
2948
+ // You can't skip headers until the grid has content
2949
+ const rowsVisible = gridRendered === 'rows-visible';
2950
+ const skipHeader = sizeColumns === 'auto-skip-headers' && rowsVisible;
2951
+ // If grid was empty and now has content we need to autosize
2952
+ if (rowsVisible !== prevRowsVisibleRef.current && rowsVisible) {
2953
+ prevRowsVisibleRef.current = rowsVisible;
2954
+ autoSizeResultRef.current = null;
2829
2955
  }
2830
- }
2831
- else if (gridRendered === 'rows-visible') {
2832
- // we have rows now so callback grid size
2833
- if (!hasSetContentSize.current) {
2834
- hasSetContentSize.current = true;
2835
- params.onContentSize?.(autoSizeResult);
2956
+ const autoSizeResult = autoSizeResultRef.current ??
2957
+ (await autoSizeColumns({
2958
+ skipHeader,
2959
+ userSizedColIds: new Set(userSizedColIds.current.keys()),
2960
+ }));
2961
+ // Auto-size failed retry later
2962
+ if (!autoSizeResult) {
2963
+ needsAutoSize.current = true;
2964
+ return;
2965
+ }
2966
+ autoSizeResultRef.current = autoSizeResult;
2967
+ // Calculate the auto-sized width, limit it to maxInitialWidth
2968
+ autoSizeResult.width = maxInitialWidth ? Math.min(autoSizeResult.width, maxInitialWidth) : autoSizeResult.width;
2969
+ if (gridRendered === 'empty') {
2970
+ // If the grid is empty we still do an onContentSize callback, we will do another callback when grid has data
2971
+ // We don't do this callback if we have previously had row data, or have already called back for empty
2972
+ if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
2973
+ hasSetContentSizeEmpty.current = true;
2974
+ params.onContentSize?.(autoSizeResult);
2975
+ }
2976
+ }
2977
+ else if (gridRendered === 'rows-visible') {
2978
+ // we have rows now so callback grid size
2979
+ if (!hasSetContentSize.current) {
2980
+ hasSetContentSize.current = true;
2981
+ params.onContentSize?.(autoSizeResult);
2982
+ }
2983
+ }
2984
+ else {
2985
+ // It should be impossible to get here
2986
+ console.error('Unknown value returned from hasGridRendered');
2836
2987
  }
2837
2988
  }
2838
2989
  else {
2839
- // It should be impossible to get here
2840
- console.error('Unknown value returned from hasGridRendered');
2990
+ sizeColumnsToFit();
2841
2991
  }
2992
+ setAutoSized(true);
2993
+ needsAutoSize.current = false;
2842
2994
  }
2843
- else {
2844
- sizeColumnsToFit();
2995
+ finally {
2996
+ initialContentSizeInProgressRef.current = false;
2845
2997
  }
2846
- setAutoSized(true);
2847
- needsAutoSize.current = false;
2848
2998
  }, [autoSizeColumns, gridRenderState, maxInitialWidth, params, rowData, sizeColumns, sizeColumnsToFit]);
2849
2999
  const lastOwnerDocumentRef = useRef();
2850
3000
  const wasVisibleRef = useRef(false);
@@ -2878,8 +3028,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2878
3028
  }
2879
3029
  if (needsAutoSize.current ||
2880
3030
  (!hasSetContentSize.current && (sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers'))) {
2881
- needsAutoSize.current = false;
2882
- setInitialContentSize();
3031
+ void setInitialContentSize();
2883
3032
  }
2884
3033
  }, 200);
2885
3034
  /**
@@ -3008,11 +3157,13 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3008
3157
  if (previousRowDataLength.current !== length) {
3009
3158
  // We need to autosize all cells again
3010
3159
  autoSizeResultRef.current = null;
3011
- setInitialContentSize();
3012
3160
  previousRowDataLength.current = length;
3161
+ void setInitialContentSize();
3162
+ return;
3013
3163
  }
3014
- if (lastUpdatedDep.current === updatedDep || isEmpty(colIdsEdited.current))
3164
+ if (lastUpdatedDep.current === updatedDep || isEmpty(colIdsEdited.current)) {
3015
3165
  return;
3166
+ }
3016
3167
  lastUpdatedDep.current = updatedDep;
3017
3168
  // Don't update while there are spinners
3018
3169
  if (anyUpdating()) {
@@ -3020,7 +3171,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3020
3171
  }
3021
3172
  const skipHeader = sizeColumns === 'auto-skip-headers';
3022
3173
  if ((sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') && hasSetContentSize.current) {
3023
- autoSizeColumns({
3174
+ void autoSizeColumns({
3024
3175
  skipHeader,
3025
3176
  userSizedColIds: new Set(userSizedColIds.current.keys()),
3026
3177
  colIds: colIdsEdited.current,
@@ -3110,11 +3261,51 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3110
3261
  ...colDef,
3111
3262
  children: colDef.children.map((colDef) => adjustColDefOrGroup(colDef)),
3112
3263
  });
3113
- const adjustColDef = (colDef) => ({
3114
- ...colDef,
3115
- suppressSizeToFit: (sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') && !colDef.flex,
3116
- sortable: colDef.sortable && params.defaultColDef?.sortable !== false,
3117
- });
3264
+ const adjustColDef = (colDef) => {
3265
+ const flex = colDef.flex ?? (sizeColumns === 'fit' ? 1 : undefined);
3266
+ const valueFormatter = colDef.valueFormatter;
3267
+ const sortable = colDef.sortable && params.defaultColDef?.sortable !== false;
3268
+ let comparator = colDef.comparator;
3269
+ if (sortable && !comparator) {
3270
+ comparator = (value1, value2, node1, node2) => {
3271
+ let r = 0;
3272
+ if (typeof valueFormatter === 'function') {
3273
+ r = compareNaturalInsensitive(valueFormatter({
3274
+ data: node1.data,
3275
+ value: value1,
3276
+ node: node1,
3277
+ colDef: adjustedColDef,
3278
+ ...NotAGridValueFormatterCall,
3279
+ }), valueFormatter({
3280
+ data: node2.data,
3281
+ value: value2,
3282
+ node: node2,
3283
+ colDef: adjustedColDef,
3284
+ ...NotAGridValueFormatterCall,
3285
+ }));
3286
+ }
3287
+ else {
3288
+ r = compareNaturalInsensitive(value1, value2);
3289
+ }
3290
+ // secondary compare as primary sort column rows are equal
3291
+ return r === 0 ? compareNaturalInsensitive(node1.data?.id, node2.data?.id) : r;
3292
+ };
3293
+ }
3294
+ const adjustedColDef = {
3295
+ ...colDef,
3296
+ // You cannot pass a width to a flex
3297
+ width: !!colDef.flex ? undefined : colDef.width,
3298
+ ...(!!colDef.flex && { flexAutoSizeWidth: colDef.width }),
3299
+ // If this is allowed flex columns don't size based on flex
3300
+ suppressSizeToFit: true,
3301
+ // Auto-sizing flex columns breaks everything
3302
+ flex,
3303
+ suppressAutoSize: !!flex,
3304
+ sortable,
3305
+ comparator,
3306
+ };
3307
+ return adjustedColDef;
3308
+ };
3118
3309
  return columnDefs.map((colDef) => adjustColDefOrGroup(colDef));
3119
3310
  }, [columnDefs, params.defaultColDef?.sortable, sizeColumns]);
3120
3311
  /**
@@ -3139,7 +3330,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3139
3330
  if (sizeColumns === 'auto' || skipHeader) {
3140
3331
  defer(() => {
3141
3332
  if (hasSetContentSize.current) {
3142
- autoSizeColumns({
3333
+ void autoSizeColumns({
3143
3334
  skipHeader,
3144
3335
  userSizedColIds: new Set(userSizedColIds.current.keys()),
3145
3336
  colIds: colIdsEdited.current,
@@ -3294,7 +3485,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3294
3485
  }, [columnDefs, params.loading, params.noRowsMatchingOverlayText, params.noRowsOverlayText, rowData, rowHeight]);
3295
3486
  const selectionColumnDef = useMemo(() => {
3296
3487
  // Note this has to be 1 for hidden otherwise ag-grid does crazy things whilst resizing
3297
- const selectWidth = params.hideSelectColumn ? 0 : selectable && params.onRowDragEnd ? 76 : 48;
3488
+ const selectWidth = params.onRowDragEnd ? 76 : 48;
3298
3489
  return {
3299
3490
  suppressNavigable: params.hideSelectColumn,
3300
3491
  rowDrag: !!params.onRowDragEnd,
@@ -3304,6 +3495,8 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3304
3495
  headerComponentParams: {
3305
3496
  exportable: false,
3306
3497
  },
3498
+ suppressAutoSize: true,
3499
+ suppressSizeToFit: true,
3307
3500
  headerClass: clsx('ag-header-hide-default-select', params.onRowDragEnd && 'ag-header-select-draggable'),
3308
3501
  headerComponent: rowSelection == 'multiple' ? GridHeaderSelect : undefined,
3309
3502
  suppressHeaderKeyboardEvent: (e) => {
@@ -3334,7 +3527,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3334
3527
  selectable,
3335
3528
  ]);
3336
3529
  const onGridSizeChanged = useCallback((event) => {
3337
- if (sizeColumns === 'fit') {
3530
+ if (sizeColumns === 'fit' || (['auto', 'auto-skip-headers'].includes(sizeColumns) && hasSetContentSize.current)) {
3338
3531
  event.api.sizeColumnsToFit();
3339
3532
  }
3340
3533
  }, [sizeColumns]);
@@ -3343,13 +3536,26 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3343
3536
  enableSelectionWithoutKeys: params.enableSelectionWithoutKeys ?? false,
3344
3537
  enableClickSelection: params.enableClickSelection ?? false,
3345
3538
  mode: rowSelection === 'single' ? 'singleRow' : 'multiRow',
3539
+ ...(params.hideSelectColumn && {
3540
+ checkboxes: false,
3541
+ headerCheckbox: false,
3542
+ }),
3346
3543
  }
3347
- : undefined, rowHeight: rowHeight, animateRows: params.animateRows ?? false, rowClassRules: params.rowClassRules, getRowId: getRowId, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onGridSizeChanged: onGridSizeChanged, onColumnVisible: setInitialContentSize, onRowDataUpdated: onRowDataUpdated, onCellFocused: onCellFocused, onCellKeyDown: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, onCellEditingStopped: onCellEditingStopped, domLayout: params.domLayout, onColumnResized: onColumnResized, defaultColDef: defaultColDef, columnDefs: columnDefsAdjusted, selectionColumnDef: selectionColumnDef, rowData: rowData, postSortRows: params.onRowDragEnd || !defaultPostSort ? undefined : postSortRows, onModelUpdated: onModelUpdated, onGridReady: onGridReady, onSortChanged: ensureSelectedRowIsVisible, quickFilterParser: quickFilterParser, onSelectionChanged: synchroniseExternalStateToGridSelection, onColumnMoved: params.onColumnMoved, noRowsOverlayComponent: noRowsOverlayComponent, alwaysShowVerticalScroll: params.alwaysShowVerticalScroll, isExternalFilterPresent: isExternalFilterPresent, doesExternalFilterPass: doesExternalFilterPass, maintainColumnOrder: true, preventDefaultOnContextMenu: true, onCellContextMenu: gridContextMenu.cellContextMenu, rowDragText: params.rowDragText, onRowDragCancel: clearHighlightRowClasses, onRowDragMove: onRowDragMove, onRowDragEnd: onRowDragEnd, suppressCellFocus: params.suppressCellFocus, pinnedTopRowData: params.pinnedTopRowData, pinnedBottomRowData: params.pinnedBottomRowData, onRowClicked: params.onRowClicked, onRowDoubleClicked: params.onRowDoubleClicked, suppressStartEditOnTab: true }) })] }));
3544
+ : undefined, selectionColumnDef: selectionColumnDef, rowHeight: rowHeight, animateRows: params.animateRows ?? false, rowClassRules: params.rowClassRules, getRowId: getRowId, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onGridSizeChanged: onGridSizeChanged, onColumnVisible: () => void setInitialContentSize(), onRowDataUpdated: onRowDataUpdated, onCellFocused: onCellFocused, onCellKeyDown: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, onCellEditingStopped: onCellEditingStopped, domLayout: params.domLayout, onColumnResized: onColumnResized, defaultColDef: defaultColDef, columnDefs: columnDefsAdjusted, rowData: rowData, postSortRows: params.onRowDragEnd || !defaultPostSort ? undefined : postSortRows, onModelUpdated: onModelUpdated, onGridReady: onGridReady, onSortChanged: ensureSelectedRowIsVisible, quickFilterParser: quickFilterParser, onSelectionChanged: synchroniseExternalStateToGridSelection, onColumnMoved: params.onColumnMoved, noRowsOverlayComponent: noRowsOverlayComponent, alwaysShowVerticalScroll: params.alwaysShowVerticalScroll, isExternalFilterPresent: isExternalFilterPresent, doesExternalFilterPass: doesExternalFilterPass, maintainColumnOrder: true, preventDefaultOnContextMenu: true, onCellContextMenu: gridContextMenu.cellContextMenu, rowDragText: params.rowDragText, onRowDragCancel: clearHighlightRowClasses, onRowDragMove: onRowDragMove, onRowDragEnd: onRowDragEnd, suppressCellFocus: params.suppressCellFocus, pinnedTopRowData: params.pinnedTopRowData, pinnedBottomRowData: params.pinnedBottomRowData, onRowClicked: params.onRowClicked, onRowDoubleClicked: params.onRowDoubleClicked, suppressStartEditOnTab: true }) })] }));
3348
3545
  };
3349
3546
  const quickFilterParser = (filterStr) => {
3350
3547
  // filter is exact matches exactly groups separated by commas
3351
3548
  return filterStr.split(',').map((str) => str.trim());
3352
3549
  };
3550
+ /**
3551
+ * Columns to indicate to user when they debug why things are broken in the default comparator if their valueFormatter
3552
+ * is too complicated.
3553
+ */
3554
+ const NotAGridValueFormatterCall = {
3555
+ column: 'Default comparator has no access to column, write your own comparator',
3556
+ api: 'Default comparator has no access to api, write your own comparator',
3557
+ context: 'Default comparator has no access to context, write your own comparator',
3558
+ };
3353
3559
 
3354
3560
  const GridPopoverContext = createContext({
3355
3561
  anchorRef: { current: null },
@@ -5608,40 +5814,57 @@ const GridContextProvider = (props) => {
5608
5814
  * If you don't clear flex column widths ag-grid gets confused and does random sizing's.
5609
5815
  * Then we size the flexed columns.
5610
5816
  */
5611
- const autoSizeColumns = useCallback(({ skipHeader, colIds, userSizedColIds } = {}) => {
5817
+ const autoSizeColumns = useCallback(async ({ skipHeader, colIds, userSizedColIds } = {}) => {
5612
5818
  if (!gridApi || !gridApi.getColumnState()) {
5613
5819
  return null;
5614
5820
  }
5615
- const colIdsSet = colIds instanceof Set ? colIds : new Set(colIds);
5616
- const getVisibleColStates = () => {
5617
- const colStates = gridApi.getColumnState();
5618
- return colStates.filter((colState) => {
5619
- const colId = colState.colId;
5620
- return (isEmpty(colIdsSet) || colIdsSet.has(colId)) && !userSizedColIds?.has(colId);
5821
+ try {
5822
+ const colIdsSet = colIds instanceof Set ? colIds : new Set(colIds);
5823
+ const getVisibleColStates = () => {
5824
+ const colStates = gridApi.getColumnState();
5825
+ return colStates.filter((colState) => {
5826
+ const colId = colState.colId;
5827
+ return (isEmpty(colIdsSet) || colIdsSet.has(colId)) && !userSizedColIds?.has(colId);
5828
+ });
5829
+ };
5830
+ const getFlexColStates = () => getVisibleColStates().filter(colStateFlexed);
5831
+ const getNonFlexColStates = () => getVisibleColStates().filter(colStateNotFlexed);
5832
+ // You cannot autosize flex columns it will break layout randomly
5833
+ // So, a flex column is assumed to be 150 wide, unless width is provided
5834
+ const flexColumns = getFlexColStates().map(colStateId);
5835
+ let width = 0;
5836
+ flexColumns.forEach((colId) => {
5837
+ const colDef = gridApi.getColumnDef(colId);
5838
+ width += colDef?.flexAutoSizeWidth ?? 200;
5621
5839
  });
5622
- };
5623
- const getFlexColStates = () => getVisibleColStates().filter(colStateFlexed);
5624
- const getNonFlexColStates = () => getVisibleColStates().filter(colStateNotFlexed);
5625
- // If we don't reset the flex columns auto size it causes issues with random resizing of flex columns
5626
- let flexColumns = getFlexColStates();
5627
- let width = 0;
5628
- if (!isEmpty(flexColumns)) {
5629
- gridApi.autoSizeColumns(flexColumns.map(colStateId), skipHeader);
5630
- const flexColumnIds = flexColumns.map(colStateId);
5631
- flexColumns = getVisibleColStates().filter((colState) => flexColumnIds.includes(colState.colId));
5632
- width += sumBy(flexColumns.filter((col) => !col.hide), 'width');
5633
- gridApi.resetColumnState();
5634
- }
5635
- let nonFlexColumns = getNonFlexColStates();
5636
- if (!isEmpty(nonFlexColumns)) {
5637
- gridApi.autoSizeColumns(nonFlexColumns.map(colStateId), skipHeader);
5840
+ const nonFlexColumns = getNonFlexColStates();
5638
5841
  const nonFlexColumnIds = nonFlexColumns.map(colStateId);
5639
- nonFlexColumns = getVisibleColStates().filter((colState) => nonFlexColumnIds.includes(colState.colId));
5640
- width += sumBy(nonFlexColumns.filter((col) => !col.hide), 'width');
5842
+ gridApi.autoSizeColumns({ colIds: nonFlexColumnIds, skipHeader });
5843
+ const calcSubWidth = () => {
5844
+ const updatedFlexColumns = getVisibleColStates().filter((colState) => nonFlexColumnIds.includes(colState.colId));
5845
+ return sumBy(updatedFlexColumns.filter((col) => !col.hide), 'width');
5846
+ };
5847
+ // ag-grid updates widths asynchronously, so we wait here for the default calculated width to change
5848
+ let lastSubWidth = calcSubWidth();
5849
+ const endTime = Date.now() + 1000;
5850
+ while (Date.now() < endTime) {
5851
+ await wait(40);
5852
+ const newSubWidth = calcSubWidth();
5853
+ if (lastSubWidth !== newSubWidth) {
5854
+ lastSubWidth = newSubWidth;
5855
+ break;
5856
+ }
5857
+ }
5858
+ width += lastSubWidth;
5859
+ gridApi.sizeColumnsToFit();
5860
+ return {
5861
+ width,
5862
+ };
5863
+ }
5864
+ catch (ex) {
5865
+ console.info('autosize failed', ex);
5866
+ return null;
5641
5867
  }
5642
- return {
5643
- width,
5644
- };
5645
5868
  }, [gridApi]);
5646
5869
  /**
5647
5870
  * Resize columns to fit container
@@ -6125,5 +6348,5 @@ const useDeferredPromise = () => {
6125
6348
  };
6126
6349
  };
6127
6350
 
6128
- export { ActionButton, CancelPromise, ComponentLoadingWrapper, ControlledMenu, Editor, FocusableItem, FormError, GenericCellEditorComponentWrapper, Grid, GridButton, GridCell, GridCellFiller, GridCellFillerColId, GridCellMultiEditor, GridCellMultiSelectClassRules, GridCellRenderer, GridContext, GridContextProvider, GridEditBoolean, GridFilterButtons, GridFilterColumnsMultiSelect, GridFilterColumnsToggle, GridFilterDownloadCsvButton, GridFilterHeaderIconButton, GridFilterQuick, GridFilters, GridFormDropDown, GridFormEditBearing, GridFormMessage, GridFormMultiSelect, GridFormMultiSelectGrid, GridFormPopoverMenu, GridFormSubComponentTextArea, GridFormSubComponentTextInput, GridFormTextArea, GridFormTextInput, GridIcon, GridLoadableCell, GridNoRowsOverlay, GridNoRowsOverlayFr, GridPopoutEditMultiSelect, GridPopoutEditMultiSelectGrid, GridPopoverContext, GridPopoverContextProvider, GridPopoverEditBearing, GridPopoverEditBearingCorrection, GridPopoverEditBearingCorrectionEditorParams, GridPopoverEditBearingEditorParams, GridPopoverEditDropDown, GridPopoverMenu, GridPopoverMessage, GridPopoverTextArea, GridPopoverTextInput, GridRenderPopoutMenuCell, GridSubComponentContext, GridUpdatingContext, GridUpdatingContextProvider, GridWrapper, Menu, MenuButton, MenuDivider, MenuGroup, MenuHeader, MenuHeaderItem, MenuHeaderString, MenuItem, MenuRadioGroup, MenuSeparator, MenuSeparatorString, PopoutMenuSeparator, SubMenu, TextAreaInput, TextInputFormatted, TextInputValidator, bearingCorrectionRangeValidator, bearingCorrectionValueFormatter, bearingNumberParser, bearingRangeValidator, bearingStringValidator, bearingValueFormatter, colStateFlexed, colStateId, colStateNotFlexed, convertDDToDMS, createCheckboxMultiFilterParams, defaultValueFormatter, downloadCsvUseValueFormattersProcessCellCallback, findParentWithClass, fnOrVar, generateFilterGetter, hasParentClass, isFloat, isGridCellFiller, isNotEmpty, primitiveToSelectOption, sanitiseFileName, stringByteLengthIsInvalid, suppressCellKeyboardEvents, textMatch, useDeferredPromise, useGridContext, useGridContextMenu, useGridFilter, useGridPopoverContext, useGridPopoverHook, useMenuState, usePostSortRowsHook, wait, waitForCondition };
6351
+ export { ActionButton, CancelPromise, ComponentLoadingWrapper, ControlledMenu, Editor, FocusableItem, FormError, GenericCellEditorComponentWrapper, Grid, GridButton, GridCell, GridCellFiller, GridCellFillerColId, GridCellMultiEditor, GridCellMultiSelectClassRules, GridCellRenderer, GridContext, GridContextProvider, GridEditBoolean, GridFilterButtons, GridFilterColumnsMultiSelect, GridFilterColumnsToggle, GridFilterDownloadCsvButton, GridFilterHeaderIconButton, GridFilterQuick, GridFilters, GridFormDropDown, GridFormEditBearing, GridFormMessage, GridFormMultiSelect, GridFormMultiSelectGrid, GridFormPopoverMenu, GridFormSubComponentTextArea, GridFormSubComponentTextInput, GridFormTextArea, GridFormTextInput, GridIcon, GridLoadableCell, GridNoRowsOverlay, GridNoRowsOverlayFr, GridPopoutEditMultiSelect, GridPopoutEditMultiSelectGrid, GridPopoverContext, GridPopoverContextProvider, GridPopoverEditBearing, GridPopoverEditBearingCorrection, GridPopoverEditBearingCorrectionEditorParams, GridPopoverEditBearingEditorParams, GridPopoverEditDropDown, GridPopoverMenu, GridPopoverMessage, GridPopoverTextArea, GridPopoverTextInput, GridRenderPopoutMenuCell, GridSubComponentContext, GridUpdatingContext, GridUpdatingContextProvider, GridWrapper, Menu, MenuButton, MenuDivider, MenuGroup, MenuHeader, MenuHeaderItem, MenuHeaderString, MenuItem, MenuRadioGroup, MenuSeparator, MenuSeparatorString, PopoutMenuSeparator, SubMenu, TextAreaInput, TextInputFormatted, TextInputValidator, bearingCorrectionRangeValidator, bearingCorrectionValueFormatter, bearingNumberParser, bearingRangeValidator, bearingStringValidator, bearingValueFormatter, colStateFlexed, colStateId, colStateNotFlexed, compareNaturalInsensitive, convertDDToDMS, createCheckboxMultiFilterParams, defaultValueFormatter, downloadCsvUseValueFormattersProcessCellCallback, findParentWithClass, fnOrVar, generateFilterGetter, hasParentClass, isFloat, isGridCellFiller, isNotEmpty, primitiveToSelectOption, sanitiseFileName, stringByteLengthIsInvalid, suppressCellKeyboardEvents, textMatch, useDeferredPromise, useGridContext, useGridContextMenu, useGridFilter, useGridPopoverContext, useGridPopoverHook, useMenuState, usePostSortRowsHook, wait, waitForCondition };
6129
6352
  //# sourceMappingURL=step-ag-grid.esm.js.map