@docsearch/react 3.0.0-alpha.38 → 3.0.0-alpha.42

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.
Files changed (48) hide show
  1. package/README.md +30 -4
  2. package/dist/esm/AlgoliaLogo.d.ts +8 -1
  3. package/dist/esm/AlgoliaLogo.js +6 -2
  4. package/dist/esm/DocSearch.d.ts +17 -10
  5. package/dist/esm/DocSearch.js +7 -3
  6. package/dist/esm/DocSearchButton.d.ts +3 -4
  7. package/dist/esm/DocSearchButton.js +6 -4
  8. package/dist/esm/DocSearchModal.d.ts +13 -5
  9. package/dist/esm/DocSearchModal.js +52 -37
  10. package/dist/esm/ErrorScreen.d.ts +9 -1
  11. package/dist/esm/ErrorScreen.js +9 -3
  12. package/dist/esm/Footer.d.ts +11 -1
  13. package/dist/esm/Footer.js +33 -18
  14. package/dist/esm/Hit.d.ts +2 -2
  15. package/dist/esm/NoResultsScreen.d.ts +12 -4
  16. package/dist/esm/NoResultsScreen.js +24 -5
  17. package/dist/esm/Results.d.ts +8 -8
  18. package/dist/esm/ResultsScreen.d.ts +3 -3
  19. package/dist/esm/ResultsScreen.js +2 -2
  20. package/dist/esm/ScreenState.d.ts +16 -7
  21. package/dist/esm/ScreenState.js +19 -4
  22. package/dist/esm/SearchBox.d.ts +13 -5
  23. package/dist/esm/SearchBox.js +25 -3
  24. package/dist/esm/Snippet.d.ts +2 -2
  25. package/dist/esm/Snippet.js +6 -3
  26. package/dist/esm/StartScreen.d.ts +14 -5
  27. package/dist/esm/StartScreen.js +40 -14
  28. package/dist/esm/__tests__/api.test.js +224 -0
  29. package/dist/esm/icons/SourceIcon.js +14 -13
  30. package/dist/esm/stored-searches.d.ts +4 -4
  31. package/dist/esm/stored-searches.js +3 -1
  32. package/dist/esm/types/DocSearchHit.d.ts +2 -2
  33. package/dist/esm/types/DocSearchHit.js +1 -0
  34. package/dist/esm/types/InternalDocSearchHit.d.ts +2 -2
  35. package/dist/esm/types/InternalDocSearchHit.js +1 -0
  36. package/dist/esm/types/StoredDocSearchHit.d.ts +1 -1
  37. package/dist/esm/types/StoredDocSearchHit.js +1 -0
  38. package/dist/esm/useDocSearchKeyboardEvents.d.ts +3 -3
  39. package/dist/esm/useSearchClient.d.ts +1 -1
  40. package/dist/esm/useTouchEvents.d.ts +1 -1
  41. package/dist/esm/utils/groupBy.d.ts +1 -1
  42. package/dist/esm/utils/removeHighlightTags.d.ts +1 -1
  43. package/dist/esm/utils/removeHighlightTags.js +6 -2
  44. package/dist/esm/version.d.ts +1 -1
  45. package/dist/esm/version.js +1 -1
  46. package/dist/umd/index.js +2 -2
  47. package/dist/umd/index.js.map +1 -1
  48. package/package.json +4 -4
