This commit is contained in:
NoryiE
2025-02-16 14:12:49 +00:00
parent c6a89e5b35
commit e0aeb9b06e
2737 changed files with 5220 additions and 1039045 deletions

View File

@@ -1,27 +0,0 @@
# @docsearch/css
Style package for [DocSearch](http://docsearch.algolia.com/), the best search experience for docs.
## Installation
```bash
yarn add @docsearch/css@3
# or
npm install @docsearch/css@3
```
If you dont want to use a package manager, you can use a standalone endpoint:
```html
<script src="https://cdn.jsdelivr.net/npm/@docsearch/css@3"></script>
```
## Get started
```js
import '@docsearch/css';
```
## Documentation
[Read documentation →](https://docsearch.algolia.com/docs/styling)

View File

@@ -1,2 +0,0 @@
/*! @docsearch/css Variables 3.5.2 | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
:root{--docsearch-primary-color:#5468ff;--docsearch-text-color:#1c1e21;--docsearch-spacing:12px;--docsearch-icon-stroke-width:1.4;--docsearch-highlight-color:var(--docsearch-primary-color);--docsearch-muted-color:#969faf;--docsearch-container-background:rgba(101,108,133,0.8);--docsearch-logo-color:#5468ff;--docsearch-modal-width:560px;--docsearch-modal-height:600px;--docsearch-modal-background:#f5f6f7;--docsearch-modal-shadow:inset 1px 1px 0 0 hsla(0,0%,100%,0.5),0 3px 8px 0 #555a64;--docsearch-searchbox-height:56px;--docsearch-searchbox-background:#ebedf0;--docsearch-searchbox-focus-background:#fff;--docsearch-searchbox-shadow:inset 0 0 0 2px var(--docsearch-primary-color);--docsearch-hit-height:56px;--docsearch-hit-color:#444950;--docsearch-hit-active-color:#fff;--docsearch-hit-background:#fff;--docsearch-hit-shadow:0 1px 3px 0 #d4d9e1;--docsearch-key-gradient:linear-gradient(-225deg,#d5dbe4,#f8f8f8);--docsearch-key-shadow:inset 0 -2px 0 0 #cdcde6,inset 0 0 1px 1px #fff,0 1px 2px 1px rgba(30,35,90,0.4);--docsearch-footer-height:44px;--docsearch-footer-background:#fff;--docsearch-footer-shadow:0 -1px 0 0 #e0e3e8,0 -3px 6px 0 rgba(69,98,155,0.12)}html[data-theme=dark]{--docsearch-text-color:#f5f6f7;--docsearch-container-background:rgba(9,10,17,0.8);--docsearch-modal-background:#15172a;--docsearch-modal-shadow:inset 1px 1px 0 0 #2c2e40,0 3px 8px 0 #000309;--docsearch-searchbox-background:#090a11;--docsearch-searchbox-focus-background:#000;--docsearch-hit-color:#bec3c9;--docsearch-hit-shadow:none;--docsearch-hit-background:#090a11;--docsearch-key-gradient:linear-gradient(-26.5deg,#565872,#31355b);--docsearch-key-shadow:inset 0 -2px 0 0 #282d55,inset 0 0 1px 1px #51577d,0 2px 2px 0 rgba(3,4,9,0.3);--docsearch-footer-background:#1e2136;--docsearch-footer-shadow:inset 0 1px 0 0 rgba(73,76,106,0.5),0 -4px 8px 0 rgba(0,0,0,0.2);--docsearch-logo-color:#fff;--docsearch-muted-color:#7f8497}

View File

@@ -1,2 +0,0 @@
/*! @docsearch/css Button 3.5.2 | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
.DocSearch-Button{align-items:center;background:var(--docsearch-searchbox-background);border:0;border-radius:40px;color:var(--docsearch-muted-color);cursor:pointer;display:flex;font-weight:500;height:36px;justify-content:space-between;margin:0 0 0 16px;padding:0 8px;user-select:none}.DocSearch-Button:active,.DocSearch-Button:focus,.DocSearch-Button:hover{background:var(--docsearch-searchbox-focus-background);box-shadow:var(--docsearch-searchbox-shadow);color:var(--docsearch-text-color);outline:none}.DocSearch-Button-Container{align-items:center;display:flex}.DocSearch-Search-Icon{stroke-width:1.6}.DocSearch-Button .DocSearch-Search-Icon{color:var(--docsearch-text-color)}.DocSearch-Button-Placeholder{font-size:1rem;padding:0 12px 0 6px}.DocSearch-Button-Keys{display:flex;min-width:calc(40px + .8em)}.DocSearch-Button-Key{align-items:center;background:var(--docsearch-key-gradient);border-radius:3px;box-shadow:var(--docsearch-key-shadow);color:var(--docsearch-muted-color);display:flex;height:18px;justify-content:center;margin-right:.4em;position:relative;padding:0 0 2px;border:0;top:-1px;width:20px}@media (max-width:768px){.DocSearch-Button-Keys,.DocSearch-Button-Placeholder{display:none}}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,24 +0,0 @@
{
"name": "@docsearch/css",
"description": "Styles for DocSearch.",
"version": "3.5.2",
"license": "MIT",
"homepage": "https://docsearch.algolia.com",
"repository": "algolia/docsearch",
"author": {
"name": "Algolia, Inc.",
"url": "https://www.algolia.com"
},
"files": [
"dist/"
],
"main": "dist/style.css",
"unpkg": "dist/style.css",
"jsdelivr": "dist/style.css",
"scripts": {
"build:clean": "rm -rf ./dist",
"build:css": "node build-css.js",
"build": "yarn build:clean && mkdir dist && yarn build:css",
"watch": "watch \"yarn build:css\" --ignoreDirectoryPattern \"/dist/\""
}
}

46
node_modules/@docsearch/js/README.md generated vendored
View File

@@ -1,46 +0,0 @@
# @docsearch/js
JavaScript package for [DocSearch](http://docsearch.algolia.com/), the best search experience for docs.
## Installation
```sh
yarn add @docsearch/js@3
# or
npm install @docsearch/js@3
```
## Get started
If you dont want to use a package manager, you can use a standalone endpoint:
```html
<script src="https://cdn.jsdelivr.net/npm/@docsearch/js@3"></script>
```
To get started, you need a [`container`](https://docsearch.algolia.com/docs/api#container) for your DocSearch component to go in. If you dont have one already, you can insert one into your markup:
```html
<div id="docsearch"></div>
```
Then, insert DocSearch into it by calling the [`docsearch`](https://docsearch.algolia.com/docs/api) function and providing the container. It can be a [CSS selector](https://developer.mozilla.org/en-us/docs/web/css/css_selectors) or an [Element](https://developer.mozilla.org/en-us/docs/web/api/htmlelement).
Make sure to provide a [`container`](https://docsearch.algolia.com/docs/api#container) (for example, a `div`), not an `input`. DocSearch generates a fully accessible search box for you.
```js app.js
import docsearch from '@docsearch/js';
import '@docsearch/css';
docsearch({
container: '#docsearch',
appId: 'YOUR_APP_ID',
indexName: 'YOUR_INDEX_NAME',
apiKey: 'YOUR_SEARCH_API_KEY',
});
```
## Documentation
[Read documentation →](https://docsearch.algolia.com/docs/DocSearch-v3)

View File

@@ -1,7 +0,0 @@
import type { DocSearchProps as DocSearchComponentProps } from '@docsearch/react';
interface DocSearchProps extends DocSearchComponentProps {
container: HTMLElement | string;
environment?: typeof window;
}
export declare function docsearch(props: DocSearchProps): void;
export {};

View File

@@ -1 +0,0 @@
export { docsearch as default } from './docsearch';

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -1,36 +0,0 @@
{
"name": "@docsearch/js",
"description": "JavaScript package for DocSearch, the best search experience for docs.",
"version": "3.5.2",
"license": "MIT",
"homepage": "https://docsearch.algolia.com",
"repository": "algolia/docsearch",
"author": {
"name": "Algolia, Inc.",
"url": "https://www.algolia.com"
},
"sideEffects": false,
"files": [
"dist/"
],
"source": "src/index.ts",
"types": "dist/esm/index.d.ts",
"module": "dist/esm/index.js",
"main": "dist/umd/index.js",
"umd:main": "dist/umd/index.js",
"unpkg": "dist/umd/index.js",
"jsdelivr": "dist/umd/index.js",
"scripts": {
"build:clean": "rm -rf ./dist",
"build:esm": "cross-env BUILD=esm rollup --config",
"build:types": "tsc -p ./tsconfig.declaration.json --outDir ./dist/esm",
"build:umd": "cross-env BUILD=umd rollup --config",
"build": "yarn build:clean && yarn build:umd && yarn build:esm && yarn build:types",
"on:change": "concurrently \"yarn build:esm\" \"yarn build:types\"",
"watch": "watch \"yarn on:change\" --ignoreDirectoryPattern \"/dist/\""
},
"dependencies": {
"@docsearch/react": "3.5.2",
"preact": "^10.0.0"
}
}

View File

@@ -1,43 +0,0 @@
# @docsearch/react
React package for [DocSearch](http://docsearch.algolia.com/), the best search experience for docs.
## Installation
```bash
yarn add @docsearch/react@3
# or
npm install @docsearch/react@3
```
If you dont want to use a package manager, you can use a standalone endpoint:
```html
<script src="https://cdn.jsdelivr.net/npm/@docsearch/react@3"></script>
```
## Get started
DocSearch generates a fully accessible search box for you.
```jsx App.js
import { DocSearch } from '@docsearch/react';
import '@docsearch/css';
function App() {
return (
<DocSearch
appId="YOUR_APP_ID"
indexName="YOUR_INDEX_NAME"
apiKey="YOUR_SEARCH_API_KEY"
/>
);
}
export default App;
```
## Documentation
[Read documentation →](https://docsearch.algolia.com/docs/DocSearch-v3)

View File

@@ -1 +0,0 @@
export { DocSearchButton } from './dist/esm/DocSearchButton.js';

View File

@@ -1,8 +0,0 @@
declare type AlgoliaLogoTranslations = Partial<{
searchByText: string;
}>;
declare type AlgoliaLogoProps = {
translations?: AlgoliaLogoTranslations;
};
export declare function AlgoliaLogo({ translations }: AlgoliaLogoProps): JSX.Element;
export {};

View File

@@ -1,54 +0,0 @@
import React from 'react';
export function AlgoliaLogo(_ref) {
var _ref$translations = _ref.translations,
translations = _ref$translations === void 0 ? {} : _ref$translations;
var _translations$searchB = translations.searchByText,
searchByText = _translations$searchB === void 0 ? 'Search by' : _translations$searchB;
return /*#__PURE__*/React.createElement("a", {
href: "https://www.algolia.com/ref/docsearch/?utm_source=".concat(window.location.hostname, "&utm_medium=referral&utm_content=powered_by&utm_campaign=docsearch"),
target: "_blank",
rel: "noopener noreferrer"
}, /*#__PURE__*/React.createElement("span", {
className: "DocSearch-Label"
}, searchByText), /*#__PURE__*/React.createElement("svg", {
width: "77",
height: "19",
"aria-label": "Algolia",
role: "img",
id: "Layer_1",
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 2196.2 500"
}, /*#__PURE__*/React.createElement("defs", null, /*#__PURE__*/React.createElement("style", null, ".cls-1,.cls-2{fill:#003dff;}.cls-2{fill-rule:evenodd;}")), /*#__PURE__*/React.createElement("path", {
className: "cls-2",
d: "M1070.38,275.3V5.91c0-3.63-3.24-6.39-6.82-5.83l-50.46,7.94c-2.87,.45-4.99,2.93-4.99,5.84l.17,273.22c0,12.92,0,92.7,95.97,95.49,3.33,.1,6.09-2.58,6.09-5.91v-40.78c0-2.96-2.19-5.51-5.12-5.84-34.85-4.01-34.85-47.57-34.85-54.72Z"
}), /*#__PURE__*/React.createElement("rect", {
className: "cls-1",
x: "1845.88",
y: "104.73",
width: "62.58",
height: "277.9",
rx: "5.9",
ry: "5.9"
}), /*#__PURE__*/React.createElement("path", {
className: "cls-2",
d: "M1851.78,71.38h50.77c3.26,0,5.9-2.64,5.9-5.9V5.9c0-3.62-3.24-6.39-6.82-5.83l-50.77,7.95c-2.87,.45-4.99,2.92-4.99,5.83v51.62c0,3.26,2.64,5.9,5.9,5.9Z"
}), /*#__PURE__*/React.createElement("path", {
className: "cls-2",
d: "M1764.03,275.3V5.91c0-3.63-3.24-6.39-6.82-5.83l-50.46,7.94c-2.87,.45-4.99,2.93-4.99,5.84l.17,273.22c0,12.92,0,92.7,95.97,95.49,3.33,.1,6.09-2.58,6.09-5.91v-40.78c0-2.96-2.19-5.51-5.12-5.84-34.85-4.01-34.85-47.57-34.85-54.72Z"
}), /*#__PURE__*/React.createElement("path", {
className: "cls-2",
d: "M1631.95,142.72c-11.14-12.25-24.83-21.65-40.78-28.31-15.92-6.53-33.26-9.85-52.07-9.85-18.78,0-36.15,3.17-51.92,9.85-15.59,6.66-29.29,16.05-40.76,28.31-11.47,12.23-20.38,26.87-26.76,44.03-6.38,17.17-9.24,37.37-9.24,58.36,0,20.99,3.19,36.87,9.55,54.21,6.38,17.32,15.14,32.11,26.45,44.36,11.29,12.23,24.83,21.62,40.6,28.46,15.77,6.83,40.12,10.33,52.4,10.48,12.25,0,36.78-3.82,52.7-10.48,15.92-6.68,29.46-16.23,40.78-28.46,11.29-12.25,20.05-27.04,26.25-44.36,6.22-17.34,9.24-33.22,9.24-54.21,0-20.99-3.34-41.19-10.03-58.36-6.38-17.17-15.14-31.8-26.43-44.03Zm-44.43,163.75c-11.47,15.75-27.56,23.7-48.09,23.7-20.55,0-36.63-7.8-48.1-23.7-11.47-15.75-17.21-34.01-17.21-61.2,0-26.89,5.59-49.14,17.06-64.87,11.45-15.75,27.54-23.52,48.07-23.52,20.55,0,36.63,7.78,48.09,23.52,11.47,15.57,17.36,37.98,17.36,64.87,0,27.19-5.72,45.3-17.19,61.2Z"
}), /*#__PURE__*/React.createElement("path", {
className: "cls-2",
d: "M894.42,104.73h-49.33c-48.36,0-90.91,25.48-115.75,64.1-14.52,22.58-22.99,49.63-22.99,78.73,0,44.89,20.13,84.92,51.59,111.1,2.93,2.6,6.05,4.98,9.31,7.14,12.86,8.49,28.11,13.47,44.52,13.47,1.23,0,2.46-.03,3.68-.09,.36-.02,.71-.05,1.07-.07,.87-.05,1.75-.11,2.62-.2,.34-.03,.68-.08,1.02-.12,.91-.1,1.82-.21,2.73-.34,.21-.03,.42-.07,.63-.1,32.89-5.07,61.56-30.82,70.9-62.81v57.83c0,3.26,2.64,5.9,5.9,5.9h50.42c3.26,0,5.9-2.64,5.9-5.9V110.63c0-3.26-2.64-5.9-5.9-5.9h-56.32Zm0,206.92c-12.2,10.16-27.97,13.98-44.84,15.12-.16,.01-.33,.03-.49,.04-1.12,.07-2.24,.1-3.36,.1-42.24,0-77.12-35.89-77.12-79.37,0-10.25,1.96-20.01,5.42-28.98,11.22-29.12,38.77-49.74,71.06-49.74h49.33v142.83Z"
}), /*#__PURE__*/React.createElement("path", {
className: "cls-2",
d: "M2133.97,104.73h-49.33c-48.36,0-90.91,25.48-115.75,64.1-14.52,22.58-22.99,49.63-22.99,78.73,0,44.89,20.13,84.92,51.59,111.1,2.93,2.6,6.05,4.98,9.31,7.14,12.86,8.49,28.11,13.47,44.52,13.47,1.23,0,2.46-.03,3.68-.09,.36-.02,.71-.05,1.07-.07,.87-.05,1.75-.11,2.62-.2,.34-.03,.68-.08,1.02-.12,.91-.1,1.82-.21,2.73-.34,.21-.03,.42-.07,.63-.1,32.89-5.07,61.56-30.82,70.9-62.81v57.83c0,3.26,2.64,5.9,5.9,5.9h50.42c3.26,0,5.9-2.64,5.9-5.9V110.63c0-3.26-2.64-5.9-5.9-5.9h-56.32Zm0,206.92c-12.2,10.16-27.97,13.98-44.84,15.12-.16,.01-.33,.03-.49,.04-1.12,.07-2.24,.1-3.36,.1-42.24,0-77.12-35.89-77.12-79.37,0-10.25,1.96-20.01,5.42-28.98,11.22-29.12,38.77-49.74,71.06-49.74h49.33v142.83Z"
}), /*#__PURE__*/React.createElement("path", {
className: "cls-2",
d: "M1314.05,104.73h-49.33c-48.36,0-90.91,25.48-115.75,64.1-11.79,18.34-19.6,39.64-22.11,62.59-.58,5.3-.88,10.68-.88,16.14s.31,11.15,.93,16.59c4.28,38.09,23.14,71.61,50.66,94.52,2.93,2.6,6.05,4.98,9.31,7.14,12.86,8.49,28.11,13.47,44.52,13.47h0c17.99,0,34.61-5.93,48.16-15.97,16.29-11.58,28.88-28.54,34.48-47.75v50.26h-.11v11.08c0,21.84-5.71,38.27-17.34,49.36-11.61,11.08-31.04,16.63-58.25,16.63-11.12,0-28.79-.59-46.6-2.41-2.83-.29-5.46,1.5-6.27,4.22l-12.78,43.11c-1.02,3.46,1.27,7.02,4.83,7.53,21.52,3.08,42.52,4.68,54.65,4.68,48.91,0,85.16-10.75,108.89-32.21,21.48-19.41,33.15-48.89,35.2-88.52V110.63c0-3.26-2.64-5.9-5.9-5.9h-56.32Zm0,64.1s.65,139.13,0,143.36c-12.08,9.77-27.11,13.59-43.49,14.7-.16,.01-.33,.03-.49,.04-1.12,.07-2.24,.1-3.36,.1-1.32,0-2.63-.03-3.94-.1-40.41-2.11-74.52-37.26-74.52-79.38,0-10.25,1.96-20.01,5.42-28.98,11.22-29.12,38.77-49.74,71.06-49.74h49.33Z"
}), /*#__PURE__*/React.createElement("path", {
className: "cls-1",
d: "M249.83,0C113.3,0,2,110.09,.03,246.16c-2,138.19,110.12,252.7,248.33,253.5,42.68,.25,83.79-10.19,120.3-30.03,3.56-1.93,4.11-6.83,1.08-9.51l-23.38-20.72c-4.75-4.21-11.51-5.4-17.36-2.92-25.48,10.84-53.17,16.38-81.71,16.03-111.68-1.37-201.91-94.29-200.13-205.96,1.76-110.26,92-199.41,202.67-199.41h202.69V407.41l-115-102.18c-3.72-3.31-9.42-2.66-12.42,1.31-18.46,24.44-48.53,39.64-81.93,37.34-46.33-3.2-83.87-40.5-87.34-86.81-4.15-55.24,39.63-101.52,94-101.52,49.18,0,89.68,37.85,93.91,85.95,.38,4.28,2.31,8.27,5.52,11.12l29.95,26.55c3.4,3.01,8.79,1.17,9.63-3.3,2.16-11.55,2.92-23.58,2.07-35.92-4.82-70.34-61.8-126.93-132.17-131.26-80.68-4.97-148.13,58.14-150.27,137.25-2.09,77.1,61.08,143.56,138.19,145.26,32.19,.71,62.03-9.41,86.14-26.95l150.26,133.2c6.44,5.71,16.61,1.14,16.61-7.47V9.48C499.66,4.25,495.42,0,490.18,0H249.83Z"
})));
}

View File

@@ -1,36 +0,0 @@
import type { AutocompleteState, AutocompleteOptions } from '@algolia/autocomplete-core';
import type { SearchOptions } from '@algolia/client-search';
import type { SearchClient } from 'algoliasearch/lite';
import React from 'react';
import type { DocSearchHit, InternalDocSearchHit, StoredDocSearchHit } from './types';
import type { ButtonTranslations, ModalTranslations } from '.';
export declare type DocSearchTranslations = Partial<{
button: ButtonTranslations;
modal: ModalTranslations;
}>;
export interface DocSearchProps {
appId: string;
apiKey: string;
indexName: string;
placeholder?: string;
searchParameters?: SearchOptions;
maxResultsPerGroup?: number;
transformItems?: (items: DocSearchHit[]) => DocSearchHit[];
hitComponent?: (props: {
hit: InternalDocSearchHit | StoredDocSearchHit;
children: React.ReactNode;
}) => JSX.Element;
resultsFooterComponent?: (props: {
state: AutocompleteState<InternalDocSearchHit>;
}) => JSX.Element | null;
transformSearchClient?: (searchClient: SearchClient) => SearchClient;
disableUserPersonalization?: boolean;
initialQuery?: string;
navigator?: AutocompleteOptions<InternalDocSearchHit>['navigator'];
translations?: DocSearchTranslations;
getMissingResultsUrl?: ({ query }: {
query: string;
}) => string;
insights?: AutocompleteOptions<InternalDocSearchHit>['insights'];
}
export declare function DocSearch(props: DocSearchProps): JSX.Element;

View File

@@ -1,62 +0,0 @@
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); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React from 'react';
import { createPortal } from 'react-dom';
import { DocSearchButton } from './DocSearchButton';
import { DocSearchModal } from './DocSearchModal';
import { useDocSearchKeyboardEvents } from './useDocSearchKeyboardEvents';
export function DocSearch(props) {
var _props$translations, _props$translations2;
var searchButtonRef = React.useRef(null);
var _React$useState = React.useState(false),
_React$useState2 = _slicedToArray(_React$useState, 2),
isOpen = _React$useState2[0],
setIsOpen = _React$useState2[1];
var _React$useState3 = React.useState((props === null || props === void 0 ? void 0 : props.initialQuery) || undefined),
_React$useState4 = _slicedToArray(_React$useState3, 2),
initialQuery = _React$useState4[0],
setInitialQuery = _React$useState4[1];
var onOpen = React.useCallback(function () {
setIsOpen(true);
}, [setIsOpen]);
var onClose = React.useCallback(function () {
setIsOpen(false);
}, [setIsOpen]);
var onInput = React.useCallback(function (event) {
setIsOpen(true);
setInitialQuery(event.key);
}, [setIsOpen, setInitialQuery]);
useDocSearchKeyboardEvents({
isOpen: isOpen,
onOpen: onOpen,
onClose: onClose,
onInput: onInput,
searchButtonRef: searchButtonRef
});
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DocSearchButton, {
ref: searchButtonRef,
translations: props === null || props === void 0 || (_props$translations = props.translations) === null || _props$translations === void 0 ? void 0 : _props$translations.button,
onClick: onOpen
}), isOpen && createPortal( /*#__PURE__*/React.createElement(DocSearchModal, _extends({}, props, {
initialScrollY: window.scrollY,
initialQuery: initialQuery,
translations: props === null || props === void 0 || (_props$translations2 = props.translations) === null || _props$translations2 === void 0 ? void 0 : _props$translations2.modal,
onClose: onClose
})), document.body));
}

