@linzjs/step-ag-grid 29.11.4 → 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.
@@ -2,7 +2,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
2
  import { LuiMiniSpinner, LuiStatusSpinner, LuiIcon, LuiButtonGroup, LuiButton, LuiCheckboxInput } from '@linzjs/lui';
3
3
  import { ModuleRegistry, AllCommunityModule } from 'ag-grid-community';
4
4
  import { AgGridReact } from 'ag-grid-react';
5
- import { negate, isEmpty, findIndex, defer, debounce as debounce$1, xorBy, last, difference, delay, omit, sortBy, partition, compact, pick, groupBy, fromPairs, toPairs, isEqual, pull, filter, remove, sumBy, flatten, castArray } from 'lodash-es';
5
+ import { negate, isEmpty, findIndex, defer, debounce as debounce$1, xorBy, last, difference, delay, omit, sortBy, partition, compact, pick, groupBy, fromPairs, toPairs, isEqual, pull, filter, sumBy, remove, flatten, castArray } from 'lodash-es';
6
6
  import React, { useRef, useLayoutEffect, useEffect, createContext, useContext, useState, useMemo, memo, forwardRef, useCallback, useReducer, cloneElement, useImperativeHandle, Fragment as Fragment$1, useId } from 'react';
7
7
  import { unstable_batchedUpdates, flushSync, createPortal } from 'react-dom';
8
8
  import { createRoot } from 'react-dom/client';
@@ -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.
@@ -3124,18 +3263,48 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3124
3263
  });
3125
3264
  const adjustColDef = (colDef) => {
3126
3265
  const flex = colDef.flex ?? (sizeColumns === 'fit' ? 1 : undefined);
3127
- return {
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 = {
3128
3295
  ...colDef,
3129
3296
  // You cannot pass a width to a flex
3130
3297
  width: !!colDef.flex ? undefined : colDef.width,
3131
- flexAutoSizeWidth: colDef.width,
3298
+ ...(!!colDef.flex && { flexAutoSizeWidth: colDef.width }),
3132
3299
  // If this is allowed flex columns don't size based on flex
3133
3300
  suppressSizeToFit: true,
3134
3301
  // Auto-sizing flex columns breaks everything
3135
3302
  flex,
3136
3303
  suppressAutoSize: !!flex,
3137
- sortable: colDef.sortable && params.defaultColDef?.sortable !== false,
3304
+ sortable,
3305
+ comparator,
3138
3306
  };
3307
+ return adjustedColDef;
3139
3308
  };
3140
3309
  return columnDefs.map((colDef) => adjustColDefOrGroup(colDef));
3141
3310
  }, [columnDefs, params.defaultColDef?.sortable, sizeColumns]);
@@ -3378,6 +3547,15 @@ const quickFilterParser = (filterStr) => {
3378
3547
  // filter is exact matches exactly groups separated by commas
3379
3548
  return filterStr.split(',').map((str) => str.trim());
3380
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
+ };
3381
3559
 
3382
3560
  const GridPopoverContext = createContext({
3383
3561
  anchorRef: { current: null },
@@ -5640,47 +5818,53 @@ const GridContextProvider = (props) => {
5640
5818
  if (!gridApi || !gridApi.getColumnState()) {
5641
5819
  return null;
5642
5820
  }
5643
- const colIdsSet = colIds instanceof Set ? colIds : new Set(colIds);
5644
- const getVisibleColStates = () => {
5645
- const colStates = gridApi.getColumnState();
5646
- return colStates.filter((colState) => {
5647
- const colId = colState.colId;
5648
- 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;
5649
5839
  });
5650
- };
5651
- const getFlexColStates = () => getVisibleColStates().filter(colStateFlexed);
5652
- const getNonFlexColStates = () => getVisibleColStates().filter(colStateNotFlexed);
5653
- // You cannot autosize flex columns it will break layout randomly
5654
- // So, a flex column is assumed to be 150 wide, unless width is provided
5655
- const flexColumns = getFlexColStates().map(colStateId);
5656
- let width = 0;
5657
- flexColumns.forEach((colId) => {
5658
- const colDef = gridApi.getColumnDef(colId);
5659
- width += colDef?.flexAutoSizeWidth ?? 200;
5660
- });
5661
- const nonFlexColumns = getNonFlexColStates();
5662
- const nonFlexColumnIds = nonFlexColumns.map(colStateId);
5663
- gridApi.autoSizeColumns({ colIds: nonFlexColumnIds, skipHeader });
5664
- const calcSubWidth = () => {
5665
- const updatedFlexColumns = getVisibleColStates().filter((colState) => nonFlexColumnIds.includes(colState.colId));
5666
- return sumBy(updatedFlexColumns.filter((col) => !col.hide), 'width');
5667
- };
5668
- // ag-grid updates widths asynchronously, so we wait here for the default calculated width to change
5669
- let lastSubWidth = calcSubWidth();
5670
- const endTime = Date.now() + 1000;
5671
- while (Date.now() < endTime) {
5672
- await wait(40);
5673
- const newSubWidth = calcSubWidth();
5674
- if (lastSubWidth !== newSubWidth) {
5675
- lastSubWidth = newSubWidth;
5676
- break;
5840
+ const nonFlexColumns = getNonFlexColStates();
5841
+ const nonFlexColumnIds = nonFlexColumns.map(colStateId);
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
+ }
5677
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;
5678
5867
  }
5679
- width += lastSubWidth;
5680
- gridApi.sizeColumnsToFit();
5681
- return {
5682
- width,
5683
- };
5684
5868
  }, [gridApi]);
5685
5869
  /**
5686
5870
  * Resize columns to fit container
@@ -6164,5 +6348,5 @@ const useDeferredPromise = () => {
6164
6348
  };
6165
6349
  };
6166
6350
 
6167
- 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 };
6168
6352
  //# sourceMappingURL=step-ag-grid.esm.js.map