@ringcentral/juno 2.4.2 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/components/Buttons/IconButton/IconButton.d.ts +10 -2
  2. package/components/Buttons/IconButton/IconButton.js +10 -8
  3. package/components/Buttons/IconButton/styles/StyledIconButton.js +15 -7
  4. package/components/Buttons/IconButton/utils/IconButtonUtils.d.ts +1 -1
  5. package/components/Buttons/IconButton/utils/IconButtonUtils.js +9 -1
  6. package/components/Dialer/DialPad/DialPad.d.ts +25 -7
  7. package/components/Dialer/DialPad/DialPad.js +6 -6
  8. package/components/Dialer/DialPad/utils/useDialKeyboard.d.ts +8 -9
  9. package/components/Dialer/DialTextField/DialTextField.d.ts +3 -1
  10. package/components/Dialer/DialTextField/DialTextField.js +7 -6
  11. package/components/Downshift/SuggestionList/SuggestionList.d.ts +74 -2
  12. package/components/Downshift/styles/DownshiftStyle.d.ts +1 -1
  13. package/components/Forms/Picker/DatePicker/styles/StyledDatePickerHeader.d.ts +1 -1
  14. package/components/Forms/Picker/DatePicker/styles/StyledYear.d.ts +1 -1
  15. package/components/Forms/Picker/TimePicker/styles/StyledSelectionItem.d.ts +1 -1
  16. package/components/Forms/Picker/TimePicker/styles/StyledTimeIconButton.d.ts +1 -1
  17. package/components/Forms/Picker/styles/PickerBaseIconButton.d.ts +1 -1
  18. package/components/Forms/TextField/styles/ClearIconButton.d.ts +2 -2
  19. package/components/Grid/Grid.d.ts +1 -1
  20. package/components/Pagination/Pagination/Pagination.d.ts +1 -1
  21. package/components/Stepper/StepButton/StepButton.d.ts +1 -1
  22. package/components/Stepper/StepLabel/StepLabel.d.ts +1 -1
  23. package/components/Table/TableCell/styles/TableCellStyle.js +3 -1
  24. package/components/Table/types.d.ts +1 -1
  25. package/components/TablePagination/TablePagination.d.ts +1 -1
  26. package/components/VirtualizedMenu/VirtualizedMenu.js +11 -0
  27. package/components/VirtualizedMenu/VirtualizedMenuList.js +6 -2
  28. package/components/Virtuoso/react-virtuoso/AATree.js +15 -15
  29. package/components/Virtuoso/react-virtuoso/Grid.d.ts +193 -106
  30. package/components/Virtuoso/react-virtuoso/Grid.js +19 -24
  31. package/components/Virtuoso/react-virtuoso/List.d.ts +2664 -596
  32. package/components/Virtuoso/react-virtuoso/List.js +83 -70
  33. package/components/Virtuoso/react-virtuoso/Table.d.ts +6253 -0
  34. package/components/Virtuoso/react-virtuoso/Table.js +184 -0
  35. package/components/Virtuoso/react-virtuoso/alignToBottomSystem.d.ts +153 -37
  36. package/components/Virtuoso/react-virtuoso/components.d.ts +248 -41
  37. package/components/Virtuoso/react-virtuoso/components.js +2 -0
  38. package/components/Virtuoso/react-virtuoso/domIOSystem.d.ts +2 -4
  39. package/components/Virtuoso/react-virtuoso/domIOSystem.js +12 -10
  40. package/components/Virtuoso/react-virtuoso/followOutputSystem.d.ts +146 -27
  41. package/components/Virtuoso/react-virtuoso/followOutputSystem.js +28 -15
  42. package/components/Virtuoso/react-virtuoso/gridSystem.d.ts +67 -52
  43. package/components/Virtuoso/react-virtuoso/gridSystem.js +17 -15
  44. package/components/Virtuoso/react-virtuoso/groupedListSystem.d.ts +17 -3
  45. package/components/Virtuoso/react-virtuoso/hooks/useChangedChildSizes.d.ts +2 -1
  46. package/components/Virtuoso/react-virtuoso/hooks/useChangedChildSizes.js +32 -7
  47. package/components/Virtuoso/react-virtuoso/hooks/useScrollTop.d.ts +1 -1
  48. package/components/Virtuoso/react-virtuoso/hooks/useScrollTop.js +40 -26
  49. package/components/Virtuoso/react-virtuoso/hooks/useSize.d.ts +2 -2
  50. package/components/Virtuoso/react-virtuoso/hooks/useSize.js +26 -28
  51. package/components/Virtuoso/react-virtuoso/hooks/useWindowViewportRect.d.ts +1 -1
  52. package/components/Virtuoso/react-virtuoso/hooks/useWindowViewportRect.js +32 -12
  53. package/components/Virtuoso/react-virtuoso/index.d.ts +1 -0
  54. package/components/Virtuoso/react-virtuoso/index.js +2 -0
  55. package/components/Virtuoso/react-virtuoso/initialItemCountSystem.d.ts +165 -35
  56. package/components/Virtuoso/react-virtuoso/initialItemCountSystem.js +1 -8
  57. package/components/Virtuoso/react-virtuoso/initialScrollTopSystem.d.ts +160 -38
  58. package/components/Virtuoso/react-virtuoso/initialTopMostItemIndexSystem.d.ts +54 -12
  59. package/components/Virtuoso/react-virtuoso/initialTopMostItemIndexSystem.js +26 -10
  60. package/components/Virtuoso/react-virtuoso/interfaces.d.ts +134 -28
  61. package/components/Virtuoso/react-virtuoso/listStateSystem.d.ts +141 -32
  62. package/components/Virtuoso/react-virtuoso/listStateSystem.js +1 -2
  63. package/components/Virtuoso/react-virtuoso/listSystem.d.ts +2123 -407
  64. package/components/Virtuoso/react-virtuoso/listSystem.js +10 -7
  65. package/components/Virtuoso/react-virtuoso/loggerSystem.d.ts +17 -0
  66. package/components/Virtuoso/react-virtuoso/loggerSystem.js +37 -0
  67. package/components/Virtuoso/react-virtuoso/propsReadySystem.d.ts +8 -1
  68. package/components/Virtuoso/react-virtuoso/propsReadySystem.js +8 -2
  69. package/components/Virtuoso/react-virtuoso/scrollIntoViewSystem.d.ts +641 -0
  70. package/components/Virtuoso/react-virtuoso/scrollIntoViewSystem.js +42 -0
  71. package/components/Virtuoso/react-virtuoso/scrollSeekSystem.d.ts +52 -67
  72. package/components/Virtuoso/react-virtuoso/scrollSeekSystem.js +11 -25
  73. package/components/Virtuoso/react-virtuoso/scrollToIndexSystem.d.ts +26 -5
  74. package/components/Virtuoso/react-virtuoso/scrollToIndexSystem.js +37 -13
  75. package/components/Virtuoso/react-virtuoso/sizeRangeSystem.d.ts +11 -4
  76. package/components/Virtuoso/react-virtuoso/sizeRangeSystem.js +44 -15
  77. package/components/Virtuoso/react-virtuoso/sizeSystem.d.ts +12 -2
  78. package/components/Virtuoso/react-virtuoso/sizeSystem.js +109 -52
  79. package/components/Virtuoso/react-virtuoso/stateFlagsSystem.d.ts +17 -5
  80. package/components/Virtuoso/react-virtuoso/stateFlagsSystem.js +87 -18
  81. package/components/Virtuoso/react-virtuoso/topItemCountSystem.d.ts +145 -33
  82. package/components/Virtuoso/react-virtuoso/totalListHeightSystem.d.ts +149 -35
  83. package/components/Virtuoso/react-virtuoso/upwardScrollFixSystem.d.ts +183 -42
  84. package/components/Virtuoso/react-virtuoso/upwardScrollFixSystem.js +37 -26
  85. package/components/Virtuoso/react-virtuoso/utils/correctItemSize.d.ts +1 -0
  86. package/components/Virtuoso/react-virtuoso/utils/correctItemSize.js +6 -0
  87. package/components/Virtuoso/react-virtuoso/windowScrollerSystem.d.ts +7 -4
  88. package/components/Virtuoso/react-virtuoso/windowScrollerSystem.js +9 -7
  89. package/es6/components/Buttons/IconButton/IconButton.js +12 -10
  90. package/es6/components/Buttons/IconButton/styles/StyledIconButton.js +16 -8
  91. package/es6/components/Buttons/IconButton/utils/IconButtonUtils.js +9 -1
  92. package/es6/components/Dialer/DialPad/DialPad.js +6 -6
  93. package/es6/components/Dialer/DialTextField/DialTextField.js +7 -6
  94. package/es6/components/Table/TableCell/TableCell.js +2 -2
  95. package/es6/components/Table/TableCell/styles/TableCellStyle.js +3 -1
  96. package/es6/components/VirtualizedMenu/VirtualizedMenu.js +13 -2
  97. package/es6/components/VirtualizedMenu/VirtualizedMenuList.js +6 -2
  98. package/es6/components/Virtuoso/react-virtuoso/AATree.js +15 -15
  99. package/es6/components/Virtuoso/react-virtuoso/Grid.js +20 -25
  100. package/es6/components/Virtuoso/react-virtuoso/List.js +84 -72
  101. package/es6/components/Virtuoso/react-virtuoso/Table.js +182 -0
  102. package/es6/components/Virtuoso/react-virtuoso/components.js +2 -0
  103. package/es6/components/Virtuoso/react-virtuoso/domIOSystem.js +13 -10
  104. package/es6/components/Virtuoso/react-virtuoso/followOutputSystem.js +28 -15
  105. package/es6/components/Virtuoso/react-virtuoso/gridSystem.js +17 -15
  106. package/es6/components/Virtuoso/react-virtuoso/hooks/useChangedChildSizes.js +31 -6
  107. package/es6/components/Virtuoso/react-virtuoso/hooks/useScrollTop.js +40 -26
  108. package/es6/components/Virtuoso/react-virtuoso/hooks/useSize.js +27 -29
  109. package/es6/components/Virtuoso/react-virtuoso/hooks/useWindowViewportRect.js +32 -12
  110. package/es6/components/Virtuoso/react-virtuoso/index.js +1 -0
  111. package/es6/components/Virtuoso/react-virtuoso/initialItemCountSystem.js +1 -8
  112. package/es6/components/Virtuoso/react-virtuoso/initialTopMostItemIndexSystem.js +25 -10
  113. package/es6/components/Virtuoso/react-virtuoso/listStateSystem.js +2 -3
  114. package/es6/components/Virtuoso/react-virtuoso/listSystem.js +10 -7
  115. package/es6/components/Virtuoso/react-virtuoso/loggerSystem.js +34 -0
  116. package/es6/components/Virtuoso/react-virtuoso/propsReadySystem.js +9 -2
  117. package/es6/components/Virtuoso/react-virtuoso/scrollIntoViewSystem.js +40 -0
  118. package/es6/components/Virtuoso/react-virtuoso/scrollSeekSystem.js +11 -25
  119. package/es6/components/Virtuoso/react-virtuoso/scrollToIndexSystem.js +37 -13
  120. package/es6/components/Virtuoso/react-virtuoso/sizeRangeSystem.js +39 -11
  121. package/es6/components/Virtuoso/react-virtuoso/sizeSystem.js +109 -52
  122. package/es6/components/Virtuoso/react-virtuoso/stateFlagsSystem.js +87 -18
  123. package/es6/components/Virtuoso/react-virtuoso/upwardScrollFixSystem.js +39 -28
  124. package/es6/components/Virtuoso/react-virtuoso/utils/correctItemSize.js +3 -0
  125. package/es6/components/Virtuoso/react-virtuoso/windowScrollerSystem.js +9 -7
  126. package/es6/foundation/hooks/useEventListener/useEventListener.js +27 -8
  127. package/es6/foundation/hooks/useGlobalListener/createGlobalListener.js +81 -0
  128. package/es6/foundation/hooks/useGlobalListener/index.js +1 -0
  129. package/es6/foundation/hooks/useGlobalListener/useGlobalListener.js +67 -97
  130. package/es6/foundation/hooks/useLongPress/useLongPress.js +52 -33
  131. package/es6/foundation/hooks/useTouchMouseEvent/useTouchMouseEvent.js +27 -28
  132. package/foundation/hooks/useEventListener/useEventListener.d.ts +12 -16
  133. package/foundation/hooks/useEventListener/useEventListener.js +26 -7
  134. package/foundation/hooks/useGlobalListener/createGlobalListener.d.ts +55 -0
  135. package/foundation/hooks/useGlobalListener/createGlobalListener.js +83 -0
  136. package/foundation/hooks/useGlobalListener/index.d.ts +1 -0
  137. package/foundation/hooks/useGlobalListener/index.js +1 -0
  138. package/foundation/hooks/useGlobalListener/useGlobalListener.d.ts +11 -105
  139. package/foundation/hooks/useGlobalListener/useGlobalListener.js +67 -97
  140. package/foundation/hooks/useLongPress/useLongPress.d.ts +10 -8
  141. package/foundation/hooks/useLongPress/useLongPress.js +50 -31
  142. package/foundation/hooks/useTouchMouseEvent/useTouchMouseEvent.d.ts +27 -14
  143. package/foundation/hooks/useTouchMouseEvent/useTouchMouseEvent.js +27 -28
  144. package/foundation/typings/deepPartial.d.ts +1 -1
  145. package/package.json +2 -2