View File

@@ -1,9 +0,0 @@
import React from 'react';
export declare type ButtonTranslations = Partial<{
buttonText: string;
buttonAriaLabel: string;
}>;
export declare type DocSearchButtonProps = React.ComponentProps<'button'> & {
translations?: ButtonTranslations;
};
export declare const DocSearchButton: React.ForwardRefExoticComponent<Pick<DocSearchButtonProps, "translations" | "key" | keyof React.ButtonHTMLAttributes<HTMLButtonElement>> & React.RefAttributes<HTMLButtonElement>>;

View File

@@ -1,68 +0,0 @@
var _excluded = ["translations"];
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); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
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; }
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; }
import React, { useEffect, useState } from 'react';
import { ControlKeyIcon } from './icons/ControlKeyIcon';
import { SearchIcon } from './icons/SearchIcon';
var ACTION_KEY_DEFAULT = 'Ctrl';
var ACTION_KEY_APPLE = '⌘';
function isAppleDevice() {
return /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform);
}
export var DocSearchButton = React.forwardRef(function (_ref, ref) {
var _ref$translations = _ref.translations,
translations = _ref$translations === void 0 ? {} : _ref$translations,
props = _objectWithoutProperties(_ref, _excluded);
var _translations$buttonT = translations.buttonText,
buttonText = _translations$buttonT === void 0 ? 'Search' : _translations$buttonT,
_translations$buttonA = translations.buttonAriaLabel,
buttonAriaLabel = _translations$buttonA === void 0 ? 'Search' : _translations$buttonA;
var _useState = useState(null),
_useState2 = _slicedToArray(_useState, 2),
key = _useState2[0],
setKey = _useState2[1];
useEffect(function () {
if (typeof navigator !== 'undefined') {
isAppleDevice() ? setKey(ACTION_KEY_APPLE) : setKey(ACTION_KEY_DEFAULT);
}
}, []);
return /*#__PURE__*/React.createElement("button", _extends({
type: "button",
className: "DocSearch DocSearch-Button",
"aria-label": buttonAriaLabel
}, props, {
ref: ref
}), /*#__PURE__*/React.createElement("span", {
className: "DocSearch-Button-Container"
}, /*#__PURE__*/React.createElement(SearchIcon, null), /*#__PURE__*/React.createElement("span", {
className: "DocSearch-Button-Placeholder"
}, buttonText)), /*#__PURE__*/React.createElement("span", {
className: "DocSearch-Button-Keys"
}, key !== null && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("kbd", {
className: "DocSearch-Button-Key"
}, key === ACTION_KEY_DEFAULT ? /*#__PURE__*/React.createElement(ControlKeyIcon, null) : key), /*#__PURE__*/React.createElement("kbd", {
className: "DocSearch-Button-Key"
}, "K"))));
});

View File

@@ -1,14 +0,0 @@
import type { DocSearchProps } from './DocSearch';
import type { FooterTranslations } from './Footer';
import type { ScreenStateTranslations } from './ScreenState';
import type { SearchBoxTranslations } from './SearchBox';
export declare type ModalTranslations = Partial<{
searchBox: SearchBoxTranslations;
footer: FooterTranslations;
}> & ScreenStateTranslations;
export declare type DocSearchModalProps = DocSearchProps & {
initialScrollY: number;
onClose?: () => void;
translations?: ModalTranslations;
};
export declare function DocSearchModal({ appId, apiKey, indexName, placeholder, searchParameters, maxResultsPerGroup, onClose, transformItems, hitComponent, resultsFooterComponent, navigator, initialScrollY, transformSearchClient, disableUserPersonalization, initialQuery: initialQueryFromProp, translations, getMissingResultsUrl, insights, }: DocSearchModalProps): JSX.Element;

