@brightspace-ui/core 3.37.0 → 3.38.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -259,6 +259,11 @@ export const tableStyles = css`
259
259
  }
260
260
  `;
261
261
 
262
+ const SELECTORS = {
263
+ headers: 'tr.d2l-table-header, tr[header], thead tr',
264
+ items: ':not(thead) > tr:not(.d2l-table-header):not([header])',
265
+ };
266
+
262
267
  /**
263
268
  * Wraps a native <table> element, providing styling and scroll buttons for overflow.
264
269
  * @slot - Content to wrap
@@ -486,7 +491,7 @@ export class TableWrapper extends RtlMixin(PageableMixin(SelectionMixin(LitEleme
486
491
  }
487
492
 
488
493
  _getItems() {
489
- return this._table?.querySelectorAll(':not(thead) > tr:not(.d2l-table-header):not([header])') || [];
494
+ return this._table?.querySelectorAll(SELECTORS.items) || [];
490
495
  }
491
496
 
492
497
  _getItemShowingCount() {
@@ -574,13 +579,37 @@ export class TableWrapper extends RtlMixin(PageableMixin(SelectionMixin(LitEleme
574
579
  this._handleTableChange();
575
580
  }
576
581
 
577
- async _handleTableChange() {
582
+ async _handleTableChange(mutationRecords) {
583
+ const flag = window.D2L?.LP?.Web?.UI?.Flags.Flag('table-update-filter-GAUD-6955', true) ?? true;
584
+ const updates = { count: true, classNames: true, sticky: true, syncWidths: true };
585
+ if (flag) {
586
+ if (mutationRecords) {
587
+ for (const key in updates) updates[key] = false;
588
+ for (const { type, removedNodes, addedNodes, target, attributeName } of mutationRecords) {
589
+ if (type === 'attributes') {
590
+ updates.classNames = attributeName === 'selected';
591
+ continue;
592
+ }
593
+
594
+ updates.sticky ||= target.matches(SELECTORS.headers);
595
+ const affectedNodes = [...removedNodes, ...addedNodes];
596
+ for (const node of affectedNodes) {
597
+ if (!(node instanceof Element)) continue;
598
+ updates.classNames ||= node.matches('tr');
599
+ updates.syncWidths ||= node.matches('tr');
600
+ updates.sticky ||= node.matches(SELECTORS.headers);
601
+ updates.count ||= node.matches(SELECTORS.items);
602
+ }
603
+ }
604
+ }
605
+ }
606
+
578
607
  await new Promise(resolve => requestAnimationFrame(resolve));
579
608
 
580
- this._updateItemShowingCount();
581
- this._applyClassNames();
582
- this._syncColumnWidths();
583
- this._updateStickyTops();
609
+ if (updates.count) this._updateItemShowingCount();
610
+ if (updates.classNames) this._applyClassNames();
611
+ if (updates.syncWidths) this._syncColumnWidths();
612
+ if (updates.sticky) this._updateStickyTops();
584
613
  }
585
614
 
586
615
  _registerMutationObserver(observerName, callback, target, options) {
@@ -721,7 +750,7 @@ export class TableWrapper extends RtlMixin(PageableMixin(SelectionMixin(LitEleme
721
750
 
722
751
  if (!this._table || !this.stickyHeaders || this.stickyHeadersScrollWrapper) return;
723
752
 
724
- const stickyRows = Array.from(this._table.querySelectorAll('tr.d2l-table-header, tr[header], thead tr'));
753
+ const stickyRows = Array.from(this._table.querySelectorAll(SELECTORS.headers));
725
754
  stickyRows.forEach(r => {
726
755
  const thTop = hasStickyControls ? `${rowTop}px` : `calc(${rowTop}px + var(--d2l-table-border-radius-sticky-offset, 0px))`;
727
756
  const ths = Array.from(r.querySelectorAll('th'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.37.0",
3
+ "version": "3.38.0",
4
4
  "description": "A collection of accessible, free, open-source web components for building Brightspace applications",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/BrightspaceUI/core.git",