@enact/ui 5.4.4 → 5.5.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.
Files changed (65) hide show
  1. package/AnnounceDecorator/Announce.js +9 -5
  2. package/AnnounceDecorator/AnnounceDecorator.js +5 -3
  3. package/AnnounceDecorator/tests/AnnounceDecorator-specs.js +4 -1
  4. package/AnnounceDecorator/tests/useAnnounce-specs.js +4 -1
  5. package/CHANGELOG.md +30 -0
  6. package/Cancelable/Cancelable.js +7 -0
  7. package/Cancelable/tests/Cancelable-specs.js +26 -0
  8. package/Changeable/Changeable.js +6 -0
  9. package/Changeable/tests/Changeable-specs.js +4 -1
  10. package/FloatingLayer/FloatingLayer.js +3 -0
  11. package/FloatingLayer/FloatingLayerDecorator.js +2 -0
  12. package/FloatingLayer/Scrim.js +3 -0
  13. package/Marquee/Marquee.module.css +1 -1
  14. package/Marquee/MarqueeDecorator.js +19 -3
  15. package/Marquee/tests/Marquee-specs.js +306 -1
  16. package/Marquee/useMarqueeController.js +6 -4
  17. package/Measurable/tests/Measurable-specs.js +6 -2
  18. package/Media/Media.js +5 -2
  19. package/Placeholder/tests/PlaceholderControllerDecorator-specs.js +4 -1
  20. package/Resizable/tests/Resizable-specs.js +4 -1
  21. package/Resizable/tests/useResize-specs.js +4 -1
  22. package/Routable/Route.js +5 -3
  23. package/Routable/Router.js +25 -16
  24. package/Routable/tests/Routable-specs.js +16 -0
  25. package/Scroller/Scroller.js +6 -5
  26. package/Scroller/ScrollerBasic.js +5 -5
  27. package/Skinnable/Skinnable.js +9 -7
  28. package/Skinnable/tests/Skinnable-specs.js +7 -2
  29. package/Skinnable/useSkins.js +6 -2
  30. package/Slider/PositionDecorator.js +20 -5
  31. package/Slider/Slider.d.ts +4 -0
  32. package/Slider/Slider.js +10 -0
  33. package/Slider/tests/Slider-specs.js +18 -0
  34. package/Slider/utils.js +9 -1
  35. package/Toggleable/Toggleable.js +4 -2
  36. package/Toggleable/tests/Toggleable-specs.js +4 -1
  37. package/Touchable/Touchable.js +6 -4
  38. package/Touchable/tests/Touchable-specs.js +4 -1
  39. package/Touchable/tests/useTouch-specs.js +4 -1
  40. package/Touchable/useTouch.js +7 -2
  41. package/Transition/Transition.js +2 -0
  42. package/ViewManager/TransitionGroup.js +3 -0
  43. package/ViewManager/View.js +2 -0
  44. package/ViewManager/ViewManager.js +7 -0
  45. package/VirtualList/VirtualList.js +7 -5
  46. package/VirtualList/VirtualListBasic.js +170 -32
  47. package/VirtualList/tests/VirtualList-native-specs.js +233 -3
  48. package/VirtualList/tests/VirtualList-specs.js +13 -0
  49. package/internal/IdProvider/IdProvider.js +2 -0
  50. package/internal/IdProvider/tests/IdProvider-specs.js +4 -1
  51. package/internal/Pure/tests/Pure-specs.js +7 -0
  52. package/package.json +8 -3
  53. package/resolution/ResolutionDecorator.js +21 -18
  54. package/resolution/index.d.ts +63 -4
  55. package/resolution/index.js +18 -2
  56. package/resolution/resolution.js +209 -29
  57. package/resolution/tests/ResolutionDecorator-specs.js +84 -4
  58. package/resolution/tests/resolution-specs.js +217 -599
  59. package/useControlledState/tests/useControlledState-specs.js +4 -1
  60. package/useControlledState/useControlledState.js +11 -7
  61. package/useScroll/Scrollbar.js +27 -24
  62. package/useScroll/ScrollbarTrack.js +5 -3
  63. package/useScroll/tests/useScroll-specs.js +408 -42
  64. package/useScroll/useScroll.js +132 -27
  65. package/useScroll/utilEvent.js +18 -0