View File

@@ -1,418 +0,0 @@
var _excluded = ["footer", "searchBox"];
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); }
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; }
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; }
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; }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
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; }
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; }
import { createAutocomplete } from '@algolia/autocomplete-core';
import React from 'react';
import { MAX_QUERY_SIZE } from './constants';
import { Footer } from './Footer';
import { Hit } from './Hit';
import { ScreenState } from './ScreenState';
import { SearchBox } from './SearchBox';
import { createStoredSearches } from './stored-searches';
import { useSearchClient } from './useSearchClient';
import { useTouchEvents } from './useTouchEvents';
import { useTrapFocus } from './useTrapFocus';
import { groupBy, identity, noop, removeHighlightTags, isModifierEvent } from './utils';
export function DocSearchModal(_ref) {
var appId = _ref.appId,
apiKey = _ref.apiKey,
indexName = _ref.indexName,
_ref$placeholder = _ref.placeholder,
placeholder = _ref$placeholder === void 0 ? 'Search docs' : _ref$placeholder,
searchParameters = _ref.searchParameters,
maxResultsPerGroup = _ref.maxResultsPerGroup,
_ref$onClose = _ref.onClose,
onClose = _ref$onClose === void 0 ? noop : _ref$onClose,
_ref$transformItems = _ref.transformItems,
transformItems = _ref$transformItems === void 0 ? identity : _ref$transformItems,
_ref$hitComponent = _ref.hitComponent,
hitComponent = _ref$hitComponent === void 0 ? Hit : _ref$hitComponent,
_ref$resultsFooterCom = _ref.resultsFooterComponent,
resultsFooterComponent = _ref$resultsFooterCom === void 0 ? function () {
return null;
} : _ref$resultsFooterCom,
navigator = _ref.navigator,
_ref$initialScrollY = _ref.initialScrollY,
initialScrollY = _ref$initialScrollY === void 0 ? 0 : _ref$initialScrollY,
_ref$transformSearchC = _ref.transformSearchClient,
transformSearchClient = _ref$transformSearchC === void 0 ? identity : _ref$transformSearchC,
_ref$disableUserPerso = _ref.disableUserPersonalization,
disableUserPersonalization = _ref$disableUserPerso === void 0 ? false : _ref$disableUserPerso,
_ref$initialQuery = _ref.initialQuery,
initialQueryFromProp = _ref$initialQuery === void 0 ? '' : _ref$initialQuery,
_ref$translations = _ref.translations,
translations = _ref$translations === void 0 ? {} : _ref$translations,
getMissingResultsUrl = _ref.getMissingResultsUrl,
_ref$insights = _ref.insights,
insights = _ref$insights === void 0 ? false : _ref$insights;
var footerTranslations = translations.footer,
searchBoxTranslations = translations.searchBox,
screenStateTranslations = _objectWithoutProperties(translations, _excluded);
var _React$useState = React.useState({
query: '',
collections: [],
completion: null,
context: {},
isOpen: false,
activeItemId: null,
status: 'idle'
}),
_React$useState2 = _slicedToArray(_React$useState, 2),
state = _React$useState2[0],
setState = _React$useState2[1];
var containerRef = React.useRef(null);
var modalRef = React.useRef(null);
var formElementRef = React.useRef(null);
var dropdownRef = React.useRef(null);
var inputRef = React.useRef(null);
var snippetLength = React.useRef(10);
var initialQueryFromSelection = React.useRef(typeof window !== 'undefined' ? window.getSelection().toString().slice(0, MAX_QUERY_SIZE) : '').current;
var initialQuery = React.useRef(initialQueryFromProp || initialQueryFromSelection).current;
var searchClient = useSearchClient(appId, apiKey, transformSearchClient);
var favoriteSearches = React.useRef(createStoredSearches({
key: "__DOCSEARCH_FAVORITE_SEARCHES__".concat(indexName),
limit: 10
})).current;
var recentSearches = React.useRef(createStoredSearches({
key: "__DOCSEARCH_RECENT_SEARCHES__".concat(indexName),
// We display 7 recent searches and there's no favorites, but only
// 4 when there are favorites.
limit: favoriteSearches.getAll().length === 0 ? 7 : 4
})).current;
var saveRecentSearch = React.useCallback(function saveRecentSearch(item) {
if (disableUserPersonalization) {
return;
} // We don't store `content` record, but their parent if available.
var search = item.type === 'content' ? item.__docsearch_parent : item; // We save the recent search only if it's not favorited.
if (search && favoriteSearches.getAll().findIndex(function (x) {
return x.objectID === search.objectID;
}) === -1) {
recentSearches.add(search);
}
}, [favoriteSearches, recentSearches, disableUserPersonalization]);
var sendItemClickEvent = React.useCallback(function (item) {
if (!state.context.algoliaInsightsPlugin || !item.__autocomplete_id) return;
var insightsItem = item;
var insightsClickParams = {
eventName: 'Item Selected',
index: insightsItem.__autocomplete_indexName,
items: [insightsItem],
positions: [item.__autocomplete_id],
queryID: insightsItem.__autocomplete_queryID
};
state.context.algoliaInsightsPlugin.insights.clickedObjectIDsAfterSearch(insightsClickParams);
}, [state.context.algoliaInsightsPlugin]);
var autocomplete = React.useMemo(function () {
return createAutocomplete({
id: 'docsearch',
defaultActiveItemId: 0,
placeholder: placeholder,
openOnFocus: true,
initialState: {
query: initialQuery,
context: {
searchSuggestions: []
}
},
insights: insights,
navigator: navigator,
onStateChange: function onStateChange(props) {
setState(props.state);
},
getSources: function getSources(_ref2) {
var query = _ref2.query,
sourcesState = _ref2.state,
setContext = _ref2.setContext,
setStatus = _ref2.setStatus;
if (!query) {
if (disableUserPersonalization) {
return [];
}
return [{
sourceId: 'recentSearches',
onSelect: function onSelect(_ref3) {
var item = _ref3.item,
event = _ref3.event;
saveRecentSearch(item);
if (!isModifierEvent(event)) {
onClose();
}
},
getItemUrl: function getItemUrl(_ref4) {
var item = _ref4.item;
return item.url;
},
getItems: function getItems() {
return recentSearches.getAll();
}
}, {
sourceId: 'favoriteSearches',
onSelect: function onSelect(_ref5) {
var item = _ref5.item,
event = _ref5.event;
saveRecentSearch(item);
if (!isModifierEvent(event)) {
onClose();
}
},
getItemUrl: function getItemUrl(_ref6) {
var item = _ref6.item;
return item.url;
},
getItems: function getItems() {
return favoriteSearches.getAll();
}
}];
}
var insightsActive = Boolean(insights);
return searchClient.search([{
query: query,
indexName: indexName,
params: _objectSpread({
attributesToRetrieve: ['hierarchy.lvl0', 'hierarchy.lvl1', 'hierarchy.lvl2', 'hierarchy.lvl3', 'hierarchy.lvl4', 'hierarchy.lvl5', 'hierarchy.lvl6', 'content', 'type', 'url'],
attributesToSnippet: ["hierarchy.lvl1:".concat(snippetLength.current), "hierarchy.lvl2:".concat(snippetLength.current), "hierarchy.lvl3:".concat(snippetLength.current), "hierarchy.lvl4:".concat(snippetLength.current), "hierarchy.lvl5:".concat(snippetLength.current), "hierarchy.lvl6:".concat(snippetLength.current), "content:".concat(snippetLength.current)],
snippetEllipsisText: '…',
highlightPreTag: '<mark>',
highlightPostTag: '</mark>',
hitsPerPage: 20,
clickAnalytics: insightsActive
}, searchParameters)
}]).catch(function (error) {
// The Algolia `RetryError` happens when all the servers have
// failed, meaning that there's no chance the response comes
// back. This is the right time to display an error.
// See https://github.com/algolia/algoliasearch-client-javascript/blob/2ffddf59bc765cd1b664ee0346b28f00229d6e12/packages/transporter/src/errors/createRetryError.ts#L5
if (error.name === 'RetryError') {
setStatus('error');
}
throw error;
}).then(function (_ref7) {
var results = _ref7.results;
var firstResult = results[0];
var hits = firstResult.hits,
nbHits = firstResult.nbHits;
var sources = groupBy(hits, function (hit) {
return removeHighlightTags(hit);
}, maxResultsPerGroup); // We store the `lvl0`s to display them as search suggestions
// in the "no results" screen.
if (sourcesState.context.searchSuggestions.length < Object.keys(sources).length) {
setContext({
searchSuggestions: Object.keys(sources)
});
}
setContext({
nbHits: nbHits
});
var insightsParams = {};
if (insightsActive) {
insightsParams = {
__autocomplete_indexName: indexName,
__autocomplete_queryID: firstResult.queryID,
__autocomplete_algoliaCredentials: {
appId: appId,
apiKey: apiKey
}
};
}
return Object.values(sources).map(function (items, index) {
return {
sourceId: "hits".concat(index),
onSelect: function onSelect(_ref8) {
var item = _ref8.item,
event = _ref8.event;
saveRecentSearch(item);
if (!isModifierEvent(event)) {
onClose();
}
},
getItemUrl: function getItemUrl(_ref9) {
var item = _ref9.item;
return item.url;
},
getItems: function getItems() {
return Object.values(groupBy(items, function (item) {
return item.hierarchy.lvl1;
}, maxResultsPerGroup)).map(transformItems).map(function (groupedHits) {
return groupedHits.map(function (item) {
var parent = null;
var potentialParent = groupedHits.find(function (siblingItem) {
return siblingItem.type === 'lvl1' && siblingItem.hierarchy.lvl1 === item.hierarchy.lvl1;
});
if (item.type !== 'lvl1' && potentialParent) {
parent = potentialParent;
}
return _objectSpread(_objectSpread({}, item), {}, {
__docsearch_parent: parent
}, insightsParams);
});
}).flat();
}
};
});
});
}
});
}, [indexName, searchParameters, maxResultsPerGroup, searchClient, onClose, recentSearches, favoriteSearches, saveRecentSearch, initialQuery, placeholder, navigator, transformItems, disableUserPersonalization, insights, appId, apiKey]);
var getEnvironmentProps = autocomplete.getEnvironmentProps,
getRootProps = autocomplete.getRootProps,
refresh = autocomplete.refresh;
useTouchEvents({
getEnvironmentProps: getEnvironmentProps,
panelElement: dropdownRef.current,
formElement: formElementRef.current,
inputElement: inputRef.current
});
useTrapFocus({
container: containerRef.current
});
React.useEffect(function () {
document.body.classList.add('DocSearch--active');
return function () {
var _window$scrollTo, _window;
document.body.classList.remove('DocSearch--active'); // IE11 doesn't support `scrollTo` so we check that the method exists
// first.
(_window$scrollTo = (_window = window).scrollTo) === null || _window$scrollTo === void 0 ? void 0 : _window$scrollTo.call(_window, 0, initialScrollY);
}; // eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
React.useEffect(function () {
var isMobileMediaQuery = window.matchMedia('(max-width: 768px)');
if (isMobileMediaQuery.matches) {
snippetLength.current = 5;
}
}, []);
React.useEffect(function () {
if (dropdownRef.current) {
dropdownRef.current.scrollTop = 0;
}
}, [state.query]); // We don't focus the input when there's an initial query (i.e. Selection
// Search) because users rather want to see the results directly, without the
// keyboard appearing.
// We therefore need to refresh the autocomplete instance to load all the
// results, which is usually triggered on focus.
React.useEffect(function () {
if (initialQuery.length > 0) {
refresh();
if (inputRef.current) {
inputRef.current.focus();
}
}
}, [initialQuery, refresh]); // We rely on a CSS property to set the modal height to the full viewport height
// because all mobile browsers don't compute their height the same way.
// See https://css-tricks.com/the-trick-to-viewport-units-on-mobile/
React.useEffect(function () {
function setFullViewportHeight() {
if (modalRef.current) {
var vh = window.innerHeight * 0.01;
modalRef.current.style.setProperty('--docsearch-vh', "".concat(vh, "px"));
}
}
setFullViewportHeight();
window.addEventListener('resize', setFullViewportHeight);
return function () {
window.removeEventListener('resize', setFullViewportHeight);
};
}, []);
return /*#__PURE__*/React.createElement("div", _extends({
ref: containerRef
}, getRootProps({
'aria-expanded': true
}), {
className: ['DocSearch', 'DocSearch-Container', state.status === 'stalled' && 'DocSearch-Container--Stalled', state.status === 'error' && 'DocSearch-Container--Errored'].filter(Boolean).join(' '),
role: "button",
tabIndex: 0,
onMouseDown: function onMouseDown(event) {
if (event.target === event.currentTarget) {
onClose();
}
}
}), /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Modal",
ref: modalRef
}, /*#__PURE__*/React.createElement("header", {
className: "DocSearch-SearchBar",
ref: formElementRef
}, /*#__PURE__*/React.createElement(SearchBox, _extends({}, autocomplete, {
state: state,
autoFocus: initialQuery.length === 0,
inputRef: inputRef,
isFromSelection: Boolean(initialQuery) && initialQuery === initialQueryFromSelection,
translations: searchBoxTranslations,
onClose: onClose
}))), /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Dropdown",
ref: dropdownRef
}, /*#__PURE__*/React.createElement(ScreenState, _extends({}, autocomplete, {
indexName: indexName,
state: state,
hitComponent: hitComponent,
resultsFooterComponent: resultsFooterComponent,
disableUserPersonalization: disableUserPersonalization,
recentSearches: recentSearches,
favoriteSearches: favoriteSearches,
inputRef: inputRef,
translations: screenStateTranslations,
getMissingResultsUrl: getMissingResultsUrl,
onItemClick: function onItemClick(item, event) {
// If insights is active, send insights click event
sendItemClickEvent(item);
saveRecentSearch(item);
if (!isModifierEvent(event)) {
onClose();
}
}
}))), /*#__PURE__*/React.createElement("footer", {
className: "DocSearch-Footer"
}, /*#__PURE__*/React.createElement(Footer, {
translations: footerTranslations
}))));
}

