@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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var index$1 = require('./index-D-n4TKMG.js');
|
|
4
4
|
var index = require('./index-DcAhLZUH.js');
|
|
5
5
|
var sortable_esm = require('./sortable.esm-B1ZNencO.js');
|
|
6
|
-
var utils = require('./utils-
|
|
6
|
+
var utils = require('./utils-C4tLdXqU.js');
|
|
7
7
|
|
|
8
8
|
var dist;
|
|
9
9
|
var hasRequiredDist;
|
|
@@ -89,6 +89,2157 @@ function requireDist () {
|
|
|
89
89
|
var distExports = requireDist();
|
|
90
90
|
var debouncePromise = /*@__PURE__*/index.getDefaultExportFromCjs(distExports);
|
|
91
91
|
|
|
92
|
+
function getMeasurementKey(item) {
|
|
93
|
+
return typeof item === "object" ? item.key : item;
|
|
94
|
+
}
|
|
95
|
+
function createLazyMeasurementsView(cache, flat) {
|
|
96
|
+
const count = cache.length;
|
|
97
|
+
return new Proxy(cache, {
|
|
98
|
+
get(target, prop, receiver) {
|
|
99
|
+
if (typeof prop === "string") {
|
|
100
|
+
const c = prop.charCodeAt(0);
|
|
101
|
+
if (c >= 48 && c <= 57) {
|
|
102
|
+
const i = +prop;
|
|
103
|
+
if (Number.isInteger(i) && i >= 0 && i < count) {
|
|
104
|
+
let v = target[i];
|
|
105
|
+
if (typeof v !== "object") {
|
|
106
|
+
const s = flat[i * 2];
|
|
107
|
+
v = target[i] = {
|
|
108
|
+
index: i,
|
|
109
|
+
key: v,
|
|
110
|
+
start: s,
|
|
111
|
+
size: flat[i * 2 + 1],
|
|
112
|
+
end: s + flat[i * 2 + 1],
|
|
113
|
+
lane: 0
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return v;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (prop === "length") return count;
|
|
120
|
+
}
|
|
121
|
+
return Reflect.get(target, prop, receiver);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function memo(getDeps, fn, opts) {
|
|
127
|
+
let deps = opts.initialDeps ?? [];
|
|
128
|
+
let result;
|
|
129
|
+
let isInitial = true;
|
|
130
|
+
function memoizedFunction() {
|
|
131
|
+
const newDeps = getDeps();
|
|
132
|
+
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
|
|
133
|
+
if (!depsChanged) {
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
deps = newDeps;
|
|
137
|
+
result = fn(...newDeps);
|
|
138
|
+
if ((opts == null ? void 0 : opts.onChange) && !(isInitial && opts.skipInitialOnChange)) {
|
|
139
|
+
opts.onChange(result);
|
|
140
|
+
}
|
|
141
|
+
isInitial = false;
|
|
142
|
+
return result;
|
|
143
|
+
}
|
|
144
|
+
memoizedFunction.updateDeps = (newDeps) => {
|
|
145
|
+
deps = newDeps;
|
|
146
|
+
};
|
|
147
|
+
return memoizedFunction;
|
|
148
|
+
}
|
|
149
|
+
function notUndefined(value, msg) {
|
|
150
|
+
if (value === void 0) {
|
|
151
|
+
throw new Error(`Unexpected undefined${""}`);
|
|
152
|
+
} else {
|
|
153
|
+
return value;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
const approxEqual = (a, b) => Math.abs(a - b) < 1.01;
|
|
157
|
+
const debounce = (targetWindow, fn, ms) => {
|
|
158
|
+
let timeoutId;
|
|
159
|
+
return Object.assign(
|
|
160
|
+
function(...args) {
|
|
161
|
+
targetWindow.clearTimeout(timeoutId);
|
|
162
|
+
timeoutId = targetWindow.setTimeout(() => fn.apply(this, args), ms);
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
// The handle is closure-local, so a caller that has already
|
|
166
|
+
// unsubscribed has no way to stop a queued call. Teardown paths use
|
|
167
|
+
// this to drop the pending invocation instead of letting it land.
|
|
168
|
+
cancel: () => {
|
|
169
|
+
targetWindow.clearTimeout(timeoutId);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
function classifyScrollEvent({
|
|
176
|
+
offset,
|
|
177
|
+
isScrolling,
|
|
178
|
+
elementMax,
|
|
179
|
+
holdOffset,
|
|
180
|
+
scrollOffset,
|
|
181
|
+
pendingWrite,
|
|
182
|
+
clampedMaxAtWrite
|
|
183
|
+
}) {
|
|
184
|
+
var _a;
|
|
185
|
+
if (isScrolling && pendingWrite === null && offset === scrollOffset) {
|
|
186
|
+
return "spurious";
|
|
187
|
+
}
|
|
188
|
+
if (pendingWrite !== null && Math.abs(offset - pendingWrite.target) < 1.5) {
|
|
189
|
+
return "readBack";
|
|
190
|
+
}
|
|
191
|
+
if (pendingWrite !== null && !pendingWrite.smooth && elementMax !== null && pendingWrite.target > elementMax + holdOffset + 0.5 && Math.abs(offset - (elementMax + holdOffset)) < 1.5) {
|
|
192
|
+
return "clampedReadBack";
|
|
193
|
+
}
|
|
194
|
+
if (pendingWrite !== null && !pendingWrite.smooth && ((_a = pendingWrite.lowMaxes) == null ? void 0 : _a.some((max) => Math.abs(offset - max) < 1.5))) {
|
|
195
|
+
return "clampedReadBack";
|
|
196
|
+
}
|
|
197
|
+
if (clampedMaxAtWrite !== null && Math.abs(offset - clampedMaxAtWrite) < 1.5) {
|
|
198
|
+
return "clampedEcho";
|
|
199
|
+
}
|
|
200
|
+
return "external";
|
|
201
|
+
}
|
|
202
|
+
const isAnimating = (phase) => phase === "smooth" || phase === "smoothFinishing";
|
|
203
|
+
function externalRetiresCommand({
|
|
204
|
+
kind,
|
|
205
|
+
offset,
|
|
206
|
+
command,
|
|
207
|
+
target
|
|
208
|
+
}) {
|
|
209
|
+
return kind !== "spurious" && kind !== "readBack" && // Our own write, clamped (`clampedReadBack`, #1310): the command is not
|
|
210
|
+
// retired by it, and reconcile retargets below the new max.
|
|
211
|
+
kind !== "clampedReadBack" && (command == null ? void 0 : command.index) != null && // Nothing has been written for a command waiting for the tail; these
|
|
212
|
+
// are the fling's events.
|
|
213
|
+
command.phase !== "queued" && // A non-smooth write lands at once, so any other scroll event is the
|
|
214
|
+
// user's, even before reconcile saw the target reached (the target may
|
|
215
|
+
// keep moving, or iOS ignored the write under a finger). A write the
|
|
216
|
+
// browser clamped because the sizer hasn't grown yet reads back at the
|
|
217
|
+
// max, which is also where the fresh target clamps, so the check below
|
|
218
|
+
// keeps it reconciling (#1294). While a smooth scroll's animation may
|
|
219
|
+
// still report, its events look like a user's, so it yields only once it
|
|
220
|
+
// has landed.
|
|
221
|
+
!isAnimating(command.phase) && !approxEqual(offset, command.lastTargetOffset) && !approxEqual(offset, target()) && // A compensation write's clamped echo (#1258) keeps the command. The
|
|
222
|
+
// order is deliberate, not tidiness: this clause stays after `target()`
|
|
223
|
+
// (and `clampedReadBack` before it) because `target()` can rebuild the
|
|
224
|
+
// measurements, so it must run for exactly the events it always did.
|
|
225
|
+
kind !== "clampedEcho";
|
|
226
|
+
}
|
|
227
|
+
const FLING_WINDOW_MS = 40;
|
|
228
|
+
function flingSpedUp(samples) {
|
|
229
|
+
const last = samples[samples.length - 1];
|
|
230
|
+
if (last === void 0) return false;
|
|
231
|
+
let j = samples.length - 2;
|
|
232
|
+
while (j >= 0 && last.t - samples[j].t < FLING_WINDOW_MS) j--;
|
|
233
|
+
if (j < 0) return false;
|
|
234
|
+
const mid = samples[j];
|
|
235
|
+
let k = j - 1;
|
|
236
|
+
while (k >= 0 && mid.t - samples[k].t < FLING_WINDOW_MS) k--;
|
|
237
|
+
if (k < 0) return false;
|
|
238
|
+
const first = samples[k];
|
|
239
|
+
const recent = (last.offset - mid.offset) / (last.t - mid.t);
|
|
240
|
+
const before = (mid.offset - first.offset) / (mid.t - first.t);
|
|
241
|
+
return recent * before >= 0 && Math.abs(recent) >= 2 * Math.abs(before) && Math.abs(recent) - Math.abs(before) >= 0.8;
|
|
242
|
+
}
|
|
243
|
+
function flingCaught(samples) {
|
|
244
|
+
const last = samples[samples.length - 1];
|
|
245
|
+
if (last === void 0) return false;
|
|
246
|
+
let j = samples.length - 2;
|
|
247
|
+
while (j >= 0 && last.t - samples[j].t < FLING_WINDOW_MS) j--;
|
|
248
|
+
if (j < 0) return false;
|
|
249
|
+
const from = samples[j];
|
|
250
|
+
return Math.abs(last.offset - from.offset) / (last.t - from.t) >= 0.05;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
let _isIOSResult;
|
|
254
|
+
const isIOSWebKit = () => {
|
|
255
|
+
if (_isIOSResult !== void 0) return _isIOSResult;
|
|
256
|
+
if (typeof navigator === "undefined") return _isIOSResult = false;
|
|
257
|
+
if (/iP(hone|od|ad)/.test(navigator.userAgent)) return _isIOSResult = true;
|
|
258
|
+
const mtp = navigator.maxTouchPoints;
|
|
259
|
+
return _isIOSResult = navigator.platform === "MacIntel" && mtp !== void 0 && mtp > 0;
|
|
260
|
+
};
|
|
261
|
+
let _iosMomentumOverridesWritesResult;
|
|
262
|
+
const iosMomentumOverridesWrites = () => {
|
|
263
|
+
if (_iosMomentumOverridesWritesResult !== void 0) {
|
|
264
|
+
return _iosMomentumOverridesWritesResult;
|
|
265
|
+
}
|
|
266
|
+
return _iosMomentumOverridesWritesResult = isIOSWebKit() && typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("overflow-anchor: auto");
|
|
267
|
+
};
|
|
268
|
+
const momentumOverridesWrites = () => !isIOSWebKit() || iosMomentumOverridesWrites();
|
|
269
|
+
const touchListenerOptions = {
|
|
270
|
+
capture: true,
|
|
271
|
+
passive: true
|
|
272
|
+
};
|
|
273
|
+
class IosGesture {
|
|
274
|
+
constructor(host) {
|
|
275
|
+
this.host = host;
|
|
276
|
+
this._touch = null;
|
|
277
|
+
this.inMotion = () => this._touch !== null && this._touch.phase !== "lateFling";
|
|
278
|
+
this.dragging = () => {
|
|
279
|
+
var _a;
|
|
280
|
+
return ((_a = this._touch) == null ? void 0 : _a.phase) === "down" && this._touch.moved;
|
|
281
|
+
};
|
|
282
|
+
this.tail = () => {
|
|
283
|
+
var _a;
|
|
284
|
+
return ((_a = this._touch) == null ? void 0 : _a.phase) === "tail" ? this._touch.moved ? "fling" : "tap" : null;
|
|
285
|
+
};
|
|
286
|
+
this.onScroll = ({
|
|
287
|
+
isScrolling,
|
|
288
|
+
ownReadBack,
|
|
289
|
+
moved,
|
|
290
|
+
external
|
|
291
|
+
}) => {
|
|
292
|
+
var _a, _b, _c;
|
|
293
|
+
if (isScrolling && ((_a = this._touch) == null ? void 0 : _a.phase) === "tail") {
|
|
294
|
+
this._openTail(this._touch.moved || !ownReadBack, false);
|
|
295
|
+
} else if (((_b = this._touch) == null ? void 0 : _b.phase) === "lateFling") {
|
|
296
|
+
if (this.host.now() > this._touch.until) {
|
|
297
|
+
this._touch = null;
|
|
298
|
+
} else if (external && isScrolling && moved) {
|
|
299
|
+
this._openTail(true, false);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (!ownReadBack && isScrolling && moved && ((_c = this._touch) == null ? void 0 : _c.phase) === "down") {
|
|
303
|
+
this._touch.moved = true;
|
|
304
|
+
return true;
|
|
305
|
+
}
|
|
306
|
+
return false;
|
|
307
|
+
};
|
|
308
|
+
this.touchStart = () => {
|
|
309
|
+
this.end();
|
|
310
|
+
this._touch = { phase: "down", moved: false };
|
|
311
|
+
};
|
|
312
|
+
this.touchEnd = () => {
|
|
313
|
+
var _a;
|
|
314
|
+
const moved = ((_a = this._touch) == null ? void 0 : _a.phase) === "down" && this._touch.moved;
|
|
315
|
+
this.end();
|
|
316
|
+
this._openTail(moved, moved);
|
|
317
|
+
};
|
|
318
|
+
this.end = () => {
|
|
319
|
+
var _a;
|
|
320
|
+
const win = this.host.getWindow();
|
|
321
|
+
if (((_a = this._touch) == null ? void 0 : _a.phase) === "tail" && win != null) {
|
|
322
|
+
win.clearTimeout(this._touch.timerId);
|
|
323
|
+
}
|
|
324
|
+
this._touch = null;
|
|
325
|
+
};
|
|
326
|
+
this.listen = (target) => {
|
|
327
|
+
const onTouchStart = () => this.touchStart();
|
|
328
|
+
const onTouchEnd = () => this.touchEnd();
|
|
329
|
+
target.addEventListener("touchstart", onTouchStart, touchListenerOptions);
|
|
330
|
+
target.addEventListener("touchend", onTouchEnd, touchListenerOptions);
|
|
331
|
+
target.addEventListener("touchcancel", onTouchEnd, touchListenerOptions);
|
|
332
|
+
return () => {
|
|
333
|
+
target.removeEventListener(
|
|
334
|
+
"touchstart",
|
|
335
|
+
onTouchStart,
|
|
336
|
+
touchListenerOptions
|
|
337
|
+
);
|
|
338
|
+
target.removeEventListener("touchend", onTouchEnd, touchListenerOptions);
|
|
339
|
+
target.removeEventListener(
|
|
340
|
+
"touchcancel",
|
|
341
|
+
onTouchEnd,
|
|
342
|
+
touchListenerOptions
|
|
343
|
+
);
|
|
344
|
+
this.end();
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
this._openTail = (moved, awaitingFling) => {
|
|
348
|
+
const win = this.host.getWindow();
|
|
349
|
+
if (win == null) return;
|
|
350
|
+
this.end();
|
|
351
|
+
const tail = {
|
|
352
|
+
phase: "tail",
|
|
353
|
+
moved,
|
|
354
|
+
awaitingFling,
|
|
355
|
+
// Only fires while this tail is current: `end` clears it otherwise.
|
|
356
|
+
timerId: win.setTimeout(() => {
|
|
357
|
+
if (this.host.tailStillMoving()) {
|
|
358
|
+
this._openTail(tail.moved, tail.awaitingFling);
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
this._touch = tail.awaitingFling ? { phase: "lateFling", until: this.host.now() + 1e3 } : null;
|
|
362
|
+
this.host.onTailClosed();
|
|
363
|
+
}, 150)
|
|
364
|
+
};
|
|
365
|
+
this._touch = tail;
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
get touch() {
|
|
369
|
+
return this._touch;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const getRect = (element) => {
|
|
374
|
+
const { clientWidth, clientHeight } = element;
|
|
375
|
+
return { width: clientWidth, height: clientHeight };
|
|
376
|
+
};
|
|
377
|
+
const createFrameQueue = (targetWindow) => {
|
|
378
|
+
const ids = /* @__PURE__ */ new Set();
|
|
379
|
+
return {
|
|
380
|
+
schedule: (fn) => {
|
|
381
|
+
const id = targetWindow.requestAnimationFrame(() => {
|
|
382
|
+
ids.delete(id);
|
|
383
|
+
fn();
|
|
384
|
+
});
|
|
385
|
+
ids.add(id);
|
|
386
|
+
},
|
|
387
|
+
cancel: () => {
|
|
388
|
+
ids.forEach((id) => targetWindow.cancelAnimationFrame(id));
|
|
389
|
+
ids.clear();
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
};
|
|
393
|
+
const defaultKeyExtractor = (index) => index;
|
|
394
|
+
const defaultRangeExtractor = (range) => {
|
|
395
|
+
const overscan = range.overscan * Math.max(range.lanes ?? 1, 1);
|
|
396
|
+
const start = Math.max(range.startIndex - overscan, 0);
|
|
397
|
+
const end = Math.min(range.endIndex + overscan, range.count - 1);
|
|
398
|
+
const len = end - start + 1;
|
|
399
|
+
const arr = new Array(len);
|
|
400
|
+
for (let i = 0; i < len; i++) {
|
|
401
|
+
arr[i] = start + i;
|
|
402
|
+
}
|
|
403
|
+
return arr;
|
|
404
|
+
};
|
|
405
|
+
const observeElementRect = (instance, cb) => {
|
|
406
|
+
const element = instance.scrollElement;
|
|
407
|
+
if (!element) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const targetWindow = instance.targetWindow;
|
|
411
|
+
if (!targetWindow) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
const handler = (rect) => {
|
|
415
|
+
const { width, height } = rect;
|
|
416
|
+
cb({ width: Math.round(width), height: Math.round(height) });
|
|
417
|
+
};
|
|
418
|
+
handler(getRect(element));
|
|
419
|
+
if (!targetWindow.ResizeObserver) {
|
|
420
|
+
return () => {
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
const frames = createFrameQueue(targetWindow);
|
|
424
|
+
const observer = new targetWindow.ResizeObserver(() => {
|
|
425
|
+
const run = () => {
|
|
426
|
+
handler(getRect(element));
|
|
427
|
+
};
|
|
428
|
+
instance.options.useAnimationFrameWithResizeObserver ? frames.schedule(run) : run();
|
|
429
|
+
});
|
|
430
|
+
observer.observe(element, { box: "content-box" });
|
|
431
|
+
return () => {
|
|
432
|
+
observer.unobserve(element);
|
|
433
|
+
frames.cancel();
|
|
434
|
+
};
|
|
435
|
+
};
|
|
436
|
+
const addEventListenerOptions = {
|
|
437
|
+
passive: true
|
|
438
|
+
};
|
|
439
|
+
const observeWindowRect = (instance, cb) => {
|
|
440
|
+
const element = instance.scrollElement;
|
|
441
|
+
if (!element) {
|
|
442
|
+
return;
|
|
443
|
+
}
|
|
444
|
+
const handler = () => {
|
|
445
|
+
cb({ width: element.innerWidth, height: element.innerHeight });
|
|
446
|
+
};
|
|
447
|
+
handler();
|
|
448
|
+
element.addEventListener("resize", handler, addEventListenerOptions);
|
|
449
|
+
return () => {
|
|
450
|
+
element.removeEventListener("resize", handler);
|
|
451
|
+
};
|
|
452
|
+
};
|
|
453
|
+
const supportsScrollend = typeof window == "undefined" ? true : "onscrollend" in window;
|
|
454
|
+
const observeOffset = (instance, cb, readOffset) => {
|
|
455
|
+
const element = instance.scrollElement;
|
|
456
|
+
if (!element) {
|
|
457
|
+
return;
|
|
458
|
+
}
|
|
459
|
+
const targetWindow = instance.targetWindow;
|
|
460
|
+
if (!targetWindow) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
const registerScrollendEvent = instance.options.useScrollendEvent && supportsScrollend;
|
|
464
|
+
let offset = 0;
|
|
465
|
+
const fallback = registerScrollendEvent ? null : debounce(
|
|
466
|
+
targetWindow,
|
|
467
|
+
() => cb(readOffset(element), false),
|
|
468
|
+
instance.options.isScrollingResetDelay
|
|
469
|
+
);
|
|
470
|
+
const createHandler = (isScrolling) => () => {
|
|
471
|
+
offset = readOffset(element);
|
|
472
|
+
fallback == null ? void 0 : fallback();
|
|
473
|
+
cb(offset, isScrolling);
|
|
474
|
+
};
|
|
475
|
+
const handler = createHandler(true);
|
|
476
|
+
const endHandler = createHandler(false);
|
|
477
|
+
element.addEventListener("scroll", handler, addEventListenerOptions);
|
|
478
|
+
if (registerScrollendEvent) {
|
|
479
|
+
element.addEventListener("scrollend", endHandler, addEventListenerOptions);
|
|
480
|
+
}
|
|
481
|
+
return () => {
|
|
482
|
+
element.removeEventListener("scroll", handler);
|
|
483
|
+
if (registerScrollendEvent) {
|
|
484
|
+
element.removeEventListener("scrollend", endHandler);
|
|
485
|
+
}
|
|
486
|
+
fallback == null ? void 0 : fallback.cancel();
|
|
487
|
+
};
|
|
488
|
+
};
|
|
489
|
+
const observeElementOffset = (instance, cb) => observeOffset(instance, cb, (el) => {
|
|
490
|
+
const { horizontal, isRtl } = instance.options;
|
|
491
|
+
return horizontal ? el.scrollLeft * (isRtl && -1 || 1) : el.scrollTop;
|
|
492
|
+
});
|
|
493
|
+
const observeWindowOffset = (instance, cb) => observeOffset(
|
|
494
|
+
instance,
|
|
495
|
+
cb,
|
|
496
|
+
(win) => instance.options.horizontal ? win.scrollX : win.scrollY
|
|
497
|
+
);
|
|
498
|
+
const measureElement = (element, entry, instance) => {
|
|
499
|
+
if (instance.options.useCachedMeasurements) {
|
|
500
|
+
const index = instance.indexFromElement(element);
|
|
501
|
+
const key = instance.options.getItemKey(index);
|
|
502
|
+
return instance.itemSizeCache.get(key) ?? instance.options.estimateSize(index);
|
|
503
|
+
}
|
|
504
|
+
if (entry == null ? void 0 : entry.borderBoxSize) {
|
|
505
|
+
const box = entry.borderBoxSize[0];
|
|
506
|
+
if (box) {
|
|
507
|
+
const size = Math.round(
|
|
508
|
+
box[instance.options.horizontal ? "inlineSize" : "blockSize"]
|
|
509
|
+
);
|
|
510
|
+
return size;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
if (!entry) {
|
|
514
|
+
const index = instance.indexFromElement(element);
|
|
515
|
+
const key = instance.options.getItemKey(index);
|
|
516
|
+
const cachedSize = instance.itemSizeCache.get(key);
|
|
517
|
+
if (cachedSize !== void 0) {
|
|
518
|
+
return cachedSize;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
return element[instance.options.horizontal ? "offsetWidth" : "offsetHeight"];
|
|
522
|
+
};
|
|
523
|
+
const scrollWithAdjustments = (offset, {
|
|
524
|
+
adjustments = 0,
|
|
525
|
+
behavior
|
|
526
|
+
}, instance) => {
|
|
527
|
+
var _a, _b;
|
|
528
|
+
(_b = (_a = instance.scrollElement) == null ? void 0 : _a.scrollTo) == null ? void 0 : _b.call(_a, {
|
|
529
|
+
[instance.options.horizontal ? "left" : "top"]: offset + adjustments,
|
|
530
|
+
behavior
|
|
531
|
+
});
|
|
532
|
+
};
|
|
533
|
+
const windowScroll = scrollWithAdjustments;
|
|
534
|
+
const elementScroll = scrollWithAdjustments;
|
|
535
|
+
const initialScrollPhase = (behavior, atTarget) => behavior === "smooth" ? atTarget ? "smoothLanded" : "smooth" : "instant";
|
|
536
|
+
const isSmoothScroll = (state) => (state == null ? void 0 : state.phase) === "smooth" || (state == null ? void 0 : state.phase) === "smoothLanded";
|
|
537
|
+
function isAppendWithTrim(prevCount, nextCount, getPreviousKey, getNextKey) {
|
|
538
|
+
if (nextCount === 0) return false;
|
|
539
|
+
const firstKey = getNextKey(0);
|
|
540
|
+
const removedKeys = /* @__PURE__ */ new Set();
|
|
541
|
+
let removedCount = 0;
|
|
542
|
+
while (removedCount < prevCount) {
|
|
543
|
+
const key = getPreviousKey(removedCount);
|
|
544
|
+
if (key === firstKey) break;
|
|
545
|
+
removedKeys.add(key);
|
|
546
|
+
removedCount++;
|
|
547
|
+
}
|
|
548
|
+
const retainedCount = prevCount - removedCount;
|
|
549
|
+
if (retainedCount === 0 || retainedCount >= nextCount) return false;
|
|
550
|
+
for (let i = 0; i < retainedCount; i++) {
|
|
551
|
+
if (getNextKey(i) !== getPreviousKey(removedCount + i)) return false;
|
|
552
|
+
}
|
|
553
|
+
for (let i = retainedCount; i < nextCount; i++) {
|
|
554
|
+
if (removedKeys.has(getNextKey(i))) return false;
|
|
555
|
+
}
|
|
556
|
+
return true;
|
|
557
|
+
}
|
|
558
|
+
class Virtualizer {
|
|
559
|
+
constructor(opts) {
|
|
560
|
+
this.unsubs = [];
|
|
561
|
+
this.scrollElement = null;
|
|
562
|
+
this.targetWindow = null;
|
|
563
|
+
this.isScrolling = false;
|
|
564
|
+
this.scrollState = null;
|
|
565
|
+
this.measurementsCache = [];
|
|
566
|
+
this._singleLaneMeasurements = null;
|
|
567
|
+
this.itemSizeCache = /* @__PURE__ */ new Map();
|
|
568
|
+
this.itemSizeCacheVersion = 0;
|
|
569
|
+
this.laneAssignments = /* @__PURE__ */ new Map();
|
|
570
|
+
this.pendingMin = null;
|
|
571
|
+
this.prevLanes = void 0;
|
|
572
|
+
this.lanesChangedFlag = false;
|
|
573
|
+
this.lanesSettling = false;
|
|
574
|
+
this.pendingScrollAnchor = null;
|
|
575
|
+
this.scrollRect = null;
|
|
576
|
+
this.scrollOffset = null;
|
|
577
|
+
this.scrollDirection = null;
|
|
578
|
+
this._holdOffset = 0;
|
|
579
|
+
this._reportedOverscroll = false;
|
|
580
|
+
this._iosGesture = new IosGesture({
|
|
581
|
+
getWindow: () => this.targetWindow,
|
|
582
|
+
now: () => this.now(),
|
|
583
|
+
// The end of a fling can move less than a pixel per scroll event, so
|
|
584
|
+
// events can stop for 150ms while the fling is still running (seen on
|
|
585
|
+
// an iPhone, 27.0.1). A command waiting for it would then be written
|
|
586
|
+
// into the fling and overridden. The element having moved since the
|
|
587
|
+
// last event means it has not ended: wait again. Not while our own
|
|
588
|
+
// write has yet to report: that moved it.
|
|
589
|
+
tailStillMoving: () => {
|
|
590
|
+
const state = this.scrollState;
|
|
591
|
+
if ((state == null ? void 0 : state.phase) !== "queued" || this.pendingWrite !== null) {
|
|
592
|
+
return false;
|
|
593
|
+
}
|
|
594
|
+
const now = this._readElementOffset();
|
|
595
|
+
if (now === null || this._lastElementOffset === null || Math.abs(now - this._lastElementOffset) < 1) {
|
|
596
|
+
return false;
|
|
597
|
+
}
|
|
598
|
+
this._lastElementOffset = now;
|
|
599
|
+
state.samples = [...state.samples ?? [], { t: this.now(), offset: now }];
|
|
600
|
+
return true;
|
|
601
|
+
},
|
|
602
|
+
onTailClosed: () => {
|
|
603
|
+
const state = this.scrollState;
|
|
604
|
+
if ((state == null ? void 0 : state.phase) === "queued" && flingCaught(state.samples ?? [])) {
|
|
605
|
+
this.scrollState = null;
|
|
606
|
+
}
|
|
607
|
+
this._flushHoldIfReady(true);
|
|
608
|
+
this._writeAwaitingCommand();
|
|
609
|
+
this._retryClampedAdjustment();
|
|
610
|
+
}
|
|
611
|
+
});
|
|
612
|
+
this._lastElementOffset = null;
|
|
613
|
+
this.pendingWrite = null;
|
|
614
|
+
this._clampedAdjustment = null;
|
|
615
|
+
this.elementsCache = /* @__PURE__ */ new Map();
|
|
616
|
+
this._resizeBatch = null;
|
|
617
|
+
this.now = () => {
|
|
618
|
+
var _a, _b, _c;
|
|
619
|
+
return ((_c = (_b = (_a = this.targetWindow) == null ? void 0 : _a.performance) == null ? void 0 : _b.now) == null ? void 0 : _c.call(_b)) ?? Date.now();
|
|
620
|
+
};
|
|
621
|
+
this.observer = /* @__PURE__ */ (() => {
|
|
622
|
+
let _ro = null;
|
|
623
|
+
let _frames = null;
|
|
624
|
+
let delivering = false;
|
|
625
|
+
let observeQueued = false;
|
|
626
|
+
const pendingObservations = /* @__PURE__ */ new Set();
|
|
627
|
+
const get = () => {
|
|
628
|
+
if (_ro) {
|
|
629
|
+
return _ro;
|
|
630
|
+
}
|
|
631
|
+
const targetWindow = this.targetWindow;
|
|
632
|
+
if (!targetWindow || !targetWindow.ResizeObserver) {
|
|
633
|
+
return null;
|
|
634
|
+
}
|
|
635
|
+
const frames = _frames = createFrameQueue(targetWindow);
|
|
636
|
+
return _ro = new targetWindow.ResizeObserver((entries) => {
|
|
637
|
+
const run = () => {
|
|
638
|
+
const batch = { sync: false };
|
|
639
|
+
this._resizeBatch = batch;
|
|
640
|
+
try {
|
|
641
|
+
entries.forEach(measureEntry);
|
|
642
|
+
} finally {
|
|
643
|
+
this._resizeBatch = null;
|
|
644
|
+
if (batch.notify) {
|
|
645
|
+
this.notify(batch.sync);
|
|
646
|
+
this._noteClampMax();
|
|
647
|
+
this._flushHoldIfReady(true);
|
|
648
|
+
this._retryClampedAdjustment();
|
|
649
|
+
this.measureElement(null);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
};
|
|
653
|
+
if (this.options.useAnimationFrameWithResizeObserver) {
|
|
654
|
+
frames.schedule(run);
|
|
655
|
+
} else {
|
|
656
|
+
delivering = true;
|
|
657
|
+
try {
|
|
658
|
+
run();
|
|
659
|
+
} finally {
|
|
660
|
+
delivering = false;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
};
|
|
665
|
+
const measureEntry = (entry) => {
|
|
666
|
+
const node = entry.target;
|
|
667
|
+
const index = this.indexFromElement(node);
|
|
668
|
+
if (!node.isConnected) {
|
|
669
|
+
this.observer.unobserve(node);
|
|
670
|
+
for (const [cacheKey, cachedNode] of this.elementsCache) {
|
|
671
|
+
if (cachedNode === node) {
|
|
672
|
+
this.elementsCache.delete(cacheKey);
|
|
673
|
+
break;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
return;
|
|
677
|
+
}
|
|
678
|
+
if (!this.isIndexInRange(index)) return;
|
|
679
|
+
if (this.shouldMeasureDuringScroll(index)) {
|
|
680
|
+
this.resizeItem(index, this.options.measureElement(node, entry, this));
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
return {
|
|
684
|
+
disconnect: () => {
|
|
685
|
+
var _a;
|
|
686
|
+
(_a = get()) == null ? void 0 : _a.disconnect();
|
|
687
|
+
_frames == null ? void 0 : _frames.cancel();
|
|
688
|
+
pendingObservations.clear();
|
|
689
|
+
observeQueued = false;
|
|
690
|
+
_ro = null;
|
|
691
|
+
_frames = null;
|
|
692
|
+
},
|
|
693
|
+
observe: (target) => {
|
|
694
|
+
const observer = get();
|
|
695
|
+
if (!observer) return;
|
|
696
|
+
if (!delivering) {
|
|
697
|
+
observer.observe(target, { box: "border-box" });
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
pendingObservations.add(target);
|
|
701
|
+
if (!observeQueued) {
|
|
702
|
+
observeQueued = true;
|
|
703
|
+
_frames == null ? void 0 : _frames.schedule(() => {
|
|
704
|
+
observeQueued = false;
|
|
705
|
+
pendingObservations.forEach((node) => {
|
|
706
|
+
if (node.isConnected) _ro == null ? void 0 : _ro.observe(node, { box: "border-box" });
|
|
707
|
+
});
|
|
708
|
+
pendingObservations.clear();
|
|
709
|
+
});
|
|
710
|
+
}
|
|
711
|
+
},
|
|
712
|
+
unobserve: (target) => {
|
|
713
|
+
var _a;
|
|
714
|
+
pendingObservations.delete(target);
|
|
715
|
+
(_a = get()) == null ? void 0 : _a.unobserve(target);
|
|
716
|
+
}
|
|
717
|
+
};
|
|
718
|
+
})();
|
|
719
|
+
this.range = null;
|
|
720
|
+
this.setOptions = (opts2) => {
|
|
721
|
+
var _a;
|
|
722
|
+
const merged = {
|
|
723
|
+
debug: false,
|
|
724
|
+
initialOffset: 0,
|
|
725
|
+
overscan: 1,
|
|
726
|
+
paddingStart: 0,
|
|
727
|
+
paddingEnd: 0,
|
|
728
|
+
scrollPaddingStart: 0,
|
|
729
|
+
scrollPaddingEnd: 0,
|
|
730
|
+
horizontal: false,
|
|
731
|
+
getItemKey: defaultKeyExtractor,
|
|
732
|
+
rangeExtractor: defaultRangeExtractor,
|
|
733
|
+
onChange: () => {
|
|
734
|
+
},
|
|
735
|
+
measureElement,
|
|
736
|
+
initialRect: { width: 0, height: 0 },
|
|
737
|
+
scrollMargin: 0,
|
|
738
|
+
gap: 0,
|
|
739
|
+
indexAttribute: "data-index",
|
|
740
|
+
initialMeasurementsCache: [],
|
|
741
|
+
lanes: 1,
|
|
742
|
+
anchorTo: "start",
|
|
743
|
+
followOnAppend: false,
|
|
744
|
+
scrollEndThreshold: 1,
|
|
745
|
+
isScrollingResetDelay: 150,
|
|
746
|
+
enabled: true,
|
|
747
|
+
isRtl: false,
|
|
748
|
+
useScrollendEvent: false,
|
|
749
|
+
useAnimationFrameWithResizeObserver: false,
|
|
750
|
+
laneAssignmentMode: "estimate",
|
|
751
|
+
useCachedMeasurements: false
|
|
752
|
+
};
|
|
753
|
+
for (const key in opts2) {
|
|
754
|
+
const v = opts2[key];
|
|
755
|
+
if (v !== void 0) merged[key] = v;
|
|
756
|
+
}
|
|
757
|
+
const prevOptions = this.options;
|
|
758
|
+
let anchor = null;
|
|
759
|
+
let followOnAppend = null;
|
|
760
|
+
let edgeKeysChanged = false;
|
|
761
|
+
if (prevOptions !== void 0 && prevOptions.enabled && merged.enabled && merged.anchorTo === "end" && this.scrollElement !== null) {
|
|
762
|
+
const prevCount = prevOptions.count;
|
|
763
|
+
const nextCount = merged.count;
|
|
764
|
+
const measurements = this.getMeasurements();
|
|
765
|
+
const previousItems = ((_a = this._singleLaneMeasurements) == null ? void 0 : _a.items) ?? measurements;
|
|
766
|
+
const getPreviousKey = (index) => getMeasurementKey(previousItems[index]);
|
|
767
|
+
const prevFirstKey = prevCount > 0 ? getPreviousKey(0) : null;
|
|
768
|
+
const prevLastKey = prevCount > 0 ? getPreviousKey(prevCount - 1) : null;
|
|
769
|
+
const didCountChange = nextCount !== prevCount;
|
|
770
|
+
const didEdgeKeysChange = didCountChange || prevCount > 0 && nextCount > 0 && (merged.getItemKey(0) !== prevFirstKey || merged.getItemKey(nextCount - 1) !== prevLastKey);
|
|
771
|
+
if (didEdgeKeysChange) {
|
|
772
|
+
edgeKeysChanged = true;
|
|
773
|
+
const item = prevCount > 0 ? this.getVirtualItemForOffset(this.getScrollOffset()) ?? measurements[0] : null;
|
|
774
|
+
if (item) {
|
|
775
|
+
anchor = [item.key, this.getScrollOffset() - item.start];
|
|
776
|
+
}
|
|
777
|
+
const behavior = merged.followOnAppend === true ? "auto" : merged.followOnAppend || null;
|
|
778
|
+
if (behavior && nextCount > 0 && this.isAtEnd(prevOptions.scrollEndThreshold) && (prevCount === 0 || merged.getItemKey(nextCount - 1) !== prevLastKey)) {
|
|
779
|
+
if (nextCount > prevCount || isAppendWithTrim(
|
|
780
|
+
prevCount,
|
|
781
|
+
nextCount,
|
|
782
|
+
getPreviousKey,
|
|
783
|
+
merged.getItemKey
|
|
784
|
+
)) {
|
|
785
|
+
followOnAppend = behavior;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
this.options = merged;
|
|
791
|
+
if (edgeKeysChanged) {
|
|
792
|
+
this.pendingMin = 0;
|
|
793
|
+
this.itemSizeCacheVersion++;
|
|
794
|
+
}
|
|
795
|
+
let anchorDelta = null;
|
|
796
|
+
if (anchor && this.scrollOffset !== null && !this._awaitingCommandReadBack()) {
|
|
797
|
+
const [anchorKey, anchorOffset] = anchor;
|
|
798
|
+
const newMeasurements = this.getMeasurements();
|
|
799
|
+
const { count, getItemKey } = this.options;
|
|
800
|
+
let idx = 0;
|
|
801
|
+
while (idx < count && getItemKey(idx) !== anchorKey) {
|
|
802
|
+
idx++;
|
|
803
|
+
}
|
|
804
|
+
if (idx < count) {
|
|
805
|
+
const anchorItem = newMeasurements[idx];
|
|
806
|
+
if (anchorItem) {
|
|
807
|
+
const newOffset = Math.max(0, anchorItem.start + anchorOffset);
|
|
808
|
+
if (!followOnAppend && newOffset !== this.scrollOffset) {
|
|
809
|
+
anchorDelta = newOffset - this.scrollOffset;
|
|
810
|
+
this.scrollOffset = newOffset;
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
if (followOnAppend) {
|
|
816
|
+
this.pendingScrollAnchor = { kind: "follow", behavior: followOnAppend };
|
|
817
|
+
} else if (anchorDelta !== null) {
|
|
818
|
+
if (this._canWriteScroll()) {
|
|
819
|
+
this.pendingScrollAnchor = { kind: "anchor", delta: anchorDelta };
|
|
820
|
+
} else {
|
|
821
|
+
this._holdOffset += anchorDelta;
|
|
822
|
+
this._followOffsetTarget(anchorDelta);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
this.notify = (sync) => {
|
|
827
|
+
var _a, _b;
|
|
828
|
+
(_b = (_a = this.options).onChange) == null ? void 0 : _b.call(_a, this, sync);
|
|
829
|
+
};
|
|
830
|
+
this.maybeNotify = memo(
|
|
831
|
+
() => {
|
|
832
|
+
this.calculateRange();
|
|
833
|
+
return [
|
|
834
|
+
this.isScrolling,
|
|
835
|
+
this.range ? this.range.startIndex : null,
|
|
836
|
+
this.range ? this.range.endIndex : null
|
|
837
|
+
];
|
|
838
|
+
},
|
|
839
|
+
(isScrolling) => {
|
|
840
|
+
this.notify(isScrolling);
|
|
841
|
+
},
|
|
842
|
+
{
|
|
843
|
+
key: "production" !== "production",
|
|
844
|
+
debug: () => this.options.debug,
|
|
845
|
+
initialDeps: [
|
|
846
|
+
this.isScrolling,
|
|
847
|
+
this.range ? this.range.startIndex : null,
|
|
848
|
+
this.range ? this.range.endIndex : null
|
|
849
|
+
]
|
|
850
|
+
}
|
|
851
|
+
);
|
|
852
|
+
this.cleanup = () => {
|
|
853
|
+
var _a;
|
|
854
|
+
this.unsubs.filter(Boolean).forEach((d) => d());
|
|
855
|
+
this.unsubs = [];
|
|
856
|
+
this.observer.disconnect();
|
|
857
|
+
if (this.rafId != null && this.targetWindow) {
|
|
858
|
+
this.targetWindow.cancelAnimationFrame(this.rafId);
|
|
859
|
+
this.rafId = null;
|
|
860
|
+
}
|
|
861
|
+
this.scrollState = null;
|
|
862
|
+
(_a = this._momentumStop) == null ? void 0 : _a.restore();
|
|
863
|
+
this._momentumStop = null;
|
|
864
|
+
this.isScrolling = false;
|
|
865
|
+
this.scrollDirection = null;
|
|
866
|
+
this._holdOffset = 0;
|
|
867
|
+
this._reportedOverscroll = false;
|
|
868
|
+
this._clampedAdjustment = null;
|
|
869
|
+
this.pendingWrite = null;
|
|
870
|
+
this.scrollElement = null;
|
|
871
|
+
this.targetWindow = null;
|
|
872
|
+
};
|
|
873
|
+
this._didMount = () => {
|
|
874
|
+
return () => {
|
|
875
|
+
this.cleanup();
|
|
876
|
+
};
|
|
877
|
+
};
|
|
878
|
+
this._willUpdate = () => {
|
|
879
|
+
var _a;
|
|
880
|
+
const scrollElement = this.options.enabled ? this.options.getScrollElement() : null;
|
|
881
|
+
if (this.scrollElement !== scrollElement) {
|
|
882
|
+
this.cleanup();
|
|
883
|
+
if (!scrollElement) {
|
|
884
|
+
this.maybeNotify();
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
this.scrollElement = scrollElement;
|
|
888
|
+
if (this.scrollElement && "ownerDocument" in this.scrollElement) {
|
|
889
|
+
this.targetWindow = this.scrollElement.ownerDocument.defaultView;
|
|
890
|
+
} else {
|
|
891
|
+
this.targetWindow = ((_a = this.scrollElement) == null ? void 0 : _a.window) ?? null;
|
|
892
|
+
}
|
|
893
|
+
this.elementsCache.forEach((cached) => {
|
|
894
|
+
this.observer.observe(cached);
|
|
895
|
+
});
|
|
896
|
+
this.unsubs.push(
|
|
897
|
+
this.options.observeElementRect(this, (rect) => {
|
|
898
|
+
this.scrollRect = rect;
|
|
899
|
+
this.maybeNotify();
|
|
900
|
+
})
|
|
901
|
+
);
|
|
902
|
+
this.unsubs.push(
|
|
903
|
+
this.options.observeElementOffset(this, (offset, isScrolling) => {
|
|
904
|
+
var _a2, _b, _c, _d;
|
|
905
|
+
const elementMax = isScrolling ? this._elementMaxScrollOffset() : null;
|
|
906
|
+
const wasOverscrolled = this._reportedOverscroll;
|
|
907
|
+
this._reportedOverscroll = offset < 0 || elementMax !== null && offset > elementMax + 1;
|
|
908
|
+
const elementOffset = offset;
|
|
909
|
+
this._lastElementOffset = elementOffset;
|
|
910
|
+
offset = this._toLayoutOffset(offset);
|
|
911
|
+
const kind = this._classifyScrollEvent(
|
|
912
|
+
offset,
|
|
913
|
+
isScrolling,
|
|
914
|
+
elementMax
|
|
915
|
+
);
|
|
916
|
+
if (kind === "spurious") return;
|
|
917
|
+
if (kind === "readBack") {
|
|
918
|
+
offset = this.pendingWrite.target;
|
|
919
|
+
} else if (kind === "clampedReadBack" && ((_a2 = this.scrollState) == null ? void 0 : _a2.index) != null && // Not `elementMax`: an adapter can report the read-back at rest.
|
|
920
|
+
offset < this.getMaxScrollOffset() - 1.5) {
|
|
921
|
+
this.scrollState.lastTargetOffset = offset;
|
|
922
|
+
} else if (externalRetiresCommand({
|
|
923
|
+
kind,
|
|
924
|
+
offset,
|
|
925
|
+
command: this.scrollState,
|
|
926
|
+
target: () => this.getScrollStateTarget(this.scrollState)
|
|
927
|
+
})) {
|
|
928
|
+
this.scrollState = null;
|
|
929
|
+
}
|
|
930
|
+
this.pendingWrite = null;
|
|
931
|
+
if (this._clampedAdjustment !== null && Math.abs(offset - this._clampedAdjustment.maxAtWrite) >= 1.5) {
|
|
932
|
+
this._clampedAdjustment = null;
|
|
933
|
+
}
|
|
934
|
+
const prevOffset = this.getScrollOffset();
|
|
935
|
+
const prevDirection = this.scrollDirection;
|
|
936
|
+
this.scrollDirection = isScrolling ? prevOffset === offset ? this.scrollDirection : prevOffset < offset ? "forward" : "backward" : null;
|
|
937
|
+
this.scrollOffset = offset;
|
|
938
|
+
this.isScrolling = isScrolling;
|
|
939
|
+
const queued = this.scrollState;
|
|
940
|
+
if ((queued == null ? void 0 : queued.phase) === "queued" && kind === "external" && isScrolling) {
|
|
941
|
+
if (wasOverscrolled || this._reportedOverscroll) {
|
|
942
|
+
queued.samples = [];
|
|
943
|
+
} else {
|
|
944
|
+
const t = this.now();
|
|
945
|
+
queued.samples = [
|
|
946
|
+
...(queued.samples ?? []).filter(
|
|
947
|
+
(sample) => t - sample.t <= 200
|
|
948
|
+
),
|
|
949
|
+
{ t, offset: elementOffset }
|
|
950
|
+
];
|
|
951
|
+
if (prevDirection !== null && this.scrollDirection !== prevDirection || flingSpedUp(queued.samples)) {
|
|
952
|
+
this.scrollState = null;
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
if (this._iosGesture.onScroll({
|
|
957
|
+
isScrolling,
|
|
958
|
+
ownReadBack: kind === "readBack",
|
|
959
|
+
moved: offset !== prevOffset,
|
|
960
|
+
// Neither our write's read-back nor a frame of our smooth
|
|
961
|
+
// animation: the user or a fling moved it.
|
|
962
|
+
external: kind === "external" && ((_b = this.scrollState) == null ? void 0 : _b.phase) !== "smooth" && ((_c = this.scrollState) == null ? void 0 : _c.phase) !== "smoothFinishing"
|
|
963
|
+
}) && // The user scrolls: a command still waiting for the tail is
|
|
964
|
+
// theirs to override, like a written one would be.
|
|
965
|
+
((_d = this.scrollState) == null ? void 0 : _d.phase) === "queued") {
|
|
966
|
+
this.scrollState = null;
|
|
967
|
+
}
|
|
968
|
+
this._flushHoldIfReady(true);
|
|
969
|
+
if (this.scrollState) {
|
|
970
|
+
this.scheduleScrollReconcile();
|
|
971
|
+
}
|
|
972
|
+
this.maybeNotify();
|
|
973
|
+
})
|
|
974
|
+
);
|
|
975
|
+
if ("addEventListener" in this.scrollElement) {
|
|
976
|
+
this.unsubs.push(
|
|
977
|
+
this._iosGesture.listen(this.scrollElement)
|
|
978
|
+
);
|
|
979
|
+
}
|
|
980
|
+
this._scrollToOffset(this.getScrollOffset());
|
|
981
|
+
}
|
|
982
|
+
this._noteClampMax();
|
|
983
|
+
const anchor = this.pendingScrollAnchor;
|
|
984
|
+
this.pendingScrollAnchor = null;
|
|
985
|
+
if (anchor && this.scrollElement && this.options.enabled) {
|
|
986
|
+
if (anchor.kind === "anchor") {
|
|
987
|
+
if (!this._canWriteScroll()) {
|
|
988
|
+
this._holdOffset += anchor.delta;
|
|
989
|
+
this._followOffsetTarget(anchor.delta);
|
|
990
|
+
this.notify(false);
|
|
991
|
+
} else if (isSmoothScroll(this.scrollState) && !approxEqual(
|
|
992
|
+
this.getScrollOffset() - anchor.delta,
|
|
993
|
+
this.scrollState.lastTargetOffset
|
|
994
|
+
)) ;
|
|
995
|
+
else {
|
|
996
|
+
this._followOffsetTarget(anchor.delta);
|
|
997
|
+
this._scrollToOffset(this.getScrollOffset());
|
|
998
|
+
}
|
|
999
|
+
} else {
|
|
1000
|
+
this.scrollToEnd({ behavior: anchor.behavior });
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
this._flushHoldIfReady(false);
|
|
1004
|
+
this._retryClampedAdjustment();
|
|
1005
|
+
};
|
|
1006
|
+
this._classifyScrollEvent = (offset, isScrolling, elementMax) => {
|
|
1007
|
+
var _a;
|
|
1008
|
+
return classifyScrollEvent({
|
|
1009
|
+
offset,
|
|
1010
|
+
isScrolling,
|
|
1011
|
+
elementMax,
|
|
1012
|
+
holdOffset: this._holdOffset,
|
|
1013
|
+
scrollOffset: this.scrollOffset,
|
|
1014
|
+
pendingWrite: this.pendingWrite,
|
|
1015
|
+
clampedMaxAtWrite: ((_a = this._clampedAdjustment) == null ? void 0 : _a.maxAtWrite) ?? null
|
|
1016
|
+
});
|
|
1017
|
+
};
|
|
1018
|
+
this._retryClampedAdjustment = () => {
|
|
1019
|
+
if (this._clampedAdjustment === null || !this.scrollElement || !this.options.enabled || !this._canWriteScroll()) {
|
|
1020
|
+
return;
|
|
1021
|
+
}
|
|
1022
|
+
const { target, maxAtWrite } = this._clampedAdjustment;
|
|
1023
|
+
const max = this.getMaxScrollOffset();
|
|
1024
|
+
if (max > maxAtWrite + 0.5) {
|
|
1025
|
+
this._clampedAdjustment = target > max + 0.5 ? { target, maxAtWrite: max } : null;
|
|
1026
|
+
this._scrollToOffset(target);
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
this._writeAwaitingCommand = () => {
|
|
1030
|
+
const state = this.scrollState;
|
|
1031
|
+
if (state === null || state.phase !== "queued") return;
|
|
1032
|
+
const { behavior } = state;
|
|
1033
|
+
this.getMeasurements();
|
|
1034
|
+
const offset = this.getScrollStateTarget(state);
|
|
1035
|
+
state.lastTargetOffset = offset;
|
|
1036
|
+
this._clampedAdjustment = null;
|
|
1037
|
+
state.phase = initialScrollPhase(
|
|
1038
|
+
behavior,
|
|
1039
|
+
state.index != null && approxEqual(offset, this.getScrollOffset())
|
|
1040
|
+
);
|
|
1041
|
+
this._scrollToOffset(offset, { behavior });
|
|
1042
|
+
this.scheduleScrollReconcile();
|
|
1043
|
+
};
|
|
1044
|
+
this._readElementOffset = () => {
|
|
1045
|
+
const el = this.scrollElement;
|
|
1046
|
+
if (el == null) return null;
|
|
1047
|
+
const { horizontal, isRtl } = this.options;
|
|
1048
|
+
if (typeof el.scrollTop === "number") {
|
|
1049
|
+
return horizontal ? el.scrollLeft * (isRtl && -1 || 1) : el.scrollTop;
|
|
1050
|
+
}
|
|
1051
|
+
if (typeof el.scrollY === "number") {
|
|
1052
|
+
return horizontal ? el.scrollX : el.scrollY;
|
|
1053
|
+
}
|
|
1054
|
+
return null;
|
|
1055
|
+
};
|
|
1056
|
+
this._canWriteScroll = () => !(isIOSWebKit() && this._iosGesture.inMotion()) && !this._reportedOverscroll;
|
|
1057
|
+
this._flushHoldIfReady = (sync) => {
|
|
1058
|
+
var _a;
|
|
1059
|
+
if (this._holdOffset === 0) return;
|
|
1060
|
+
if (!this.scrollElement || !this.options.enabled) return;
|
|
1061
|
+
if (!this._canWriteScroll()) return;
|
|
1062
|
+
if (((_a = this.scrollState) == null ? void 0 : _a.phase) === "smooth") return;
|
|
1063
|
+
this._holdOffset = 0;
|
|
1064
|
+
if (this.scrollOffset !== null && this.scrollOffset < 0) {
|
|
1065
|
+
this.scrollOffset = 0;
|
|
1066
|
+
}
|
|
1067
|
+
this.notify(sync);
|
|
1068
|
+
const target = this.getCommandWrittenOffset() ?? this.getScrollOffset();
|
|
1069
|
+
this._clampedAdjustment = this._clampedBy(target);
|
|
1070
|
+
this._scrollToOffset(target);
|
|
1071
|
+
};
|
|
1072
|
+
this.rafId = null;
|
|
1073
|
+
this.getSize = () => {
|
|
1074
|
+
if (!this.options.enabled) {
|
|
1075
|
+
this.scrollRect = null;
|
|
1076
|
+
return 0;
|
|
1077
|
+
}
|
|
1078
|
+
this.scrollRect = this.scrollRect ?? this.options.initialRect;
|
|
1079
|
+
return this.scrollRect[this.options.horizontal ? "width" : "height"];
|
|
1080
|
+
};
|
|
1081
|
+
this.getScrollOffset = () => {
|
|
1082
|
+
if (!this.options.enabled) {
|
|
1083
|
+
this.scrollOffset = null;
|
|
1084
|
+
return 0;
|
|
1085
|
+
}
|
|
1086
|
+
this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset === "function" ? this.options.initialOffset() : this.options.initialOffset);
|
|
1087
|
+
return this.scrollOffset;
|
|
1088
|
+
};
|
|
1089
|
+
this.getMeasurementOptions = memo(
|
|
1090
|
+
() => [
|
|
1091
|
+
this.options.count,
|
|
1092
|
+
this.options.paddingStart,
|
|
1093
|
+
this.options.scrollMargin,
|
|
1094
|
+
this.options.getItemKey,
|
|
1095
|
+
this.options.enabled,
|
|
1096
|
+
this.options.lanes,
|
|
1097
|
+
this.options.laneAssignmentMode,
|
|
1098
|
+
this.options.gap
|
|
1099
|
+
],
|
|
1100
|
+
(count, paddingStart, scrollMargin, getItemKey, enabled, lanes, laneAssignmentMode, gap) => {
|
|
1101
|
+
const lanesChanged = this.prevLanes !== void 0 && this.prevLanes !== lanes;
|
|
1102
|
+
if (lanesChanged) {
|
|
1103
|
+
this.lanesChangedFlag = true;
|
|
1104
|
+
}
|
|
1105
|
+
this.prevLanes = lanes;
|
|
1106
|
+
this.pendingMin = null;
|
|
1107
|
+
return {
|
|
1108
|
+
count,
|
|
1109
|
+
paddingStart,
|
|
1110
|
+
scrollMargin,
|
|
1111
|
+
getItemKey,
|
|
1112
|
+
enabled,
|
|
1113
|
+
lanes,
|
|
1114
|
+
laneAssignmentMode,
|
|
1115
|
+
gap
|
|
1116
|
+
};
|
|
1117
|
+
},
|
|
1118
|
+
{
|
|
1119
|
+
key: false
|
|
1120
|
+
}
|
|
1121
|
+
);
|
|
1122
|
+
this.isIndexInRange = (index) => index >= 0 && index < this.options.count;
|
|
1123
|
+
this.getMeasurements = memo(
|
|
1124
|
+
() => [this.getMeasurementOptions(), this.itemSizeCacheVersion],
|
|
1125
|
+
({
|
|
1126
|
+
count,
|
|
1127
|
+
paddingStart,
|
|
1128
|
+
scrollMargin,
|
|
1129
|
+
getItemKey,
|
|
1130
|
+
enabled,
|
|
1131
|
+
lanes,
|
|
1132
|
+
laneAssignmentMode,
|
|
1133
|
+
gap
|
|
1134
|
+
}, _itemSizeCacheVersion) => {
|
|
1135
|
+
var _a;
|
|
1136
|
+
const itemSizeCache = this.itemSizeCache;
|
|
1137
|
+
if (!enabled) {
|
|
1138
|
+
this.measurementsCache = [];
|
|
1139
|
+
this._singleLaneMeasurements = null;
|
|
1140
|
+
this.itemSizeCache.clear();
|
|
1141
|
+
this.laneAssignments.clear();
|
|
1142
|
+
return [];
|
|
1143
|
+
}
|
|
1144
|
+
if (this.laneAssignments.size > count) {
|
|
1145
|
+
for (const index of this.laneAssignments.keys()) {
|
|
1146
|
+
if (index >= count) {
|
|
1147
|
+
this.laneAssignments.delete(index);
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
}
|
|
1151
|
+
if (this.lanesChangedFlag) {
|
|
1152
|
+
this.lanesChangedFlag = false;
|
|
1153
|
+
this.lanesSettling = true;
|
|
1154
|
+
this.measurementsCache = [];
|
|
1155
|
+
this._singleLaneMeasurements = null;
|
|
1156
|
+
this.itemSizeCache.clear();
|
|
1157
|
+
this.laneAssignments.clear();
|
|
1158
|
+
this.pendingMin = null;
|
|
1159
|
+
}
|
|
1160
|
+
if (this.measurementsCache.length === 0 && !this.lanesSettling) {
|
|
1161
|
+
this.measurementsCache = this.options.initialMeasurementsCache;
|
|
1162
|
+
this.measurementsCache.forEach((item) => {
|
|
1163
|
+
this.itemSizeCache.set(item.key, item.size);
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
const min = this.lanesSettling ? 0 : this.pendingMin ?? 0;
|
|
1167
|
+
this.pendingMin = null;
|
|
1168
|
+
if (this.lanesSettling && this.measurementsCache.length === count) {
|
|
1169
|
+
this.lanesSettling = false;
|
|
1170
|
+
}
|
|
1171
|
+
if (lanes === 1) {
|
|
1172
|
+
const need = count * 2;
|
|
1173
|
+
let flat = (_a = this._singleLaneMeasurements) == null ? void 0 : _a.flat;
|
|
1174
|
+
if (!flat || flat.length < need) {
|
|
1175
|
+
const next = new Float64Array(need);
|
|
1176
|
+
if (flat && min > 0) next.set(flat.subarray(0, min * 2));
|
|
1177
|
+
flat = next;
|
|
1178
|
+
}
|
|
1179
|
+
const items = min === 0 ? new Array(count) : this._singleLaneMeasurements.items.slice();
|
|
1180
|
+
let runningStart;
|
|
1181
|
+
if (min === 0) {
|
|
1182
|
+
runningStart = paddingStart + scrollMargin;
|
|
1183
|
+
} else {
|
|
1184
|
+
const prevIdx = min - 1;
|
|
1185
|
+
runningStart = flat[prevIdx * 2] + flat[prevIdx * 2 + 1] + gap;
|
|
1186
|
+
}
|
|
1187
|
+
for (let i = min; i < count; i++) {
|
|
1188
|
+
const key = getItemKey(i);
|
|
1189
|
+
items[i] = key;
|
|
1190
|
+
const measuredSize = itemSizeCache.get(key);
|
|
1191
|
+
const size = typeof measuredSize === "number" ? measuredSize : this.options.estimateSize(i);
|
|
1192
|
+
flat[i * 2] = runningStart;
|
|
1193
|
+
flat[i * 2 + 1] = size;
|
|
1194
|
+
runningStart += size + gap;
|
|
1195
|
+
}
|
|
1196
|
+
this._singleLaneMeasurements = { flat, items };
|
|
1197
|
+
const view = createLazyMeasurementsView(items, flat);
|
|
1198
|
+
this.measurementsCache = view;
|
|
1199
|
+
return view;
|
|
1200
|
+
}
|
|
1201
|
+
const measurements = this.measurementsCache.slice(0, min);
|
|
1202
|
+
const laneLastIndex = new Array(lanes).fill(
|
|
1203
|
+
void 0
|
|
1204
|
+
);
|
|
1205
|
+
const laneEnds = new Float64Array(lanes);
|
|
1206
|
+
let filledLanes = 0;
|
|
1207
|
+
for (let m = 0; m < min; m++) {
|
|
1208
|
+
const item = measurements[m];
|
|
1209
|
+
if (item) {
|
|
1210
|
+
if (laneLastIndex[item.lane] === void 0) filledLanes++;
|
|
1211
|
+
laneLastIndex[item.lane] = m;
|
|
1212
|
+
laneEnds[item.lane] = item.end;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
for (let i = min; i < count; i++) {
|
|
1216
|
+
const key = getItemKey(i);
|
|
1217
|
+
const cachedLane = this.laneAssignments.get(i);
|
|
1218
|
+
let lane;
|
|
1219
|
+
let start;
|
|
1220
|
+
const shouldCacheLane = laneAssignmentMode === "estimate" || itemSizeCache.has(key);
|
|
1221
|
+
if (cachedLane !== void 0 && this.options.lanes > 1) {
|
|
1222
|
+
lane = cachedLane;
|
|
1223
|
+
const prevIndex = laneLastIndex[lane];
|
|
1224
|
+
const prevInLane = prevIndex !== void 0 ? measurements[prevIndex] : void 0;
|
|
1225
|
+
start = prevInLane ? prevInLane.end + gap : paddingStart + scrollMargin;
|
|
1226
|
+
} else if (filledLanes === lanes) {
|
|
1227
|
+
let bestLane = 0;
|
|
1228
|
+
let bestEnd = laneEnds[0];
|
|
1229
|
+
let bestIdx = laneLastIndex[0];
|
|
1230
|
+
for (let l = 1; l < lanes; l++) {
|
|
1231
|
+
const e = laneEnds[l];
|
|
1232
|
+
if (e < bestEnd || e === bestEnd && laneLastIndex[l] < bestIdx) {
|
|
1233
|
+
bestLane = l;
|
|
1234
|
+
bestEnd = e;
|
|
1235
|
+
bestIdx = laneLastIndex[l];
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
lane = bestLane;
|
|
1239
|
+
start = bestEnd + gap;
|
|
1240
|
+
if (shouldCacheLane) {
|
|
1241
|
+
this.laneAssignments.set(i, lane);
|
|
1242
|
+
}
|
|
1243
|
+
} else {
|
|
1244
|
+
lane = i % this.options.lanes;
|
|
1245
|
+
start = paddingStart + scrollMargin;
|
|
1246
|
+
if (shouldCacheLane) {
|
|
1247
|
+
this.laneAssignments.set(i, lane);
|
|
1248
|
+
}
|
|
1249
|
+
}
|
|
1250
|
+
const measuredSize = itemSizeCache.get(key);
|
|
1251
|
+
const size = typeof measuredSize === "number" ? measuredSize : this.options.estimateSize(i);
|
|
1252
|
+
const end = start + size;
|
|
1253
|
+
measurements[i] = {
|
|
1254
|
+
index: i,
|
|
1255
|
+
start,
|
|
1256
|
+
size,
|
|
1257
|
+
end,
|
|
1258
|
+
key,
|
|
1259
|
+
lane
|
|
1260
|
+
};
|
|
1261
|
+
if (laneLastIndex[lane] === void 0) filledLanes++;
|
|
1262
|
+
laneLastIndex[lane] = i;
|
|
1263
|
+
laneEnds[lane] = end;
|
|
1264
|
+
}
|
|
1265
|
+
this.measurementsCache = measurements;
|
|
1266
|
+
return measurements;
|
|
1267
|
+
},
|
|
1268
|
+
{
|
|
1269
|
+
key: "production" !== "production",
|
|
1270
|
+
debug: () => this.options.debug
|
|
1271
|
+
}
|
|
1272
|
+
);
|
|
1273
|
+
this.calculateRange = memo(
|
|
1274
|
+
() => [
|
|
1275
|
+
this.getMeasurements(),
|
|
1276
|
+
this.getSize(),
|
|
1277
|
+
this.getScrollOffset(),
|
|
1278
|
+
this.options.lanes,
|
|
1279
|
+
// scrollOffset is measured in the scroll element and the layout total
|
|
1280
|
+
// from the list start, so the list ends scrollMargin further down.
|
|
1281
|
+
this._getLayoutTotalSize() + this.options.scrollMargin
|
|
1282
|
+
],
|
|
1283
|
+
(measurements, outerSize, scrollOffset, lanes, listEnd) => {
|
|
1284
|
+
if (measurements.length === 0 || outerSize === 0) {
|
|
1285
|
+
this.range = null;
|
|
1286
|
+
return null;
|
|
1287
|
+
}
|
|
1288
|
+
const maxScrollOffset = Math.max(listEnd - outerSize, 0);
|
|
1289
|
+
this.range = calculateRangeImpl(
|
|
1290
|
+
measurements,
|
|
1291
|
+
outerSize,
|
|
1292
|
+
Math.min(scrollOffset, maxScrollOffset),
|
|
1293
|
+
lanes,
|
|
1294
|
+
// Pass the typed array so binary search + forward-walk can read
|
|
1295
|
+
// start/end directly from Float64Array, skipping the Proxy traps.
|
|
1296
|
+
lanes === 1 && this._singleLaneMeasurements !== null ? this._singleLaneMeasurements.flat : null
|
|
1297
|
+
);
|
|
1298
|
+
return this.range;
|
|
1299
|
+
},
|
|
1300
|
+
{
|
|
1301
|
+
key: "production" !== "production",
|
|
1302
|
+
debug: () => this.options.debug
|
|
1303
|
+
}
|
|
1304
|
+
);
|
|
1305
|
+
this.getVirtualIndexes = memo(
|
|
1306
|
+
() => {
|
|
1307
|
+
let startIndex = null;
|
|
1308
|
+
let endIndex = null;
|
|
1309
|
+
const range = this.calculateRange();
|
|
1310
|
+
if (range) {
|
|
1311
|
+
startIndex = range.startIndex;
|
|
1312
|
+
endIndex = range.endIndex;
|
|
1313
|
+
}
|
|
1314
|
+
this.maybeNotify.updateDeps([this.isScrolling, startIndex, endIndex]);
|
|
1315
|
+
return [
|
|
1316
|
+
this.options.rangeExtractor,
|
|
1317
|
+
this.options.overscan,
|
|
1318
|
+
this.options.count,
|
|
1319
|
+
startIndex,
|
|
1320
|
+
endIndex,
|
|
1321
|
+
this.options.lanes
|
|
1322
|
+
];
|
|
1323
|
+
},
|
|
1324
|
+
(rangeExtractor, overscan, count, startIndex, endIndex, lanes) => {
|
|
1325
|
+
return startIndex === null || endIndex === null ? [] : rangeExtractor({
|
|
1326
|
+
startIndex,
|
|
1327
|
+
endIndex,
|
|
1328
|
+
overscan,
|
|
1329
|
+
count,
|
|
1330
|
+
lanes
|
|
1331
|
+
});
|
|
1332
|
+
},
|
|
1333
|
+
{
|
|
1334
|
+
key: "production" !== "production",
|
|
1335
|
+
debug: () => this.options.debug
|
|
1336
|
+
}
|
|
1337
|
+
);
|
|
1338
|
+
this.indexFromElement = (node) => {
|
|
1339
|
+
const attributeName = this.options.indexAttribute;
|
|
1340
|
+
const indexStr = node.getAttribute(attributeName);
|
|
1341
|
+
if (!indexStr) {
|
|
1342
|
+
console.warn(
|
|
1343
|
+
`Missing attribute name '${attributeName}={index}' on measured element.`
|
|
1344
|
+
);
|
|
1345
|
+
return -1;
|
|
1346
|
+
}
|
|
1347
|
+
return parseInt(indexStr, 10);
|
|
1348
|
+
};
|
|
1349
|
+
this.shouldMeasureDuringScroll = (index) => {
|
|
1350
|
+
var _a;
|
|
1351
|
+
if (!isSmoothScroll(this.scrollState)) {
|
|
1352
|
+
return true;
|
|
1353
|
+
}
|
|
1354
|
+
const scrollIndex = this.scrollState.index ?? ((_a = this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)) == null ? void 0 : _a.index);
|
|
1355
|
+
if (scrollIndex !== void 0 && this.range) {
|
|
1356
|
+
const bufferSize = Math.max(
|
|
1357
|
+
this.options.overscan,
|
|
1358
|
+
Math.ceil((this.range.endIndex - this.range.startIndex) / 2)
|
|
1359
|
+
);
|
|
1360
|
+
const minIndex = Math.max(0, scrollIndex - bufferSize);
|
|
1361
|
+
const maxIndex = Math.min(
|
|
1362
|
+
this.options.count - 1,
|
|
1363
|
+
scrollIndex + bufferSize
|
|
1364
|
+
);
|
|
1365
|
+
return index >= minIndex && index <= maxIndex;
|
|
1366
|
+
}
|
|
1367
|
+
return true;
|
|
1368
|
+
};
|
|
1369
|
+
this.measureElement = (node) => {
|
|
1370
|
+
if (!node) {
|
|
1371
|
+
this.elementsCache.forEach((cached, key2) => {
|
|
1372
|
+
if (!cached.isConnected) {
|
|
1373
|
+
this.observer.unobserve(cached);
|
|
1374
|
+
this.elementsCache.delete(key2);
|
|
1375
|
+
}
|
|
1376
|
+
});
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1379
|
+
const index = this.indexFromElement(node);
|
|
1380
|
+
if (!this.isIndexInRange(index)) return;
|
|
1381
|
+
const key = this.options.getItemKey(index);
|
|
1382
|
+
const prevNode = this.elementsCache.get(key);
|
|
1383
|
+
if (prevNode !== node) {
|
|
1384
|
+
if (prevNode) {
|
|
1385
|
+
this.observer.unobserve(prevNode);
|
|
1386
|
+
}
|
|
1387
|
+
this.observer.observe(node);
|
|
1388
|
+
this.elementsCache.set(key, node);
|
|
1389
|
+
}
|
|
1390
|
+
if (node.isConnected && (!this.isScrolling || this.scrollState) && this.shouldMeasureDuringScroll(index)) {
|
|
1391
|
+
this.resizeItem(index, this.options.measureElement(node, void 0, this));
|
|
1392
|
+
}
|
|
1393
|
+
};
|
|
1394
|
+
this.resizeItem = (index, size) => {
|
|
1395
|
+
var _a, _b, _c;
|
|
1396
|
+
if (!this.isIndexInRange(index)) return;
|
|
1397
|
+
if ((_a = this._resizeBatch) == null ? void 0 : _a.sync) this.getMeasurements();
|
|
1398
|
+
let cachedSize;
|
|
1399
|
+
let itemStart;
|
|
1400
|
+
let key;
|
|
1401
|
+
const flat = (_b = this._singleLaneMeasurements) == null ? void 0 : _b.flat;
|
|
1402
|
+
if (this.options.lanes === 1 && flat != null) {
|
|
1403
|
+
key = this.options.getItemKey(index);
|
|
1404
|
+
itemStart = flat[index * 2];
|
|
1405
|
+
cachedSize = flat[index * 2 + 1];
|
|
1406
|
+
} else {
|
|
1407
|
+
const item = this.measurementsCache[index];
|
|
1408
|
+
if (!item) return;
|
|
1409
|
+
key = item.key;
|
|
1410
|
+
itemStart = item.start;
|
|
1411
|
+
cachedSize = item.size;
|
|
1412
|
+
}
|
|
1413
|
+
const itemSize = this.itemSizeCache.get(key) ?? cachedSize;
|
|
1414
|
+
const delta = size - itemSize;
|
|
1415
|
+
if (delta !== 0) {
|
|
1416
|
+
const wasAtEnd = this.options.anchorTo === "end" && !isSmoothScroll(this.scrollState) && this.getVirtualDistanceFromEnd() <= this.options.scrollEndThreshold;
|
|
1417
|
+
const prevTotalSize = wasAtEnd ? this._getLayoutTotalSize() : 0;
|
|
1418
|
+
const scrollOffset = this.getScrollOffset();
|
|
1419
|
+
const isFirstMeasure = !this.itemSizeCache.has(key);
|
|
1420
|
+
const defaultShouldAdjust = isFirstMeasure ? (
|
|
1421
|
+
// First measurement: compensate any item whose top sits above the
|
|
1422
|
+
// fold — the estimate→actual delta must be corrected regardless of
|
|
1423
|
+
// scroll direction, since the whole estimated block was above it.
|
|
1424
|
+
itemStart < scrollOffset
|
|
1425
|
+
) : (
|
|
1426
|
+
// Re-measurement: only compensate an item that is ENTIRELY above the
|
|
1427
|
+
// fold. An item that merely *spans* the fold (top above, bottom
|
|
1428
|
+
// below — e.g. a streaming chat message growing at its bottom)
|
|
1429
|
+
// changes size *below* the anchor point, so shifting scrollTop by the
|
|
1430
|
+
// delta would drag the viewport downward on every growth (#1218).
|
|
1431
|
+
// Also skip during backward scroll to avoid the "items jump while
|
|
1432
|
+
// scrolling up" cascade.
|
|
1433
|
+
itemStart + itemSize <= scrollOffset && this.scrollDirection !== "backward"
|
|
1434
|
+
);
|
|
1435
|
+
const shouldAdjustScroll = !isSmoothScroll(this.scrollState) && (this.shouldAdjustScrollPositionOnItemSizeChange !== void 0 ? this.shouldAdjustScrollPositionOnItemSizeChange(
|
|
1436
|
+
// The callback expects a VirtualItem; build one lazily only
|
|
1437
|
+
// when the consumer actually supplied a custom predicate.
|
|
1438
|
+
this.measurementsCache[index] ?? {
|
|
1439
|
+
index,
|
|
1440
|
+
key,
|
|
1441
|
+
start: itemStart,
|
|
1442
|
+
size: cachedSize,
|
|
1443
|
+
end: itemStart + cachedSize,
|
|
1444
|
+
lane: 0
|
|
1445
|
+
},
|
|
1446
|
+
delta,
|
|
1447
|
+
this
|
|
1448
|
+
) : defaultShouldAdjust);
|
|
1449
|
+
if (this.pendingMin === null || index < this.pendingMin) {
|
|
1450
|
+
this.pendingMin = index;
|
|
1451
|
+
}
|
|
1452
|
+
this.itemSizeCache.set(key, size);
|
|
1453
|
+
this.itemSizeCacheVersion++;
|
|
1454
|
+
let adjustedSync = false;
|
|
1455
|
+
if (!this._awaitingCommandReadBack()) {
|
|
1456
|
+
if (wasAtEnd) {
|
|
1457
|
+
adjustedSync = this.applyScrollAdjustment(
|
|
1458
|
+
this._getLayoutTotalSize() - prevTotalSize
|
|
1459
|
+
);
|
|
1460
|
+
} else if (shouldAdjustScroll) {
|
|
1461
|
+
adjustedSync = this.applyScrollAdjustment(delta);
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
if (this._resizeBatch) {
|
|
1465
|
+
this._resizeBatch.notify = true;
|
|
1466
|
+
(_c = this._resizeBatch).sync || (_c.sync = adjustedSync);
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
this.notify(adjustedSync);
|
|
1470
|
+
this._noteClampMax();
|
|
1471
|
+
this._flushHoldIfReady(true);
|
|
1472
|
+
this._retryClampedAdjustment();
|
|
1473
|
+
}
|
|
1474
|
+
};
|
|
1475
|
+
this.getVirtualItems = memo(
|
|
1476
|
+
() => [this.getVirtualIndexes(), this.getMeasurements(), this._holdOffset],
|
|
1477
|
+
(indexes, measurements, hold) => {
|
|
1478
|
+
const virtualItems = [];
|
|
1479
|
+
for (let k = 0, len = indexes.length; k < len; k++) {
|
|
1480
|
+
const i = indexes[k];
|
|
1481
|
+
const measurement = measurements[i];
|
|
1482
|
+
virtualItems.push(
|
|
1483
|
+
hold === 0 ? measurement : {
|
|
1484
|
+
...measurement,
|
|
1485
|
+
start: measurement.start - hold,
|
|
1486
|
+
end: measurement.end - hold
|
|
1487
|
+
}
|
|
1488
|
+
);
|
|
1489
|
+
}
|
|
1490
|
+
return virtualItems;
|
|
1491
|
+
},
|
|
1492
|
+
{
|
|
1493
|
+
key: "production" !== "production",
|
|
1494
|
+
debug: () => this.options.debug
|
|
1495
|
+
}
|
|
1496
|
+
);
|
|
1497
|
+
this.getVirtualItemForOffset = (offset) => {
|
|
1498
|
+
var _a;
|
|
1499
|
+
const measurements = this.getMeasurements();
|
|
1500
|
+
if (measurements.length === 0) {
|
|
1501
|
+
return void 0;
|
|
1502
|
+
}
|
|
1503
|
+
const flat = (_a = this._singleLaneMeasurements) == null ? void 0 : _a.flat;
|
|
1504
|
+
const useFlat = this.options.lanes === 1 && flat != null;
|
|
1505
|
+
const idx = findNearestBinarySearch(
|
|
1506
|
+
0,
|
|
1507
|
+
measurements.length - 1,
|
|
1508
|
+
useFlat ? (i) => flat[i * 2] : (i) => notUndefined(measurements[i]).start,
|
|
1509
|
+
offset
|
|
1510
|
+
);
|
|
1511
|
+
return notUndefined(measurements[idx]);
|
|
1512
|
+
};
|
|
1513
|
+
this._noteClampMax = () => {
|
|
1514
|
+
if (!this._awaitingCommandReadBack()) return;
|
|
1515
|
+
const elementMax = this._elementMaxScrollOffset();
|
|
1516
|
+
if (elementMax === null) return;
|
|
1517
|
+
const write = this.pendingWrite;
|
|
1518
|
+
const max = Math.max(elementMax, 0) + this._holdOffset;
|
|
1519
|
+
if (max >= write.target) return;
|
|
1520
|
+
const lowMaxes = write.lowMaxes ?? (write.lowMaxes = []);
|
|
1521
|
+
if (lowMaxes[lowMaxes.length - 1] !== max) lowMaxes.push(max);
|
|
1522
|
+
};
|
|
1523
|
+
this.getMaxScrollOffset = () => (this._elementMaxScrollOffset() ?? 0) + this._holdOffset;
|
|
1524
|
+
this._toLayoutOffset = (elementOffset) => {
|
|
1525
|
+
var _a;
|
|
1526
|
+
let offset = elementOffset + this._holdOffset;
|
|
1527
|
+
if (((_a = this.pendingScrollAnchor) == null ? void 0 : _a.kind) === "anchor") {
|
|
1528
|
+
offset += this.pendingScrollAnchor.delta;
|
|
1529
|
+
}
|
|
1530
|
+
return offset;
|
|
1531
|
+
};
|
|
1532
|
+
this._elementMaxScrollOffset = () => {
|
|
1533
|
+
const el = this.scrollElement;
|
|
1534
|
+
if (el === null) return null;
|
|
1535
|
+
if ("scrollHeight" in el) {
|
|
1536
|
+
return this.options.horizontal ? el.scrollWidth - el.clientWidth : el.scrollHeight - el.clientHeight;
|
|
1537
|
+
}
|
|
1538
|
+
if ("document" in el) {
|
|
1539
|
+
const doc = el.document.documentElement;
|
|
1540
|
+
return this.options.horizontal ? doc.scrollWidth - el.innerWidth : doc.scrollHeight - el.innerHeight;
|
|
1541
|
+
}
|
|
1542
|
+
return null;
|
|
1543
|
+
};
|
|
1544
|
+
this._momentumStop = null;
|
|
1545
|
+
this._stopMomentum = (done) => {
|
|
1546
|
+
const el = this.scrollElement;
|
|
1547
|
+
const win = this.targetWindow;
|
|
1548
|
+
if (el === null || win === null) return;
|
|
1549
|
+
const scroller = "document" in el ? el.document.scrollingElement : el;
|
|
1550
|
+
if (!(scroller == null ? void 0 : scroller.style)) return;
|
|
1551
|
+
if (this._momentumStop) {
|
|
1552
|
+
this._momentumStop.done = done;
|
|
1553
|
+
return;
|
|
1554
|
+
}
|
|
1555
|
+
const { style } = scroller;
|
|
1556
|
+
const property = this.options.horizontal ? "overflow-x" : "overflow-y";
|
|
1557
|
+
const value = style.getPropertyValue(property);
|
|
1558
|
+
const priority = style.getPropertyPriority(property);
|
|
1559
|
+
const crossSize = () => this.options.horizontal ? scroller.clientHeight : scroller.clientWidth;
|
|
1560
|
+
const crossSizeBefore = crossSize();
|
|
1561
|
+
style.setProperty(property, "hidden", "important");
|
|
1562
|
+
if (crossSize() !== crossSizeBefore) {
|
|
1563
|
+
style.setProperty(property, value, priority);
|
|
1564
|
+
return;
|
|
1565
|
+
}
|
|
1566
|
+
const stop = {
|
|
1567
|
+
// False when the app replaced the hidden value: the fling may not
|
|
1568
|
+
// have stopped.
|
|
1569
|
+
restore: () => {
|
|
1570
|
+
if (style.getPropertyValue(property) !== "hidden" || style.getPropertyPriority(property) !== "important") {
|
|
1571
|
+
return false;
|
|
1572
|
+
}
|
|
1573
|
+
style.setProperty(property, value, priority);
|
|
1574
|
+
return true;
|
|
1575
|
+
},
|
|
1576
|
+
done
|
|
1577
|
+
};
|
|
1578
|
+
this._momentumStop = stop;
|
|
1579
|
+
win.requestAnimationFrame(
|
|
1580
|
+
() => win.requestAnimationFrame(() => {
|
|
1581
|
+
if (this._momentumStop !== stop) return;
|
|
1582
|
+
this._momentumStop = null;
|
|
1583
|
+
if (stop.restore()) stop.done();
|
|
1584
|
+
})
|
|
1585
|
+
);
|
|
1586
|
+
};
|
|
1587
|
+
this._clampedBy = (target) => {
|
|
1588
|
+
const elementMax = this._elementMaxScrollOffset();
|
|
1589
|
+
if (elementMax === null) return null;
|
|
1590
|
+
const maxAtWrite = elementMax + this._holdOffset;
|
|
1591
|
+
return target > maxAtWrite + 0.5 ? { target, maxAtWrite } : null;
|
|
1592
|
+
};
|
|
1593
|
+
this.getVirtualDistanceFromEnd = () => {
|
|
1594
|
+
return Math.max(
|
|
1595
|
+
this._getLayoutTotalSize() + this.options.scrollMargin - this.getSize() - this.getScrollOffset(),
|
|
1596
|
+
0
|
|
1597
|
+
);
|
|
1598
|
+
};
|
|
1599
|
+
this.getDistanceFromEnd = () => {
|
|
1600
|
+
return Math.max(this.getMaxScrollOffset() - this.getScrollOffset(), 0);
|
|
1601
|
+
};
|
|
1602
|
+
this.isAtEnd = (threshold = this.options.scrollEndThreshold) => {
|
|
1603
|
+
return this.getDistanceFromEnd() <= threshold;
|
|
1604
|
+
};
|
|
1605
|
+
this.getOffsetForAlignment = (toOffset, align, itemSize = 0) => {
|
|
1606
|
+
if (!this.scrollElement) return 0;
|
|
1607
|
+
const size = this.getSize();
|
|
1608
|
+
const scrollOffset = this.getScrollOffset();
|
|
1609
|
+
if (align === "auto") {
|
|
1610
|
+
align = toOffset >= scrollOffset + size ? "end" : "start";
|
|
1611
|
+
}
|
|
1612
|
+
if (align === "center") {
|
|
1613
|
+
toOffset += (itemSize - size) / 2;
|
|
1614
|
+
} else if (align === "end") {
|
|
1615
|
+
toOffset -= size;
|
|
1616
|
+
}
|
|
1617
|
+
const maxOffset = this.getMaxScrollOffset();
|
|
1618
|
+
return Math.max(Math.min(maxOffset, toOffset), 0);
|
|
1619
|
+
};
|
|
1620
|
+
this.getOffsetForIndex = (index, align = "auto") => {
|
|
1621
|
+
index = Math.max(0, Math.min(index, this.options.count - 1));
|
|
1622
|
+
const size = this.getSize();
|
|
1623
|
+
const scrollOffset = this.getScrollOffset();
|
|
1624
|
+
const item = this.measurementsCache[index];
|
|
1625
|
+
if (!item) return;
|
|
1626
|
+
if (align === "auto") {
|
|
1627
|
+
if (item.end >= scrollOffset + size - this.options.scrollPaddingEnd) {
|
|
1628
|
+
align = "end";
|
|
1629
|
+
} else if (item.start <= scrollOffset + this.options.scrollPaddingStart) {
|
|
1630
|
+
align = "start";
|
|
1631
|
+
} else {
|
|
1632
|
+
return [scrollOffset, align];
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
if (align === "end" && index === this.options.count - 1) {
|
|
1636
|
+
const maxOffset = this.getMaxScrollOffset();
|
|
1637
|
+
const toOffset2 = maxOffset - this.options.paddingEnd + this.options.scrollPaddingEnd;
|
|
1638
|
+
return [Math.max(Math.min(toOffset2, maxOffset), 0), align];
|
|
1639
|
+
}
|
|
1640
|
+
const toOffset = align === "end" ? item.end + this.options.scrollPaddingEnd : item.start - this.options.scrollPaddingStart;
|
|
1641
|
+
return [
|
|
1642
|
+
this.getOffsetForAlignment(toOffset, align, item.size),
|
|
1643
|
+
align
|
|
1644
|
+
];
|
|
1645
|
+
};
|
|
1646
|
+
this.scrollToOffset = (toOffset, { align = "start", behavior = "auto" } = {}) => {
|
|
1647
|
+
this._startScroll(
|
|
1648
|
+
{ index: null, align },
|
|
1649
|
+
this.getOffsetForAlignment(toOffset, align),
|
|
1650
|
+
behavior,
|
|
1651
|
+
"absolute"
|
|
1652
|
+
);
|
|
1653
|
+
};
|
|
1654
|
+
this.scrollToIndex = (index, {
|
|
1655
|
+
align: initialAlign = "auto",
|
|
1656
|
+
behavior = "auto"
|
|
1657
|
+
} = {}) => {
|
|
1658
|
+
index = Math.max(0, Math.min(index, this.options.count - 1));
|
|
1659
|
+
const offsetInfo = this.getOffsetForIndex(index, initialAlign);
|
|
1660
|
+
if (!offsetInfo) return;
|
|
1661
|
+
const [offset, align] = offsetInfo;
|
|
1662
|
+
this._startScroll({ index, align }, offset, behavior, "absolute");
|
|
1663
|
+
};
|
|
1664
|
+
this.scrollBy = (delta, { behavior = "auto" } = {}) => {
|
|
1665
|
+
const offset = this.getOffsetForAlignment(
|
|
1666
|
+
(this.getCommandWrittenOffset() ?? this.getScrollOffset()) + delta,
|
|
1667
|
+
"start"
|
|
1668
|
+
);
|
|
1669
|
+
this._startScroll(
|
|
1670
|
+
{ index: null, align: "start" },
|
|
1671
|
+
offset,
|
|
1672
|
+
behavior,
|
|
1673
|
+
"relative"
|
|
1674
|
+
);
|
|
1675
|
+
};
|
|
1676
|
+
this.scrollToEnd = ({ behavior = "auto" } = {}) => {
|
|
1677
|
+
if (this.options.count > 0) {
|
|
1678
|
+
this._startScroll(
|
|
1679
|
+
{ index: this.options.count - 1, align: "end", toEnd: true },
|
|
1680
|
+
Math.max(this.getMaxScrollOffset(), 0),
|
|
1681
|
+
behavior,
|
|
1682
|
+
"absolute"
|
|
1683
|
+
);
|
|
1684
|
+
return;
|
|
1685
|
+
}
|
|
1686
|
+
this.scrollToOffset(Math.max(this.getTotalSize() - this.getSize(), 0), {
|
|
1687
|
+
behavior
|
|
1688
|
+
});
|
|
1689
|
+
};
|
|
1690
|
+
this.cancelScroll = () => {
|
|
1691
|
+
if (this.rafId != null && this.targetWindow) {
|
|
1692
|
+
this.targetWindow.cancelAnimationFrame(this.rafId);
|
|
1693
|
+
this.rafId = null;
|
|
1694
|
+
}
|
|
1695
|
+
this.scrollState = null;
|
|
1696
|
+
};
|
|
1697
|
+
this.getTotalSize = () => Math.max(this._getLayoutTotalSize() - this._holdOffset, 0);
|
|
1698
|
+
this._getLayoutTotalSize = () => {
|
|
1699
|
+
var _a, _b;
|
|
1700
|
+
const measurements = this.getMeasurements();
|
|
1701
|
+
let end;
|
|
1702
|
+
if (measurements.length === 0) {
|
|
1703
|
+
end = this.options.paddingStart;
|
|
1704
|
+
} else if (this.options.lanes === 1) {
|
|
1705
|
+
const lastIdx = measurements.length - 1;
|
|
1706
|
+
const flat = (_a = this._singleLaneMeasurements) == null ? void 0 : _a.flat;
|
|
1707
|
+
if (flat != null) {
|
|
1708
|
+
end = flat[lastIdx * 2] + flat[lastIdx * 2 + 1];
|
|
1709
|
+
} else {
|
|
1710
|
+
end = ((_b = measurements[lastIdx]) == null ? void 0 : _b.end) ?? 0;
|
|
1711
|
+
}
|
|
1712
|
+
} else {
|
|
1713
|
+
const endByLane = Array(this.options.lanes).fill(null);
|
|
1714
|
+
let endIndex = measurements.length - 1;
|
|
1715
|
+
while (endIndex >= 0 && endByLane.some((val) => val === null)) {
|
|
1716
|
+
const item = measurements[endIndex];
|
|
1717
|
+
if (endByLane[item.lane] === null) {
|
|
1718
|
+
endByLane[item.lane] = item.end;
|
|
1719
|
+
}
|
|
1720
|
+
endIndex--;
|
|
1721
|
+
}
|
|
1722
|
+
end = Math.max(...endByLane.filter((val) => val !== null));
|
|
1723
|
+
}
|
|
1724
|
+
return Math.max(
|
|
1725
|
+
end - this.options.scrollMargin + this.options.paddingEnd,
|
|
1726
|
+
0
|
|
1727
|
+
);
|
|
1728
|
+
};
|
|
1729
|
+
this.takeSnapshot = () => {
|
|
1730
|
+
const snapshot = [];
|
|
1731
|
+
if (this.itemSizeCache.size === 0) return snapshot;
|
|
1732
|
+
const m = this.getMeasurements();
|
|
1733
|
+
for (const item of m) {
|
|
1734
|
+
if (item && this.itemSizeCache.has(item.key)) {
|
|
1735
|
+
snapshot.push({
|
|
1736
|
+
index: item.index,
|
|
1737
|
+
key: item.key,
|
|
1738
|
+
start: item.start,
|
|
1739
|
+
size: item.size,
|
|
1740
|
+
end: item.end,
|
|
1741
|
+
lane: item.lane
|
|
1742
|
+
});
|
|
1743
|
+
}
|
|
1744
|
+
}
|
|
1745
|
+
return snapshot;
|
|
1746
|
+
};
|
|
1747
|
+
this._scrollToOffset = (offset, {
|
|
1748
|
+
adjustments,
|
|
1749
|
+
behavior
|
|
1750
|
+
} = {}) => {
|
|
1751
|
+
const write = {
|
|
1752
|
+
target: offset + (adjustments ?? 0),
|
|
1753
|
+
smooth: behavior === "smooth"
|
|
1754
|
+
};
|
|
1755
|
+
this.pendingWrite = write;
|
|
1756
|
+
this.options.scrollToFn(
|
|
1757
|
+
offset - this._holdOffset,
|
|
1758
|
+
{ behavior, adjustments },
|
|
1759
|
+
this
|
|
1760
|
+
);
|
|
1761
|
+
return write;
|
|
1762
|
+
};
|
|
1763
|
+
this.getCommandWrittenOffset = () => this.scrollState !== null && this.pendingWrite !== null && !this.pendingWrite.smooth ? this.pendingWrite.target : null;
|
|
1764
|
+
this._awaitingCommandReadBack = () => {
|
|
1765
|
+
const writtenOffset = this.getCommandWrittenOffset();
|
|
1766
|
+
return !(isIOSWebKit() && this._iosGesture.dragging()) && writtenOffset !== null && !approxEqual(writtenOffset, this.getScrollOffset());
|
|
1767
|
+
};
|
|
1768
|
+
this._followOffsetTarget = (delta) => {
|
|
1769
|
+
if (this.scrollState !== null && this.scrollState.index == null) {
|
|
1770
|
+
this.scrollState.lastTargetOffset += delta;
|
|
1771
|
+
}
|
|
1772
|
+
};
|
|
1773
|
+
this.measure = () => {
|
|
1774
|
+
this.pendingMin = null;
|
|
1775
|
+
this.itemSizeCache.clear();
|
|
1776
|
+
this.laneAssignments.clear();
|
|
1777
|
+
this.itemSizeCacheVersion++;
|
|
1778
|
+
this.notify(false);
|
|
1779
|
+
};
|
|
1780
|
+
this.setOptions(opts);
|
|
1781
|
+
}
|
|
1782
|
+
/**
|
|
1783
|
+
* @deprecated Always 0: a scroll correction is folded into `scrollOffset`
|
|
1784
|
+
* at once, so there is never an outstanding adjustment to add to it. Read
|
|
1785
|
+
* `scrollOffset` alone.
|
|
1786
|
+
*/
|
|
1787
|
+
get scrollAdjustments() {
|
|
1788
|
+
return 0;
|
|
1789
|
+
}
|
|
1790
|
+
// Returns `true` when it performed a synchronous `scrollTop` write this
|
|
1791
|
+
// tick, `false` when the delta was zero or the write was deferred (iOS).
|
|
1792
|
+
// `resizeItem` uses that to decide whether the follow-up `notify` must be
|
|
1793
|
+
// synchronous so the grown transforms commit in the same paint (#1227).
|
|
1794
|
+
applyScrollAdjustment(delta, behavior) {
|
|
1795
|
+
if (delta === 0) return false;
|
|
1796
|
+
this._followOffsetTarget(delta);
|
|
1797
|
+
if (!this._canWriteScroll()) {
|
|
1798
|
+
this._holdOffset += delta;
|
|
1799
|
+
if (this.scrollOffset !== null) this.scrollOffset += delta;
|
|
1800
|
+
return true;
|
|
1801
|
+
} else {
|
|
1802
|
+
const offset = this.getScrollOffset();
|
|
1803
|
+
this._clampedAdjustment = this._clampedBy(offset + delta);
|
|
1804
|
+
const write = this._scrollToOffset(offset, {
|
|
1805
|
+
adjustments: delta,
|
|
1806
|
+
behavior
|
|
1807
|
+
});
|
|
1808
|
+
if (this.scrollOffset !== null) {
|
|
1809
|
+
if (this.pendingWrite === write) this.scrollOffset += delta;
|
|
1810
|
+
if (this.scrollOffset < 0) this.scrollOffset = 0;
|
|
1811
|
+
}
|
|
1812
|
+
return true;
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
scheduleScrollReconcile() {
|
|
1816
|
+
if (!this.targetWindow) {
|
|
1817
|
+
this.scrollState = null;
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1820
|
+
if (this.rafId != null) return;
|
|
1821
|
+
this.rafId = this.targetWindow.requestAnimationFrame(() => {
|
|
1822
|
+
this.rafId = null;
|
|
1823
|
+
this.reconcileScroll();
|
|
1824
|
+
});
|
|
1825
|
+
}
|
|
1826
|
+
getScrollStateTarget(state) {
|
|
1827
|
+
const offsetInfo = state.toEnd ? [Math.max(this.getMaxScrollOffset(), 0)] : state.index != null ? this.getOffsetForIndex(state.index, state.align) : void 0;
|
|
1828
|
+
return offsetInfo ? offsetInfo[0] : state.lastTargetOffset;
|
|
1829
|
+
}
|
|
1830
|
+
reconcileScroll() {
|
|
1831
|
+
if (!this.scrollState) return;
|
|
1832
|
+
const el = this.scrollElement;
|
|
1833
|
+
if (!el) return;
|
|
1834
|
+
const MAX_RECONCILE_MS = 5e3;
|
|
1835
|
+
if (this.now() - this.scrollState.startedAt > MAX_RECONCILE_MS) {
|
|
1836
|
+
this.scrollState = null;
|
|
1837
|
+
return;
|
|
1838
|
+
}
|
|
1839
|
+
if (this.scrollState.phase === "queued") {
|
|
1840
|
+
this.scheduleScrollReconcile();
|
|
1841
|
+
return;
|
|
1842
|
+
}
|
|
1843
|
+
this.getMeasurements();
|
|
1844
|
+
const targetOffset = this.getScrollStateTarget(this.scrollState);
|
|
1845
|
+
const STABLE_FRAMES = this.scrollState.index == null ? 1 : this.options.useAnimationFrameWithResizeObserver ? 3 : 2;
|
|
1846
|
+
const targetChanged = targetOffset !== this.scrollState.lastTargetOffset;
|
|
1847
|
+
if (!targetChanged && approxEqual(targetOffset, this.getScrollOffset())) {
|
|
1848
|
+
if (this.scrollState.phase === "smooth") {
|
|
1849
|
+
this.scrollState.phase = "smoothLanded";
|
|
1850
|
+
} else if (this.scrollState.phase === "smoothFinishing") {
|
|
1851
|
+
this.scrollState.phase = "instant";
|
|
1852
|
+
}
|
|
1853
|
+
this.scrollState.stableFrames++;
|
|
1854
|
+
if (this.scrollState.stableFrames >= STABLE_FRAMES) {
|
|
1855
|
+
if (this.getScrollOffset() !== targetOffset) {
|
|
1856
|
+
this._scrollToOffset(targetOffset, { behavior: "auto" });
|
|
1857
|
+
}
|
|
1858
|
+
this.scrollState = null;
|
|
1859
|
+
return;
|
|
1860
|
+
}
|
|
1861
|
+
} else {
|
|
1862
|
+
this.scrollState.stableFrames = 0;
|
|
1863
|
+
if (targetChanged) {
|
|
1864
|
+
const viewport = this.getSize() || 600;
|
|
1865
|
+
const distance = Math.abs(targetOffset - this.getScrollOffset());
|
|
1866
|
+
const keepSmooth = isSmoothScroll(this.scrollState) && distance > viewport;
|
|
1867
|
+
this.scrollState.lastTargetOffset = targetOffset;
|
|
1868
|
+
if (keepSmooth) {
|
|
1869
|
+
this.scrollState.phase = "smooth";
|
|
1870
|
+
} else if (this.scrollState.phase === "smooth") {
|
|
1871
|
+
this.scrollState.phase = "smoothFinishing";
|
|
1872
|
+
} else if (this.scrollState.phase === "smoothLanded") {
|
|
1873
|
+
this.scrollState.phase = "instant";
|
|
1874
|
+
}
|
|
1875
|
+
this._scrollToOffset(targetOffset, {
|
|
1876
|
+
behavior: keepSmooth ? "smooth" : "auto"
|
|
1877
|
+
});
|
|
1878
|
+
}
|
|
1879
|
+
}
|
|
1880
|
+
this.scheduleScrollReconcile();
|
|
1881
|
+
}
|
|
1882
|
+
// Every scroll command starts here: it becomes the in-flight command,
|
|
1883
|
+
// writes its first target and leaves reconcile to retarget and retire it.
|
|
1884
|
+
//
|
|
1885
|
+
// Targets are layout offsets. A held correction is not dropped by a
|
|
1886
|
+
// command: the write lands the element `_holdOffset` short of the target,
|
|
1887
|
+
// under the rows exposed shifted by the same amount, and the flush moves
|
|
1888
|
+
// both together once a write is possible.
|
|
1889
|
+
//
|
|
1890
|
+
// An index or end target that is already at its offset starts a smooth
|
|
1891
|
+
// scroll as landed; an offset target never does, so its first scroll
|
|
1892
|
+
// event is read as the user's (see the scroll handler in `_willUpdate`).
|
|
1893
|
+
_startScroll(target, offset, behavior, kind) {
|
|
1894
|
+
this.pendingScrollAnchor = null;
|
|
1895
|
+
this._clampedAdjustment = null;
|
|
1896
|
+
const tail = this._iosGesture.tail();
|
|
1897
|
+
if (kind === "absolute" && tail !== null) {
|
|
1898
|
+
if (tail === "fling" && momentumOverridesWrites()) {
|
|
1899
|
+
this._stopMomentum(() => {
|
|
1900
|
+
const state = this.scrollState;
|
|
1901
|
+
if ((state == null ? void 0 : state.phase) !== "queued" || // A finger came down: it owns the scroll until it lifts.
|
|
1902
|
+
this._iosGesture.tail() !== "fling" || // In a bounce WebKit can drop the write (#1287): the tail
|
|
1903
|
+
// decides, as without the stop. (Not `flingCaught`: our stop
|
|
1904
|
+
// also ends the fling at speed, so a slow frame would read as
|
|
1905
|
+
// a catch and the tail would drop the command.)
|
|
1906
|
+
this._reportedOverscroll) {
|
|
1907
|
+
return;
|
|
1908
|
+
}
|
|
1909
|
+
this._iosGesture.end();
|
|
1910
|
+
this._flushHoldIfReady(true);
|
|
1911
|
+
this._writeAwaitingCommand();
|
|
1912
|
+
});
|
|
1913
|
+
this.scrollState = {
|
|
1914
|
+
...target,
|
|
1915
|
+
startedAt: this.now(),
|
|
1916
|
+
lastTargetOffset: offset,
|
|
1917
|
+
stableFrames: 0,
|
|
1918
|
+
phase: "queued",
|
|
1919
|
+
behavior,
|
|
1920
|
+
samples: []
|
|
1921
|
+
};
|
|
1922
|
+
this.scheduleScrollReconcile();
|
|
1923
|
+
return;
|
|
1924
|
+
}
|
|
1925
|
+
this._iosGesture.end();
|
|
1926
|
+
}
|
|
1927
|
+
this.scrollState = {
|
|
1928
|
+
...target,
|
|
1929
|
+
startedAt: this.now(),
|
|
1930
|
+
lastTargetOffset: offset,
|
|
1931
|
+
stableFrames: 0,
|
|
1932
|
+
behavior,
|
|
1933
|
+
phase: initialScrollPhase(
|
|
1934
|
+
behavior,
|
|
1935
|
+
target.index != null && approxEqual(offset, this.getScrollOffset())
|
|
1936
|
+
)
|
|
1937
|
+
};
|
|
1938
|
+
this._scrollToOffset(offset, { behavior });
|
|
1939
|
+
this.scheduleScrollReconcile();
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
const findNearestBinarySearch = (low, high, getCurrentValue, value) => {
|
|
1943
|
+
while (low <= high) {
|
|
1944
|
+
const middle = (low + high) / 2 | 0;
|
|
1945
|
+
const currentValue = getCurrentValue(middle);
|
|
1946
|
+
if (currentValue < value) {
|
|
1947
|
+
low = middle + 1;
|
|
1948
|
+
} else if (currentValue > value) {
|
|
1949
|
+
high = middle - 1;
|
|
1950
|
+
} else {
|
|
1951
|
+
return middle;
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
if (low > 0) {
|
|
1955
|
+
return low - 1;
|
|
1956
|
+
} else {
|
|
1957
|
+
return 0;
|
|
1958
|
+
}
|
|
1959
|
+
};
|
|
1960
|
+
function findNearestBinarySearchFlat(flat, high, value) {
|
|
1961
|
+
let low = 0;
|
|
1962
|
+
while (low <= high) {
|
|
1963
|
+
const middle = (low + high) / 2 | 0;
|
|
1964
|
+
const currentValue = flat[middle * 2];
|
|
1965
|
+
if (currentValue < value) {
|
|
1966
|
+
low = middle + 1;
|
|
1967
|
+
} else if (currentValue > value) {
|
|
1968
|
+
high = middle - 1;
|
|
1969
|
+
} else {
|
|
1970
|
+
return middle;
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
return low > 0 ? low - 1 : 0;
|
|
1974
|
+
}
|
|
1975
|
+
function calculateRangeImpl(measurements, outerSize, scrollOffset, lanes, flat) {
|
|
1976
|
+
const lastIndex = measurements.length - 1;
|
|
1977
|
+
if (measurements.length <= lanes) {
|
|
1978
|
+
return { startIndex: 0, endIndex: lastIndex };
|
|
1979
|
+
}
|
|
1980
|
+
if (lanes === 1 && flat !== null) {
|
|
1981
|
+
const startIndex2 = findNearestBinarySearchFlat(
|
|
1982
|
+
flat,
|
|
1983
|
+
lastIndex,
|
|
1984
|
+
scrollOffset
|
|
1985
|
+
);
|
|
1986
|
+
let endIndex2 = startIndex2;
|
|
1987
|
+
const limit = scrollOffset + outerSize;
|
|
1988
|
+
while (endIndex2 < lastIndex && flat[endIndex2 * 2] + flat[endIndex2 * 2 + 1] < limit) {
|
|
1989
|
+
endIndex2++;
|
|
1990
|
+
}
|
|
1991
|
+
return { startIndex: startIndex2, endIndex: endIndex2 };
|
|
1992
|
+
}
|
|
1993
|
+
const getStart = (index) => measurements[index].start;
|
|
1994
|
+
let startIndex = findNearestBinarySearch(0, lastIndex, getStart, scrollOffset);
|
|
1995
|
+
let endIndex = startIndex;
|
|
1996
|
+
if (lanes === 1) {
|
|
1997
|
+
while (endIndex < lastIndex && measurements[endIndex].end < scrollOffset + outerSize) {
|
|
1998
|
+
endIndex++;
|
|
1999
|
+
}
|
|
2000
|
+
} else if (lanes > 1) {
|
|
2001
|
+
const endPerLane = Array(lanes).fill(0);
|
|
2002
|
+
while (endIndex < lastIndex && endPerLane.some((pos) => pos < scrollOffset + outerSize)) {
|
|
2003
|
+
const item = measurements[endIndex];
|
|
2004
|
+
endPerLane[item.lane] = item.end;
|
|
2005
|
+
endIndex++;
|
|
2006
|
+
}
|
|
2007
|
+
const startPerLane = Array(lanes).fill(scrollOffset + outerSize);
|
|
2008
|
+
while (startIndex >= 0 && startPerLane.some((pos) => pos >= scrollOffset)) {
|
|
2009
|
+
const item = measurements[startIndex];
|
|
2010
|
+
startPerLane[item.lane] = item.start;
|
|
2011
|
+
startIndex--;
|
|
2012
|
+
}
|
|
2013
|
+
startIndex = Math.max(0, startIndex - startIndex % lanes);
|
|
2014
|
+
endIndex = Math.min(lastIndex, endIndex + (lanes - 1 - endIndex % lanes));
|
|
2015
|
+
}
|
|
2016
|
+
return { startIndex, endIndex };
|
|
2017
|
+
}
|
|
2018
|
+
|
|
2019
|
+
/**
|
|
2020
|
+
* Decides which rows of a swirl-table to draw and positions them. The consumer
|
|
2021
|
+
* renders the rows, identified by `data-index`. Padding on the table body
|
|
2022
|
+
* stands in for the rows not drawn. A row's margin-top fills the gap before a
|
|
2023
|
+
* kept row far from the visible ones.
|
|
2024
|
+
*/
|
|
2025
|
+
class SwirlTableVirtualizer {
|
|
2026
|
+
constructor(bodyEl, scrollElement, config, onIndexesChange) {
|
|
2027
|
+
this.bodyEl = bodyEl;
|
|
2028
|
+
this.scrollElement = scrollElement;
|
|
2029
|
+
this.config = config;
|
|
2030
|
+
this.onIndexesChange = onIndexesChange;
|
|
2031
|
+
// Index each row was last measured for. Rows can be reused for other indexes.
|
|
2032
|
+
this.measuredIndexes = new WeakMap();
|
|
2033
|
+
this.observedRows = new Set();
|
|
2034
|
+
/**
|
|
2035
|
+
* Own observer, because the virtualizer's `measureElement` caches elements
|
|
2036
|
+
* by index and stops observing reused ones.
|
|
2037
|
+
*/
|
|
2038
|
+
this.resizeObserver = new ResizeObserver((entries) => this.resizeRows(entries.map(({ borderBoxSize, target }) => ({
|
|
2039
|
+
row: target,
|
|
2040
|
+
height: borderBoxSize[0].blockSize,
|
|
2041
|
+
}))));
|
|
2042
|
+
this.indexes = [];
|
|
2043
|
+
this.isResizingRows = false;
|
|
2044
|
+
this.hasChangeWhileResizing = false;
|
|
2045
|
+
this.bodyEl.style.overflowAnchor = "none";
|
|
2046
|
+
this.scrollMargin = this.measureScrollMargin();
|
|
2047
|
+
this.virtualizer = new Virtualizer(this.options());
|
|
2048
|
+
this.unmount = this.virtualizer._didMount();
|
|
2049
|
+
this.virtualizer._willUpdate();
|
|
2050
|
+
this.update();
|
|
2051
|
+
}
|
|
2052
|
+
setConfig(config) {
|
|
2053
|
+
this.config = config;
|
|
2054
|
+
this.applyOptions();
|
|
2055
|
+
}
|
|
2056
|
+
/**
|
|
2057
|
+
* Call after rows were added, removed or re-indexed. Measures new rows and
|
|
2058
|
+
* positions all rows.
|
|
2059
|
+
*/
|
|
2060
|
+
sync() {
|
|
2061
|
+
this.updateScrollMargin();
|
|
2062
|
+
this.observedRows.forEach((row) => {
|
|
2063
|
+
if (!row.isConnected) {
|
|
2064
|
+
this.resizeObserver.unobserve(row);
|
|
2065
|
+
this.observedRows.delete(row);
|
|
2066
|
+
}
|
|
2067
|
+
});
|
|
2068
|
+
const rows = this.getRenderedRows();
|
|
2069
|
+
rows.forEach((row) => {
|
|
2070
|
+
if (!this.observedRows.has(row)) {
|
|
2071
|
+
this.observedRows.add(row);
|
|
2072
|
+
this.resizeObserver.observe(row);
|
|
2073
|
+
}
|
|
2074
|
+
});
|
|
2075
|
+
// Read all heights before resizeRows() writes styles, so the browser lays
|
|
2076
|
+
// out the table once instead of once per row.
|
|
2077
|
+
this.resizeRows(rows
|
|
2078
|
+
.filter((row) => this.measuredIndexes.get(row) !== getRowIndex(row))
|
|
2079
|
+
.map((row) => ({ row, height: row.getBoundingClientRect().height })));
|
|
2080
|
+
this.layout();
|
|
2081
|
+
}
|
|
2082
|
+
destroy() {
|
|
2083
|
+
this.unmount();
|
|
2084
|
+
this.resizeObserver.disconnect();
|
|
2085
|
+
this.observedRows.clear();
|
|
2086
|
+
this.bodyEl.style.overflowAnchor = "";
|
|
2087
|
+
this.bodyEl.style.paddingTop = "";
|
|
2088
|
+
this.bodyEl.style.paddingBottom = "";
|
|
2089
|
+
this.getRenderedRows().forEach((row) => (row.style.marginTop = ""));
|
|
2090
|
+
}
|
|
2091
|
+
applyOptions() {
|
|
2092
|
+
this.virtualizer.setOptions(this.options());
|
|
2093
|
+
this.virtualizer._willUpdate();
|
|
2094
|
+
this.update();
|
|
2095
|
+
}
|
|
2096
|
+
update() {
|
|
2097
|
+
// applyOptions() calls update() again with the new margin.
|
|
2098
|
+
if (this.updateScrollMargin()) {
|
|
2099
|
+
return;
|
|
2100
|
+
}
|
|
2101
|
+
const indexes = this.virtualizer
|
|
2102
|
+
.getVirtualItems()
|
|
2103
|
+
.map(({ index }) => index);
|
|
2104
|
+
if (!equalIndexes(indexes, this.indexes)) {
|
|
2105
|
+
this.indexes = indexes;
|
|
2106
|
+
this.onIndexesChange(indexes);
|
|
2107
|
+
}
|
|
2108
|
+
this.layout();
|
|
2109
|
+
}
|
|
2110
|
+
/**
|
|
2111
|
+
* Measures where the rows start again, as content above the table can
|
|
2112
|
+
* change height, e.g. a toolbar appears. Returns whether it changed.
|
|
2113
|
+
*/
|
|
2114
|
+
updateScrollMargin() {
|
|
2115
|
+
const scrollMargin = this.measureScrollMargin();
|
|
2116
|
+
if (Math.abs(scrollMargin - this.scrollMargin) < 1) {
|
|
2117
|
+
return false;
|
|
2118
|
+
}
|
|
2119
|
+
this.scrollMargin = scrollMargin;
|
|
2120
|
+
this.applyOptions();
|
|
2121
|
+
return true;
|
|
2122
|
+
}
|
|
2123
|
+
/**
|
|
2124
|
+
* Reports each row's height for its current index. Every resize makes the
|
|
2125
|
+
* virtualizer call onChange, so the rows are positioned once at the end
|
|
2126
|
+
* instead of after each resize.
|
|
2127
|
+
*/
|
|
2128
|
+
resizeRows(sizes) {
|
|
2129
|
+
this.isResizingRows = true;
|
|
2130
|
+
try {
|
|
2131
|
+
sizes.forEach(({ row, height }) => {
|
|
2132
|
+
const index = getRowIndex(row);
|
|
2133
|
+
// An unrendered row has no height yet. Counting it as 0 would draw
|
|
2134
|
+
// every row. The ResizeObserver measures it later.
|
|
2135
|
+
if (!row.isConnected || Number.isNaN(index) || height === 0) {
|
|
2136
|
+
return;
|
|
2137
|
+
}
|
|
2138
|
+
this.measuredIndexes.set(row, index);
|
|
2139
|
+
this.virtualizer.resizeItem(index, height);
|
|
2140
|
+
});
|
|
2141
|
+
}
|
|
2142
|
+
finally {
|
|
2143
|
+
this.isResizingRows = false;
|
|
2144
|
+
}
|
|
2145
|
+
if (this.hasChangeWhileResizing) {
|
|
2146
|
+
this.hasChangeWhileResizing = false;
|
|
2147
|
+
this.update();
|
|
2148
|
+
}
|
|
2149
|
+
}
|
|
2150
|
+
handleChange() {
|
|
2151
|
+
if (this.isResizingRows) {
|
|
2152
|
+
this.hasChangeWhileResizing = true;
|
|
2153
|
+
return;
|
|
2154
|
+
}
|
|
2155
|
+
this.update();
|
|
2156
|
+
}
|
|
2157
|
+
layout() {
|
|
2158
|
+
const items = new Map(this.virtualizer.getVirtualItems().map((item) => [item.index, item]));
|
|
2159
|
+
let cursor;
|
|
2160
|
+
this.getRenderedRows().forEach((row) => {
|
|
2161
|
+
const index = getRowIndex(row);
|
|
2162
|
+
const item = items.get(index);
|
|
2163
|
+
// The consumer hasn't removed this row yet.
|
|
2164
|
+
if (!item) {
|
|
2165
|
+
return;
|
|
2166
|
+
}
|
|
2167
|
+
// aria-rowindex starts at 1, which is the header row.
|
|
2168
|
+
if (row.index !== index + 2) {
|
|
2169
|
+
row.index = index + 2;
|
|
2170
|
+
}
|
|
2171
|
+
const start = item.start - this.scrollMargin;
|
|
2172
|
+
if (cursor === undefined) {
|
|
2173
|
+
setStyle(this.bodyEl, "paddingTop", start);
|
|
2174
|
+
setStyle(row, "marginTop", 0);
|
|
2175
|
+
}
|
|
2176
|
+
else {
|
|
2177
|
+
setStyle(row, "marginTop", start - cursor);
|
|
2178
|
+
}
|
|
2179
|
+
cursor = item.end - this.scrollMargin;
|
|
2180
|
+
});
|
|
2181
|
+
if (cursor === undefined) {
|
|
2182
|
+
setStyle(this.bodyEl, "paddingTop", 0);
|
|
2183
|
+
}
|
|
2184
|
+
setStyle(this.bodyEl, "paddingBottom", this.virtualizer.getTotalSize() - (cursor ?? 0));
|
|
2185
|
+
}
|
|
2186
|
+
getRenderedRows() {
|
|
2187
|
+
return Array.from(this.bodyEl.querySelectorAll("swirl-table-row[data-index]"));
|
|
2188
|
+
}
|
|
2189
|
+
options() {
|
|
2190
|
+
const { estimatedRowHeight, keptIndexes, overscan, rowCount } = this.config;
|
|
2191
|
+
const isWindow = this.scrollElement instanceof Window;
|
|
2192
|
+
return {
|
|
2193
|
+
count: rowCount,
|
|
2194
|
+
estimateSize: () => estimatedRowHeight,
|
|
2195
|
+
getScrollElement: () => this.scrollElement,
|
|
2196
|
+
// defaults to 0, which makes the virtualizer scroll to the top when it
|
|
2197
|
+
// subscribes to the scroll container.
|
|
2198
|
+
initialOffset: () => this.scrollElement instanceof Window
|
|
2199
|
+
? this.scrollElement.scrollY
|
|
2200
|
+
: this.scrollElement.scrollTop,
|
|
2201
|
+
overscan,
|
|
2202
|
+
scrollMargin: this.scrollMargin,
|
|
2203
|
+
rangeExtractor: (range) => mergeIndexes(defaultRangeExtractor(range), keptIndexes.filter((index) => Number.isInteger(index) && index >= 0 && index < rowCount)),
|
|
2204
|
+
observeElementRect: (isWindow
|
|
2205
|
+
? observeWindowRect
|
|
2206
|
+
: observeElementRect),
|
|
2207
|
+
observeElementOffset: (isWindow
|
|
2208
|
+
? observeWindowOffset
|
|
2209
|
+
: observeElementOffset),
|
|
2210
|
+
scrollToFn: (isWindow
|
|
2211
|
+
? windowScroll
|
|
2212
|
+
: elementScroll),
|
|
2213
|
+
onChange: () => this.handleChange(),
|
|
2214
|
+
};
|
|
2215
|
+
}
|
|
2216
|
+
/** Offset of the first row from the top of the scrolled content. */
|
|
2217
|
+
measureScrollMargin() {
|
|
2218
|
+
const bodyTop = this.bodyEl.getBoundingClientRect().top;
|
|
2219
|
+
if (this.scrollElement instanceof Window) {
|
|
2220
|
+
return bodyTop + this.scrollElement.scrollY;
|
|
2221
|
+
}
|
|
2222
|
+
return (bodyTop -
|
|
2223
|
+
this.scrollElement.getBoundingClientRect().top +
|
|
2224
|
+
this.scrollElement.scrollTop);
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
function getRowIndex(row) {
|
|
2228
|
+
return Number(row.dataset.index);
|
|
2229
|
+
}
|
|
2230
|
+
function mergeIndexes(a, b) {
|
|
2231
|
+
return [...new Set([...a, ...b])].sort((x, y) => x - y);
|
|
2232
|
+
}
|
|
2233
|
+
function equalIndexes(a, b) {
|
|
2234
|
+
return a.length === b.length && a.every((index, i) => index === b[i]);
|
|
2235
|
+
}
|
|
2236
|
+
function setStyle(el, property, px) {
|
|
2237
|
+
const value = px > 0 ? `${px}px` : "";
|
|
2238
|
+
if (el.style[property] !== value) {
|
|
2239
|
+
el.style[property] = value;
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
|
|
92
2243
|
const swirlTableCss = () => `.sc-swirl-table-h{--swirl-table-shadow-rgba:rgba(23, 23, 23, 0.2);position:relative;display:block}.sc-swirl-table-h *.sc-swirl-table{box-sizing:border-box}html.theme-dark.sc-swirl-table-h,html.theme-dark .sc-swirl-table-h{--swirl-table-shadow-rgba:rgba(0, 0, 0, 0.2)}.table--keyboard-move.sc-swirl-table:focus-within{--swirl-table-moving-row-border:var(--s-border-width-default) solid var(--s-border-highlight)}.table--show-empty-state.sc-swirl-table .table__empty-row.sc-swirl-table{display:flex}.table__container.sc-swirl-table{position:relative;overflow:auto;width:100%}.table__container--scrolled.sc-swirl-table{--swirl-table-sticky-right-shadow:4px 0 16px -4px var(--swirl-table-shadow-rgba), 2px 0 4px -2px var(--swirl-table-shadow-rgba)}.table__container--scrollable.sc-swirl-table:not(.table__container--scrolled-to-end){--swirl-table-sticky-left-shadow:0px 4px 16px 0px var(--swirl-table-shadow-rgba), 0px 1px 4px 0px var(--swirl-table-shadow-rgba)}.table__table.sc-swirl-table{width:-moz-max-content;width:max-content;min-width:max(20rem, 100%)}.table__header.sc-swirl-table-s>*,.table__header .sc-swirl-table-s>*{display:flex}.table__empty-row.sc-swirl-table{display:none}.table__empty-row-cell.sc-swirl-table{display:flex;overflow:auto;padding-top:var(--s-space-8);padding-right:var(--s-space-16);padding-bottom:var(--s-space-8);padding-left:var(--s-space-16);flex-basis:0;flex-grow:1;flex-shrink:1;align-items:center;background-color:var(--s-surface-default)}.table__empty-row-cell.sc-swirl-table>*.sc-swirl-table{flex-grow:1}`;
|
|
93
2244
|
|
|
94
2245
|
const defaultDragDropInstructions = {
|
|
@@ -101,13 +2252,19 @@ const SwirlTable = class {
|
|
|
101
2252
|
constructor(hostRef) {
|
|
102
2253
|
index$1.registerInstance(this, hostRef);
|
|
103
2254
|
this.dropRow = index$1.createEvent(this, "dropRow", 7);
|
|
2255
|
+
this.virtualizationRowsChange = index$1.createEvent(this, "virtualizationRowsChange", 7);
|
|
104
2256
|
this.dragDropInstructions = defaultDragDropInstructions;
|
|
105
2257
|
this.emptyStateLabel = "No results found.";
|
|
2258
|
+
/** Height in px assumed for rows not drawn yet. */
|
|
2259
|
+
this.virtualizationEstimatedRowHeight = 56;
|
|
2260
|
+
/** Number of extra rows drawn above and below the visible ones. */
|
|
2261
|
+
this.virtualizationOverscan = 10;
|
|
2262
|
+
/**
|
|
2263
|
+
* Indexes of rows to keep drawn when out of view, e.g. a row with an open
|
|
2264
|
+
* menu. The focused row is always kept.
|
|
2265
|
+
*/
|
|
2266
|
+
this.virtualizationKeepRowsRendered = [];
|
|
106
2267
|
this.liveRegionText = "";
|
|
107
|
-
this.triggerRerender = utils.debounce(async () => {
|
|
108
|
-
await this.updateLayout();
|
|
109
|
-
this.updateEmptyState();
|
|
110
|
-
}, 0, true);
|
|
111
2268
|
this.updateLayout = debouncePromise(async () => {
|
|
112
2269
|
this.resetCellStyles();
|
|
113
2270
|
this.resetColumnStyles();
|
|
@@ -122,6 +2279,7 @@ const SwirlTable = class {
|
|
|
122
2279
|
this.updateScrolledState();
|
|
123
2280
|
};
|
|
124
2281
|
this.onFocus = (event) => {
|
|
2282
|
+
this.trackFocusedRow(event.target);
|
|
125
2283
|
if (this.movingViaKeyboard) {
|
|
126
2284
|
const movingRow = this.el.querySelector(".table-row--moving");
|
|
127
2285
|
if (movingRow) {
|
|
@@ -135,6 +2293,9 @@ const SwirlTable = class {
|
|
|
135
2293
|
};
|
|
136
2294
|
this.onBlur = (event) => {
|
|
137
2295
|
const newlyFocusedElement = event.relatedTarget;
|
|
2296
|
+
if (!this.el.contains(newlyFocusedElement)) {
|
|
2297
|
+
this.trackFocusedRow(null);
|
|
2298
|
+
}
|
|
138
2299
|
const focusedDragHandle = !!newlyFocusedElement?.closest(this.dragDropHandle);
|
|
139
2300
|
if (this.el.contains(newlyFocusedElement) && focusedDragHandle) {
|
|
140
2301
|
return;
|
|
@@ -177,6 +2338,7 @@ const SwirlTable = class {
|
|
|
177
2338
|
async componentDidLoad() {
|
|
178
2339
|
this.setupIntersectionObserver();
|
|
179
2340
|
this.setupMutationObservers();
|
|
2341
|
+
this.updateVirtualizer();
|
|
180
2342
|
queueMicrotask(() => {
|
|
181
2343
|
this.setupDragDrop();
|
|
182
2344
|
});
|
|
@@ -186,6 +2348,60 @@ const SwirlTable = class {
|
|
|
186
2348
|
this.columnMutationObserver?.disconnect();
|
|
187
2349
|
this.rowMutationObserver?.disconnect();
|
|
188
2350
|
this.sortable?.destroy();
|
|
2351
|
+
this.destroyVirtualizer();
|
|
2352
|
+
}
|
|
2353
|
+
handleVirtualizationChange() {
|
|
2354
|
+
this.updateVirtualizer();
|
|
2355
|
+
}
|
|
2356
|
+
get virtualizerConfig() {
|
|
2357
|
+
if (!this.enableVirtualization || !this.virtualizationRowCount) {
|
|
2358
|
+
return undefined;
|
|
2359
|
+
}
|
|
2360
|
+
return {
|
|
2361
|
+
estimatedRowHeight: this.virtualizationEstimatedRowHeight,
|
|
2362
|
+
keptIndexes: this.focusedRowIndex === undefined
|
|
2363
|
+
? this.virtualizationKeepRowsRendered ?? []
|
|
2364
|
+
: [
|
|
2365
|
+
...(this.virtualizationKeepRowsRendered ?? []),
|
|
2366
|
+
this.focusedRowIndex,
|
|
2367
|
+
],
|
|
2368
|
+
overscan: this.virtualizationOverscan,
|
|
2369
|
+
rowCount: this.virtualizationRowCount,
|
|
2370
|
+
};
|
|
2371
|
+
}
|
|
2372
|
+
updateVirtualizer() {
|
|
2373
|
+
if (!this.bodyEl) {
|
|
2374
|
+
return;
|
|
2375
|
+
}
|
|
2376
|
+
const config = this.virtualizerConfig;
|
|
2377
|
+
if (!config) {
|
|
2378
|
+
const hadVirtualizer = Boolean(this.virtualizer);
|
|
2379
|
+
this.destroyVirtualizer();
|
|
2380
|
+
// tell the app to clear its rows when they drop to 0. checking for a
|
|
2381
|
+
// previous virtualizer emits only once, not on every focus change.
|
|
2382
|
+
if (this.enableVirtualization && hadVirtualizer) {
|
|
2383
|
+
queueMicrotask(() => this.virtualizationRowsChange.emit({ indexes: [] }));
|
|
2384
|
+
}
|
|
2385
|
+
return;
|
|
2386
|
+
}
|
|
2387
|
+
if (this.virtualizer) {
|
|
2388
|
+
this.virtualizer.setConfig(config);
|
|
2389
|
+
// find the scroll container when more rows make it overflow
|
|
2390
|
+
if (this.virtualizer.scrollElement === window) {
|
|
2391
|
+
this.updateScrollParent();
|
|
2392
|
+
}
|
|
2393
|
+
return;
|
|
2394
|
+
}
|
|
2395
|
+
// reserve the full height first, so the scroll container overflows and
|
|
2396
|
+
// can be found.
|
|
2397
|
+
this.bodyEl.style.paddingBottom = `${config.rowCount * config.estimatedRowHeight}px`;
|
|
2398
|
+
this.virtualizer = new SwirlTableVirtualizer(this.bodyEl, utils.getScrollParent(this.el), config, (indexes) =>
|
|
2399
|
+
// emit async, so frameworks don't get it mid-render.
|
|
2400
|
+
queueMicrotask(() => this.virtualizationRowsChange.emit({ indexes })));
|
|
2401
|
+
}
|
|
2402
|
+
destroyVirtualizer() {
|
|
2403
|
+
this.virtualizer?.destroy();
|
|
2404
|
+
this.virtualizer = undefined;
|
|
189
2405
|
}
|
|
190
2406
|
handleEnableDragDropChange() {
|
|
191
2407
|
queueMicrotask(() => {
|
|
@@ -221,15 +2437,21 @@ const SwirlTable = class {
|
|
|
221
2437
|
});
|
|
222
2438
|
this.rowMutationObserver = new MutationObserver((mutations) => {
|
|
223
2439
|
const rowWasAddedOrRemoved = mutations.some((mutation) => mutation.addedNodes.length || mutation.removedNodes.length);
|
|
2440
|
+
// rows tracked by position are reused: only their data-index changes.
|
|
2441
|
+
const rowIndexChanged = mutations.some((mutation) => mutation.type === "attributes");
|
|
224
2442
|
if (rowWasAddedOrRemoved) {
|
|
225
2443
|
this.updateEmptyState();
|
|
226
2444
|
this.setupDragDrop();
|
|
227
2445
|
}
|
|
2446
|
+
if (rowWasAddedOrRemoved || rowIndexChanged) {
|
|
2447
|
+
this.syncVirtualizedRows({ layOutCells: rowWasAddedOrRemoved });
|
|
2448
|
+
}
|
|
228
2449
|
});
|
|
229
2450
|
this.startRowMutationObserver();
|
|
230
2451
|
}
|
|
231
2452
|
startRowMutationObserver() {
|
|
232
2453
|
this.rowMutationObserver?.observe(this.bodyEl, {
|
|
2454
|
+
attributeFilter: ["data-index"],
|
|
233
2455
|
childList: true,
|
|
234
2456
|
subtree: true,
|
|
235
2457
|
});
|
|
@@ -291,10 +2513,23 @@ const SwirlTable = class {
|
|
|
291
2513
|
// Delay layout update to ensure the container is fully visible,
|
|
292
2514
|
// especially if it was initially rendered in a modal.
|
|
293
2515
|
setTimeout(async () => {
|
|
2516
|
+
this.updateScrollParent();
|
|
294
2517
|
await this.updateLayout();
|
|
295
2518
|
}, 100);
|
|
296
2519
|
}
|
|
297
2520
|
}
|
|
2521
|
+
/**
|
|
2522
|
+
* A table hidden on load falls back to the window. Look for the scroll
|
|
2523
|
+
* container again once it is visible.
|
|
2524
|
+
*/
|
|
2525
|
+
updateScrollParent() {
|
|
2526
|
+
if (!this.virtualizer ||
|
|
2527
|
+
utils.getScrollParent(this.el) === this.virtualizer.scrollElement) {
|
|
2528
|
+
return;
|
|
2529
|
+
}
|
|
2530
|
+
this.destroyVirtualizer();
|
|
2531
|
+
this.updateVirtualizer();
|
|
2532
|
+
}
|
|
298
2533
|
async componentDidRender() {
|
|
299
2534
|
await this.updateLayout();
|
|
300
2535
|
this.updateEmptyState();
|
|
@@ -306,7 +2541,10 @@ const SwirlTable = class {
|
|
|
306
2541
|
* Force a re-render of the table
|
|
307
2542
|
*/
|
|
308
2543
|
async rerender() {
|
|
309
|
-
|
|
2544
|
+
// updateLayout is debounced with a trailing call, so a row that loads
|
|
2545
|
+
// while a layout runs still gets laid out.
|
|
2546
|
+
await this.updateLayout();
|
|
2547
|
+
this.updateEmptyState();
|
|
310
2548
|
}
|
|
311
2549
|
resetEmptyRowStyles() {
|
|
312
2550
|
const emptyRow = this.el.querySelector(".table__empty-row");
|
|
@@ -408,11 +2646,14 @@ const SwirlTable = class {
|
|
|
408
2646
|
layOutCellsAndColumns() {
|
|
409
2647
|
const columns = this.getColumns();
|
|
410
2648
|
const cells = this.getCells();
|
|
2649
|
+
// Measure every column before sizing any cell. The table is as wide as its
|
|
2650
|
+
// widest row, so sizing one column's cells moves the columns not measured
|
|
2651
|
+
// yet.
|
|
2652
|
+
const columnProperties = columns.map((column, colIndex) => this.calculateColumnProperties(column, columns, colIndex));
|
|
411
2653
|
columns.forEach((column, colIndex) => {
|
|
412
2654
|
const cellsOfColumn = this.getCellsForColumn(cells, columns, colIndex);
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
this.applyColumnStyles(column, columnProperties);
|
|
2655
|
+
cellsOfColumn.forEach((cell) => this.applyCellStyles(cell, column, columnProperties[colIndex]));
|
|
2656
|
+
this.applyColumnStyles(column, columnProperties[colIndex]);
|
|
416
2657
|
});
|
|
417
2658
|
}
|
|
418
2659
|
getCellsForColumn(cells, columns, colIndex) {
|
|
@@ -479,6 +2720,10 @@ const SwirlTable = class {
|
|
|
479
2720
|
.some((column) => column.sticky);
|
|
480
2721
|
}
|
|
481
2722
|
updateEmptyState() {
|
|
2723
|
+
if (this.enableVirtualization && this.virtualizationRowCount) {
|
|
2724
|
+
this.empty = false;
|
|
2725
|
+
return;
|
|
2726
|
+
}
|
|
482
2727
|
const rowsContainer = this.el.querySelector('[slot="rows"]');
|
|
483
2728
|
this.empty = !Boolean(rowsContainer) || rowsContainer.children.length === 0;
|
|
484
2729
|
}
|
|
@@ -574,16 +2819,64 @@ const SwirlTable = class {
|
|
|
574
2819
|
handle.querySelector("button")?.focus();
|
|
575
2820
|
}
|
|
576
2821
|
}
|
|
2822
|
+
/**
|
|
2823
|
+
* Measures and positions rows after they were added, removed or re-indexed.
|
|
2824
|
+
* The focused row's index is read again first, as it changes when e.g. a row
|
|
2825
|
+
* is inserted above it.
|
|
2826
|
+
*
|
|
2827
|
+
* Added rows and cells are laid out too: a row calls `rerender()` only when
|
|
2828
|
+
* it first loads, so cells added to a drawn row would get no width.
|
|
2829
|
+
*/
|
|
2830
|
+
syncVirtualizedRows({ layOutCells }) {
|
|
2831
|
+
if (!this.virtualizer) {
|
|
2832
|
+
return;
|
|
2833
|
+
}
|
|
2834
|
+
this.trackFocusedRow(this.el.querySelector("swirl-table-row[data-index]:focus-within"));
|
|
2835
|
+
this.virtualizer.sync();
|
|
2836
|
+
if (layOutCells) {
|
|
2837
|
+
this.updateLayout();
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
/** Keeps the focused row drawn, so it doesn't lose focus. */
|
|
2841
|
+
trackFocusedRow(target) {
|
|
2842
|
+
if (!this.enableVirtualization) {
|
|
2843
|
+
return;
|
|
2844
|
+
}
|
|
2845
|
+
const index = target?.closest("swirl-table-row[data-index]")
|
|
2846
|
+
?.dataset.index;
|
|
2847
|
+
const focusedRowIndex = index === undefined ? undefined : Number(index);
|
|
2848
|
+
if (focusedRowIndex !== this.focusedRowIndex) {
|
|
2849
|
+
this.focusedRowIndex = focusedRowIndex;
|
|
2850
|
+
this.updateVirtualizer();
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
577
2853
|
render() {
|
|
578
2854
|
const hasEmptyStateSlotAssignment = Boolean(this.el.querySelector('[slot="empty"]'));
|
|
579
2855
|
const className = index.classnames("table", {
|
|
580
2856
|
"table--show-empty-state": this.empty && !this.loading,
|
|
581
2857
|
"table--keyboard-move": this.movingViaKeyboard,
|
|
582
2858
|
});
|
|
583
|
-
return (index$1.h(index$1.Host, { key: '
|
|
2859
|
+
return (index$1.h(index$1.Host, { key: '24e14d3eb739219aa9965fe16ccff5e9dae28180' }, index$1.h("div", { key: '25deaf84f1bb1131977e6e07f45ac2301585354d', class: className }, this.enableDragDrop && (index$1.h("swirl-visually-hidden", { key: '277292ebfaa8c1ada6c5c982b214efbda5f2f8a9' }, index$1.h("span", { key: 'e07ea9745ee40064160001ed0d702971cce78efa', "aria-live": "assertive" }, this.liveRegionText))), index$1.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 }, index$1.h("div", { key: 'b7d1bb696755df6fd20983eebf6b800685a59983', "aria-describedby": Boolean(this.caption) ? "caption" : undefined, "aria-label": this.label, "aria-rowcount": this.enableVirtualization && this.virtualizationRowCount
|
|
2860
|
+
? this.virtualizationRowCount + 1
|
|
2861
|
+
: undefined, role: "table", class: "table__table" }, this.caption && (index$1.h("swirl-visually-hidden", { key: '013e2aff85772e44a3cdbb67dc4479d8eb581ffc' }, index$1.h("div", { key: '9f1b0dda1fe39b823e6df87dae2285e71a738265', id: "caption" }, this.caption))), index$1.h("div", { key: '9cd533c163bd42c8ebb4f641a91860170a2ca3e3', role: "rowgroup" }, index$1.h("div", { key: '0516399b0ed45a6f8e817fa9f342a188738fca0d', class: "table__header", "aria-rowindex": this.enableVirtualization ? 1 : undefined, ref: (el) => (this.headerEl = el), role: "row" }, index$1.h("slot", { key: '9924e00f3ac41423e4cf183ad3f0c993f9235d83', name: "columns" }))), index$1.h("div", { key: '0be013c95ef6910e4a27b388282403843cd520ea', class: "table__body", ref: (el) => (this.bodyEl = el) }, index$1.h("slot", { key: 'f5660dcec786b0091ec3cbe38407948173146147', name: "rows" }), index$1.h("div", { key: 'db077c06ab60df00e149468bb54f52ebeb40cd66', class: "table__empty-row", role: "row" }, index$1.h("div", { key: 'd7b514fe706e96437496ee4f7f5b2b0052943629', "aria-colspan": this.getColumns().length, class: "table__empty-row-cell", role: "cell" }, index$1.h("slot", { key: '8b1c1f506c3a5479def5c178856900103a05e1d6', name: "empty" }), !hasEmptyStateSlotAssignment && (index$1.h("swirl-text", { key: 'f94bccc0907f8052c63cebdfb7b99c8708d1ab76', align: "center", size: "sm" }, this.emptyStateLabel))))))))));
|
|
584
2862
|
}
|
|
585
2863
|
get el() { return index$1.getElement(this); }
|
|
586
2864
|
static get watchers() { return {
|
|
2865
|
+
"enableVirtualization": [{
|
|
2866
|
+
"handleVirtualizationChange": 0
|
|
2867
|
+
}],
|
|
2868
|
+
"virtualizationRowCount": [{
|
|
2869
|
+
"handleVirtualizationChange": 0
|
|
2870
|
+
}],
|
|
2871
|
+
"virtualizationEstimatedRowHeight": [{
|
|
2872
|
+
"handleVirtualizationChange": 0
|
|
2873
|
+
}],
|
|
2874
|
+
"virtualizationOverscan": [{
|
|
2875
|
+
"handleVirtualizationChange": 0
|
|
2876
|
+
}],
|
|
2877
|
+
"virtualizationKeepRowsRendered": [{
|
|
2878
|
+
"handleVirtualizationChange": 0
|
|
2879
|
+
}],
|
|
587
2880
|
"enableDragDrop": [{
|
|
588
2881
|
"handleEnableDragDropChange": 0
|
|
589
2882
|
}]
|