@xh/hoist 72.0.0-SNAPSHOT.1737725354262 → 72.0.0-SNAPSHOT.1737748132453

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.
package/cmp/grid/Grid.ts CHANGED
@@ -4,9 +4,10 @@
4
4
  *
5
5
  * Copyright © 2025 Extremely Heavy Industries Inc.
6
6
  */
7
+ import {ColumnState as AgColumnState, GridApi} from '@ag-grid-community/core';
7
8
  import composeRefs from '@seznam/compose-react-refs';
8
9
  import {agGrid, AgGrid} from '@xh/hoist/cmp/ag-grid';
9
- import {getTreeStyleClasses} from '@xh/hoist/cmp/grid';
10
+ import {ColumnState, getTreeStyleClasses} from '@xh/hoist/cmp/grid';
10
11
  import {gridHScrollbar} from '@xh/hoist/cmp/grid/impl/GridHScrollbar';
11
12
  import {getAgGridMenuItems} from '@xh/hoist/cmp/grid/impl/MenuSupport';
12
13
  import {div, fragment, frame, vframe} from '@xh/hoist/cmp/layout';
@@ -17,6 +18,7 @@ import {
17
18
  LayoutProps,
18
19
  lookup,
19
20
  PlainObject,
21
+ ReactionSpec,
20
22
  TestSupportProps,
21
23
  useLocalModel,
22
24
  uses,
@@ -44,7 +46,7 @@ import {wait} from '@xh/hoist/promise';
44
46
  import {consumeEvent, isDisplayed, logWithDebug} from '@xh/hoist/utils/js';
45
47
  import {createObservableRef, getLayoutProps} from '@xh/hoist/utils/react';
46
48
  import classNames from 'classnames';
47
- import {debounce, isEmpty, isEqual, isNil, max, maxBy, merge} from 'lodash';
49
+ import {compact, debounce, isBoolean, isEmpty, isEqual, isNil, max, maxBy, merge} from 'lodash';
48
50
  import './Grid.scss';
49
51
  import {GridModel} from './GridModel';
50
52
  import {columnGroupHeader} from './impl/ColumnGroupHeader';
@@ -463,7 +465,7 @@ export class GridLocalModel extends HoistModel {
463
465
  };
464
466
  }
465
467
 
