instantsearch.js 4.82.0 → 4.84.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.
@@ -251,7 +251,10 @@ function ChatWrapper(_ref0) {
251
251
  loaderComponent: messagesProps.loaderComponent,
252
252
  errorComponent: messagesProps.errorComponent,
253
253
  actionsComponent: messagesProps.actionsComponent,
254
- translations: messagesProps.translations
254
+ assistantMessageProps: messagesProps.assistantMessageProps,
255
+ userMessageProps: messagesProps.userMessageProps,
256
+ translations: messagesProps.translations,
257
+ messageTranslations: messagesProps.messageTranslations
255
258
  },
256
259
  promptProps: {
257
260
  promptRef: promptProps.promptRef,
@@ -285,8 +288,10 @@ var createRenderer = function createRenderer(_ref1) {
285
288
  var promptRef = {
286
289
  current: null
287
290
  };
291
+
292
+ // eslint-disable-next-line complexity
288
293
  return function (props, isFirstRendering) {
289
- var _templates$header, _templates$header2, _templates$header3, _templates$header4, _templates$header5, _templates$header6, _templates$header7, _templates$header8, _templates$header9, _templates$header0, _templates$messages, _templates$messages2, _templates$messages3, _templates$messages4, _templates$messages5, _templates$messages6, _templates$prompt, _templates$prompt2, _templates$prompt3, _templates$prompt4, _templates$prompt5, _templates$prompt6, _templates$prompt7, _templates$prompt8, _templates$prompt9, _templates$toggleButt, _templates$toggleButt2;
294
+ var _templates$header, _templates$header2, _templates$header3, _templates$header4, _templates$header5, _templates$header6, _templates$header7, _templates$header8, _templates$header9, _templates$header0, _templates$messages, _templates$messages2, _templates$messages3, _templates$messages4, _templates$messages5, _templates$messages6, _templates$assistantM, _templates$assistantM2, _templates$message, _templates$message2, _templates$userMessag, _templates$userMessag2, _templates$prompt, _templates$prompt2, _templates$prompt3, _templates$prompt4, _templates$prompt5, _templates$prompt6, _templates$prompt7, _templates$prompt8, _templates$prompt9, _templates$toggleButt, _templates$toggleButt2;
290
295
  var indexUiState = props.indexUiState,
291
296
  input = props.input,
292
297
  instantSearchInstance = props.instantSearchInstance,
@@ -298,7 +303,6 @@ var createRenderer = function createRenderer(_ref1) {
298
303
  setOpen = props.setOpen,
299
304
  status = props.status,
300
305
  error = props.error,
301
- addToolResult = props.addToolResult,
302
306
  regenerate = props.regenerate,
303
307
  stop = props.stop,
304
308
  isClearing = props.isClearing,
@@ -318,12 +322,12 @@ var createRenderer = function createRenderer(_ref1) {
318
322
  }
319
323
  var toolsForUi = {};
320
324
  Object.entries(toolsFromConnector).forEach(function (_ref10) {
325
+ var _widgetTool$templates;
321
326
  var _ref11 = _slicedToArray(_ref10, 2),
322
327
  key = _ref11[0],
323
328
  connectorTool = _ref11[1];
324
329
  var widgetTool = tools[key];
325
- toolsForUi[key] = _objectSpread(_objectSpread({}, connectorTool), {}, {
326
- addToolResult: addToolResult,
330
+ toolsForUi[key] = _objectSpread(_objectSpread({}, connectorTool), (widgetTool === null || widgetTool === void 0 ? void 0 : (_widgetTool$templates = widgetTool.templates) === null || _widgetTool$templates === void 0 ? void 0 : _widgetTool$templates.layout) && {
327
331
  layoutComponent: function layoutComponent(layoutComponentProps) {
328
332
  return h(TemplateComponent, {
329
333
  templates: widgetTool.templates,
@@ -406,6 +410,44 @@ var createRenderer = function createRenderer(_ref1) {
406
410
  copyToClipboardLabel: (_templates$messages5 = templates.messages) === null || _templates$messages5 === void 0 ? void 0 : _templates$messages5.copyToClipboardLabelText,
407
411
  regenerateLabel: (_templates$messages6 = templates.messages) === null || _templates$messages6 === void 0 ? void 0 : _templates$messages6.regenerateLabelText
408
412
  });
413
+ var assistantMessageTemplateProps = prepareTemplateProps({
414
+ defaultTemplates: {},
415
+ templatesConfig: instantSearchInstance.templatesConfig,
416
+ templates: templates.assistantMessage
417
+ });
418
+ var assistantMessageLeadingComponent = (_templates$assistantM = templates.assistantMessage) !== null && _templates$assistantM !== void 0 && _templates$assistantM.leading ? function () {
419
+ return h(TemplateComponent, _extends({}, assistantMessageTemplateProps, {
420
+ templateKey: "leading",
421
+ rootTagName: "fragment"
422
+ }));
423
+ } : undefined;
424
+ var assistantMessageFooterComponent = (_templates$assistantM2 = templates.assistantMessage) !== null && _templates$assistantM2 !== void 0 && _templates$assistantM2.footer ? function () {
425
+ return h(TemplateComponent, _extends({}, assistantMessageTemplateProps, {
426
+ templateKey: "footer",
427
+ rootTagName: "fragment"
428
+ }));
429
+ } : undefined;
430
+ var messageTranslations = getDefinedProperties({
431
+ actionsLabel: (_templates$message = templates.message) === null || _templates$message === void 0 ? void 0 : _templates$message.actionsLabelText,
432
+ messageLabel: (_templates$message2 = templates.message) === null || _templates$message2 === void 0 ? void 0 : _templates$message2.messageLabelText
433
+ });
434
+ var userMessageTemplateProps = prepareTemplateProps({
435
+ defaultTemplates: {},
436
+ templatesConfig: instantSearchInstance.templatesConfig,
437
+ templates: templates.userMessage
438
+ });
439
+ var userMessageLeadingComponent = (_templates$userMessag = templates.userMessage) !== null && _templates$userMessag !== void 0 && _templates$userMessag.leading ? function () {
440
+ return h(TemplateComponent, _extends({}, userMessageTemplateProps, {
441
+ templateKey: "leading",
442
+ rootTagName: "fragment"
443
+ }));
444
+ } : undefined;
445
+ var userMessageFooterComponent = (_templates$userMessag2 = templates.userMessage) !== null && _templates$userMessag2 !== void 0 && _templates$userMessag2.footer ? function () {
446
+ return h(TemplateComponent, _extends({}, userMessageTemplateProps, {
447
+ templateKey: "footer",
448
+ rootTagName: "fragment"
449
+ }));
450
+ } : undefined;
409
451
  var promptTemplateProps = prepareTemplateProps({
410
452
  defaultTemplates: {},
411
453
  templatesConfig: instantSearchInstance.templatesConfig,
@@ -502,7 +544,16 @@ var createRenderer = function createRenderer(_ref1) {
502
544
  loaderComponent: messagesLoaderComponent,
503
545
  errorComponent: messagesErrorComponent,
504
546
  actionsComponent: actionsComponent,
505
- translations: messagesTranslations
547
+ assistantMessageProps: {
548
+ leadingComponent: assistantMessageLeadingComponent,
549
+ footerComponent: assistantMessageFooterComponent
550
+ },
551
+ userMessageProps: {
552
+ leadingComponent: userMessageLeadingComponent,
553
+ footerComponent: userMessageFooterComponent
554
+ },
555
+ translations: messagesTranslations,
556
+ messageTranslations: messageTranslations
506
557
  },
507
558
  promptProps: {
508
559
  layoutComponent: promptLayoutComponent,
@@ -97,6 +97,11 @@ export type IndexWidget<TUiState extends UiState = UiState> = Omit<Widget<IndexW
97
97
  * @private
98
98
  */
99
99
  _isolated: boolean;
100
+ /**
101
+ * Schedules a search for this index only.
102
+ * @private
103
+ */
104
+ scheduleLocalSearch: () => void;
100
105
  };
101
106
  declare const index: (widgetParams: IndexWidgetParams) => IndexWidget;
102
107
  export default index;
@@ -15,7 +15,7 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
15
15
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
16
16
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
17
17
  import algoliasearchHelper from 'algoliasearch-helper';
18
- import { checkIndexUiState, createDocumentationMessageGenerator, resolveSearchParameters, mergeSearchParameters, warning, isIndexWidget, createInitArgs, createRenderArgs } from "../../lib/utils/index.js";
18
+ import { checkIndexUiState, createDocumentationMessageGenerator, resolveSearchParameters, mergeSearchParameters, warning, isIndexWidget, createInitArgs, createRenderArgs, defer } from "../../lib/utils/index.js";
19
19
  import { addWidgetId } from "../../lib/utils/addWidgetId.js";
20
20
  var withUsage = createDocumentationMessageGenerator({
21
21
  name: 'index-widget'
@@ -197,6 +197,12 @@ var index = function index(widgetParams) {
197
197
  helper: helper
198
198
  })));
199
199
  },
200
+ scheduleLocalSearch: defer(function () {
201
+ if (isolated) {
202
+ var _helper2;
203
+ (_helper2 = helper) === null || _helper2 === void 0 ? void 0 : _helper2.search();
204
+ }
205
+ }),
200
206
  getWidgets: function getWidgets() {
201
207
  return localWidgets;
202
208
  },
@@ -262,8 +268,7 @@ var index = function index(widgetParams) {
262
268
  }
263
269
  });
264
270
  if (isolated) {
265
- var _helper2;
266
- (_helper2 = helper) === null || _helper2 === void 0 ? void 0 : _helper2.search();
271
+ this.scheduleLocalSearch();
267
272
  } else {
268
273
  localInstantSearchInstance.scheduleSearch();
269
274
  }
@@ -342,8 +347,7 @@ var index = function index(widgetParams) {
342
347
  helper.recommendState = cleanedRecommendState;
343
348
  if (localWidgets.length) {
344
349
  if (isolated) {
345
- var _helper3;
346
- (_helper3 = helper) === null || _helper3 === void 0 ? void 0 : _helper3.search();
350
+ this.scheduleLocalSearch();
347
351
  } else {
348
352
  localInstantSearchInstance.scheduleSearch();
349
353
  }
@@ -415,12 +419,6 @@ var index = function index(widgetParams) {
415
419
  helper.searchWithoutTriggeringOnStateChange = function () {
416
420
  return mainHelper.search();
417
421
  };
418
-
419
- // We use the same pattern for the `searchForFacetValues`.
420
- helper.searchForFacetValues = function (facetName, facetValue, maxFacetHits, userState) {
421
- var state = helper.state.setQueryParameters(userState);
422
- return mainHelper.searchForFacetValues(facetName, facetValue, maxFacetHits, state);
423
- };
424
422
  var isolatedHelper = indexName ? helper : algoliasearchHelper({}, '__empty_index__', {});
425
423
  var derivingHelper = isolated ? isolatedHelper : nearestIsolatedHelper(parent, mainHelper);
426
424
  derivedHelper = derivingHelper.derive(function () {
@@ -603,7 +601,7 @@ var index = function index(widgetParams) {
603
601
  },
604
602
  dispose: function dispose() {
605
603
  var _this5 = this,
606
- _helper4,
604
+ _helper3,
607
605
  _derivedHelper3;
608
606
  localWidgets.forEach(function (widget) {
609
607
  if (widget.dispose && helper) {
@@ -623,7 +621,7 @@ var index = function index(widgetParams) {
623
621
  });
624
622
  localInstantSearchInstance = null;
625
623
  localParent = null;
626
- (_helper4 = helper) === null || _helper4 === void 0 ? void 0 : _helper4.removeAllListeners();
624
+ (_helper3 = helper) === null || _helper3 === void 0 ? void 0 : _helper3.removeAllListeners();
627
625
  helper = null;
628
626
  (_derivedHelper3 = derivedHelper) === null || _derivedHelper3 === void 0 ? void 0 : _derivedHelper3.detach();
629
627
  derivedHelper = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instantsearch.js",
3
- "version": "4.82.0",
3
+ "version": "4.84.0",
4
4
  "description": "InstantSearch.js is a JavaScript library for building performant and instant search experiences with Algolia.",
5
5
  "homepage": "https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/",
6
6
  "types": "es/index.d.ts",
@@ -32,10 +32,10 @@
32
32
  "@types/hogan.js": "^3.0.0",
33
33
  "@types/qs": "^6.5.3",
34
34
  "ai": "^5.0.18",
35
- "algoliasearch-helper": "3.26.0",
35
+ "algoliasearch-helper": "3.26.1",
36
36
  "hogan.js": "^3.0.2",
37
37
  "htm": "^3.0.0",
38
- "instantsearch-ui-components": "0.13.0",
38
+ "instantsearch-ui-components": "0.15.0",
39
39
  "preact": "^10.10.0",
40
40
  "qs": "^6.5.1 < 6.10",
41
41
  "react": ">= 0.14.0",
@@ -60,9 +60,9 @@
60
60
  "watch:es": "yarn --silent build:es:base --watch"
61
61
  },
62
62
  "devDependencies": {
63
- "@instantsearch/mocks": "1.80.0",
64
- "@instantsearch/tests": "1.80.0",
65
- "@instantsearch/testutils": "1.69.0",
63
+ "@instantsearch/mocks": "1.82.0",
64
+ "@instantsearch/tests": "1.82.0",
65
+ "@instantsearch/testutils": "1.71.0",
66
66
  "@storybook/html": "5.3.9",
67
67
  "@types/scriptjs": "0.0.2",
68
68
  "algoliasearch": "5.1.1",
@@ -70,5 +70,5 @@
70
70
  "scriptjs": "2.5.9",
71
71
  "webpack": "4.47.0"
72
72
  },
73
- "gitHead": "89dc58afb61fbabb29e326d18543e51907eaea88"
73
+ "gitHead": "b4cb69c8cfaa9dc22dfe8fe695568cf5200f3893"
74
74
  }