instantsearch-ui-components 0.11.2 → 0.13.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.
- package/dist/cjs/components/Button.js +29 -0
- package/dist/cjs/components/Carousel.js +26 -6
- package/dist/cjs/components/autocomplete/Autocomplete.js +23 -0
- package/dist/cjs/components/autocomplete/AutocompleteIndex.js +44 -0
- package/dist/cjs/components/autocomplete/AutocompletePanel.js +25 -0
- package/dist/cjs/components/autocomplete/AutocompleteSearch.js +70 -0
- package/dist/cjs/components/autocomplete/AutocompleteSuggestion.js +20 -0
- package/dist/cjs/components/autocomplete/createAutocompletePropGetters.js +222 -0
- package/dist/cjs/components/autocomplete/icons.js +56 -0
- package/dist/cjs/components/autocomplete/index.js +71 -0
- package/dist/cjs/components/chat/Chat.js +79 -0
- package/dist/cjs/components/chat/ChatHeader.js +89 -0
- package/dist/cjs/components/chat/ChatMessage.js +138 -0
- package/dist/cjs/components/chat/ChatMessageError.js +57 -0
- package/dist/cjs/components/chat/ChatMessageLoader.js +47 -0
- package/dist/cjs/components/chat/ChatMessages.js +192 -0
- package/dist/cjs/components/chat/ChatPrompt.js +179 -0
- package/dist/cjs/components/chat/ChatToggleButton.js +46 -0
- package/dist/cjs/components/chat/icons.js +375 -0
- package/dist/cjs/components/chat/types.js +1 -0
- package/dist/cjs/components/index.js +132 -0
- package/dist/cjs/lib/index.js +22 -0
- package/dist/cjs/lib/stickToBottom.js +481 -0
- package/dist/cjs/lib/utils/find.js +15 -0
- package/dist/cjs/lib/utils/index.js +27 -0
- package/dist/cjs/lib/utils/startsWith.js +9 -0
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/warn.js +40 -0
- package/dist/es/components/Button.d.ts +38 -0
- package/dist/es/components/Button.js +22 -0
- package/dist/es/components/Carousel.d.ts +11 -0
- package/dist/es/components/Carousel.js +26 -6
- package/dist/es/components/autocomplete/Autocomplete.d.ts +13 -0
- package/dist/es/components/autocomplete/Autocomplete.js +16 -0
- package/dist/es/components/autocomplete/AutocompleteIndex.d.ts +38 -0
- package/dist/es/components/autocomplete/AutocompleteIndex.js +37 -0
- package/dist/es/components/autocomplete/AutocompletePanel.d.ts +17 -0
- package/dist/es/components/autocomplete/AutocompletePanel.js +18 -0
- package/dist/es/components/autocomplete/AutocompleteSearch.d.ts +8 -0
- package/dist/es/components/autocomplete/AutocompleteSearch.js +63 -0
- package/dist/es/components/autocomplete/AutocompleteSuggestion.d.ts +16 -0
- package/dist/es/components/autocomplete/AutocompleteSuggestion.js +14 -0
- package/dist/es/components/autocomplete/createAutocompletePropGetters.d.ts +49 -0
- package/dist/es/components/autocomplete/createAutocompletePropGetters.js +215 -0
- package/dist/es/components/autocomplete/icons.d.ts +7 -0
- package/dist/es/components/autocomplete/icons.js +48 -0
- package/dist/es/components/autocomplete/index.d.ts +6 -0
- package/dist/es/components/autocomplete/index.js +6 -0
- package/dist/es/components/chat/Chat.d.ts +42 -0
- package/dist/es/components/chat/Chat.js +72 -0
- package/dist/es/components/chat/ChatHeader.d.ts +99 -0
- package/dist/es/components/chat/ChatHeader.js +82 -0
- package/dist/es/components/chat/ChatMessage.d.ts +124 -0
- package/dist/es/components/chat/ChatMessage.js +131 -0
- package/dist/es/components/chat/ChatMessageError.d.ts +27 -0
- package/dist/es/components/chat/ChatMessageError.js +50 -0
- package/dist/es/components/chat/ChatMessageLoader.d.ts +15 -0
- package/dist/es/components/chat/ChatMessageLoader.js +40 -0
- package/dist/es/components/chat/ChatMessages.d.ts +139 -0
- package/dist/es/components/chat/ChatMessages.js +185 -0
- package/dist/es/components/chat/ChatPrompt.d.ts +119 -0
- package/dist/es/components/chat/ChatPrompt.js +172 -0
- package/dist/es/components/chat/ChatToggleButton.d.ts +29 -0
- package/dist/es/components/chat/ChatToggleButton.js +39 -0
- package/dist/es/components/chat/icons.d.ts +22 -0
- package/dist/es/components/chat/icons.js +355 -0
- package/dist/es/components/chat/types.d.ts +29 -0
- package/dist/es/components/chat/types.js +1 -0
- package/dist/es/components/index.d.ts +12 -0
- package/dist/es/components/index.js +12 -0
- package/dist/es/lib/index.d.ts +2 -0
- package/dist/es/lib/index.js +3 -1
- package/dist/es/lib/stickToBottom.d.ts +114 -0
- package/dist/es/lib/stickToBottom.js +474 -0
- package/dist/es/lib/utils/find.d.ts +1 -0
- package/dist/es/lib/utils/find.js +9 -0
- package/dist/es/lib/utils/index.d.ts +2 -0
- package/dist/es/lib/utils/index.js +2 -0
- package/dist/es/lib/utils/startsWith.d.ts +1 -0
- package/dist/es/lib/utils/startsWith.js +3 -0
- package/dist/es/types/Renderer.d.ts +1 -1
- package/dist/es/version.d.ts +1 -1
- package/dist/es/version.js +1 -1
- package/dist/es/warn.d.ts +10 -0
- package/dist/es/warn.js +33 -0
- package/package.json +7 -3
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _autocomplete = require("./autocomplete");
|
|
7
|
+
Object.keys(_autocomplete).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _autocomplete[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _autocomplete[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _Button = require("./Button");
|
|
18
|
+
Object.keys(_Button).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _Button[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function get() {
|
|
24
|
+
return _Button[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
6
28
|
var _Carousel = require("./Carousel");
|
|
7
29
|
Object.keys(_Carousel).forEach(function (key) {
|
|
8
30
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -14,6 +36,116 @@ Object.keys(_Carousel).forEach(function (key) {
|
|
|
14
36
|
}
|
|
15
37
|
});
|
|
16
38
|
});
|
|
39
|
+
var _Chat = require("./chat/Chat");
|
|
40
|
+
Object.keys(_Chat).forEach(function (key) {
|
|
41
|
+
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (key in exports && exports[key] === _Chat[key]) return;
|
|
43
|
+
Object.defineProperty(exports, key, {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function get() {
|
|
46
|
+
return _Chat[key];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
var _ChatHeader = require("./chat/ChatHeader");
|
|
51
|
+
Object.keys(_ChatHeader).forEach(function (key) {
|
|
52
|
+
if (key === "default" || key === "__esModule") return;
|
|
53
|
+
if (key in exports && exports[key] === _ChatHeader[key]) return;
|
|
54
|
+
Object.defineProperty(exports, key, {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function get() {
|
|
57
|
+
return _ChatHeader[key];
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
var _ChatMessage = require("./chat/ChatMessage");
|
|
62
|
+
Object.keys(_ChatMessage).forEach(function (key) {
|
|
63
|
+
if (key === "default" || key === "__esModule") return;
|
|
64
|
+
if (key in exports && exports[key] === _ChatMessage[key]) return;
|
|
65
|
+
Object.defineProperty(exports, key, {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function get() {
|
|
68
|
+
return _ChatMessage[key];
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
var _ChatMessages = require("./chat/ChatMessages");
|
|
73
|
+
Object.keys(_ChatMessages).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (key in exports && exports[key] === _ChatMessages[key]) return;
|
|
76
|
+
Object.defineProperty(exports, key, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function get() {
|
|
79
|
+
return _ChatMessages[key];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
var _ChatMessageLoader = require("./chat/ChatMessageLoader");
|
|
84
|
+
Object.keys(_ChatMessageLoader).forEach(function (key) {
|
|
85
|
+
if (key === "default" || key === "__esModule") return;
|
|
86
|
+
if (key in exports && exports[key] === _ChatMessageLoader[key]) return;
|
|
87
|
+
Object.defineProperty(exports, key, {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
get: function get() {
|
|
90
|
+
return _ChatMessageLoader[key];
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
var _ChatMessageError = require("./chat/ChatMessageError");
|
|
95
|
+
Object.keys(_ChatMessageError).forEach(function (key) {
|
|
96
|
+
if (key === "default" || key === "__esModule") return;
|
|
97
|
+
if (key in exports && exports[key] === _ChatMessageError[key]) return;
|
|
98
|
+
Object.defineProperty(exports, key, {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function get() {
|
|
101
|
+
return _ChatMessageError[key];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
var _ChatPrompt = require("./chat/ChatPrompt");
|
|
106
|
+
Object.keys(_ChatPrompt).forEach(function (key) {
|
|
107
|
+
if (key === "default" || key === "__esModule") return;
|
|
108
|
+
if (key in exports && exports[key] === _ChatPrompt[key]) return;
|
|
109
|
+
Object.defineProperty(exports, key, {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function get() {
|
|
112
|
+
return _ChatPrompt[key];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
var _ChatToggleButton = require("./chat/ChatToggleButton");
|
|
117
|
+
Object.keys(_ChatToggleButton).forEach(function (key) {
|
|
118
|
+
if (key === "default" || key === "__esModule") return;
|
|
119
|
+
if (key in exports && exports[key] === _ChatToggleButton[key]) return;
|
|
120
|
+
Object.defineProperty(exports, key, {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function get() {
|
|
123
|
+
return _ChatToggleButton[key];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
var _icons = require("./chat/icons");
|
|
128
|
+
Object.keys(_icons).forEach(function (key) {
|
|
129
|
+
if (key === "default" || key === "__esModule") return;
|
|
130
|
+
if (key in exports && exports[key] === _icons[key]) return;
|
|
131
|
+
Object.defineProperty(exports, key, {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
get: function get() {
|
|
134
|
+
return _icons[key];
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
var _types = require("./chat/types");
|
|
139
|
+
Object.keys(_types).forEach(function (key) {
|
|
140
|
+
if (key === "default" || key === "__esModule") return;
|
|
141
|
+
if (key in exports && exports[key] === _types[key]) return;
|
|
142
|
+
Object.defineProperty(exports, key, {
|
|
143
|
+
enumerable: true,
|
|
144
|
+
get: function get() {
|
|
145
|
+
return _types[key];
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
17
149
|
var _FrequentlyBoughtTogether = require("./FrequentlyBoughtTogether");
|
|
18
150
|
Object.keys(_FrequentlyBoughtTogether).forEach(function (key) {
|
|
19
151
|
if (key === "default" || key === "__esModule") return;
|
package/dist/cjs/lib/index.js
CHANGED
|
@@ -13,4 +13,26 @@ Object.keys(_cx).forEach(function (key) {
|
|
|
13
13
|
return _cx[key];
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
+
});
|
|
17
|
+
var _stickToBottom = require("./stickToBottom");
|
|
18
|
+
Object.keys(_stickToBottom).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _stickToBottom[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function get() {
|
|
24
|
+
return _stickToBottom[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
var _utils = require("./utils");
|
|
29
|
+
Object.keys(_utils).forEach(function (key) {
|
|
30
|
+
if (key === "default" || key === "__esModule") return;
|
|
31
|
+
if (key in exports && exports[key] === _utils[key]) return;
|
|
32
|
+
Object.defineProperty(exports, key, {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function get() {
|
|
35
|
+
return _utils[key];
|
|
36
|
+
}
|
|
37
|
+
});
|
|
16
38
|
});
|
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createStickToBottom = createStickToBottom;
|
|
8
|
+
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
9
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
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; }
|
|
12
|
+
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) { (0, _defineProperty2.default)(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; }
|
|
13
|
+
/* !---------------------------------------------------------------------------------------------
|
|
14
|
+
* Copyright (c) StackBlitz. All rights reserved.
|
|
15
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
16
|
+
*--------------------------------------------------------------------------------------------*/
|
|
17
|
+
|
|
18
|
+
var DEFAULT_SPRING_ANIMATION = {
|
|
19
|
+
/**
|
|
20
|
+
* A value from 0 to 1, on how much to damp the animation.
|
|
21
|
+
* 0 means no damping, 1 means full damping.
|
|
22
|
+
*
|
|
23
|
+
* @default 0.7
|
|
24
|
+
*/
|
|
25
|
+
damping: 0.7,
|
|
26
|
+
/**
|
|
27
|
+
* The stiffness of how fast/slow the animation gets up to speed.
|
|
28
|
+
*
|
|
29
|
+
* @default 0.05
|
|
30
|
+
*/
|
|
31
|
+
stiffness: 0.05,
|
|
32
|
+
/**
|
|
33
|
+
* The inertial mass associated with the animation.
|
|
34
|
+
* Higher numbers make the animation slower.
|
|
35
|
+
*
|
|
36
|
+
* @default 1.25
|
|
37
|
+
*/
|
|
38
|
+
mass: 1.25
|
|
39
|
+
};
|
|
40
|
+
var STICK_TO_BOTTOM_OFFSET_PX = 70;
|
|
41
|
+
var SIXTY_FPS_INTERVAL_MS = 1000 / 60;
|
|
42
|
+
var RETAIN_ANIMATION_DURATION_MS = 350;
|
|
43
|
+
var mouseDown = false;
|
|
44
|
+
if (typeof window !== 'undefined') {
|
|
45
|
+
var _window$document, _window$document2, _window$document3;
|
|
46
|
+
(_window$document = window.document) === null || _window$document === void 0 ? void 0 : _window$document.addEventListener('mousedown', function () {
|
|
47
|
+
mouseDown = true;
|
|
48
|
+
});
|
|
49
|
+
(_window$document2 = window.document) === null || _window$document2 === void 0 ? void 0 : _window$document2.addEventListener('mouseup', function () {
|
|
50
|
+
mouseDown = false;
|
|
51
|
+
});
|
|
52
|
+
(_window$document3 = window.document) === null || _window$document3 === void 0 ? void 0 : _window$document3.addEventListener('click', function () {
|
|
53
|
+
mouseDown = false;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function createStickToBottom(_ref) {
|
|
57
|
+
var useCallback = _ref.useCallback,
|
|
58
|
+
useEffect = _ref.useEffect,
|
|
59
|
+
useMemo = _ref.useMemo,
|
|
60
|
+
useRef = _ref.useRef,
|
|
61
|
+
useState = _ref.useState;
|
|
62
|
+
return function useStickToBottom() {
|
|
63
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
64
|
+
var _useState = useState(false),
|
|
65
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
66
|
+
escapedFromLock = _useState2[0],
|
|
67
|
+
updateEscapedFromLock = _useState2[1];
|
|
68
|
+
var _useState3 = useState(options.initial !== false),
|
|
69
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
70
|
+
isAtBottom = _useState4[0],
|
|
71
|
+
updateIsAtBottom = _useState4[1];
|
|
72
|
+
var _useState5 = useState(false),
|
|
73
|
+
_useState6 = (0, _slicedToArray2.default)(_useState5, 2),
|
|
74
|
+
isNearBottom = _useState6[0],
|
|
75
|
+
setIsNearBottom = _useState6[1];
|
|
76
|
+
var optionsRef = useRef(null);
|
|
77
|
+
optionsRef.current = options;
|
|
78
|
+
|
|
79
|
+
// Create refs early so they can be used in other hooks
|
|
80
|
+
var scrollRef = useRef(null);
|
|
81
|
+
var contentRef = useRef(null);
|
|
82
|
+
var isSelecting = useCallback(function () {
|
|
83
|
+
var _scrollRef$current;
|
|
84
|
+
if (!mouseDown) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
if (typeof window === 'undefined') {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
var selection = window.getSelection();
|
|
91
|
+
if (!selection || !selection.rangeCount) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
var range = selection.getRangeAt(0);
|
|
95
|
+
return range.commonAncestorContainer.contains(scrollRef.current) || ((_scrollRef$current = scrollRef.current) === null || _scrollRef$current === void 0 ? void 0 : _scrollRef$current.contains(range.commonAncestorContainer));
|
|
96
|
+
}, []);
|
|
97
|
+
|
|
98
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: state is intentionally stable
|
|
99
|
+
var state = useMemo(function () {
|
|
100
|
+
var lastCalculation;
|
|
101
|
+
return {
|
|
102
|
+
escapedFromLock: escapedFromLock,
|
|
103
|
+
isAtBottom: isAtBottom,
|
|
104
|
+
resizeDifference: 0,
|
|
105
|
+
accumulated: 0,
|
|
106
|
+
velocity: 0,
|
|
107
|
+
get scrollTop() {
|
|
108
|
+
var _scrollRef$current$sc, _scrollRef$current2;
|
|
109
|
+
return (_scrollRef$current$sc = (_scrollRef$current2 = scrollRef.current) === null || _scrollRef$current2 === void 0 ? void 0 : _scrollRef$current2.scrollTop) !== null && _scrollRef$current$sc !== void 0 ? _scrollRef$current$sc : 0;
|
|
110
|
+
},
|
|
111
|
+
set scrollTop(scrollTop) {
|
|
112
|
+
if (scrollRef.current) {
|
|
113
|
+
scrollRef.current.scrollTop = scrollTop;
|
|
114
|
+
state.ignoreScrollToTop = scrollRef.current.scrollTop;
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
get targetScrollTop() {
|
|
118
|
+
if (!scrollRef.current || !contentRef.current) {
|
|
119
|
+
return 0;
|
|
120
|
+
}
|
|
121
|
+
return scrollRef.current.scrollHeight - 1 - scrollRef.current.clientHeight;
|
|
122
|
+
},
|
|
123
|
+
get calculatedTargetScrollTop() {
|
|
124
|
+
var _lastCalculation;
|
|
125
|
+
if (!scrollRef.current || !contentRef.current) {
|
|
126
|
+
return 0;
|
|
127
|
+
}
|
|
128
|
+
var targetScrollTop = this.targetScrollTop;
|
|
129
|
+
if (!optionsRef.current.targetScrollTop) {
|
|
130
|
+
return targetScrollTop;
|
|
131
|
+
}
|
|
132
|
+
if (((_lastCalculation = lastCalculation) === null || _lastCalculation === void 0 ? void 0 : _lastCalculation.targetScrollTop) === targetScrollTop) {
|
|
133
|
+
return lastCalculation.calculatedScrollTop;
|
|
134
|
+
}
|
|
135
|
+
var calculatedScrollTop = Math.max(Math.min(optionsRef.current.targetScrollTop(targetScrollTop, {
|
|
136
|
+
scrollElement: scrollRef.current,
|
|
137
|
+
contentElement: contentRef.current
|
|
138
|
+
}), targetScrollTop), 0);
|
|
139
|
+
lastCalculation = {
|
|
140
|
+
targetScrollTop: targetScrollTop,
|
|
141
|
+
calculatedScrollTop: calculatedScrollTop
|
|
142
|
+
};
|
|
143
|
+
requestAnimationFrame(function () {
|
|
144
|
+
lastCalculation = undefined;
|
|
145
|
+
});
|
|
146
|
+
return calculatedScrollTop;
|
|
147
|
+
},
|
|
148
|
+
get scrollDifference() {
|
|
149
|
+
return this.calculatedTargetScrollTop - this.scrollTop;
|
|
150
|
+
},
|
|
151
|
+
get isNearBottom() {
|
|
152
|
+
return this.scrollDifference <= STICK_TO_BOTTOM_OFFSET_PX;
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
156
|
+
}, []);
|
|
157
|
+
var setIsAtBottom = useCallback(function (value) {
|
|
158
|
+
state.isAtBottom = value;
|
|
159
|
+
updateIsAtBottom(value);
|
|
160
|
+
}, [state]);
|
|
161
|
+
var setEscapedFromLock = useCallback(function (value) {
|
|
162
|
+
state.escapedFromLock = value;
|
|
163
|
+
updateEscapedFromLock(value);
|
|
164
|
+
}, [state]);
|
|
165
|
+
var scrollToBottom = useCallback(function () {
|
|
166
|
+
var _state$animation2;
|
|
167
|
+
var scrollOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
168
|
+
if (typeof scrollOptions === 'string') {
|
|
169
|
+
scrollOptions = {
|
|
170
|
+
animation: scrollOptions
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
if (!scrollOptions.preserveScrollPosition) {
|
|
174
|
+
setIsAtBottom(true);
|
|
175
|
+
}
|
|
176
|
+
var waitElapsed = Date.now() + (Number(scrollOptions.wait) || 0);
|
|
177
|
+
var behavior = mergeAnimations(optionsRef.current, scrollOptions.animation);
|
|
178
|
+
var _scrollOptions = scrollOptions,
|
|
179
|
+
_scrollOptions$ignore = _scrollOptions.ignoreEscapes,
|
|
180
|
+
ignoreEscapes = _scrollOptions$ignore === void 0 ? false : _scrollOptions$ignore;
|
|
181
|
+
var durationElapsed;
|
|
182
|
+
var startTarget = state.calculatedTargetScrollTop;
|
|
183
|
+
if (scrollOptions.duration instanceof Promise) {
|
|
184
|
+
scrollOptions.duration.then(function () {
|
|
185
|
+
durationElapsed = Date.now();
|
|
186
|
+
}, function () {
|
|
187
|
+
durationElapsed = Date.now();
|
|
188
|
+
});
|
|
189
|
+
} else {
|
|
190
|
+
var _scrollOptions$durati;
|
|
191
|
+
durationElapsed = waitElapsed + ((_scrollOptions$durati = scrollOptions.duration) !== null && _scrollOptions$durati !== void 0 ? _scrollOptions$durati : 0);
|
|
192
|
+
}
|
|
193
|
+
var next = function next() {
|
|
194
|
+
var promise = new Promise(requestAnimationFrame).then(function () {
|
|
195
|
+
var _state$lastTick;
|
|
196
|
+
if (!state.isAtBottom) {
|
|
197
|
+
state.animation = undefined;
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
var scrollTop = state.scrollTop;
|
|
201
|
+
var tick = performance.now();
|
|
202
|
+
var tickDelta = (tick - ((_state$lastTick = state.lastTick) !== null && _state$lastTick !== void 0 ? _state$lastTick : tick)) / SIXTY_FPS_INTERVAL_MS;
|
|
203
|
+
state.animation || (state.animation = {
|
|
204
|
+
behavior: behavior,
|
|
205
|
+
promise: promise,
|
|
206
|
+
ignoreEscapes: ignoreEscapes
|
|
207
|
+
});
|
|
208
|
+
if (state.animation.behavior === behavior) {
|
|
209
|
+
state.lastTick = tick;
|
|
210
|
+
}
|
|
211
|
+
if (isSelecting()) {
|
|
212
|
+
return next();
|
|
213
|
+
}
|
|
214
|
+
if (waitElapsed > Date.now()) {
|
|
215
|
+
return next();
|
|
216
|
+
}
|
|
217
|
+
if (scrollTop < Math.min(startTarget, state.calculatedTargetScrollTop)) {
|
|
218
|
+
var _state$animation;
|
|
219
|
+
if (((_state$animation = state.animation) === null || _state$animation === void 0 ? void 0 : _state$animation.behavior) === behavior) {
|
|
220
|
+
if (behavior === 'instant') {
|
|
221
|
+
state.scrollTop = state.calculatedTargetScrollTop;
|
|
222
|
+
return next();
|
|
223
|
+
}
|
|
224
|
+
state.velocity = (behavior.damping * state.velocity + behavior.stiffness * state.scrollDifference) / behavior.mass;
|
|
225
|
+
state.accumulated += state.velocity * tickDelta;
|
|
226
|
+
state.scrollTop += state.accumulated;
|
|
227
|
+
if (state.scrollTop !== scrollTop) {
|
|
228
|
+
state.accumulated = 0;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return next();
|
|
232
|
+
}
|
|
233
|
+
if (durationElapsed > Date.now()) {
|
|
234
|
+
startTarget = state.calculatedTargetScrollTop;
|
|
235
|
+
return next();
|
|
236
|
+
}
|
|
237
|
+
state.animation = undefined;
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* If we're still below the target, then queue
|
|
241
|
+
* up another scroll to the bottom with the last
|
|
242
|
+
* requested animatino.
|
|
243
|
+
*/
|
|
244
|
+
if (state.scrollTop < state.calculatedTargetScrollTop) {
|
|
245
|
+
return scrollToBottom({
|
|
246
|
+
animation: mergeAnimations(optionsRef.current, optionsRef.current.resize),
|
|
247
|
+
ignoreEscapes: ignoreEscapes,
|
|
248
|
+
duration: Math.max(0, durationElapsed - Date.now()) || undefined
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
return state.isAtBottom;
|
|
252
|
+
});
|
|
253
|
+
return promise.then(function (result) {
|
|
254
|
+
requestAnimationFrame(function () {
|
|
255
|
+
if (!state.animation) {
|
|
256
|
+
state.lastTick = undefined;
|
|
257
|
+
state.velocity = 0;
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
return result;
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
if (scrollOptions.wait !== true) {
|
|
264
|
+
state.animation = undefined;
|
|
265
|
+
}
|
|
266
|
+
if (((_state$animation2 = state.animation) === null || _state$animation2 === void 0 ? void 0 : _state$animation2.behavior) === behavior) {
|
|
267
|
+
return state.animation.promise;
|
|
268
|
+
}
|
|
269
|
+
return next();
|
|
270
|
+
}, [setIsAtBottom, isSelecting, state]);
|
|
271
|
+
var stopScroll = useCallback(function () {
|
|
272
|
+
setEscapedFromLock(true);
|
|
273
|
+
setIsAtBottom(false);
|
|
274
|
+
}, [setEscapedFromLock, setIsAtBottom]);
|
|
275
|
+
var handleScroll = useCallback(function (_ref2) {
|
|
276
|
+
var target = _ref2.target;
|
|
277
|
+
if (target !== scrollRef.current) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
var scrollTop = state.scrollTop,
|
|
281
|
+
ignoreScrollToTop = state.ignoreScrollToTop;
|
|
282
|
+
var _state$lastScrollTop = state.lastScrollTop,
|
|
283
|
+
lastScrollTop = _state$lastScrollTop === void 0 ? scrollTop : _state$lastScrollTop;
|
|
284
|
+
state.lastScrollTop = scrollTop;
|
|
285
|
+
state.ignoreScrollToTop = undefined;
|
|
286
|
+
if (ignoreScrollToTop && ignoreScrollToTop > scrollTop) {
|
|
287
|
+
/**
|
|
288
|
+
* When the user scrolls up while the animation plays, the `scrollTop` may
|
|
289
|
+
* not come in separate events; if this happens, to make sure `isScrollingUp`
|
|
290
|
+
* is correct, set the lastScrollTop to the ignored event.
|
|
291
|
+
*/
|
|
292
|
+
lastScrollTop = ignoreScrollToTop;
|
|
293
|
+
}
|
|
294
|
+
setIsNearBottom(state.isNearBottom);
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Scroll events may come before a ResizeObserver event,
|
|
298
|
+
* so in order to ignore resize events correctly we use a
|
|
299
|
+
* timeout.
|
|
300
|
+
*
|
|
301
|
+
* @see https://github.com/WICG/resize-observer/issues/25#issuecomment-248757228
|
|
302
|
+
*/
|
|
303
|
+
setTimeout(function () {
|
|
304
|
+
var _state$animation3;
|
|
305
|
+
/**
|
|
306
|
+
* When theres a resize difference ignore the resize event.
|
|
307
|
+
*/
|
|
308
|
+
if (state.resizeDifference || scrollTop === ignoreScrollToTop) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
if (isSelecting()) {
|
|
312
|
+
setEscapedFromLock(true);
|
|
313
|
+
setIsAtBottom(false);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
var isScrollingDown = scrollTop > lastScrollTop;
|
|
317
|
+
var isScrollingUp = scrollTop < lastScrollTop;
|
|
318
|
+
if ((_state$animation3 = state.animation) !== null && _state$animation3 !== void 0 && _state$animation3.ignoreEscapes) {
|
|
319
|
+
state.scrollTop = lastScrollTop;
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (isScrollingUp) {
|
|
323
|
+
setEscapedFromLock(true);
|
|
324
|
+
setIsAtBottom(false);
|
|
325
|
+
}
|
|
326
|
+
if (isScrollingDown) {
|
|
327
|
+
setEscapedFromLock(false);
|
|
328
|
+
}
|
|
329
|
+
if (!state.escapedFromLock && state.isNearBottom) {
|
|
330
|
+
setIsAtBottom(true);
|
|
331
|
+
}
|
|
332
|
+
}, 1);
|
|
333
|
+
}, [setEscapedFromLock, setIsAtBottom, isSelecting, state]);
|
|
334
|
+
var handleWheel = useCallback(function (_ref3) {
|
|
335
|
+
var _state$animation4;
|
|
336
|
+
var target = _ref3.target,
|
|
337
|
+
deltaY = _ref3.deltaY;
|
|
338
|
+
var element = target;
|
|
339
|
+
while (!['scroll', 'auto'].includes(getComputedStyle(element).overflow)) {
|
|
340
|
+
if (!element.parentElement) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
element = element.parentElement;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* The browser may cancel the scrolling from the mouse wheel
|
|
348
|
+
* if we update it from the animation in meantime.
|
|
349
|
+
* To prevent this, always escape when the wheel is scrolled up.
|
|
350
|
+
*/
|
|
351
|
+
if (element === scrollRef.current && deltaY < 0 && scrollRef.current.scrollHeight > scrollRef.current.clientHeight && !((_state$animation4 = state.animation) !== null && _state$animation4 !== void 0 && _state$animation4.ignoreEscapes)) {
|
|
352
|
+
setEscapedFromLock(true);
|
|
353
|
+
setIsAtBottom(false);
|
|
354
|
+
}
|
|
355
|
+
}, [setEscapedFromLock, setIsAtBottom, state]);
|
|
356
|
+
|
|
357
|
+
// Attach scroll and wheel event listeners
|
|
358
|
+
useEffect(function () {
|
|
359
|
+
var scroll = scrollRef.current;
|
|
360
|
+
if (!scroll) {
|
|
361
|
+
return undefined;
|
|
362
|
+
}
|
|
363
|
+
scroll.addEventListener('scroll', handleScroll, {
|
|
364
|
+
passive: true
|
|
365
|
+
});
|
|
366
|
+
scroll.addEventListener('wheel', handleWheel, {
|
|
367
|
+
passive: true
|
|
368
|
+
});
|
|
369
|
+
return function () {
|
|
370
|
+
scroll.removeEventListener('scroll', handleScroll);
|
|
371
|
+
scroll.removeEventListener('wheel', handleWheel);
|
|
372
|
+
};
|
|
373
|
+
}, [handleScroll, handleWheel]);
|
|
374
|
+
|
|
375
|
+
// Attach ResizeObserver to content element
|
|
376
|
+
useEffect(function () {
|
|
377
|
+
var content = contentRef.current;
|
|
378
|
+
if (!content) {
|
|
379
|
+
return undefined;
|
|
380
|
+
}
|
|
381
|
+
var previousHeight;
|
|
382
|
+
var resizeObserver = new ResizeObserver(function (_ref4) {
|
|
383
|
+
var _previousHeight;
|
|
384
|
+
var _ref5 = (0, _slicedToArray2.default)(_ref4, 1),
|
|
385
|
+
entry = _ref5[0];
|
|
386
|
+
var height = entry.contentRect.height;
|
|
387
|
+
var difference = height - ((_previousHeight = previousHeight) !== null && _previousHeight !== void 0 ? _previousHeight : height);
|
|
388
|
+
state.resizeDifference = difference;
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* Sometimes the browser can overscroll past the target,
|
|
392
|
+
* so check for this and adjust appropriately.
|
|
393
|
+
*/
|
|
394
|
+
if (state.scrollTop > state.targetScrollTop) {
|
|
395
|
+
state.scrollTop = state.targetScrollTop;
|
|
396
|
+
}
|
|
397
|
+
setIsNearBottom(state.isNearBottom);
|
|
398
|
+
if (difference >= 0) {
|
|
399
|
+
/**
|
|
400
|
+
* If it's a positive resize, scroll to the bottom when
|
|
401
|
+
* we're already at the bottom.
|
|
402
|
+
*/
|
|
403
|
+
var animation = mergeAnimations(optionsRef.current, previousHeight ? optionsRef.current.resize : optionsRef.current.initial);
|
|
404
|
+
scrollToBottom({
|
|
405
|
+
animation: animation,
|
|
406
|
+
wait: true,
|
|
407
|
+
preserveScrollPosition: true,
|
|
408
|
+
duration: animation === 'instant' ? undefined : RETAIN_ANIMATION_DURATION_MS
|
|
409
|
+
});
|
|
410
|
+
} else if (state.isNearBottom) {
|
|
411
|
+
/**
|
|
412
|
+
* Else if it's a negative resize, check if we're near the bottom
|
|
413
|
+
* if we are want to un-escape from the lock, because the resize
|
|
414
|
+
* could have caused the container to be at the bottom.
|
|
415
|
+
*/
|
|
416
|
+
setEscapedFromLock(false);
|
|
417
|
+
setIsAtBottom(true);
|
|
418
|
+
}
|
|
419
|
+
previousHeight = height;
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Reset the resize difference after the scroll event
|
|
423
|
+
* has fired. Requires a rAF to wait for the scroll event,
|
|
424
|
+
* and a setTimeout to wait for the other timeout we have in
|
|
425
|
+
* resizeObserver in case the scroll event happens after the
|
|
426
|
+
* resize event.
|
|
427
|
+
*/
|
|
428
|
+
requestAnimationFrame(function () {
|
|
429
|
+
setTimeout(function () {
|
|
430
|
+
if (state.resizeDifference === difference) {
|
|
431
|
+
state.resizeDifference = 0;
|
|
432
|
+
}
|
|
433
|
+
}, 1);
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
resizeObserver.observe(content);
|
|
437
|
+
state.resizeObserver = resizeObserver;
|
|
438
|
+
return function () {
|
|
439
|
+
resizeObserver.disconnect();
|
|
440
|
+
state.resizeObserver = undefined;
|
|
441
|
+
};
|
|
442
|
+
}, [state, setIsNearBottom, setEscapedFromLock, setIsAtBottom, scrollToBottom]);
|
|
443
|
+
return {
|
|
444
|
+
contentRef: contentRef,
|
|
445
|
+
scrollRef: scrollRef,
|
|
446
|
+
scrollToBottom: scrollToBottom,
|
|
447
|
+
stopScroll: stopScroll,
|
|
448
|
+
isAtBottom: isAtBottom || isNearBottom,
|
|
449
|
+
isNearBottom: isNearBottom,
|
|
450
|
+
escapedFromLock: escapedFromLock,
|
|
451
|
+
state: state
|
|
452
|
+
};
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
var animationCache = new Map();
|
|
456
|
+
function mergeAnimations() {
|
|
457
|
+
var result = _objectSpread({}, DEFAULT_SPRING_ANIMATION);
|
|
458
|
+
var instant = false;
|
|
459
|
+
for (var _len = arguments.length, animations = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
460
|
+
animations[_key] = arguments[_key];
|
|
461
|
+
}
|
|
462
|
+
animations.forEach(function (animation) {
|
|
463
|
+
var _animation$damping, _animation$stiffness, _animation$mass;
|
|
464
|
+
if (animation === 'instant') {
|
|
465
|
+
instant = true;
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if ((0, _typeof2.default)(animation) !== 'object') {
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
instant = false;
|
|
472
|
+
result.damping = (_animation$damping = animation.damping) !== null && _animation$damping !== void 0 ? _animation$damping : result.damping;
|
|
473
|
+
result.stiffness = (_animation$stiffness = animation.stiffness) !== null && _animation$stiffness !== void 0 ? _animation$stiffness : result.stiffness;
|
|
474
|
+
result.mass = (_animation$mass = animation.mass) !== null && _animation$mass !== void 0 ? _animation$mass : result.mass;
|
|
475
|
+
});
|
|
476
|
+
var key = JSON.stringify(result);
|
|
477
|
+
if (!animationCache.has(key)) {
|
|
478
|
+
animationCache.set(key, Object.freeze(result));
|
|
479
|
+
}
|
|
480
|
+
return instant ? 'instant' : animationCache.get(key);
|
|
481
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.find = find;
|
|
7
|
+
function find(array, predicate) {
|
|
8
|
+
for (var index = 0; index < array.length; index++) {
|
|
9
|
+
var item = array[index];
|
|
10
|
+
if (predicate(item, index, array)) {
|
|
11
|
+
return item;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _find = require("./find");
|
|
7
|
+
Object.keys(_find).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _find[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _find[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _startsWith = require("./startsWith");
|
|
18
|
+
Object.keys(_startsWith).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _startsWith[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function get() {
|
|
24
|
+
return _startsWith[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|