View File

@@ -1,9 +0,0 @@
export declare type ErrorScreenTranslations = Partial<{
titleText: string;
helpText: string;
}>;
declare type ErrorScreenProps = {
translations?: ErrorScreenTranslations;
};
export declare function ErrorScreen({ translations }: ErrorScreenProps): JSX.Element;
export {};

View File

@@ -1,19 +0,0 @@
import React from 'react';
import { ErrorIcon } from './icons';
export function ErrorScreen(_ref) {
var _ref$translations = _ref.translations,
translations = _ref$translations === void 0 ? {} : _ref$translations;
var _translations$titleTe = translations.titleText,
titleText = _translations$titleTe === void 0 ? 'Unable to fetch results' : _translations$titleTe,
_translations$helpTex = translations.helpText,
helpText = _translations$helpTex === void 0 ? 'You might want to check your network connection.' : _translations$helpTex;
return /*#__PURE__*/React.createElement("div", {
className: "DocSearch-ErrorScreen"
}, /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Screen-Icon"
}, /*#__PURE__*/React.createElement(ErrorIcon, null)), /*#__PURE__*/React.createElement("p", {
className: "DocSearch-Title"
}, titleText), /*#__PURE__*/React.createElement("p", {
className: "DocSearch-Help"
}, helpText));
}

View File

@@ -1,15 +0,0 @@
export declare type FooterTranslations = Partial<{
selectText: string;
selectKeyAriaLabel: string;
navigateText: string;
navigateUpKeyAriaLabel: string;
navigateDownKeyAriaLabel: string;
closeText: string;
closeKeyAriaLabel: string;
searchByText: string;
}>;
declare type FooterProps = Partial<{
translations: FooterTranslations;
}>;
export declare function Footer({ translations }: FooterProps): JSX.Element;
export {};

View File

@@ -1,77 +0,0 @@
import React from 'react';
import { AlgoliaLogo } from './AlgoliaLogo';
function CommandIcon(props) {
return /*#__PURE__*/React.createElement("svg", {
width: "15",
height: "15",
"aria-label": props.ariaLabel,
role: "img"
}, /*#__PURE__*/React.createElement("g", {
fill: "none",
stroke: "currentColor",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeWidth: "1.2"
}, props.children));
}
export function Footer(_ref) {
var _ref$translations = _ref.translations,
translations = _ref$translations === void 0 ? {} : _ref$translations;
var _translations$selectT = translations.selectText,
selectText = _translations$selectT === void 0 ? 'to select' : _translations$selectT,
_translations$selectK = translations.selectKeyAriaLabel,
selectKeyAriaLabel = _translations$selectK === void 0 ? 'Enter key' : _translations$selectK,
_translations$navigat = translations.navigateText,
navigateText = _translations$navigat === void 0 ? 'to navigate' : _translations$navigat,
_translations$navigat2 = translations.navigateUpKeyAriaLabel,
navigateUpKeyAriaLabel = _translations$navigat2 === void 0 ? 'Arrow up' : _translations$navigat2,
_translations$navigat3 = translations.navigateDownKeyAriaLabel,
navigateDownKeyAriaLabel = _translations$navigat3 === void 0 ? 'Arrow down' : _translations$navigat3,
_translations$closeTe = translations.closeText,
closeText = _translations$closeTe === void 0 ? 'to close' : _translations$closeTe,
_translations$closeKe = translations.closeKeyAriaLabel,
closeKeyAriaLabel = _translations$closeKe === void 0 ? 'Escape key' : _translations$closeKe,
_translations$searchB = translations.searchByText,
searchByText = _translations$searchB === void 0 ? 'Search by' : _translations$searchB;
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Logo"
}, /*#__PURE__*/React.createElement(AlgoliaLogo, {
translations: {
searchByText: searchByText
}
})), /*#__PURE__*/React.createElement("ul", {
className: "DocSearch-Commands"
}, /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement("kbd", {
className: "DocSearch-Commands-Key"
}, /*#__PURE__*/React.createElement(CommandIcon, {
ariaLabel: selectKeyAriaLabel
}, /*#__PURE__*/React.createElement("path", {
d: "M12 3.53088v3c0 1-1 2-2 2H4M7 11.53088l-3-3 3-3"
}))), /*#__PURE__*/React.createElement("span", {
className: "DocSearch-Label"
}, selectText)), /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement("kbd", {
className: "DocSearch-Commands-Key"
}, /*#__PURE__*/React.createElement(CommandIcon, {
ariaLabel: navigateDownKeyAriaLabel
}, /*#__PURE__*/React.createElement("path", {
d: "M7.5 3.5v8M10.5 8.5l-3 3-3-3"
}))), /*#__PURE__*/React.createElement("kbd", {
className: "DocSearch-Commands-Key"
}, /*#__PURE__*/React.createElement(CommandIcon, {
ariaLabel: navigateUpKeyAriaLabel
}, /*#__PURE__*/React.createElement("path", {
d: "M7.5 11.5v-8M10.5 6.5l-3-3-3 3"
}))), /*#__PURE__*/React.createElement("span", {
className: "DocSearch-Label"
}, navigateText)), /*#__PURE__*/React.createElement("li", null, /*#__PURE__*/React.createElement("kbd", {
className: "DocSearch-Commands-Key"
}, /*#__PURE__*/React.createElement(CommandIcon, {
ariaLabel: closeKeyAriaLabel
}, /*#__PURE__*/React.createElement("path", {
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"
}))), /*#__PURE__*/React.createElement("span", {
className: "DocSearch-Label"
}, closeText))));
}

View File

@@ -1,8 +0,0 @@
import React from 'react';
import type { InternalDocSearchHit, StoredDocSearchHit } from './types';
interface HitProps {
hit: InternalDocSearchHit | StoredDocSearchHit;
children: React.ReactNode;
}
export declare function Hit({ hit, children }: HitProps): JSX.Element;
export {};

View File

@@ -1,8 +0,0 @@
import React from 'react';
export function Hit(_ref) {
var hit = _ref.hit,
children = _ref.children;
return /*#__PURE__*/React.createElement("a", {
href: hit.url
}, children);
}

View File

@@ -1,13 +0,0 @@
import type { ScreenStateProps } from './ScreenState';
import type { InternalDocSearchHit } from './types';
export declare type NoResultsScreenTranslations = Partial<{
noResultsText: string;
suggestedQueryText: string;
reportMissingResultsText: string;
reportMissingResultsLinkText: string;
}>;
declare type NoResultsScreenProps = Omit<ScreenStateProps<InternalDocSearchHit>, 'translations'> & {
translations?: NoResultsScreenTranslations;
};
export declare function NoResultsScreen({ translations, ...props }: NoResultsScreenProps): JSX.Element;
export {};

View File

@@ -1,67 +0,0 @@
var _excluded = ["translations"];
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
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; }
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; }
import React from 'react';
import { NoResultsIcon } from './icons';
export function NoResultsScreen(_ref) {
var _ref$translations = _ref.translations,
translations = _ref$translations === void 0 ? {} : _ref$translations,
props = _objectWithoutProperties(_ref, _excluded);
var _translations$noResul = translations.noResultsText,
noResultsText = _translations$noResul === void 0 ? 'No results for' : _translations$noResul,
_translations$suggest = translations.suggestedQueryText,
suggestedQueryText = _translations$suggest === void 0 ? 'Try searching for' : _translations$suggest,
_translations$reportM = translations.reportMissingResultsText,
reportMissingResultsText = _translations$reportM === void 0 ? 'Believe this query should return results?' : _translations$reportM,
_translations$reportM2 = translations.reportMissingResultsLinkText,
reportMissingResultsLinkText = _translations$reportM2 === void 0 ? 'Let us know.' : _translations$reportM2;
var searchSuggestions = props.state.context.searchSuggestions;
return /*#__PURE__*/React.createElement("div", {
className: "DocSearch-NoResults"
}, /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Screen-Icon"
}, /*#__PURE__*/React.createElement(NoResultsIcon, null)), /*#__PURE__*/React.createElement("p", {
className: "DocSearch-Title"
}, noResultsText, " \"", /*#__PURE__*/React.createElement("strong", null, props.state.query), "\""), searchSuggestions && searchSuggestions.length > 0 && /*#__PURE__*/React.createElement("div", {
className: "DocSearch-NoResults-Prefill-List"
}, /*#__PURE__*/React.createElement("p", {
className: "DocSearch-Help"
}, suggestedQueryText, ":"), /*#__PURE__*/React.createElement("ul", null, searchSuggestions.slice(0, 3).reduce(function (acc, search) {
return [].concat(_toConsumableArray(acc), [/*#__PURE__*/React.createElement("li", {
key: search
}, /*#__PURE__*/React.createElement("button", {
className: "DocSearch-Prefill",
key: search,
type: "button",
onClick: function onClick() {
props.setQuery(search.toLowerCase() + ' ');
props.refresh();
props.inputRef.current.focus();
}
}, search))]);
}, []))), props.getMissingResultsUrl && /*#__PURE__*/React.createElement("p", {
className: "DocSearch-Help"
}, "".concat(reportMissingResultsText, " "), /*#__PURE__*/React.createElement("a", {
href: props.getMissingResultsUrl({
query: props.state.query
}),
target: "_blank",
rel: "noopener noreferrer"
}, reportMissingResultsLinkText)));
}

View File

@@ -1,21 +0,0 @@
import type { AutocompleteApi, AutocompleteState, BaseItem } from '@algolia/autocomplete-core';
import React from 'react';
import type { DocSearchProps } from './DocSearch';
import type { StoredDocSearchHit } from './types';
interface ResultsProps<TItem extends BaseItem> extends AutocompleteApi<TItem, React.FormEvent, React.MouseEvent, React.KeyboardEvent> {
title: string;
collection: AutocompleteState<TItem>['collections'][0];
renderIcon: (props: {
item: TItem;
index: number;
}) => React.ReactNode;
renderAction: (props: {
item: TItem;
runDeleteTransition: (cb: () => void) => void;
runFavoriteTransition: (cb: () => void) => void;
}) => React.ReactNode;
onItemClick: (item: TItem, event: KeyboardEvent | MouseEvent) => void;
hitComponent: DocSearchProps['hitComponent'];
}
export declare function Results<TItem extends StoredDocSearchHit>(props: ResultsProps<TItem>): JSX.Element | null;
export {};

View File

@@ -1,123 +0,0 @@
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
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); }
import React from 'react';
import { Snippet } from './Snippet';
export function Results(props) {
if (!props.collection || props.collection.items.length === 0) {
return null;
}
return /*#__PURE__*/React.createElement("section", {
className: "DocSearch-Hits"
}, /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Hit-source"
}, props.title), /*#__PURE__*/React.createElement("ul", props.getListProps(), props.collection.items.map(function (item, index) {
return /*#__PURE__*/React.createElement(Result, _extends({
key: [props.title, item.objectID].join(':'),
item: item,
index: index
}, props));
})));
}
function Result(_ref) {
var item = _ref.item,
index = _ref.index,
renderIcon = _ref.renderIcon,
renderAction = _ref.renderAction,
getItemProps = _ref.getItemProps,
onItemClick = _ref.onItemClick,
collection = _ref.collection,
hitComponent = _ref.hitComponent;
var _React$useState = React.useState(false),
_React$useState2 = _slicedToArray(_React$useState, 2),
isDeleting = _React$useState2[0],
setIsDeleting = _React$useState2[1];
var _React$useState3 = React.useState(false),
_React$useState4 = _slicedToArray(_React$useState3, 2),
isFavoriting = _React$useState4[0],
setIsFavoriting = _React$useState4[1];
var action = React.useRef(null);
var Hit = hitComponent;
function runDeleteTransition(cb) {
setIsDeleting(true);
action.current = cb;
}
function runFavoriteTransition(cb) {
setIsFavoriting(true);
action.current = cb;
}
return /*#__PURE__*/React.createElement("li", _extends({
className: ['DocSearch-Hit', item.__docsearch_parent && 'DocSearch-Hit--Child', isDeleting && 'DocSearch-Hit--deleting', isFavoriting && 'DocSearch-Hit--favoriting'].filter(Boolean).join(' '),
onTransitionEnd: function onTransitionEnd() {
if (action.current) {
action.current();
}
}
}, getItemProps({
item: item,
source: collection.source,
onClick: function onClick(event) {
onItemClick(item, event);
}
})), /*#__PURE__*/React.createElement(Hit, {
hit: item
}, /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Hit-Container"
}, renderIcon({
item: item,
index: index
}), item.hierarchy[item.type] && item.type === 'lvl1' && /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Hit-content-wrapper"
}, /*#__PURE__*/React.createElement(Snippet, {
className: "DocSearch-Hit-title",
hit: item,
attribute: "hierarchy.lvl1"
}), item.content && /*#__PURE__*/React.createElement(Snippet, {
className: "DocSearch-Hit-path",
hit: item,
attribute: "content"
})), item.hierarchy[item.type] && (item.type === 'lvl2' || item.type === 'lvl3' || item.type === 'lvl4' || item.type === 'lvl5' || item.type === 'lvl6') && /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Hit-content-wrapper"
}, /*#__PURE__*/React.createElement(Snippet, {
className: "DocSearch-Hit-title",
hit: item,
attribute: "hierarchy.".concat(item.type)
}), /*#__PURE__*/React.createElement(Snippet, {
className: "DocSearch-Hit-path",
hit: item,
attribute: "hierarchy.lvl1"
})), item.type === 'content' && /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Hit-content-wrapper"
}, /*#__PURE__*/React.createElement(Snippet, {
className: "DocSearch-Hit-title",
hit: item,
attribute: "content"
}), /*#__PURE__*/React.createElement(Snippet, {
className: "DocSearch-Hit-path",
hit: item,
attribute: "hierarchy.lvl1"
})), renderAction({
item: item,
runDeleteTransition: runDeleteTransition,
runFavoriteTransition: runFavoriteTransition
}))));
}