@@ -0,0 +1,224 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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
+ }
24
+
25
+ describe('api', function () {
26
+ beforeEach(function () {
27
+ document.body.innerHTML = '';
28
+ });
29
+ it('renders with minimal parameters', function () {
30
+ render( /*#__PURE__*/React.createElement(DocSearch, null));
31
+ expect(document.querySelector('.DocSearch')).toBeInTheDocument();
32
+ });
33
+ describe('translations', function () {
34
+ it('overrides the default DocSearchButton text', function () {
35
+ render( /*#__PURE__*/React.createElement(DocSearch, {
36
+ translations: {
37
+ button: {
38
+ buttonText: 'Recherche',
39
+ buttonAriaLabel: 'Recherche'
40
+ }
41
+ }
42
+ }));
43
+ expect(document.querySelector('.DocSearch-Button-Placeholder').innerHTML).toBe('Recherche');
44
+ expect(document.querySelector('.DocSearch-Button').getAttribute('aria-label')).toBe('Recherche');
45
+ });
46
+ it('overrides the default DocSearchModal startScreen text', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
47
+ return regeneratorRuntime.wrap(function _callee$(_context) {
48
+ while (1) {
49
+ switch (_context.prev = _context.next) {
50
+ case 0:
51
+ render( /*#__PURE__*/React.createElement(DocSearch, {
52
+ translations: {
53
+ modal: {
54
+ startScreen: {
55
+ noRecentSearchesText: 'Pas de recherche récentes'
56
+ }
57
+ }
58
+ }
59
+ }));
60
+ _context.next = 3;
61
+ return waitFor(function () {
62
+ fireEvent.click(document.querySelector('.DocSearch-Button'));
63
+ });
64
+
65
+ case 3:
66
+ expect(screen.getByText('Pas de recherche récentes')).toBeInTheDocument();
67
+
68
+ case 4:
69
+ case "end":
70
+ return _context.stop();
71
+ }
72
+ }
73
+ }, _callee);
74
+ })));
75
+ it('overrides the default DocSearchModal noResultsScreen text', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
76
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
77
+ while (1) {
78
+ switch (_context3.prev = _context3.next) {
79
+ case 0:
80
+ render( /*#__PURE__*/React.createElement(DocSearch // mock empty response
81
+ , {
82
+ transformSearchClient: function transformSearchClient(searchClient) {
83
+ return _objectSpread(_objectSpread({}, searchClient), {}, {
84
+ search: function search() {
85
+ return new Promise(function (resolve) {
86
+ resolve({
87
+ results: [{
88
+ hits: [],
89
+ hitsPerPage: 0,
90
+ nbHits: 0,
91
+ nbPages: 0,
92
+ page: 0,
93
+ processingTimeMS: 0,
94
+ exhaustiveNbHits: true,
95
+ params: '',
96
+ query: ''
97
+ }]
98
+ });
99
+ });
100
+ }
101
+ });
102
+ },
103
+ translations: {
104
+ modal: {
105
+ noResultsScreen: {
106
+ noResultsText: 'Pas de résultats pour',
107
+ openIssueText: 'Ouvrez une issue sur docsearch-configs',
108
+ openIssueLinkText: 'Lien du repo'
109
+ }
110
+ }
111
+ }
112
+ }));
113
+ _context3.next = 3;
114
+ return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
115
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
116
+ while (1) {
117
+ switch (_context2.prev = _context2.next) {
118
+ case 0:
119
+ _context2.next = 2;
120
+ return waitFor(function () {
121
+ fireEvent.click(document.querySelector('.DocSearch-Button'));
122
+ });
123
+
124
+ case 2:
125
+ fireEvent.input(document.querySelector('.DocSearch-Input'), {
126
+ target: {
127
+ value: 'q'
128
+ }
129
+ });
130
+
131
+ case 3:
132
+ case "end":
133
+ return _context2.stop();
134
+ }
135
+ }
136
+ }, _callee2);
137
+ })));
138
+
139
+ case 3:
140
+ expect(screen.getByText(/Pas de résultats pour/)).toBeInTheDocument();
141
+ expect(screen.getByText(/Ouvrez une issue sur docsearch-configs/)).toBeInTheDocument();
142
+ expect(screen.getByRole('link', {
143
+ name: 'Lien du repo'
144
+ })).toBeInTheDocument();
145
+
146
+ case 6:
147
+ case "end":
148
+ return _context3.stop();
149
+ }
150
+ }
151
+ }, _callee3);
152
+ })));
153
+ it('overrides the default DocSearchModal searchbox text', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
154
+ return regeneratorRuntime.wrap(function _callee4$(_context4) {
155
+ while (1) {
156
+ switch (_context4.prev = _context4.next) {
157
+ case 0:
158
+ render( /*#__PURE__*/React.createElement(DocSearch, {
159
+ translations: {
160
+ modal: {
161
+ searchBox: {
162
+ resetButtonTitle: 'Effacer',
163
+ resetButtonAriaLabel: 'Effacer',
164
+ cancelButtonText: 'Annuler',
165
+ cancelButtonAriaLabel: 'Annuler'
166
+ }
167
+ }
168
+ }
169
+ }));
170
+ _context4.next = 3;
171
+ return waitFor(function () {
172
+ fireEvent.click(document.querySelector('.DocSearch-Button'));
173
+ });
174
+
175
+ case 3:
176
+ expect(document.querySelector('.DocSearch-Cancel').innerHTML).toBe('Annuler');
177
+ expect(document.querySelector('.DocSearch-Cancel').getAttribute('aria-label')).toBe('Annuler');
178
+ expect(document.querySelector('.DocSearch-Reset').getAttribute('title')).toBe('Effacer');
179
+ expect(document.querySelector('.DocSearch-Reset').getAttribute('aria-label')).toBe('Effacer');
180
+
181
+ case 7:
182
+ case "end":
183
+ return _context4.stop();
184
+ }
185
+ }
186
+ }, _callee4);
187
+ })));
188
+ it('overrides the default DocSearchModal footer text', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
189
+ return regeneratorRuntime.wrap(function _callee5$(_context5) {
190
+ while (1) {
191
+ switch (_context5.prev = _context5.next) {
192
+ case 0:
193
+ render( /*#__PURE__*/React.createElement(DocSearch, {
194
+ translations: {
195
+ modal: {
196
+ footer: {
197
+ closeText: 'Fermer',
198
+ navigateText: 'Naviguer',
199
+ searchByText: 'Recherche par',
200
+ selectText: 'Selectionner'
201
+ }
202
+ }
203
+ }
204
+ }));
205
+ _context5.next = 3;
206
+ return waitFor(function () {
207
+ fireEvent.click(document.querySelector('.DocSearch-Button'));
208
+ });
209
+
210
+ case 3:
211
+ expect(screen.getByText('Recherche par')).toBeInTheDocument();
212
+ expect(screen.getByText('Fermer')).toBeInTheDocument();
213
+ expect(screen.getByText('Naviguer')).toBeInTheDocument();
214
+ expect(screen.getByText('Selectionner')).toBeInTheDocument();
215
+
216
+ case 7:
217
+ case "end":
218
+ return _context5.stop();
219
+ }
220
+ }
221
+ }, _callee5);
222
+ })));
223
+ });
224
+ });
@@ -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): void;
8
- remove(item: TItem): void;
9
- getAll(): TItem[];
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, ["_highlightResult", "_snippetResult"]);
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: 'none' | 'partial' | 'full';
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: 'none' | 'partial' | 'full';
24
+ matchLevel: 'full' | 'none' | 'partial';
25
25
  }
