@getflip/swirl-components 0.533.0 → 0.534.0

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.
Files changed (156) hide show
  1. package/components.json +158 -1
  2. package/dist/cjs/index-D-n4TKMG.js +4 -4
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/{media-query.service-B8u-DqoO.js → media-query.service-C1jMjjiy.js} +1 -1
  5. package/dist/cjs/swirl-action-list_2.cjs.entry.js +2 -2
  6. package/dist/cjs/swirl-app-layout.cjs.entry.js +2 -2
  7. package/dist/cjs/swirl-autocomplete.cjs.entry.js +1 -1
  8. package/dist/cjs/swirl-banner.cjs.entry.js +2 -2
  9. package/dist/cjs/swirl-button.cjs.entry.js +2 -2
  10. package/dist/cjs/swirl-carousel.cjs.entry.js +1 -1
  11. package/dist/cjs/swirl-components.cjs.js +1 -1
  12. package/dist/cjs/swirl-console-layout.cjs.entry.js +1 -1
  13. package/dist/cjs/swirl-date-input.cjs.entry.js +2 -2
  14. package/dist/cjs/swirl-date-picker_2.cjs.entry.js +1 -1
  15. package/dist/cjs/swirl-file-chip.cjs.entry.js +1 -1
  16. package/dist/cjs/swirl-file-viewer-audio_7.cjs.entry.js +1 -1
  17. package/dist/cjs/swirl-file-viewer_7.cjs.entry.js +1 -1
  18. package/dist/cjs/swirl-form-control.cjs.entry.js +1 -1
  19. package/dist/cjs/swirl-icon-check-small_3.cjs.entry.js +2 -2
  20. package/dist/cjs/swirl-icon-error_3.cjs.entry.js +2 -2
  21. package/dist/cjs/swirl-image-grid-item.cjs.entry.js +1 -1
  22. package/dist/cjs/swirl-inline-status.cjs.entry.js +2 -2
  23. package/dist/cjs/swirl-lightbox.cjs.entry.js +1 -1
  24. package/dist/cjs/swirl-menu-item.cjs.entry.js +1 -1
  25. package/dist/cjs/swirl-menu.cjs.entry.js +1 -1
  26. package/dist/cjs/swirl-modal.cjs.entry.js +1 -1
  27. package/dist/cjs/swirl-option-list.cjs.entry.js +1 -1
  28. package/dist/cjs/swirl-pagination.cjs.entry.js +1 -1
  29. package/dist/cjs/swirl-pdf-reader.cjs.entry.js +1 -1
  30. package/dist/cjs/swirl-popover_2.cjs.entry.js +1 -1
  31. package/dist/cjs/swirl-resource-list-file-item.cjs.entry.js +2 -2
  32. package/dist/cjs/swirl-resource-list-item.cjs.entry.js +2 -2
  33. package/dist/cjs/swirl-search.cjs.entry.js +2 -2
  34. package/dist/cjs/swirl-select.cjs.entry.js +1 -1
  35. package/dist/cjs/swirl-shell-layout.cjs.entry.js +1 -1
  36. package/dist/cjs/swirl-tab-bar.cjs.entry.js +1 -1
  37. package/dist/cjs/swirl-table-column.cjs.entry.js +1 -1
  38. package/dist/cjs/swirl-table-row.cjs.entry.js +1 -1
  39. package/dist/cjs/swirl-table.cjs.entry.js +2287 -2
  40. package/dist/cjs/swirl-tabs.cjs.entry.js +1 -1
  41. package/dist/cjs/swirl-text-input.cjs.entry.js +2 -2
  42. package/dist/cjs/swirl-time-input.cjs.entry.js +2 -2
  43. package/dist/cjs/swirl-toast.cjs.entry.js +2 -2
  44. package/dist/cjs/swirl-toolbar.cjs.entry.js +1 -1
  45. package/dist/cjs/swirl-tooltip.cjs.entry.js +1 -1
  46. package/dist/cjs/{utils-UfZG-xPD.js → utils-C4tLdXqU.js} +33 -0
  47. package/dist/collection/components/swirl-table/swirl-table-virtualizer.js +224 -0
  48. package/dist/collection/components/swirl-table/swirl-table.js +253 -2
  49. package/dist/collection/components/swirl-table/swirl-table.stories.js +190 -0
  50. package/dist/collection/utils.js +32 -0
  51. package/dist/components/media-query.service.js +1 -1
  52. package/dist/components/swirl-file-viewer-pdf2.js +1 -1
  53. package/dist/components/swirl-popover2.js +1 -1
  54. package/dist/components/swirl-tab-bar2.js +1 -1
  55. package/dist/components/swirl-table.js +1 -1
  56. package/dist/components/swirl-tabs.js +1 -1
  57. package/dist/components/swirl-tooltip2.js +1 -1
  58. package/dist/components/utils.js +1 -1
  59. package/dist/esm/index-Dz56lJ37.js +4 -4
  60. package/dist/esm/loader.js +1 -1
  61. package/dist/esm/{media-query.service-CCYT6DU8.js → media-query.service-Bbqqduao.js} +1 -1
  62. package/dist/esm/swirl-action-list_2.entry.js +2 -2
  63. package/dist/esm/swirl-app-layout.entry.js +2 -2
  64. package/dist/esm/swirl-autocomplete.entry.js +1 -1
  65. package/dist/esm/swirl-banner.entry.js +2 -2
  66. package/dist/esm/swirl-button.entry.js +2 -2
  67. package/dist/esm/swirl-carousel.entry.js +1 -1
  68. package/dist/esm/swirl-components.js +1 -1
  69. package/dist/esm/swirl-console-layout.entry.js +1 -1
  70. package/dist/esm/swirl-date-input.entry.js +2 -2
  71. package/dist/esm/swirl-date-picker_2.entry.js +1 -1
  72. package/dist/esm/swirl-file-chip.entry.js +1 -1
  73. package/dist/esm/swirl-file-viewer-audio_7.entry.js +1 -1
  74. package/dist/esm/swirl-file-viewer_7.entry.js +1 -1
  75. package/dist/esm/swirl-form-control.entry.js +1 -1
  76. package/dist/esm/swirl-icon-check-small_3.entry.js +2 -2
  77. package/dist/esm/swirl-icon-error_3.entry.js +2 -2
  78. package/dist/esm/swirl-image-grid-item.entry.js +1 -1
  79. package/dist/esm/swirl-inline-status.entry.js +2 -2
  80. package/dist/esm/swirl-lightbox.entry.js +1 -1
  81. package/dist/esm/swirl-menu-item.entry.js +1 -1
  82. package/dist/esm/swirl-menu.entry.js +1 -1
  83. package/dist/esm/swirl-modal.entry.js +1 -1
  84. package/dist/esm/swirl-option-list.entry.js +1 -1
  85. package/dist/esm/swirl-pagination.entry.js +1 -1
  86. package/dist/esm/swirl-pdf-reader.entry.js +1 -1
  87. package/dist/esm/swirl-popover_2.entry.js +1 -1
  88. package/dist/esm/swirl-resource-list-file-item.entry.js +2 -2
  89. package/dist/esm/swirl-resource-list-item.entry.js +2 -2
  90. package/dist/esm/swirl-search.entry.js +2 -2
  91. package/dist/esm/swirl-select.entry.js +1 -1
  92. package/dist/esm/swirl-shell-layout.entry.js +1 -1
  93. package/dist/esm/swirl-tab-bar.entry.js +1 -1
  94. package/dist/esm/swirl-table-column.entry.js +1 -1
  95. package/dist/esm/swirl-table-row.entry.js +1 -1
  96. package/dist/esm/swirl-table.entry.js +2288 -3
  97. package/dist/esm/swirl-tabs.entry.js +1 -1
  98. package/dist/esm/swirl-text-input.entry.js +2 -2
  99. package/dist/esm/swirl-time-input.entry.js +2 -2
  100. package/dist/esm/swirl-toast.entry.js +2 -2
  101. package/dist/esm/swirl-toolbar.entry.js +1 -1
  102. package/dist/esm/swirl-tooltip.entry.js +1 -1
  103. package/dist/esm/{utils-CCck-DTo.js → utils-D23VxAsw.js} +33 -1
  104. package/dist/swirl-components/p-0cb6bbde.entry.js +1 -0
  105. package/dist/swirl-components/{p-ea6bdee5.entry.js → p-20354a36.entry.js} +1 -1
  106. package/dist/swirl-components/{p-8d078f8a.entry.js → p-247ada6e.entry.js} +1 -1
  107. package/dist/swirl-components/{p-270be9f2.entry.js → p-29fed244.entry.js} +1 -1
  108. package/dist/swirl-components/{p-c924fc96.entry.js → p-437ac2fa.entry.js} +1 -1
  109. package/dist/swirl-components/{p-97deaddc.entry.js → p-48c1b8e4.entry.js} +1 -1
  110. package/dist/swirl-components/{p-40be5fde.entry.js → p-48c559a4.entry.js} +1 -1
  111. package/dist/swirl-components/p-4a1d3582.entry.js +1 -0
  112. package/dist/swirl-components/{p-ad4fd14f.entry.js → p-5c6fc0bc.entry.js} +1 -1
  113. package/dist/swirl-components/{p-73a8e8a0.entry.js → p-6242f9bb.entry.js} +1 -1
  114. package/dist/swirl-components/{p-0c0acfd3.entry.js → p-641bb5b1.entry.js} +1 -1
  115. package/dist/swirl-components/{p-993dae75.entry.js → p-6528e39b.entry.js} +1 -1
  116. package/dist/swirl-components/{p-b45902de.entry.js → p-6785b8a5.entry.js} +1 -1
  117. package/dist/swirl-components/{p-dcf08d9a.entry.js → p-692dd291.entry.js} +1 -1
  118. package/dist/swirl-components/{p-418a8b7b.entry.js → p-6e0825ae.entry.js} +1 -1
  119. package/dist/swirl-components/{p-22931b7b.entry.js → p-71e1f20d.entry.js} +1 -1
  120. package/dist/swirl-components/{p-f015fc2d.entry.js → p-78af0765.entry.js} +1 -1
  121. package/dist/swirl-components/{p-2ddf4a93.entry.js → p-7a9bb681.entry.js} +1 -1
  122. package/dist/swirl-components/{p-b36ee49f.entry.js → p-84cfb27a.entry.js} +1 -1
  123. package/dist/swirl-components/{p-c6bceca5.entry.js → p-91b316f9.entry.js} +1 -1
  124. package/dist/swirl-components/{p-da6fa0fa.entry.js → p-958aa736.entry.js} +1 -1
  125. package/dist/swirl-components/{p-fbdb4aff.entry.js → p-95d6d7ad.entry.js} +1 -1
  126. package/dist/swirl-components/{p-577174d9.entry.js → p-984c4d86.entry.js} +1 -1
  127. package/dist/swirl-components/{p-CCck-DTo.js → p-D23VxAsw.js} +1 -1
  128. package/dist/swirl-components/{p-Bfn7CHM9.js → p-_iAIu_AF.js} +1 -1
  129. package/dist/swirl-components/{p-d0275263.entry.js → p-a11ba0b5.entry.js} +1 -1
  130. package/dist/swirl-components/{p-1bf78baf.entry.js → p-ae978c57.entry.js} +1 -1
  131. package/dist/swirl-components/{p-95a403cf.entry.js → p-b08aa57d.entry.js} +1 -1
  132. package/dist/swirl-components/{p-26362ab2.entry.js → p-bb4c80bf.entry.js} +1 -1
  133. package/dist/swirl-components/{p-e63650e3.entry.js → p-c182f4c1.entry.js} +1 -1
  134. package/dist/swirl-components/{p-d763ce05.entry.js → p-c4dad69d.entry.js} +1 -1
  135. package/dist/swirl-components/{p-47b02bc4.entry.js → p-cf855c44.entry.js} +1 -1
  136. package/dist/swirl-components/{p-fbcc5141.entry.js → p-d26aa1e7.entry.js} +1 -1
  137. package/dist/swirl-components/{p-3340670b.entry.js → p-d298c94c.entry.js} +1 -1
  138. package/dist/swirl-components/{p-9ad61433.entry.js → p-d8924470.entry.js} +1 -1
  139. package/dist/swirl-components/{p-268ddaee.entry.js → p-dab890a1.entry.js} +2 -2
  140. package/dist/swirl-components/{p-3e6fb027.entry.js → p-de5a7b4a.entry.js} +1 -1
  141. package/dist/swirl-components/p-ea36e3ec.entry.js +1 -0
  142. package/dist/swirl-components/{p-96c9486a.entry.js → p-eb297822.entry.js} +1 -1
  143. package/dist/swirl-components/{p-bee027a0.entry.js → p-ec10ca71.entry.js} +1 -1
  144. package/dist/swirl-components/{p-94e6a907.entry.js → p-f6c37730.entry.js} +1 -1
  145. package/dist/swirl-components/{p-b581b1e6.entry.js → p-fd188df6.entry.js} +1 -1
  146. package/dist/swirl-components/swirl-components.esm.js +1 -1
  147. package/dist/types/components/swirl-table/swirl-table-virtualizer.d.ts +60 -0
  148. package/dist/types/components/swirl-table/swirl-table.d.ts +43 -0
  149. package/dist/types/components/swirl-table/swirl-table.stories.d.ts +2 -0
  150. package/dist/types/components.d.ts +57 -2
  151. package/dist/types/utils.d.ts +12 -0
  152. package/package.json +2 -1
  153. package/vscode-data.json +16 -0
  154. package/dist/swirl-components/p-0c0b46e1.entry.js +0 -1
  155. package/dist/swirl-components/p-2943bc69.entry.js +0 -1
  156. package/dist/swirl-components/p-5fa1c77c.entry.js +0 -1
