@ni/nimble-components 18.3.3 → 18.3.5

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.
@@ -26577,6 +26577,9 @@
26577
26577
  this.setAttribute('slot', uniqueId('table-column-slot'));
26578
26578
  }
26579
26579
  }
26580
+ __decorate$1([
26581
+ attr({ attribute: 'column-id' })
26582
+ ], TableColumn.prototype, "columnId", void 0);
26580
26583
 
26581
26584
  /**
26582
26585
  * Helper class for the nimble-table to validate that the table's configuration
@@ -26587,12 +26590,16 @@
26587
26590
  this.duplicateRecordId = false;
26588
26591
  this.missingRecordId = false;
26589
26592
  this.invalidRecordId = false;
26593
+ this.duplicateColumnId = false;
26594
+ this.missingColumnId = false;
26590
26595
  }
26591
26596
  getValidity() {
26592
26597
  return {
26593
26598
  duplicateRecordId: this.duplicateRecordId,
26594
26599
  missingRecordId: this.missingRecordId,
26595
- invalidRecordId: this.invalidRecordId
26600
+ invalidRecordId: this.invalidRecordId,
26601
+ duplicateColumnId: this.duplicateColumnId,
26602
+ missingColumnId: this.missingColumnId
26596
26603
  };
26597
26604
  }
26598
26605
  isValid() {
@@ -26626,6 +26633,26 @@
26626
26633
  && !this.invalidRecordId
26627
26634
  && !this.duplicateRecordId);
26628
26635
  }
26636
+ validateColumnIds(columnIds) {
26637
+ this.missingColumnId = false;
26638
+ this.duplicateColumnId = false;
26639
+ const anyColumnsHaveIds = columnIds.some(id => id);
26640
+ if (!anyColumnsHaveIds) {
26641
+ return true;
26642
+ }
26643
+ const idSet = new Set();
26644
+ for (const columnId of columnIds) {
26645
+ if (!columnId) {
26646
+ this.missingColumnId = true;
26647
+ continue;
26648
+ }
26649
+ if (idSet.has(columnId)) {
26650
+ this.duplicateColumnId = true;
26651
+ }
26652
+ idSet.add(columnId);
26653
+ }
26654
+ return !this.missingColumnId && !this.duplicateColumnId;
26655
+ }
26629
26656
  }
26630
26657
 
26631
26658
  const styles$d = css `
@@ -27680,6 +27707,7 @@
27680
27707
  */
27681
27708
  this.canRenderRows = true;
27682
27709
  this.tableValidator = new TableValidator();
27710
+ this.columnNotifiers = [];
27683
27711
  this.update = (state) => {
27684
27712
  this.table.setOptions(prev => ({
27685
27713
  ...prev,
@@ -27712,24 +27740,66 @@
27712
27740
  this.generateTanStackColumns(newData);
27713
27741
  this.setTableData(newData);
27714
27742
  }
27715
- idFieldNameChanged(_prev, _next) {
27716
- // Force TanStack to detect a data update because a row's ID is only
27717
- // generated when creating a new row model.
27718
- this.setTableData(this.table.options.data);
27719
- }
27720
27743
  connectedCallback() {
27721
27744
  super.connectedCallback();
27722
27745
  this.virtualizer.connectedCallback();
27746
+ this.validateAndObserveColumns();
27723
27747
  }
27724
27748
  disconnectedCallback() {
27749
+ super.disconnectedCallback();
27725
27750
  this.virtualizer.disconnectedCallback();
27751
+ this.removeColumnObservers();
27726
27752
  }
27727
27753
  checkValidity() {
27728
27754
  return this.tableValidator.isValid();
27729
27755
  }
27756
+ /**
27757
+ * @internal
27758
+ *
27759
+ * The event handler that is called when a notifier detects a change. Notifiers are added
27760
+ * to each column, so `source` is expected to be an instance of `TableColumn`, and `args`
27761
+ * is the string name of the property that changed on that column.
27762
+ */
27763
+ handleChange(source, args) {
27764
+ if (source instanceof TableColumn) {
27765
+ if (args === 'columnId') {
27766
+ this.validateColumnIds();
27767
+ }
27768
+ }
27769
+ }
27730
27770
  childItemsChanged() {
27731
27771
  void this.updateColumnsFromChildItems();
27732
27772
  }
27773
+ idFieldNameChanged(_prev, _next) {
27774
+ // Force TanStack to detect a data update because a row's ID is only
27775
+ // generated when creating a new row model.
27776
+ this.setTableData(this.table.options.data);
27777
+ }
27778
+ columnsChanged(_prev, _next) {
27779
+ if (!this.$fastController.isConnected) {
27780
+ return;
27781
+ }
27782
+ this.validateAndObserveColumns();
27783
+ }
27784
+ removeColumnObservers() {
27785
+ this.columnNotifiers.forEach(notifier => {
27786
+ notifier.unsubscribe(this);
27787
+ });
27788
+ this.columnNotifiers = [];
27789
+ }
27790
+ validateAndObserveColumns() {
27791
+ this.removeColumnObservers();
27792
+ for (const column of this.columns) {
27793
+ const notifier = Observable.getNotifier(column);
27794
+ notifier.subscribe(this);
27795
+ this.columnNotifiers.push(notifier);
27796
+ }
27797
+ this.validateColumnIds();
27798
+ }
27799
+ validateColumnIds() {
27800
+ this.tableValidator.validateColumnIds(this.columns.map(x => x.columnId));
27801
+ this.canRenderRows = this.checkValidity();
27802
+ }
27733
27803
  async updateColumnsFromChildItems() {
27734
27804
  const definedElements = this.childItems.map(async (item) => (item.matches(':not(:defined)')
27735
27805
  ? customElements.whenDefined(item.localName)