@@ -18,6 +18,7 @@ var _excluded = ["className", "containerProps", "placeholderRenderer", "role", "
18
18
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
19
19
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
20
20
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
21
+ function _readOnlyError(r) { throw new TypeError('"' + r + '" is read-only'); }
21
22
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
22
23
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
23
24
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
@@ -104,16 +105,22 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
104
105
  _this.isItemSized = false;
105
106
  _this.shouldUpdateBounds = false;
106
107
  _this.dimensionToExtent = 0;
108
+ _this.itemMarginLeft = null;
109
+ _this.itemMarginRight = null;
110
+ _this.itemMarginTop = null;
111
+ _this.itemMarginBottom = null;
107
112
  _this.threshold = 0;
108
113
  _this.maxFirstIndex = 0;
109
114
  _this.curDataSize = 0;
110
115
  _this.hasDataSizeChanged = false;
111
116
  _this.cc = [];
112
117
  _this.scrollPosition = 0;
118
+ _this.prevScrollPosition = 0;
113
119
  _this.scrollPositionTarget = 0;
114
120
  _this.scrollToPositionTarget = -1;
115
121
  // For individually sized item
116
122
  _this.itemPositions = [];
123
+ _this.prevItemPositions = [];
117
124
  _this.indexToScrollIntoView = -1;
118
125
  _this.updateScrollPosition = function (_ref, behavior) {
119
126
  var x = _ref.x,
@@ -165,18 +172,19 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
165
172
  var maxPos = isPrimaryDirectionVertical ? scrollBounds.maxTop : scrollBounds.maxLeft;
166
173
  var position = _this.getGridPosition(index);
167
174
  var offset = 0;
175
+ var marginOffset = isPrimaryDirectionVertical ? _this.itemMarginTop + _this.itemMarginBottom : _this.itemMarginLeft + _this.itemMarginRight;
168
176
  if (stickTo === 'start') {
169
177
  // 'start'
170
178
  offset = optionalOffset;
171
179
  } else if (_this.props.itemSizes) {
172
180
  // 'end' for different item sizes
173
- offset = primary.clientSize - _this.props.itemSizes[index] - optionalOffset;
181
+ offset = primary.clientSize - _this.props.itemSizes[index] - (optionalOffset || marginOffset);
174
182
  } else if (stickTo === 'center') {
175
183
  // 'center'
176
184
  offset = primary.clientSize / 2 - primary.gridSize / 2 - optionalOffset;
177
185
  } else {
178
186
  // 'end' for same item sizes
179
- offset = primary.clientSize - primary.itemSize - optionalOffset;
187
+ offset = primary.clientSize - primary.itemSize - (optionalOffset || marginOffset);
180
188
  }
181
189
 
182
190
  /* istanbul ignore next */
@@ -350,6 +358,7 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
350
358
  }
351
359
  return false;
352
360
  };
361
+ (0, _util.checkPropTypes)(_this, _props);
353
362
  _this.contentRef = /*#__PURE__*/(0, _react.createRef)();
354
363
  _this.itemContainerRefs = [];
355
364
  _this.state = {
@@ -387,6 +396,25 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
387
396
  }, {
388
397
  key: "componentDidUpdate",
389
398
  value: function componentDidUpdate(prevProps, prevState) {
399
+ var items = this.props.itemRefs.current;
400
+ (0, _util.checkPropTypes)(this, this.props, prevProps);
401
+ if (!this.itemMarginTop && this.itemMarginTop !== 0 && items[0]) {
402
+ var firstItemStyle = window.getComputedStyle(items[0]);
403
+ this.itemMarginTop = Number(firstItemStyle.getPropertyValue('margin-top').slice(0, -2));
404
+ this.itemMarginBottom = Number(firstItemStyle.getPropertyValue('margin-bottom').slice(0, -2));
405
+ this.itemMarginLeft = Number(firstItemStyle.getPropertyValue('margin-left').slice(0, -2));
406
+ this.itemMarginRight = Number(firstItemStyle.getPropertyValue('margin-right').slice(0, -2));
407
+ if (this.isPrimaryDirectionVertical) {
408
+ var marginSum = this.itemMarginTop + this.itemMarginBottom;
409
+ this.scrollBounds.scrollHeight += marginSum;
410
+ this.scrollBounds.maxTop += marginSum;
411
+ } else {
412
+ var _marginSum = this.itemMarginLeft + this.itemMarginRight;
413
+ this.scrollBounds.scrollWidth += _marginSum;
414
+ this.scrollBounds.maxLeft += _marginSum;
415
+ }
416
+ this.setContainerSize();
417
+ }
390
418
  var deferScrollTo = false;
391
419
  var _this$state = this.state,
392
420
  firstIndex = _this$state.firstIndex,
@@ -442,17 +470,42 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
442
470
  }
443
471
  }