@@ -2,7 +2,8 @@ import debouncePromise from "debounce-promise";
2
2
  import { h, Host, } from "@stencil/core";
3
3
  import classNames from "classnames";
4
4
  import Sortable from "sortablejs";
5
- import { debounce, isMobileViewport, querySelectorAllDeep } from "../../utils";
5
+ import { debounce, getScrollParent, isMobileViewport, querySelectorAllDeep, } from "../../utils";
6
+ import { SwirlTableVirtualizer, } from "./swirl-table-virtualizer";
6
7
  const defaultDragDropInstructions = {
7
8
  end: "Dropped. Final position in table: {position} of {rowCount}.",
8
9
  initial: "Press space to move the row.",
@@ -18,6 +19,15 @@ export class SwirlTable {
18
19
  constructor() {
19
20
  this.dragDropInstructions = defaultDragDropInstructions;
20
21
  this.emptyStateLabel = "No results found.";
22
+ /** Height in px assumed for rows not drawn yet. */
23
+ this.virtualizationEstimatedRowHeight = 56;
24
+ /** Number of extra rows drawn above and below the visible ones. */
25
+ this.virtualizationOverscan = 10;
26
+ /**
27
+ * Indexes of rows to keep drawn when out of view, e.g. a row with an open
28
+ * menu. The focused row is always kept.
29
+ */
30
+ this.virtualizationKeepRowsRendered = [];
21
31
  this.liveRegionText = "";
22
32
  this.triggerRerender = debounce(async () => {
23
33
  await this.updateLayout();
@@ -37,6 +47,7 @@ export class SwirlTable {
37
47
  this.updateScrolledState();
38
48
  };
39
49
  this.onFocus = (event) => {
50
+ this.trackFocusedRow(event.target);
40
51
  if (this.movingViaKeyboard) {
41
52
  const movingRow = this.el.querySelector(".table-row--moving");
42
53
  if (movingRow) {
@@ -50,6 +61,9 @@ export class SwirlTable {
50
61
  };
51
62
  this.onBlur = (event) => {
52
63
  const newlyFocusedElement = event.relatedTarget;
64
+ if (!this.el.contains(newlyFocusedElement)) {
65
+ this.trackFocusedRow(null);
66
+ }
53
67
  const focusedDragHandle = !!newlyFocusedElement?.closest(this.dragDropHandle);
54
68
  if (this.el.contains(newlyFocusedElement) && focusedDragHandle) {
55
69
  return;
@@ -92,6 +106,7 @@ export class SwirlTable {
92
106
  async componentDidLoad() {
93
107
  this.setupIntersectionObserver();
94
108
  this.setupMutationObservers();
109
+ this.updateVirtualizer();
95
110
  queueMicrotask(() => {
96
111
  this.setupDragDrop();
97
112
  });
@@ -101,6 +116,60 @@ export class SwirlTable {
101
116
  this.columnMutationObserver?.disconnect();
102
117
  this.rowMutationObserver?.disconnect();
103
118
  this.sortable?.destroy();
119
+ this.destroyVirtualizer();
120
+ }
121
+ handleVirtualizationChange() {
122
+ this.updateVirtualizer();
123
+ }
124
+ get virtualizerConfig() {
125
+ if (!this.enableVirtualization || !this.virtualizationRowCount) {
126
+ return undefined;
127
+ }
128
+ return {
129
+ estimatedRowHeight: this.virtualizationEstimatedRowHeight,
130
+ keptIndexes: this.focusedRowIndex === undefined
131
+ ? this.virtualizationKeepRowsRendered ?? []
132
+ : [
133
+ ...(this.virtualizationKeepRowsRendered ?? []),
134
+ this.focusedRowIndex,
135
+ ],
136
+ overscan: this.virtualizationOverscan,
137
+ rowCount: this.virtualizationRowCount,
138
+ };
139
+ }
140
+ updateVirtualizer() {
141
+ if (!this.bodyEl) {
142
+ return;
143
+ }
144
+ const config = this.virtualizerConfig;
145
+ if (!config) {
146
+ const hadVirtualizer = Boolean(this.virtualizer);
147
+ this.destroyVirtualizer();
148
+ // tell the app to clear its rows when they drop to 0. checking for a
149
+ // previous virtualizer emits only once, not on every focus change.
150
+ if (this.enableVirtualization && hadVirtualizer) {
151
+ queueMicrotask(() => this.virtualizationRowsChange.emit({ indexes: [] }));
152
+ }
153
+ return;
154
+ }
155
+ if (this.virtualizer) {
156
+ this.virtualizer.setConfig(config);
157
+ // find the scroll container when more rows make it overflow
158
+ if (this.virtualizer.scrollElement === window) {
159
+ this.updateScrollParent();
160
+ }
161
+ return;
162
+ }
163
+ // reserve the full height first, so the scroll container overflows and
164
+ // can be found.
165
+ this.bodyEl.style.paddingBottom = `${config.rowCount * config.estimatedRowHeight}px`;
166
+ this.virtualizer = new SwirlTableVirtualizer(this.bodyEl, getScrollParent(this.el), config, (indexes) =>
167
+ // emit async, so frameworks don't get it mid-render.
168
+ queueMicrotask(() => this.virtualizationRowsChange.emit({ indexes })));
169
+ }
170
+ destroyVirtualizer() {
171
+ this.virtualizer?.destroy();
172
+ this.virtualizer = undefined;
104
173
  }
105
174
  handleEnableDragDropChange() {
106
175
  queueMicrotask(() => {
@@ -136,15 +205,21 @@ export class SwirlTable {
136
205
  });
137
206
  this.rowMutationObserver = new MutationObserver((mutations) => {
138
207
  const rowWasAddedOrRemoved = mutations.some((mutation) => mutation.addedNodes.length || mutation.removedNodes.length);
208
+ // rows tracked by position are reused: only their data-index changes.
209
+ const rowIndexChanged = mutations.some((mutation) => mutation.type === "attributes");
139
210
  if (rowWasAddedOrRemoved) {
140
211
  this.updateEmptyState();
141
212
  this.setupDragDrop();
142
213
  }
214
+ if (rowWasAddedOrRemoved || rowIndexChanged) {
215
+ this.syncVirtualizedRows();
216
+ }
143
217
  });
144
218
  this.startRowMutationObserver();
145
219
  }
146
220
  startRowMutationObserver() {
147
221
  this.rowMutationObserver?.observe(this.bodyEl, {
222
+ attributeFilter: ["data-index"],
148
223
  childList: true,
149
224
  subtree: true,
150
225
  });
@@ -206,10 +281,23 @@ export class SwirlTable {
206
281
  // Delay layout update to ensure the container is fully visible,
207
282
  // especially if it was initially rendered in a modal.
208
283
  setTimeout(async () => {
284
+ this.updateScrollParent();
209
285
  await this.updateLayout();
210
286
  }, 100);
211
287
  }
212
288
  }
289
+ /**
290
+ * A table hidden on load falls back to the window. Look for the scroll
291
+ * container again once it is visible.
292
+ */
293
+ updateScrollParent() {
294
+ if (!this.virtualizer ||
295
+ getScrollParent(this.el) === this.virtualizer.scrollElement) {
296
+ return;
297
+ }
298
+ this.destroyVirtualizer();
299
+ this.updateVirtualizer();
300
+ }
213
301
  async componentDidRender() {
214
302
  await this.updateLayout();
215
303
  this.updateEmptyState();
@@ -394,6 +482,10 @@ export class SwirlTable {
394
482
  .some((column) => column.sticky);
395
483
  }
396
484
  updateEmptyState() {
485
+ if (this.enableVirtualization && this.virtualizationRowCount) {
486
+ this.empty = false;
487
+ return;
488
+ }
397
489
  const rowsContainer = this.el.querySelector('[slot="rows"]');
398
490
  this.empty = !Boolean(rowsContainer) || rowsContainer.children.length === 0;
399
491
  }
@@ -489,13 +581,40 @@ export class SwirlTable {
489
581
  handle.querySelector("button")?.focus();
490
582
  }
491
583
  }
584
+ /**
585
+ * Measures and positions rows after they were added, removed or re-indexed.
586
+ * The focused row's index is read again first, as it changes when e.g. a row
587
+ * is inserted above it.
588
+ */
589
+ syncVirtualizedRows() {
590
+ if (!this.virtualizer) {
591
+ return;
592
+ }
593
+ this.trackFocusedRow(this.el.querySelector("swirl-table-row[data-index]:focus-within"));
594
+ this.virtualizer.sync();
595
+ }
596
+ /** Keeps the focused row drawn, so it doesn't lose focus. */
597
+ trackFocusedRow(target) {
598
+ if (!this.enableVirtualization) {
599
+ return;
600
+ }
601
+ const index = target?.closest("swirl-table-row[data-index]")
602
+ ?.dataset.index;
603
+ const focusedRowIndex = index === undefined ? undefined : Number(index);
604
+ if (focusedRowIndex !== this.focusedRowIndex) {
605
+ this.focusedRowIndex = focusedRowIndex;
606
+ this.updateVirtualizer();
607
+ }
608
+ }
492
609
  render() {
493
610
  const hasEmptyStateSlotAssignment = Boolean(this.el.querySelector('[slot="empty"]'));
494
611
  const className = classNames("table", {
495
612
  "table--show-empty-state": this.empty && !this.loading,
496
613
  "table--keyboard-move": this.movingViaKeyboard,
497
614
  });
498
- return (h(Host, { key: '16d0611e24b24ee9f79cc38e0095a67672d74c2e' }, h("div", { key: 'aec12bf6d94bef63f68acfaf028658254d01f181', class: className }, this.enableDragDrop && (h("swirl-visually-hidden", { key: '0af23c204985e8578aee552beff188f5e599275f' }, h("span", { key: '0f4bcc195d7bd265c028b70604ba74b1531e3c25', "aria-live": "assertive" }, this.liveRegionText))), h("div", { key: '77e6c52ecbf5e81d268b9c49364cbe166e8ba45e', class: "table__container", onFocusin: this.onFocus, onFocusout: this.onBlur, onKeyDown: this.onKeyDown, onScroll: this.onScroll, ref: (el) => (this.container = el), tabIndex: -1 }, h("div", { key: '21156e4f5d0a98c1c11cdab2c8d812833d1af031', "aria-describedby": Boolean(this.caption) ? "caption" : undefined, "aria-label": this.label, role: "table", class: "table__table" }, this.caption && (h("swirl-visually-hidden", { key: 'deea452f4a44ffaf0f8472e0ba07446f555de0c2' }, h("div", { key: 'e0f7da4bf4009659451e3890827861a64045d740', id: "caption" }, this.caption))), h("div", { key: 'ce3b91d7709fb0b607cf3b4fa48f5d118d04ac4f', role: "rowgroup" }, h("div", { key: '15c9d000b9d69eedc6ca1285a9dcfa20ca2bec02', class: "table__header", ref: (el) => (this.headerEl = el), role: "row" }, h("slot", { key: '31f61474ba47292819e5fbaf655817ed28a03434', name: "columns" }))), h("div", { key: '2d5e8fab1af067c1eb59ad84db517113cc6935e3', class: "table__body", ref: (el) => (this.bodyEl = el) }, h("slot", { key: '47f0b034e0412de19194c87bf2dd1eea524af173', name: "rows" }), h("div", { key: '4b97574c5c5919c35fd5a9ce48a4b4dbb24d9518', class: "table__empty-row", role: "row" }, h("div", { key: 'e8d44d595d30450512ad57defb3c61fd77f2040a', "aria-colspan": this.getColumns().length, class: "table__empty-row-cell", role: "cell" }, h("slot", { key: '6551e8e625520b44e608a41e67d58e65a06c20d2', name: "empty" }), !hasEmptyStateSlotAssignment && (h("swirl-text", { key: '7689d667f7574ddd4dfa3ad54d05906e1822c035', align: "center", size: "sm" }, this.emptyStateLabel))))))))));
615
+ return (h(Host, { key: '5fd51d538c87dce53702fa483657035e251d3507' }, h("div", { key: '7ec3b5830bcc7b0dfc5324f554b80b442b7bc290', class: className }, this.enableDragDrop && (h("swirl-visually-hidden", { key: '2928eb420bb8cad6477917a1883aeeffda3260eb' }, h("span", { key: 'fc615afed57d8dbfbf636f9e8feb9c6ef76ae72b', "aria-live": "assertive" }, this.liveRegionText))), h("div", { key: '4b7d5b9c4691d1828d0c24fc635d8e7c5dc48cf4', class: "table__container", onFocusin: this.onFocus, onFocusout: this.onBlur, onKeyDown: this.onKeyDown, onScroll: this.onScroll, ref: (el) => (this.container = el), tabIndex: -1 }, h("div", { key: '9669435927eb4944290b4fdcb4083ef1473c000e', "aria-describedby": Boolean(this.caption) ? "caption" : undefined, "aria-label": this.label, "aria-rowcount": this.enableVirtualization && this.virtualizationRowCount
616
+ ? this.virtualizationRowCount + 1
617
+ : undefined, role: "table", class: "table__table" }, this.caption && (h("swirl-visually-hidden", { key: '6806eedf8d1aa22b3ee8f51736032ead77a502cc' }, h("div", { key: 'bea8e3d31ba2e81461ff8e4d056ee3ea718707ea', id: "caption" }, this.caption))), h("div", { key: '386fa4a8c2d31471a43580b62ad1003cfbcf224d', role: "rowgroup" }, h("div", { key: 'aebae228fab2eb7d4a688bb50ee069e7138001c1', class: "table__header", "aria-rowindex": this.enableVirtualization ? 1 : undefined, ref: (el) => (this.headerEl = el), role: "row" }, h("slot", { key: '111dd938896772934ba589167ee254936c8bbe9d', name: "columns" }))), h("div", { key: '7a6b87e277bd50dfc8c5ff3e680aabe95384bb7f', class: "table__body", ref: (el) => (this.bodyEl = el) }, h("slot", { key: 'a766d1ff38bf321fac0b3c52a686d57d2b4551ea', name: "rows" }), h("div", { key: 'a26bec40f580546c85e3dd1007c913d53da4c18a', class: "table__empty-row", role: "row" }, h("div", { key: 'cd9793a4e353a88bfb04658354f247ddfd621e20', "aria-colspan": this.getColumns().length, class: "table__empty-row-cell", role: "cell" }, h("slot", { key: '3c79cf8327876b4be8e237e6d43c918d6f6dbda0', name: "empty" }), !hasEmptyStateSlotAssignment && (h("swirl-text", { key: '6f2d3365cd41f0242f8dc6720aed3c5bc1edf4fb', align: "center", size: "sm" }, this.emptyStateLabel))))))))));
499
618
  }
500
619
  static get is() { return "swirl-table"; }
501
620
  static get encapsulation() { return "scoped"; }
@@ -643,6 +762,102 @@ export class SwirlTable {
643
762
  "setter": false,
644
763
  "reflect": false,
645
764
  "attribute": "loading"
765
+ },
766
+ "enableVirtualization": {
767
+ "type": "boolean",
768
+ "mutable": false,
769
+ "complexType": {
770
+ "original": "boolean",
771
+ "resolved": "boolean",
772
+ "references": {}
773
+ },
774
+ "required": false,
775
+ "optional": true,
776
+ "docs": {
777
+ "tags": [],
778
+ "text": "Draws only the rows near the visible area. Render the rows from\n`virtualizationRowsChange`, each with its 0-based index in `data-index`.\nRequires `virtualizationRowCount`. Doesn't work with drag & drop or row\ngroups."
779
+ },
780
+ "getter": false,
781
+ "setter": false,
782
+ "reflect": false,
783
+ "attribute": "enable-virtualization"
784
+ },
785
+ "virtualizationRowCount": {
786
+ "type": "number",
787
+ "mutable": false,
788
+ "complexType": {
789
+ "original": "number",
790
+ "resolved": "number",
791
+ "references": {}
792
+ },
793
+ "required": false,
794
+ "optional": true,
795
+ "docs": {
796
+ "tags": [],
797
+ "text": "Total number of rows when virtualized."
798
+ },
799
+ "getter": false,
800
+ "setter": false,
801
+ "reflect": false,
802
+ "attribute": "virtualization-row-count"
803
+ },
804
+ "virtualizationEstimatedRowHeight": {
805
+ "type": "number",
806
+ "mutable": false,
807
+ "complexType": {
808
+ "original": "number",
809
+ "resolved": "number",
810
+ "references": {}
811
+ },
812
+ "required": false,
813
+ "optional": true,
814
+ "docs": {
815
+ "tags": [],
816
+ "text": "Height in px assumed for rows not drawn yet."
817
+ },
818
+ "getter": false,
819
+ "setter": false,
820
+ "reflect": false,
821
+ "attribute": "virtualization-estimated-row-height",
822
+ "defaultValue": "56"
823
+ },
824
+ "virtualizationOverscan": {
825
+ "type": "number",
826
+ "mutable": false,
827
+ "complexType": {
828
+ "original": "number",
829
+ "resolved": "number",
830
+ "references": {}
831
+ },
832
+ "required": false,
833
+ "optional": true,
834
+ "docs": {
835
+ "tags": [],
836
+ "text": "Number of extra rows drawn above and below the visible ones."
837
+ },
838
+ "getter": false,
839
+ "setter": false,
840
+ "reflect": false,
841
+ "attribute": "virtualization-overscan",
842
+ "defaultValue": "10"
843
+ },
844
+ "virtualizationKeepRowsRendered": {
845
+ "type": "unknown",
846
+ "mutable": false,
847
+ "complexType": {
848
+ "original": "number[]",
849
+ "resolved": "number[]",
850
+ "references": {}
851
+ },
852
+ "required": false,
853
+ "optional": true,
854
+ "docs": {
855
+ "tags": [],
856
+ "text": "Indexes of rows to keep drawn when out of view, e.g. a row with an open\nmenu. The focused row is always kept."
857
+ },
858
+ "getter": false,
859
+ "setter": false,
860
+ "defaultValue": "[]"
646
861
  }
647
862
  };
648
863
  }
@@ -677,6 +892,27 @@ export class SwirlTable {
677
892
  }
678
893
  }
679
894
  }
895
+ }, {
896
+ "method": "virtualizationRowsChange",
897
+ "name": "virtualizationRowsChange",
898
+ "bubbles": true,
899
+ "cancelable": true,
900
+ "composed": true,
901
+ "docs": {
902
+ "tags": [],
903
+ "text": "Emits the indexes of the rows to render."
904
+ },
905
+ "complexType": {
906
+ "original": "SwirlTableVirtualizationRows",
907
+ "resolved": "{ indexes: number[]; }",
908
+ "references": {
909
+ "SwirlTableVirtualizationRows": {
910
+ "location": "local",
911
+ "path": "/home/runner/work/swirl/swirl/packages/swirl-components/src/components/swirl-table/swirl-table.tsx",
912
+ "id": "src/components/swirl-table/swirl-table.tsx::SwirlTableVirtualizationRows"
913
+ }
914
+ }
915
+ }
680
916
  }];
681
917
  }
682
918
  static get methods() {
@@ -703,6 +939,21 @@ export class SwirlTable {
703
939
  static get elementRef() { return "el"; }
704
940
  static get watchers() {
705
941
  return [{
942
+ "propName": "enableVirtualization",
943
+ "methodName": "handleVirtualizationChange"
944
+ }, {
945
+ "propName": "virtualizationRowCount",
946
+ "methodName": "handleVirtualizationChange"
947
+ }, {
948
+ "propName": "virtualizationEstimatedRowHeight",
949
+ "methodName": "handleVirtualizationChange"
950
+ }, {
951
+ "propName": "virtualizationOverscan",
952
+ "methodName": "handleVirtualizationChange"
953
+ }, {
954
+ "propName": "virtualizationKeepRowsRendered",
955
+ "methodName": "handleVirtualizationChange"
956
+ }, {
706
957
  "propName": "enableDragDrop",
707
958
  "methodName": "handleEnableDragDropChange"
708
959
  }];
@@ -143,3 +143,193 @@ SwirlTable.args = {
143
143
  enableDragDrop: true,
144
144
  label: "Table",
145
145
  };
146
+ const firstNames = [
147
+ "Isabel",
148
+ "Doyle",
149
+ "Don",
150
+ "Amara",
151
+ "Kenji",
152
+ "Lena",
153
+ "Mateo",
154
+ "Priya",
155
+ "Sven",
156
+ "Zoe",
157
+ ];
158
+ const lastNames = [
159
+ "Lakin",
160
+ "Stoltenberg",
161
+ "Conroy",
162
+ "Okafor",
163
+ "Tanaka",
164
+ "Schmidt",
165
+ "Rossi",
166
+ "Patel",
167
+ "Larsen",
168
+ "Moreau",
169
+ "Novak",
170
+ ];
171
+ const statuses = [
172
+ { intent: "success", label: "Active" },
173
+ { intent: "warning", label: "Pending" },
174
+ { intent: "critical", label: "Blocked" },
175
+ ];
176
+ /**
177
+ * Builds the row for an index. Content depends on the index only, so a row
178
+ * drawn again after scrolling looks the same. Every 7th row has two lines of
179
+ * text, so the rows have different heights.
180
+ */
181
+ const createVirtualizedRow = (index, idPrefix) => {
182
+ const firstName = firstNames[index % firstNames.length];
183
+ const lastName = lastNames[(index * 7) % lastNames.length];
184
+ const name = `${firstName} ${lastName}`;
185
+ const email = `${firstName}.${lastName}.${index}@flipapp.de`.toLowerCase();
186
+ const status = statuses[index % statuses.length];
187
+ const isTall = index % 7 === 0;
188
+ const popoverId = `${idPrefix}-popover-${index}`;
189
+ const row = document.createElement("swirl-table-row");
190
+ row.id = `${idPrefix}-row-${index}`;
191
+ row.dataset.index = String(index);
192
+ row.innerHTML = `
193
+ <swirl-table-cell>
194
+ <swirl-text size="sm" truncate>${index}</swirl-text>
195
+ </swirl-table-cell>
196
+ <swirl-table-cell>
197
+ <swirl-stack>
198
+ <swirl-text size="sm" weight="medium">${name}</swirl-text>
199
+ ${isTall
200
+ ? `<swirl-text color="subdued" size="sm">Taller row with a second line of text</swirl-text>`
201
+ : ""}
202
+ </swirl-stack>
203
+ </swirl-table-cell>
204
+ <swirl-table-cell>
205
+ <swirl-text size="sm"><swirl-link href="#" label="${email}"></swirl-link></swirl-text>
206
+ </swirl-table-cell>
207
+ <swirl-table-cell>
208
+ <swirl-tag label="${status.label}" intent="${status.intent}"></swirl-tag>
209
+ </swirl-table-cell>
210
+ <swirl-table-cell>
211
+ <swirl-popover-trigger hide-popover-when-invisible="false" swirl-popover="${popoverId}">
212
+ <swirl-button hide-label icon="<swirl-icon-more-vertikal></swirl-icon-more-vertikal>" label="Options for ${name}"></swirl-button>
213
+ </swirl-popover-trigger>
214
+ <swirl-popover disable-scroll-lock id="${popoverId}" label="Options for ${name}">
215
+ <swirl-action-list>
216
+ <swirl-action-list-item icon="<swirl-icon-edit></swirl-icon-edit>" label="Edit"></swirl-action-list-item>
217
+ <swirl-action-list-item icon="<swirl-icon-delete></swirl-icon-delete>" intent="critical" label="Delete"></swirl-action-list-item>
218
+ </swirl-action-list>
219
+ </swirl-popover>
220
+ </swirl-table-cell>
221
+ `;
222
+ return row;
223
+ };
224
+ /**
225
+ * Renders the rows named by `virtualizationRowsChange`, tracked by id. Rows
226
+ * that stay drawn are not moved, so focus and open popovers survive scrolling.
227
+ * Rows with an open popover are kept drawn via
228
+ * `virtualizationKeepRowsRendered`. The popovers stay open while scrolled out
229
+ * of view and don't lock scrolling, so kept rows can be tested by scrolling
230
+ * away from an open menu.
231
+ */
232
+ const createVirtualizedTable = (args, idPrefix) => {
233
+ const table = generateStoryElement("swirl-table", args);
234
+ table.innerHTML = `
235
+ <div slot="columns">
236
+ <swirl-table-column width="80px">#</swirl-table-column>
237
+ <swirl-table-column min-width="200px">Name</swirl-table-column>
238
+ <swirl-table-column min-width="240px">Email</swirl-table-column>
239
+ <swirl-table-column min-width="120px">Status</swirl-table-column>
240
+ <swirl-table-column sticky width="74px"><swirl-visually-hidden>Options</swirl-visually-hidden></swirl-table-column>
241
+ </div>
242
+ <div slot="rows"></div>
243
+ `;
244
+ const rowsContainer = table.querySelector('[slot="rows"]');
245
+ const rowsByIndex = new Map();
246
+ const openPopoverRows = new Set();
247
+ const renderRows = (indexes) => {
248
+ const wantedSet = new Set(indexes);
249
+ // Remove rows first, so the rows that stay are never moved.
250
+ rowsByIndex.forEach((row, index) => {
251
+ if (!wantedSet.has(index)) {
252
+ row.remove();
253
+ rowsByIndex.delete(index);
254
+ }
255
+ });
256
+ let nextRow = rowsContainer.firstElementChild;
257
+ indexes.forEach((index) => {
258
+ const existingRow = rowsByIndex.get(index);
259
+ if (existingRow) {
260
+ nextRow = existingRow.nextElementSibling;
261
+ return;
262
+ }
263
+ const row = createVirtualizedRow(index, idPrefix);
264
+ rowsByIndex.set(index, row);
265
+ rowsContainer.insertBefore(row, nextRow);
266
+ });
267
+ };
268
+ const getRowIndexOf = (target) => Number(target.closest("swirl-table-row")?.dataset.index ?? NaN);
269
+ const toggleKeptRow = (event, isKept) => {
270
+ const index = getRowIndexOf(event.target);
271
+ if (Number.isNaN(index)) {
272
+ return;
273
+ }
274
+ if (isKept) {
275
+ openPopoverRows.add(index);
276
+ }
277
+ else {
278
+ openPopoverRows.delete(index);
279
+ }
280
+ table.virtualizationKeepRowsRendered = [...openPopoverRows];
281
+ };
282
+ table.addEventListener("virtualizationRowsChange", (event) => {
283
+ renderRows(event.detail.indexes);
284
+ });
285
+ table.addEventListener("popoverOpen", (event) => toggleKeptRow(event, true));
286
+ table.addEventListener("popoverClose", (event) => toggleKeptRow(event, false));
287
+ // Without virtualization, render all rows for comparison.
288
+ if (!args.enableVirtualization) {
289
+ renderRows(Array.from({ length: args.virtualizationRowCount ?? 0 }, (_, index) => index));
290
+ }
291
+ return table;
292
+ };
293
+ const virtualizedArgTypes = {
294
+ enableVirtualization: {
295
+ control: { type: "boolean" },
296
+ description: "Draws only the rows near the visible area.",
297
+ },
298
+ virtualizationEstimatedRowHeight: {
299
+ control: { type: "number" },
300
+ description: "Height in px assumed for rows not drawn yet.",
301
+ },
302
+ virtualizationOverscan: {
303
+ control: { type: "number" },
304
+ description: "Number of extra rows drawn above and below the visible ones.",
305
+ },
306
+ virtualizationRowCount: {
307
+ control: { type: "number" },
308
+ description: "Total number of rows when virtualized.",
309
+ },
310
+ };
311
+ const virtualizedArgs = {
312
+ emptyStateLabel: "No rows.",
313
+ enableVirtualization: true,
314
+ label: "Virtualized table",
315
+ virtualizationEstimatedRowHeight: 56,
316
+ virtualizationOverscan: 10,
317
+ virtualizationRowCount: 1000,
318
+ };
319
+ const VirtualizedTemplate = (args) => {
320
+ const scrollContainer = document.createElement("div");
321
+ const table = createVirtualizedTable(args, "virtualized");
322
+ scrollContainer.style.height = "500px";
323
+ scrollContainer.style.overflowY = "auto";
324
+ scrollContainer.style.border =
325
+ "1px solid var(--s-border-default, currentColor)";
326
+ scrollContainer.append(table);
327
+ return scrollContainer;
328
+ };
329
+ export const Virtualized = VirtualizedTemplate.bind({});
330
+ Virtualized.args = { ...virtualizedArgs };
331
+ Virtualized.argTypes = virtualizedArgTypes;
332
+ const VirtualizedWindowScrollTemplate = (args) => createVirtualizedTable(args, "virtualized-window-scroll");
333
+ export const VirtualizedWindowScroll = VirtualizedWindowScrollTemplate.bind({});
334
+ VirtualizedWindowScroll.args = { ...virtualizedArgs };
335
+ VirtualizedWindowScroll.argTypes = virtualizedArgTypes;
@@ -245,3 +245,35 @@ export function getPixelsFromRemToken(token) {
245
245
  .getPropertyValue(token)
246
246
  .replace("rem", "") * 16);
247
247
  }
248
+ /**
249
+ * Nearest vertically scrolling ancestor, also across shadow roots. Falls back
250
+ * to the window.
251
+ */
252
+ export function getScrollParent(el) {
253
+ let node = getFlatTreeParent(el);
254
+ while (node && node !== document.body && node !== document.documentElement) {
255
+ const { overflowY } = getComputedStyle(node);
256
+ if (/(auto|scroll|overlay)/.test(overflowY) &&
257
+ node.scrollHeight > node.clientHeight) {
258
+ return node;
259
+ }
260
+ node = getFlatTreeParent(node);
261
+ }
262
+ return window;
263
+ }
264
+ /**
265
+ * Parent in the rendered (flat) tree: a slotted element's parent is its slot,
266
+ * not its light DOM parent, and a shadow root's top element's parent is the
267
+ * host. Unlike `closestPassShadow`, this finds ancestors inside the shadow
268
+ * root an element is slotted into.
269
+ */
270
+ export function getFlatTreeParent(el) {
271
+ if (el.assignedSlot) {
272
+ return el.assignedSlot;
273
+ }
274
+ if (el.parentElement) {
275
+ return el.parentElement;
276
+ }
277
+ const root = el.getRootNode();
278
+ return root instanceof ShadowRoot ? root.host : null;
279
+ }
@@ -1 +1 @@
1
- import{u as s}from"./utils.js";const t=new class{constructor(){this.listeners=new Set,this.onChange=s=>{this.listeners.forEach((t=>t(s.matches)))},this.mediaQueryList=s(),this.mediaQueryList.addEventListener("change",this.onChange)}subscribe(s){return this.listeners.add(s),s(this.mediaQueryList.matches),()=>{this.listeners.delete(s)}}};export{t as D}
1
+ import{v as s}from"./utils.js";const t=new class{constructor(){this.listeners=new Set,this.onChange=s=>{this.listeners.forEach((t=>t(s.matches)))},this.mediaQueryList=s(),this.mediaQueryList.addEventListener("change",this.onChange)}subscribe(s){return this.listeners.add(s),s(this.mediaQueryList.matches),()=>{this.listeners.delete(s)}}};export{t as D}
@@ -1,4 +1,4 @@
1
- import{proxyCustomElement as t,HTMLElement as e,createEvent as i,h as s,Host as n,transformTag as r}from"@stencil/core/internal/client";import{c as o}from"./index2.js";import{d as h,s as a,i as c}from"./utils.js";import{d as l}from"./swirl-icon-error2.js";import{d as u}from"./swirl-inline-error2.js";import{d}from"./swirl-spinner2.js";import{d as f}from"./swirl-visually-hidden2.js";
1
+ import{proxyCustomElement as t,HTMLElement as e,createEvent as i,h as s,Host as n,transformTag as r}from"@stencil/core/internal/client";import{c as o}from"./index2.js";import{d as h,t as a,i as c}from"./utils.js";import{d as l}from"./swirl-icon-error2.js";import{d as u}from"./swirl-inline-error2.js";import{d}from"./swirl-spinner2.js";import{d as f}from"./swirl-visually-hidden2.js";
2
2
  /**
3
3
  * @licstart The following is the entire license notice for the
4
4
  * JavaScript code in this page