@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
package/README.md CHANGED
@@ -2,16 +2,42 @@
2
2
 
3
3
  React package for [DocSearch](http://docsearch.algolia.com/), the best search experience for docs.
4
4
 
5
- [![Percy](https://percy.io/static/images/percy-badge.svg)](https://percy.io/DX/DocSearch)
6
-
7
5
  ## Installation
8
6
 
9
- ```sh
7
+ ```bash
10
8
  yarn add @docsearch/react@alpha
11
9
  # or
12
10
  npm install @docsearch/react@alpha
13
11
  ```
14
12
 
13
+ If you don’t want to use a package manager, you can use a standalone endpoint:
14
+
15
+ ```html
16
+ <script src="https://cdn.jsdelivr.net/npm/@docsearch/react@alpha"></script>
17
+ ```
18
+
19
+ ## Get started
20
+
21
+ DocSearch generates a fully accessible search box for you.
22
+
23
+ ```jsx App.js
24
+ import { DocSearch } from '@docsearch/react';
25
+
26
+ import '@docsearch/css';
27
+
28
+ function App() {
29
+ return (
30
+ <DocSearch
31
+ appId="YOUR_APP_ID"
32
+ indexName="YOUR_INDEX_NAME"
33
+ apiKey="YOUR_SEARCH_API_KEY"
34
+ />
35
+ );
36
+ }
37
+
38
+ export default App;
39
+ ```
40
+
15
41
  ## Documentation
16
42
 
17
- [Read documentation →](https://autocomplete-experimental.netlify.app/docs/DocSearch)
43
+ [Read documentation →](https://docsearch.algolia.com/docs/DocSearch-v3)
@@ -1,2 +1,9 @@
1
1
  /// <reference types="react" />
2
- export declare function AlgoliaLogo(): JSX.Element;
2
+ declare type AlgoliaLogoTranslations = Partial<{
3
+ searchByText: string;
4
+ }>;
5
+ declare type AlgoliaLogoProps = {
6
+ translations?: AlgoliaLogoTranslations;
7
+ };
8
+ export declare function AlgoliaLogo({ translations }: AlgoliaLogoProps): JSX.Element;
9
+ export {};
@@ -1,12 +1,16 @@
1
1
  import React from 'react';
2
- export function AlgoliaLogo() {
2
+ export function AlgoliaLogo(_ref) {
3
+ var _ref$translations = _ref.translations,
4
+ translations = _ref$translations === void 0 ? {} : _ref$translations;
5
+ var _translations$searchB = translations.searchByText,
6
+ searchByText = _translations$searchB === void 0 ? 'Search by' : _translations$searchB;
3
7
  return /*#__PURE__*/React.createElement("a", {
4
8
  href: "https://www.algolia.com/docsearch",
5
9
  target: "_blank",
6
10
  rel: "noopener noreferrer"
7
11
  }, /*#__PURE__*/React.createElement("span", {
8
12
  className: "DocSearch-Label"
9
- }, "Search by"), /*#__PURE__*/React.createElement("svg", {
13
+ }, searchByText), /*#__PURE__*/React.createElement("svg", {
10
14
  width: "77",
11
15
  height: "19"
12
16
  }, /*#__PURE__*/React.createElement("path", {
@@ -1,24 +1,31 @@
1
- import { AutocompleteState, AutocompleteOptions } from '@algolia/autocomplete-core';
2
- import { SearchClient } from 'algoliasearch/lite';
1
+ import type { AutocompleteState, AutocompleteOptions } from '@algolia/autocomplete-core';
2
+ import type { SearchOptions } from '@algolia/client-search';
3
+ import type { SearchClient } from 'algoliasearch/lite';
3
4
  import React from 'react';
4
- import { DocSearchHit, InternalDocSearchHit, StoredDocSearchHit } from './types';
5
+ import type { DocSearchHit, InternalDocSearchHit, StoredDocSearchHit } from './types';
6
+ import type { ButtonTranslations, ModalTranslations } from '.';
7
+ export declare type DocSearchTranslations = Partial<{
8
+ button: ButtonTranslations;
9
+ modal: ModalTranslations;
10
+ }>;
5
11
  export interface DocSearchProps {
6
12
  appId?: string;
7
13
  apiKey: string;
8
14
  indexName: string;
9
15
  placeholder?: string;
10
- searchParameters?: any;
11
- transformItems?(items: DocSearchHit[]): DocSearchHit[];
12
- hitComponent?(props: {
16
+ searchParameters?: SearchOptions;
17
+ transformItems?: (items: DocSearchHit[]) => DocSearchHit[];
18
+ hitComponent?: (props: {
13
19
  hit: InternalDocSearchHit | StoredDocSearchHit;
14
20
  children: React.ReactNode;
15
- }): JSX.Element;
16
- resultsFooterComponent?(props: {
21
+ }) => JSX.Element;
22
+ resultsFooterComponent?: (props: {
17
23
  state: AutocompleteState<InternalDocSearchHit>;
18
- }): JSX.Element | null;
19
- transformSearchClient?(searchClient: SearchClient): SearchClient;
24
+ }) => JSX.Element | null;
25
+ transformSearchClient?: (searchClient: SearchClient) => SearchClient;
20
26
  disableUserPersonalization?: boolean;
21
27
  initialQuery?: string;
22
28
  navigator?: AutocompleteOptions<InternalDocSearchHit>['navigator'];
29
+ translations?: DocSearchTranslations;
23
30
  }
24
31
  export declare function DocSearch(props: DocSearchProps): JSX.Element;
@@ -18,6 +18,8 @@ import { DocSearchButton } from './DocSearchButton';
18
18
  import { DocSearchModal } from './DocSearchModal';
19
19
  import { useDocSearchKeyboardEvents } from './useDocSearchKeyboardEvents';
20
20
  export function DocSearch(props) {
21
+ var _props$translations, _props$translations2;
22
+
21
23
  var searchButtonRef = React.useRef(null);
22
24
 
23
25
  var _React$useState = React.useState(false),
@@ -25,7 +27,7 @@ export function DocSearch(props) {
25
27
  isOpen = _React$useState2[0],
26
28
  setIsOpen = _React$useState2[1];
27
29
 
28
- var _React$useState3 = React.useState(undefined),
30
+ var _React$useState3 = React.useState((props === null || props === void 0 ? void 0 : props.initialQuery) || undefined),
29
31
  _React$useState4 = _slicedToArray(_React$useState3, 2),
30
32
  initialQuery = _React$useState4[0],
31
33
  setInitialQuery = _React$useState4[1];
@@ -48,11 +50,13 @@ export function DocSearch(props) {
48
50
  searchButtonRef: searchButtonRef
49
51
  });
50
52
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DocSearchButton, {
51
- onClick: onOpen,
52
- ref: searchButtonRef
53
+ ref: searchButtonRef,
54
+ translations: props === null || props === void 0 ? void 0 : (_props$translations = props.translations) === null || _props$translations === void 0 ? void 0 : _props$translations.button,
55
+ onClick: onOpen
53
56
  }), isOpen && createPortal( /*#__PURE__*/React.createElement(DocSearchModal, _extends({}, props, {
54
57
  initialScrollY: window.scrollY,
55
58
  initialQuery: initialQuery,
59
+ translations: props === null || props === void 0 ? void 0 : (_props$translations2 = props.translations) === null || _props$translations2 === void 0 ? void 0 : _props$translations2.modal,
56
60
  onClose: onClose
57
61
  })), document.body));
58
62
  }
@@ -1,10 +1,9 @@
1
1
  import React from 'react';
2
- declare type Translations = Partial<{
2
+ export declare type ButtonTranslations = Partial<{
3
3
  buttonText: string;
4
4
  buttonAriaLabel: string;
5
5
  }>;
6
6
  export declare type DocSearchButtonProps = React.ComponentProps<'button'> & {
7
- translations?: Translations;
7
+ translations?: ButtonTranslations;
8
8
  };
9
- export declare const DocSearchButton: React.ForwardRefExoticComponent<Pick<DocSearchButtonProps, "form" | "slot" | "style" | "title" | "children" | "translations" | "key" | "autoFocus" | "disabled" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "name" | "type" | "value" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture"> & React.RefAttributes<HTMLButtonElement>>;
10
- export {};
9
+ export declare const DocSearchButton: React.ForwardRefExoticComponent<Pick<DocSearchButtonProps, "translations" | "key" | keyof React.ButtonHTMLAttributes<HTMLButtonElement>> & React.RefAttributes<HTMLButtonElement>>;
@@ -1,3 +1,5 @@
1
+ var _excluded = ["translations"];
2
+
1
3
  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); }
2
4
 
3
5
  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; }
@@ -17,7 +19,7 @@ function isAppleDevice() {
17
19
  export var DocSearchButton = React.forwardRef(function (_ref, ref) {
18
20
  var _ref$translations = _ref.translations,
19
21
  translations = _ref$translations === void 0 ? {} : _ref$translations,
20
- props = _objectWithoutProperties(_ref, ["translations"]);
22
+ props = _objectWithoutProperties(_ref, _excluded);
21
23
 
22
24
  var _translations$buttonT = translations.buttonText,
23
25
  buttonText = _translations$buttonT === void 0 ? 'Search' : _translations$buttonT,
@@ -40,11 +42,11 @@ export var DocSearchButton = React.forwardRef(function (_ref, ref) {
40
42
  className: "DocSearch-Button-Container"
41
43
  }, /*#__PURE__*/React.createElement(SearchIcon, null), /*#__PURE__*/React.createElement("span", {
42
44
  className: "DocSearch-Button-Placeholder"
43
- }, buttonText)), key !== null && /*#__PURE__*/React.createElement("span", {
45
+ }, buttonText)), /*#__PURE__*/React.createElement("span", {
44
46
  className: "DocSearch-Button-Keys"
45
- }, /*#__PURE__*/React.createElement("span", {
47
+ }, key !== null && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
46
48
  className: "DocSearch-Button-Key"
47
49
  }, key === ACTION_KEY_DEFAULT ? /*#__PURE__*/React.createElement(ControlKeyIcon, null) : key), /*#__PURE__*/React.createElement("span", {
48
50
  className: "DocSearch-Button-Key"
49
- }, "K")));
51
+ }, "K"))));
50
52
  });
@@ -1,7 +1,15 @@
1
1
  /// <reference types="react" />
2
- import { DocSearchProps } from './DocSearch';
3
- export interface DocSearchModalProps extends DocSearchProps {
2
+ import type { DocSearchProps } from './DocSearch';
3
+ import type { FooterTranslations } from './Footer';
4
+ import type { ScreenStateTranslations } from './ScreenState';
5
+ import type { SearchBoxTranslations } from './SearchBox';
6
+ export declare type ModalTranslations = Partial<{
7
+ searchBox: SearchBoxTranslations;
8
+ footer: FooterTranslations;
9
+ }> & ScreenStateTranslations;
10
+ export declare type DocSearchModalProps = DocSearchProps & {
4
11
  initialScrollY: number;
5
- onClose?(): void;
6
- }
7
- export declare function DocSearchModal({ appId, apiKey, indexName, placeholder, searchParameters, onClose, transformItems, hitComponent, resultsFooterComponent, navigator, initialScrollY, transformSearchClient, disableUserPersonalization, initialQuery: initialQueryFromProp, }: DocSearchModalProps): JSX.Element;
12
+ onClose?: () => void;
13
+ translations?: ModalTranslations;
14
+ };
15
+ export declare function DocSearchModal({ appId, apiKey, indexName, placeholder, searchParameters, onClose, transformItems, hitComponent, resultsFooterComponent, navigator, initialScrollY, transformSearchClient, disableUserPersonalization, initialQuery: initialQueryFromProp, translations, }: DocSearchModalProps): JSX.Element;
@@ -1,3 +1,5 @@
1
+ var _excluded = ["footer", "searchBox"];
2
+
1
3
  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); }
2
4
 
3
5
  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; }
@@ -18,6 +20,10 @@ function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(
18
20
 
19
21
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
20
22
 
23
+ 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; }
24
+
25
+ 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; }
26
+
21
27
  import { createAutocomplete } from '@algolia/autocomplete-core';
22
28
  import React from 'react';
23
29
  import { MAX_QUERY_SIZE } from './constants';
@@ -56,7 +62,13 @@ export function DocSearchModal(_ref) {
56
62
  _ref$disableUserPerso = _ref.disableUserPersonalization,
57
63
  disableUserPersonalization = _ref$disableUserPerso === void 0 ? false : _ref$disableUserPerso,
58
64
  _ref$initialQuery = _ref.initialQuery,
59
- initialQueryFromProp = _ref$initialQuery === void 0 ? '' : _ref$initialQuery;
65
+ initialQueryFromProp = _ref$initialQuery === void 0 ? '' : _ref$initialQuery,
66
+ _ref$translations = _ref.translations,
67
+ translations = _ref$translations === void 0 ? {} : _ref$translations;
68
+
69
+ var footerTranslations = translations.footer,
70
+ searchBoxTranslations = translations.searchBox,
71
+ screenStateTranslations = _objectWithoutProperties(translations, _excluded);
60
72
 
61
73
  var _React$useState = React.useState({
62
74
  query: '',
@@ -117,16 +129,14 @@ export function DocSearchModal(_ref) {
117
129
  }
118
130
  },
119
131
  navigator: navigator,
120
- onStateChange: function onStateChange(_ref2) {
121
- var state = _ref2.state;
122
- setState(state);
132
+ onStateChange: function onStateChange(props) {
133
+ setState(props.state);
123
134
  },
124
- // @ts-ignore Temporarily ignore bad typing in autocomplete-core.
125
- getSources: function getSources(_ref3) {
126
- var query = _ref3.query,
127
- state = _ref3.state,
128
- setContext = _ref3.setContext,
129
- setStatus = _ref3.setStatus;
135
+ getSources: function getSources(_ref2) {
136
+ var query = _ref2.query,
137
+ sourcesState = _ref2.state,
138
+ setContext = _ref2.setContext,
139
+ setStatus = _ref2.setStatus;
130
140
 
131
141
  if (!query) {
132
142
  if (disableUserPersonalization) {
@@ -135,17 +145,17 @@ export function DocSearchModal(_ref) {
135
145
 
136
146
  return [{
137
147
  sourceId: 'recentSearches',
138
- onSelect: function onSelect(_ref4) {
139
- var item = _ref4.item,
140
- event = _ref4.event;
148
+ onSelect: function onSelect(_ref3) {
149
+ var item = _ref3.item,
150
+ event = _ref3.event;
141
151
  saveRecentSearch(item);
142
152
 
143
153
  if (!event.shiftKey && !event.ctrlKey && !event.metaKey) {
144
154
  onClose();
145
155
  }
146
156
  },
147
- getItemUrl: function getItemUrl(_ref5) {
148
- var item = _ref5.item;
157
+ getItemUrl: function getItemUrl(_ref4) {
158
+ var item = _ref4.item;
149
159
  return item.url;
150
160
  },
151
161
  getItems: function getItems() {
@@ -153,17 +163,17 @@ export function DocSearchModal(_ref) {
153
163
  }
154
164
  }, {
155
165
  sourceId: 'favoriteSearches',
156
- onSelect: function onSelect(_ref6) {
157
- var item = _ref6.item,
158
- event = _ref6.event;
166
+ onSelect: function onSelect(_ref5) {
167
+ var item = _ref5.item,
168
+ event = _ref5.event;
159
169
  saveRecentSearch(item);
160
170
 
161
171
  if (!event.shiftKey && !event.ctrlKey && !event.metaKey) {
162
172
  onClose();
163
173
  }
164
174
  },
165
- getItemUrl: function getItemUrl(_ref7) {
166
- var item = _ref7.item;
175
+ getItemUrl: function getItemUrl(_ref6) {
176
+ var item = _ref6.item;
167
177
  return item.url;
168
178
  },
169
179
  getItems: function getItems() {
@@ -193,8 +203,8 @@ export function DocSearchModal(_ref) {
193
203
  }
194
204
 
195
205
  throw error;
196
- }).then(function (_ref8) {
197
- var results = _ref8.results;
206
+ }).then(function (_ref7) {
207
+ var results = _ref7.results;
198
208
  var _results$ = results[0],
199
209
  hits = _results$.hits,
200
210
  nbHits = _results$.nbHits;
@@ -203,7 +213,7 @@ export function DocSearchModal(_ref) {
203
213
  }); // We store the `lvl0`s to display them as search suggestions
204
214
  // in the "no results" screen.
205
215
 
206
- if (state.context.searchSuggestions.length < Object.keys(sources).length) {
216
+ if (sourcesState.context.searchSuggestions.length < Object.keys(sources).length) {
207
217
  setContext({
208
218
  searchSuggestions: Object.keys(sources)
209
219
  });
@@ -215,27 +225,26 @@ export function DocSearchModal(_ref) {
215
225
  return Object.values(sources).map(function (items, index) {
216
226
  return {
217
227
  sourceId: "hits".concat(index),
218
- onSelect: function onSelect(_ref9) {
219
- var item = _ref9.item,
220
- event = _ref9.event;
228
+ onSelect: function onSelect(_ref8) {
229
+ var item = _ref8.item,
230
+ event = _ref8.event;
221
231
  saveRecentSearch(item);
222
232
 
223
233
  if (!event.shiftKey && !event.ctrlKey && !event.metaKey) {
224
234
  onClose();
225
235
  }
226
236
  },
227
- getItemUrl: function getItemUrl(_ref10) {
228
- var item = _ref10.item;
237
+ getItemUrl: function getItemUrl(_ref9) {
238
+ var item = _ref9.item;
229
239
  return item.url;
230
240
  },
231
241
  getItems: function getItems() {
232
242
  return Object.values(groupBy(items, function (item) {
233
243
  return item.hierarchy.lvl1;
234
- })).map(transformItems).map(function (hits) {
235
- return hits.map(function (item) {
244
+ })).map(transformItems).map(function (groupedHits) {
245
+ return groupedHits.map(function (item) {
236
246
  return _objectSpread(_objectSpread({}, item), {}, {
237
- // eslint-disable-next-line @typescript-eslint/camelcase
238
- __docsearch_parent: item.type !== 'lvl1' && hits.find(function (siblingItem) {
247
+ __docsearch_parent: item.type !== 'lvl1' && groupedHits.find(function (siblingItem) {
239
248
  return siblingItem.type === 'lvl1' && siblingItem.hierarchy.lvl1 === item.hierarchy.lvl1;
240
249
  })
241
250
  });
@@ -320,6 +329,8 @@ export function DocSearchModal(_ref) {
320
329
  'aria-expanded': true
321
330
  }), {
322
331
  className: ['DocSearch', 'DocSearch-Container', state.status === 'stalled' && 'DocSearch-Container--Stalled', state.status === 'error' && 'DocSearch-Container--Errored'].filter(Boolean).join(' '),
332
+ role: "button",
333
+ tabIndex: 0,
323
334
  onMouseDown: function onMouseDown(event) {
324
335
  if (event.target === event.currentTarget) {
325
336
  onClose();
@@ -334,9 +345,10 @@ export function DocSearchModal(_ref) {
334
345
  }, /*#__PURE__*/React.createElement(SearchBox, _extends({}, autocomplete, {
335
346
  state: state,
336
347
  autoFocus: initialQuery.length === 0,
337
- onClose: onClose,
338
348
  inputRef: inputRef,
339
- isFromSelection: Boolean(initialQuery) && initialQuery === initialQueryFromSelection
349
+ isFromSelection: Boolean(initialQuery) && initialQuery === initialQueryFromSelection,
350
+ translations: searchBoxTranslations,
351
+ onClose: onClose
340
352
  }))), /*#__PURE__*/React.createElement("div", {
341
353
  className: "DocSearch-Dropdown",
342
354
  ref: dropdownRef
@@ -348,12 +360,15 @@ export function DocSearchModal(_ref) {
348
360
  disableUserPersonalization: disableUserPersonalization,
349
361
  recentSearches: recentSearches,
350
362
  favoriteSearches: favoriteSearches,
363
+ inputRef: inputRef,
364
+ translations: screenStateTranslations,
351
365
  onItemClick: function onItemClick(item) {
352
366
  saveRecentSearch(item);
353
367
  onClose();
354
- },
355
- inputRef: inputRef
368
+ }
356
369
  }))), /*#__PURE__*/React.createElement("footer", {
357
370
  className: "DocSearch-Footer"
358
- }, /*#__PURE__*/React.createElement(Footer, null))));
371
+ }, /*#__PURE__*/React.createElement(Footer, {
372
+ translations: footerTranslations
373
+ }))));
359
374
  }
@@ -1,2 +1,10 @@
1
1
  /// <reference types="react" />
2
- export declare function ErrorScreen(): JSX.Element;
2
+ export declare type ErrorScreenTranslations = Partial<{
3
+ titleText: string;
4
+ helpText: string;
5
+ }>;
6
+ declare type ErrorScreenProps = {
7
+ translations?: ErrorScreenTranslations;
8
+ };
9
+ export declare function ErrorScreen({ translations }: ErrorScreenProps): JSX.Element;
10
+ export {};
@@ -1,13 +1,19 @@
1
1
  import React from 'react';
2
2
  import { ErrorIcon } from './icons';
3
- export function ErrorScreen() {
3
+ export function ErrorScreen(_ref) {
4
+ var _ref$translations = _ref.translations,
5
+ translations = _ref$translations === void 0 ? {} : _ref$translations;
6
+ var _translations$titleTe = translations.titleText,
7
+ titleText = _translations$titleTe === void 0 ? 'Unable to fetch results' : _translations$titleTe,
8
+ _translations$helpTex = translations.helpText,
9
+ helpText = _translations$helpTex === void 0 ? 'You might want to check your network connection.' : _translations$helpTex;
4
10
  return /*#__PURE__*/React.createElement("div", {
5
11
  className: "DocSearch-ErrorScreen"
6
12
  }, /*#__PURE__*/React.createElement("div", {
7
13
  className: "DocSearch-Screen-Icon"
8
14
  }, /*#__PURE__*/React.createElement(ErrorIcon, null)), /*#__PURE__*/React.createElement("p", {
9
15
  className: "DocSearch-Title"
10
- }, "Unable to fetch results"), /*#__PURE__*/React.createElement("p", {
16
+ }, titleText), /*#__PURE__*/React.createElement("p", {
11
17
  className: "DocSearch-Help"
12
- }, "You might want to check your network connection."));
18
+ }, helpText));
13
19
  }
@@ -1,2 +1,12 @@
1
1
  /// <reference types="react" />
2
- export declare function Footer(): JSX.Element;
2
+ export declare type FooterTranslations = Partial<{
3
+ selectText: string;
4
+ navigateText: string;
5
+ closeText: string;
6
+ searchByText: string;
7
+ }>;
8
+ declare type FooterProps = Partial<{
9
+ translations: FooterTranslations;
10
+ }>;
11
+ export declare function Footer({ translations }: FooterProps): JSX.Element;
12
+ export {};
@@ -1,9 +1,37 @@
1
1
  import React from 'react';
2
2
  import { AlgoliaLogo } from './AlgoliaLogo';
3
- export function Footer() {
3
+
4
+ function CommandIcon(props) {
5
+ return /*#__PURE__*/React.createElement("svg", {
6
+ width: "15",
7
+ height: "15"
8
+ }, /*#__PURE__*/React.createElement("g", {
9
+ fill: "none",
10
+ stroke: "currentColor",
11
+ strokeLinecap: "round",
12
+ strokeLinejoin: "round",
13
+ strokeWidth: "1.2"
14
+ }, props.children));
15
+ }
16
+
17
+ export function Footer(_ref) {
18
+ var _ref$translations = _ref.translations,
19
+ translations = _ref$translations === void 0 ? {} : _ref$translations;
20
+ var _translations$selectT = translations.selectText,
21
+ selectText = _translations$selectT === void 0 ? 'to select' : _translations$selectT,
22
+ _translations$navigat = translations.navigateText,
23
+ navigateText = _translations$navigat === void 0 ? 'to navigate' : _translations$navigat,
24
+ _translations$closeTe = translations.closeText,
25
+ closeText = _translations$closeTe === void 0 ? 'to close' : _translations$closeTe,
26
+ _translations$searchB = translations.searchByText,
27
+ searchByText = _translations$searchB === void 0 ? 'Search by' : _translations$searchB;
4
28
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
5
29
  className: "DocSearch-Logo"
6
- }, /*#__PURE__*/React.createElement(AlgoliaLogo, null)), /*#__PURE__*/React.createElement("ul", {
30
+ }, /*#__PURE__*/React.createElement(AlgoliaLogo, {
31
+ translations: {
32
+ searchByText: searchByText
33
+ }
34
+ })), /*#__PURE__*/React.createElement("ul", {
7
35
  className: "DocSearch-Commands"
8
36
  }, /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement("span", {
9
37
  className: "DocSearch-Commands-Key"
@@ -11,7 +39,7 @@ export function Footer() {
11
39
  d: "M12 3.53088v3c0 1-1 2-2 2H4M7 11.53088l-3-3 3-3"
12
40
  }))), /*#__PURE__*/React.createElement("span", {
13
41
  className: "DocSearch-Label"
14
- }, "to select")), /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement("span", {
42
+ }, selectText)), /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement("span", {
15
43
  className: "DocSearch-Commands-Key"
16
44
  }, /*#__PURE__*/React.createElement(CommandIcon, null, /*#__PURE__*/React.createElement("path", {
17
45
  d: "M7.5 3.5v8M10.5 8.5l-3 3-3-3"
@@ -21,24 +49,11 @@ export function Footer() {
21
49
  d: "M7.5 11.5v-8M10.5 6.5l-3-3-3 3"
22
50
  }))), /*#__PURE__*/React.createElement("span", {
23
51
  className: "DocSearch-Label"
24
- }, "to navigate")), /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement("span", {
52
+ }, navigateText)), /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement("span", {
25
53
  className: "DocSearch-Commands-Key"
26
54
  }, /*#__PURE__*/React.createElement(CommandIcon, null, /*#__PURE__*/React.createElement("path", {
27
55
  d: "M13.6167 8.936c-.1065.3583-.6883.962-1.4875.962-.7993 0-1.653-.9165-1.653-2.1258v-.5678c0-1.2548.7896-2.1016 1.653-2.1016.8634 0 1.3601.4778 1.4875 1.0724M9 6c-.1352-.4735-.7506-.9219-1.46-.8972-.7092.0246-1.344.57-1.344 1.2166s.4198.8812 1.3445.9805C8.465 7.3992 8.968 7.9337 9 8.5c.032.5663-.454 1.398-1.4595 1.398C6.6593 9.898 6 9 5.963 8.4851m-1.4748.5368c-.2635.5941-.8099.876-1.5443.876s-1.7073-.6248-1.7073-2.204v-.4603c0-1.0416.721-2.131 1.7073-2.131.9864 0 1.6425 1.031 1.5443 2.2492h-2.956"
28
56
  }))), /*#__PURE__*/React.createElement("span", {
29
57
  className: "DocSearch-Label"
30
- }, "to close"))));
31
- }
32
-
33
- function CommandIcon(props) {
34
- return /*#__PURE__*/React.createElement("svg", {
35
- width: "15",
36
- height: "15"
37
- }, /*#__PURE__*/React.createElement("g", {
38
- fill: "none",
39
- stroke: "currentColor",
40
- strokeLinecap: "round",
41
- strokeLinejoin: "round",
42
- strokeWidth: "1.2"
43
- }, props.children));
58
+ }, closeText))));
44
59
  }
package/dist/esm/Hit.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
- import { DocSearchHit } from './types';
2
+ import type { InternalDocSearchHit, StoredDocSearchHit } from './types';
3
3
  interface HitProps {
4
- hit: DocSearchHit;
4
+ hit: InternalDocSearchHit | StoredDocSearchHit;
5
5
  children: React.ReactNode;
6
6
  }
7
7
  export declare function Hit({ hit, children }: HitProps): JSX.Element;
@@ -1,6 +1,14 @@
1
1
  /// <reference types="react" />
2
- import { ScreenStateProps } from './ScreenState';
3
- import { InternalDocSearchHit } from './types';
4
- declare type NoResultsScreenProps = ScreenStateProps<InternalDocSearchHit>;
5
- export declare function NoResultsScreen(props: NoResultsScreenProps): JSX.Element;
2
+ import type { ScreenStateProps } from './ScreenState';
3
+ import type { InternalDocSearchHit } from './types';
4
+ export declare type NoResultsScreenTranslations = Partial<{
5
+ noResultsText: string;
6
+ suggestedQueryText: string;
7
+ openIssueText: string;
8
+ openIssueLinkText: string;
9
+ }>;
10
+ declare type NoResultsScreenProps = Omit<ScreenStateProps<InternalDocSearchHit>, 'translations'> & {
11
+ translations?: NoResultsScreenTranslations;
12
+ };
13
+ export declare function NoResultsScreen({ translations, ...props }: NoResultsScreenProps): JSX.Element;
6
14
  export {};