View File

@@ -1,5 +0,0 @@
import type { ScreenStateProps } from './ScreenState';
import type { InternalDocSearchHit } from './types';
declare type ResultsScreenProps = Omit<ScreenStateProps<InternalDocSearchHit>, 'translations'>;
export declare function ResultsScreen(props: ResultsScreenProps): JSX.Element;
export {};

View File

@@ -1,55 +0,0 @@
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); }
import React from 'react';
import { SelectIcon, SourceIcon } from './icons';
import { Results } from './Results';
import { removeHighlightTags } from './utils';
export function ResultsScreen(props) {
return /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Dropdown-Container"
}, props.state.collections.map(function (collection) {
if (collection.items.length === 0) {
return null;
}
var title = removeHighlightTags(collection.items[0]);
return /*#__PURE__*/React.createElement(Results, _extends({}, props, {
key: collection.source.sourceId,
title: title,
collection: collection,
renderIcon: function renderIcon(_ref) {
var _collection$items;
var item = _ref.item,
index = _ref.index;
return /*#__PURE__*/React.createElement(React.Fragment, null, item.__docsearch_parent && /*#__PURE__*/React.createElement("svg", {
className: "DocSearch-Hit-Tree",
viewBox: "0 0 24 54"
}, /*#__PURE__*/React.createElement("g", {
stroke: "currentColor",
fill: "none",
fillRule: "evenodd",
strokeLinecap: "round",
strokeLinejoin: "round"
}, item.__docsearch_parent !== ((_collection$items = collection.items[index + 1]) === null || _collection$items === void 0 ? void 0 : _collection$items.__docsearch_parent) ? /*#__PURE__*/React.createElement("path", {
d: "M8 6v21M20 27H8.3"
}) : /*#__PURE__*/React.createElement("path", {
d: "M8 6v42M20 27H8.3"
}))), /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Hit-icon"
}, /*#__PURE__*/React.createElement(SourceIcon, {
type: item.type
})));
},
renderAction: function renderAction() {
return /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Hit-action"
}, /*#__PURE__*/React.createElement(SelectIcon, null));
}
}));
}), props.resultsFooterComponent && /*#__PURE__*/React.createElement("section", {
className: "DocSearch-HitsFooter"
}, /*#__PURE__*/React.createElement(props.resultsFooterComponent, {
state: props.state
})));
}

View File

@@ -1,27 +0,0 @@
import type { AutocompleteApi, AutocompleteState, BaseItem } from '@algolia/autocomplete-core';
import React from 'react';
import type { DocSearchProps } from './DocSearch';
import type { ErrorScreenTranslations } from './ErrorScreen';
import type { NoResultsScreenTranslations } from './NoResultsScreen';
import type { StartScreenTranslations } from './StartScreen';
import type { StoredSearchPlugin } from './stored-searches';
import type { InternalDocSearchHit, StoredDocSearchHit } from './types';
export declare type ScreenStateTranslations = Partial<{
errorScreen: ErrorScreenTranslations;
startScreen: StartScreenTranslations;
noResultsScreen: NoResultsScreenTranslations;
}>;
export interface ScreenStateProps<TItem extends BaseItem> extends AutocompleteApi<TItem, React.FormEvent, React.MouseEvent, React.KeyboardEvent> {
state: AutocompleteState<TItem>;
recentSearches: StoredSearchPlugin<StoredDocSearchHit>;
favoriteSearches: StoredSearchPlugin<StoredDocSearchHit>;
onItemClick: (item: InternalDocSearchHit, event: KeyboardEvent | MouseEvent) => void;
inputRef: React.MutableRefObject<HTMLInputElement | null>;
hitComponent: DocSearchProps['hitComponent'];
indexName: DocSearchProps['indexName'];
disableUserPersonalization: boolean;
resultsFooterComponent: DocSearchProps['resultsFooterComponent'];
translations: ScreenStateTranslations;
getMissingResultsUrl?: DocSearchProps['getMissingResultsUrl'];
}
export declare const ScreenState: React.MemoExoticComponent<({ translations, ...props }: ScreenStateProps<InternalDocSearchHit>) => JSX.Element>;

View File

@@ -1,49 +0,0 @@
var _excluded = ["translations"];
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); }
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; }
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; }
import React from 'react';
import { ErrorScreen } from './ErrorScreen';
import { NoResultsScreen } from './NoResultsScreen';
import { ResultsScreen } from './ResultsScreen';
import { StartScreen } from './StartScreen';
export var ScreenState = React.memo(function (_ref) {
var _ref$translations = _ref.translations,
translations = _ref$translations === void 0 ? {} : _ref$translations,
props = _objectWithoutProperties(_ref, _excluded);
if (props.state.status === 'error') {
return /*#__PURE__*/React.createElement(ErrorScreen, {
translations: translations === null || translations === void 0 ? void 0 : translations.errorScreen
});
}
var hasCollections = props.state.collections.some(function (collection) {
return collection.items.length > 0;
});
if (!props.state.query) {
return /*#__PURE__*/React.createElement(StartScreen, _extends({}, props, {
hasCollections: hasCollections,
translations: translations === null || translations === void 0 ? void 0 : translations.startScreen
}));
}
if (hasCollections === false) {
return /*#__PURE__*/React.createElement(NoResultsScreen, _extends({}, props, {
translations: translations === null || translations === void 0 ? void 0 : translations.noResultsScreen
}));
}
return /*#__PURE__*/React.createElement(ResultsScreen, props);
}, function areEqual(_prevProps, nextProps) {
// We don't update the screen when Autocomplete is loading or stalled to
// avoid UI flashes:
// - Empty screen → Results screen
// - NoResults screen → NoResults screen with another query
return nextProps.state.status === 'loading' || nextProps.state.status === 'stalled';
});

View File

@@ -1,20 +0,0 @@
import type { AutocompleteApi, AutocompleteState } from '@algolia/autocomplete-core';
import type { MutableRefObject } from 'react';
import React from 'react';
import type { InternalDocSearchHit } from './types';
export declare type SearchBoxTranslations = Partial<{
resetButtonTitle: string;
resetButtonAriaLabel: string;
cancelButtonText: string;
cancelButtonAriaLabel: string;
}>;
interface SearchBoxProps extends AutocompleteApi<InternalDocSearchHit, React.FormEvent, React.MouseEvent, React.KeyboardEvent> {
state: AutocompleteState<InternalDocSearchHit>;
autoFocus: boolean;
inputRef: MutableRefObject<HTMLInputElement | null>;
onClose: () => void;
isFromSelection: boolean;
translations?: SearchBoxTranslations;
}
export declare function SearchBox({ translations, ...props }: SearchBoxProps): JSX.Element;
export {};

View File

@@ -1,72 +0,0 @@
var _excluded = ["translations"];
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); }
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; }
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; }
import React from 'react';
import { MAX_QUERY_SIZE } from './constants';
import { LoadingIcon } from './icons/LoadingIcon';
import { ResetIcon } from './icons/ResetIcon';
import { SearchIcon } from './icons/SearchIcon';
export function SearchBox(_ref) {
var _ref$translations = _ref.translations,
translations = _ref$translations === void 0 ? {} : _ref$translations,
props = _objectWithoutProperties(_ref, _excluded);
var _translations$resetBu = translations.resetButtonTitle,
resetButtonTitle = _translations$resetBu === void 0 ? 'Clear the query' : _translations$resetBu,
_translations$resetBu2 = translations.resetButtonAriaLabel,
resetButtonAriaLabel = _translations$resetBu2 === void 0 ? 'Clear the query' : _translations$resetBu2,
_translations$cancelB = translations.cancelButtonText,
cancelButtonText = _translations$cancelB === void 0 ? 'Cancel' : _translations$cancelB,
_translations$cancelB2 = translations.cancelButtonAriaLabel,
cancelButtonAriaLabel = _translations$cancelB2 === void 0 ? 'Cancel' : _translations$cancelB2;
var _props$getFormProps = props.getFormProps({
inputElement: props.inputRef.current
}),
onReset = _props$getFormProps.onReset;
React.useEffect(function () {
if (props.autoFocus && props.inputRef.current) {
props.inputRef.current.focus();
}
}, [props.autoFocus, props.inputRef]);
React.useEffect(function () {
if (props.isFromSelection && props.inputRef.current) {
props.inputRef.current.select();
}
}, [props.isFromSelection, props.inputRef]);
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("form", {
className: "DocSearch-Form",
onSubmit: function onSubmit(event) {
event.preventDefault();
},
onReset: onReset
}, /*#__PURE__*/React.createElement("label", _extends({
className: "DocSearch-MagnifierLabel"
}, props.getLabelProps()), /*#__PURE__*/React.createElement(SearchIcon, null)), /*#__PURE__*/React.createElement("div", {
className: "DocSearch-LoadingIndicator"
}, /*#__PURE__*/React.createElement(LoadingIcon, null)), /*#__PURE__*/React.createElement("input", _extends({
className: "DocSearch-Input",
ref: props.inputRef
}, props.getInputProps({
inputElement: props.inputRef.current,
autoFocus: props.autoFocus,
maxLength: MAX_QUERY_SIZE
}))), /*#__PURE__*/React.createElement("button", {
type: "reset",
title: resetButtonTitle,
className: "DocSearch-Reset",
"aria-label": resetButtonAriaLabel,
hidden: !props.state.query
}, /*#__PURE__*/React.createElement(ResetIcon, null))), /*#__PURE__*/React.createElement("button", {
className: "DocSearch-Cancel",
type: "reset",
"aria-label": cancelButtonAriaLabel,
onClick: props.onClose
}, cancelButtonText));
}

View File

@@ -1,14 +0,0 @@
/// <reference types="react" />
import type { StoredDocSearchHit } from './types';
interface SnippetProps<TItem> {
hit: TItem;
attribute: string;
tagName?: string;
[prop: string]: unknown;
}
export declare function Snippet<TItem extends StoredDocSearchHit>({ hit, attribute, tagName, ...rest }: SnippetProps<TItem>): import("react").DOMElement<{
dangerouslySetInnerHTML: {
__html: any;
};
}, Element>;
export {};

View File

@@ -1,35 +0,0 @@
var _excluded = ["hit", "attribute", "tagName"];
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; }
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; }
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; }
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; }
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; }
import { createElement } from 'react';
function getPropertyByPath(object, path) {
var parts = path.split('.');
return parts.reduce(function (prev, current) {
if (prev !== null && prev !== void 0 && prev[current]) return prev[current];
return null;
}, object);
}
export function Snippet(_ref) {
var hit = _ref.hit,
attribute = _ref.attribute,
_ref$tagName = _ref.tagName,
tagName = _ref$tagName === void 0 ? 'span' : _ref$tagName,
rest = _objectWithoutProperties(_ref, _excluded);
return createElement(tagName, _objectSpread(_objectSpread({}, rest), {}, {
dangerouslySetInnerHTML: {
__html: getPropertyByPath(hit, "_snippetResult.".concat(attribute, ".value")) || getPropertyByPath(hit, attribute)
}
}));
}

View File

@@ -1,16 +0,0 @@
import type { ScreenStateProps } from './ScreenState';
import type { InternalDocSearchHit } from './types';
export declare type StartScreenTranslations = Partial<{
recentSearchesTitle: string;
noRecentSearchesText: string;
saveRecentSearchButtonTitle: string;
removeRecentSearchButtonTitle: string;
favoriteSearchesTitle: string;
removeFavoriteSearchButtonTitle: string;
}>;
declare type StartScreenProps = Omit<ScreenStateProps<InternalDocSearchHit>, 'translations'> & {
hasCollections: boolean;
translations?: StartScreenTranslations;
};
export declare function StartScreen({ translations, ...props }: StartScreenProps): JSX.Element | null;
export {};

View File

