react-instantsearch-core 7.16.2 → 7.17.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.
@@ -0,0 +1,110 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _excluded = ["resume"];
3
+ 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; }
4
+ 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; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
12
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
13
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
15
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
16
+ import { DefaultChatTransport } from 'ai';
17
+ import { Chat } from "instantsearch.js/es/lib/chat/index.js";
18
+ import { useCallback, useEffect, useMemo, useRef, useSyncExternalStore } from 'react';
19
+ import { useAppIdAndApiKey } from "../lib/useAppIdAndApiKey.js";
20
+ import { warn } from "../lib/warn.js";
21
+ export function useChat() {
22
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
23
+ _ref$resume = _ref.resume,
24
+ resume = _ref$resume === void 0 ? false : _ref$resume,
25
+ options = _objectWithoutProperties(_ref, _excluded);
26
+ process.env.NODE_ENV === 'development' ? warn(false, 'Chat is not yet stable and will change in the future.') : void 0;
27
+ process.env.NODE_ENV === 'development' ? warn(!('agentId' in options && 'transport' in options), "`useChat` with `agentId` and `transport` can't be used together. The `transport` option will be used.") : void 0;
28
+ var _useAppIdAndApiKey = useAppIdAndApiKey(),
29
+ _useAppIdAndApiKey2 = _slicedToArray(_useAppIdAndApiKey, 2),
30
+ appId = _useAppIdAndApiKey2[0],
31
+ apiKey = _useAppIdAndApiKey2[1];
32
+ var transport = useMemo(function () {
33
+ if ('transport' in options && options.transport) {
34
+ return new DefaultChatTransport(options.transport);
35
+ }
36
+ if ('agentId' in options && options.agentId) {
37
+ var agentId = options.agentId;
38
+ if (!appId || !apiKey) {
39
+ throw new Error('The `useChat` hook requires an `appId` and `apiKey` to be set on the `InstantSearch` component when using the `agentId` option.');
40
+ }
41
+ return new DefaultChatTransport({
42
+ api: "https://".concat(appId, ".algolia.net/agent-studio/1/agents/").concat(agentId, "/completions?compatibilityMode=ai-sdk-5"),
43
+ headers: {
44
+ 'x-algolia-application-id': appId,
45
+ 'x-algolia-api-Key': apiKey
46
+ }
47
+ });
48
+ }
49
+ throw new Error('You need to provide either an `agentId` or a `transport`.');
50
+ }, [apiKey, appId, options]);
51
+ var optionsWithTransport = useMemo(function () {
52
+ if ('chat' in options) {
53
+ return options;
54
+ }
55
+ return _objectSpread(_objectSpread({}, options), {}, {
56
+ transport: transport
57
+ });
58
+ }, [options, transport]);
59
+ var chatRef = useRef('chat' in optionsWithTransport ? optionsWithTransport.chat : new Chat(optionsWithTransport));
60
+ var shouldRecreateChat = 'chat' in optionsWithTransport && optionsWithTransport.chat !== chatRef.current || 'id' in optionsWithTransport && chatRef.current.id !== optionsWithTransport.id;
61
+ if (shouldRecreateChat) {
62
+ chatRef.current = 'chat' in optionsWithTransport ? optionsWithTransport.chat : new Chat(optionsWithTransport);
63
+ }
64
+ var optionsId = 'id' in optionsWithTransport ? optionsWithTransport.id : null;
65
+ var subscribeToMessages = useCallback(function (update) {
66
+ return chatRef.current['~registerMessagesCallback'](update);
67
+ },
68
+ // optionsId is required to trigger re-subscription when the chat ID changes
69
+ // eslint-disable-next-line react-hooks/exhaustive-deps
70
+ [optionsId]);
71
+ var messages = useSyncExternalStore(subscribeToMessages, function () {
72
+ return chatRef.current.messages;
73
+ }, function () {
74
+ return chatRef.current.messages;
75
+ });
76
+ var status = useSyncExternalStore(chatRef.current['~registerStatusCallback'], function () {
77
+ return chatRef.current.status;
78
+ }, function () {
79
+ return chatRef.current.status;
80
+ });
81
+ var error = useSyncExternalStore(chatRef.current['~registerErrorCallback'], function () {
82
+ return chatRef.current.error;
83
+ }, function () {
84
+ return chatRef.current.error;
85
+ });
86
+ var setMessages = useCallback(function (messagesParam) {
87
+ if (typeof messagesParam === 'function') {
88
+ messagesParam = messagesParam(chatRef.current.messages);
89
+ }
90
+ chatRef.current.messages = messagesParam;
91
+ }, [chatRef]);
92
+ useEffect(function () {
93
+ if (resume) {
94
+ chatRef.current.resumeStream();
95
+ }
96
+ }, [resume, chatRef]);
97
+ return {
98
+ id: chatRef.current.id,
99
+ messages: messages,
100
+ setMessages: setMessages,
101
+ sendMessage: chatRef.current.sendMessage,
102
+ regenerate: chatRef.current.regenerate,
103
+ clearError: chatRef.current.clearError,
104
+ stop: chatRef.current.stop,
105
+ error: error,
106
+ resumeStream: chatRef.current.resumeStream,
107
+ status: status,
108
+ addToolResult: chatRef.current.addToolResult
109
+ };
110
+ }
@@ -6,6 +6,7 @@ export * from './components/InstantSearch';
6
6
  export * from './components/InstantSearchServerContext';
