@ni/nimble-components 18.1.1 → 18.1.2
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.
|
@@ -26915,7 +26915,8 @@
|
|
|
26915
26915
|
* @license MIT
|
|
26916
26916
|
*/
|
|
26917
26917
|
function memo(getDeps, fn, opts) {
|
|
26918
|
-
var
|
|
26918
|
+
var _opts$initialDeps;
|
|
26919
|
+
var deps = (_opts$initialDeps = opts.initialDeps) != null ? _opts$initialDeps : [];
|
|
26919
26920
|
var result;
|
|
26920
26921
|
return function () {
|
|
26921
26922
|
var depTime;
|
|
@@ -26930,11 +26931,7 @@
|
|
|
26930
26931
|
deps = newDeps;
|
|
26931
26932
|
var resultTime;
|
|
26932
26933
|
if (opts.key && opts.debug != null && opts.debug()) resultTime = Date.now();
|
|
26933
|
-
|
|
26934
|
-
fArgs[_key] = arguments[_key];
|
|
26935
|
-
}
|
|
26936
|
-
result = fn.apply(void 0, newDeps.concat([fArgs]));
|
|
26937
|
-
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
|
|
26934
|
+
result = fn.apply(void 0, newDeps);
|
|
26938
26935
|
if (opts.key && opts.debug != null && opts.debug()) {
|
|
26939
26936
|
var depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
|
|
26940
26937
|
var resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
|
|
@@ -26948,9 +26945,20 @@
|
|
|
26948
26945
|
};
|
|
26949
26946
|
console.info("%c\u23F1 " + pad(resultEndTime, 5) + " /" + pad(depEndTime, 5) + " ms", "\n font-size: .6rem;\n font-weight: bold;\n color: hsl(" + Math.max(0, Math.min(120 - 120 * resultFpsPercentage, 120)) + "deg 100% 31%);", opts == null ? void 0 : opts.key);
|
|
26950
26947
|
}
|
|
26948
|
+
opts == null ? void 0 : opts.onChange == null ? void 0 : opts.onChange(result);
|
|
26951
26949
|
return result;
|
|
26952
26950
|
};
|
|
26953
26951
|
}
|
|
26952
|
+
function notUndefined(value, msg) {
|
|
26953
|
+
if (value === undefined) {
|
|
26954
|
+
throw new Error("Unexpected undefined" + (msg ? ": " + msg : ''));
|
|
26955
|
+
} else {
|
|
26956
|
+
return value;
|
|
26957
|
+
}
|
|
26958
|
+
}
|
|
26959
|
+
var approxEqual = function approxEqual(a, b) {
|
|
26960
|
+
return Math.abs(a - b) < 1;
|
|
26961
|
+
};
|
|
26954
26962
|
|
|
26955
26963
|
/**
|
|
26956
26964
|
* virtual-core
|
|
@@ -27148,7 +27156,7 @@
|
|
|
27148
27156
|
});
|
|
27149
27157
|
_this.unsubs.push(_this.options.observeElementRect(_this, function (rect) {
|
|
27150
27158
|
_this.scrollRect = rect;
|
|
27151
|
-
_this.
|
|
27159
|
+
_this.maybeNotify();
|
|
27152
27160
|
}));
|
|
27153
27161
|
_this.unsubs.push(_this.options.observeElementOffset(_this, function (offset) {
|
|
27154
27162
|
_this.scrollAdjustments = 0;
|
|
@@ -27159,20 +27167,15 @@
|
|
|
27159
27167
|
clearTimeout(_this.isScrollingTimeoutId);
|
|
27160
27168
|
_this.isScrollingTimeoutId = null;
|
|
27161
27169
|
}
|
|
27162
|
-
|
|
27163
|
-
if (_this.isScrolling !== isScrolling) {
|
|
27164
|
-
_this.isScrolling = isScrolling;
|
|
27165
|
-
_this.notify();
|
|
27166
|
-
}
|
|
27167
|
-
};
|
|
27170
|
+
_this.isScrolling = true;
|
|
27168
27171
|
_this.scrollDirection = _this.scrollOffset < offset ? 'forward' : 'backward';
|
|
27169
27172
|
_this.scrollOffset = offset;
|
|
27170
|
-
_this.
|
|
27171
|
-
onIsScrollingChange(true);
|
|
27173
|
+
_this.maybeNotify();
|
|
27172
27174
|
_this.isScrollingTimeoutId = setTimeout(function () {
|
|
27173
27175
|
_this.isScrollingTimeoutId = null;
|
|
27176
|
+
_this.isScrolling = false;
|
|
27174
27177
|
_this.scrollDirection = null;
|
|
27175
|
-
|
|
27178
|
+
_this.maybeNotify();
|
|
27176
27179
|
}, _this.options.scrollingDelay);
|
|
27177
27180
|
}));
|
|
27178
27181
|
}
|
|
@@ -27210,29 +27213,31 @@
|
|
|
27210
27213
|
});
|
|
27211
27214
|
this.calculateRange = memo(function () {
|
|
27212
27215
|
return [_this.getMeasurements(), _this.getSize(), _this.scrollOffset];
|
|
27213
|
-
}, function (measurements, outerSize, scrollOffset
|
|
27214
|
-
|
|
27215
|
-
flush = _ref4$ === void 0 ? true : _ref4$;
|
|
27216
|
-
var range = calculateRange({
|
|
27216
|
+
}, function (measurements, outerSize, scrollOffset) {
|
|
27217
|
+
return _this.range = calculateRange({
|
|
27217
27218
|
measurements: measurements,
|
|
27218
27219
|
outerSize: outerSize,
|
|
27219
27220
|
scrollOffset: scrollOffset
|
|
27220
27221
|
});
|
|
27221
|
-
if (range.startIndex !== _this.range.startIndex || range.endIndex !== _this.range.endIndex) {
|
|
27222
|
-
_this.range = range;
|
|
27223
|
-
if (flush) {
|
|
27224
|
-
_this.notify();
|
|
27225
|
-
}
|
|
27226
|
-
}
|
|
27227
|
-
return _this.range;
|
|
27228
27222
|
}, {
|
|
27229
27223
|
key: 'calculateRange',
|
|
27230
27224
|
debug: function debug() {
|
|
27231
27225
|
return _this.options.debug;
|
|
27232
27226
|
}
|
|
27233
27227
|
});
|
|
27228
|
+
this.maybeNotify = memo(function () {
|
|
27229
|
+
return [].concat(Object.values(_this.calculateRange()), [_this.isScrolling]);
|
|
27230
|
+
}, function () {
|
|
27231
|
+
_this.notify();
|
|
27232
|
+
}, {
|
|
27233
|
+
key: 'maybeNotify',
|
|
27234
|
+
debug: function debug() {
|
|
27235
|
+
return _this.options.debug;
|
|
27236
|
+
},
|
|
27237
|
+
initialDeps: [].concat(Object.values(this.range), [this.isScrolling])
|
|
27238
|
+
});
|
|
27234
27239
|
this.getIndexes = memo(function () {
|
|
27235
|
-
return [_this.options.rangeExtractor, _this.calculateRange(
|
|
27240
|
+
return [_this.options.rangeExtractor, _this.calculateRange(), _this.options.overscan, _this.options.count];
|
|
27236
27241
|
}, function (rangeExtractor, range, overscan, count) {
|
|
27237
27242
|
return rangeExtractor(_extends({}, range, {
|
|
27238
27243
|
overscan: overscan,
|
|
@@ -27345,74 +27350,71 @@
|
|
|
27345
27350
|
var maxOffset = scrollSize - _this.getSize();
|
|
27346
27351
|
return Math.max(Math.min(maxOffset, toOffset), 0);
|
|
27347
27352
|
};
|
|
27348
|
-
this.
|
|
27349
|
-
|
|
27350
|
-
|
|
27351
|
-
align = _ref5$align === void 0 ? 'start' : _ref5$align,
|
|
27352
|
-
behavior = _ref5.behavior;
|
|
27353
|
-
var isDynamic = Object.keys(_this.measureElementCache).length > 0;
|
|
27354
|
-
if (isDynamic && behavior === 'smooth') {
|
|
27355
|
-
console.warn('The `smooth` scroll behavior is not supported with dynamic size.');
|
|
27356
|
-
return;
|
|
27357
|
-
}
|
|
27358
|
-
var options = {
|
|
27359
|
-
adjustments: undefined,
|
|
27360
|
-
behavior: behavior,
|
|
27361
|
-
sync: false
|
|
27362
|
-
};
|
|
27363
|
-
_this._scrollToOffset(_this.getOffsetForAlignment(toOffset, align), options);
|
|
27364
|
-
};
|
|
27365
|
-
this.scrollToIndex = function (index, _temp2) {
|
|
27366
|
-
var _ref6 = _temp2 === void 0 ? {} : _temp2,
|
|
27367
|
-
_ref6$align = _ref6.align,
|
|
27368
|
-
align = _ref6$align === void 0 ? 'auto' : _ref6$align,
|
|
27369
|
-
behavior = _ref6.behavior;
|
|
27370
|
-
if (_this.scrollToIndexTimeoutId !== null) {
|
|
27371
|
-
clearTimeout(_this.scrollToIndexTimeoutId);
|
|
27372
|
-
_this.scrollToIndexTimeoutId = null;
|
|
27373
|
-
}
|
|
27374
|
-
var isDynamic = Object.keys(_this.measureElementCache).length > 0;
|
|
27375
|
-
if (isDynamic && behavior === 'smooth') {
|
|
27376
|
-
console.warn('The `smooth` scroll behavior is not supported with dynamic size.');
|
|
27377
|
-
return;
|
|
27353
|
+
this.getOffsetForIndex = function (index, align) {
|
|
27354
|
+
if (align === void 0) {
|
|
27355
|
+
align = 'auto';
|
|
27378
27356
|
}
|
|
27379
|
-
|
|
27380
|
-
|
|
27381
|
-
var measurement = measurements[Math.max(0, Math.min(index, _this.options.count - 1))];
|
|
27382
|
-
if (!measurement) {
|
|
27383
|
-
throw new Error("VirtualItem not found for index = " + index);
|
|
27384
|
-
}
|
|
27385
|
-
return measurement;
|
|
27386
|
-
};
|
|
27387
|
-
var measurement = getMeasurement();
|
|
27357
|
+
index = Math.max(0, Math.min(index, _this.options.count - 1));
|
|
27358
|
+
var measurement = notUndefined(_this.getMeasurements()[index]);
|
|
27388
27359
|
if (align === 'auto') {
|
|
27389
27360
|
if (measurement.end >= _this.scrollOffset + _this.getSize() - _this.options.scrollPaddingEnd) {
|
|
27390
27361
|
align = 'end';
|
|
27391
27362
|
} else if (measurement.start <= _this.scrollOffset + _this.options.scrollPaddingStart) {
|
|
27392
27363
|
align = 'start';
|
|
27393
27364
|
} else {
|
|
27394
|
-
return;
|
|
27365
|
+
return [_this.scrollOffset, align];
|
|
27395
27366
|
}
|
|
27396
27367
|
}
|
|
27397
|
-
var
|
|
27398
|
-
|
|
27399
|
-
|
|
27400
|
-
|
|
27401
|
-
|
|
27402
|
-
|
|
27368
|
+
var toOffset = align === 'end' ? measurement.end + _this.options.scrollPaddingEnd : measurement.start - _this.options.scrollPaddingStart;
|
|
27369
|
+
return [_this.getOffsetForAlignment(toOffset, align), align];
|
|
27370
|
+
};
|
|
27371
|
+
this.isDynamicMode = function () {
|
|
27372
|
+
return Object.keys(_this.measureElementCache).length > 0;
|
|
27373
|
+
};
|
|
27374
|
+
this.cancelScrollToIndex = function () {
|
|
27375
|
+
if (_this.scrollToIndexTimeoutId !== null) {
|
|
27376
|
+
clearTimeout(_this.scrollToIndexTimeoutId);
|
|
27377
|
+
_this.scrollToIndexTimeoutId = null;
|
|
27378
|
+
}
|
|
27379
|
+
};
|
|
27380
|
+
this.scrollToOffset = function (toOffset, _temp) {
|
|
27381
|
+
var _ref4 = _temp === void 0 ? {} : _temp,
|
|
27382
|
+
_ref4$align = _ref4.align,
|
|
27383
|
+
align = _ref4$align === void 0 ? 'start' : _ref4$align,
|
|
27384
|
+
behavior = _ref4.behavior;
|
|
27385
|
+
_this.cancelScrollToIndex();
|
|
27386
|
+
if (behavior === 'smooth' && _this.isDynamicMode()) {
|
|
27387
|
+
console.warn('The `smooth` scroll behavior is not fully supported with dynamic size.');
|
|
27388
|
+
}
|
|
27389
|
+
_this._scrollToOffset(_this.getOffsetForAlignment(toOffset, align), {
|
|
27403
27390
|
adjustments: undefined,
|
|
27404
27391
|
behavior: behavior
|
|
27405
|
-
};
|
|
27406
|
-
|
|
27407
|
-
|
|
27408
|
-
|
|
27409
|
-
|
|
27410
|
-
|
|
27392
|
+
});
|
|
27393
|
+
};
|
|
27394
|
+
this.scrollToIndex = function (index, _temp2) {
|
|
27395
|
+
var _ref5 = _temp2 === void 0 ? {} : _temp2,
|
|
27396
|
+
_ref5$align = _ref5.align,
|
|
27397
|
+
initialAlign = _ref5$align === void 0 ? 'auto' : _ref5$align,
|
|
27398
|
+
behavior = _ref5.behavior;
|
|
27399
|
+
index = Math.max(0, Math.min(index, _this.options.count - 1));
|
|
27400
|
+
_this.cancelScrollToIndex();
|
|
27401
|
+
if (behavior === 'smooth' && _this.isDynamicMode()) {
|
|
27402
|
+
console.warn('The `smooth` scroll behavior is not fully supported with dynamic size.');
|
|
27403
|
+
}
|
|
27404
|
+
var _this$getOffsetForInd = _this.getOffsetForIndex(index, initialAlign),
|
|
27405
|
+
toOffset = _this$getOffsetForInd[0],
|
|
27406
|
+
align = _this$getOffsetForInd[1];
|
|
27407
|
+
_this._scrollToOffset(toOffset, {
|
|
27408
|
+
adjustments: undefined,
|
|
27409
|
+
behavior: behavior
|
|
27410
|
+
});
|
|
27411
|
+
if (behavior !== 'smooth' && _this.isDynamicMode()) {
|
|
27411
27412
|
_this.scrollToIndexTimeoutId = setTimeout(function () {
|
|
27412
27413
|
_this.scrollToIndexTimeoutId = null;
|
|
27413
27414
|
var elementInDOM = !!_this.measureElementCache[_this.options.getItemKey(index)];
|
|
27414
27415
|
if (elementInDOM) {
|
|
27415
|
-
var
|
|
27416
|
+
var _this$getOffsetForInd2 = _this.getOffsetForIndex(index, align),
|
|
27417
|
+
_toOffset = _this$getOffsetForInd2[0];
|
|
27416
27418
|
if (!approxEqual(_toOffset, _this.scrollOffset)) {
|
|
27417
27419
|
_this.scrollToIndex(index, {
|
|
27418
27420
|
align: align,
|
|
@@ -27429,12 +27431,11 @@
|
|
|
27429
27431
|
}
|
|
27430
27432
|
};
|
|
27431
27433
|
this.scrollBy = function (delta, _temp3) {
|
|
27432
|
-
var
|
|
27433
|
-
behavior =
|
|
27434
|
-
|
|
27435
|
-
if (
|
|
27436
|
-
console.warn('The `smooth` scroll behavior is not supported with dynamic size.');
|
|
27437
|
-
return;
|
|
27434
|
+
var _ref6 = _temp3 === void 0 ? {} : _temp3,
|
|
27435
|
+
behavior = _ref6.behavior;
|
|
27436
|
+
_this.cancelScrollToIndex();
|
|
27437
|
+
if (behavior === 'smooth' && _this.isDynamicMode()) {
|
|
27438
|
+
console.warn('The `smooth` scroll behavior is not fully supported with dynamic size.');
|
|
27438
27439
|
}
|
|
27439
27440
|
_this._scrollToOffset(_this.scrollOffset + delta, {
|
|
27440
27441
|
adjustments: undefined,
|
|
@@ -27445,9 +27446,9 @@
|
|
|
27445
27446
|
var _this$getMeasurements;
|
|
27446
27447
|
return (((_this$getMeasurements = _this.getMeasurements()[_this.options.count - 1]) == null ? void 0 : _this$getMeasurements.end) || _this.options.paddingStart) - _this.options.scrollMargin + _this.options.paddingEnd;
|
|
27447
27448
|
};
|
|
27448
|
-
this._scrollToOffset = function (offset,
|
|
27449
|
-
var adjustments =
|
|
27450
|
-
behavior =
|
|
27449
|
+
this._scrollToOffset = function (offset, _ref7) {
|
|
27450
|
+
var adjustments = _ref7.adjustments,
|
|
27451
|
+
behavior = _ref7.behavior;
|
|
27451
27452
|
_this.options.scrollToFn(offset, {
|
|
27452
27453
|
behavior: behavior,
|
|
27453
27454
|
adjustments: adjustments
|
|
@@ -27464,7 +27465,7 @@
|
|
|
27464
27465
|
this.measurementsCache.forEach(function (item) {
|
|
27465
27466
|
_this.itemSizeCache[item.key] = item.size;
|
|
27466
27467
|
});
|
|
27467
|
-
this.
|
|
27468
|
+
this.maybeNotify();
|
|
27468
27469
|
};
|
|
27469
27470
|
var findNearestBinarySearch = function findNearestBinarySearch(low, high, getCurrentValue, value) {
|
|
27470
27471
|
while (low <= high) {
|
|
@@ -27484,10 +27485,10 @@
|
|
|
27484
27485
|
return 0;
|
|
27485
27486
|
}
|
|
27486
27487
|
};
|
|
27487
|
-
function calculateRange(
|
|
27488
|
-
var measurements =
|
|
27489
|
-
outerSize =
|
|
27490
|
-
scrollOffset =
|
|
27488
|
+
function calculateRange(_ref8) {
|
|
27489
|
+
var measurements = _ref8.measurements,
|
|
27490
|
+
outerSize = _ref8.outerSize,
|
|
27491
|
+
scrollOffset = _ref8.scrollOffset;
|
|
27491
27492
|
var count = measurements.length - 1;
|
|
27492
27493
|
var getOffset = function getOffset(index) {
|
|
27493
27494
|
return measurements[index].start;
|