@@ -1,119 +0,0 @@
var _excluded = ["translations"];
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); }
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; }
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; }
import React from 'react';
import { RecentIcon, ResetIcon, StarIcon } from './icons';
import { Results } from './Results';
export function StartScreen(_ref) {
var _ref$translations = _ref.translations,
translations = _ref$translations === void 0 ? {} : _ref$translations,
props = _objectWithoutProperties(_ref, _excluded);
var _translations$recentS = translations.recentSearchesTitle,
recentSearchesTitle = _translations$recentS === void 0 ? 'Recent' : _translations$recentS,
_translations$noRecen = translations.noRecentSearchesText,
noRecentSearchesText = _translations$noRecen === void 0 ? 'No recent searches' : _translations$noRecen,
_translations$saveRec = translations.saveRecentSearchButtonTitle,
saveRecentSearchButtonTitle = _translations$saveRec === void 0 ? 'Save this search' : _translations$saveRec,
_translations$removeR = translations.removeRecentSearchButtonTitle,
removeRecentSearchButtonTitle = _translations$removeR === void 0 ? 'Remove this search from history' : _translations$removeR,
_translations$favorit = translations.favoriteSearchesTitle,
favoriteSearchesTitle = _translations$favorit === void 0 ? 'Favorite' : _translations$favorit,
_translations$removeF = translations.removeFavoriteSearchButtonTitle,
removeFavoriteSearchButtonTitle = _translations$removeF === void 0 ? 'Remove this search from favorites' : _translations$removeF;
if (props.state.status === 'idle' && props.hasCollections === false) {
if (props.disableUserPersonalization) {
return null;
}
return /*#__PURE__*/React.createElement("div", {
className: "DocSearch-StartScreen"
}, /*#__PURE__*/React.createElement("p", {
className: "DocSearch-Help"
}, noRecentSearchesText));
}
if (props.hasCollections === false) {
return null;
}
return /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Dropdown-Container"
}, /*#__PURE__*/React.createElement(Results, _extends({}, props, {
title: recentSearchesTitle,
collection: props.state.collections[0],
renderIcon: function renderIcon() {
return /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Hit-icon"
}, /*#__PURE__*/React.createElement(RecentIcon, null));
},
renderAction: function renderAction(_ref2) {
var item = _ref2.item,
runFavoriteTransition = _ref2.runFavoriteTransition,
runDeleteTransition = _ref2.runDeleteTransition;
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Hit-action"
}, /*#__PURE__*/React.createElement("button", {
className: "DocSearch-Hit-action-button",
title: saveRecentSearchButtonTitle,
type: "submit",
onClick: function onClick(event) {
event.preventDefault();
event.stopPropagation();
runFavoriteTransition(function () {
props.favoriteSearches.add(item);
props.recentSearches.remove(item);
props.refresh();
});
}
}, /*#__PURE__*/React.createElement(StarIcon, null))), /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Hit-action"
}, /*#__PURE__*/React.createElement("button", {
className: "DocSearch-Hit-action-button",
title: removeRecentSearchButtonTitle,
type: "submit",
onClick: function onClick(event) {
event.preventDefault();
event.stopPropagation();
runDeleteTransition(function () {
props.recentSearches.remove(item);
props.refresh();
});
}
}, /*#__PURE__*/React.createElement(ResetIcon, null))));
}
})), /*#__PURE__*/React.createElement(Results, _extends({}, props, {
title: favoriteSearchesTitle,
collection: props.state.collections[1],
renderIcon: function renderIcon() {
return /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Hit-icon"
}, /*#__PURE__*/React.createElement(StarIcon, null));
},
renderAction: function renderAction(_ref3) {
var item = _ref3.item,
runDeleteTransition = _ref3.runDeleteTransition;
return /*#__PURE__*/React.createElement("div", {
className: "DocSearch-Hit-action"
}, /*#__PURE__*/React.createElement("button", {
className: "DocSearch-Hit-action-button",
title: removeFavoriteSearchButtonTitle,
type: "submit",
onClick: function onClick(event) {
event.preventDefault();
event.stopPropagation();
runDeleteTransition(function () {
props.favoriteSearches.remove(item);
props.refresh();
});
}
}, /*#__PURE__*/React.createElement(ResetIcon, null)));
}
})));
}

View File

@@ -1,461 +0,0 @@
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; }
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; }
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; }
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); } }
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); }); }; }
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); }
import { render, act, fireEvent, screen } from '@testing-library/react';
import React from 'react';
import '@testing-library/jest-dom';
import { DocSearch as DocSearchComponent } from '../DocSearch';
function DocSearch(props) {
return /*#__PURE__*/React.createElement(DocSearchComponent, _extends({
appId: "woo",
apiKey: "foo",
indexName: "bar"
}, props));
} // mock empty response
function noResultSearch(_queries, _requestOptions) {
return new Promise(function (resolve) {
resolve({
results: [{
hits: [],
hitsPerPage: 0,
nbHits: 0,
nbPages: 0,
page: 0,
processingTimeMS: 0,
exhaustiveNbHits: true,
params: '',
query: ''
}]
});
});
}
describe('api', function () {
var container;
var docSearchSelector = '.DocSearch';
beforeEach(function () {
container = document.createElement('div');
document.body.appendChild(container);
});
afterEach(function () {
document.body.removeChild(container);
container = null;
});
it('renders with minimal parameters', function () {
render( /*#__PURE__*/React.createElement(DocSearch, null));
expect(document.querySelector(docSearchSelector)).toBeInTheDocument();
});
describe('translations', function () {
it('overrides the default DocSearchButton text', function () {
render( /*#__PURE__*/React.createElement(DocSearch, {
translations: {
button: {
buttonText: 'Recherche',
buttonAriaLabel: 'Recherche'
}
}
}));
expect(document.querySelector(docSearchSelector)).toBeInTheDocument();
expect(document.querySelector('.DocSearch-Button-Placeholder').innerHTML).toBe('Recherche');
expect(document.querySelector('.DocSearch-Button').getAttribute('aria-label')).toBe('Recherche');
});
it('overrides the default DocSearchModal startScreen text', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
return regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) switch (_context2.prev = _context2.next) {
case 0:
render( /*#__PURE__*/React.createElement(DocSearch, {
translations: {
modal: {
startScreen: {
noRecentSearchesText: 'Pas de recherche récentes'
}
}
}
}));
expect(document.querySelector(docSearchSelector)).toBeInTheDocument();
_context2.next = 4;
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.t0 = fireEvent;
_context.next = 3;
return screen.findByText('Search');
case 3:
_context.t1 = _context.sent;
_context.t0.click.call(_context.t0, _context.t1);
case 5:
case "end":
return _context.stop();
}
}, _callee);
})));
case 4:
expect(document.querySelector('.DocSearch-Modal')).toBeInTheDocument();
expect(screen.getByText('Pas de recherche récentes')).toBeInTheDocument();
case 6:
case "end":
return _context2.stop();
}
}, _callee2);
})));
it('overrides the default DocSearchModal noResultsScreen text', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5() {
return regeneratorRuntime.wrap(function _callee5$(_context5) {
while (1) switch (_context5.prev = _context5.next) {
case 0:
render( /*#__PURE__*/React.createElement(DocSearch, {
transformSearchClient: function transformSearchClient(searchClient) {
return _objectSpread(_objectSpread({}, searchClient), {}, {
search: noResultSearch
});
},
translations: {
modal: {
noResultsScreen: {
noResultsText: 'Pas de résultats pour',
reportMissingResultsText: 'Ouvrez une issue sur docsearch-configs',
reportMissingResultsLinkText: 'Lien du repo'
}
}
},
getMissingResultsUrl: function getMissingResultsUrl() {
return 'algolia.com';
}
}));
expect(document.querySelector(docSearchSelector)).toBeInTheDocument();
_context5.next = 4;
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
return regeneratorRuntime.wrap(function _callee3$(_context3) {
while (1) switch (_context3.prev = _context3.next) {
case 0:
_context3.t0 = fireEvent;
_context3.next = 3;
return screen.findByText('Search');
case 3:
_context3.t1 = _context3.sent;
_context3.t0.click.call(_context3.t0, _context3.t1);
case 5:
case "end":
return _context3.stop();
}
}, _callee3);
})));
case 4:
_context5.next = 6;
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() {
return regeneratorRuntime.wrap(function _callee4$(_context4) {
while (1) switch (_context4.prev = _context4.next) {
case 0:
_context4.t0 = fireEvent;
_context4.next = 3;
return screen.findByPlaceholderText('Search docs');
case 3:
_context4.t1 = _context4.sent;
_context4.t2 = {
target: {
value: 'q'
}
};
_context4.t0.input.call(_context4.t0, _context4.t1, _context4.t2);
case 6:
case "end":
return _context4.stop();
}
}, _callee4);
})));
case 6:
expect(screen.getByText(/Pas de résultats pour/)).toBeInTheDocument();
expect(screen.getByText(/Ouvrez une issue sur docsearch-configs/)).toBeInTheDocument();
expect(screen.getByRole('link', {
name: 'Lien du repo'
})).toBeInTheDocument();
case 9:
case "end":
return _context5.stop();
}
}, _callee5);
})));
it('overrides the default DocSearchModal searchbox text', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() {
return regeneratorRuntime.wrap(function _callee7$(_context7) {
while (1) switch (_context7.prev = _context7.next) {
case 0:
render( /*#__PURE__*/React.createElement(DocSearch, {
translations: {
modal: {
searchBox: {
resetButtonTitle: 'Effacer',
resetButtonAriaLabel: 'Effacer',
cancelButtonText: 'Annuler',
cancelButtonAriaLabel: 'Annuler'
}
}
}
}));
expect(document.querySelector(docSearchSelector)).toBeInTheDocument();
_context7.next = 4;
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {
return regeneratorRuntime.wrap(function _callee6$(_context6) {
while (1) switch (_context6.prev = _context6.next) {
case 0:
_context6.t0 = fireEvent;
_context6.next = 3;
return screen.findByText('Search');
case 3:
_context6.t1 = _context6.sent;
_context6.t0.click.call(_context6.t0, _context6.t1);
case 5:
case "end":
return _context6.stop();
}
}, _callee6);
})));
case 4:
expect(document.querySelector('.DocSearch-Cancel').innerHTML).toBe('Annuler');
expect(document.querySelector('.DocSearch-Cancel').getAttribute('aria-label')).toBe('Annuler');
expect(document.querySelector('.DocSearch-Reset').getAttribute('title')).toBe('Effacer');
expect(document.querySelector('.DocSearch-Reset').getAttribute('aria-label')).toBe('Effacer');
case 8:
case "end":
return _context7.stop();
}
}, _callee7);
})));
it('overrides the default DocSearchModal footer text', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee9() {
return regeneratorRuntime.wrap(function _callee9$(_context9) {
while (1) switch (_context9.prev = _context9.next) {
case 0:
render( /*#__PURE__*/React.createElement(DocSearch, {
translations: {
modal: {
footer: {
closeText: 'Pour fermer',
closeKeyAriaLabel: "Touche d'échappement",
navigateText: 'Pour naviguer',
navigateUpKeyAriaLabel: 'Flèche vers le haut',
navigateDownKeyAriaLabel: 'Flèche le bas',
searchByText: 'Recherche par',
selectText: 'Pour selectionner',
selectKeyAriaLabel: "Touche d'entrée"
}
}
}
}));
expect(document.querySelector(docSearchSelector)).toBeInTheDocument();
_context9.next = 4;
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8() {
return regeneratorRuntime.wrap(function _callee8$(_context8) {
while (1) switch (_context8.prev = _context8.next) {
case 0:
_context8.t0 = fireEvent;
_context8.next = 3;
return screen.findByText('Search');
case 3:
_context8.t1 = _context8.sent;
_context8.t0.click.call(_context8.t0, _context8.t1);
case 5:
case "end":
return _context8.stop();
}
}, _callee8);
})));
case 4:
expect(screen.getByText('Recherche par')).toBeInTheDocument();
expect(screen.getByText('Pour fermer')).toBeInTheDocument();
expect(screen.getByText('Pour naviguer')).toBeInTheDocument();
expect(screen.getByText('Pour selectionner')).toBeInTheDocument();
expect(document.querySelector('.DocSearch-Commands-Key > svg[aria-label="Touche d\'échappement"]')).toBeInTheDocument();
expect(document.querySelector('.DocSearch-Commands-Key > svg[aria-label="Flèche vers le haut"]')).toBeInTheDocument();
expect(document.querySelector('.DocSearch-Commands-Key > svg[aria-label="Flèche le bas"]')).toBeInTheDocument();
expect(document.querySelector('.DocSearch-Commands-Key > svg[aria-label="Touche d\'entrée"]')).toBeInTheDocument();
case 12:
case "end":
return _context9.stop();
}
}, _callee9);
})));
});
describe('getMissingResultsUrl', function () {
it('does not render the link to the repository by default', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee12() {
return regeneratorRuntime.wrap(function _callee12$(_context12) {
while (1) switch (_context12.prev = _context12.next) {
case 0:
render( /*#__PURE__*/React.createElement(DocSearch, {
transformSearchClient: function transformSearchClient(searchClient) {
return _objectSpread(_objectSpread({}, searchClient), {}, {
search: noResultSearch
});
}
}));
expect(document.querySelector(docSearchSelector)).toBeInTheDocument();
_context12.next = 4;
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee10() {
return regeneratorRuntime.wrap(function _callee10$(_context10) {
while (1) switch (_context10.prev = _context10.next) {
case 0:
_context10.t0 = fireEvent;
_context10.next = 3;
return screen.findByText('Search');
case 3:
_context10.t1 = _context10.sent;
_context10.t0.click.call(_context10.t0, _context10.t1);
case 5:
case "end":
return _context10.stop();
}
}, _callee10);
})));
case 4:
_context12.next = 6;
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11() {
return regeneratorRuntime.wrap(function _callee11$(_context11) {
while (1) switch (_context11.prev = _context11.next) {
case 0:
_context11.t0 = fireEvent;
_context11.next = 3;
return screen.findByPlaceholderText('Search docs');
case 3:
_context11.t1 = _context11.sent;
_context11.t2 = {
target: {
value: 'q'
}
};
_context11.t0.input.call(_context11.t0, _context11.t1, _context11.t2);
case 6:
case "end":
return _context11.stop();
}
}, _callee11);
})));
case 6:
expect(screen.getByText(/No results for/)).toBeInTheDocument();
expect(document.querySelector('.DocSearch-Help a')).not.toBeInTheDocument();
case 8:
case "end":
return _context12.stop();
}
}, _callee12);
})));
it('render the link to the repository', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee15() {
var link;
return regeneratorRuntime.wrap(function _callee15$(_context15) {
while (1) switch (_context15.prev = _context15.next) {
case 0:
render( /*#__PURE__*/React.createElement(DocSearch, {
transformSearchClient: function transformSearchClient(searchClient) {
return _objectSpread(_objectSpread({}, searchClient), {}, {
search: noResultSearch
});
},
getMissingResultsUrl: function getMissingResultsUrl(_ref14) {
var query = _ref14.query;
return "https://github.com/algolia/docsearch/issues/new?title=".concat(query);
}
}));
_context15.next = 3;
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee13() {
return regeneratorRuntime.wrap(function _callee13$(_context13) {
while (1) switch (_context13.prev = _context13.next) {
case 0:
_context13.t0 = fireEvent;
_context13.next = 3;
return screen.findByText('Search');
case 3:
_context13.t1 = _context13.sent;
_context13.t0.click.call(_context13.t0, _context13.t1);
case 5:
case "end":
return _context13.stop();
}
}, _callee13);
})));
case 3:
_context15.next = 5;
return act( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee14() {
return regeneratorRuntime.wrap(function _callee14$(_context14) {
while (1) switch (_context14.prev = _context14.next) {
case 0:
_context14.t0 = fireEvent;
_context14.next = 3;
return screen.findByPlaceholderText('Search docs');
case 3:
_context14.t1 = _context14.sent;
_context14.t2 = {
target: {
value: 'q'
}
};
_context14.t0.input.call(_context14.t0, _context14.t1, _context14.t2);
case 6:
case "end":
return _context14.stop();
}
}, _callee14);
})));
case 5:
expect(screen.getByText(/No results for/)).toBeInTheDocument();
link = document.querySelector('.DocSearch-Help a');
expect(link).toBeInTheDocument();
expect(link.getAttribute('href')).toBe('https://github.com/algolia/docsearch/issues/new?title=q');
case 9:
case "end":
return _context15.stop();
}
}, _callee15);
})));
});
});