466
- columnStateReaction() {
468
+ columnStateReaction(): ReactionSpec<[GridApi, ColumnState[]]> {
467
469
  const {model} = this;
468
470
  return {
469
471
  track: () => [model.agApi, model.columnState],
@@ -472,65 +474,57 @@ export class GridLocalModel extends HoistModel {
472
474
 
473
475
  const agColState = api.getColumnState();
474
476
 
475
- // 0) Insert the auto group col state if it exists, since we won't have it in our column state list
477
+ // Insert the auto group col state if it exists, since we won't have it in our column state list
476
478
  const autoColState = agColState.find(c => c.colId === 'ag-Grid-AutoColumn');
477
479
  if (autoColState) {
478
- colState.splice(agColState.indexOf(autoColState), 0, autoColState);
480
+ const {colId, width, hide, pinned} = autoColState;
481
+ colState.splice(agColState.indexOf(autoColState), 0, {
482
+ colId,
483
+ width,
484
+ hidden: hide,
485
+ pinned: isBoolean(pinned) ? (pinned ? 'left' : null) : pinned
486
+ });
479
487
  }
480
488
 
481
- // 1) Columns all in right place -- simply update incorrect props we maintain
482
- if (
483
- isEqual(
484
- colState.map(c => c.colId),
485
- agColState.map(c => c.colId)
486
- )
487
- ) {
488
- let hasChanges = false;
489
- colState.forEach((col, index) => {
490
- const agCol = agColState[index],
491
- id = col.colId;
492
-
493
- if (agCol.width !== col.width) {
494
- api.setColumnWidths([{key: id, newWidth: col.width}]);
489
+ // Determine if column order has changed
490
+ const applyOrder = !isEqual(
491
+ colState.map(c => c.colId),
492
+ agColState.map(c => c.colId)
493
+ );
494
+
495
+ // Build a list of column state changes
496
+ colState = compact(
497
+ colState.map(({colId, width, hidden, pinned}) => {
498
+ const agCol: AgColumnState = agColState.find(c => c.colId === colId) || {
499
+ colId
500
+ },
501
+ ret: any = {colId};
502
+
503
+ let hasChanges = applyOrder;
504
+
505
+ if (agCol.width !== width) {
506
+ ret.width = width;
495
507
  hasChanges = true;
496
508
  }
497
- if (agCol.hide !== col.hidden) {
498
- api.setColumnsVisible([id], !col.hidden);
509
+
510
+ if (agCol.hide !== hidden) {
511
+ ret.hide = hidden;
499
512
  hasChanges = true;
500
513
  }
501
- if (agCol.pinned !== col.pinned) {
502
- api.setColumnsPinned([id], col.pinned);
514
+
515
+ if (agCol.pinned !== pinned) {
516
+ ret.pinned = pinned;
503
517
  hasChanges = true;
504
518
  }
505
- });
506
-
507
- // We need to tell agGrid to refresh its flexed column sizes due to
508
- // a regression introduced in 25.1.0. See #2341
509
- if (hasChanges) {
510
- api.columnModel.refreshFlexedColumns({
511
- updateBodyWidths: true,
512
- fireResizedEvent: true
513
- });
514
- }
515
519
 
516
- return;
517
- }
520
+ return hasChanges ? ret : null;
521
+ })
522
+ );
518
523
 
519
- // 2) Otherwise do an (expensive) full refresh of column state
520
- // Merge our state onto the ag column state to get any state which we do not yet support
521
- colState = colState.map(({colId, width, hidden, pinned}) => {
522
- const agCol = agColState.find(c => c.colId === colId) || {};
523
- return {
524
- colId,
525
- ...agCol,
526
- width,
527
- pinned,
528
- hide: hidden
529
- };
530
- });
524
+ if (isEmpty(colState)) return;
531
525
 
532
526
  this.doWithPreservedState({expansion: false}, () => {
533
- api.applyColumnState({state: colState, applyOrder: true});
527
+ api.applyColumnState({state: colState, applyOrder});
534
528
  });
535
529
  }
536
530
  };
@@ -870,6 +864,7 @@ export class GridLocalModel extends HoistModel {
870
864
  * by conditionally stopping the focus event from propagating.
871
865
  */
872
866
  private static didAddFocusFixListener = false;
867
+
873
868
  static addFocusFixListener() {
874
869
  if (this.didAddFocusFixListener) return;
875
870
  document.addEventListener(
@@ -9,6 +9,7 @@ import {
9
9
  CellContextMenuEvent,
10
10
  CellDoubleClickedEvent,
11
11
  ColumnEvent,
12
+ ColumnState as AgColumnState,
12
13
  RowClickedEvent,
13
14
  RowDoubleClickedEvent
14
15
  } from '@ag-grid-community/core';
@@ -77,6 +78,7 @@ import {
77
78
  first,
78
79
  forEach,
79
80
  isArray,
81
+ isBoolean,
80
82
  isEmpty,
81
83
  isFunction,
82
84
  isNil,
@@ -1073,17 +1075,19 @@ export class GridModel extends HoistModel {
1073
1075
  (this.colChooserModel as any)?.open();
1074
1076
  }
1075
1077
 
1076
- noteAgColumnStateChanged(agColState) {
1077
- const colStateChanges = agColState.map(({colId, width, hide, pinned}) => {
1078
- const col = this.findColumn(this.columns, colId);
1079
- if (!col) return null;
1080
- return {
1081
- colId,
1082
- pinned: pinned ?? null,
1083
- hidden: !!hide,
1084
- width: col.flex ? undefined : width
1085
- };
1086
- });
1078
+ noteAgColumnStateChanged(agColState: AgColumnState[]) {
1079
+ const colStateChanges: Partial<ColumnState>[] = agColState.map(
1080
+ ({colId, width, hide, pinned}) => {
1081
+ const col = this.findColumn(this.columns, colId);
1082
+ if (!col) return null;
1083
+ return {
1084
+ colId,
1085
+ pinned: isBoolean(pinned) ? (pinned ? 'left' : null) : pinned,
1086
+ hidden: !!hide,
1087
+ width: col.flex ? undefined : width
1088
+ };
1089
+ }
1090
+ );
1087
1091
 
1088
1092
  pull(colStateChanges, null);
1089
1093
  this.applyColumnStateChanges(colStateChanges);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "72.0.0-SNAPSHOT.1737725354262",
3
+ "version": "72.0.0-SNAPSHOT.1737748132453",
4
4
  "description": "Hoist add-on for building and deploying React Applications.",
5
5
  "repository": "github:xh/hoist-react",
6
6
  "homepage": "https://xh.io",