algolia-experiences 1.7.4 → 1.8.1

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.
@@ -1,4 +1,4 @@
1
- /*! algolia-experiences 1.7.4 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
1
+ /*! algolia-experiences 1.8.1 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch */
2
2
  (function (factory) {
3
3
  typeof define === 'function' && define.amd ? define(factory) :
4
4
  factory();
@@ -2575,6 +2575,12 @@
2575
2575
  * This doesn't contain any beta/hidden features.
2576
2576
  * @private
2577
2577
  */ SearchParameters.PARAMETERS = Object.keys(new SearchParameters());
2578
+ // Returns a finite number or null. Used to reject Infinity/-Infinity from parseFloat.
2579
+ function parseFiniteFloat(value) {
2580
+ var n = parseFloat(value);
2581
+ // global isFinite is safe here: n is always a number type (no string coercion risk)
2582
+ return isFinite(n) ? n : null;
2583
+ }
2578
2584
  /**
2579
2585
  * @private
2580
2586
  * @param {object} partialState full or part of a state
@@ -2600,8 +2606,18 @@
2600
2606
  var value = partialState[k];
2601
2607
  if (typeof value === 'string') {
2602
2608
  var parsedValue = parseFloat(value);
2603
- // global isNaN is ok to use here, value is only number or NaN
2604
- numbers[k] = isNaN(parsedValue) ? value : parsedValue;
2609
+ if (isNaN(parsedValue)) {
2610
+ // originally an unparseable string like "all", keep NaN
2611
+ numbers[k] = value;
2612
+ } else if (!isFinite(parsedValue)) {
2613
+ // Infinity/-Infinity — convert to null
2614
+ numbers[k] = null;
2615
+ } else {
2616
+ numbers[k] = parsedValue;
2617
+ }
2618
+ } else if (typeof value === 'number' && !isFinite(value)) {
2619
+ // Already-numeric Infinity — convert to null
2620
+ numbers[k] = null;
2605
2621
  }
2606
2622
  });
2607
2623
  // there's two formats of insideBoundingBox, we need to parse
@@ -2610,7 +2626,13 @@
2610
2626
  numbers.insideBoundingBox = partialState.insideBoundingBox.map(function(geoRect) {
2611
2627
  if (Array.isArray(geoRect)) {
2612
2628
  return geoRect.map(function(value) {
2613
- return parseFloat(value);
2629
+ if (typeof value === 'string') {
2630
+ return parseFiniteFloat(value);
2631
+ }
2632
+ if (typeof value === 'number' && !isFinite(value)) {
2633
+ return null;
2634
+ }
2635
+ return value;
2614
2636
  });
2615
2637
  }
2616
2638
  return geoRect;
@@ -2627,12 +2649,17 @@
2627
2649
  if (Array.isArray(v)) {
2628
2650
  return v.map(function(vPrime) {
2629
2651
  if (typeof vPrime === 'string') {
2630
- return parseFloat(vPrime);
2652
+ return parseFiniteFloat(vPrime);
2653
+ }
2654
+ if (typeof vPrime === 'number' && !isFinite(vPrime)) {
2655
+ return null;
2631
2656
  }
2632
2657
  return vPrime;
2633
2658
  });
2634
2659
  } else if (typeof v === 'string') {
2635
- return parseFloat(v);
2660
+ return parseFiniteFloat(v);
2661
+ } else if (typeof v === 'number' && !isFinite(v)) {
2662
+ return null;
2636
2663
  }
2637
2664
  return v;
2638
2665
  });
@@ -4960,7 +4987,7 @@
4960
4987
  function requireVersion() {
4961
4988
  if (hasRequiredVersion) return version$1;
4962
4989
  hasRequiredVersion = 1;
4963
- version$1 = '3.28.1';
4990
+ version$1 = '3.28.2';
4964
4991
  return version$1;
4965
4992
  }
4966
4993
 
@@ -9930,7 +9957,7 @@
9930
9957
  };
9931
9958
  }
9932
9959
 
9933
- var version = '4.93.0';
9960
+ var version = '4.95.0';
9934
9961
 
9935
9962
  function hydrateSearchClient(client, results) {
9936
9963
  if (!results) {
@@ -13926,6 +13953,10 @@
13926
13953
  _this.setState({
13927
13954
  focused: true
13928
13955
  });
13956
+ }), _define_property(_this, "onAiModeClick", function(event) {
13957
+ var _this_props_onAiModeClick, _this_props;
13958
+ event.preventDefault();
13959
+ (_this_props_onAiModeClick = (_this_props = _this.props).onAiModeClick) === null || _this_props_onAiModeClick === void 0 ? void 0 : _this_props_onAiModeClick.call(_this_props, _this.state.query);
13929
13960
  });
13930
13961
  return _this;
13931
13962
  }
@@ -13961,7 +13992,7 @@
13961
13992
  {
13962
13993
  key: "render",
13963
13994
  value: function render() {
13964
- var _this_props = this.props, cssClasses = _this_props.cssClasses, placeholder = _this_props.placeholder, autofocus = _this_props.autofocus, showSubmit = _this_props.showSubmit, showReset = _this_props.showReset, showLoadingIndicator = _this_props.showLoadingIndicator, templates = _this_props.templates, isSearchStalled = _this_props.isSearchStalled, ariaLabel = _this_props.ariaLabel, inputProps = _this_props.inputProps;
13995
+ var _this_props = this.props, cssClasses = _this_props.cssClasses, placeholder = _this_props.placeholder, autofocus = _this_props.autofocus, showSubmit = _this_props.showSubmit, showReset = _this_props.showReset, showLoadingIndicator = _this_props.showLoadingIndicator, templates = _this_props.templates, isSearchStalled = _this_props.isSearchStalled, ariaLabel = _this_props.ariaLabel, inputProps = _this_props.inputProps, onAiModeClick = _this_props.onAiModeClick;
13965
13996
  return /*#__PURE__*/ h$1("div", {
13966
13997
  className: cssClasses.root
13967
13998
  }, /*#__PURE__*/ h$1("form", {
@@ -14029,6 +14060,19 @@
14029
14060
  data: {
14030
14061
  cssClasses: cssClasses
14031
14062
  }
14063
+ }), onAiModeClick && /*#__PURE__*/ h$1(Template, {
14064
+ templateKey: "aiMode",
14065
+ rootTagName: "button",
14066
+ rootProps: {
14067
+ className: cssClasses.aiModeButton,
14068
+ type: 'button',
14069
+ title: 'AI Mode',
14070
+ onClick: this.onAiModeClick
14071
+ },
14072
+ templates: templates,
14073
+ data: {
14074
+ cssClasses: cssClasses
14075
+ }
14032
14076
  })));
14033
14077
  }