View File

@@ -1 +0,0 @@
export declare const MAX_QUERY_SIZE = 64;

View File

@@ -1 +0,0 @@
export var MAX_QUERY_SIZE = 64;

View File

@@ -1 +0,0 @@
export declare function ControlKeyIcon(): JSX.Element;

View File

@@ -1,14 +0,0 @@
import React from 'react';
export function ControlKeyIcon() {
return /*#__PURE__*/React.createElement("svg", {
width: "15",
height: "15",
className: "DocSearch-Control-Key-Icon"
}, /*#__PURE__*/React.createElement("path", {
d: "M4.505 4.496h2M5.505 5.496v5M8.216 4.496l.055 5.993M10 7.5c.333.333.5.667.5 1v2M12.326 4.5v5.996M8.384 4.496c1.674 0 2.116 0 2.116 1.5s-.442 1.5-2.116 1.5M3.205 9.303c-.09.448-.277 1.21-1.241 1.203C1 10.5.5 9.513.5 8V7c0-1.57.5-2.5 1.464-2.494.964.006 1.134.598 1.24 1.342M12.553 10.5h1.953",
strokeWidth: "1.2",
stroke: "currentColor",
fill: "none",
strokeLinecap: "square"
}));
}

View File

@@ -1 +0,0 @@
export declare function ErrorIcon(): JSX.Element;

View File

@@ -1,15 +0,0 @@
import React from 'react';
export function ErrorIcon() {
return /*#__PURE__*/React.createElement("svg", {
width: "40",
height: "40",
viewBox: "0 0 20 20",
fill: "none",
fillRule: "evenodd",
stroke: "currentColor",
strokeLinecap: "round",
strokeLinejoin: "round"
}, /*#__PURE__*/React.createElement("path", {
d: "M19 4.8a16 16 0 00-2-1.2m-3.3-1.2A16 16 0 001.1 4.7M16.7 8a12 12 0 00-2.8-1.4M10 6a12 12 0 00-6.7 2M12.3 14.7a4 4 0 00-4.5 0M14.5 11.4A8 8 0 0010 10M3 16L18 2M10 18h0"
}));
}

View File

@@ -1 +0,0 @@
export declare function GoToExternal(): JSX.Element;

View File

@@ -1,11 +0,0 @@
import React from 'react';
export function GoToExternal() {
return /*#__PURE__*/React.createElement("svg", {
width: "20",
height: "20"
}, /*#__PURE__*/React.createElement("path", {
d: "M5 6v9h9v-3a1 1 0 112 0v4l-1 1H4l-1-1V5l1-1h4a1 1 0 110 2H5zm5 5a1 1 0 11-1-1l5-6h-3a1 1 0 110-2h6a1 1 0 011 1v6a1 1 0 11-2 0V6l-6 5z",
fill: "currentColor",
fillRule: "nonzero"
}));
}

View File

@@ -1 +0,0 @@
export declare function LoadingIcon(): JSX.Element;

View File

@@ -1,28 +0,0 @@
import React from 'react';
export function LoadingIcon() {
return /*#__PURE__*/React.createElement("svg", {
viewBox: "0 0 38 38",
stroke: "currentColor",
strokeOpacity: ".5"
}, /*#__PURE__*/React.createElement("g", {
fill: "none",
fillRule: "evenodd"
}, /*#__PURE__*/React.createElement("g", {
transform: "translate(1 1)",
strokeWidth: "2"
}, /*#__PURE__*/React.createElement("circle", {
strokeOpacity: ".3",
cx: "18",
cy: "18",
r: "18"
}), /*#__PURE__*/React.createElement("path", {
d: "M36 18c0-9.94-8.06-18-18-18"
}, /*#__PURE__*/React.createElement("animateTransform", {
attributeName: "transform",
type: "rotate",
from: "0 18 18",
to: "360 18 18",
dur: "1s",
repeatCount: "indefinite"
})))));
}

View File

@@ -1 +0,0 @@
export declare function NoResultsIcon(): JSX.Element;

View File

@@ -1,15 +0,0 @@
import React from 'react';
export function NoResultsIcon() {
return /*#__PURE__*/React.createElement("svg", {
width: "40",
height: "40",
viewBox: "0 0 20 20",
fill: "none",
fillRule: "evenodd",
stroke: "currentColor",
strokeLinecap: "round",
strokeLinejoin: "round"
}, /*#__PURE__*/React.createElement("path", {
d: "M15.5 4.8c2 3 1.7 7-1 9.7h0l4.3 4.3-4.3-4.3a7.8 7.8 0 01-9.8 1m-2.2-2.2A7.8 7.8 0 0113.2 2.4M2 18L18 2"
}));
}

View File

@@ -1 +0,0 @@
export declare function RecentIcon(): JSX.Element;

View File

@@ -1,18 +0,0 @@
import React from 'react';
export function RecentIcon() {
return /*#__PURE__*/React.createElement("svg", {
width: "20",
height: "20",
viewBox: "0 0 20 20"
}, /*#__PURE__*/React.createElement("g", {
stroke: "currentColor",
fill: "none",
fillRule: "evenodd",
strokeLinecap: "round",
strokeLinejoin: "round"
}, /*#__PURE__*/React.createElement("path", {
d: "M3.18 6.6a8.23 8.23 0 1112.93 9.94h0a8.23 8.23 0 01-11.63 0"
}), /*#__PURE__*/React.createElement("path", {
d: "M6.44 7.25H2.55V3.36M10.45 6v5.6M10.45 11.6L13 13"
})));
}

View File

@@ -1 +0,0 @@
export declare function ResetIcon(): JSX.Element;

View File

@@ -1,15 +0,0 @@
import React from 'react';
export function ResetIcon() {
return /*#__PURE__*/React.createElement("svg", {
width: "20",
height: "20",
viewBox: "0 0 20 20"
}, /*#__PURE__*/React.createElement("path", {
d: "M10 10l5.09-5.09L10 10l5.09 5.09L10 10zm0 0L4.91 4.91 10 10l-5.09 5.09L10 10z",
stroke: "currentColor",
fill: "none",
fillRule: "evenodd",
strokeLinecap: "round",
strokeLinejoin: "round"
}));
}

View File

@@ -1 +0,0 @@
export declare function SearchIcon(): JSX.Element;

View File

@@ -1,16 +0,0 @@
import React from 'react';
export function SearchIcon() {
return /*#__PURE__*/React.createElement("svg", {
width: "20",
height: "20",
className: "DocSearch-Search-Icon",
viewBox: "0 0 20 20"
}, /*#__PURE__*/React.createElement("path", {
d: "M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z",
stroke: "currentColor",
fill: "none",
fillRule: "evenodd",
strokeLinecap: "round",
strokeLinejoin: "round"
}));
}

View File

@@ -1 +0,0 @@
export declare function SelectIcon(): JSX.Element;

View File

@@ -1,19 +0,0 @@
import React from 'react';
export function SelectIcon() {
return /*#__PURE__*/React.createElement("svg", {
className: "DocSearch-Hit-Select-Icon",
width: "20",
height: "20",
viewBox: "0 0 20 20"
}, /*#__PURE__*/React.createElement("g", {
stroke: "currentColor",
fill: "none",
fillRule: "evenodd",
strokeLinecap: "round",
strokeLinejoin: "round"
}, /*#__PURE__*/React.createElement("path", {
d: "M18 3v4c0 2-2 4-4 4H2"
}), /*#__PURE__*/React.createElement("path", {
d: "M8 17l-6-6 6-6"
})));
}

View File

@@ -1,3 +0,0 @@
export declare function SourceIcon(props: {
type: string;
}): JSX.Element;

View File

@@ -1,57 +0,0 @@
import React from 'react';
var LvlIcon = function LvlIcon() {
return /*#__PURE__*/React.createElement("svg", {
width: "20",
height: "20",
viewBox: "0 0 20 20"
}, /*#__PURE__*/React.createElement("path", {
d: "M17 6v12c0 .52-.2 1-1 1H4c-.7 0-1-.33-1-1V2c0-.55.42-1 1-1h8l5 5zM14 8h-3.13c-.51 0-.87-.34-.87-.87V4",
stroke: "currentColor",
fill: "none",
fillRule: "evenodd",
strokeLinejoin: "round"
}));
};
export function SourceIcon(props) {
switch (props.type) {
case 'lvl1':
return /*#__PURE__*/React.createElement(LvlIcon, null);
case 'content':
return /*#__PURE__*/React.createElement(ContentIcon, null);
default:
return /*#__PURE__*/React.createElement(AnchorIcon, null);
}
}
function AnchorIcon() {
return /*#__PURE__*/React.createElement("svg", {
width: "20",
height: "20",
viewBox: "0 0 20 20"
}, /*#__PURE__*/React.createElement("path", {
d: "M13 13h4-4V8H7v5h6v4-4H7V8H3h4V3v5h6V3v5h4-4v5zm-6 0v4-4H3h4z",
stroke: "currentColor",
fill: "none",
fillRule: "evenodd",
strokeLinecap: "round",
strokeLinejoin: "round"
}));
}
function ContentIcon() {
return /*#__PURE__*/React.createElement("svg", {
width: "20",
height: "20",
viewBox: "0 0 20 20"
}, /*#__PURE__*/React.createElement("path", {
d: "M17 5H3h14zm0 5H3h14zm0 5H3h14z",
stroke: "currentColor",
fill: "none",
fillRule: "evenodd",
strokeLinejoin: "round"
}));
}

View File

@@ -1 +0,0 @@
export declare function StarIcon(): JSX.Element;

View File

@@ -1,14 +0,0 @@
import React from 'react';
export function StarIcon() {
return /*#__PURE__*/React.createElement("svg", {
width: "20",
height: "20",
viewBox: "0 0 20 20"
}, /*#__PURE__*/React.createElement("path", {
d: "M10 14.2L5 17l1-5.6-4-4 5.5-.7 2.5-5 2.5 5 5.6.8-4 4 .9 5.5z",
stroke: "currentColor",
fill: "none",
fillRule: "evenodd",
strokeLinejoin: "round"
}));
}

View File

@@ -1,10 +0,0 @@
export * from './GoToExternalIcon';
export * from './LoadingIcon';
export * from './RecentIcon';
export * from './ResetIcon';
export * from './SearchIcon';
export * from './SelectIcon';
export * from './SourceIcon';
export * from './StarIcon';
export * from './ErrorIcon';
export * from './NoResultsIcon';

View File

@@ -1,10 +0,0 @@
export * from './GoToExternalIcon';
export * from './LoadingIcon';
export * from './RecentIcon';
export * from './ResetIcon';
export * from './SearchIcon';
export * from './SelectIcon';
export * from './SourceIcon';
export * from './StarIcon';
export * from './ErrorIcon';
export * from './NoResultsIcon';

View File

@@ -1,5 +0,0 @@
export * from './DocSearch';
export * from './DocSearchButton';
export * from './DocSearchModal';
export * from './useDocSearchKeyboardEvents';
export * from './version';

View File

@@ -1,5 +0,0 @@
export * from './DocSearch';
export * from './DocSearchButton';
export * from './DocSearchModal';
export * from './useDocSearchKeyboardEvents';
export * from './version';

View File

