@getflip/swirl-components 0.533.0 → 0.534.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.
- package/components.json +158 -1
- package/dist/cjs/index-D-n4TKMG.js +4 -4
- package/dist/cjs/loader.cjs.js +1 -1
- package/dist/cjs/{media-query.service-B8u-DqoO.js → media-query.service-C1jMjjiy.js} +1 -1
- package/dist/cjs/swirl-action-list_2.cjs.entry.js +2 -2
- package/dist/cjs/swirl-app-layout.cjs.entry.js +2 -2
- package/dist/cjs/swirl-autocomplete.cjs.entry.js +1 -1
- package/dist/cjs/swirl-banner.cjs.entry.js +2 -2
- package/dist/cjs/swirl-button.cjs.entry.js +2 -2
- package/dist/cjs/swirl-carousel.cjs.entry.js +1 -1
- package/dist/cjs/swirl-components.cjs.js +1 -1
- package/dist/cjs/swirl-console-layout.cjs.entry.js +1 -1
- package/dist/cjs/swirl-date-input.cjs.entry.js +2 -2
- package/dist/cjs/swirl-date-picker_2.cjs.entry.js +1 -1
- package/dist/cjs/swirl-file-chip.cjs.entry.js +1 -1
- package/dist/cjs/swirl-file-viewer-audio_7.cjs.entry.js +1 -1
- package/dist/cjs/swirl-file-viewer_7.cjs.entry.js +1 -1
- package/dist/cjs/swirl-form-control.cjs.entry.js +1 -1
- package/dist/cjs/swirl-icon-check-small_3.cjs.entry.js +2 -2
- package/dist/cjs/swirl-icon-error_3.cjs.entry.js +2 -2
- package/dist/cjs/swirl-image-grid-item.cjs.entry.js +1 -1
- package/dist/cjs/swirl-inline-status.cjs.entry.js +2 -2
- package/dist/cjs/swirl-lightbox.cjs.entry.js +1 -1
- package/dist/cjs/swirl-menu-item.cjs.entry.js +1 -1
- package/dist/cjs/swirl-menu.cjs.entry.js +1 -1
- package/dist/cjs/swirl-modal.cjs.entry.js +1 -1
- package/dist/cjs/swirl-option-list.cjs.entry.js +1 -1
- package/dist/cjs/swirl-pagination.cjs.entry.js +1 -1
- package/dist/cjs/swirl-pdf-reader.cjs.entry.js +1 -1
- package/dist/cjs/swirl-popover_2.cjs.entry.js +1 -1
- package/dist/cjs/swirl-resource-list-file-item.cjs.entry.js +2 -2
- package/dist/cjs/swirl-resource-list-item.cjs.entry.js +2 -2
- package/dist/cjs/swirl-search.cjs.entry.js +2 -2
- package/dist/cjs/swirl-select.cjs.entry.js +1 -1
- package/dist/cjs/swirl-shell-layout.cjs.entry.js +1 -1
- package/dist/cjs/swirl-tab-bar.cjs.entry.js +1 -1
- package/dist/cjs/swirl-table-column.cjs.entry.js +1 -1
- package/dist/cjs/swirl-table-row.cjs.entry.js +1 -1
- package/dist/cjs/swirl-table.cjs.entry.js +2303 -10
- package/dist/cjs/swirl-tabs.cjs.entry.js +1 -1
- package/dist/cjs/swirl-text-input.cjs.entry.js +2 -2
- package/dist/cjs/swirl-time-input.cjs.entry.js +2 -2
- package/dist/cjs/swirl-toast.cjs.entry.js +2 -2
- package/dist/cjs/swirl-toolbar.cjs.entry.js +1 -1
- package/dist/cjs/swirl-tooltip.cjs.entry.js +1 -1
- package/dist/cjs/{utils-UfZG-xPD.js → utils-C4tLdXqU.js} +33 -0
- package/dist/collection/components/swirl-table/swirl-table-virtualizer.js +224 -0
- package/dist/collection/components/swirl-table/swirl-table.js +269 -10
- package/dist/collection/components/swirl-table/swirl-table.stories.js +190 -0
- package/dist/collection/utils.js +32 -0
- package/dist/components/media-query.service.js +1 -1
- package/dist/components/swirl-file-viewer-pdf2.js +1 -1
- package/dist/components/swirl-popover2.js +1 -1
- package/dist/components/swirl-tab-bar2.js +1 -1
- package/dist/components/swirl-table.js +1 -1
- package/dist/components/swirl-tabs.js +1 -1
- package/dist/components/swirl-tooltip2.js +1 -1
- package/dist/components/utils.js +1 -1
- package/dist/esm/index-Dz56lJ37.js +4 -4
- package/dist/esm/loader.js +1 -1
- package/dist/esm/{media-query.service-CCYT6DU8.js → media-query.service-Bbqqduao.js} +1 -1
- package/dist/esm/swirl-action-list_2.entry.js +2 -2
- package/dist/esm/swirl-app-layout.entry.js +2 -2
- package/dist/esm/swirl-autocomplete.entry.js +1 -1
- package/dist/esm/swirl-banner.entry.js +2 -2
- package/dist/esm/swirl-button.entry.js +2 -2
- package/dist/esm/swirl-carousel.entry.js +1 -1
- package/dist/esm/swirl-components.js +1 -1
- package/dist/esm/swirl-console-layout.entry.js +1 -1
- package/dist/esm/swirl-date-input.entry.js +2 -2
- package/dist/esm/swirl-date-picker_2.entry.js +1 -1
- package/dist/esm/swirl-file-chip.entry.js +1 -1
- package/dist/esm/swirl-file-viewer-audio_7.entry.js +1 -1
- package/dist/esm/swirl-file-viewer_7.entry.js +1 -1
- package/dist/esm/swirl-form-control.entry.js +1 -1
- package/dist/esm/swirl-icon-check-small_3.entry.js +2 -2
- package/dist/esm/swirl-icon-error_3.entry.js +2 -2
- package/dist/esm/swirl-image-grid-item.entry.js +1 -1
- package/dist/esm/swirl-inline-status.entry.js +2 -2
- package/dist/esm/swirl-lightbox.entry.js +1 -1
- package/dist/esm/swirl-menu-item.entry.js +1 -1
- package/dist/esm/swirl-menu.entry.js +1 -1
- package/dist/esm/swirl-modal.entry.js +1 -1
- package/dist/esm/swirl-option-list.entry.js +1 -1
- package/dist/esm/swirl-pagination.entry.js +1 -1
- package/dist/esm/swirl-pdf-reader.entry.js +1 -1
- package/dist/esm/swirl-popover_2.entry.js +1 -1
- package/dist/esm/swirl-resource-list-file-item.entry.js +2 -2
- package/dist/esm/swirl-resource-list-item.entry.js +2 -2
- package/dist/esm/swirl-search.entry.js +2 -2
- package/dist/esm/swirl-select.entry.js +1 -1
- package/dist/esm/swirl-shell-layout.entry.js +1 -1
- package/dist/esm/swirl-tab-bar.entry.js +1 -1
- package/dist/esm/swirl-table-column.entry.js +1 -1
- package/dist/esm/swirl-table-row.entry.js +1 -1
- package/dist/esm/swirl-table.entry.js +2303 -10
- package/dist/esm/swirl-tabs.entry.js +1 -1
- package/dist/esm/swirl-text-input.entry.js +2 -2
- package/dist/esm/swirl-time-input.entry.js +2 -2
- package/dist/esm/swirl-toast.entry.js +2 -2
- package/dist/esm/swirl-toolbar.entry.js +1 -1
- package/dist/esm/swirl-tooltip.entry.js +1 -1
- package/dist/esm/{utils-CCck-DTo.js → utils-D23VxAsw.js} +33 -1
- package/dist/swirl-components/p-0cb6bbde.entry.js +1 -0
- package/dist/swirl-components/{p-ea6bdee5.entry.js → p-20354a36.entry.js} +1 -1
- package/dist/swirl-components/{p-8d078f8a.entry.js → p-247ada6e.entry.js} +1 -1
- package/dist/swirl-components/{p-270be9f2.entry.js → p-29fed244.entry.js} +1 -1
- package/dist/swirl-components/{p-c924fc96.entry.js → p-437ac2fa.entry.js} +1 -1
- package/dist/swirl-components/{p-97deaddc.entry.js → p-48c1b8e4.entry.js} +1 -1
- package/dist/swirl-components/{p-40be5fde.entry.js → p-48c559a4.entry.js} +1 -1
- package/dist/swirl-components/p-4a1d3582.entry.js +1 -0
- package/dist/swirl-components/p-4dc32920.entry.js +1 -0
- package/dist/swirl-components/{p-ad4fd14f.entry.js → p-5c6fc0bc.entry.js} +1 -1
- package/dist/swirl-components/{p-73a8e8a0.entry.js → p-6242f9bb.entry.js} +1 -1
- package/dist/swirl-components/{p-0c0acfd3.entry.js → p-641bb5b1.entry.js} +1 -1
- package/dist/swirl-components/{p-993dae75.entry.js → p-6528e39b.entry.js} +1 -1
- package/dist/swirl-components/{p-b45902de.entry.js → p-6785b8a5.entry.js} +1 -1
- package/dist/swirl-components/{p-dcf08d9a.entry.js → p-692dd291.entry.js} +1 -1
- package/dist/swirl-components/{p-418a8b7b.entry.js → p-6e0825ae.entry.js} +1 -1
- package/dist/swirl-components/{p-22931b7b.entry.js → p-71e1f20d.entry.js} +1 -1
- package/dist/swirl-components/{p-f015fc2d.entry.js → p-78af0765.entry.js} +1 -1
- package/dist/swirl-components/{p-2ddf4a93.entry.js → p-7a9bb681.entry.js} +1 -1
- package/dist/swirl-components/{p-b36ee49f.entry.js → p-84cfb27a.entry.js} +1 -1
- package/dist/swirl-components/{p-c6bceca5.entry.js → p-91b316f9.entry.js} +1 -1
- package/dist/swirl-components/{p-da6fa0fa.entry.js → p-958aa736.entry.js} +1 -1
- package/dist/swirl-components/{p-fbdb4aff.entry.js → p-95d6d7ad.entry.js} +1 -1
- package/dist/swirl-components/{p-577174d9.entry.js → p-984c4d86.entry.js} +1 -1
- package/dist/swirl-components/{p-CCck-DTo.js → p-D23VxAsw.js} +1 -1
- package/dist/swirl-components/{p-Bfn7CHM9.js → p-_iAIu_AF.js} +1 -1
- package/dist/swirl-components/{p-d0275263.entry.js → p-a11ba0b5.entry.js} +1 -1
- package/dist/swirl-components/{p-1bf78baf.entry.js → p-ae978c57.entry.js} +1 -1
- package/dist/swirl-components/{p-95a403cf.entry.js → p-b08aa57d.entry.js} +1 -1
- package/dist/swirl-components/{p-26362ab2.entry.js → p-bb4c80bf.entry.js} +1 -1
- package/dist/swirl-components/{p-e63650e3.entry.js → p-c182f4c1.entry.js} +1 -1
- package/dist/swirl-components/{p-d763ce05.entry.js → p-c4dad69d.entry.js} +1 -1
- package/dist/swirl-components/{p-47b02bc4.entry.js → p-cf855c44.entry.js} +1 -1
- package/dist/swirl-components/{p-fbcc5141.entry.js → p-d26aa1e7.entry.js} +1 -1
- package/dist/swirl-components/{p-3340670b.entry.js → p-d298c94c.entry.js} +1 -1
- package/dist/swirl-components/{p-9ad61433.entry.js → p-d8924470.entry.js} +1 -1
- package/dist/swirl-components/{p-268ddaee.entry.js → p-dab890a1.entry.js} +2 -2
- package/dist/swirl-components/{p-3e6fb027.entry.js → p-de5a7b4a.entry.js} +1 -1
- package/dist/swirl-components/{p-96c9486a.entry.js → p-eb297822.entry.js} +1 -1
- package/dist/swirl-components/{p-bee027a0.entry.js → p-ec10ca71.entry.js} +1 -1
- package/dist/swirl-components/{p-94e6a907.entry.js → p-f6c37730.entry.js} +1 -1
- package/dist/swirl-components/{p-b581b1e6.entry.js → p-fd188df6.entry.js} +1 -1
- package/dist/swirl-components/swirl-components.esm.js +1 -1
- package/dist/types/components/swirl-table/swirl-table-virtualizer.d.ts +60 -0
- package/dist/types/components/swirl-table/swirl-table.d.ts +46 -1
- package/dist/types/components/swirl-table/swirl-table.stories.d.ts +2 -0
- package/dist/types/components.d.ts +57 -2
- package/dist/types/utils.d.ts +12 -0
- package/package.json +2 -1
- package/vscode-data.json +16 -0
- package/dist/swirl-components/p-0c0b46e1.entry.js +0 -1
- package/dist/swirl-components/p-2943bc69.entry.js +0 -1
- 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 {
|
|
5
|
+
import { 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,11 +19,16 @@ 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
|
-
this.triggerRerender = debounce(async () => {
|
|
23
|
-
await this.updateLayout();
|
|
24
|
-
this.updateEmptyState();
|
|
25
|
-
}, 0, true);
|
|
26
32
|
this.updateLayout = debouncePromise(async () => {
|
|
27
33
|
this.resetCellStyles();
|
|
28
34
|
this.resetColumnStyles();
|
|
@@ -37,6 +43,7 @@ export class SwirlTable {
|
|
|
37
43
|
this.updateScrolledState();
|
|
38
44
|
};
|
|
39
45
|
this.onFocus = (event) => {
|
|
46
|
+
this.trackFocusedRow(event.target);
|
|
40
47
|
if (this.movingViaKeyboard) {
|
|
41
48
|
const movingRow = this.el.querySelector(".table-row--moving");
|
|
42
49
|
if (movingRow) {
|
|
@@ -50,6 +57,9 @@ export class SwirlTable {
|
|
|
50
57
|
};
|
|
51
58
|
this.onBlur = (event) => {
|
|
52
59
|
const newlyFocusedElement = event.relatedTarget;
|
|
60
|
+
if (!this.el.contains(newlyFocusedElement)) {
|
|
61
|
+
this.trackFocusedRow(null);
|
|
62
|
+
}
|
|
53
63
|
const focusedDragHandle = !!newlyFocusedElement?.closest(this.dragDropHandle);
|
|
54
64
|
if (this.el.contains(newlyFocusedElement) && focusedDragHandle) {
|
|
55
65
|
return;
|
|
@@ -92,6 +102,7 @@ export class SwirlTable {
|
|
|
92
102
|
async componentDidLoad() {
|
|
93
103
|
this.setupIntersectionObserver();
|
|
94
104
|
this.setupMutationObservers();
|
|
105
|
+
this.updateVirtualizer();
|
|
95
106
|
queueMicrotask(() => {
|
|
96
107
|
this.setupDragDrop();
|
|
97
108
|
});
|
|
@@ -101,6 +112,60 @@ export class SwirlTable {
|
|
|
101
112
|
this.columnMutationObserver?.disconnect();
|
|
102
113
|
this.rowMutationObserver?.disconnect();
|
|
103
114
|
this.sortable?.destroy();
|
|
115
|
+
this.destroyVirtualizer();
|
|
116
|
+
}
|
|
117
|
+
handleVirtualizationChange() {
|
|
118
|
+
this.updateVirtualizer();
|
|
119
|
+
}
|
|
120
|
+
get virtualizerConfig() {
|
|
121
|
+
if (!this.enableVirtualization || !this.virtualizationRowCount) {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
estimatedRowHeight: this.virtualizationEstimatedRowHeight,
|
|
126
|
+
keptIndexes: this.focusedRowIndex === undefined
|
|
127
|
+
? this.virtualizationKeepRowsRendered ?? []
|
|
128
|
+
: [
|
|
129
|
+
...(this.virtualizationKeepRowsRendered ?? []),
|
|
130
|
+
this.focusedRowIndex,
|
|
131
|
+
],
|
|
132
|
+
overscan: this.virtualizationOverscan,
|
|
133
|
+
rowCount: this.virtualizationRowCount,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
updateVirtualizer() {
|
|
137
|
+
if (!this.bodyEl) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const config = this.virtualizerConfig;
|
|
141
|
+
if (!config) {
|
|
142
|
+
const hadVirtualizer = Boolean(this.virtualizer);
|
|
143
|
+
this.destroyVirtualizer();
|
|
144
|
+
// tell the app to clear its rows when they drop to 0. checking for a
|
|
145
|
+
// previous virtualizer emits only once, not on every focus change.
|
|
146
|
+
if (this.enableVirtualization && hadVirtualizer) {
|
|
147
|
+
queueMicrotask(() => this.virtualizationRowsChange.emit({ indexes: [] }));
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (this.virtualizer) {
|
|
152
|
+
this.virtualizer.setConfig(config);
|
|
153
|
+
// find the scroll container when more rows make it overflow
|
|
154
|
+
if (this.virtualizer.scrollElement === window) {
|
|
155
|
+
this.updateScrollParent();
|
|
156
|
+
}
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
// reserve the full height first, so the scroll container overflows and
|
|
160
|
+
// can be found.
|
|
161
|
+
this.bodyEl.style.paddingBottom = `${config.rowCount * config.estimatedRowHeight}px`;
|
|
162
|
+
this.virtualizer = new SwirlTableVirtualizer(this.bodyEl, getScrollParent(this.el), config, (indexes) =>
|
|
163
|
+
// emit async, so frameworks don't get it mid-render.
|
|
164
|
+
queueMicrotask(() => this.virtualizationRowsChange.emit({ indexes })));
|
|
165
|
+
}
|
|
166
|
+
destroyVirtualizer() {
|
|
167
|
+
this.virtualizer?.destroy();
|
|
168
|
+
this.virtualizer = undefined;
|
|
104
169
|
}
|
|
105
170
|
handleEnableDragDropChange() {
|
|
106
171
|
queueMicrotask(() => {
|
|
@@ -136,15 +201,21 @@ export class SwirlTable {
|
|
|
136
201
|
});
|
|
137
202
|
this.rowMutationObserver = new MutationObserver((mutations) => {
|
|
138
203
|
const rowWasAddedOrRemoved = mutations.some((mutation) => mutation.addedNodes.length || mutation.removedNodes.length);
|
|
204
|
+
// rows tracked by position are reused: only their data-index changes.
|
|
205
|
+
const rowIndexChanged = mutations.some((mutation) => mutation.type === "attributes");
|
|
139
206
|
if (rowWasAddedOrRemoved) {
|
|
140
207
|
this.updateEmptyState();
|
|
141
208
|
this.setupDragDrop();
|
|
142
209
|
}
|
|
210
|
+
if (rowWasAddedOrRemoved || rowIndexChanged) {
|
|
211
|
+
this.syncVirtualizedRows({ layOutCells: rowWasAddedOrRemoved });
|
|
212
|
+
}
|
|
143
213
|
});
|
|
144
214
|
this.startRowMutationObserver();
|
|
145
215
|
}
|
|
146
216
|
startRowMutationObserver() {
|
|
147
217
|
this.rowMutationObserver?.observe(this.bodyEl, {
|
|
218
|
+
attributeFilter: ["data-index"],
|
|
148
219
|
childList: true,
|
|
149
220
|
subtree: true,
|
|
150
221
|
});
|
|
@@ -206,10 +277,23 @@ export class SwirlTable {
|
|
|
206
277
|
// Delay layout update to ensure the container is fully visible,
|
|
207
278
|
// especially if it was initially rendered in a modal.
|
|
208
279
|
setTimeout(async () => {
|
|
280
|
+
this.updateScrollParent();
|
|
209
281
|
await this.updateLayout();
|
|
210
282
|
}, 100);
|
|
211
283
|
}
|
|
212
284
|
}
|
|
285
|
+
/**
|
|
286
|
+
* A table hidden on load falls back to the window. Look for the scroll
|
|
287
|
+
* container again once it is visible.
|
|
288
|
+
*/
|
|
289
|
+
updateScrollParent() {
|
|
290
|
+
if (!this.virtualizer ||
|
|
291
|
+
getScrollParent(this.el) === this.virtualizer.scrollElement) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
this.destroyVirtualizer();
|
|
295
|
+
this.updateVirtualizer();
|
|
296
|
+
}
|
|
213
297
|
async componentDidRender() {
|
|
214
298
|
await this.updateLayout();
|
|
215
299
|
this.updateEmptyState();
|
|
@@ -221,7 +305,10 @@ export class SwirlTable {
|
|
|
221
305
|
* Force a re-render of the table
|
|
222
306
|
*/
|
|
223
307
|
async rerender() {
|
|
224
|
-
|
|
308
|
+
// updateLayout is debounced with a trailing call, so a row that loads
|
|
309
|
+
// while a layout runs still gets laid out.
|
|
310
|
+
await this.updateLayout();
|
|
311
|
+
this.updateEmptyState();
|
|
225
312
|
}
|
|
226
313
|
resetEmptyRowStyles() {
|
|
227
314
|
const emptyRow = this.el.querySelector(".table__empty-row");
|
|
@@ -323,11 +410,14 @@ export class SwirlTable {
|
|
|
323
410
|
layOutCellsAndColumns() {
|
|
324
411
|
const columns = this.getColumns();
|
|
325
412
|
const cells = this.getCells();
|
|
413
|
+
// Measure every column before sizing any cell. The table is as wide as its
|
|
414
|
+
// widest row, so sizing one column's cells moves the columns not measured
|
|
415
|
+
// yet.
|
|
416
|
+
const columnProperties = columns.map((column, colIndex) => this.calculateColumnProperties(column, columns, colIndex));
|
|
326
417
|
columns.forEach((column, colIndex) => {
|
|
327
418
|
const cellsOfColumn = this.getCellsForColumn(cells, columns, colIndex);
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
this.applyColumnStyles(column, columnProperties);
|
|
419
|
+
cellsOfColumn.forEach((cell) => this.applyCellStyles(cell, column, columnProperties[colIndex]));
|
|
420
|
+
this.applyColumnStyles(column, columnProperties[colIndex]);
|
|
331
421
|
});
|
|
332
422
|
}
|
|
333
423
|
getCellsForColumn(cells, columns, colIndex) {
|
|
@@ -394,6 +484,10 @@ export class SwirlTable {
|
|
|
394
484
|
.some((column) => column.sticky);
|
|
395
485
|
}
|
|
396
486
|
updateEmptyState() {
|
|
487
|
+
if (this.enableVirtualization && this.virtualizationRowCount) {
|
|
488
|
+
this.empty = false;
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
397
491
|
const rowsContainer = this.el.querySelector('[slot="rows"]');
|
|
398
492
|
this.empty = !Boolean(rowsContainer) || rowsContainer.children.length === 0;
|
|
399
493
|
}
|
|
@@ -489,13 +583,46 @@ export class SwirlTable {
|
|
|
489
583
|
handle.querySelector("button")?.focus();
|
|
490
584
|
}
|
|
491
585
|
}
|
|
586
|
+
/**
|
|
587
|
+
* Measures and positions rows after they were added, removed or re-indexed.
|
|
588
|
+
* The focused row's index is read again first, as it changes when e.g. a row
|
|
589
|
+
* is inserted above it.
|
|
590
|
+
*
|
|
591
|
+
* Added rows and cells are laid out too: a row calls `rerender()` only when
|
|
592
|
+
* it first loads, so cells added to a drawn row would get no width.
|
|
593
|
+
*/
|
|
594
|
+
syncVirtualizedRows({ layOutCells }) {
|
|
595
|
+
if (!this.virtualizer) {
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
this.trackFocusedRow(this.el.querySelector("swirl-table-row[data-index]:focus-within"));
|
|
599
|
+
this.virtualizer.sync();
|
|
600
|
+
if (layOutCells) {
|
|
601
|
+
this.updateLayout();
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
/** Keeps the focused row drawn, so it doesn't lose focus. */
|
|
605
|
+
trackFocusedRow(target) {
|
|
606
|
+
if (!this.enableVirtualization) {
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
const index = target?.closest("swirl-table-row[data-index]")
|
|
610
|
+
?.dataset.index;
|
|
611
|
+
const focusedRowIndex = index === undefined ? undefined : Number(index);
|
|
612
|
+
if (focusedRowIndex !== this.focusedRowIndex) {
|
|
613
|
+
this.focusedRowIndex = focusedRowIndex;
|
|
614
|
+
this.updateVirtualizer();
|
|
615
|
+
}
|
|
616
|
+
}
|
|
492
617
|
render() {
|
|
493
618
|
const hasEmptyStateSlotAssignment = Boolean(this.el.querySelector('[slot="empty"]'));
|
|
494
619
|
const className = classNames("table", {
|
|
495
620
|
"table--show-empty-state": this.empty && !this.loading,
|
|
496
621
|
"table--keyboard-move": this.movingViaKeyboard,
|
|
497
622
|
});
|
|
498
|
-
return (h(Host, { key: '
|
|
623
|
+
return (h(Host, { key: '24e14d3eb739219aa9965fe16ccff5e9dae28180' }, h("div", { key: '25deaf84f1bb1131977e6e07f45ac2301585354d', class: className }, this.enableDragDrop && (h("swirl-visually-hidden", { key: '277292ebfaa8c1ada6c5c982b214efbda5f2f8a9' }, h("span", { key: 'e07ea9745ee40064160001ed0d702971cce78efa', "aria-live": "assertive" }, this.liveRegionText))), h("div", { key: 'f6919c9d48793c1abba7901b4365817ae7dfc5dc', 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: 'b7d1bb696755df6fd20983eebf6b800685a59983', "aria-describedby": Boolean(this.caption) ? "caption" : undefined, "aria-label": this.label, "aria-rowcount": this.enableVirtualization && this.virtualizationRowCount
|
|
624
|
+
? this.virtualizationRowCount + 1
|
|
625
|
+
: undefined, role: "table", class: "table__table" }, this.caption && (h("swirl-visually-hidden", { key: '013e2aff85772e44a3cdbb67dc4479d8eb581ffc' }, h("div", { key: '9f1b0dda1fe39b823e6df87dae2285e71a738265', id: "caption" }, this.caption))), h("div", { key: '9cd533c163bd42c8ebb4f641a91860170a2ca3e3', role: "rowgroup" }, h("div", { key: '0516399b0ed45a6f8e817fa9f342a188738fca0d', class: "table__header", "aria-rowindex": this.enableVirtualization ? 1 : undefined, ref: (el) => (this.headerEl = el), role: "row" }, h("slot", { key: '9924e00f3ac41423e4cf183ad3f0c993f9235d83', name: "columns" }))), h("div", { key: '0be013c95ef6910e4a27b388282403843cd520ea', class: "table__body", ref: (el) => (this.bodyEl = el) }, h("slot", { key: 'f5660dcec786b0091ec3cbe38407948173146147', name: "rows" }), h("div", { key: 'db077c06ab60df00e149468bb54f52ebeb40cd66', class: "table__empty-row", role: "row" }, h("div", { key: 'd7b514fe706e96437496ee4f7f5b2b0052943629', "aria-colspan": this.getColumns().length, class: "table__empty-row-cell", role: "cell" }, h("slot", { key: '8b1c1f506c3a5479def5c178856900103a05e1d6', name: "empty" }), !hasEmptyStateSlotAssignment && (h("swirl-text", { key: 'f94bccc0907f8052c63cebdfb7b99c8708d1ab76', align: "center", size: "sm" }, this.emptyStateLabel))))))))));
|
|
499
626
|
}
|
|
500
627
|
static get is() { return "swirl-table"; }
|
|
501
628
|
static get encapsulation() { return "scoped"; }
|
|
@@ -643,6 +770,102 @@ export class SwirlTable {
|
|
|
643
770
|
"setter": false,
|
|
644
771
|
"reflect": false,
|
|
645
772
|
"attribute": "loading"
|
|
773
|
+
},
|
|
774
|
+
"enableVirtualization": {
|
|
775
|
+
"type": "boolean",
|
|
776
|
+
"mutable": false,
|
|
777
|
+
"complexType": {
|
|
778
|
+
"original": "boolean",
|
|
779
|
+
"resolved": "boolean",
|
|
780
|
+
"references": {}
|
|
781
|
+
},
|
|
782
|
+
"required": false,
|
|
783
|
+
"optional": true,
|
|
784
|
+
"docs": {
|
|
785
|
+
"tags": [],
|
|
786
|
+
"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."
|
|
787
|
+
},
|
|
788
|
+
"getter": false,
|
|
789
|
+
"setter": false,
|
|
790
|
+
"reflect": false,
|
|
791
|
+
"attribute": "enable-virtualization"
|
|
792
|
+
},
|
|
793
|
+
"virtualizationRowCount": {
|
|
794
|
+
"type": "number",
|
|
795
|
+
"mutable": false,
|
|
796
|
+
"complexType": {
|
|
797
|
+
"original": "number",
|
|
798
|
+
"resolved": "number",
|
|
799
|
+
"references": {}
|
|
800
|
+
},
|
|
801
|
+
"required": false,
|
|
802
|
+
"optional": true,
|
|
803
|
+
"docs": {
|
|
804
|
+
"tags": [],
|
|
805
|
+
"text": "Total number of rows when virtualized."
|
|
806
|
+
},
|
|
807
|
+
"getter": false,
|
|
808
|
+
"setter": false,
|
|
809
|
+
"reflect": false,
|
|
810
|
+
"attribute": "virtualization-row-count"
|
|
811
|
+
},
|
|
812
|
+
"virtualizationEstimatedRowHeight": {
|
|
813
|
+
"type": "number",
|
|
814
|
+
"mutable": false,
|
|
815
|
+
"complexType": {
|
|
816
|
+
"original": "number",
|
|
817
|
+
"resolved": "number",
|
|
818
|
+
"references": {}
|
|
819
|
+
},
|
|
820
|
+
"required": false,
|
|
821
|
+
"optional": true,
|
|
822
|
+
"docs": {
|
|
823
|
+
"tags": [],
|
|
824
|
+
"text": "Height in px assumed for rows not drawn yet."
|
|
825
|
+
},
|
|
826
|
+
"getter": false,
|
|
827
|
+
"setter": false,
|
|
828
|
+
"reflect": false,
|
|
829
|
+
"attribute": "virtualization-estimated-row-height",
|
|
830
|
+
"defaultValue": "56"
|
|
831
|
+
},
|
|
832
|
+
"virtualizationOverscan": {
|
|
833
|
+
"type": "number",
|
|
834
|
+
"mutable": false,
|
|
835
|
+
"complexType": {
|
|
836
|
+
"original": "number",
|
|
837
|
+
"resolved": "number",
|
|
838
|
+
"references": {}
|
|
839
|
+
},
|
|
840
|
+
"required": false,
|
|
841
|
+
"optional": true,
|
|
842
|
+
"docs": {
|
|
843
|
+
"tags": [],
|
|
844
|
+
"text": "Number of extra rows drawn above and below the visible ones."
|
|
845
|
+
},
|
|
846
|
+
"getter": false,
|
|
847
|
+
"setter": false,
|
|
848
|
+
"reflect": false,
|
|
849
|
+
"attribute": "virtualization-overscan",
|
|
850
|
+
"defaultValue": "10"
|
|
851
|
+
},
|
|
852
|
+
"virtualizationKeepRowsRendered": {
|
|
853
|
+
"type": "unknown",
|
|
854
|
+
"mutable": false,
|
|
855
|
+
"complexType": {
|
|
856
|
+
"original": "number[]",
|
|
857
|
+
"resolved": "number[]",
|
|
858
|
+
"references": {}
|
|
859
|
+
},
|
|
860
|
+
"required": false,
|
|
861
|
+
"optional": true,
|
|
862
|
+
"docs": {
|
|
863
|
+
"tags": [],
|
|
864
|
+
"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."
|
|
865
|
+
},
|
|
866
|
+
"getter": false,
|
|
867
|
+
"setter": false,
|
|
868
|
+
"defaultValue": "[]"
|
|
646
869
|
}
|
|
647
870
|
};
|
|
648
871
|
}
|
|
@@ -677,6 +900,27 @@ export class SwirlTable {
|
|
|
677
900
|
}
|
|
678
901
|
}
|
|
679
902
|
}
|
|
903
|
+
}, {
|
|
904
|
+
"method": "virtualizationRowsChange",
|
|
905
|
+
"name": "virtualizationRowsChange",
|
|
906
|
+
"bubbles": true,
|
|
907
|
+
"cancelable": true,
|
|
908
|
+
"composed": true,
|
|
909
|
+
"docs": {
|
|
910
|
+
"tags": [],
|
|
911
|
+
"text": "Emits the indexes of the rows to render."
|
|
912
|
+
},
|
|
913
|
+
"complexType": {
|
|
914
|
+
"original": "SwirlTableVirtualizationRows",
|
|
915
|
+
"resolved": "{ indexes: number[]; }",
|
|
916
|
+
"references": {
|
|
917
|
+
"SwirlTableVirtualizationRows": {
|
|
918
|
+
"location": "local",
|
|
919
|
+
"path": "/home/runner/work/swirl/swirl/packages/swirl-components/src/components/swirl-table/swirl-table.tsx",
|
|
920
|
+
"id": "src/components/swirl-table/swirl-table.tsx::SwirlTableVirtualizationRows"
|
|
921
|
+
}
|
|
922
|
+
}
|
|
923
|
+
}
|
|
680
924
|
}];
|
|
681
925
|
}
|
|
682
926
|
static get methods() {
|
|
@@ -703,6 +947,21 @@ export class SwirlTable {
|
|
|
703
947
|
static get elementRef() { return "el"; }
|
|
704
948
|
static get watchers() {
|
|
705
949
|
return [{
|
|
950
|
+
"propName": "enableVirtualization",
|
|
951
|
+
"methodName": "handleVirtualizationChange"
|
|
952
|
+
}, {
|
|
953
|
+
"propName": "virtualizationRowCount",
|
|
954
|
+
"methodName": "handleVirtualizationChange"
|
|
955
|
+
}, {
|
|
956
|
+
"propName": "virtualizationEstimatedRowHeight",
|
|
957
|
+
"methodName": "handleVirtualizationChange"
|
|
958
|
+
}, {
|
|
959
|
+
"propName": "virtualizationOverscan",
|
|
960
|
+
"methodName": "handleVirtualizationChange"
|
|
961
|
+
}, {
|
|
962
|
+
"propName": "virtualizationKeepRowsRendered",
|
|
963
|
+
"methodName": "handleVirtualizationChange"
|
|
964
|
+
}, {
|
|
706
965
|
"propName": "enableDragDrop",
|
|
707
966
|
"methodName": "handleEnableDragDropChange"
|
|
708
967
|
}];
|
|
@@ -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;
|
package/dist/collection/utils.js
CHANGED
|
@@ -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{
|
|
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,
|
|
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
|