@docsearch/react 3.0.0-alpha.39 → 3.0.0-alpha.50
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/README.md +30 -4
- package/dist/esm/AlgoliaLogo.d.ts +8 -1
- package/dist/esm/AlgoliaLogo.js +7 -3
- package/dist/esm/DocSearch.d.ts +20 -10
- package/dist/esm/DocSearch.js +8 -4
- package/dist/esm/DocSearchButton.d.ts +3 -4
- package/dist/esm/DocSearchButton.js +3 -1
- package/dist/esm/DocSearchModal.d.ts +13 -5
- package/dist/esm/DocSearchModal.js +57 -40
- package/dist/esm/ErrorScreen.d.ts +9 -1
- package/dist/esm/ErrorScreen.js +9 -3
- package/dist/esm/Footer.d.ts +11 -1
- package/dist/esm/Footer.js +33 -18
- package/dist/esm/Hit.d.ts +2 -2
- package/dist/esm/NoResultsScreen.d.ts +12 -4
- package/dist/esm/NoResultsScreen.js +29 -8
- package/dist/esm/Results.d.ts +8 -8
- package/dist/esm/Results.js +1 -1
- package/dist/esm/ResultsScreen.d.ts +3 -3
- package/dist/esm/ResultsScreen.js +2 -2
- package/dist/esm/ScreenState.d.ts +17 -7
- package/dist/esm/ScreenState.js +19 -4
- package/dist/esm/SearchBox.d.ts +13 -5
- package/dist/esm/SearchBox.js +25 -3
- package/dist/esm/Snippet.d.ts +2 -2
- package/dist/esm/Snippet.js +8 -5
- package/dist/esm/StartScreen.d.ts +14 -5
- package/dist/esm/StartScreen.js +40 -14
- package/dist/esm/__tests__/api.test.js +336 -0
- package/dist/esm/icons/SourceIcon.js +14 -13
- package/dist/esm/stored-searches.d.ts +4 -4
- package/dist/esm/stored-searches.js +3 -1
- package/dist/esm/types/DocSearchHit.d.ts +2 -2
- package/dist/esm/types/DocSearchHit.js +1 -0
- package/dist/esm/types/InternalDocSearchHit.d.ts +2 -2
- package/dist/esm/types/InternalDocSearchHit.js +1 -0
- package/dist/esm/types/StoredDocSearchHit.d.ts +1 -1
- package/dist/esm/types/StoredDocSearchHit.js +1 -0
- package/dist/esm/useDocSearchKeyboardEvents.d.ts +3 -3
- package/dist/esm/useSearchClient.d.ts +1 -1
- package/dist/esm/useTouchEvents.d.ts +1 -1
- package/dist/esm/utils/groupBy.d.ts +1 -1
- package/dist/esm/utils/removeHighlightTags.d.ts +1 -1
- package/dist/esm/utils/removeHighlightTags.js +6 -2
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/index.js +2 -2
- package/dist/umd/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
|
+
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
|
|
5
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
+
|
|
7
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
8
|
+
|
|
9
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
10
|
+
|
|
11
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
12
|
+
|
|
13
|
+
import { render, fireEvent, waitFor, screen, act } from '@testing-library/react';
|
|
14
|
+
import React from 'react';
|
|
15
|
+
import '@testing-library/jest-dom';
|
|
16
|
+
import { DocSearch as DocSearchComponent } from '../DocSearch';
|
|
17
|
+
|
|
18
|
+
function DocSearch(props) {
|
|
19
|
+
return /*#__PURE__*/React.createElement(DocSearchComponent, _extends({
|
|
20
|
+
apiKey: "foo",
|
|
21
|
+
indexName: "bar"
|
|
22
|
+
}, props));
|
|
23
|
+
} // mock empty response
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
function noResultSearch(_queries, _requestOptions) {
|
|
27
|
+
return new Promise(function (resolve) {
|
|
28
|
+
resolve({
|
|
29
|
+
results: [{
|
|
30
|
+
hits: [],
|
|
31
|
+
hitsPerPage: 0,
|
|
32
|
+
nbHits: 0,
|
|
33
|
+
nbPages: 0,
|
|
34
|
+
page: 0,
|
|
35
|
+
processingTimeMS: 0,
|
|
36
|
+
exhaustiveNbHits: true,
|
|
37
|
+
params: '',
|
|
38
|
+
query: ''
|
|
39
|
+
}]
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
describe('api', function () {
|
|
45
|
+
beforeEach(function () {
|
|
46
|
+
document.body.innerHTML = '';
|
|
47
|
+
});
|
|
48
|
+
it('renders with minimal parameters', function () {
|
|
49
|
+
render( /*#__PURE__*/React.createElement(DocSearch, null));
|
|
50
|
+
expect(document.querySelector('.DocSearch')).toBeInTheDocument();
|
|
51
|
+
});
|
|
52
|
+
describe('translations', function () {
|
|
53
|
+
it('overrides the default DocSearchButton text', function () {
|
|
54
|
+
render( /*#__PURE__*/React.createElement(DocSearch, {
|
|
55
|
+
translations: {
|
|
56
|
+
button: {
|
|
57
|
+
buttonText: 'Recherche',
|
|
58
|
+
buttonAriaLabel: 'Recherche'
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}));
|
|
62
|
+
expect(document.querySelector('.DocSearch-Button-Placeholder').innerHTML).toBe('Recherche');
|
|
63
|
+
expect(document.querySelector('.DocSearch-Button').getAttribute('aria-label')).toBe('Recherche');
|
|
64
|
+
});
|
|
65
|
+
it('overrides the default DocSearchModal startScreen text', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
66
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
67
|
+
while (1) {
|
|
68
|
+
switch (_context.prev = _context.next) {
|
|
69
|
+
case 0:
|
|
70
|
+
render( /*#__PURE__*/React.createElement(DocSearch, {
|
|
71
|
+
translations: {
|
|
72
|
+
modal: {
|
|
73
|
+
startScreen: {
|
|
74
|
+
noRecentSearchesText: 'Pas de recherche récentes'
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}));
|
|
79
|
+
_context.next = 3;
|
|
80
|
+
return waitFor(function () {
|
|
81
|
+
fireEvent.click(document.querySelector('.DocSearch-Button'));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
case 3:
|
|
85
|
+
expect(screen.getByText('Pas de recherche récentes')).toBeInTheDocument();
|
|
86
|
+
|
|
87
|
+
case 4:
|
|
88
|
+
case "end":
|
|
89
|
+
return _context.stop();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}, _callee);
|
|
93
|
+
})));
|
|
94
|
+
it('overrides the default DocSearchModal noResultsScreen text', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
|
|
95
|
+
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
96
|
+
while (1) {
|
|
97
|
+
switch (_context3.prev = _context3.next) {
|
|
98
|
+
case 0:
|
|
99
|
+
render( /*#__PURE__*/React.createElement(DocSearch, {
|
|
100
|
+
transformSearchClient: function transformSearchClient(searchClient) {
|
|
101
|
+
return _objectSpread(_objectSpread({}, searchClient), {}, {
|
|
102
|
+
search: noResultSearch
|
|
103
|
+
});
|
|
104
|
+
},
|
|
105
|
+
translations: {
|
|
106
|
+
modal: {
|
|
107
|
+
noResultsScreen: {
|
|
108
|
+
noResultsText: 'Pas de résultats pour',
|
|
109
|
+
reportMissingResultsText: 'Ouvrez une issue sur docsearch-configs',
|
|
110
|
+
reportMissingResultsLinkText: 'Lien du repo'
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
getMissingResultsUrl: function getMissingResultsUrl() {
|
|
115
|
+
return 'algolia.com';
|
|
116
|
+
}
|
|
117
|
+
}));
|
|
118
|
+
_context3.next = 3;
|
|
119
|
+
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
|
|
120
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
121
|
+
while (1) {
|
|
122
|
+
switch (_context2.prev = _context2.next) {
|
|
123
|
+
case 0:
|
|
124
|
+
_context2.next = 2;
|
|
125
|
+
return waitFor(function () {
|
|
126
|
+
fireEvent.click(document.querySelector('.DocSearch-Button'));
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
case 2:
|
|
130
|
+
fireEvent.input(document.querySelector('.DocSearch-Input'), {
|
|
131
|
+
target: {
|
|
132
|
+
value: 'q'
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
case 3:
|
|
137
|
+
case "end":
|
|
138
|
+
return _context2.stop();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}, _callee2);
|
|
142
|
+
})));
|
|
143
|
+
|
|
144
|
+
case 3:
|
|
145
|
+
expect(screen.getByText(/Pas de résultats pour/)).toBeInTheDocument();
|
|
146
|
+
expect(screen.getByText(/Ouvrez une issue sur docsearch-configs/)).toBeInTheDocument();
|
|
147
|
+
expect(screen.getByRole('link', {
|
|
148
|
+
name: 'Lien du repo'
|
|
149
|
+
})).toBeInTheDocument();
|
|
150
|
+
|
|
151
|
+
case 6:
|
|
152
|
+
case "end":
|
|
153
|
+
return _context3.stop();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}, _callee3);
|
|
157
|
+
})));
|
|
158
|
+
it('overrides the default DocSearchModal searchbox text', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
|
|
159
|
+
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
160
|
+
while (1) {
|
|
161
|
+
switch (_context4.prev = _context4.next) {
|
|
162
|
+
case 0:
|
|
163
|
+
render( /*#__PURE__*/React.createElement(DocSearch, {
|
|
164
|
+
translations: {
|
|
165
|
+
modal: {
|
|
166
|
+
searchBox: {
|
|
167
|
+
resetButtonTitle: 'Effacer',
|
|
168
|
+
resetButtonAriaLabel: 'Effacer',
|
|
169
|
+
cancelButtonText: 'Annuler',
|
|
170
|
+
cancelButtonAriaLabel: 'Annuler'
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}));
|
|
175
|
+
_context4.next = 3;
|
|
176
|
+
return waitFor(function () {
|
|
177
|
+
fireEvent.click(document.querySelector('.DocSearch-Button'));
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
case 3:
|
|
181
|
+
expect(document.querySelector('.DocSearch-Cancel').innerHTML).toBe('Annuler');
|
|
182
|
+
expect(document.querySelector('.DocSearch-Cancel').getAttribute('aria-label')).toBe('Annuler');
|
|
183
|
+
expect(document.querySelector('.DocSearch-Reset').getAttribute('title')).toBe('Effacer');
|
|
184
|
+
expect(document.querySelector('.DocSearch-Reset').getAttribute('aria-label')).toBe('Effacer');
|
|
185
|
+
|
|
186
|
+
case 7:
|
|
187
|
+
case "end":
|
|
188
|
+
return _context4.stop();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}, _callee4);
|
|
192
|
+
})));
|
|
193
|
+
it('overrides the default DocSearchModal footer text', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
|
|
194
|
+
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
195
|
+
while (1) {
|
|
196
|
+
switch (_context5.prev = _context5.next) {
|
|
197
|
+
case 0:
|
|
198
|
+
render( /*#__PURE__*/React.createElement(DocSearch, {
|
|
199
|
+
translations: {
|
|
200
|
+
modal: {
|
|
201
|
+
footer: {
|
|
202
|
+
closeText: 'Fermer',
|
|
203
|
+
navigateText: 'Naviguer',
|
|
204
|
+
searchByText: 'Recherche par',
|
|
205
|
+
selectText: 'Selectionner'
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}));
|
|
210
|
+
_context5.next = 3;
|
|
211
|
+
return waitFor(function () {
|
|
212
|
+
fireEvent.click(document.querySelector('.DocSearch-Button'));
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
case 3:
|
|
216
|
+
expect(screen.getByText('Recherche par')).toBeInTheDocument();
|
|
217
|
+
expect(screen.getByText('Fermer')).toBeInTheDocument();
|
|
218
|
+
expect(screen.getByText('Naviguer')).toBeInTheDocument();
|
|
219
|
+
expect(screen.getByText('Selectionner')).toBeInTheDocument();
|
|
220
|
+
|
|
221
|
+
case 7:
|
|
222
|
+
case "end":
|
|
223
|
+
return _context5.stop();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}, _callee5);
|
|
227
|
+
})));
|
|
228
|
+
});
|
|
229
|
+
describe('getMissingResultsUrl', function () {
|
|
230
|
+
it('does not render the link to the repository by default', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() {
|
|
231
|
+
return regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
232
|
+
while (1) {
|
|
233
|
+
switch (_context7.prev = _context7.next) {
|
|
234
|
+
case 0:
|
|
235
|
+
render( /*#__PURE__*/React.createElement(DocSearch, {
|
|
236
|
+
transformSearchClient: function transformSearchClient(searchClient) {
|
|
237
|
+
return _objectSpread(_objectSpread({}, searchClient), {}, {
|
|
238
|
+
search: noResultSearch
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}));
|
|
242
|
+
_context7.next = 3;
|
|
243
|
+
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
|
|
244
|
+
return regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
245
|
+
while (1) {
|
|
246
|
+
switch (_context6.prev = _context6.next) {
|
|
247
|
+
case 0:
|
|
248
|
+
_context6.next = 2;
|
|
249
|
+
return waitFor(function () {
|
|
250
|
+
fireEvent.click(document.querySelector('.DocSearch-Button'));
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
case 2:
|
|
254
|
+
fireEvent.input(document.querySelector('.DocSearch-Input'), {
|
|
255
|
+
target: {
|
|
256
|
+
value: 'q'
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
case 3:
|
|
261
|
+
case "end":
|
|
262
|
+
return _context6.stop();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}, _callee6);
|
|
266
|
+
})));
|
|
267
|
+
|
|
268
|
+
case 3:
|
|
269
|
+
expect(screen.getByText(/No results for/)).toBeInTheDocument();
|
|
270
|
+
expect(document.querySelector('.DocSearch-Help a')).not.toBeInTheDocument();
|
|
271
|
+
|
|
272
|
+
case 5:
|
|
273
|
+
case "end":
|
|
274
|
+
return _context7.stop();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}, _callee7);
|
|
278
|
+
})));
|
|
279
|
+
it('render the link to the repository', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() {
|
|
280
|
+
var link;
|
|
281
|
+
return regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
282
|
+
while (1) {
|
|
283
|
+
switch (_context9.prev = _context9.next) {
|
|
284
|
+
case 0:
|
|
285
|
+
render( /*#__PURE__*/React.createElement(DocSearch, {
|
|
286
|
+
transformSearchClient: function transformSearchClient(searchClient) {
|
|
287
|
+
return _objectSpread(_objectSpread({}, searchClient), {}, {
|
|
288
|
+
search: noResultSearch
|
|
289
|
+
});
|
|
290
|
+
},
|
|
291
|
+
getMissingResultsUrl: function getMissingResultsUrl(_ref9) {
|
|
292
|
+
var query = _ref9.query;
|
|
293
|
+
return "https://github.com/algolia/docsearch/issues/new?title=".concat(query);
|
|
294
|
+
}
|
|
295
|
+
}));
|
|
296
|
+
_context9.next = 3;
|
|
297
|
+
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
|
|
298
|
+
return regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
299
|
+
while (1) {
|
|
300
|
+
switch (_context8.prev = _context8.next) {
|
|
301
|
+
case 0:
|
|
302
|
+
_context8.next = 2;
|
|
303
|
+
return waitFor(function () {
|
|
304
|
+
fireEvent.click(document.querySelector('.DocSearch-Button'));
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
case 2:
|
|
308
|
+
fireEvent.input(document.querySelector('.DocSearch-Input'), {
|
|
309
|
+
target: {
|
|
310
|
+
value: 'q'
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
case 3:
|
|
315
|
+
case "end":
|
|
316
|
+
return _context8.stop();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}, _callee8);
|
|
320
|
+
})));
|
|
321
|
+
|
|
322
|
+
case 3:
|
|
323
|
+
expect(screen.getByText(/No results for/)).toBeInTheDocument();
|
|
324
|
+
link = document.querySelector('.DocSearch-Help a');
|
|
325
|
+
expect(link).toBeInTheDocument();
|
|
326
|
+
expect(link.getAttribute('href')).toBe('https://github.com/algolia/docsearch/issues/new?title=q');
|
|
327
|
+
|
|
328
|
+
case 7:
|
|
329
|
+
case "end":
|
|
330
|
+
return _context9.stop();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
}, _callee9);
|
|
334
|
+
})));
|
|
335
|
+
});
|
|
336
|
+
});
|
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
export function SourceIcon(props) {
|
|
3
|
-
switch (props.type) {
|
|
4
|
-
case 'lvl1':
|
|
5
|
-
return /*#__PURE__*/React.createElement(LvlIcon, null);
|
|
6
|
-
|
|
7
|
-
case 'content':
|
|
8
|
-
return /*#__PURE__*/React.createElement(ContentIcon, null);
|
|
9
|
-
|
|
10
|
-
default:
|
|
11
|
-
return /*#__PURE__*/React.createElement(AnchorIcon, null);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
2
|
|
|
15
|
-
function LvlIcon() {
|
|
3
|
+
var LvlIcon = function LvlIcon() {
|
|
16
4
|
return /*#__PURE__*/React.createElement("svg", {
|
|
17
5
|
width: "20",
|
|
18
6
|
height: "20",
|
|
@@ -24,6 +12,19 @@ function LvlIcon() {
|
|
|
24
12
|
fillRule: "evenodd",
|
|
25
13
|
strokeLinejoin: "round"
|
|
26
14
|
}));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function SourceIcon(props) {
|
|
18
|
+
switch (props.type) {
|
|
19
|
+
case 'lvl1':
|
|
20
|
+
return /*#__PURE__*/React.createElement(LvlIcon, null);
|
|
21
|
+
|
|
22
|
+
case 'content':
|
|
23
|
+
return /*#__PURE__*/React.createElement(ContentIcon, null);
|
|
24
|
+
|
|
25
|
+
default:
|
|
26
|
+
return /*#__PURE__*/React.createElement(AnchorIcon, null);
|
|
27
|
+
}
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
function AnchorIcon() {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { StoredDocSearchHit } from './types';
|
|
1
|
+
import type { StoredDocSearchHit } from './types';
|
|
2
2
|
declare type CreateStoredSearchesOptions = {
|
|
3
3
|
key: string;
|
|
4
4
|
limit?: number;
|
|
5
5
|
};
|
|
6
6
|
export declare type StoredSearchPlugin<TItem> = {
|
|
7
|
-
add(item: TItem)
|
|
8
|
-
remove(item: TItem)
|
|
9
|
-
getAll()
|
|
7
|
+
add: (item: TItem) => void;
|
|
8
|
+
remove: (item: TItem) => void;
|
|
9
|
+
getAll: () => TItem[];
|
|
10
10
|
};
|
|
11
11
|
export declare function createStoredSearches<TItem extends StoredDocSearchHit>({ key, limit, }: CreateStoredSearchesOptions): StoredSearchPlugin<TItem>;
|
|
12
12
|
export {};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var _excluded = ["_highlightResult", "_snippetResult"];
|
|
2
|
+
|
|
1
3
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
2
4
|
|
|
3
5
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
@@ -46,7 +48,7 @@ export function createStoredSearches(_ref) {
|
|
|
46
48
|
var _ref2 = item,
|
|
47
49
|
_highlightResult = _ref2._highlightResult,
|
|
48
50
|
_snippetResult = _ref2._snippetResult,
|
|
49
|
-
hit = _objectWithoutProperties(_ref2,
|
|
51
|
+
hit = _objectWithoutProperties(_ref2, _excluded);
|
|
50
52
|
|
|
51
53
|
var isQueryAlreadySaved = items.findIndex(function (x) {
|
|
52
54
|
return x.objectID === hit.objectID;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
declare type ContentType = 'content' | 'lvl0' | 'lvl1' | 'lvl2' | 'lvl3' | 'lvl4' | 'lvl5' | 'lvl6';
|
|
2
2
|
interface DocSearchHitAttributeHighlightResult {
|
|
3
3
|
value: string;
|
|
4
|
-
matchLevel: '
|
|
4
|
+
matchLevel: 'full' | 'none' | 'partial';
|
|
5
5
|
matchedWords: string[];
|
|
6
6
|
fullyHighlighted?: boolean;
|
|
7
7
|
}
|
|
@@ -21,7 +21,7 @@ interface DocSearchHitHighlightResult {
|
|
|
21
21
|
}
|
|
22
22
|
interface DocSearchHitAttributeSnippetResult {
|
|
23
23
|
value: string;
|
|
24
|
-
matchLevel: '
|
|
24
|
+
matchLevel: 'full' | 'none' | 'partial';
|
|
25
25
|
}
|
|
26
26
|
interface DocSearchHitSnippetResult {
|
|
27
27
|
content: DocSearchHitAttributeSnippetResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DocSearchHit } from './DocSearchHit';
|
|
1
|
+
import type { DocSearchHit } from './DocSearchHit';
|
|
2
2
|
export declare type StoredDocSearchHit = Omit<DocSearchHit, '_highlightResult' | '_snippetResult'>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
export interface UseDocSearchKeyboardEventsProps {
|
|
3
3
|
isOpen: boolean;
|
|
4
|
-
onOpen()
|
|
5
|
-
onClose()
|
|
6
|
-
onInput
|
|
4
|
+
onOpen: () => void;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
onInput?: (event: KeyboardEvent) => void;
|
|
7
7
|
searchButtonRef?: React.RefObject<HTMLButtonElement>;
|
|
8
8
|
}
|
|
9
9
|
export declare function useDocSearchKeyboardEvents({ isOpen, onOpen, onClose, onInput, searchButtonRef, }: UseDocSearchKeyboardEventsProps): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SearchClient } from 'algoliasearch/lite';
|
|
1
|
+
import type { SearchClient } from 'algoliasearch/lite';
|
|
2
2
|
export declare function useSearchClient(appId: string, apiKey: string, transformSearchClient: (searchClient: SearchClient) => SearchClient): SearchClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function groupBy<TValue extends
|
|
1
|
+
export declare function groupBy<TValue extends Record<string, unknown>>(values: TValue[], predicate: (value: TValue) => string): Record<string, TValue[]>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DocSearchHit, InternalDocSearchHit } from '
|
|
1
|
+
import type { DocSearchHit, InternalDocSearchHit } from '../types';
|
|
2
2
|
export declare function removeHighlightTags(hit: DocSearchHit | InternalDocSearchHit): string;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
var regexHighlightTags = /(<mark>|<\/mark>)/g;
|
|
2
2
|
var regexHasHighlightTags = RegExp(regexHighlightTags.source);
|
|
3
3
|
export function removeHighlightTags(hit) {
|
|
4
|
-
|
|
4
|
+
var _internalDocSearchHit, _internalDocSearchHit2, _internalDocSearchHit3, _hit$_highlightResult, _hit$_highlightResult2;
|
|
5
|
+
|
|
6
|
+
var internalDocSearchHit = hit;
|
|
7
|
+
|
|
8
|
+
if (!internalDocSearchHit.__docsearch_parent && !hit._highlightResult) {
|
|
5
9
|
return hit.hierarchy.lvl0;
|
|
6
10
|
}
|
|
7
11
|
|
|
8
|
-
var _ref =
|
|
12
|
+
var _ref = (internalDocSearchHit.__docsearch_parent ? (_internalDocSearchHit = internalDocSearchHit.__docsearch_parent) === null || _internalDocSearchHit === void 0 ? void 0 : (_internalDocSearchHit2 = _internalDocSearchHit._highlightResult) === null || _internalDocSearchHit2 === void 0 ? void 0 : (_internalDocSearchHit3 = _internalDocSearchHit2.hierarchy) === null || _internalDocSearchHit3 === void 0 ? void 0 : _internalDocSearchHit3.lvl0 : (_hit$_highlightResult = hit._highlightResult) === null || _hit$_highlightResult === void 0 ? void 0 : (_hit$_highlightResult2 = _hit$_highlightResult.hierarchy) === null || _hit$_highlightResult2 === void 0 ? void 0 : _hit$_highlightResult2.lvl0) || {},
|
|
9
13
|
value = _ref.value;
|
|
10
14
|
|
|
11
15
|
return value && regexHasHighlightTags.test(value) ? value.replace(regexHighlightTags, '') : value;
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "3.0.0-alpha.
|
|
1
|
+
export declare const version = "3.0.0-alpha.50";
|
package/dist/esm/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export var version = '3.0.0-alpha.
|
|
1
|
+
export var version = '3.0.0-alpha.50';
|