@@ -1,12 +0,0 @@
import type { StoredDocSearchHit } from './types';
declare type CreateStoredSearchesOptions = {
key: string;
limit?: number;
};
export declare type StoredSearchPlugin<TItem> = {
add: (item: TItem) => void;
remove: (item: TItem) => void;
getAll: () => TItem[];
};
export declare function createStoredSearches<TItem extends StoredDocSearchHit>({ key, limit, }: CreateStoredSearchesOptions): StoredSearchPlugin<TItem>;
export {};

View File

@@ -1,75 +0,0 @@
var _excluded = ["_highlightResult", "_snippetResult"];
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; }
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; }
function isLocalStorageSupported() {
var key = '__TEST_KEY__';
try {
localStorage.setItem(key, '');
localStorage.removeItem(key);
return true;
} catch (error) {
return false;
}
}
function createStorage(key) {
if (isLocalStorageSupported() === false) {
return {
setItem: function setItem() {},
getItem: function getItem() {
return [];
}
};
}
return {
setItem: function setItem(item) {
return window.localStorage.setItem(key, JSON.stringify(item));
},
getItem: function getItem() {
var item = window.localStorage.getItem(key);
return item ? JSON.parse(item) : [];
}
};
}
export function createStoredSearches(_ref) {
var key = _ref.key,
_ref$limit = _ref.limit,
limit = _ref$limit === void 0 ? 5 : _ref$limit;
var storage = createStorage(key);
var items = storage.getItem().slice(0, limit);
return {
add: function add(item) {
var _ref2 = item,
_highlightResult = _ref2._highlightResult,
_snippetResult = _ref2._snippetResult,
hit = _objectWithoutProperties(_ref2, _excluded);
var isQueryAlreadySaved = items.findIndex(function (x) {
return x.objectID === hit.objectID;
});
if (isQueryAlreadySaved > -1) {
items.splice(isQueryAlreadySaved, 1);
}
items.unshift(hit);
items = items.slice(0, limit);
storage.setItem(items);
},
remove: function remove(item) {
items = items.filter(function (x) {
return x.objectID !== item.objectID;
});
storage.setItem(items);
},
getAll: function getAll() {
return items;
}
};
}

View File

@@ -1,75 +0,0 @@
declare type ContentType = 'content' | 'lvl0' | 'lvl1' | 'lvl2' | 'lvl3' | 'lvl4' | 'lvl5' | 'lvl6';
interface DocSearchHitAttributeHighlightResult {
value: string;
matchLevel: 'full' | 'none' | 'partial';
matchedWords: string[];
fullyHighlighted?: boolean;
}
interface DocSearchHitHighlightResultHierarchy {
lvl0: DocSearchHitAttributeHighlightResult;
lvl1: DocSearchHitAttributeHighlightResult;
lvl2: DocSearchHitAttributeHighlightResult;
lvl3: DocSearchHitAttributeHighlightResult;
lvl4: DocSearchHitAttributeHighlightResult;
lvl5: DocSearchHitAttributeHighlightResult;
lvl6: DocSearchHitAttributeHighlightResult;
}
interface DocSearchHitHighlightResult {
content: DocSearchHitAttributeHighlightResult;
hierarchy: DocSearchHitHighlightResultHierarchy;
hierarchy_camel: DocSearchHitHighlightResultHierarchy[];
}
interface DocSearchHitAttributeSnippetResult {
value: string;
matchLevel: 'full' | 'none' | 'partial';
}
interface DocSearchHitSnippetResult {
content: DocSearchHitAttributeSnippetResult;
hierarchy: DocSearchHitHighlightResultHierarchy;
hierarchy_camel: DocSearchHitHighlightResultHierarchy[];
}
export declare type DocSearchHit = {
objectID: string;
content: string | null;
url: string;
url_without_anchor: string;
type: ContentType;
anchor: string | null;
hierarchy: {
lvl0: string;
lvl1: string;
lvl2: string | null;
lvl3: string | null;
lvl4: string | null;
lvl5: string | null;
lvl6: string | null;
};
_highlightResult: DocSearchHitHighlightResult;
_snippetResult: DocSearchHitSnippetResult;
_rankingInfo?: {
promoted: boolean;
nbTypos: number;
firstMatchedWord: number;
proximityDistance?: number;
geoDistance: number;
geoPrecision?: number;
nbExactWords: number;
words: number;
filters: number;
userScore: number;
matchedGeoLocation?: {
lat: number;
lng: number;
distance: number;
};
};
_distinctSeqID?: number;
__autocomplete_indexName?: string;
__autocomplete_queryID?: string;
__autocomplete_algoliaCredentials?: {
appId: string;
apiKey: string;
};
__autocomplete_id?: number;
};
export {};

View File

@@ -1 +0,0 @@
export {};

View File

@@ -1,10 +0,0 @@
import type { AutocompleteContext, AutocompleteInsightsApi, AutocompleteState, BaseItem } from '@algolia/autocomplete-core';
interface DocSearchContext extends AutocompleteContext {
algoliaInsightsPlugin?: {
insights: AutocompleteInsightsApi;
};
}
export interface DocSearchState<TItem extends BaseItem> extends AutocompleteState<TItem> {
context: DocSearchContext;
}
export {};

View File

@@ -1 +0,0 @@
export {};

View File

@@ -1,4 +0,0 @@
import type { DocSearchHit } from './DocSearchHit';
export declare type InternalDocSearchHit = DocSearchHit & {
__docsearch_parent: InternalDocSearchHit | null;
};

View File

@@ -1 +0,0 @@
export {};

View File

@@ -1,2 +0,0 @@
import type { DocSearchHit } from './DocSearchHit';
export declare type StoredDocSearchHit = Omit<DocSearchHit, '_highlightResult' | '_snippetResult'>;

View File

@@ -1 +0,0 @@
export {};

View File

@@ -1,4 +0,0 @@
export * from './DocSearchHit';
export * from './DocSearchState';
export * from './InternalDocSearchHit';
export * from './StoredDocSearchHit';

View File

@@ -1,4 +0,0 @@
export * from './DocSearchHit';
export * from './DocSearchState';
export * from './InternalDocSearchHit';
export * from './StoredDocSearchHit';

View File

@@ -1,9 +0,0 @@
import React from 'react';
export interface UseDocSearchKeyboardEventsProps {
isOpen: boolean;
onOpen: () => void;
onClose: () => void;
onInput?: (event: KeyboardEvent) => void;
searchButtonRef?: React.RefObject<HTMLButtonElement>;
}
export declare function useDocSearchKeyboardEvents({ isOpen, onOpen, onClose, onInput, searchButtonRef, }: UseDocSearchKeyboardEventsProps): void;

View File

@@ -1,55 +0,0 @@
import React from 'react';
function isEditingContent(event) {
var element = event.target;
var tagName = element.tagName;
return element.isContentEditable || tagName === 'INPUT' || tagName === 'SELECT' || tagName === 'TEXTAREA';
}
export function useDocSearchKeyboardEvents(_ref) {
var isOpen = _ref.isOpen,
onOpen = _ref.onOpen,
onClose = _ref.onClose,
onInput = _ref.onInput,
searchButtonRef = _ref.searchButtonRef;
React.useEffect(function () {
function onKeyDown(event) {
var _event$key;
function open() {
// We check that no other DocSearch modal is showing before opening
// another one.
if (!document.body.classList.contains('DocSearch--active')) {
onOpen();
}
}
if (event.keyCode === 27 && isOpen || // The `Cmd+K` shortcut both opens and closes the modal.
// We need to check for `event.key` because it can be `undefined` with
// Chrome's autofill feature.
// See https://github.com/paperjs/paper.js/issues/1398
((_event$key = event.key) === null || _event$key === void 0 ? void 0 : _event$key.toLowerCase()) === 'k' && (event.metaKey || event.ctrlKey) || // The `/` shortcut opens but doesn't close the modal because it's
// a character.
!isEditingContent(event) && event.key === '/' && !isOpen) {
event.preventDefault();
if (isOpen) {
onClose();
} else if (!document.body.classList.contains('DocSearch--active')) {
open();
}
}
if (searchButtonRef && searchButtonRef.current === document.activeElement && onInput) {
if (/[a-zA-Z0-9]/.test(String.fromCharCode(event.keyCode))) {
onInput(event);
}
}
}
window.addEventListener('keydown', onKeyDown);
return function () {
window.removeEventListener('keydown', onKeyDown);
};
}, [isOpen, onOpen, onClose, onInput, searchButtonRef]);
}

View File

@@ -1,2 +0,0 @@
import type { SearchClient } from 'algoliasearch/lite';
export declare function useSearchClient(appId: string, apiKey: string, transformSearchClient: (searchClient: SearchClient) => SearchClient): SearchClient;

View File

@@ -1,20 +0,0 @@
import algoliasearch from 'algoliasearch/dist/algoliasearch-lite.esm.browser';
import React from 'react';
import { version } from './version';
export function useSearchClient(appId, apiKey, transformSearchClient) {
var searchClient = React.useMemo(function () {
var client = algoliasearch(appId, apiKey);
client.addAlgoliaAgent('docsearch', version); // Since DocSearch.js relies on DocSearch React with an alias to Preact,
// we cannot add the `docsearch-react` user agent by default, otherwise
// it would also be sent on a DocSearch.js integration.
// We therefore only add the `docsearch-react` user agent if `docsearch.js`
// is not present.
if (/docsearch.js \(.*\)/.test(client.transporter.userAgent.value) === false) {
client.addAlgoliaAgent('docsearch-react', version);
}
return transformSearchClient(client);
}, [appId, apiKey, transformSearchClient]);
return searchClient;
}

View File

@@ -1,9 +0,0 @@
import type { AutocompleteApi } from '@algolia/autocomplete-core';
interface UseTouchEventsProps {
getEnvironmentProps: AutocompleteApi<any>['getEnvironmentProps'];
panelElement: HTMLDivElement | null;
formElement: HTMLDivElement | null;
inputElement: HTMLInputElement | null;
}
export declare function useTouchEvents({ getEnvironmentProps, panelElement, formElement, inputElement, }: UseTouchEventsProps): void;
export {};

View File

@@ -1,27 +0,0 @@
import React from 'react';
export function useTouchEvents(_ref) {
var getEnvironmentProps = _ref.getEnvironmentProps,
panelElement = _ref.panelElement,
formElement = _ref.formElement,
inputElement = _ref.inputElement;
React.useEffect(function () {
if (!(panelElement && formElement && inputElement)) {
return undefined;
}
var _getEnvironmentProps = getEnvironmentProps({
panelElement: panelElement,
formElement: formElement,
inputElement: inputElement
}),
onTouchStart = _getEnvironmentProps.onTouchStart,
onTouchMove = _getEnvironmentProps.onTouchMove;
window.addEventListener('touchstart', onTouchStart);
window.addEventListener('touchmove', onTouchMove);
return function () {
window.removeEventListener('touchstart', onTouchStart);
window.removeEventListener('touchmove', onTouchMove);
};
}, [getEnvironmentProps, panelElement, formElement, inputElement]);
}

View File

@@ -1,5 +0,0 @@
interface UseTrapFocusProps {
container: HTMLElement | null;
}
export declare function useTrapFocus({ container }: UseTrapFocusProps): void;
export {};

View File

@@ -1,34 +0,0 @@
import React from 'react';
export function useTrapFocus(_ref) {
var container = _ref.container;
React.useEffect(function () {
if (!container) {
return undefined;
}
var focusableElements = container.querySelectorAll('a[href]:not([disabled]), button:not([disabled]), input:not([disabled])');
var firstElement = focusableElements[0];
var lastElement = focusableElements[focusableElements.length - 1];
function trapFocus(event) {
if (event.key !== 'Tab') {
return;
}
if (event.shiftKey) {
if (document.activeElement === firstElement) {
event.preventDefault();
lastElement.focus();
}
} else if (document.activeElement === lastElement) {
event.preventDefault();
firstElement.focus();
}
}
container.addEventListener('keydown', trapFocus);
return function () {
container.removeEventListener('keydown', trapFocus);
};
}, [container]);
}

View File

@@ -1 +0,0 @@
export declare function groupBy<TValue extends Record<string, unknown>>(values: TValue[], predicate: (value: TValue) => string, maxResultsPerGroup?: number): Record<string, TValue[]>;

View File

@@ -1,17 +0,0 @@
export function groupBy(values, predicate, maxResultsPerGroup) {
return values.reduce(function (acc, item) {
var key = predicate(item);
if (!acc.hasOwnProperty(key)) {
acc[key] = [];
} // We limit each section to show 5 hits maximum.
// This acts as a frontend alternative to `distinct`.
if (acc[key].length < (maxResultsPerGroup || 5)) {
acc[key].push(item);
}
return acc;
}, {});
}

View File

@@ -1 +0,0 @@
export declare function identity<TParam>(x: TParam): TParam;

View File

@@ -1,3 +0,0 @@
export function identity(x) {
return x;
}

View File

@@ -1,5 +0,0 @@
export * from './groupBy';
export * from './identity';
export * from './isModifierEvent';
export * from './noop';
export * from './removeHighlightTags';

View File

@@ -1,5 +0,0 @@
export * from './groupBy';
export * from './identity';
export * from './isModifierEvent';
export * from './noop';
export * from './removeHighlightTags';

View File

@@ -1,5 +0,0 @@
/**
* Detect when an event is modified with a special key to let the browser
* trigger its default behavior.
*/
export declare function isModifierEvent<TEvent extends KeyboardEvent | MouseEvent>(event: TEvent): boolean;

Some files were not shown because too many files have changed in this diff Show More