7
7
  export * from './components/InstantSearchSSRProvider';
8
8
  export * from './connectors/useBreadcrumb';
9
+ export * from './connectors/useChat';
9
10
  export * from './connectors/useClearRefinements';
10
11
  export * from './connectors/useConfigure';
11
12
  export * from './connectors/useCurrentRefinements';
package/dist/es/index.js CHANGED
@@ -6,6 +6,7 @@ export * from "./components/InstantSearch.js";
6
6
  export * from "./components/InstantSearchServerContext.js";
7
7
  export * from "./components/InstantSearchSSRProvider.js";
8
8
  export * from "./connectors/useBreadcrumb.js";
9
+ export * from "./connectors/useChat.js";
9
10
  export * from "./connectors/useClearRefinements.js";
10
11
  export * from "./connectors/useConfigure.js";
11
12
  export * from "./connectors/useCurrentRefinements.js";
@@ -0,0 +1,41 @@
1
+ export { default as version } from './version';
2
+ export * from './components/Configure';
3
+ export * from './components/DynamicWidgets';
4
+ export * from './components/Index';
5
+ export * from './components/InstantSearch';
6
+ export * from './components/InstantSearchServerContext';
7
+ export * from './components/InstantSearchSSRProvider';
8
+ export * from './connectors/useBreadcrumb';
9
+ export declare const useChat: () => never;
10
+ export * from './connectors/useClearRefinements';
11
+ export * from './connectors/useConfigure';
12
+ export * from './connectors/useCurrentRefinements';
13
+ export * from './connectors/useDynamicWidgets';
14
+ export * from './connectors/useFrequentlyBoughtTogether';
15
+ export * from './connectors/useGeoSearch';
16
+ export * from './connectors/useHierarchicalMenu';
17
+ export * from './connectors/useHits';
18
+ export * from './connectors/useHitsPerPage';
19
+ export * from './connectors/useInfiniteHits';
20
+ export * from './connectors/useMenu';
21
+ export * from './connectors/useNumericMenu';
22
+ export * from './connectors/usePagination';
23
+ export * from './connectors/usePoweredBy';
24
+ export * from './connectors/useQueryRules';
25
+ export * from './connectors/useRange';
26
+ export * from './connectors/useRefinementList';
27
+ export * from './connectors/useRelatedProducts';
28
+ export * from './connectors/useSearchBox';
29
+ export * from './connectors/useSortBy';
30
+ export * from './connectors/useStats';
31
+ export * from './connectors/useToggleRefinement';
32
+ export * from './connectors/useTrendingItems';
33
+ export * from './connectors/useLookingSimilar';
34
+ export * from './hooks/useConnector';
35
+ export * from './hooks/useInstantSearch';
36
+ export * from './lib/wrapPromiseWithState';
37
+ export * from './lib/useInstantSearchContext';
38
+ export * from './lib/useRSCContext';
39
+ export * from './lib/InstantSearchRSCContext';
40
+ export * from './lib/InstantSearchSSRContext';
41
+ export * from './server';
@@ -0,0 +1,43 @@
1
+ export { default as version } from "./version.js";
2
+ export * from "./components/Configure.js";
3
+ export * from "./components/DynamicWidgets.js";
4
+ export * from "./components/Index.js";
5
+ export * from "./components/InstantSearch.js";
6
+ export * from "./components/InstantSearchServerContext.js";
7
+ export * from "./components/InstantSearchSSRProvider.js";
8
+ export * from "./connectors/useBreadcrumb.js";
9
+ export var useChat = function useChat() {
10
+ throw new Error("\"useChat()\" is not available from the UMD build.\n\nPlease use React InstantSearch with a packaging system:\nhttps://www.algolia.com/doc/guides/building-search-ui/installation/react/#install-react-instantsearch-as-an-npm-package");
11
+ };
12
+ export * from "./connectors/useClearRefinements.js";
13
+ export * from "./connectors/useConfigure.js";
14
+ export * from "./connectors/useCurrentRefinements.js";
15
+ export * from "./connectors/useDynamicWidgets.js";
16
+ export * from "./connectors/useFrequentlyBoughtTogether.js";
17
+ export * from "./connectors/useGeoSearch.js";
18
+ export * from "./connectors/useHierarchicalMenu.js";
19
+ export * from "./connectors/useHits.js";
20
+ export * from "./connectors/useHitsPerPage.js";
21
+ export * from "./connectors/useInfiniteHits.js";
22
+ export * from "./connectors/useMenu.js";
23
+ export * from "./connectors/useNumericMenu.js";
24
+ export * from "./connectors/usePagination.js";
25
+ export * from "./connectors/usePoweredBy.js";
26
+ export * from "./connectors/useQueryRules.js";
27
+ export * from "./connectors/useRange.js";
28
+ export * from "./connectors/useRefinementList.js";
29
+ export * from "./connectors/useRelatedProducts.js";
30
+ export * from "./connectors/useSearchBox.js";
31
+ export * from "./connectors/useSortBy.js";
32
+ export * from "./connectors/useStats.js";
33
+ export * from "./connectors/useToggleRefinement.js";
34
+ export * from "./connectors/useTrendingItems.js";
35
+ export * from "./connectors/useLookingSimilar.js";
36
+ export * from "./hooks/useConnector.js";
37
+ export * from "./hooks/useInstantSearch.js";
38
+ export * from "./lib/wrapPromiseWithState.js";
39
+ export * from "./lib/useInstantSearchContext.js";
40
+ export * from "./lib/useRSCContext.js";
41
+ export * from "./lib/InstantSearchRSCContext.js";
42
+ export * from "./lib/InstantSearchSSRContext.js";
43
+ export * from "./server/index.js";
@@ -0,0 +1 @@
1
+ export declare const useAppIdAndApiKey: () => [appId: string, apiKey: string] | [appId: undefined, apiKey: undefined];
@@ -0,0 +1,7 @@
1
+ import { getAppIdAndApiKey } from "instantsearch.js/es/lib/utils/index.js";
2
+ import { useInstantSearchContext } from "./useInstantSearchContext.js";
3
+ export var useAppIdAndApiKey = function useAppIdAndApiKey() {
4
+ var _useInstantSearchCont = useInstantSearchContext(),
5
+ client = _useInstantSearchCont.client;
6
+ return getAppIdAndApiKey(client);
7
+ };
@@ -1,2 +1,2 @@
1
- declare const _default: "7.16.2";
1
+ declare const _default: "7.17.0";
2
2
  export default _default;
