react-instantsearch-core 7.33.1 → 7.34.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,18 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "useChatTrigger", {
7
+ enumerable: true,
8
+ get: function() {
9
+ return useChatTrigger;
10
+ }
11
+ });
12
+ var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
13
+ var _connectChatTrigger = /*#__PURE__*/ _interop_require_default._(require("instantsearch.js/cjs/connectors/chat/connectChatTrigger"));
14
+ var _useConnector = require("../hooks/useConnector");
15
+ function useChatTrigger() {
16
+ var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, additionalWidgetProperties = arguments.length > 1 ? arguments[1] : void 0;
17
+ return (0, _useConnector.useConnector)(_connectChatTrigger.default, props, additionalWidgetProperties);
18
+ }
package/dist/cjs/index.js CHANGED
@@ -22,6 +22,7 @@ _export_star._(require("./components/InstantSearchSSRProvider"), exports);
22
22
  _export_star._(require("./connectors/useAutocomplete"), exports);
23
23
  _export_star._(require("./connectors/useBreadcrumb"), exports);
24
24
  _export_star._(require("./connectors/useChat"), exports);
25
+ _export_star._(require("./connectors/useChatTrigger"), exports);
25
26
  _export_star._(require("./connectors/useClearRefinements"), exports);
26
27
  _export_star._(require("./connectors/useConfigure"), exports);
27
28
  _export_star._(require("./connectors/useCurrentRefinements"), exports);
@@ -9,4 +9,4 @@ Object.defineProperty(exports, "default", {
9
9
  return _default;
10
10
  }
11
11
  });
12
- var _default = '7.33.1';
12
+ var _default = '7.34.0';
@@ -0,0 +1,4 @@
1
+ import type { AdditionalWidgetProperties } from '../hooks/useConnector';
2
+ import type { ChatTriggerConnectorParams } from 'instantsearch.js/es/connectors/chat/connectChatTrigger';
3
+ export type UseChatTriggerProps = ChatTriggerConnectorParams;
4
+ export declare function useChatTrigger(props?: UseChatTriggerProps, additionalWidgetProperties?: AdditionalWidgetProperties): import("instantsearch.js/es/connectors/chat/connectChatTrigger").ChatTriggerRenderState;
@@ -0,0 +1,9 @@
1
+ import connectChatTrigger from 'instantsearch.js/es/connectors/chat/connectChatTrigger.js';
2
+ import { useConnector } from '../hooks/useConnector.js';
3
+
4
+ function useChatTrigger() {
5
+ var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, additionalWidgetProperties = arguments.length > 1 ? arguments[1] : void 0;
6
+ return useConnector(connectChatTrigger, props, additionalWidgetProperties);
7
+ }
8
+
9
+ export { useChatTrigger };
@@ -1,5 +1,6 @@
1
1
  import type { Connector, Widget, WidgetDescription } from 'instantsearch.js';
2
2
  export type AdditionalWidgetProperties = Partial<Widget<WidgetDescription>> & {
3
3
  skipSuspense?: boolean;
4
+ opensChat?: boolean;
4
5
  };
5
6
  export declare function useConnector<TProps extends Record<string, unknown>, TDescription extends WidgetDescription>(connector: Connector<TDescription, TProps>, props?: TProps, { skipSuspense, ...additionalWidgetProperties }?: AdditionalWidgetProperties): TDescription['renderState'];
@@ -9,6 +9,7 @@ export * from './components/InstantSearchSSRProvider';
9
9
  export * from './connectors/useAutocomplete';
10
10
  export * from './connectors/useBreadcrumb';
11
11
  export * from './connectors/useChat';
12
+ export * from './connectors/useChatTrigger';
12
13
  export * from './connectors/useClearRefinements';
13
14
  export * from './connectors/useConfigure';
14
15
  export * from './connectors/useCurrentRefinements';
package/dist/es/index.js CHANGED
@@ -9,6 +9,7 @@ export { InstantSearchSSRProvider } from './components/InstantSearchSSRProvider.
9
9
  export { useAutocomplete } from './connectors/useAutocomplete.js';
10
10
  export { useBreadcrumb } from './connectors/useBreadcrumb.js';
11
11
  export { useChat } from './connectors/useChat.js';
12
+ export { useChatTrigger } from './connectors/useChatTrigger.js';
12
13
  export { useClearRefinements } from './connectors/useClearRefinements.js';
13
14
  export { useConfigure } from './connectors/useConfigure.js';
14
15
  export { useCurrentRefinements } from './connectors/useCurrentRefinements.js';
@@ -1,2 +1,2 @@
1
- declare const _default: "7.33.1";
1
+ declare const _default: "7.34.0";
2
2
  export default _default;