26
26
  interface DocSearchHitSnippetResult {
27
27
  content: DocSearchHitAttributeSnippetResult;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { DocSearchHit } from './DocSearchHit';
1
+ import type { DocSearchHit } from './DocSearchHit';
2
2
  export declare type InternalDocSearchHit = DocSearchHit & {
3
- __docsearch_parent: null | InternalDocSearchHit;
3
+ __docsearch_parent: InternalDocSearchHit | null;
4
4
  };
@@ -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(): void;
5
- onClose(): void;
6
- onInput?(event: KeyboardEvent): void;
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,4 +1,4 @@
1
- import { AutocompleteApi } from '@algolia/autocomplete-core';
1
+ import type { AutocompleteApi } from '@algolia/autocomplete-core';
2
2
  interface UseTouchEventsProps {
3
3
  getEnvironmentProps: AutocompleteApi<any>['getEnvironmentProps'];
4
4
  panelElement: HTMLDivElement | null;
@@ -1 +1 @@
1
- export declare function groupBy<TValue extends object>(values: TValue[], predicate: (value: TValue) => string): Record<string, TValue[]>;
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 './../types';
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
- if (!hit.__docsearch_parent && !hit._highlightResult) {
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 = hit._highlightResult ? hit._highlightResult.hierarchy.lvl0 : hit.__docsearch_parent._highlightResult.hierarchy.lvl0,
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;
@@ -1 +1 @@
1
- export declare const version = "3.0.0-alpha.38";
1
+ export declare const version = "3.0.0-alpha.42";
@@ -1 +1 @@
1
- export var version = '3.0.0-alpha.38';
1
+ export var version = '3.0.0-alpha.42';