14034
14078
  }
@@ -14756,9 +14800,9 @@
14756
14800
  return 'No results';
14757
14801
  },
14758
14802
  item: function item(data) {
14759
- return JSON.stringify(omit(data, [
14803
+ return /*#__PURE__*/ h$1(p$1, null, JSON.stringify(omit(data, [
14760
14804
  '__hitIndex'
14761
- ]), null, 2);
14805
+ ]), null, 2));
14762
14806
  }
14763
14807
  };
14764
14808
 
@@ -15523,9 +15567,9 @@
15523
15567
  return 'Show more results';
15524
15568
  },
15525
15569
  item: function item(data) {
15526
- return JSON.stringify(omit(data, [
15570
+ return /*#__PURE__*/ h$1(p$1, null, JSON.stringify(omit(data, [
15527
15571
  '__hitIndex'
15528
- ]), null, 2);
15572
+ ]), null, 2));
15529
15573
  }
15530
15574
  };
15531
15575
 
@@ -18807,6 +18851,30 @@
18807
18851
  }
18808
18852
 
18809
18853
  var defaultTemplate = {
18854
+ aiMode: function aiMode(param) {
18855
+ var cssClasses = param.cssClasses;
18856
+ return /*#__PURE__*/ h$1(p$1, null, /*#__PURE__*/ h$1("svg", {
18857
+ className: cssClasses.aiModeIcon,
18858
+ xmlns: "http://www.w3.org/2000/svg",
18859
+ fill: "none",
18860
+ viewBox: "0 0 20 20",
18861
+ width: "16",
18862
+ height: "16",
18863
+ "aria-hidden": "true"
18864
+ }, /*#__PURE__*/ h$1("path", {
18865
+ fill: "currentColor",
18866
+ "fill-rule": "evenodd",
18867
+ d: "M10 1.875c.27 0 .51.173.594.43l1.593 4.844a1.043 1.043 0 0 0 .664.664l4.844 1.593a.625.625 0 0 1 0 1.188l-4.844 1.593a1.043 1.043 0 0 0-.664.664l-1.593 4.844a.625.625 0 0 1-1.188 0l-1.593-4.844a1.042 1.042 0 0 0-.664-.664l-4.844-1.593a.625.625 0 0 1 0-1.188l4.844-1.593a1.042 1.042 0 0 0 .664-.664l1.593-4.844a.625.625 0 0 1 .594-.43ZM9 7.539A2.292 2.292 0 0 1 7.54 9L4.5 10l3.04 1A2.292 2.292 0 0 1 9 12.46l1 3.04 1-3.04A2.293 2.293 0 0 1 12.46 11l3.04-1-3.04-1A2.292 2.292 0 0 1 11 7.54L10 4.5 9 7.54ZM4.167 1.875c.345 0 .625.28.625.625v3.333a.625.625 0 0 1-1.25 0V2.5c0-.345.28-.625.625-.625ZM15.833 13.542c.345 0 .625.28.625.625V17.5a.625.625 0 1 1-1.25 0v-3.333c0-.345.28-.625.625-.625Z",
18868
+ "clip-rule": "evenodd"
18869
+ }), /*#__PURE__*/ h$1("path", {
18870
+ fill: "currentColor",
18871
+ "fill-rule": "evenodd",
18872
+ d: "M1.875 4.167c0-.346.28-.625.625-.625h3.333a.625.625 0 1 1 0 1.25H2.5a.625.625 0 0 1-.625-.625ZM13.542 15.833c0-.345.28-.625.625-.625H17.5a.625.625 0 0 1 0 1.25h-3.333a.625.625 0 0 1-.625-.625Z",
18873
+ "clip-rule": "evenodd"
18874
+ })), /*#__PURE__*/ h$1("span", {
18875
+ className: cssClasses.aiModeLabel
18876
+ }, "AI Mode"));
18877
+ },
18810
18878
  reset: function reset(param) {
18811
18879
  var cssClasses = param.cssClasses;
18812
18880
  return /*#__PURE__*/ h$1("svg", {
@@ -19068,10 +19136,26 @@
19068
19136
  name: 'search-box'
19069
19137
  });
19070
19138
  var suit$3 = component('SearchBox');
19139
+ var aiModeSuit = component('AiModeButton');
19071
19140
  var renderer$5 = function renderer(param) {
19072
- var containerNode = param.containerNode, cssClasses = param.cssClasses, placeholder = param.placeholder, templates = param.templates, autofocus = param.autofocus, searchAsYouType = param.searchAsYouType, ignoreCompositionEvents = param.ignoreCompositionEvents, showReset = param.showReset, showSubmit = param.showSubmit, showLoadingIndicator = param.showLoadingIndicator;
19141
+ var containerNode = param.containerNode, cssClasses = param.cssClasses, placeholder = param.placeholder, templates = param.templates, autofocus = param.autofocus, searchAsYouType = param.searchAsYouType, ignoreCompositionEvents = param.ignoreCompositionEvents, showReset = param.showReset, showSubmit = param.showSubmit, showLoadingIndicator = param.showLoadingIndicator, aiMode = param.aiMode;
19073
19142
  return function(param) {
19074
- var refine = param.refine, query = param.query, isSearchStalled = param.isSearchStalled;
19143
+ var refine = param.refine, query = param.query, isSearchStalled = param.isSearchStalled, instantSearchInstance = param.instantSearchInstance;
19144
+ var onAiModeClick = aiMode ? function(currentQuery) {
19145
+ var _instantSearchInstance_renderState_indexId;
19146
+ var indexId = instantSearchInstance.mainIndex.getIndexId();
19147
+ var chatRenderState = (_instantSearchInstance_renderState_indexId = instantSearchInstance.renderState[indexId]) === null || _instantSearchInstance_renderState_indexId === void 0 ? void 0 : _instantSearchInstance_renderState_indexId.chat;
19148
+ if (chatRenderState) {
19149
+ var _chatRenderState_setOpen;
19150
+ (_chatRenderState_setOpen = chatRenderState.setOpen) === null || _chatRenderState_setOpen === void 0 ? void 0 : _chatRenderState_setOpen.call(chatRenderState, true);
19151
+ if (currentQuery.trim()) {
19152
+ var _chatRenderState_sendMessage;
19153
+ (_chatRenderState_sendMessage = chatRenderState.sendMessage) === null || _chatRenderState_sendMessage === void 0 ? void 0 : _chatRenderState_sendMessage.call(chatRenderState, {
19154
+ text: currentQuery
19155
+ });
19156
+ }
19157
+ }
19158
+ } : undefined;
19075
19159
  P(/*#__PURE__*/ h$1(SearchBox, {
19076
19160
  query: query,
19077
19161
  placeholder: placeholder,
@@ -19084,12 +19168,13 @@
19084
19168
  showReset: showReset,
19085
19169
  showLoadingIndicator: showLoadingIndicator,
19086
19170
  isSearchStalled: isSearchStalled,
19087
- cssClasses: cssClasses
19171
+ cssClasses: cssClasses,
19172
+ onAiModeClick: onAiModeClick
19088
19173
  }), containerNode);
19089
19174
  };
19090
19175
  };
19091
19176
  var searchBox = function searchBox(widgetParams) {
19092
- var _ref = widgetParams || {}, container = _ref.container, _ref_placeholder = _ref.placeholder, placeholder = _ref_placeholder === void 0 ? '' : _ref_placeholder, tmp = _ref.cssClasses, userCssClasses = tmp === void 0 ? {} : tmp, _ref_autofocus = _ref.autofocus, autofocus = _ref_autofocus === void 0 ? false : _ref_autofocus, _ref_searchAsYouType = _ref.searchAsYouType, searchAsYouType = _ref_searchAsYouType === void 0 ? true : _ref_searchAsYouType, _ref_ignoreCompositionEvents = _ref.ignoreCompositionEvents, ignoreCompositionEvents = _ref_ignoreCompositionEvents === void 0 ? false : _ref_ignoreCompositionEvents, _ref_showReset = _ref.showReset, showReset = _ref_showReset === void 0 ? true : _ref_showReset, _ref_showSubmit = _ref.showSubmit, showSubmit = _ref_showSubmit === void 0 ? true : _ref_showSubmit, _ref_showLoadingIndicator = _ref.showLoadingIndicator, showLoadingIndicator = _ref_showLoadingIndicator === void 0 ? true : _ref_showLoadingIndicator, queryHook = _ref.queryHook, tmp1 = _ref.templates, userTemplates = tmp1 === void 0 ? {} : tmp1;
19177
+ var _ref = widgetParams || {}, container = _ref.container, _ref_placeholder = _ref.placeholder, placeholder = _ref_placeholder === void 0 ? '' : _ref_placeholder, tmp = _ref.cssClasses, userCssClasses = tmp === void 0 ? {} : tmp, _ref_autofocus = _ref.autofocus, autofocus = _ref_autofocus === void 0 ? false : _ref_autofocus, _ref_searchAsYouType = _ref.searchAsYouType, searchAsYouType = _ref_searchAsYouType === void 0 ? true : _ref_searchAsYouType, _ref_ignoreCompositionEvents = _ref.ignoreCompositionEvents, ignoreCompositionEvents = _ref_ignoreCompositionEvents === void 0 ? false : _ref_ignoreCompositionEvents, _ref_showReset = _ref.showReset, showReset = _ref_showReset === void 0 ? true : _ref_showReset, _ref_showSubmit = _ref.showSubmit, showSubmit = _ref_showSubmit === void 0 ? true : _ref_showSubmit, _ref_showLoadingIndicator = _ref.showLoadingIndicator, showLoadingIndicator = _ref_showLoadingIndicator === void 0 ? true : _ref_showLoadingIndicator, queryHook = _ref.queryHook, tmp1 = _ref.templates, userTemplates = tmp1 === void 0 ? {} : tmp1, aiMode = _ref.aiMode;
19093
19178
  if (!container) {
19094
19179
  throw new Error(withUsage$c('The `container` option is required.'));
19095
19180
  }
@@ -19119,7 +19204,14 @@
19119
19204
  }), userCssClasses.loadingIndicator),