@@ -1,6 +1,10 @@
1
1
  import { __read } from "tslib";
2
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
3
  import * as u from '@virtuoso.dev/urx';
3
4
  import { domIOSystem } from './domIOSystem';
5
+ export var UP = 'up';
6
+ export var DOWN = 'down';
7
+ export var NONE = 'none';
4
8
  var INITIAL_BOTTOM_STATE = {
5
9
  atBottom: false,
6
10
  notAtBottomBecause: 'NOT_SHOWING_LAST_ITEM',
@@ -8,42 +12,54 @@ var INITIAL_BOTTOM_STATE = {
8
12
  offsetBottom: 0,
9
13
  scrollTop: 0,
10
14
  viewportHeight: 0,
11
- totalHeight: 0,
15
+ scrollHeight: 0,
12
16
  },
13
17
  };
14
18
  export var stateFlagsSystem = u.system(function (_a) {
15
- var _b = __read(_a, 1), _c = _b[0], scrollTop = _c.scrollTop, viewportHeight = _c.viewportHeight;
19
+ var _b = __read(_a, 1), _c = _b[0], scrollContainerState = _c.scrollContainerState, scrollTop = _c.scrollTop, viewportHeight = _c.viewportHeight, headerHeight = _c.headerHeight, footerHeight = _c.footerHeight, scrollBy = _c.scrollBy;
16
20
  var isAtBottom = u.statefulStream(false);
17
21
  var isAtTop = u.statefulStream(true);
18
22
  var atBottomStateChange = u.stream();
19
23
  var atTopStateChange = u.stream();
20
- var listStateListener = u.stream();
24
+ var atBottomThreshold = u.statefulStream(4);
21
25
  // skip 1 to avoid an initial on/off flick
22
26
  var isScrolling = u.streamFromEmitter(u.pipe(u.merge(u.pipe(u.duc(scrollTop), u.skip(1), u.mapTo(true)), u.pipe(u.duc(scrollTop), u.skip(1), u.mapTo(false), u.debounceTime(100))), u.distinctUntilChanged()));
27
+ var isScrollingBy = u.statefulStreamFromEmitter(u.pipe(u.merge(u.pipe(scrollBy, u.mapTo(true)), u.pipe(scrollBy, u.mapTo(false), u.debounceTime(200))), u.distinctUntilChanged()), false);
28
+ // u.subscribe(isScrollingBy, (isScrollingBy) => console.log({ isScrollingBy }))
23
29
  u.connect(u.pipe(u.duc(scrollTop), u.map(function (top) { return top === 0; }), u.distinctUntilChanged()), isAtTop);
24
30
  u.connect(isAtTop, atTopStateChange);
25
- var atBottomState = u.streamFromEmitter(u.pipe(u.combineLatest(listStateListener, u.duc(scrollTop), u.duc(viewportHeight)), u.scan(function (current, _a) {
26
- var _b = __read(_a, 3), _c = _b[0], bottom = _c.bottom, offsetBottom = _c.offsetBottom, scrollTop = _b[1], viewportHeight = _b[2];
27
- var isAtBottom = offsetBottom === 0 && scrollTop + viewportHeight - bottom > -4;
31
+ var atBottomState = u.streamFromEmitter(u.pipe(u.combineLatest(scrollContainerState, u.duc(viewportHeight), u.duc(headerHeight), u.duc(footerHeight), u.duc(atBottomThreshold)), u.scan(function (current, _a) {
32
+ var _b = __read(_a, 5), _c = __read(_b[0], 2), scrollTop = _c[0], scrollHeight = _c[1], viewportHeight = _b[1], _headerHeight = _b[2], _footerHeight = _b[3], atBottomThreshold = _b[4];
33
+ var isAtBottom = scrollTop + viewportHeight - scrollHeight > -atBottomThreshold;
28
34
  var state = {
29
35
  viewportHeight: viewportHeight,
30
36
  scrollTop: scrollTop,
31
- offsetBottom: offsetBottom,
32
- totalHeight: bottom + offsetBottom,
37
+ scrollHeight: scrollHeight,
33
38
  };
34
39
  if (isAtBottom) {
40
+ var atBottomBecause = void 0;
41
+ var scrollTopDelta = void 0;
42
+ if (scrollTop > current.state.scrollTop) {
43
+ atBottomBecause = 'SCROLLED_DOWN';
44
+ scrollTopDelta = current.state.scrollTop - scrollTop;
45
+ }
46
+ else {
47
+ atBottomBecause = 'SIZE_DECREASED';
48
+ scrollTopDelta =
49
+ current.state.scrollTop - scrollTop ||
50
+ current.scrollTopDelta;
51
+ }
35
52
  return {
36
53
  atBottom: true,
37
54
  state: state,
55
+ atBottomBecause: atBottomBecause,
56
+ scrollTopDelta: scrollTopDelta,
38
57
  };
39
58
  }
40
59
  var notAtBottomBecause;
41
- if (state.totalHeight > current.state.totalHeight) {
60
+ if (state.scrollHeight > current.state.scrollHeight) {
42
61
  notAtBottomBecause = 'SIZE_INCREASED';
43
62
  }
44
- else if (offsetBottom !== 0) {
45
- notAtBottomBecause = 'NOT_SHOWING_LAST_ITEM';
46
- }
47
63
  else if (viewportHeight < current.state.viewportHeight) {
48
64
  notAtBottomBecause = 'VIEWPORT_HEIGHT_DECREASING';
49
65
  }
@@ -59,14 +75,64 @@ export var stateFlagsSystem = u.system(function (_a) {
59
75
  state: state,
60
76
  };
61
77
  }, INITIAL_BOTTOM_STATE), u.distinctUntilChanged(function (prev, next) {
62
- // prev && console.log(prev.atBottom, next.atBottom)
63
78
  return prev && prev.atBottom === next.atBottom;
64
79
  })));
80
+ var lastJumpDueToItemResize = u.statefulStreamFromEmitter(u.pipe(scrollContainerState, u.scan(function (current, _a) {
81
+ var _b = __read(_a, 2), scrollTop = _b[0], scrollHeight = _b[1];
82
+ if (current.scrollHeight !== scrollHeight) {
83
+ if (current.scrollTop !== scrollTop) {
84
+ return {
85
+ scrollHeight: scrollHeight,
86
+ scrollTop: scrollTop,
87
+ jump: current.scrollTop - scrollTop,
88
+ changed: true,
89
+ };
90
+ }
91
+ return {
92
+ scrollHeight: scrollHeight,
93
+ scrollTop: scrollTop,
94
+ jump: 0,
95
+ changed: true,
96
+ };
97
+ }
98
+ return {
99
+ scrollTop: scrollTop,
100
+ scrollHeight: scrollHeight,
101
+ jump: 0,
102
+ changed: false,
103
+ };
104
+ }, { scrollHeight: 0, jump: 0, scrollTop: 0, changed: false }), u.filter(function (value) { return value.changed; }), u.map(function (value) { return value.jump; })), 0);
65
105
  u.connect(u.pipe(atBottomState, u.map(function (state) { return state.atBottom; })), isAtBottom);
66
- u.subscribe(isAtBottom, function (value) {
67
- setTimeout(function () { return u.publish(atBottomStateChange, value); });
68
- });
69
- // connect(isAtBottom, atBottomStateChange)
106
+ u.connect(u.pipe(isAtBottom, u.throttleTime(50)), atBottomStateChange);
107
+ var scrollDirection = u.statefulStream(DOWN);
108
+ u.connect(u.pipe(scrollContainerState, u.map(function (_a) {
109
+ var _b = __read(_a, 1), scrollTop = _b[0];
110
+ return scrollTop;
111
+ }), u.distinctUntilChanged(), u.scan(function (acc, scrollTop) {
112
+ // if things change while compensating for items, ignore,
113
+ // but store the new scrollTop
114
+ if (u.getValue(isScrollingBy)) {
115
+ return { direction: acc.direction, prevScrollTop: scrollTop };
116
+ }
117
+ return {
118
+ direction: scrollTop < acc.prevScrollTop ? UP : DOWN,
119
+ prevScrollTop: scrollTop,
120
+ };
121
+ }, { direction: DOWN, prevScrollTop: 0 }), u.map(function (value) { return value.direction; })), scrollDirection);
122
+ u.connect(u.pipe(scrollContainerState, u.throttleTime(50), u.mapTo(NONE)), scrollDirection);
123
+ var scrollVelocity = u.statefulStream(0);
124
+ u.connect(u.pipe(isScrolling, u.filter(function (value) { return !value; }), u.mapTo(0)), scrollVelocity);
125
+ u.connect(u.pipe(scrollTop, u.throttleTime(100), u.withLatestFrom(isScrolling), u.filter(function (_a) {
126
+ var _b = __read(_a, 2), _ = _b[0], isScrolling = _b[1];
127
+ return !!isScrolling;
128
+ }), u.scan(function (_a, _b) {
129
+ var _c = __read(_a, 2), _ = _c[0], prev = _c[1];
130
+ var _d = __read(_b, 1), next = _d[0];
131
+ return [prev, next];
132
+ }, [0, 0]), u.map(function (_a) {
133
+ var _b = __read(_a, 2), prev = _b[0], next = _b[1];
134
+ return next - prev;
135
+ })), scrollVelocity);
70
136
  return {
71
137
  isScrolling: isScrolling,
72
138
  isAtTop: isAtTop,
@@ -74,6 +140,9 @@ export var stateFlagsSystem = u.system(function (_a) {
74
140
  atBottomState: atBottomState,
75
141
  atTopStateChange: atTopStateChange,
76
142
  atBottomStateChange: atBottomStateChange,
77
- listStateListener: listStateListener,
143
+ scrollDirection: scrollDirection,
144
+ atBottomThreshold: atBottomThreshold,
145
+ scrollVelocity: scrollVelocity,
146
+ lastJumpDueToItemResize: lastJumpDueToItemResize,
78
147
  };
79
148
  }, u.tup(domIOSystem));
@@ -1,43 +1,43 @@
1
1
  import { __read } from "tslib";
2
2
  /* eslint-disable no-continue */
3
3
  import * as u from '@virtuoso.dev/urx';
4
- import { domIOSystem, UP } from './domIOSystem';
4
+ import { domIOSystem } from './domIOSystem';
5
5
  import { listStateSystem } from './listStateSystem';
6
+ import { loggerSystem, LogLevel } from './loggerSystem';
6
7
  import { sizeSystem } from './sizeSystem';
7
- import { stateFlagsSystem } from './stateFlagsSystem';
8
+ import { stateFlagsSystem, UP } from './stateFlagsSystem';
8
9
  /**
9
10
  * Fixes upward scrolling by calculating and compensation from changed item heights, using scrollBy.
10
11
  */
11
12
  export var upwardScrollFixSystem = u.system(function (_a) {
12
- var _b = __read(_a, 4), _c = _b[0], scrollBy = _c.scrollBy, scrollTop = _c.scrollTop, scrollDirection = _c.scrollDirection, deviation = _c.deviation, scrollingInProgress = _c.scrollingInProgress, isScrolling = _b[1].isScrolling, listState = _b[2].listState, _d = _b[3], beforeUnshiftWith = _d.beforeUnshiftWith, sizes = _d.sizes;
13
- var deviationOffset = u.streamFromEmitter(u.pipe(listState, u.withLatestFrom(scrollTop, scrollDirection, scrollingInProgress), u.filter(function (_a) {
14
- var _b = __read(_a, 4), scrollTop = _b[1], scrollDirection = _b[2], scrollingInProgress = _b[3];
15
- return (!scrollingInProgress && scrollTop !== 0 && scrollDirection === UP);
16
- }), u.map(function (_a) {
17
- var _b = __read(_a, 1), state = _b[0];
18
- return state;
19
- }), u.scan(function (_a, _b) {
20
- var _c = __read(_a, 2), prevItems = _c[1];
21
- var items = _b.items;
13
+ var _b = __read(_a, 5), _c = _b[0], scrollBy = _c.scrollBy, scrollTop = _c.scrollTop, deviation = _c.deviation, scrollingInProgress = _c.scrollingInProgress, _d = _b[1], isScrolling = _d.isScrolling, isAtBottom = _d.isAtBottom, atBottomState = _d.atBottomState, scrollDirection = _d.scrollDirection, lastJumpDueToItemResize = _d.lastJumpDueToItemResize, listState = _b[2].listState, _e = _b[3], beforeUnshiftWith = _e.beforeUnshiftWith, shiftWithOffset = _e.shiftWithOffset, sizes = _e.sizes, log = _b[4].log;
14
+ var deviationOffset = u.streamFromEmitter(u.pipe(listState, u.withLatestFrom(lastJumpDueToItemResize), u.scan(function (_a,
15
+ // @ts-ignore
16
+ _b) {
17
+ var _c = __read(_a, 3), prevItems = _c[1], prevTotalCount = _c[2];
18
+ var
19
+ // @ts-ignore
20
+ _d = __read(_b, 2), _e = _d[0], items = _e.items, totalCount = _e.totalCount, lastJumpDueToItemResize = _d[1];
22
21
  var newDev = 0;
23
- if (prevItems.length > 0 && items.length > 0) {
24
- var firstItemIndex = items[0].originalIndex;
25
- var prevFirstItemIndex = prevItems[0].originalIndex;
26
- var atStart = firstItemIndex === 0 && prevFirstItemIndex === 0;
27
- if (!atStart) {
28
- // Handles an item taller than the viewport
29
- if (firstItemIndex === prevFirstItemIndex) {
30
- newDev = items[0].size - prevItems[0].size;
31
- }
32
- else {
22
+ if (prevTotalCount === totalCount) {
23
+ if (prevItems.length > 0 && items.length > 0) {
24
+ var firstItemIndex = items[0].originalIndex;
25
+ var prevFirstItemIndex = prevItems[0].originalIndex;
26
+ var atStart = firstItemIndex === 0 && prevFirstItemIndex === 0;
27
+ var onlyItem = items.length === 1;
28
+ if (!atStart) {
33
29
  var _loop_1 = function (index) {
34
30
  var item = items[index];
35
31
  var prevItem = prevItems.find(function (pItem) { return pItem.originalIndex === item.originalIndex; });
36
32
  if (!prevItem) {
37
33
  return "continue";
38
34
  }
39
- if (item.offset !== prevItem.offset) {
40
- newDev = item.offset - prevItem.offset;
35
+ if (item.offset !== prevItem.offset || onlyItem) {
36
+ newDev =
37
+ item.offset -
38
+ prevItem.offset +
39
+ item.size -
40
+ prevItem.size;
41
41
  return "break";
42
42
  }
43
43
  };
@@ -48,13 +48,21 @@ export var upwardScrollFixSystem = u.system(function (_a) {
48
48
  }
49
49
  }
50
50
  }
51
+ if (newDev !== 0) {
52
+ newDev += lastJumpDueToItemResize;
53
+ }
51
54
  }
52
- return [newDev, items];
53
- }, [0, []]), u.filter(function (_a) {
55
+ return [newDev, items, totalCount];
56
+ }, [0, [], 0]), u.filter(function (_a) {
54
57
  var _b = __read(_a, 1), amount = _b[0];
55
58
  return amount !== 0;
59
+ }), u.withLatestFrom(scrollTop, scrollDirection, scrollingInProgress, log, isAtBottom, atBottomState), u.filter(function (_a) {
60
+ var _b = __read(_a, 4), scrollTop = _b[1], scrollDirection = _b[2], scrollingInProgress = _b[3];
61
+ // console.log({ amount, scrollTop, scrollDirection, scrollingInProgress, isAtBottom, atBottomState })
62
+ return (!scrollingInProgress && scrollTop !== 0 && scrollDirection === UP); // && (isAtBottom ? amount > 0 : true)
56
63
  }), u.map(function (_a) {
57
- var _b = __read(_a, 1), amount = _b[0];
64
+ var _b = __read(_a, 5), _c = __read(_b[0], 1), amount = _c[0], log = _b[4];
65
+ log('Upward scrolling compensation', { amount: amount }, LogLevel.DEBUG);
58
66
  return amount;
59
67
  })));
60
68
  u.connect(u.pipe(deviationOffset, u.withLatestFrom(deviation), u.map(function (_a) {
@@ -79,9 +87,12 @@ export var upwardScrollFixSystem = u.system(function (_a) {
79
87
  u.publish(scrollBy, { top: -offset, behavior: 'auto' });
80
88
  }
81
89
  });
90
+ u.connect(u.pipe(shiftWithOffset, u.map(function (offset) {
91
+ return { top: -offset };
92
+ })), scrollBy);
82
93
  u.connect(u.pipe(beforeUnshiftWith, u.withLatestFrom(sizes), u.map(function (_a) {
83
94
  var _b = __read(_a, 2), offset = _b[0], lastSize = _b[1].lastSize;
84
95
  return offset * lastSize;
85
96
  })), deviationOffset);
86
97
  return { deviation: deviation };
87
- }, u.tup(domIOSystem, stateFlagsSystem, listStateSystem, sizeSystem));
98
+ }, u.tup(domIOSystem, stateFlagsSystem, listStateSystem, sizeSystem, loggerSystem));
@@ -0,0 +1,3 @@
1
+ export function correctItemSize(el, dimension) {
2
+ return Math.round(el.getBoundingClientRect()[dimension]);
3
+ }
@@ -2,15 +2,16 @@ import { __assign, __read } from "tslib";
2
2
  import * as u from '@virtuoso.dev/urx';
3
3
  import { domIOSystem } from './domIOSystem';
4
4
  export var windowScrollerSystem = u.system(function (_a) {
5
- var _b = __read(_a, 1), _c = _b[0], scrollTop = _c.scrollTop, scrollTo = _c.scrollTo;
5
+ var _b = __read(_a, 1), _c = _b[0], scrollTo = _c.scrollTo, scrollContainerState = _c.scrollContainerState;
6
+ var windowScrollContainerState = u.stream();
6
7
  var windowViewportRect = u.stream();
7
- var windowScrollTop = u.stream();
8
8
  var windowScrollTo = u.stream();
9
9
  var useWindowScroll = u.statefulStream(false);
10
- u.connect(u.pipe(u.combineLatest(windowScrollTop, windowViewportRect), u.map(function (_a) {
11
- var _b = __read(_a, 2), windowScrollTop = _b[0], offsetTop = _b[1].offsetTop;
12
- return Math.max(0, windowScrollTop - offsetTop);
13
- })), scrollTop);
10
+ var customScrollParent = u.statefulStream(undefined);
11
+ u.connect(u.pipe(u.combineLatest(windowScrollContainerState, windowViewportRect), u.map(function (_a) {
12
+ var _b = __read(_a, 2), _c = __read(_b[0], 2), windowScrollTop = _c[0], scrollHeight = _c[1], offsetTop = _b[1].offsetTop;
13
+ return [Math.max(0, windowScrollTop - offsetTop), scrollHeight];
14
+ })), scrollContainerState);
14
15
  u.connect(u.pipe(scrollTo, u.withLatestFrom(windowViewportRect), u.map(function (_a) {
15
16
  var _b = __read(_a, 2), scrollTo = _b[0], offsetTop = _b[1].offsetTop;
16
17
  return __assign(__assign({}, scrollTo), { top: scrollTo.top + offsetTop });
@@ -18,8 +19,9 @@ export var windowScrollerSystem = u.system(function (_a) {
18
19
  return {
19
20
  // config
20
21
  useWindowScroll: useWindowScroll,
22
+ customScrollParent: customScrollParent,
21
23
  // input
22
- windowScrollTop: windowScrollTop,
24
+ windowScrollContainerState: windowScrollContainerState,
23
25
  windowViewportRect: windowViewportRect,
24
26
  // signals
25
27
  windowScrollTo: windowScrollTo,
@@ -1,4 +1,4 @@
1
- import { __read } from "tslib";
1
+ import { __assign, __rest } from "tslib";
2
2
  import { useEffect, useRef } from 'react';
3
3
  import { getRefElement } from '../../utils';
4
4
  import { useEventCallback } from '../useEventCallback';
@@ -17,13 +17,14 @@ import { useEventCallback } from '../useEventCallback';
17
17
  * useEventListener(window, 'keyup', () => console.log('window key up'))
18
18
  * ```
19
19
  */
20
- export function useEventListener(target) {
21
- var o = [];
22
- for (var _i = 1; _i < arguments.length; _i++) {
23
- o[_i - 1] = arguments[_i];
20
+ export function useEventListener(target, key, callback) {
21
+ var args = [];
22
+ for (var _i = 3; _i < arguments.length; _i++) {
23
+ args[_i - 3] = arguments[_i];
24
24
  }
25
- var _a = __read(o, 3), key = _a[0], cb = _a[1], options = _a[2];
26
- var listener = useEventCallback(cb);
25
+ var _a = getListenerOverloadOption(args), options = _a.options, config = _a.config;
26
+ var _b = (config || {}).startImmediately, startImmediately = _b === void 0 ? true : _b;
27
+ var listener = useEventCallback(callback);
27
28
  var cancelRef = useRef(function () { });
28
29
  var bindRef = useRef(function () { });
29
30
  var currentRefElm = getRefElement(target);
@@ -38,7 +39,9 @@ export function useEventListener(target) {
38
39
  cancelRef.current = function () {
39
40
  return currentElm.removeEventListener(key, listener, options);
40
41
  };
41
- bindRef.current();
42
+ if (startImmediately) {
43
+ bindRef.current();
44
+ }
42
45
  return cancelRef.current;
43
46
  // eslint-disable-next-line react-hooks/exhaustive-deps
44
47
  }, [target, currentRefElm]);
@@ -47,3 +50,19 @@ export function useEventListener(target) {
47
50
  remove: function () { return cancelRef.current(); },
48
51
  };
49
52
  }
53
+ function getListenerOverloadOption(args) {
54
+ var options;
55
+ var config;
56
+ if (typeof args[0] === 'boolean') {
57
+ options = args[0];
58
+ config = args[1];
59
+ }
60
+ else {
61
+ var _a = __assign(__assign({}, (args[0] || {})), (args[1] || {})), startImmediately = _a.startImmediately, restOptions = __rest(_a, ["startImmediately"]);
62
+ options = restOptions;
63
+ config = {
64
+ startImmediately: startImmediately,
65
+ };
66
+ }
67
+ return { options: options, config: config };
68
+ }
@@ -0,0 +1,81 @@
1
+ import { getRefElement } from '../../utils';
2
+ export var globalListenerEventMap = new Map();
3
+ /**
4
+ * create globalListener handler for share one listener event
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * const globalListener = createGlobalListener('focus', () => { console.log('focus') });
9
+ * const globalListener2 = createGlobalListener('focus', () => { console.log('focus') });
10
+ * globalListener.listen();
11
+ * globalListener2.listen();
12
+ *
13
+ * => // that will only create an event listener on window, but every callback will get emit value when event triggered
14
+ * ```
15
+ */
16
+ export var createGlobalListener = function (key, listener, options, _a) {
17
+ var _b = _a === void 0 ? {} : _a, _c = _b.customKey, customKey = _c === void 0 ? key : _c, _d = _b.target, targetProp = _d === void 0 ? window : _d;
18
+ var listening = false;
19
+ var getMapValue = function () { return globalListenerEventMap.get(customKey); };
20
+ var addListener = function () {
21
+ if (listening)
22
+ return;
23
+ var savedEvent = getMapValue();
24
+ if (!(savedEvent === null || savedEvent === void 0 ? void 0 : savedEvent.exec)) {
25
+ var exec = function (e) {
26
+ var event = getMapValue();
27
+ event === null || event === void 0 ? void 0 : event.listeners.forEach(function (c) { return c(e); });
28
+ };
29
+ globalListenerEventMap.set(customKey, {
30
+ exec: exec,
31
+ listeners: new Set([listener]),
32
+ });
33
+ var target = getRefElement(targetProp);
34
+ target === null || target === void 0 ? void 0 : target.addEventListener(key, exec, options);
35
+ }
36
+ else {
37
+ savedEvent.listeners.add(listener);
38
+ }
39
+ listening = true;
40
+ };
41
+ var removeListener = function () {
42
+ if (!listening)
43
+ return;
44
+ listening = false;
45
+ var _savedEvent = getMapValue();
46
+ if (!_savedEvent)
47
+ return;
48
+ var listeners = _savedEvent.listeners;
49
+ listeners.delete(listener);
50
+ if (listeners.size === 0) {
51
+ var target = getRefElement(targetProp);
52
+ target === null || target === void 0 ? void 0 : target.removeEventListener(key, _savedEvent.exec, options);
53
+ globalListenerEventMap.delete(customKey);
54
+ }
55
+ };
56
+ return {
57
+ listen: function () { return addListener(); },
58
+ /**
59
+ * remove listener
60
+ */
61
+ remove: function () { return removeListener(); },
62
+ /**
63
+ * current listener state
64
+ */
65
+ get state() {
66
+ return {
67
+ /**
68
+ * current listener state count
69
+ */
70
+ get count() {
71
+ var _a;
72
+ return ((_a = getMapValue()) === null || _a === void 0 ? void 0 : _a.listeners.size) || 0;
73
+ },
74
+ /**
75
+ * is that be listening
76
+ */
77
+ listening: listening,
78
+ };
79
+ },
80
+ };
81
+ };
@@ -1 +1,2 @@
1
+ export * from './createGlobalListener';
1
2
  export * from './useGlobalListener';
@@ -1,89 +1,8 @@
1
+ import { __assign, __rest } from "tslib";
1
2
  import { useEffect, useRef } from 'react';
2
3
  import { getRefElement, logInDev } from '../../utils';
3
4
  import { useEventCallback } from '../useEventCallback';
4
- export var globalListenerEventMap = new Map();
5
- /**
6
- * create globalListener handler for share one listener event
7
- *
8
- * @example
9
- * ```ts
10
- * const globalListener = createGlobalListener('focus', () => { console.log('focus') });
11
- * const globalListener2 = createGlobalListener('focus', () => { console.log('focus') });
12
- * globalListener.listen();
13
- * globalListener2.listen();
14
- *
15
- * => // that will only create an event listener on window, but every callback will get emit value when event triggered
16
- * ```
17
- */
18
- export var createGlobalListener = function (key, listener, _a) {
19
- var _b = _a === void 0 ? {} : _a, _c = _b.customKey, customKey = _c === void 0 ? key : _c, _d = _b.target, targetProp = _d === void 0 ? window : _d;
20
- var listening = false;
21
- var getMapValue = function () { return globalListenerEventMap.get(customKey); };
22
- var addListener = function () {
23
- if (listening)
24
- return;
25
- var savedEvent = getMapValue();
26
- if (!(savedEvent === null || savedEvent === void 0 ? void 0 : savedEvent.exec)) {
27
- var exec = function (e) {
28
- var event = getMapValue();
29
- event === null || event === void 0 ? void 0 : event.listeners.forEach(function (c) { return c(e); });
30
- };
31
- globalListenerEventMap.set(customKey, {
32
- exec: exec,
33
- listeners: new Set([listener]),
34
- });
35
- var target = getRefElement(targetProp);
36
- target === null || target === void 0 ? void 0 : target.addEventListener(key, exec);
37
- }
38
- else {
39
- savedEvent.listeners.add(listener);
40
- }
41
- listening = true;
42
- };
43
- var removeListener = function () {
44
- if (!listening)
45
- return;
46
- listening = false;
47
- var _savedEvent = getMapValue();
48
- if (!_savedEvent)
49
- return;
50
- var listeners = _savedEvent.listeners;
51
- listeners.delete(listener);
52
- if (listeners.size === 0) {
53
- var target = getRefElement(targetProp);
54
- target === null || target === void 0 ? void 0 : target.removeEventListener(key, _savedEvent.exec);
55
- globalListenerEventMap.delete(customKey);
56
- }
57
- };
58
- return {
59
- /**
60
- * bind listener again
61
- */
62
- listen: function () { return addListener(); },
63
- /**
64
- * remove listener
65
- */
66
- remove: function () { return removeListener(); },
67
- /**
68
- * current listener state
69
- */
70
- get state() {
71
- return {
72
- /**
73
- * current listener state count
74
- */
75
- get count() {
76
- var _a;
77
- return ((_a = getMapValue()) === null || _a === void 0 ? void 0 : _a.listeners.size) || 0;
78
- },
79
- /**
80
- * is that be listening
81
- */
82
- listening: listening,
83
- };
84
- },
85
- };
86
- };
5
+ import { createGlobalListener, } from './createGlobalListener';
87
6
  /**
88
7
  * bind global event, when you bind same key event,
89
8
  * that will reuse one event listener and trigger both callback once that listener be triggered.
@@ -91,40 +10,91 @@ export var createGlobalListener = function (key, listener, _a) {
91
10
  * also you can control listener with method `listen` and `remove`
92
11
  * and get listener `state` for check listener count number and current listing state.
93
12
  *
94
- * - `key` `options` only work when set first time, never change after first render
13
+ * config:
14
+ * - `target`: custom binding event target, default is `window`
15
+ * - `customKey`: custom key for determining different event group, default is same as `key`
16
+ * - `startImmediately`: start listener immediately, default is `true`
17
+ *
18
+ * * `key`, `options` only work when set first time, never change after first render
95
19
  *
96
20
  * @example
97
21
  * ```ts
98
22
  * useGlobalListener('keyup', () => console.log('window key up1'))
23
+ *
99
24
  * useGlobalListener('keyup', () => console.log('window key up2'))
100
- * useGlobalListener('keyup', () => console.log('window key up3'))
25
+ *
26
+ * useGlobalListener('touchend', () => console.log('window key up3'), {
27
+ * target: someWantHostElement,
28
+ * customKey: 'hostTouchend',
29
+ * })
30
+ *
31
+ * useGlobalListener('touchend', () => console.log('window key up3'), { passive: false }, {
32
+ * target: someWantHostElement,
33
+ * customKey: 'hostTouchend',
34
+ * })
101
35
  *
102
36
  * => // that will only create an event listener on `window`, but every callback will get emit value when event triggered
103
37
  * ```
104
38
  */
105
- export function useGlobalListener(key, listener, options) {
106
- if (options === void 0) { options = {}; }
39
+ export function useGlobalListener(key, listener) {
40
+ var args = [];
41
+ for (var _i = 2; _i < arguments.length; _i++) {
42
+ args[_i - 2] = arguments[_i];
43
+ }
44
+ var _a = getListenerOverloadOption(args), options = _a.options, config = _a.config;
45
+ var _b = config || {}, _c = _b.customKey, customKey = _c === void 0 ? key : _c, _d = _b.target, targetProp = _d === void 0 ? window : _d, _e = _b.startImmediately, startImmediately = _e === void 0 ? true : _e;
107
46
  var _listener = useEventCallback(listener);
108
- var globalListener = useRef(createGlobalListener(key, _listener, options)).current;
47
+ var globalListener = useRef(createGlobalListener(key, _listener, options, {
48
+ customKey: customKey,
49
+ target: targetProp,
50
+ })).current;
109
51
  if (process.env.NODE_ENV !== 'production') {
110
- var _a = options.customKey, customKey_1 = _a === void 0 ? key : _a, _b = options.target, targetProp_1 = _b === void 0 ? window : _b;
111
52
  // eslint-disable-next-line react-hooks/rules-of-hooks
112
53
  useEffect(function () {
113
- var target = getRefElement(targetProp_1);
114
- if (target !== window && customKey_1 === key) {
115
- logInDev({
116
- component: 'useGlobalListener',
117
- message: 'When you custom binding event target, you must custom key for determining different event group',
118
- level: 'error',
119
- });
54
+ if (customKey === key) {
55
+ if (Object.keys(options).length > 0) {
56
+ logInDev({
57
+ component: 'useGlobalListener',
58
+ message: 'when have set options, suggest you also bind customKey, otherwise, it may use previous listener without same options',
59
+ level: 'warn',
60
+ });
61
+ }
62
+ var target = getRefElement(targetProp);
63
+ if (target !== window) {
64
+ logInDev({
65
+ component: 'useGlobalListener',
66
+ message: 'When you custom binding event target, you must custom key for determining different event group',
67
+ level: 'error',
68
+ });
69
+ }
120
70
  }
121
71
  // eslint-disable-next-line react-hooks/exhaustive-deps
122
72
  }, []);
123
73
  }
124
74
  useEffect(function () {
125
- globalListener.listen();
75
+ if (startImmediately) {
76
+ globalListener.listen();
77
+ }
126
78
  return globalListener.remove;
127
79
  // eslint-disable-next-line react-hooks/exhaustive-deps
128
80
  }, []);
129
81
  return globalListener;
130
82
  }
83
+ function getListenerOverloadOption(args) {
84
+ var options;
85
+ var config;
86
+ if (typeof args[0] === 'boolean') {
87
+ options = args[0];
88
+ config = args[1];
89
+ }
90
+ else {
91
+ var _a = __assign(__assign({}, (args[0] || {})), (args[1] || {})), startImmediately = _a.startImmediately, customKey = _a.customKey, target = _a.target, restOptions = __rest(_a, ["startImmediately", "customKey", "target"]);
92
+ options = restOptions;
93
+ config = {
94
+ startImmediately: startImmediately,
95
+ customKey: customKey,
96
+ target: target,
97
+ };
98
+ }
99
+ return { options: options, config: config };
100
+ }