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