@@ -1 +1 @@
1
- export default '7.16.2';
1
+ export default '7.17.0';
@@ -7,7 +7,7 @@
7
7
 
8
8
  var React__default = 'default' in React ? React['default'] : React;
9
9
 
10
- var version = '7.16.2';
10
+ var version = '7.17.0';
11
11
 
12
12
  function _iterableToArrayLimit(r, l) {
13
13
  var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
@@ -10067,12 +10067,18 @@
10067
10067
  }, []);
10068
10068
  }
10069
10069
  var index = function index(widgetParams) {
10070
- if (widgetParams === undefined || widgetParams.indexName === undefined) {
10070
+ if (widgetParams === undefined || widgetParams.indexName === undefined && !widgetParams.EXPERIMENTAL_isolated) {
10071
10071
  throw new Error(withUsage$2('The `indexName` option is required.'));
10072
10072
  }
10073
- var indexName = widgetParams.indexName,
10073
+
10074
+ // When isolated=true, we use an empty string as the default indexName.
10075
+ // This is intentional: isolated indices do not require a real index name.
10076
+ var _widgetParams$indexNa = widgetParams.indexName,
10077
+ indexName = _widgetParams$indexNa === void 0 ? '' : _widgetParams$indexNa,
10074
10078
  _widgetParams$indexId = widgetParams.indexId,
10075
- indexId = _widgetParams$indexId === void 0 ? indexName : _widgetParams$indexId;
10079
+ indexId = _widgetParams$indexId === void 0 ? indexName : _widgetParams$indexId,
10080
+ _widgetParams$EXPERIM = widgetParams.EXPERIMENTAL_isolated,
10081
+ isolated = _widgetParams$EXPERIM === void 0 ? false : _widgetParams$EXPERIM;
10076
10082
  var localWidgets = [];
10077
10083
  var localUiState = {};
10078
10084
  var localInstantSearchInstance = null;
@@ -10085,6 +10091,7 @@
10085
10091
  return {
10086
10092
  $$type: 'ais.index',
10087
10093
  $$widgetType: 'ais.index',
10094
+ _isolated: isolated,
10088
10095
  getIndexName: function getIndexName() {
10089
10096
  return indexName;
10090
10097
  },
@@ -10136,7 +10143,7 @@
10136
10143
  return resolveScopedResultsFromWidgets(widgetSiblings);
10137
10144
  },
10138
10145
  getParent: function getParent() {
10139
- return localParent;
10146
+ return isolated ? null : localParent;
10140
10147
  },
10141
10148
  createURL: function createURL(nextState) {
10142
10149
  if (typeof nextState === 'function') {
@@ -10155,12 +10162,15 @@
10155
10162
  if (!Array.isArray(widgets)) {
10156
10163
  throw new Error(withUsage$2('The `addWidgets` method expects an array of widgets.'));
10157
10164
  }
10158
- if (widgets.some(function (widget) {
10165
+ var flatWidgets = widgets.reduce(function (acc, w) {
10166
+ return acc.concat(Array.isArray(w) ? w : [w]);
10167
+ }, []);
10168
+ if (flatWidgets.some(function (widget) {
10159
10169
  return typeof widget.init !== 'function' && typeof widget.render !== 'function';
10160
10170
  })) {
10161
10171
  throw new Error(withUsage$2('The widget definition expects a `render` and/or an `init` method.'));
10162
10172
  }
10163
- widgets.forEach(function (widget) {
10173
+ flatWidgets.forEach(function (widget) {
10164
10174
  if (isIndexWidget(widget)) {
10165
10175
  return;
10166
10176
  }
@@ -10175,8 +10185,8 @@
10175
10185
  }
10176
10186
  addWidgetId(widget);
10177
10187
  });
10178
- localWidgets = localWidgets.concat(widgets);
10179
- if (localInstantSearchInstance && Boolean(widgets.length)) {
10188
+ localWidgets = localWidgets.concat(flatWidgets);
10189
+ if (localInstantSearchInstance && Boolean(flatWidgets.length)) {
10180
10190
  privateHelperSetState(helper, {
10181
10191
  state: getLocalWidgetsSearchParameters(localWidgets, {
10182
10192
  uiState: localUiState,
@@ -10192,7 +10202,7 @@
10192
10202
  // We compute the render state before calling `init` in a separate loop
10193
10203
  // to construct the whole render state object that is then passed to
10194
10204
  // `init`.
10195
- widgets.forEach(function (widget) {
10205
+ flatWidgets.forEach(function (widget) {
10196
10206
  if (widget.getRenderState) {
10197
10207
  var renderState = widget.getRenderState(localInstantSearchInstance.renderState[_this.getIndexId()] || {}, createInitArgs(localInstantSearchInstance, _this, localInstantSearchInstance._initialUiState));
10198
10208
  storeRenderState({
@@ -10202,12 +10212,17 @@
10202
10212
  });
10203
10213
  }
10204
10214
  });
10205
- widgets.forEach(function (widget) {
10215
+ flatWidgets.forEach(function (widget) {
10206
10216
  if (widget.init) {
10207
10217
  widget.init(createInitArgs(localInstantSearchInstance, _this, localInstantSearchInstance._initialUiState));
10208
10218
  }
10209
10219
  });
10210
- localInstantSearchInstance.scheduleSearch();
10220
+ if (isolated) {
10221
+ var _helper2;
10222
+ (_helper2 = helper) === null || _helper2 === void 0 ? void 0 : _helper2.search();
10223
+ } else {
10224
+ localInstantSearchInstance.scheduleSearch();
10225
+ }
10211
10226
  }
10212
10227
  return this;
10213
10228
  },
@@ -10216,13 +10231,16 @@
10216
10231
  if (!Array.isArray(widgets)) {
10217
10232
  throw new Error(withUsage$2('The `removeWidgets` method expects an array of widgets.'));
10218
10233
  }
10219
- if (widgets.some(function (widget) {
10234
+ var flatWidgets = widgets.reduce(function (acc, w) {
10235
+ return acc.concat(Array.isArray(w) ? w : [w]);
10236
+ }, []);
10237
+ if (flatWidgets.some(function (widget) {
10220
10238
  return typeof widget.dispose !== 'function';
10221
10239
  })) {
10222
10240
  throw new Error(withUsage$2('The widget definition expects a `dispose` method.'));
10223
10241
  }
10224
10242
  localWidgets = localWidgets.filter(function (widget) {
10225
- return widgets.indexOf(widget) === -1;
10243
+ return flatWidgets.indexOf(widget) === -1;
10226
10244
  });
10227
10245
  localWidgets.forEach(function (widget) {
10228
10246
  if (isIndexWidget(widget)) {
@@ -10238,8 +10256,8 @@
10238
10256
  hasSearchWidget = true;
10239
10257
  }
10240
10258
  });
10241
- if (localInstantSearchInstance && Boolean(widgets.length)) {
10242
- var _widgets$reduce = widgets.reduce(function (states, widget) {
10259
+ if (localInstantSearchInstance && Boolean(flatWidgets.length)) {
10260
+ var _flatWidgets$reduce = flatWidgets.reduce(function (states, widget) {
10243
10261
  // the `dispose` method exists at this point we already assert it
10244
10262
  var next = widget.dispose({
10245
10263
  helper: helper,
@@ -10257,8 +10275,8 @@
10257
10275
  cleanedSearchState: helper.state,
10258
10276
  cleanedRecommendState: helper.recommendState
10259
10277
  }),
10260
- cleanedSearchState = _widgets$reduce.cleanedSearchState,
10261
- cleanedRecommendState = _widgets$reduce.cleanedRecommendState;
10278
+ cleanedSearchState = _flatWidgets$reduce.cleanedSearchState,
10279
+ cleanedRecommendState = _flatWidgets$reduce.cleanedRecommendState;
10262
10280
  var newState = localInstantSearchInstance.future.preserveSharedStateOnUnmount ? getLocalWidgetsSearchParameters(localWidgets, {
10263
10281
  uiState: localUiState,
10264
10282
  initialSearchParameters: new algoliasearchHelper_1.SearchParameters({
@@ -10278,7 +10296,12 @@
10278
10296
  helper.setState(newState);
10279
10297
  helper.recommendState = cleanedRecommendState;
10280
10298
  if (localWidgets.length) {
10281
- localInstantSearchInstance.scheduleSearch();
10299
+ if (isolated) {
10300
+ var _helper3;
10301
+ (_helper3 = helper) === null || _helper3 === void 0 ? void 0 : _helper3.search();
10302
+ } else {
10303
+ localInstantSearchInstance.scheduleSearch();
10304
+ }
10282
10305
  }
10283
10306
  }
10284
10307
  return this;
@@ -10316,13 +10339,20 @@
10316
10339
  // This Helper is only used for state management we do not care about the
10317
10340
  // `searchClient`. Only the "main" Helper created at the `InstantSearch`
10318
10341
  // level is aware of the client.
10319
- helper = algoliasearchHelper_1({}, parameters.index, parameters);
10342
+ helper = algoliasearchHelper_1(mainHelper.getClient(), parameters.index, parameters);
10320
10343
  helper.recommendState = recommendParameters;
10321
10344
 
10322
10345
  // We forward the call to `search` to the "main" instance of the Helper
10323
10346
  // which is responsible for managing the queries (it's the only one that is
10324
10347
  // aware of the `searchClient`).
10325
10348
  helper.search = function () {
10349
+ if (isolated) {
10350
+ instantSearchInstance.status = 'loading';
10351
+ _this3.render({
10352
+ instantSearchInstance: instantSearchInstance
10353
+ });
10354
+ return instantSearchInstance.compositionID ? helper.searchWithComposition() : helper.searchOnlyWithDerivedHelpers();
10355
+ }
10326
10356
  if (instantSearchInstance.onStateChange) {
10327
10357
  instantSearchInstance.onStateChange({
10328
10358
  uiState: instantSearchInstance.mainIndex.getWidgetUiState({}),
@@ -10346,7 +10376,9 @@
10346
10376
  var state = helper.state.setQueryParameters(userState);
10347
10377
  return mainHelper.searchForFacetValues(facetName, facetValue, maxFacetHits, state);
10348
10378
  };
10349
- derivedHelper = mainHelper.derive(function () {
10379
+ var isolatedHelper = indexName ? helper : algoliasearchHelper_1({}, '__empty_index__', {});
10380
+ var derivingHelper = isolated ? isolatedHelper : nearestIsolatedHelper(parent, mainHelper);
10381
+ derivedHelper = derivingHelper.derive(function () {
10350
10382
  return mergeSearchParameters.apply(void 0, [mainHelper.state].concat(_toConsumableArray$1(resolveSearchParameters(_this3))));
10351
10383
  }, function () {
10352
10384
  return _this3.getHelper().recommendState;
@@ -10478,7 +10510,11 @@
10478
10510
 
10479
10511
  // We only render index widgets if there are no results.
10480
10512
  // This makes sure `render` is never called with `results` being `null`.
10481
- var widgetsToRender = this.getResults() || (_derivedHelper2 = derivedHelper) !== null && _derivedHelper2 !== void 0 && _derivedHelper2.lastRecommendResults ? localWidgets : localWidgets.filter(isIndexWidget);
10513
+ // If it's an isolated index without an index name, we render all widgets,
10514
+ // as there are no results to display for the isolated index itself.
10515
+ var widgetsToRender = this.getResults() || (_derivedHelper2 = derivedHelper) !== null && _derivedHelper2 !== void 0 && _derivedHelper2.lastRecommendResults || isolated && !indexName ? localWidgets : localWidgets.filter(function (widget) {
10516
+ return widget.shouldRender;
10517
+ });
10482
10518
  widgetsToRender = widgetsToRender.filter(function (widget) {
10483
10519
  if (!widget.shouldRender) {
10484
10520
  return true;
@@ -10512,7 +10548,7 @@
10512
10548
  },
10513
10549
  dispose: function dispose() {
10514
10550
  var _this5 = this,
10515
- _helper2,
10551
+ _helper4,
10516
10552
  _derivedHelper3;
10517
10553
  localWidgets.forEach(function (widget) {
10518
10554
  if (widget.dispose && helper) {
@@ -10532,13 +10568,15 @@
10532
10568
  });
10533
10569
  localInstantSearchInstance = null;
10534
10570
  localParent = null;
10535
- (_helper2 = helper) === null || _helper2 === void 0 ? void 0 : _helper2.removeAllListeners();
10571
+ (_helper4 = helper) === null || _helper4 === void 0 ? void 0 : _helper4.removeAllListeners();
10536
10572
  helper = null;
10537
10573
  (_derivedHelper3 = derivedHelper) === null || _derivedHelper3 === void 0 ? void 0 : _derivedHelper3.detach();
10538
10574
  derivedHelper = null;
10539
10575
  },
10540
10576
  getWidgetUiState: function getWidgetUiState(uiState) {
10541
- return localWidgets.filter(isIndexWidget).reduce(function (previousUiState, innerIndex) {
10577
+ return localWidgets.filter(isIndexWidget).filter(function (w) {
10578
+ return !w._isolated;
10579
+ }).reduce(function (previousUiState, innerIndex) {
10542
10580
  return innerIndex.getWidgetUiState(previousUiState);
10543
10581
  }, _objectSpread$b(_objectSpread$b({}, uiState), {}, _defineProperty$c({}, indexId, _objectSpread$b(_objectSpread$b({}, uiState[indexId]), localUiState))));
10544
10582
  },
@@ -10552,6 +10590,9 @@
10552
10590
  initialSearchParameters: searchParameters
10553
10591
  });
10554
10592
  },
10593
+ shouldRender: function shouldRender() {
10594
+ return true;
10595
+ },
10555
10596
  refreshUiState: function refreshUiState() {
10556
10597
  localUiState = getLocalWidgetsUiState(localWidgets, {
10557
10598
  searchParameters: this.getHelper().state,
@@ -10574,6 +10615,19 @@
10574
10615
  instantSearchInstance.renderState = _objectSpread$b(_objectSpread$b({}, instantSearchInstance.renderState), {}, _defineProperty$c({}, parentIndexName, _objectSpread$b(_objectSpread$b({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
10575
10616
  }
10576
10617
 
10618
+ /**
10619
+ * Walk up the parent chain to find the closest isolated index, or fall back to mainHelper
10620
+ */
10621
+ function nearestIsolatedHelper(current, mainHelper) {
10622
+ while (current) {
10623
+ if (current._isolated) {
10624
+ return current.getHelper();
10625
+ }
10626
+ current = current.getParent();
10627
+ }
10628
+ return mainHelper;
10629
+ }
10630
+
10577
10631
  /**
10578
10632
  * Forces a React update that triggers a rerender.
10579
10633
  * @link https://reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate
@@ -12912,7 +12966,7 @@
12912
12966
  };
12913
12967
  }
12914
12968
 
12915
- var version$2 = '4.79.2';
12969
+ var version$2 = '4.81.0';
12916
12970
 
12917
12971
  function _typeof$l(o) {
12918
12972
  "@babel/helpers - typeof";
@@ -13346,12 +13400,9 @@
13346
13400
  if (!Array.isArray(widgets)) {
13347
13401
  throw new Error(withUsage$3('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
13348
13402
  }
13349
- if (widgets.some(function (widget) {
13350
- return typeof widget.init !== 'function' && typeof widget.render !== 'function';
13403
+ if (this.compositionID && widgets.some(function (w) {
13404
+ return !Array.isArray(w) && isIndexWidget(w) && !w._isolated;
13351
13405
  })) {
13352
- throw new Error(withUsage$3('The widget definition expects a `render` and/or an `init` method.'));
13353
- }
13354
- if (this.compositionID && widgets.some(isIndexWidget)) {
13355
13406
  throw new Error(withUsage$3('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
13356
13407
  }
13357
13408
  this.mainIndex.addWidgets(widgets);
@@ -13383,11 +13434,6 @@
13383
13434
  if (!Array.isArray(widgets)) {
13384
13435
  throw new Error(withUsage$3('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
13385
13436
  }
13386
- if (widgets.some(function (widget) {
13387
- return typeof widget.dispose !== 'function';
13388
- })) {
13389
- throw new Error(withUsage$3('The widget definition expects a `dispose` method.'));
13390
- }
13391
13437
  this.mainIndex.removeWidgets(widgets);
13392
13438
  return this;
13393
13439
  }
@@ -20067,6 +20113,10 @@
20067
20113
  });
20068
20114
  }
20069
20115
 
20116
+ var useChat = function useChat() {
20117
+ throw new Error("\"useChat()\" is not available from the UMD build.\n\nPlease use React InstantSearch with a packaging system:\nhttps://www.algolia.com/doc/guides/building-search-ui/installation/react/#install-react-instantsearch-as-an-npm-package");
20118
+ };
20119
+
20070
20120
  exports.Configure = Configure;
20071
20121
  exports.DynamicWidgets = DynamicWidgets;
20072
20122
  exports.Index = Index;
@@ -20077,6 +20127,7 @@
20077
20127
  exports.InstantSearchServerContext = InstantSearchServerContext;
20078
20128
  exports.getServerState = getServerState;
20079
20129
  exports.useBreadcrumb = useBreadcrumb;
20130
+ exports.useChat = useChat;
20080
20131
  exports.useClearRefinements = useClearRefinements;
20081
20132
  exports.useConfigure = useConfigure;
20082
20133
  exports.useConnector = useConnector;