@ni/nimble-components 18.0.0 → 18.0.2

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.
@@ -25627,7 +25627,7 @@
25627
25627
  this.customCellView?.bind(this.cellState, defaultExecutionContext);
25628
25628
  }
25629
25629
  cellTemplateChanged() {
25630
- if (this.isConnected) {
25630
+ if (this.$fastController.isConnected) {
25631
25631
  this.customCellView = this.cellTemplate?.render(this.cellState, this.cellContentContainer);
25632
25632
  }
25633
25633
  }
@@ -25659,12 +25659,12 @@
25659
25659
  // prettier-ignore
25660
25660
  const template$5 = html `
25661
25661
  <template role="row">
25662
- ${repeat(x => x.columns, html `
25662
+ ${repeat(x => x.columnStates, html `
25663
25663
  <${DesignSystem.tagFor(TableCell)}
25664
25664
  class="cell"
25665
- :cellTemplate="${x => x.cellTemplate}"
25666
- :cellStyles="${x => x.cellStyles}"
25667
- :cellState="${(x, c) => c.parent.getCellState(x)}"
25665
+ :cellTemplate="${x => x.column.cellTemplate}"
25666
+ :cellStyles="${x => x.column.cellStyles}"
25667
+ :cellState="${x => x.cellState}"
25668
25668
  >
25669
25669
  </${DesignSystem.tagFor(TableCell)}>
25670
25670
  `)}
@@ -25680,22 +25680,27 @@
25680
25680
  super(...arguments);
25681
25681
  this.columns = [];
25682
25682
  }