444
472
  if (prevProps.direction !== this.props.direction || prevProps.overhang !== this.props.overhang || prevProps.spacing !== this.props.spacing || !(0, _equals["default"])(prevProps.itemSize, this.props.itemSize) || !this.hasDataSizeChanged && !(0, _util.shallowEqual)(prevProps.itemSizes, this.props.itemSizes)) {
445
- var _this$getXY = this.getXY(this.scrollPosition, 0),
446
- x = _this$getXY.x,
447
- y = _this$getXY.y;
448
- this.calculateMetrics(this.props);
449
- this.setState(this.getStatesAndUpdateBounds(this.props));
450
- this.setContainerSize();
451
473
  var _this$scrollBounds = this.scrollBounds,
452
474
  clientHeight = _this$scrollBounds.clientHeight,
453
475
  clientWidth = _this$scrollBounds.clientWidth,
454
476
  scrollHeight = _this$scrollBounds.scrollHeight,
455
477
  scrollWidth = _this$scrollBounds.scrollWidth;
478
+
479
+ /* istanbul ignore next */
480
+ if (this.scrollPosition === 0 && this.moreInfo.firstVisibleIndex !== 0) {
481
+ this.scrollPosition = this.prevScrollPosition;
482
+ this.setState({
483
+ firstIndex: prevState.firstIndex
484
+ });
485
+ this.updateMoreInfo(this.props.dataSize, this.scrollPosition);
486
+ for (var i = prevState.firstIndex; i < prevState.firstIndex + this.state.numOfItems; i++) {
487
+ var _this$itemPositions, _this$prevItemPositio, _this$itemPositions2, _this$prevItemPositio2;
488
+ var size = this.isPrimaryDirectionVertical ? clientHeight : clientWidth;
489
+ if (((_this$itemPositions = this.itemPositions[i + 1]) === null || _this$itemPositions === void 0 ? void 0 : _this$itemPositions.position) > ((_this$prevItemPositio = this.prevItemPositions[i + 1]) === null || _this$prevItemPositio === void 0 ? void 0 : _this$prevItemPositio.position)) {
490
+ if (i === this.moreInfo.lastVisibleIndex && this.getItemBottomPosition(i) > this.scrollPosition + size) {
491
+ this.scrollPosition = this.getItemBottomPosition(i) - size;
492
+ }
493
+ break;
494
+ }
495
+ if (((_this$itemPositions2 = this.itemPositions[i + 1]) === null || _this$itemPositions2 === void 0 ? void 0 : _this$itemPositions2.position) < ((_this$prevItemPositio2 = this.prevItemPositions[i + 1]) === null || _this$prevItemPositio2 === void 0 ? void 0 : _this$prevItemPositio2.position)) {
496
+ if (this.itemPositions[i].position < this.scrollPosition) {
497
+ this.scrollPosition = this.itemPositions[i].position;
498
+ }
499
+ break;
500
+ }
501
+ }
502
+ }
503
+ var _this$getXY = this.getXY(this.scrollPosition, 0),
504
+ x = _this$getXY.x,
505
+ y = _this$getXY.y;
506
+ this.calculateMetrics(this.props);
507
+ this.setState(this.getStatesAndUpdateBounds(this.props, prevState.firstIndex ? prevState.firstIndex : 0));
508
+ this.setContainerSize();
456
509
  var xMax = scrollWidth - clientWidth;
457
510
  var yMax = scrollHeight - clientHeight;
458
511
  this.updateScrollPosition({
@@ -591,6 +644,10 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
591
644
  this.secondary = secondary;
592
645
 
593
646
  // reset
647
+ this.prevScrollPosition = this.scrollPosition;
648
+ for (var i = 0; i < this.itemPositions.length; i++) {
649
+ this.prevItemPositions[i] = this.itemPositions[i];
650
+ }
594
651
  this.scrollPosition = 0;
595
652
  this.scrollToPositionTarget = -1;
596
653
  if (scrollMode === 'translate' && this.contentRef.current) {
@@ -731,8 +788,31 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
731
788
  value:
732
789
  // scrollMode 'native' only
733
790
  function scrollToPosition(left, top, behavior) {
734
- if (this.props.scrollContentRef.current && this.props.scrollContentRef.current.scrollTo) {
735
- this.props.scrollContentRef.current.scrollTo({
791
+ var _this$props3 = this.props,
792
+ dataSize = _this$props3.dataSize,
793
+ scrollContentRef = _this$props3.scrollContentRef;
794
+ var node = scrollContentRef.current;
795
+ if (!node) return;
796
+ var _this$scrollBounds3 = this.scrollBounds,
797
+ clientWidth = _this$scrollBounds3.clientWidth,
798
+ clientHeight = _this$scrollBounds3.clientHeight,
799
+ scrollWidth = _this$scrollBounds3.scrollWidth,
800
+ scrollHeight = _this$scrollBounds3.scrollHeight;
801
+ var _this$moreInfo = this.moreInfo,
802
+ firstVisibleIndex = _this$moreInfo.firstVisibleIndex,
803
+ lastVisibleIndex = _this$moreInfo.lastVisibleIndex;
804
+ var scrollSize = this.isPrimaryDirectionVertical ? top >= scrollHeight - clientHeight : left >= scrollWidth - clientWidth;
805
+ var isTargetStart = this.isPrimaryDirectionVertical ? top === 0 : left === 0;
806
+ var isScrollWrap = lastVisibleIndex === dataSize - 1 && isTargetStart || firstVisibleIndex === 0 && scrollSize;
807
+ var isScrollByPageKey = node.lastInputType === 'pageKey';
808
+ var isSmoothBehavior = behavior === 'smooth';
809
+ if (_platform.platform.chrome && isSmoothBehavior && !isScrollByPageKey && !isScrollWrap) {
810
+ this.animateScroll(this.getRtlPositionX(left), top, node);
811
+ } else if (node.scrollTo) {
812
+ if (this.scrollAnimationId) {
813
+ this.cancelScrollAnimation();
814
+ }
815
+ node.scrollTo({
736
816
  left: this.getRtlPositionX(left),
737
817
  top: top,
738
818
  behavior: behavior
@@ -740,6 +820,64 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
740
820
  }
741
821
  }
742
822
 
823
+ // scroll mode 'native' only
824
+ }, {
825
+ key: "animateScroll",
826
+ value: function _animateScroll(left, top, node) {
827
+ var _this8 = this;
828
+ // Determine the direction of scroll (1 for forward/down, -1 for backward/up, 0 for no movement)
829
+ var directionX = Math.sign(left - node.scrollLeft);
830
+ var directionY = Math.sign(top - node.scrollTop);
831
+
832
+ // Calculate an adaptive scroll factor (pixels per frame).
833
+ // It uses the average item size (gridSize) to ensure the speed feels consistent.
834
+ var scrollFactor = Math.max(this.primary.gridSize / 12, 2);
835
+ var startTime = performance.now();
836
+
837
+ // Progressively scrolls the node toward a target position using requestAnimationFrame.
838
+ // It applies an incremental scroll on each frame and cancels the animation once
839
+ // the target is reached or the duration (500ms) is exceeded, falling back to
840
+ // a smooth scroll if the timeout occurs first.
841
+ var _animateScroll = function animateScroll(currentTime) {
842
+ var elapsed = (currentTime - startTime) / 500;
843
+ node.scrollBy({
844
+ top: directionY * scrollFactor,
845
+ left: directionX * scrollFactor,
846
+ behavior: 'instant'
847
+ });
848
+ _this8.scrollAnimationId = window.requestAnimationFrame(_animateScroll);
849
+ _this8.scrolling = true;
850
+ var scrollHorizontally = directionX > 0 ? node.scrollLeft < left : node.scrollLeft > left;
851
+ var scrollVertically = directionY > 0 ? node.scrollTop < top : node.scrollTop > top;
852
+ var targetReached = node.scrollLeft === left && node.scrollTop === top;
853
+
854
+ // Check if we've reached the needed scroll position
855
+ // or the elapsed time since startTime is longer than 0.5s and cancel the animation
856
+ if (!scrollHorizontally && !scrollVertically || elapsed > 1) {
857
+ _this8.cancelScrollAnimation();
858
+
859
+ // Fallback: if time is out before reaching the target, jump there with smooth scroll
860
+ if (elapsed > 1 && !targetReached) {
861
+ node.scrollTo({
862
+ top: top,
863
+ left: left,
864
+ behavior: 'smooth'
865
+ });
866
+ }
867
+ }
868
+ };
869
+ this.scrollAnimationId = window.requestAnimationFrame(_animateScroll);
870
+ }
871
+
872
+ // scrollMode 'native' only
873
+ }, {
874
+ key: "cancelScrollAnimation",
875
+ value: function cancelScrollAnimation() {
876
+ window.cancelAnimationFrame(this.scrollAnimationId);
877
+ this.scrollAnimationId = null;
878
+ this.scrolling = false;
879
+ }
880
+
743
881
  // scrollMode 'native' only
744
882
  }, {
745
883
  key: "setScrollToPositionTarget",
@@ -778,10 +916,10 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
778
916
  }, {
779
917
  key: "didScroll",
780
918
  value: function didScroll(x, y) {
781
- var _this$props3 = this.props,
782
- dataSize = _this$props3.dataSize,
783
- spacing = _this$props3.spacing,
784
- itemSizes = _this$props3.itemSizes,
919
+ var _this$props4 = this.props,
920
+ dataSize = _this$props4.dataSize,
921
+ spacing = _this$props4.spacing,
922
+ itemSizes = _this$props4.itemSizes,
785
923
  firstIndex = this.state.firstIndex,
786
924
  isPrimaryDirectionVertical = this.isPrimaryDirectionVertical,
787
925
  threshold = this.threshold,
@@ -878,9 +1016,9 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
878
1016
  }, {
879
1017
  key: "applyItemPositionToDOMElement",
880
1018
  value: function applyItemPositionToDOMElement(index) {
881
- var _this$props4 = this.props,
882
- direction = _this$props4.direction,
883
- rtl = _this$props4.rtl,
1019
+ var _this$props5 = this.props,
1020
+ direction = _this$props5.direction,
1021
+ rtl = _this$props5.rtl,
884
1022
  numOfItems = this.state.numOfItems,
885
1023
  itemPositions = this.itemPositions,
886
1024
  childNode = this.itemContainerRefs[index % numOfItems];
@@ -910,10 +1048,10 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
910
1048
  }, {
911
1049
  key: "updateScrollBoundsWithItemPositions",
912
1050
  value: function updateScrollBoundsWithItemPositions() {
913
- var _this$props5 = this.props,
914
- dataSize = _this$props5.dataSize,
915
- itemSizes = _this$props5.itemSizes,
916
- spacing = _this$props5.spacing,
1051
+ var _this$props6 = this.props,
1052
+ dataSize = _this$props6.dataSize,
1053
+ itemSizes = _this$props6.itemSizes,
1054
+ spacing = _this$props6.spacing,
917
1055
  _this$state4 = this.state,
918
1056
  firstIndex = _this$state4.firstIndex,
919
1057
  numOfItems = _this$state4.numOfItems,
@@ -990,9 +1128,9 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
990
1128
  }, {
991
1129
  key: "positionItems",
992
1130
  value: function positionItems() {
993
- var _this$props6 = this.props,
994
- dataSize = _this$props6.dataSize,
995
- itemSizes = _this$props6.itemSizes,
1131
+ var _this$props7 = this.props,
1132
+ dataSize = _this$props7.dataSize,
1133
+ itemSizes = _this$props7.itemSizes,
996
1134
  _this$state6 = this.state,
997
1135
  firstIndex = _this$state6.firstIndex,
998
1136
  numOfItems = _this$state6.numOfItems,
@@ -1050,14 +1188,14 @@ var VirtualListBasic = exports.VirtualListBasic = /*#__PURE__*/function (_Compon
1050
1188
  // render
1051
1189
 
1052
1190
  function render() {
1053
- var _this$props7 = this.props,
1054
- className = _this$props7.className,
1055
- containerProps = _this$props7.containerProps,
1056
- placeholderRenderer = _this$props7.placeholderRenderer,
1057
- role = _this$props7.role,
1058
- style = _this$props7.style,
1059
- scrollMode = _this$props7.scrollMode,
1060
- rest = _objectWithoutProperties(_this$props7, _excluded),
1191
+ var _this$props8 = this.props,
1192
+ className = _this$props8.className,
1193
+ containerProps = _this$props8.containerProps,
1194
+ placeholderRenderer = _this$props8.placeholderRenderer,
1195
+ role = _this$props8.role,
1196
+ style = _this$props8.style,
1197
+ scrollMode = _this$props8.scrollMode,
1198
+ rest = _objectWithoutProperties(_this$props8, _excluded),
1061
1199
  cc = this.cc,
1062
1200
  isPrimaryDirectionVertical = this.isPrimaryDirectionVertical,
1063
1201
  primary = this.primary,
@@ -2,11 +2,14 @@
2
2
 
3
3
  require("@testing-library/jest-dom");
4
4
  var _react = require("@testing-library/react");
5
- var _VirtualList = _interopRequireDefault(require("../VirtualList"));
5
+ var _react2 = require("react");
6
+ var _VirtualList = _interopRequireWildcard(require("../VirtualList"));
6
7
  var _jsxRuntime = require("react/jsx-runtime");
7
8
  var _excluded = ["index"],
8
- _excluded2 = ["index"];
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
9
+ _excluded2 = ["index"],
10
+ _excluded3 = ["direction"],
11
+ _excluded4 = ["index"];
12
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
10
13
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
14
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
15
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
@@ -14,6 +17,14 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
14
17
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
15
18
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
16
19
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
20
+ var mockPlatform = {};
21
+ jest.mock('@enact/core/platform', function () {
22
+ return {
23
+ get platform() {
24
+ return mockPlatform;
25
+ }
26
+ };
27
+ });
17
28
  describe('VirtualList with native scrollMode', function () {
18
29
  var clientSize, dataSize, items, itemSize, renderItem;
19
30
  beforeEach(function () {
@@ -29,6 +40,7 @@ describe('VirtualList with native scrollMode', function () {
29
40
  rest = _objectWithoutProperties(_ref, _excluded);
30
41
  // eslint-disable-line enact/display-name
31
42
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, rest), {}, {
43
+ "data-index": index,
32
44
  id: 'item' + index,
33
45
  children: items[index].name
34
46
  }));
@@ -58,6 +70,19 @@ describe('VirtualList with native scrollMode', function () {
58
70
  var actual = _react.screen.getByRole('list').children.item(0).textContent;
59
71
  expect(actual).toBe(expected);
60
72
  });
73
+ test('should render a list of \'items\' with horizontal direction', function () {
74
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_VirtualList["default"], {
75
+ clientSize: clientSize,
76
+ dataSize: dataSize,
77
+ direction: "horizontal",
78
+ itemRenderer: renderItem,
79
+ itemSize: itemSize,
80
+ scrollMode: "native"
81
+ }));
82
+ var expected = 'Account 0';
83
+ var actual = _react.screen.getByRole('list').children.item(0).textContent;
84
+ expect(actual).toBe(expected);
85
+ });
61
86
  test('should render overhang items when clientSize is not given', function () {
62
87
  (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_VirtualList["default"], {
63
88
  dataSize: dataSize,
@@ -151,4 +176,209 @@ describe('VirtualList with native scrollMode', function () {
151
176
  jest.useRealTimers();
152
177
  });
153
178
  });
179
+ describe('Animating scroll', function () {
180
+ var instance, node, scrollContentRef;
181
+ beforeEach(function () {
182
+ node = {
183
+ scrollTo: jest.fn(),
184
+ scrollBy: jest.fn(),
185
+ scrollLeft: 0,
186
+ scrollTop: 0
187
+ };
188
+ scrollContentRef = {
189
+ current: node
190
+ };
191
+ instance = new _VirtualList.VirtualListBasic({
192
+ scrollContentRef: scrollContentRef,
193
+ clientSize: clientSize,
194
+ itemSize: itemSize,
195
+ itemRenderer: renderItem,
196
+ scrollMode: 'native'
197
+ });
198
+ jest.spyOn(window, 'requestAnimationFrame').mockImplementation(function (cb) {
199
+ instance.rafCallback = cb;
200
+ return 123;
201
+ });
202
+ jest.spyOn(window, 'cancelAnimationFrame').mockImplementation(jest.fn());
203
+ jest.spyOn(performance, 'now').mockReturnValue(0);
204
+ });
205
+ afterEach(function () {
206
+ delete mockPlatform.chrome;
207
+ });
208
+ test('should call native scrollTo when behavior is instant', function () {
209
+ instance.scrollToPosition(0, 300, 'instant');
210
+ expect(node.scrollTo).toHaveBeenCalledWith({
211
+ left: 0,
212
+ top: 300,
213
+ behavior: 'instant'
214
+ });
215
+ });
216
+ test('should call native scrollTo when NOT on Chrome and behavior is smooth', function () {
217
+ mockPlatform.chrome = false;
218
+ instance.scrollToPosition(0, 300, 'smooth');
219
+ expect(node.scrollTo).toHaveBeenCalledWith({
220
+ left: 0,
221
+ top: 300,
222
+ behavior: 'smooth'
223
+ });
224
+ });
225
+ test('should call animateScroll when on Chrome and behavior is smooth', function () {
226
+ mockPlatform.chrome = 88;
227
+ instance.animateScroll = jest.fn();
228
+ instance.scrollToPosition(0, 300, 'smooth');
229
+ expect(instance.animateScroll).toHaveBeenCalledWith(0, 300, node);
230
+ });
231
+ test('should cancel animation when content is scrolled by pageKey', function () {
232
+ mockPlatform.chrome = 88;
233
+ instance.scrollToPosition(0, 600, 'smooth');
234
+ node.lastInputType = 'pageKey';
235
+ instance.scrollToPosition(0, 200, 'smooth');
236
+ expect(window.cancelAnimationFrame).toHaveBeenCalled();
237
+ });
238
+ test('should initiate animation loop using requestAnimationFrame', function () {
239
+ instance.animateScroll(0, 300, node);
240
+ expect(window.requestAnimationFrame).toHaveBeenCalled();
241
+ });
242
+ test('should scroll incrementally on each frame', function () {
243
+ instance.animateScroll(0, 300, node);
244
+ instance.rafCallback();
245
+ expect(node.scrollBy).toHaveBeenCalledWith(expect.objectContaining({
246
+ behavior: 'instant'
247
+ }));
248
+ expect(instance.scrolling).toBe(true);
249
+ });
250
+ test('should cancel animation and stop when target is reached', function () {
251
+ node.scrollTop = 300;
252
+ instance.animateScroll(0, 310, node);
253
+ instance.rafCallback(600);
254
+ expect(window.cancelAnimationFrame).toHaveBeenCalled();
255
+ expect(instance.scrolling).toBe(false);
256
+ });
257
+ test('should fallback to smooth scroll if animation exceeds duration (timeout)', function () {
258
+ instance.animateScroll(0, 300, node);
259
+ instance.rafCallback(600);
260
+ node.scrollTop = 250;
261
+ expect(node.scrollTo).toHaveBeenCalledWith({
262
+ left: 0,
263
+ top: 300,
264
+ behavior: 'smooth'
265
+ });
266
+ expect(window.cancelAnimationFrame).toHaveBeenCalled();
267
+ });
268
+ });
269
+ });
270
+ describe('VirtualListBasic scrollBounds consistency after item margin detection', function () {
271
+ var originalGetComputedStyle;
272
+ var nop = function nop() {};
273
+ function renderVirtualListBasic() {
274
+ var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
275
+ _ref3$direction = _ref3.direction,
276
+ direction = _ref3$direction === void 0 ? 'vertical' : _ref3$direction,
277
+ rest = _objectWithoutProperties(_ref3, _excluded3);
278
+ var scrollContentRef = /*#__PURE__*/(0, _react2.createRef)();
279
+ var itemRefs = /*#__PURE__*/(0, _react2.createRef)();
280
+ itemRefs.current = [];
281
+ var ref = /*#__PURE__*/(0, _react2.createRef)();
282
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_VirtualList.VirtualListBasic, _objectSpread({
283
+ clientSize: {
284
+ clientWidth: 1280,
285
+ clientHeight: 720
286
+ },
287
+ dataSize: 100,
288
+ direction: direction,
289
+ getAffordance: function getAffordance() {
290
+ return 0;
291
+ },
292
+ itemRefs: itemRefs,
293
+ itemRenderer: function itemRenderer(_ref4) {
294
+ var index = _ref4.index,
295
+ rest2 = _objectWithoutProperties(_ref4, _excluded4);
296
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, rest2), {}, {
297
+ "data-index": index
298
+ }));
299
+ },
300
+ itemSize: 30,
301
+ overhang: 3,
302
+ placeholderRenderer: nop,
303
+ role: "list",
304
+ scrollContentRef: scrollContentRef,
305
+ scrollMode: "native",
306
+ spacing: 0,
307
+ cbScrollTo: nop,
308
+ ref: ref
309
+ }, rest)));
310
+ return {
311
+ ref: ref
312
+ };
313
+ }
314
+ beforeEach(function () {
315
+ originalGetComputedStyle = window.getComputedStyle;
316
+ });
317
+ afterEach(function () {
318
+ window.getComputedStyle = originalGetComputedStyle;
319
+ });
320
+ test('should increment scrollHeight and maxTop by the same margin sum when vertical item margins are detected, and not re-apply on subsequent updates', function () {
321
+ var _renderVirtualListBas = renderVirtualListBasic(),
322
+ ref = _renderVirtualListBas.ref;
323
+ var instance = ref.current;
324
+ var marginTop = 10;
325
+ var marginBottom = 5;
326
+ window.getComputedStyle = function (el) {
327
+ if (el === instance.props.itemRefs.current[0]) {
328
+ return {
329
+ getPropertyValue: function getPropertyValue(prop) {
330
+ if (prop === 'margin-top') return "".concat(marginTop, "px");
331
+ if (prop === 'margin-bottom') return "".concat(marginBottom, "px");
332
+ if (prop === 'margin-left') return '0px';
333
+ if (prop === 'margin-right') return '0px';
334
+ return '0px';
335
+ }
336
+ };
337
+ }
338
+ return originalGetComputedStyle(el);
339
+ };
340
+ instance.itemMarginTop = null;
341
+ (0, _react.act)(function () {
342
+ instance.forceUpdate();
343
+ });
344
+ var scrollHeightAfterFirst = instance.scrollBounds.scrollHeight;
345
+ var maxTopAfterFirst = instance.scrollBounds.maxTop;
346
+ expect(scrollHeightAfterFirst - maxTopAfterFirst).toBe(instance.props.clientSize.clientHeight);
347
+ expect(instance.scrollBounds.maxTop).toBe(instance.scrollBounds.scrollHeight - instance.props.clientSize.clientHeight);
348
+
349
+ // guard prevents re-applying on subsequent updates
350
+ (0, _react.act)(function () {
351
+ instance.forceUpdate();
352
+ });
353
+ expect(instance.scrollBounds.scrollHeight).toBe(scrollHeightAfterFirst);
354
+ expect(instance.scrollBounds.maxTop).toBe(maxTopAfterFirst);
355
+ });
356
+ test('should increment scrollWidth and maxLeft by the same margin sum when horizontal item margins are detected', function () {
357
+ var _renderVirtualListBas2 = renderVirtualListBasic({
358
+ direction: 'horizontal'
359
+ }),
360
+ ref = _renderVirtualListBas2.ref;
361
+ var instance = ref.current;
362
+ var marginLeft = 8;
363
+ var marginRight = 8;
364
+ window.getComputedStyle = function (el) {
365
+ if (el === instance.props.itemRefs.current[0]) {
366
+ return {
367
+ getPropertyValue: function getPropertyValue(prop) {
368
+ if (prop === 'margin-top') return '0px';
369
+ if (prop === 'margin-bottom') return '0px';
370
+ if (prop === 'margin-left') return "".concat(marginLeft, "px");
371
+ if (prop === 'margin-right') return "".concat(marginRight, "px");
372
+ return '0px';
373
+ }
374
+ };
375
+ }
376
+ return originalGetComputedStyle(el);
377
+ };
378
+ instance.itemMarginTop = null;
379
+ (0, _react.act)(function () {
380
+ instance.forceUpdate();
381
+ });
382
+ expect(instance.scrollBounds.scrollWidth - instance.scrollBounds.maxLeft).toBe(instance.props.clientSize.clientWidth);
383
+ });
154
384
  });
@@ -114,6 +114,7 @@ describe('VirtualList', function () {
114
114
  rest = _objectWithoutProperties(_ref3, _excluded);
115
115
  // eslint-disable-line enact/display-name
116
116
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", _objectSpread(_objectSpread({}, rest), {}, {
117
+ "data-index": index,
117
118
  id: 'item' + index,
118
119
  children: items[index].name
119
120
  }));
@@ -152,6 +153,18 @@ describe('VirtualList', function () {
152
153
  var actual = _react.screen.getByRole('list').children.item(0).textContent;
153
154
  expect(actual).toBe(expected);
154
155
  });
156
+ test('should render a list of \'items\' with horizontal direction', function () {
157
+ (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_VirtualList["default"], {
158
+ clientSize: clientSize,
159
+ dataSize: dataSize,
160
+ direction: "horizontal",
161
+ itemRenderer: renderItem,
162
+ itemSize: itemSize
163
+ }));
164
+ var expected = 'Account 0';
165
+ var actual = _react.screen.getByRole('list').children.item(0).textContent;
166
+ expect(actual).toBe(expected);
167
+ });
155
168
  test('should render overhang items when clientSize is not given', function () {
156
169
  (0, _react.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_VirtualList["default"], {
157
170
  dataSize: dataSize,
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "useId", {
11
11
  }
12
12
  });
13
13
  var _hoc = _interopRequireDefault(require("@enact/core/hoc"));
14
+ var _util = require("@enact/core/util");
14
15
  var _useId2 = _interopRequireDefault(require("./useId"));
15
16
  var _jsxRuntime = require("react/jsx-runtime");
16
17
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
@@ -66,6 +67,7 @@ var IdProvider = exports.IdProvider = (0, _hoc["default"])(defaultConfig, functi
66
67
 
67
68
  // eslint-disable-next-line no-shadow
68
69
  function IdProvider(props) {
70
+ (0, _util.checkPropTypes)(IdProvider, props);
69
71
  var updated = _objectSpread({}, props);
70
72
  var _useId = (0, _useId2["default"])({
71
73
  prefix: prefix
@@ -2,6 +2,7 @@
2
2
 
3
3
  require("@testing-library/jest-dom");
4
4
  var _react = require("@testing-library/react");
5
+ var _react2 = require("react");
5
6
  var _IdProvider = _interopRequireDefault(require("../IdProvider"));
6
7
  var _jsxRuntime = require("react/jsx-runtime");
7
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
@@ -30,7 +31,9 @@ describe('IdProvider', function () {
30
31
  var expected = 'customProp';
31
32
  var actual;
32
33
  var Base = function Base(props) {
33
- actual = props;
34
+ (0, _react2.useEffect)(function () {
35
+ actual = props;
36
+ }, [props]);
34
37
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {});
35
38
  };
36
39
  var Component = (0, _IdProvider["default"])({