instantsearch.js 4.83.0 → 4.85.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.
- package/cjs/connectors/chat/connectChat.js +2 -1
- package/cjs/lib/utils/getAlgoliaAgent.js +10 -0
- package/cjs/lib/utils/index.js +11 -0
- package/cjs/lib/version.js +1 -1
- package/cjs/middlewares/createMetadataMiddleware.js +1 -2
- package/cjs/widgets/autocomplete/autocomplete.js +146 -74
- package/cjs/widgets/chat/chat.js +3 -3
- package/cjs/widgets/index/index.js +10 -6
- package/dist/instantsearch.development.d.ts +31 -2
- package/dist/instantsearch.development.js +268 -134
- package/dist/instantsearch.development.js.map +1 -1
- package/dist/instantsearch.production.d.ts +31 -2
- package/dist/instantsearch.production.min.d.ts +31 -2
- package/dist/instantsearch.production.min.js +2 -2
- package/dist/instantsearch.production.min.js.map +1 -1
- package/es/connectors/chat/connectChat.js +3 -2
- package/es/lib/utils/getAlgoliaAgent.d.ts +1 -0
- package/es/lib/utils/getAlgoliaAgent.js +4 -0
- package/es/lib/utils/index.d.ts +1 -0
- package/es/lib/utils/index.js +1 -0
- package/es/lib/version.d.ts +1 -1
- package/es/lib/version.js +1 -1
- package/es/middlewares/createMetadataMiddleware.js +2 -3
- package/es/widgets/autocomplete/autocomplete.d.ts +26 -3
- package/es/widgets/autocomplete/autocomplete.js +147 -75
- package/es/widgets/chat/chat.js +4 -4
- package/es/widgets/index/index.d.ts +5 -0
- package/es/widgets/index/index.js +11 -7
- package/package.json +6 -6
|
@@ -15,7 +15,7 @@ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i
|
|
|
15
15
|
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; }
|
|
16
16
|
import { DefaultChatTransport, lastAssistantMessageIsCompleteWithToolCalls } from 'ai';
|
|
17
17
|
import { Chat } from "../../lib/chat/index.js";
|
|
18
|
-
import { checkRendering, createDocumentationMessageGenerator, createSendEventForHits, getAppIdAndApiKey, noop, warning } from "../../lib/utils/index.js";
|
|
18
|
+
import { checkRendering, createDocumentationMessageGenerator, createSendEventForHits, getAlgoliaAgent, getAppIdAndApiKey, noop, warning } from "../../lib/utils/index.js";
|
|
19
19
|
var withUsage = createDocumentationMessageGenerator({
|
|
20
20
|
name: 'chat',
|
|
21
21
|
connector: true
|
|
@@ -74,7 +74,8 @@ export default (function connectChat(renderFn) {
|
|
|
74
74
|
api: "https://".concat(appId, ".algolia.net/agent-studio/1/agents/").concat(agentId, "/completions?compatibilityMode=ai-sdk-5"),
|
|
75
75
|
headers: {
|
|
76
76
|
'x-algolia-application-id': appId,
|
|
77
|
-
'x-algolia-api-Key': apiKey
|
|
77
|
+
'x-algolia-api-Key': apiKey,
|
|
78
|
+
'x-algolia-agent': getAlgoliaAgent(instantSearchInstance.client)
|
|
78
79
|
}
|
|
79
80
|
});
|
|
80
81
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getAlgoliaAgent(client: unknown): string;
|
package/es/lib/utils/index.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export * from './escapeFacetValue';
|
|
|
18
18
|
export * from './find';
|
|
19
19
|
export * from './findIndex';
|
|
20
20
|
export * from './geo-search';
|
|
21
|
+
export * from './getAlgoliaAgent';
|
|
21
22
|
export * from './getAppIdAndApiKey';
|
|
22
23
|
export * from './getContainerNode';
|
|
23
24
|
export * from './getHighlightedParts';
|
package/es/lib/utils/index.js
CHANGED
|
@@ -18,6 +18,7 @@ export * from "./escapeFacetValue.js";
|
|
|
18
18
|
export * from "./find.js";
|
|
19
19
|
export * from "./findIndex.js";
|
|
20
20
|
export * from "./geo-search.js";
|
|
21
|
+
export * from "./getAlgoliaAgent.js";
|
|
21
22
|
export * from "./getAppIdAndApiKey.js";
|
|
22
23
|
export * from "./getContainerNode.js";
|
|
23
24
|
export * from "./getHighlightedParts.js";
|
package/es/lib/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "4.
|
|
1
|
+
declare const _default: "4.85.0";
|
|
2
2
|
export default _default;
|
package/es/lib/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '4.
|
|
1
|
+
export default '4.85.0';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createInitArgs, safelyRunOnBrowser } from "../lib/utils/index.js";
|
|
1
|
+
import { createInitArgs, getAlgoliaAgent, safelyRunOnBrowser } from "../lib/utils/index.js";
|
|
2
2
|
function extractWidgetPayload(widgets, instantSearchInstance, payload) {
|
|
3
3
|
var initOptions = createInitArgs(instantSearchInstance, instantSearchInstance.mainIndex, instantSearchInstance._initialUiState);
|
|
4
4
|
widgets.forEach(function (widget) {
|
|
@@ -63,8 +63,7 @@ export function createMetadataMiddleware() {
|
|
|
63
63
|
subscribe: function subscribe() {
|
|
64
64
|
// using setTimeout here to delay extraction until widgets have been added in a tick (e.g. Vue)
|
|
65
65
|
setTimeout(function () {
|
|
66
|
-
|
|
67
|
-
payload.ua = client.transporter && client.transporter.userAgent ? client.transporter.userAgent.value : client._ua;
|
|
66
|
+
payload.ua = getAlgoliaAgent(instantSearchInstance.client);
|
|
68
67
|
extractWidgetPayload(instantSearchInstance.mainIndex.getWidgets(), instantSearchInstance, payload);
|
|
69
68
|
instantSearchInstance.middleware.forEach(function (middleware) {
|
|
70
69
|
return payload.widgets.push({
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
|
|
2
|
-
import type { AutocompleteConnectorParams, AutocompleteWidgetDescription } from '../../connectors/autocomplete/connectAutocomplete';
|
|
2
|
+
import type { AutocompleteConnectorParams, AutocompleteRenderState, AutocompleteWidgetDescription } from '../../connectors/autocomplete/connectAutocomplete';
|
|
3
3
|
import type { BaseHit, IndexUiState, IndexWidget, Template, WidgetFactory } from '../../types';
|
|
4
|
+
import type { PlainSearchParameters } from 'algoliasearch-helper';
|
|
4
5
|
import type { AutocompleteClassNames, AutocompleteIndexClassNames, AutocompleteIndexConfig } from 'instantsearch-ui-components';
|
|
5
6
|
export type AutocompleteCSSClasses = Partial<AutocompleteClassNames>;
|
|
6
|
-
export type
|
|
7
|
+
export type AutocompleteSearchParameters = Omit<PlainSearchParameters, 'index'>;
|
|
8
|
+
export type AutocompleteTemplates = {
|
|
9
|
+
/**
|
|
10
|
+
* Template to use for the panel.
|
|
11
|
+
*/
|
|
12
|
+
panel?: Template<{
|
|
13
|
+
elements: PanelElements;
|
|
14
|
+
indices: AutocompleteRenderState['indices'];
|
|
15
|
+
}>;
|
|
16
|
+
};
|
|
7
17
|
type IndexConfig<TItem extends BaseHit> = AutocompleteIndexConfig<TItem> & {
|
|
8
18
|
templates?: Partial<{
|
|
9
19
|
/**
|
|
@@ -20,8 +30,13 @@ type IndexConfig<TItem extends BaseHit> = AutocompleteIndexConfig<TItem> & {
|
|
|
20
30
|
onSelect: () => void;
|
|
21
31
|
}>;
|
|
22
32
|
}>;
|
|
33
|
+
/**
|
|
34
|
+
* Search parameters to apply to this index.
|
|
35
|
+
*/
|
|
36
|
+
searchParameters?: AutocompleteSearchParameters;
|
|
23
37
|
cssClasses?: Partial<AutocompleteIndexClassNames>;
|
|
24
38
|
};
|
|
39
|
+
type PanelElements = Partial<Record<'recent' | 'suggestions' | (string & {}), preact.JSX.Element>>;
|
|
25
40
|
type AutocompleteWidgetParams<TItem extends BaseHit> = {
|
|
26
41
|
/**
|
|
27
42
|
* CSS Selector or HTMLElement to insert the widget.
|
|
@@ -55,16 +70,24 @@ type AutocompleteWidgetParams<TItem extends BaseHit> = {
|
|
|
55
70
|
}>;
|
|
56
71
|
}>;
|
|
57
72
|
};
|
|
73
|
+
/**
|
|
74
|
+
* Search parameters to apply to the autocomplete indices.
|
|
75
|
+
*/
|
|
76
|
+
searchParameters?: AutocompleteSearchParameters;
|
|
58
77
|
getSearchPageURL?: (nextUiState: IndexUiState) => string;
|
|
59
78
|
onSelect?: AutocompleteIndexConfig<TItem>['onSelect'];
|
|
60
79
|
/**
|
|
61
80
|
* Templates to use for the widget.
|
|
62
81
|
*/
|
|
63
|
-
templates?: AutocompleteTemplates
|
|
82
|
+
templates?: AutocompleteTemplates;
|
|
64
83
|
/**
|
|
65
84
|
* CSS classes to add.
|
|
66
85
|
*/
|
|
67
86
|
cssClasses?: AutocompleteCSSClasses;
|
|
87
|
+
/**
|
|
88
|
+
* Placeholder text for the search input.
|
|
89
|
+
*/
|
|
90
|
+
placeholder?: string;
|
|
68
91
|
};
|
|
69
92
|
export type AutocompleteWidget<TItem extends BaseHit = BaseHit> = WidgetFactory<AutocompleteWidgetDescription & {
|
|
70
93
|
$$widgetType: 'ais.autocomplete';
|
|
@@ -19,9 +19,10 @@ import { Fragment, h, render } from 'preact';
|
|
|
19
19
|
import { useEffect, useId, useMemo, useRef, useState } from 'preact/hooks';
|
|
20
20
|
import TemplateComponent from "../../components/Template/Template.js";
|
|
21
21
|
import { connectAutocomplete, connectSearchBox } from "../../connectors/index.umd.js";
|
|
22
|
+
import { ReverseHighlight } from "../../helpers/components/index.js";
|
|
22
23
|
import { component } from "../../lib/suit.js";
|
|
23
24
|
import { prepareTemplateProps } from "../../lib/templating/index.js";
|
|
24
|
-
import { createDocumentationMessageGenerator, getContainerNode, walkIndex } from "../../lib/utils/index.js";
|
|
25
|
+
import { createDocumentationMessageGenerator, find, getContainerNode, walkIndex } from "../../lib/utils/index.js";
|
|
25
26
|
import configure from "../configure/configure.js";
|
|
26
27
|
import index from "../index/index.js";
|
|
27
28
|
var autocompleteInstanceId = 0;
|
|
@@ -83,7 +84,12 @@ var createRenderer = function createRenderer(params) {
|
|
|
83
84
|
rendererParams.renderState = {
|
|
84
85
|
indexTemplateProps: [],
|
|
85
86
|
isolatedIndex: isolatedIndex,
|
|
86
|
-
targetIndex: targetIndex
|
|
87
|
+
targetIndex: targetIndex,
|
|
88
|
+
templateProps: prepareTemplateProps({
|
|
89
|
+
defaultTemplates: {},
|
|
90
|
+
templatesConfig: connectorParams.instantSearchInstance.templatesConfig,
|
|
91
|
+
templates: rendererParams.templates
|
|
92
|
+
})
|
|
87
93
|
};
|
|
88
94
|
connectorParams.refine((_targetIndex$getHelpe = (_targetIndex$getHelpe2 = targetIndex.getHelper()) === null || _targetIndex$getHelpe2 === void 0 ? void 0 : _targetIndex$getHelpe2.state.query) !== null && _targetIndex$getHelpe !== void 0 ? _targetIndex$getHelpe : '');
|
|
89
95
|
return;
|
|
@@ -97,11 +103,14 @@ function AutocompleteWrapper(_ref) {
|
|
|
97
103
|
indices = _ref.indices,
|
|
98
104
|
getSearchPageURL = _ref.getSearchPageURL,
|
|
99
105
|
userOnSelect = _ref.onSelect,
|
|
100
|
-
|
|
106
|
+
refineAutocomplete = _ref.refine,
|
|
101
107
|
cssClasses = _ref.cssClasses,
|
|
102
108
|
renderState = _ref.renderState,
|
|
103
109
|
instantSearchInstance = _ref.instantSearchInstance,
|
|
104
|
-
showRecent = _ref.showRecent
|
|
110
|
+
showRecent = _ref.showRecent,
|
|
111
|
+
showSuggestions = _ref.showSuggestions,
|
|
112
|
+
templates = _ref.templates,
|
|
113
|
+
placeholder = _ref.placeholder;
|
|
105
114
|
var isolatedIndex = renderState.isolatedIndex,
|
|
106
115
|
targetIndex = renderState.targetIndex;
|
|
107
116
|
var searchboxQuery = isolatedIndex === null || isolatedIndex === void 0 ? void 0 : (_isolatedIndex$getHel = isolatedIndex.getHelper()) === null || _isolatedIndex$getHel === void 0 ? void 0 : _isolatedIndex$getHel.state.query;
|
|
@@ -120,6 +129,7 @@ function AutocompleteWrapper(_ref) {
|
|
|
120
129
|
return ['ais.hits', 'ais.infiniteHits'].includes($$type);
|
|
121
130
|
})) !== null && _targetIndex$getWidge !== void 0 ? _targetIndex$getWidge : false;
|
|
122
131
|
var onRefine = function onRefine(query) {
|
|
132
|
+
refineAutocomplete(query);
|
|
123
133
|
instantSearchInstance.setUiState(function (uiState) {
|
|
124
134
|
var _objectSpread2;
|
|
125
135
|
return _objectSpread(_objectSpread({}, uiState), {}, (_objectSpread2 = {}, _defineProperty(_objectSpread2, targetIndex.getIndexId(), _objectSpread(_objectSpread({}, uiState[targetIndex.getIndexId()]), {}, {
|
|
@@ -150,23 +160,35 @@ function AutocompleteWrapper(_ref) {
|
|
|
150
160
|
return;
|
|
151
161
|
}
|
|
152
162
|
setQuery(query);
|
|
153
|
-
}
|
|
163
|
+
},
|
|
164
|
+
placeholder: placeholder
|
|
154
165
|
}),
|
|
155
166
|
getInputProps = _usePropGetters.getInputProps,
|
|
156
167
|
getItemProps = _usePropGetters.getItemProps,
|
|
157
168
|
getPanelProps = _usePropGetters.getPanelProps,
|
|
158
169
|
getRootProps = _usePropGetters.getRootProps;
|
|
159
|
-
var AutocompleteRecentSearchComponent =
|
|
170
|
+
var AutocompleteRecentSearchComponent = function AutocompleteRecentSearchComponent(_ref4) {
|
|
171
|
+
var item = _ref4.item,
|
|
172
|
+
onSelect = _ref4.onSelect,
|
|
173
|
+
onRemoveRecentSearch = _ref4.onRemoveRecentSearch;
|
|
174
|
+
return h(AutocompleteRecentSearch, {
|
|
175
|
+
item: item,
|
|
176
|
+
onSelect: onSelect,
|
|
177
|
+
onRemoveRecentSearch: onRemoveRecentSearch
|
|
178
|
+
}, h(ConditionalReverseHighlight, {
|
|
179
|
+
item: item
|
|
180
|
+
}));
|
|
181
|
+
};
|
|
160
182
|
if (_typeof(showRecent) === 'object' && (_showRecent$templates = showRecent.templates) !== null && _showRecent$templates !== void 0 && _showRecent$templates.item) {
|
|
161
183
|
var props = prepareTemplateProps({
|
|
162
184
|
defaultTemplates: {},
|
|
163
185
|
templatesConfig: instantSearchInstance.templatesConfig,
|
|
164
186
|
templates: showRecent.templates
|
|
165
187
|
});
|
|
166
|
-
AutocompleteRecentSearchComponent = function AutocompleteRecentSearchComponent(
|
|
167
|
-
var item =
|
|
168
|
-
onSelect =
|
|
169
|
-
onRemoveRecentSearch =
|
|
188
|
+
AutocompleteRecentSearchComponent = function AutocompleteRecentSearchComponent(_ref5) {
|
|
189
|
+
var item = _ref5.item,
|
|
190
|
+
onSelect = _ref5.onSelect,
|
|
191
|
+
onRemoveRecentSearch = _ref5.onRemoveRecentSearch;
|
|
170
192
|
return h(TemplateComponent, _extends({}, props, {
|
|
171
193
|
templateKey: "item",
|
|
172
194
|
rootTagName: "fragment",
|
|
@@ -178,45 +200,36 @@ function AutocompleteWrapper(_ref) {
|
|
|
178
200
|
}));
|
|
179
201
|
};
|
|
180
202
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
});
|
|
208
|
-
},
|
|
209
|
-
classNames: {
|
|
210
|
-
root: 'ais-AutocompleteRecentSearches',
|
|
211
|
-
list: 'ais-AutocompleteRecentSearchesList',
|
|
212
|
-
item: 'ais-AutocompleteRecentSearchesItem'
|
|
213
|
-
},
|
|
214
|
-
items: storageHits,
|
|
215
|
-
getItemProps: getItemProps
|
|
216
|
-
}), indices.map(function (_ref6, i) {
|
|
203
|
+
var elements = {};
|
|
204
|
+
if (showRecent) {
|
|
205
|
+
elements.recent = h(AutocompleteIndex
|
|
206
|
+
// @ts-ignore - there seems to be problems with React.ComponentType and this, but it's actually correct
|
|
207
|
+
, {
|
|
208
|
+
ItemComponent: function ItemComponent(_ref6) {
|
|
209
|
+
var item = _ref6.item,
|
|
210
|
+
onSelect = _ref6.onSelect;
|
|
211
|
+
return h(AutocompleteRecentSearchComponent, {
|
|
212
|
+
item: item,
|
|
213
|
+
onSelect: onSelect,
|
|
214
|
+
onRemoveRecentSearch: function onRemoveRecentSearch() {
|
|
215
|
+
return storage.onRemove(item.query);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
},
|
|
219
|
+
classNames: {
|
|
220
|
+
root: 'ais-AutocompleteRecentSearches',
|
|
221
|
+
list: 'ais-AutocompleteRecentSearchesList',
|
|
222
|
+
item: 'ais-AutocompleteRecentSearchesItem'
|
|
223
|
+
},
|
|
224
|
+
items: storageHits,
|
|
225
|
+
getItemProps: getItemProps
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
indices.forEach(function (_ref7, i) {
|
|
217
229
|
var _indicesConfig$i$temp;
|
|
218
|
-
var indexId =
|
|
219
|
-
|
|
230
|
+
var indexId = _ref7.indexId,
|
|
231
|
+
indexName = _ref7.indexName,
|
|
232
|
+
hits = _ref7.hits;
|
|
220
233
|
if (!renderState.indexTemplateProps[i]) {
|
|
221
234
|
renderState.indexTemplateProps[i] = prepareTemplateProps({
|
|
222
235
|
defaultTemplates: {},
|
|
@@ -224,8 +237,8 @@ function AutocompleteWrapper(_ref) {
|
|
|
224
237
|
templates: indicesConfig[i].templates
|
|
225
238
|
});
|
|
226
239
|
}
|
|
227
|
-
var headerComponent = (_indicesConfig$i$temp = indicesConfig[i].templates) !== null && _indicesConfig$i$temp !== void 0 && _indicesConfig$i$temp.header ? function (
|
|
228
|
-
var items =
|
|
240
|
+
var headerComponent = (_indicesConfig$i$temp = indicesConfig[i].templates) !== null && _indicesConfig$i$temp !== void 0 && _indicesConfig$i$temp.header ? function (_ref8) {
|
|
241
|
+
var items = _ref8.items;
|
|
229
242
|
return h(TemplateComponent, _extends({}, renderState.indexTemplateProps[i], {
|
|
230
243
|
templateKey: "header",
|
|
231
244
|
rootTagName: "fragment",
|
|
@@ -234,9 +247,9 @@ function AutocompleteWrapper(_ref) {
|
|
|
234
247
|
}
|
|
235
248
|
}));
|
|
236
249
|
} : undefined;
|
|
237
|
-
var itemComponent = function itemComponent(
|
|
238
|
-
var item =
|
|
239
|
-
onSelect =
|
|
250
|
+
var itemComponent = function itemComponent(_ref9) {
|
|
251
|
+
var item = _ref9.item,
|
|
252
|
+
onSelect = _ref9.onSelect;
|
|
240
253
|
return h(TemplateComponent, _extends({}, renderState.indexTemplateProps[i], {
|
|
241
254
|
templateKey: "item",
|
|
242
255
|
rootTagName: "fragment",
|
|
@@ -246,11 +259,17 @@ function AutocompleteWrapper(_ref) {
|
|
|
246
259
|
}
|
|
247
260
|
}));
|
|
248
261
|
};
|
|
249
|
-
|
|
262
|
+
var elementId = indexName === (showSuggestions === null || showSuggestions === void 0 ? void 0 : showSuggestions.indexName) ? 'suggestions' : indexName;
|
|
263
|
+
var filteredHits = elementId === 'suggestions' && showRecent ? hits.filter(function (suggestionHit) {
|
|
264
|
+
return !find(storageHits, function (storageHit) {
|
|
265
|
+
return storageHit.query === suggestionHit.query;
|
|
266
|
+
});
|
|
267
|
+
}) : hits;
|
|
268
|
+
elements[elementId] = h(AutocompleteIndex, {
|
|
250
269
|
key: indexId,
|
|
251
270
|
HeaderComponent: headerComponent,
|
|
252
271
|
ItemComponent: itemComponent,
|
|
253
|
-
items:
|
|
272
|
+
items: filteredHits.map(function (item) {
|
|
254
273
|
return _objectSpread(_objectSpread({}, item), {}, {
|
|
255
274
|
__indexName: indexId
|
|
256
275
|
});
|
|
@@ -258,26 +277,55 @@ function AutocompleteWrapper(_ref) {
|
|
|
258
277
|
getItemProps: getItemProps,
|
|
259
278
|
classNames: indicesConfig[i].cssClasses
|
|
260
279
|
});
|
|
280
|
+
});
|
|
281
|
+
return h(Autocomplete, _extends({}, getRootProps(), {
|
|
282
|
+
classNames: cssClasses
|
|
283
|
+
}), h(AutocompleteSearchBox, {
|
|
284
|
+
query: searchboxQuery || '',
|
|
285
|
+
inputProps: _objectSpread(_objectSpread({}, getInputProps()), {}, {
|
|
286
|
+
// @ts-ignore - This clashes with some ambient React JSX declarations.
|
|
287
|
+
onInput: function onInput(evt) {
|
|
288
|
+
return refineAutocomplete(evt.currentTarget.value);
|
|
289
|
+
}
|
|
290
|
+
}),
|
|
291
|
+
onClear: function onClear() {
|
|
292
|
+
onRefine('');
|
|
293
|
+
},
|
|
294
|
+
isSearchStalled: instantSearchInstance.status === 'stalled'
|
|
295
|
+
}), h(AutocompletePanel, getPanelProps(), templates.panel ? h(TemplateComponent, _extends({}, renderState.templateProps, {
|
|
296
|
+
templateKey: "panel",
|
|
297
|
+
rootTagName: "fragment",
|
|
298
|
+
data: {
|
|
299
|
+
elements: elements,
|
|
300
|
+
indices: indices
|
|
301
|
+
}
|
|
302
|
+
})) : Object.keys(elements).map(function (elementId) {
|
|
303
|
+
return elements[elementId];
|
|
261
304
|
})));
|
|
262
305
|
}
|
|
263
306
|
export function EXPERIMENTAL_autocomplete(widgetParams) {
|
|
264
|
-
var
|
|
265
|
-
container =
|
|
266
|
-
escapeHTML =
|
|
267
|
-
|
|
268
|
-
indices =
|
|
269
|
-
showSuggestions =
|
|
270
|
-
showRecent =
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
templates =
|
|
275
|
-
|
|
276
|
-
|
|
307
|
+
var _ref0 = widgetParams || {},
|
|
308
|
+
container = _ref0.container,
|
|
309
|
+
escapeHTML = _ref0.escapeHTML,
|
|
310
|
+
_ref0$indices = _ref0.indices,
|
|
311
|
+
indices = _ref0$indices === void 0 ? [] : _ref0$indices,
|
|
312
|
+
showSuggestions = _ref0.showSuggestions,
|
|
313
|
+
showRecent = _ref0.showRecent,
|
|
314
|
+
userSearchParameters = _ref0.searchParameters,
|
|
315
|
+
getSearchPageURL = _ref0.getSearchPageURL,
|
|
316
|
+
onSelect = _ref0.onSelect,
|
|
317
|
+
_ref0$templates = _ref0.templates,
|
|
318
|
+
templates = _ref0$templates === void 0 ? {} : _ref0$templates,
|
|
319
|
+
_ref0$cssClasses = _ref0.cssClasses,
|
|
320
|
+
userCssClasses = _ref0$cssClasses === void 0 ? {} : _ref0$cssClasses,
|
|
321
|
+
placeholder = _ref0.placeholder;
|
|
277
322
|
if (!container) {
|
|
278
323
|
throw new Error(withUsage('The `container` option is required.'));
|
|
279
324
|
}
|
|
280
325
|
var containerNode = getContainerNode(container);
|
|
326
|
+
var searchParameters = _objectSpread({
|
|
327
|
+
hitsPerPage: 5
|
|
328
|
+
}, userSearchParameters);
|
|
281
329
|
var cssClasses = {
|
|
282
330
|
root: cx(suit(), userCssClasses.root)
|
|
283
331
|
};
|
|
@@ -288,7 +336,16 @@ export function EXPERIMENTAL_autocomplete(widgetParams) {
|
|
|
288
336
|
indexName: showSuggestions.indexName,
|
|
289
337
|
templates: _objectSpread({
|
|
290
338
|
// @ts-expect-error
|
|
291
|
-
item:
|
|
339
|
+
item: function item(_ref1) {
|
|
340
|
+
var _item = _ref1.item,
|
|
341
|
+
onSelectItem = _ref1.onSelect;
|
|
342
|
+
return h(AutocompleteSuggestion, {
|
|
343
|
+
item: _item,
|
|
344
|
+
onSelect: onSelectItem
|
|
345
|
+
}, h(ConditionalReverseHighlight, {
|
|
346
|
+
item: _item
|
|
347
|
+
}));
|
|
348
|
+
}
|
|
292
349
|
}, showSuggestions.templates),
|
|
293
350
|
cssClasses: {
|
|
294
351
|
root: cx('ais-AutocompleteSuggestions', (_showSuggestions$cssC = showSuggestions.cssClasses) === null || _showSuggestions$cssC === void 0 ? void 0 : _showSuggestions$cssC.root),
|
|
@@ -311,10 +368,13 @@ export function EXPERIMENTAL_autocomplete(widgetParams) {
|
|
|
311
368
|
onSelect: onSelect,
|
|
312
369
|
cssClasses: cssClasses,
|
|
313
370
|
showRecent: showRecent,
|
|
371
|
+
showSuggestions: showSuggestions,
|
|
372
|
+
placeholder: placeholder,
|
|
314
373
|
renderState: {
|
|
315
374
|
indexTemplateProps: [],
|
|
316
375
|
isolatedIndex: undefined,
|
|
317
|
-
targetIndex: undefined
|
|
376
|
+
targetIndex: undefined,
|
|
377
|
+
templateProps: undefined
|
|
318
378
|
},
|
|
319
379
|
templates: templates
|
|
320
380
|
});
|
|
@@ -326,17 +386,29 @@ export function EXPERIMENTAL_autocomplete(widgetParams) {
|
|
|
326
386
|
})({}), index({
|
|
327
387
|
indexId: "ais-autocomplete-".concat(instanceId),
|
|
328
388
|
EXPERIMENTAL_isolated: true
|
|
329
|
-
}).addWidgets([].concat(_toConsumableArray(indicesConfig.map(function (
|
|
330
|
-
var indexName =
|
|
389
|
+
}).addWidgets([configure(searchParameters)].concat(_toConsumableArray(indicesConfig.map(function (_ref10) {
|
|
390
|
+
var indexName = _ref10.indexName,
|
|
391
|
+
indexSearchParameters = _ref10.searchParameters;
|
|
331
392
|
return index({
|
|
332
393
|
indexName: indexName,
|
|
333
394
|
indexId: indexName
|
|
334
|
-
}).addWidgets([configure({
|
|
335
|
-
hitsPerPage: 5
|
|
336
|
-
})]);
|
|
395
|
+
}).addWidgets([configure(indexSearchParameters || {})]);
|
|
337
396
|
})), [_objectSpread(_objectSpread({}, makeWidget({
|
|
338
397
|
escapeHTML: escapeHTML
|
|
339
398
|
})), {}, {
|
|
340
399
|
$$widgetType: 'ais.autocomplete'
|
|
341
400
|
})]))];
|
|
401
|
+
}
|
|
402
|
+
function ConditionalReverseHighlight(_ref11) {
|
|
403
|
+
var _item$_highlightResul;
|
|
404
|
+
var item = _ref11.item;
|
|
405
|
+
if (!((_item$_highlightResul = item._highlightResult) !== null && _item$_highlightResul !== void 0 && _item$_highlightResul.query) ||
|
|
406
|
+
// @ts-expect-error - we should not have matchLevel as arrays here
|
|
407
|
+
item._highlightResult.query.matchLevel === 'none') {
|
|
408
|
+
return item.query;
|
|
409
|
+
}
|
|
410
|
+
return h(ReverseHighlight, {
|
|
411
|
+
attribute: "query",
|
|
412
|
+
hit: item
|
|
413
|
+
});
|
|
342
414
|
}
|
package/es/widgets/chat/chat.js
CHANGED
|
@@ -14,7 +14,7 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
|
|
|
14
14
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
15
15
|
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; } }
|
|
16
16
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
17
|
-
import {
|
|
17
|
+
import { ArrowRightIcon, ChevronLeftIcon, ChevronRightIcon, createButtonComponent, createChatComponent } from 'instantsearch-ui-components';
|
|
18
18
|
import { Fragment, h, render } from 'preact';
|
|
19
19
|
import { useMemo } from 'preact/hooks';
|
|
20
20
|
import TemplateComponent from "../../components/Template/Template.js";
|
|
@@ -39,13 +39,13 @@ function getDefinedProperties(obj) {
|
|
|
39
39
|
return value !== undefined;
|
|
40
40
|
}));
|
|
41
41
|
}
|
|
42
|
-
var _ref6 = h(
|
|
42
|
+
var _ref6 = h(ArrowRightIcon, {
|
|
43
43
|
createElement: h
|
|
44
44
|
});
|
|
45
|
-
var _ref7 = h(
|
|
45
|
+
var _ref7 = h(ChevronLeftIcon, {
|
|
46
46
|
createElement: h
|
|
47
47
|
});
|
|
48
|
-
var _ref8 = h(
|
|
48
|
+
var _ref8 = h(ChevronRightIcon, {
|
|
49
49
|
createElement: h
|
|
50
50
|
});
|
|
51
51
|
function createCarouselTool(showViewAll, templates, getSearchPageURL) {
|
|
@@ -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
|
-
|
|
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
|
-
|
|
346
|
-
(_helper3 = helper) === null || _helper3 === void 0 ? void 0 : _helper3.search();
|
|
350
|
+
this.scheduleLocalSearch();
|
|
347
351
|
} else {
|
|
348
352
|
localInstantSearchInstance.scheduleSearch();
|
|
349
353
|
}
|
|
@@ -597,7 +601,7 @@ var index = function index(widgetParams) {
|
|
|
597
601
|
},
|
|
598
602
|
dispose: function dispose() {
|
|
599
603
|
var _this5 = this,
|
|
600
|
-
|
|
604
|
+
_helper3,
|
|
601
605
|
_derivedHelper3;
|
|
602
606
|
localWidgets.forEach(function (widget) {
|
|
603
607
|
if (widget.dispose && helper) {
|
|
@@ -617,7 +621,7 @@ var index = function index(widgetParams) {
|
|
|
617
621
|
});
|
|
618
622
|
localInstantSearchInstance = null;
|
|
619
623
|
localParent = null;
|
|
620
|
-
(
|
|
624
|
+
(_helper3 = helper) === null || _helper3 === void 0 ? void 0 : _helper3.removeAllListeners();
|
|
621
625
|
helper = null;
|
|
622
626
|
(_derivedHelper3 = derivedHelper) === null || _derivedHelper3 === void 0 ? void 0 : _derivedHelper3.detach();
|
|
623
627
|
derivedHelper = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "instantsearch.js",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.85.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",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"algoliasearch-helper": "3.26.1",
|
|
36
36
|
"hogan.js": "^3.0.2",
|
|
37
37
|
"htm": "^3.0.0",
|
|
38
|
-
"instantsearch-ui-components": "0.
|
|
38
|
+
"instantsearch-ui-components": "0.15.1",
|
|
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.
|
|
64
|
-
"@instantsearch/tests": "1.
|
|
65
|
-
"@instantsearch/testutils": "1.
|
|
63
|
+
"@instantsearch/mocks": "1.83.0",
|
|
64
|
+
"@instantsearch/tests": "1.83.0",
|
|
65
|
+
"@instantsearch/testutils": "1.72.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": "
|
|
73
|
+
"gitHead": "417c7fb9ebaa31063d7a817466a303ce51558453"
|
|
74
74
|
}
|