25683
- getCellState(column) {
25684
- const fieldNames = column.getDataRecordFieldNames();
25685
- if (this.hasValidFieldNames(fieldNames) && this.dataRecord) {
25686
- const cellDataValues = fieldNames.map(field => this.dataRecord[field]);
25687
- const cellRecord = Object.fromEntries(column.cellRecordFieldNames.map((k, i) => [
25688
- k,
25689
- cellDataValues[i]
25690
- ]));
25691
- const columnConfig = column.getColumnConfig?.() ?? {};
25692
- const cellState = {
25693
- cellRecord,
25694
- columnConfig
25695
- };
25696
- return cellState;
25697
- }
25698
- return { cellRecord: {}, columnConfig: {} };
25683
+ get columnStates() {
25684
+ return this.columns.map(column => {
25685
+ const fieldNames = column.getDataRecordFieldNames();
25686
+ let cellState;
25687
+ if (this.hasValidFieldNames(fieldNames) && this.dataRecord) {
25688
+ const cellDataValues = fieldNames.map(field => this.dataRecord[field]);
25689
+ const cellRecord = Object.fromEntries(column.cellRecordFieldNames.map((k, i) => [
25690
+ k,
25691
+ cellDataValues[i]
25692
+ ]));
25693
+ const columnConfig = column.getColumnConfig?.() ?? {};
25694
+ cellState = {
25695
+ cellRecord,
25696
+ columnConfig
25697
+ };
25698
+ }
25699
+ else {
25700
+ cellState = { cellRecord: {}, columnConfig: {} };
25701
+ }
25702
+ return { column, cellState };
25703
+ });
25699
25704
  }
25700
25705
  hasValidFieldNames(keys) {
25701
25706
  return keys.every(key => key !== undefined);
@@ -25710,6 +25715,9 @@
25710
25715
  __decorate$1([
25711
25716
  observable
25712
25717
  ], TableRow.prototype, "columns", void 0);
25718
+ __decorate$1([
25719
+ volatile
25720
+ ], TableRow.prototype, "columnStates", null);
25713
25721
  const nimbleTableRow = TableRow.compose({
25714
25722
  baseName: 'table-row',
25715
25723
  template: template$5,
@@ -25743,7 +25751,7 @@
25743
25751
  </div>
25744
25752
  </div>
25745
25753
  <div class="table-viewport" role="rowgroup">
25746
- ${when(x => x.columns.length > 0, html `
25754
+ ${when(x => x.columns.length > 0 && x.canRenderRows, html `
25747
25755
  ${repeat(x => x.tableData, html `
25748
25756
  <${DesignSystem.tagFor(TableRow)}
25749
25757
  class="row"
@@ -25766,13 +25774,15 @@
25766
25774
  class Table extends FoundationElement {
25767
25775
  constructor() {
25768
25776
  super();
25769
- this.data = [];
25770
25777
  /**
25771
25778
  * @internal
25772
25779
  */
25773
25780
  this.tableData = [];
25774
25781
  this.columns = [];
25775
- this.tableInitialized = false;
25782
+ /**
25783
+ * @internal
25784
+ */
25785
+ this.canRenderRows = true;
25776
25786
  this.tableValidator = new TableValidator();
25777
25787
  this.update = (state) => {
25778
25788
  this.table.setOptions(prev => ({
@@ -25797,35 +25807,33 @@
25797
25807
  autoResetAll: false
25798
25808
  };
25799
25809
  this.table = createTable(this.options);
25800
- this.tableInitialized = true;
25801
25810
  }
25802
25811
  get validity() {
25803
25812
  return this.tableValidator.getValidity();
25804
25813
  }
25814
+ setData(newData) {
25815
+ this.generateTanStackColumns(newData);
25816
+ this.setTableData(newData);
25817
+ }
25805
25818
  idFieldNameChanged(_prev, _next) {
25806
25819
  // Force TanStack to detect a data update because a row's ID is only
25807
25820
  // generated when creating a new row model.
25808
- this.trySetData([...this.data]);
25809
- }
25810
- dataChanged(prev, next) {
25811
- if ((!prev || prev.length === 0) && next && next.length > 0) {
25812
- this.generateColumns();
25813
- }
25814
- // Ignore any updates that occur prior to the TanStack table being initialized.
25815
- if (this.tableInitialized) {
25816
- this.trySetData(this.data);
25817
- }
25821
+ this.setTableData(this.table.options.data);
25818
25822
  }
25819
25823
  checkValidity() {
25820
25824
  return this.tableValidator.isValid();
25821
25825
  }
25822
- trySetData(newData) {
25823
- const areIdsValid = this.tableValidator.validateRecordIds(newData, this.idFieldName);
25826
+ setTableData(newData) {
25827
+ const data = newData.map(record => {
25828
+ return { ...record };
25829
+ });
25830
+ this.tableValidator.validateRecordIds(data, this.idFieldName);
25831
+ this.canRenderRows = this.checkValidity();
25824
25832
  const getRowIdFunction = this.idFieldName === null || this.idFieldName === undefined
25825
25833
  ? undefined
25826
25834
  : (record) => record[this.idFieldName];
25827
25835
  this.updateTableOptions({
25828
- data: areIdsValid ? newData : [],
25836
+ data,
25829
25837
  getRowId: getRowIdFunction
25830
25838
  });
25831
25839
  }
@@ -25846,11 +25854,11 @@
25846
25854
  }
25847
25855
  // Generate columns for TanStack that correspond to all the keys in TData because all operations,
25848
25856
  // such as grouping and sorting, will be performed on the data's records, not the values rendered within a cell.
25849
- generateColumns() {
25850
- if (this.data.length === 0) {
25857
+ generateTanStackColumns(data) {
25858
+ if (data.length === 0) {
25851
25859
  return;
25852
25860
  }
25853
- const firstItem = this.data[0];
25861
+ const firstItem = data[0];
25854
25862
  const keys = Object.keys(firstItem);
25855
25863
  const generatedColumns = keys.map(key => {
25856
25864
  const columnDef = {
@@ -25866,15 +25874,15 @@
25866
25874
  __decorate$1([
25867
25875
  attr({ attribute: 'id-field-name' })
25868
25876
  ], Table.prototype, "idFieldName", void 0);
25869
- __decorate$1([
25870
- observable
25871
- ], Table.prototype, "data", void 0);
25872
25877
  __decorate$1([
25873
25878
  observable
25874
25879
  ], Table.prototype, "tableData", void 0);
25875
25880
  __decorate$1([
25876
25881
  observable
25877
25882
  ], Table.prototype, "columns", void 0);
25883
+ __decorate$1([
25884
+ observable
25885
+ ], Table.prototype, "canRenderRows", void 0);
25878
25886
  const nimbleTable = Table.compose({
25879
25887
  baseName: 'table',
25880
25888
  template: template$4,