19120
19205
  loadingIcon: cx(suit$3({
19121
19206
  descendantName: 'loadingIcon'
19122
- }), userCssClasses.loadingIcon)
19207
+ }), userCssClasses.loadingIcon),
19208
+ aiModeButton: cx(aiModeSuit(), userCssClasses.aiModeButton),
19209
+ aiModeIcon: cx(aiModeSuit({
19210
+ descendantName: 'icon'
19211
+ }), userCssClasses.aiModeIcon),
19212
+ aiModeLabel: cx(aiModeSuit({
19213
+ descendantName: 'label'
19214
+ }), userCssClasses.aiModeLabel)
19123
19215
  };
19124
19216
  var templates = _object_spread({}, defaultTemplate, userTemplates);
19125
19217
  var specializedRenderer = renderer$5({
@@ -19132,7 +19224,8 @@
19132
19224
  ignoreCompositionEvents: ignoreCompositionEvents,
19133
19225
  showReset: showReset,
19134
19226
  showSubmit: showSubmit,
19135
- showLoadingIndicator: showLoadingIndicator
19227
+ showLoadingIndicator: showLoadingIndicator,
19228
+ aiMode: aiMode
19136
19229
  });
19137
19230
  var makeWidget = connectSearchBox(specializedRenderer, function() {
19138
19231
  return P(null, containerNode);