@ni/nimble-components 21.2.1 → 21.3.1

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.
@@ -16301,7 +16301,7 @@
16301
16301
 
16302
16302
  /**
16303
16303
  * Do not edit directly
16304
- * Generated on Wed, 07 Feb 2024 18:51:04 GMT
16304
+ * Generated on Fri, 09 Feb 2024 01:47:11 GMT
16305
16305
  */
16306
16306
 
16307
16307
  const Information100DarkUi = "#a46eff";
@@ -61322,6 +61322,10 @@ img.ProseMirror-separator {
61322
61322
  };
61323
61323
  }
61324
61324
 
61325
+ const TableRecordDelayedHierarchyState = {
61326
+ none: undefined,
61327
+ canLoadChildren: 'canLoadChildren'
61328
+ };
61325
61329
  /**
61326
61330
  * The possible directions a table column can be sorted in.
61327
61331
  */
@@ -61804,6 +61808,9 @@ img.ProseMirror-separator {
61804
61808
  getPresentRecordIds(requestedRecordIds) {
61805
61809
  return requestedRecordIds.filter(id => this.recordIds.has(id));
61806
61810
  }
61811
+ getOptionsWithPresentIds(requestedOptions) {
61812
+ return requestedOptions.filter(item => this.recordIds.has(item.recordId));
61813
+ }
61807
61814
  setParentIdConfigurationValidity(valid) {
61808
61815
  this.invalidParentIdConfiguration = !valid;
61809
61816
  }
@@ -64629,8 +64636,8 @@ img.ProseMirror-separator {
64629
64636
  * We must track the expansion state separately from TanStack because:
64630
64637
  * 1. TanStack does not support having a different initial expansion state per row unless explicitly
64631
64638
  * specified for each row by ID. This causes problems in the nimble-table because we could have
64632
- * a different initial expansion state for group rows, parent rows, and parent rows with lazy
64633
- * loaded children.
64639
+ * a different initial expansion state for group rows, parent rows, and parent rows with delay-loaded
64640
+ * children.
64634
64641
  * 2. TanStack does not remove entries from its expanded state when those rows are no longer present
64635
64642
  * in the data. This is not ideal because the object maintaining the expansion state can grow unbounded.
64636
64643
  */
@@ -64642,11 +64649,16 @@ img.ProseMirror-separator {
64642
64649
  // potentially be different (e.g. expanded for groups and collapsed for parent rows).
64643
64650
  this.isInDefaultState = true;
64644
64651
  this.collapsedRows = new Set();
64652
+ this.hierarchyOptions = new Map();
64653
+ this.isHierarchyEnabled = false;
64645
64654
  }
64646
64655
  isRowExpanded(row) {
64647
64656
  if (!this.isRowExpandable(row)) {
64648
64657
  return false;
64649
64658
  }
64659
+ if (row.subRows.length === 0) {
64660
+ return false;
64661
+ }
64650
64662
  return this.isInDefaultState || !this.collapsedRows.has(row.id);
64651
64663
  }
64652
64664
  toggleRowExpansion(row) {
@@ -64664,7 +64676,7 @@ img.ProseMirror-separator {
64664
64676
  row.toggleExpanded();
64665
64677
  }
64666
64678
  collapseAll() {
64667
- this.reset();
64679
+ this.resetExpansionState();
64668
64680
  this.isInDefaultState = false;
64669
64681
  const rows = this.tanStackTable.getRowModel().flatRows;
64670
64682
  for (const row of rows) {
@@ -64674,25 +64686,50 @@ img.ProseMirror-separator {
64674
64686
  }
64675
64687
  this.tanStackTable.toggleAllRowsExpanded(false);
64676
64688
  }
64677
- reset() {
64689
+ resetExpansionState() {
64678
64690
  this.collapsedRows.clear();
64679
64691
  this.isInDefaultState = true;
64680
64692
  }
64693
+ resetHierarchyOptions() {
64694
+ this.hierarchyOptions.clear();
64695
+ }
64681
64696
  processDataUpdate(rows) {
64682
- if (this.isInDefaultState) {
64697
+ if (this.collapsedRows.size === 0 && this.hierarchyOptions.size === 0) {
64683
64698
  return;
64684
64699
  }
64685
64700
  const updatedCollapsedRows = new Set();
64701
+ const updatedHierarchyOptions = new Map();
64686
64702
  for (const row of rows) {
64687
64703
  const rowId = row.id;
64688
64704
  if (this.collapsedRows.has(rowId)) {
64689
64705
  updatedCollapsedRows.add(rowId);
64690
64706
  }
64707
+ const rowHierarchyOptions = this.hierarchyOptions.get(rowId);
64708
+ if (!row.getIsGrouped() && rowHierarchyOptions) {
64709
+ updatedHierarchyOptions.set(rowId, rowHierarchyOptions);
64710
+ }
64691
64711
  }
64692
64712
  this.collapsedRows = updatedCollapsedRows;
64713
+ this.hierarchyOptions = updatedHierarchyOptions;
64714
+ }
64715
+ setHierarchyOptions(hierarchyOptions) {
64716
+ this.hierarchyOptions.clear();
64717
+ for (const { recordId, options } of hierarchyOptions) {
64718
+ this.hierarchyOptions.set(recordId, options);
64719
+ }
64693
64720
  }
64694
64721
  isRowExpandable(row) {
64695
- return row.getIsGrouped() || row.subRows.length > 0;
64722
+ return row.subRows.length > 0 || this.canLoadDelayedChildren(row.id);
64723
+ }
64724
+ setHierarchyEnabled(isHierarchyEnabled) {
64725
+ this.isHierarchyEnabled = isHierarchyEnabled;
64726
+ }
64727
+ canLoadDelayedChildren(id) {
64728
+ if (!this.isHierarchyEnabled) {
64729
+ return false;
64730
+ }
64731
+ return (this.hierarchyOptions.get(id)?.delayedHierarchyState
64732
+ === TableRecordDelayedHierarchyState.canLoadChildren ?? false);
64696
64733
  }
64697
64734
  }
64698
64735
 
@@ -64772,6 +64809,9 @@ img.ProseMirror-separator {
64772
64809
  this.documentShiftKeyDown = false;
64773
64810
  }
64774
64811
  };
64812
+ this.getRowCanExpand = (row) => {
64813
+ return this.expansionManager.isRowExpandable(row);
64814
+ };
64775
64815
  this.getIsRowExpanded = (row) => {
64776
64816
  return this.expansionManager.isRowExpanded(row);
64777
64817
  };
@@ -64804,6 +64844,7 @@ img.ProseMirror-separator {
64804
64844
  getSortedRowModel: getSortedRowModel(),
64805
64845
  getGroupedRowModel: getGroupedRowModel(),
64806
64846
  getExpandedRowModel: getExpandedRowModel(),
64847
+ getRowCanExpand: this.getRowCanExpand,
64807
64848
  getIsRowExpanded: this.getIsRowExpanded,
64808
64849
  getSubRows: r => r.subRows,
64809
64850
  columns: [],
@@ -64858,6 +64899,13 @@ img.ProseMirror-separator {
64858
64899
  }
64859
64900
  });
64860
64901
  }
64902
+ async setRecordHierarchyOptions(hierarchyOptions) {
64903
+ await this.processPendingUpdates();
64904
+ const clonedOptions = structuredClone(hierarchyOptions);
64905
+ const presentOptions = this.tableValidator.getOptionsWithPresentIds(clonedOptions);
64906
+ this.expansionManager.setHierarchyOptions(presentOptions);
64907
+ this.refreshRows();
64908
+ }
64861
64909
  connectedCallback() {
64862
64910
  super.connectedCallback();
64863
64911
  this.initialize();
@@ -65178,6 +65226,10 @@ img.ProseMirror-separator {
65178
65226
  updatedOptions.getRowId = this.calculateTanStackRowIdFunction();
65179
65227
  updatedOptions.state.rowSelection = {};
65180
65228
  this.selectionManager.handleSelectionReset();
65229
+ this.expansionManager.resetHierarchyOptions();
65230
+ }
65231
+ if (this.tableUpdateTracker.updateRowParentIds) {
65232
+ this.expansionManager.setHierarchyEnabled(this.isHierarchyEnabled());
65181
65233
  }
65182
65234
  if (this.tableUpdateTracker.updateSelectionMode) {
65183
65235
  updatedOptions.enableMultiRowSelection = this.selectionMode === TableRowSelectionMode.multiple;
@@ -65208,7 +65260,7 @@ img.ProseMirror-separator {
65208
65260
  || this.tableUpdateTracker.updateRowParentIds
65209
65261
  || this.tableUpdateTracker.updateGroupRows) {
65210
65262
  updatedOptions.state.expanded = true;
65211
- this.expansionManager.reset();
65263
+ this.expansionManager.resetExpansionState();
65212
65264
  }
65213
65265
  this.updateTableOptions(updatedOptions);
65214
65266
  }
@@ -65270,6 +65322,9 @@ img.ProseMirror-separator {
65270
65322
  this.ignoreSelectionChangeEvents = false;
65271
65323
  }
65272
65324
  }
65325
+ isHierarchyEnabled() {
65326
+ return typeof this.parentIdFieldName === 'string';
65327
+ }
65273
65328
  refreshRows() {
65274
65329
  this.selectionState = this.getTableSelectionState();
65275
65330
  let hasDataHierarchy = false;
@@ -65277,10 +65332,7 @@ img.ProseMirror-separator {
65277
65332
  this.tableData = rows.map(row => {
65278
65333
  const isGroupRow = row.getIsGrouped();
65279
65334
  const hasParentRow = isGroupRow ? false : row.getParentRow();
65280
- // we check row.original.subRows below because row.subRows is populated for group rows
65281
- // which we don't want to include
65282
- const isParent = row.original.subRows !== undefined
65283
- && row.original.subRows.length > 0;
65335
+ const isParent = !isGroupRow && this.getRowCanExpand(row);
65284
65336
  const isChildOfGroupRowWithNoHierarchy = !isGroupRow
65285
65337
  && !isParent
65286
65338
  && !hasParentRow
@@ -65372,7 +65424,7 @@ img.ProseMirror-separator {
65372
65424
  state: { ...this.options.state, ...updatedOptions.state }
65373
65425
  };
65374
65426
  this.table.setOptions(this.options);
65375
- if (updatedOptions.data) {
65427
+ if (updatedOptions.data && this.tableValidator.areRecordIdsValid()) {
65376
65428
  const rows = this.table.getRowModel().flatRows;
65377
65429
  this.expansionManager.processDataUpdate(rows);
65378
65430
  }