@@ -1,3 +1,3 @@
1
- var version = '7.33.1';
1
+ var version = '7.34.0';
2
2
 
3
3
  export { version as default };
@@ -1,4 +1,4 @@
1
- /*! React InstantSearch Core 7.33.1 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
1
+ /*! React InstantSearch Core 7.34.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
4
4
  typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
@@ -24,7 +24,7 @@
24
24
 
25
25
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
26
26
 
27
- var version$2 = '7.33.1';
27
+ var version$2 = '7.34.0';
28
28
 
29
29
  function _define_property(obj, key, value) {
30
30
  if (key in obj) {
@@ -5980,7 +5980,7 @@
5980
5980
  }
5981
5981
  }
5982
5982
 
5983
- var withUsage$u = createDocumentationMessageGenerator({
5983
+ var withUsage$v = createDocumentationMessageGenerator({
5984
5984
  name: 'configure',
5985
5985
  connector: true
5986
5986
  });
@@ -5996,7 +5996,7 @@
5996
5996
  var renderFn = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : noop, unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
5997
5997
  return function(widgetParams) {
5998
5998
  if (!widgetParams || !isPlainObject(widgetParams.searchParameters)) {
5999
- throw new Error(withUsage$u('The `searchParameters` option expects an object.'));
5999
+ throw new Error(withUsage$v('The `searchParameters` option expects an object.'));
6000
6000
  }
6001
6001
  var connectorState = {};
6002
6002
  function refine(helper) {
@@ -7651,13 +7651,13 @@
7651
7651
  return null;
7652
7652
  }
7653
7653
 
7654
- var withUsage$t = createDocumentationMessageGenerator({
7654
+ var withUsage$u = createDocumentationMessageGenerator({
7655
7655
  name: 'dynamic-widgets',
7656
7656
  connector: true
7657
7657
  });
7658
7658
  var connectDynamicWidgets = function connectDynamicWidgets(renderFn) {
7659
7659
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
7660
- checkRendering(renderFn, withUsage$t());
7660
+ checkRendering(renderFn, withUsage$u());
7661
7661
  return function(widgetParams) {
7662
7662
  var widgets = widgetParams.widgets, _widgetParams_maxValuesPerFacet = widgetParams.maxValuesPerFacet, maxValuesPerFacet = _widgetParams_maxValuesPerFacet === void 0 ? 20 : _widgetParams_maxValuesPerFacet, _widgetParams_facets = widgetParams.facets, facets = _widgetParams_facets === void 0 ? [
7663
7663
  '*'
@@ -7667,10 +7667,10 @@
7667
7667
  if (!(widgets && Array.isArray(widgets) && widgets.every(function(widget) {
7668
7668
  return (typeof widget === "undefined" ? "undefined" : _type_of(widget)) === 'object';
7669
7669
  }))) {
7670
- throw new Error(withUsage$t('The `widgets` option expects an array of widgets.'));
7670
+ throw new Error(withUsage$u('The `widgets` option expects an array of widgets.'));
7671
7671
  }
7672
7672
  if (!Array.isArray(facets)) {
7673
- throw new Error(withUsage$t("The `facets` option only accepts an array of facets, you passed ".concat(JSON.stringify(facets))));
7673
+ throw new Error(withUsage$u("The `facets` option only accepts an array of facets, you passed ".concat(JSON.stringify(facets))));
7674
7674
  }
7675
7675
  var localWidgets = new Map();
7676
7676
  return {
@@ -7772,7 +7772,7 @@
7772
7772
  results: results
7773
7773
  });
7774
7774
  if (!Array.isArray(attributesToRender)) {
7775
- throw new Error(withUsage$t('The `transformItems` option expects a function that returns an Array.'));
7775
+ throw new Error(withUsage$u('The `transformItems` option expects a function that returns an Array.'));
7776
7776
  }
7777
7777
  return {
7778
7778
  attributesToRender: attributesToRender,
@@ -8094,19 +8094,19 @@
8094
8094
  return toFeedSearchResults(lastResults._state, raw);
8095
8095
  });
8096
8096
  }
8097
- var withUsage$s = createDocumentationMessageGenerator({
8097
+ var withUsage$t = createDocumentationMessageGenerator({
8098
8098
  name: 'feeds',
8099
8099
  connector: true
8100
8100
  });
8101
8101
  var connectFeeds = function connectFeeds(renderFn) {
8102
8102
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
8103
- checkRendering(renderFn, withUsage$s());
8103
+ checkRendering(renderFn, withUsage$t());
8104
8104
  return function(widgetParams) {
8105
8105
  var isolated = widgetParams.isolated, _widgetParams_transformFeeds = widgetParams.transformFeeds, transformFeeds = _widgetParams_transformFeeds === void 0 ? function(feeds) {
8106
8106
  return feeds;
8107
8107
  } : _widgetParams_transformFeeds;
8108
8108
  if (isolated !== false) {
8109
- throw new Error(withUsage$s('The `isolated` option currently only supports `false`.'));
8109
+ throw new Error(withUsage$t('The `isolated` option currently only supports `false`.'));
8110
8110
  }
8111
8111
  return {
8112
8112
  $$type: 'ais.feeds',
@@ -8114,7 +8114,7 @@
8114
8114
  init: function init(initOptions) {
8115
8115
  var instantSearchInstance = initOptions.instantSearchInstance;
8116
8116
  if (!instantSearchInstance.compositionID) {
8117
- throw new Error(withUsage$s('The `feeds` widget requires a composition-based InstantSearch instance (compositionID must be set).'));
8117
+ throw new Error(withUsage$t('The `feeds` widget requires a composition-based InstantSearch instance (compositionID must be set).'));
8118
8118
  }
8119
8119
  hydrateFeedsFromInitialResultsIfNeeded(instantSearchInstance, initOptions.parent);
8120
8120
  renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
@@ -8160,12 +8160,12 @@
8160
8160
  ];
8161
8161
  feedIDs = transformFeeds(feedIDs);
8162
8162
  if (!Array.isArray(feedIDs)) {
8163
- throw new Error(withUsage$s('The `transformFeeds` option expects a function that returns an Array.'));
8163
+ throw new Error(withUsage$t('The `transformFeeds` option expects a function that returns an Array.'));
8164
8164
  }
8165
8165
  if (!feedIDs.every(function(feedID) {
8166
8166
  return typeof feedID === 'string';
8167
8167
  })) {
8168
- throw new Error(withUsage$s('The `transformFeeds` option expects a function that returns an array of feed IDs (strings).'));
8168
+ throw new Error(withUsage$t('The `transformFeeds` option expects a function that returns an array of feed IDs (strings).'));
8169
8169
  }
8170
8170
  return {
8171
8171
  feedIDs: feedIDs,
@@ -8276,7 +8276,7 @@
8276
8276
  }));
8277
8277
  }
8278
8278
 
8279
- var withUsage$r = createDocumentationMessageGenerator({
8279
+ var withUsage$s = createDocumentationMessageGenerator({
8280
8280
  name: 'index-widget'
8281
8281
  });
8282
8282
  /**
@@ -8370,7 +8370,7 @@
8370
8370
  }
8371
8371
  var index = function index(widgetParams) {
8372
8372
  if (widgetParams === undefined || widgetParams.indexName === undefined && !widgetParams.EXPERIMENTAL_isolated) {
8373
- throw new Error(withUsage$r('The `indexName` option is required.'));
8373
+ throw new Error(withUsage$s('The `indexName` option is required.'));
8374
8374
  }
8375
8375
  // When isolated=true, we use an empty string as the default indexName.
8376
8376
  // This is intentional: isolated indices do not require a real index name.
@@ -8460,7 +8460,7 @@
8460
8460
  addWidgets: function addWidgets(widgets) {
8461
8461
  var _this = this;
8462
8462
  if (!Array.isArray(widgets)) {
8463
- throw new Error(withUsage$r('The `addWidgets` method expects an array of widgets.'));
8463
+ throw new Error(withUsage$s('The `addWidgets` method expects an array of widgets.'));
8464
8464
  }
8465
8465
  var flatWidgets = widgets.reduce(function(acc, w) {
8466
8466
  return acc.concat(Array.isArray(w) ? w : [
@@ -8470,7 +8470,7 @@
8470
8470
  if (flatWidgets.some(function(widget) {
8471
8471
  return typeof widget.init !== 'function' && typeof widget.render !== 'function';
8472
8472
  })) {
8473
- throw new Error(withUsage$r('The widget definition expects a `render` and/or an `init` method.'));
8473
+ throw new Error(withUsage$s('The widget definition expects a `render` and/or an `init` method.'));
8474
8474
  }
8475
8475
  flatWidgets.forEach(function(widget) {
8476
8476
  widget.parent = _this;
@@ -8530,7 +8530,7 @@
8530
8530
  removeWidgets: function removeWidgets(widgets) {
8531
8531
  var _this = this;
8532
8532
  if (!Array.isArray(widgets)) {
8533
- throw new Error(withUsage$r('The `removeWidgets` method expects an array of widgets.'));
8533
+ throw new Error(withUsage$s('The `removeWidgets` method expects an array of widgets.'));
8534
8534
  }
8535
8535
  var flatWidgets = widgets.reduce(function(acc, w) {
8536
8536
  return acc.concat(Array.isArray(w) ? w : [
@@ -8540,7 +8540,7 @@
8540
8540
  if (flatWidgets.some(function(widget) {
8541
8541
  return typeof widget.dispose !== 'function';
8542
8542
  })) {
8543
- throw new Error(withUsage$r('The widget definition expects a `dispose` method.'));
8543
+ throw new Error(withUsage$s('The widget definition expects a `dispose` method.'));
8544
8544
  }
8545
8545
  localWidgets = localWidgets.filter(function(widget) {
8546
8546
  return flatWidgets.indexOf(widget) === -1;
@@ -10853,9 +10853,9 @@
10853
10853
  };
10854
10854
  }
10855
10855
 
10856
- var version = '4.99.0';
10856
+ var version = '4.100.0';
10857
10857
 
10858
- var withUsage$q = createDocumentationMessageGenerator({
10858
+ var withUsage$r = createDocumentationMessageGenerator({
10859
10859
  name: 'instantsearch'
10860
10860
  });
10861
10861
  function defaultCreateURL() {
@@ -10911,7 +10911,7 @@
10911
10911
  _this.setMaxListeners(100);
10912
10912
  var _options_indexName = options.indexName, indexName = _options_indexName === void 0 ? '' : _options_indexName, compositionID = options.compositionID, numberLocale = options.numberLocale, _options_initialUiState = options.initialUiState, initialUiState = _options_initialUiState === void 0 ? {} : _options_initialUiState, _options_routing = options.routing, routing = _options_routing === void 0 ? null : _options_routing, _options_insights = options.insights, insights = _options_insights === void 0 ? undefined : _options_insights, searchFunction = options.searchFunction, _options_stalledSearchDelay = options.stalledSearchDelay, stalledSearchDelay = _options_stalledSearchDelay === void 0 ? 200 : _options_stalledSearchDelay, _options_searchClient = options.searchClient, searchClient = _options_searchClient === void 0 ? null : _options_searchClient, _options_insightsClient = options.insightsClient, insightsClient = _options_insightsClient === void 0 ? null : _options_insightsClient, _options_onStateChange = options.onStateChange, onStateChange = _options_onStateChange === void 0 ? null : _options_onStateChange, _options_future1 = options.future, future = _options_future1 === void 0 ? _object_spread({}, INSTANTSEARCH_FUTURE_DEFAULTS, options.future || {}) : _options_future1;
10913
10913
  if (searchClient === null) {
10914
- throw new Error(withUsage$q('The `searchClient` option is required.'));
10914
+ throw new Error(withUsage$r('The `searchClient` option is required.'));
10915
10915
  }
10916
10916
  if (typeof searchClient.search !== 'function') {
10917
10917
  throw new Error("The `searchClient` must implement a `search` method.\n\nSee: https://www.algolia.com/doc/guides/building-search-ui/going-further/backend-search/in-depth/backend-instantsearch/js/");
@@ -10920,7 +10920,7 @@
10920
10920
  searchClient.addAlgoliaAgent("instantsearch.js (".concat(version, ")"));
10921
10921
  }
10922
10922
  if (insightsClient && typeof insightsClient !== 'function') {
10923
- throw new Error(withUsage$q('The `insightsClient` option should be a function.'));
10923
+ throw new Error(withUsage$r('The `insightsClient` option should be a function.'));
10924
10924
  }
10925
10925
  _this.client = searchClient;
10926
10926
  _this.future = future;
@@ -11068,12 +11068,12 @@
11068
11068
  * @param widgets The array of widgets to add to InstantSearch.
11069
11069
  */ function addWidgets(widgets) {
11070
11070
  if (!Array.isArray(widgets)) {
11071
- throw new Error(withUsage$q('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
11071
+ throw new Error(withUsage$r('The `addWidgets` method expects an array of widgets. Please use `addWidget`.'));
11072
11072
  }
11073
11073
  if (this.compositionID && widgets.some(function(w) {
11074
11074
  return !Array.isArray(w) && isIndexWidget(w) && !w._isolated;
11075
11075
  })) {
11076
- throw new Error(withUsage$q('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
11076
+ throw new Error(withUsage$r('The `index` widget cannot be used with a composition-based InstantSearch implementation.'));
11077
11077
  }
11078
11078
  this.mainIndex.addWidgets(widgets);
11079
11079
  return this;
@@ -11102,7 +11102,7 @@
11102
11102
  * The widgets must implement a `dispose()` method to clear their states.
11103
11103
  */ function removeWidgets(widgets) {
11104
11104
  if (!Array.isArray(widgets)) {
11105
- throw new Error(withUsage$q('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
11105
+ throw new Error(withUsage$r('The `removeWidgets` method expects an array of widgets. Please use `removeWidget`.'));
11106
11106
  }
11107
11107
  this.mainIndex.removeWidgets(widgets);
11108
11108
  return this;
@@ -11116,7 +11116,7 @@
11116
11116
  */ function start() {
11117
11117
  var _this = this;
11118
11118
  if (this.started) {
11119
- throw new Error(withUsage$q('The `start` method has already been called once.'));
11119
+ throw new Error(withUsage$r('The `start` method has already been called once.'));
11120
11120
  }
11121
11121
  // This Helper is used for the queries, we don't care about its state. The
11122
11122
  // states are managed at the `index` level. We use this Helper to create
@@ -11318,7 +11318,7 @@
11318
11318
  var _this = this;
11319
11319
  var callOnStateChange = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
11320
11320
  if (!this.mainHelper) {
11321
- throw new Error(withUsage$q('The `start` method needs to be called before `setUiState`.'));
11321
+ throw new Error(withUsage$r('The `start` method needs to be called before `setUiState`.'));
11322
11322
  }
11323
11323
  // We refresh the index UI state to update the local UI state that the
11324
11324
  // main index passes to the function form of `setUiState`.
@@ -11355,7 +11355,7 @@
11355
11355
  value: function createURL() {
11356
11356
  var nextState = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
11357
11357
  if (!this.started) {
11358
- throw new Error(withUsage$q('The `start` method needs to be called before `createURL`.'));
11358
+ throw new Error(withUsage$r('The `start` method needs to be called before `createURL`.'));
11359
11359
  }
11360
11360
  return this._createURL(nextState);
11361
11361
  }
@@ -11364,7 +11364,7 @@
11364
11364
  key: "refresh",
11365
11365
  value: function refresh() {
11366
11366
  if (!this.mainHelper) {
11367
- throw new Error(withUsage$q('The `start` method needs to be called before `refresh`.'));
11367
+ throw new Error(withUsage$r('The `start` method needs to be called before `refresh`.'));
11368
11368
  }
11369
11369
  this.mainHelper.clearCache().search();
11370
11370
  }
@@ -11890,13 +11890,13 @@
11890
11890
  }, children);
11891
11891
  }
11892
11892
 
11893
- var withUsage$p = createDocumentationMessageGenerator({
11893
+ var withUsage$q = createDocumentationMessageGenerator({
11894
11894
  name: 'autocomplete',
11895
11895
  connector: true
11896
11896
  });
11897
11897
  var connectAutocomplete = function connectAutocomplete(renderFn) {
11898
11898
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
11899
- checkRendering(renderFn, withUsage$p());
11899
+ checkRendering(renderFn, withUsage$q());
11900
11900
  return function(widgetParams) {
11901
11901
  var _ref = widgetParams || {}, _ref_escapeHTML = _ref.escapeHTML, escapeHTML = _ref_escapeHTML === void 0 ? true : _ref_escapeHTML, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(indices) {
11902
11902
  return indices;
@@ -12005,20 +12005,20 @@
12005
12005
  return useConnector(connectAutocomplete, props, additionalWidgetProperties);
12006
12006
  }
12007
12007
 
12008
- var withUsage$o = createDocumentationMessageGenerator({
12008
+ var withUsage$p = createDocumentationMessageGenerator({
12009
12009
  name: 'breadcrumb',
12010
12010
  connector: true
12011
12011
  });
12012
12012
  var connectBreadcrumb = function connectBreadcrumb(renderFn) {
12013
12013
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
12014
- checkRendering(renderFn, withUsage$o());
12014
+ checkRendering(renderFn, withUsage$p());
12015
12015
  var connectorState = {};
12016
12016
  return function(widgetParams) {
12017
12017
  var _ref = widgetParams || {}, attributes = _ref.attributes, _ref_separator = _ref.separator, separator = _ref_separator === void 0 ? ' > ' : _ref_separator, _ref_rootPath = _ref.rootPath, rootPath = _ref_rootPath === void 0 ? null : _ref_rootPath, _ref_transformItems = _ref.transformItems, transformItems = _ref_transformItems === void 0 ? function(items) {
12018
12018
  return items;
12019
12019
  } : _ref_transformItems;
12020
12020
  if (!attributes || !Array.isArray(attributes) || attributes.length === 0) {
12021
- throw new Error(withUsage$o('The `attributes` option expects an array of strings.'));
12021
+ throw new Error(withUsage$p('The `attributes` option expects an array of strings.'));
12022
12022
  }
12023
12023
  var _attributes = _sliced_to_array(attributes, 1), hierarchicalFacetName = _attributes[0];
12024
12024
  function getRefinedState(state, facetValue) {
@@ -13469,6 +13469,41 @@
13469
13469
  return Chat;
13470
13470
  }(AbstractChat);
13471
13471
 
13472
+ // Centralizes the "open the chat from an entry point" behavior shared by the
13473
+ // SearchBox AI button, the Autocomplete AI button, prompt suggestions, and any
13474
+ // future entry point. The chat is always opened; the message is only sent when
13475
+ // it is non-empty and the chat is not already processing a message.
13476
+ // Returns true when a message was submitted, so callers can clear their input.
13477
+ function openChat(chatRenderState) {
13478
+ var _ref = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, message = _ref.message, referer = _ref.referer;
13479
+ var _ref1;
13480
+ var _chatRenderState_setOpen;
13481
+ if (!chatRenderState) {
13482
+ return false;
13483
+ }
13484
+ (_chatRenderState_setOpen = chatRenderState.setOpen) === null || _chatRenderState_setOpen === void 0 ? void 0 : _chatRenderState_setOpen.call(chatRenderState, true);
13485
+ var trimmed = (_ref1 = message === null || message === void 0 ? void 0 : message.trim()) !== null && _ref1 !== void 0 ? _ref1 : '';
13486
+ if (!trimmed) {
13487
+ var _chatRenderState_focusInput;
13488
+ (_chatRenderState_focusInput = chatRenderState.focusInput) === null || _chatRenderState_focusInput === void 0 ? void 0 : _chatRenderState_focusInput.call(chatRenderState);
13489
+ return false;
13490
+ }
13491
+ if (isChatBusy(chatRenderState) || !chatRenderState.sendMessage) {
13492
+ return false;
13493
+ }
13494
+ chatRenderState.sendMessage({
13495
+ text: trimmed
13496
+ }, referer ? {
13497
+ headers: {
13498
+ 'x-algolia-referer': referer
13499
+ }
13500
+ } : undefined);
13501
+ return true;
13502
+ }
13503
+ function isChatBusy(chatRenderState) {
13504
+ return (chatRenderState === null || chatRenderState === void 0 ? void 0 : chatRenderState.status) === 'submitted' || (chatRenderState === null || chatRenderState === void 0 ? void 0 : chatRenderState.status) === 'streaming';
13505
+ }
13506
+
13472
13507
  var SearchIndexToolType = 'algolia_search_index';
13473
13508
 
13474
13509
  function flat(arr) {
@@ -13649,7 +13684,7 @@
13649
13684
  return DefaultChatTransport;
13650
13685
  }(HttpChatTransport);
13651
13686
 
13652
- var withUsage$n = createDocumentationMessageGenerator({
13687
+ var withUsage$o = createDocumentationMessageGenerator({
13653
13688
  name: 'chat',
13654
13689
  connector: true
13655
13690
  });
@@ -13700,15 +13735,16 @@
13700
13735
  }
13701
13736
  var connectChat = function connectChat(renderFn) {
13702
13737
  var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
13703
- checkRendering(renderFn, withUsage$n());
13738
+ checkRendering(renderFn, withUsage$o());
13704
13739
  return function(widgetParams) {
13705
- var _ref = widgetParams || {}, _ref_resume = _ref.resume, resume = _ref_resume === void 0 ? false : _ref_resume, _ref_tools = _ref.tools, tools = _ref_tools === void 0 ? {} : _ref_tools, _ref_type = _ref.type, type = _ref_type === void 0 ? 'chat' : _ref_type, context = _ref.context, initialUserMessage = _ref.initialUserMessage, initialMessages = _ref.initialMessages, options = _object_without_properties(_ref, [
13740
+ var _ref = widgetParams || {}, _ref_resume = _ref.resume, resume = _ref_resume === void 0 ? false : _ref_resume, _ref_tools = _ref.tools, tools = _ref_tools === void 0 ? {} : _ref_tools, _ref_type = _ref.type, type = _ref_type === void 0 ? 'chat' : _ref_type, context = _ref.context, initialUserMessage = _ref.initialUserMessage, initialMessages = _ref.initialMessages, _ref_disableTriggerValidation = _ref.disableTriggerValidation, disableTriggerValidation = _ref_disableTriggerValidation === void 0 ? false : _ref_disableTriggerValidation, options = _object_without_properties(_ref, [
13706
13741
  "resume",
13707
13742
  "tools",
13708
13743
  "type",
13709
13744
  "context",
13710
13745
  "initialUserMessage",
13711
- "initialMessages"
13746
+ "initialMessages",
13747
+ "disableTriggerValidation"
13712
13748
  ]);
13713
13749
  var _chatInstance;
13714
13750
  var input = '';
@@ -13720,6 +13756,7 @@
13720
13756
  var focusInput;
13721
13757
  var setIsClearing;
13722
13758
  var setFeedbackState;
13759
+ var hasValidatedEntryPoints = false;
13723
13760
  var agentId = 'agentId' in options ? options.agentId : undefined;
13724
13761
  var feedbackState = {};
13725
13762
  var _sendChatMessageFeedback;
@@ -13763,6 +13800,22 @@
13763
13800
  feedbackState = {};
13764
13801
  setIsClearing(false);
13765
13802
  };
13803
+ var validateEntryPoints = function validateEntryPoints(instantSearchInstance) {
13804
+ if (disableTriggerValidation || hasValidatedEntryPoints) {
13805
+ return;
13806
+ }
13807
+ // warning only relevant once mounted
13808
+ if (!instantSearchInstance.mainIndex) {
13809
+ return;
13810
+ }
13811
+ walkIndex(instantSearchInstance.mainIndex, function(indexWidget) {
13812
+ var widgets = indexWidget.getWidgets();
13813
+ if (widgets.some(function(w) {
13814
+ return w.opensChat === true;
13815
+ })) ;
13816
+ });
13817
+ hasValidatedEntryPoints = true;
13818
+ };
13766
13819
  var makeChatInstance = function makeChatInstance(instantSearchInstance) {
13767
13820
  var transport;
13768
13821
  var client = instantSearchInstance.client;
@@ -13812,7 +13865,7 @@
13812
13865
  }
13813
13866
  if ('agentId' in options && options.agentId) {
13814
13867
  if (!appId || !apiKey) {
13815
- throw new Error(withUsage$n('Could not extract Algolia credentials from the search client.'));
13868
+ throw new Error(withUsage$o('Could not extract Algolia credentials from the search client.'));
13816
13869
  }
13817
13870
  var baseApi = "https://".concat(appId, ".algolia.net/agent-studio/1/agents/").concat(agentId, "/completions?compatibilityMode=ai-sdk-5");
13818
13871
  transport = new DefaultChatTransport({
@@ -13837,7 +13890,7 @@
13837
13890
  });
13838
13891
  }
13839
13892
  if (!transport) {
13840
- throw new Error(withUsage$n('You need to provide either an `agentId` or a `transport`.'));
13893
+ throw new Error(withUsage$o('You need to provide either an `agentId` or a `transport`.'));
13841
13894
  }
13842
13895
  if ('chat' in options) {
13843
13896
  return options.chat;
@@ -13889,6 +13942,7 @@
13889
13942
  init: function init(initOptions) {
13890
13943
  var _this = this;
13891
13944
  var instantSearchInstance = initOptions.instantSearchInstance;
13945
+ validateEntryPoints(instantSearchInstance);
13892
13946
  _chatInstance = makeChatInstance(instantSearchInstance);
13893
13947
  var render = function render() {
13894
13948
  renderFn(_object_spread_props(_object_spread({}, _this.getWidgetRenderState(initOptions)), {
@@ -13898,6 +13952,10 @@
13898
13952
  setOpen = function setOpen(o) {
13899
13953
  open = o;
13900
13954
  render();
13955
+ // `open` is read by sibling widgets (e.g. `chatTrigger`) via the
13956
+ // shared `renderState`. Schedule a full re-render so they pick up
13957
+ // the new value instead of staying frozen on their initial state.
13958
+ initOptions.instantSearchInstance.scheduleRender();
13901
13959
  };
13902
13960
  focusInput = function focusInput() {
13903
13961
  setOpen(true);
@@ -13918,7 +13976,7 @@
13918
13976
  if (agentId && feedback) {
13919
13977
  var _getAppIdAndApiKey = _sliced_to_array(getAppIdAndApiKey(initOptions.instantSearchInstance.client), 2), appId = _getAppIdAndApiKey[0], apiKey = _getAppIdAndApiKey[1];
13920
13978
  if (!appId || !apiKey) {
13921
- throw new Error(withUsage$n('Could not extract Algolia credentials from the search client.'));
13979
+ throw new Error(withUsage$o('Could not extract Algolia credentials from the search client.'));
13922
13980
  }
13923
13981
  feedbackAbortController = new AbortController();
13924
13982
  _sendChatMessageFeedback = function _sendChatMessageFeedback(messageId, vote) {
@@ -13959,6 +14017,7 @@
13959
14017
  }), true);
13960
14018
  },
13961
14019
  render: function render(renderOptions) {
14020
+ validateEntryPoints(renderOptions.instantSearchInstance);
13962
14021
  renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(renderOptions)), {
13963
14022
  instantSearchInstance: renderOptions.instantSearchInstance
13964
14023
  }), false);
@@ -14065,6 +14124,77 @@
14065
14124
  return useConnector(connectChat, props, additionalWidgetProperties);
14066
14125
  }
14067
14126
 
14127
+ var withUsage$n = createDocumentationMessageGenerator({
14128
+ name: 'chatTrigger',
14129
+ connector: true
14130
+ });
14131
+ // Reads the sibling chat widget's render state from the live cross-index
14132
+ // `instantSearchInstance.renderState` map. We resolve at call time so that
14133
+ // `toggleOpen` always sees the latest `open`/`setOpen` values.
14134
+ function getChatRenderState(options) {
14135
+ var _options_parent, _options_instantSearchInstance_renderState_indexId;
14136
+ var indexId = (_options_parent = options.parent) === null || _options_parent === void 0 ? void 0 : _options_parent.getIndexId();
14137
+ if (!indexId) return undefined;
14138
+ return (_options_instantSearchInstance_renderState_indexId = options.instantSearchInstance.renderState[indexId]) === null || _options_instantSearchInstance_renderState_indexId === void 0 ? void 0 : _options_instantSearchInstance_renderState_indexId.chat;
14139
+ }
14140
+ var connectChatTrigger = function connectChatTrigger(renderFn) {
14141
+ var unmountFn = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
14142
+ checkRendering(renderFn, withUsage$n());
14143
+ return function(widgetParams) {
14144
+ var params = widgetParams !== null && widgetParams !== void 0 ? widgetParams : {};
14145
+ var lastOptions = null;
14146
+ function toggleOpen() {
14147
+ if (!lastOptions) return;
14148
+ var chatState = getChatRenderState(lastOptions);
14149
+ if (!chatState) return;
14150
+ if (chatState.open) {
14151
+ var _chatState_setOpen;
14152
+ (_chatState_setOpen = chatState.setOpen) === null || _chatState_setOpen === void 0 ? void 0 : _chatState_setOpen.call(chatState, false);
14153
+ } else {
14154
+ openChat(chatState);
14155
+ }
14156
+ }
14157
+ return {
14158
+ $$type: 'ais.chatTrigger',
14159
+ opensChat: true,
14160
+ init: function init(initOptions) {
14161
+ lastOptions = initOptions;
14162
+ renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(initOptions)), {
14163
+ instantSearchInstance: initOptions.instantSearchInstance
14164
+ }), true);
14165
+ },
14166
+ render: function render(renderOptions) {
14167
+ lastOptions = renderOptions;
14168
+ renderFn(_object_spread_props(_object_spread({}, this.getWidgetRenderState(renderOptions)), {
14169
+ instantSearchInstance: renderOptions.instantSearchInstance
14170
+ }), false);
14171
+ },
14172
+ dispose: function dispose() {
14173
+ unmountFn();
14174
+ },
14175
+ getWidgetRenderState: function getWidgetRenderState(renderOptions) {
14176
+ var _ref;
14177
+ var chatState = getChatRenderState(renderOptions);
14178
+ return {
14179
+ open: (_ref = chatState === null || chatState === void 0 ? void 0 : chatState.open) !== null && _ref !== void 0 ? _ref : false,
14180
+ toggleOpen: toggleOpen,
14181
+ widgetParams: params
14182
+ };
14183
+ },
14184
+ getRenderState: function getRenderState(renderState, renderOptions) {
14185
+ return _object_spread_props(_object_spread({}, renderState), {
14186
+ chatTrigger: this.getWidgetRenderState(renderOptions)
14187
+ });
14188
+ }
14189
+ };
14190
+ };
14191
+ };
14192
+
14193
+ function useChatTrigger() {
14194
+ var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, additionalWidgetProperties = arguments.length > 1 ? arguments[1] : void 0;
14195
+ return useConnector(connectChatTrigger, props, additionalWidgetProperties);
14196
+ }
14197
+
14068
14198
  var withUsage$m = createDocumentationMessageGenerator({
14069
14199
  name: 'clear-refinements',
14070
14200
  connector: true
@@ -18190,6 +18320,7 @@
18190
18320
  exports.useAutocomplete = useAutocomplete;
18191
18321
  exports.useBreadcrumb = useBreadcrumb;
18192
18322
  exports.useChat = useChat;
18323
+ exports.useChatTrigger = useChatTrigger;
18193
18324
  exports.useClearRefinements = useClearRefinements;
18194
18325
  exports.useConfigure = useConfigure;
18195
18326
  exports.useConnector = useConnector;