@docsearch/react 4.0.1 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/button.js +1 -1
- package/dist/esm/DocSearchButton.d.ts +32 -0
- package/dist/esm/DocSearchButton.js +1 -0
- package/dist/esm/DocSearchModal.d.ts +391 -0
- package/dist/esm/DocSearchModal.js +3 -0
- package/dist/esm/index.d.ts +31 -7
- package/dist/esm/index.js +3 -1
- package/dist/esm/useDocSearchKeyboardEvents.d.ts +31 -0
- package/dist/esm/useDocSearchKeyboardEvents.js +1 -0
- package/dist/esm/useTheme.d.ts +9 -0
- package/dist/esm/useTheme.js +1 -0
- package/dist/esm/version.d.ts +3 -0
- package/dist/esm/version.js +1 -0
- package/dist/umd/DocSearchModal.js +5 -0
- package/dist/umd/DocSearchModal.js.map +1 -0
- package/dist/umd/DocsearchButton.js +3 -0
- package/dist/umd/DocsearchButton.js.map +1 -0
- package/dist/umd/index.js +4 -2
- package/dist/umd/index.js.map +1 -1
- package/dist/umd/useDocSearchKeyboardEvents.js +3 -0
- package/dist/umd/useDocSearchKeyboardEvents.js.map +1 -0
- package/dist/umd/useTheme.js +3 -0
- package/dist/umd/useTheme.js.map +1 -0
- package/dist/umd/version.js +3 -0
- package/dist/umd/version.js.map +1 -0
- package/modal.js +1 -1
- package/package.json +17 -5
- package/useDocSearchKeyboardEvents.js +1 -0
- package/useTheme.js +1 -0
- package/version.js +1 -0
package/button.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { DocSearchButton } from './dist/esm';
|
|
1
|
+
export { DocSearchButton } from './dist/esm/DocSearchButton.js';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
type DocSearchTheme = 'dark' | 'light';
|
|
4
|
+
|
|
5
|
+
interface KeyboardShortcuts {
|
|
6
|
+
/**
|
|
7
|
+
* Enable/disable the Ctrl/Cmd+K shortcut to toggle the search modal.
|
|
8
|
+
*
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
'Ctrl/Cmd+K'?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Enable/disable the / shortcut to open the search modal.
|
|
14
|
+
*
|
|
15
|
+
* @default true
|
|
16
|
+
*/
|
|
17
|
+
'/'?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type ButtonTranslations = Partial<{
|
|
21
|
+
buttonText: string;
|
|
22
|
+
buttonAriaLabel: string;
|
|
23
|
+
}>;
|
|
24
|
+
type DocSearchButtonProps = React.ComponentProps<'button'> & {
|
|
25
|
+
theme?: DocSearchTheme;
|
|
26
|
+
translations?: ButtonTranslations;
|
|
27
|
+
keyboardShortcuts?: KeyboardShortcuts;
|
|
28
|
+
};
|
|
29
|
+
declare const DocSearchButton: React.ForwardRefExoticComponent<Omit<DocSearchButtonProps, "ref"> & React.RefAttributes<HTMLButtonElement>>;
|
|
30
|
+
|
|
31
|
+
export { DocSearchButton };
|
|
32
|
+
export type { ButtonTranslations, DocSearchButtonProps };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import e,{useEffect as t,useState as r}from"react";function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function o(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)({}).hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},a.apply(null,arguments)}function c(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function i(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?c(Object(r),!0).forEach(function(t){o(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):c(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function l(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,a,c,i=[],l=!0,u=!1;try{if(a=(r=r.call(e)).next,0===t){if(Object(r)!==r)return;l=!1}else for(;!(l=(n=a.call(r)).done)&&(i.push(n.value),i.length!==t);l=!0);}catch(e){u=!0,o=e}finally{try{if(!l&&null!=r.return&&(c=r.return(),Object(c)!==c))return}finally{if(u)throw o}}return i}}(e,t)||function(e,t){if(e){if("string"==typeof e)return n(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var u={"Ctrl/Cmd+K":!0,"/":!0};function C(){return e.createElement("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("path",{d:"M8.19531 8.76758H7.33398C7.02539 8.76758 6.74414 8.69531 6.49023 8.55078C6.23633 8.40234 6.0332 8.20312 5.88086 7.95312C5.73242 7.70312 5.6582 7.42188 5.6582 7.10938C5.6582 6.80078 5.73242 6.51953 5.88086 6.26562C6.0332 6.01172 6.23633 5.80859 6.49023 5.65625C6.74414 5.50391 7.02539 5.42773 7.33398 5.42773C7.64258 5.42773 7.92383 5.50391 8.17773 5.65625C8.43164 5.80859 8.63281 6.01172 8.78125 6.26562C8.93359 6.51953 9.00977 6.80078 9.00977 7.10938V7.96484H10.9902V7.10938C10.9902 6.80078 11.0664 6.51953 11.2188 6.26562C11.3711 6.01172 11.5723 5.80859 11.8223 5.65625C12.0762 5.50391 12.3574 5.42773 12.666 5.42773C12.9746 5.42773 13.2559 5.50391 13.5098 5.65625C13.7637 5.80859 13.9648 6.01172 14.1133 6.26562C14.2656 6.51953 14.3418 6.80078 14.3418 7.10938C14.3418 7.42188 14.2656 7.70312 14.1133 7.95312C13.9648 8.20312 13.7637 8.40234 13.5098 8.55078C13.2559 8.69531 12.9746 8.76758 12.666 8.76758H11.8105V10.7773H12.666C12.9746 10.7773 13.2559 10.8516 13.5098 11C13.7637 11.1445 13.9648 11.3418 14.1133 11.5918C14.2656 11.8418 14.3418 12.123 14.3418 12.4355C14.3418 12.7441 14.2656 13.0254 14.1133 13.2793C13.9648 13.5332 13.7637 13.7363 13.5098 13.8887C13.2559 14.041 12.9746 14.1172 12.666 14.1172C12.3574 14.1172 12.0762 14.041 11.8223 13.8887C11.5723 13.7363 11.3711 13.5332 11.2188 13.2793C11.0664 13.0254 10.9902 12.7441 10.9902 12.4355V11.5801H9.00977V12.4355C9.00977 12.7441 8.93359 13.0254 8.78125 13.2793C8.63281 13.5332 8.43164 13.7363 8.17773 13.8887C7.92383 14.041 7.64258 14.1172 7.33398 14.1172C7.02539 14.1172 6.74414 14.041 6.49023 13.8887C6.23633 13.7363 6.0332 13.5332 5.88086 13.2793C5.73242 13.0254 5.6582 12.7441 5.6582 12.4355C5.6582 12.123 5.73242 11.8418 5.88086 11.5918C6.0332 11.3418 6.23633 11.1445 6.49023 11C6.74414 10.8516 7.02539 10.7773 7.33398 10.7773H8.19531V8.76758ZM7.33398 7.97656H8.19531V7.10938C8.19531 6.875 8.10938 6.67383 7.9375 6.50586C7.76953 6.33398 7.56836 6.24805 7.33398 6.24805C7.09961 6.24805 6.89648 6.33398 6.72461 6.50586C6.55664 6.67383 6.47266 6.875 6.47266 7.10938C6.47266 7.34766 6.55664 7.55273 6.72461 7.72461C6.89648 7.89258 7.09961 7.97656 7.33398 7.97656ZM12.666 7.97656C12.9004 7.97656 13.1016 7.89258 13.2695 7.72461C13.4414 7.55273 13.5273 7.34766 13.5273 7.10938C13.5273 6.875 13.4414 6.67383 13.2695 6.50586C13.1016 6.33398 12.9004 6.24805 12.666 6.24805C12.4316 6.24805 12.2305 6.33398 12.0625 6.50586C11.8945 6.67383 11.8105 6.875 11.8105 7.10938V7.97656H12.666ZM9.00977 10.7773H10.9902V8.76758H9.00977V10.7773ZM7.33398 11.5625C7.09961 11.5625 6.89648 11.6484 6.72461 11.8203C6.55664 11.9883 6.47266 12.1914 6.47266 12.4297C6.47266 12.6641 6.55664 12.8672 6.72461 13.0391C6.89648 13.207 7.09961 13.291 7.33398 13.291C7.56836 13.291 7.76953 13.207 7.9375 13.0391C8.10938 12.8672 8.19531 12.6641 8.19531 12.4297V11.5625H7.33398ZM12.666 11.5625H11.8105V12.4297C11.8105 12.6641 11.8945 12.8672 12.0625 13.0391C12.2305 13.207 12.4316 13.291 12.666 13.291C12.9004 13.291 13.1016 13.207 13.2695 13.0391C13.4414 12.8672 13.5273 12.6641 13.5273 12.4297C13.5273 12.1914 13.4414 11.9883 13.2695 11.8203C13.1016 11.6484 12.9004 11.5625 12.666 11.5625Z",fill:"currentColor"}))}function f(){return e.createElement("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("path",{d:"M8.01562 11.1758L7.95703 9.65234H8.22656L11.9297 5.54492H13.2539L9.75586 9.32422L9.26367 9.79883L8.01562 11.1758ZM7.07812 14V5.54492H8.13281V14H7.07812ZM12.1992 14L9.04102 9.78711L9.76758 9.05469L13.5645 14H12.1992Z",fill:"currentColor"}))}function s(){return e.createElement("svg",{width:"33",height:"20",viewBox:"0 0 33 20",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("path",{d:"M10.4824 14.1992C9.7168 14.1992 9.05469 14.0195 8.49609 13.6602C7.9375 13.3008 7.50586 12.791 7.20117 12.1309C6.90039 11.4707 6.75 10.6875 6.75 9.78125V9.76953C6.75 8.85938 6.90039 8.07422 7.20117 7.41406C7.50586 6.75391 7.93555 6.24414 8.49023 5.88477C9.04883 5.52539 9.71094 5.3457 10.4766 5.3457C11.0703 5.3457 11.6094 5.46289 12.0938 5.69727C12.582 5.92773 12.9844 6.25 13.3008 6.66406C13.6172 7.07422 13.8164 7.54883 13.8984 8.08789L13.8926 8.09961H12.832L12.8262 8.08789C12.7324 7.72461 12.5742 7.41211 12.3516 7.15039C12.1289 6.88477 11.8574 6.67969 11.5371 6.53516C11.2207 6.39062 10.8672 6.31836 10.4766 6.31836C9.9375 6.31836 9.46875 6.45898 9.07031 6.74023C8.67578 7.02148 8.37109 7.41992 8.15625 7.93555C7.94141 8.45117 7.83398 9.0625 7.83398 9.76953V9.78125C7.83398 10.4844 7.94141 11.0938 8.15625 11.6094C8.37109 12.125 8.67578 12.5234 9.07031 12.8047C9.46875 13.0859 9.93945 13.2266 10.4824 13.2266C10.877 13.2266 11.2344 13.1641 11.5547 13.0391C11.875 12.9102 12.1445 12.7285 12.3633 12.4941C12.582 12.2559 12.7344 11.9746 12.8203 11.6504L12.832 11.6387H13.8984V11.6504C13.8047 12.166 13.6016 12.6152 13.2891 12.998C12.9766 13.377 12.5801 13.6719 12.0996 13.8828C11.623 14.0938 11.084 14.1992 10.4824 14.1992ZM17.7832 14.0469C17.1348 14.0469 16.6641 13.916 16.3711 13.6543C16.082 13.3926 15.9375 12.9609 15.9375 12.3594V8.52734H14.9414V7.68359H15.9375V6.04883H16.9922V7.68359H18.375V8.52734H16.9922V12.1016C16.9922 12.4727 17.0625 12.7402 17.2031 12.9043C17.3438 13.0645 17.5781 13.1445 17.9062 13.1445C17.9961 13.1445 18.0723 13.1426 18.1348 13.1387C18.2012 13.1348 18.2812 13.1289 18.375 13.1211V13.9883C18.2773 14.0039 18.1797 14.0176 18.082 14.0293C17.9844 14.041 17.8848 14.0469 17.7832 14.0469ZM19.8984 14V7.68359H20.918V8.62109H21.0117C21.1328 8.28906 21.3379 8.03125 21.627 7.84766C21.916 7.66406 22.2734 7.57227 22.6992 7.57227C22.7969 7.57227 22.8926 7.57812 22.9863 7.58984C23.084 7.59766 23.1582 7.60547 23.209 7.61328V8.60352C23.1035 8.58398 23 8.57031 22.8984 8.5625C22.8008 8.55078 22.6953 8.54492 22.582 8.54492C22.2578 8.54492 21.9707 8.60938 21.7207 8.73828C21.4707 8.86719 21.2734 9.04688 21.1289 9.27734C20.9883 9.50781 20.918 9.77734 20.918 10.0859V14H19.8984ZM24.5273 14V5.17578H25.5469V14H24.5273Z",fill:"currentColor"}))}function m(t){var r=t.size,n=void 0===r?20:r,o=t.color,a=void 0===o?"currentColor":o;return e.createElement("svg",{width:n,height:n,className:"DocSearch-Search-Icon",viewBox:"0 0 24 24","aria-hidden":"true"},e.createElement("circle",{cx:"11",cy:"11",r:"8",stroke:a,fill:"none",strokeWidth:"1.4"}),e.createElement("path",{d:"m21 21-4.3-4.3",stroke:a,fill:"none",strokeLinecap:"round",strokeLinejoin:"round"}))}var d=["translations","keyboardShortcuts"],h="Ctrl";var v=e.forwardRef(function(n,o){var c,v=n.translations,p=void 0===v?{}:v,b=n.keyboardShortcuts,w=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r={};for(var n in e)if({}.hasOwnProperty.call(e,n)){if(-1!==t.indexOf(n))continue;r[n]=e[n]}return r}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(n=0;n<a.length;n++)r=a[n],-1===t.indexOf(r)&&{}.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(n,d),g=p.buttonText,E=void 0===g?"Search":g,O=p.buttonAriaLabel,V=void 0===O?"Search":O,H=(c=b,i(i({},u),c)),S=l(r(null),2),j=S[0],k=S[1];!function(e){var r=e.theme;t(function(){if(r){var e=document.documentElement.dataset.theme;if(r!==e)return document.documentElement.dataset.theme=r,function(){void 0===e?delete document.documentElement.dataset.theme:document.documentElement.dataset.theme=e}}},[r])}({theme:w.theme}),t(function(){"undefined"!=typeof navigator&&(/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)?k("⌘"):k(h))},[]);var P=l(j===h?[h,"Control",e.createElement(s,null)]:["Meta","Meta",e.createElement(C,null)],3),L=P[0],M=P[1],D=P[2],x=H["Ctrl/Cmd+K"],Z="".concat(M,"+k");return e.createElement("button",a({type:"button",className:"DocSearch DocSearch-Button","aria-label":x?"".concat(V," (").concat(Z,")"):V,"aria-keyshortcuts":x?Z:void 0},w,{ref:o}),e.createElement("span",{className:"DocSearch-Button-Container"},e.createElement(m,null),e.createElement("span",{className:"DocSearch-Button-Placeholder"},E)),e.createElement("span",{className:"DocSearch-Button-Keys"},null!==j&&x&&e.createElement(e.Fragment,null,e.createElement(y,{reactsToKey:L},D),e.createElement(y,{reactsToKey:"k"},e.createElement(f,null)))))});function y(n){var o=n.reactsToKey,a=n.children,c=l(r(!1),2),i=c[0],u=c[1];return t(function(){if(o)return window.addEventListener("keydown",e),window.addEventListener("keyup",t),function(){window.removeEventListener("keydown",e),window.removeEventListener("keyup",t)};function e(e){e.key===o&&u(!0)}function t(e){e.key!==o&&"Meta"!==e.key||u(!1)}},[o]),e.createElement("kbd",{className:i?"DocSearch-Button-Key DocSearch-Button-Key--pressed":"DocSearch-Button-Key"+("Ctrl"===o?" DocSearch-Button-Key--ctrl":"")},a)}export{v as DocSearchButton};
|
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import React, { JSX } from 'react';
|
|
2
|
+
import { AutocompleteState, AutocompleteOptions } from '@algolia/autocomplete-core';
|
|
3
|
+
import { SearchParamsObject, LiteClient } from 'algoliasearch/lite';
|
|
4
|
+
|
|
5
|
+
type ContentType = 'askAI' | 'content' | 'lvl0' | 'lvl1' | 'lvl2' | 'lvl3' | 'lvl4' | 'lvl5' | 'lvl6';
|
|
6
|
+
interface DocSearchHitAttributeHighlightResult {
|
|
7
|
+
value: string;
|
|
8
|
+
matchLevel: 'full' | 'none' | 'partial';
|
|
9
|
+
matchedWords: string[];
|
|
10
|
+
fullyHighlighted?: boolean;
|
|
11
|
+
}
|
|
12
|
+
interface DocSearchHitHighlightResultHierarchy {
|
|
13
|
+
lvl0: DocSearchHitAttributeHighlightResult;
|
|
14
|
+
lvl1: DocSearchHitAttributeHighlightResult;
|
|
15
|
+
lvl2: DocSearchHitAttributeHighlightResult;
|
|
16
|
+
lvl3: DocSearchHitAttributeHighlightResult;
|
|
17
|
+
lvl4: DocSearchHitAttributeHighlightResult;
|
|
18
|
+
lvl5: DocSearchHitAttributeHighlightResult;
|
|
19
|
+
lvl6: DocSearchHitAttributeHighlightResult;
|
|
20
|
+
}
|
|
21
|
+
interface DocSearchHitHighlightResult {
|
|
22
|
+
content: DocSearchHitAttributeHighlightResult;
|
|
23
|
+
hierarchy: DocSearchHitHighlightResultHierarchy;
|
|
24
|
+
hierarchy_camel: DocSearchHitHighlightResultHierarchy[];
|
|
25
|
+
}
|
|
26
|
+
interface DocSearchHitAttributeSnippetResult {
|
|
27
|
+
value: string;
|
|
28
|
+
matchLevel: 'full' | 'none' | 'partial';
|
|
29
|
+
}
|
|
30
|
+
interface DocSearchHitSnippetResult {
|
|
31
|
+
content: DocSearchHitAttributeSnippetResult;
|
|
32
|
+
hierarchy: DocSearchHitHighlightResultHierarchy;
|
|
33
|
+
hierarchy_camel: DocSearchHitHighlightResultHierarchy[];
|
|
34
|
+
}
|
|
35
|
+
declare type DocSearchHit = {
|
|
36
|
+
objectID: string;
|
|
37
|
+
content: string | null;
|
|
38
|
+
query?: string;
|
|
39
|
+
url: string;
|
|
40
|
+
url_without_anchor: string;
|
|
41
|
+
type: ContentType;
|
|
42
|
+
anchor: string | null;
|
|
43
|
+
hierarchy: {
|
|
44
|
+
lvl0: string;
|
|
45
|
+
lvl1: string;
|
|
46
|
+
lvl2: string | null;
|
|
47
|
+
lvl3: string | null;
|
|
48
|
+
lvl4: string | null;
|
|
49
|
+
lvl5: string | null;
|
|
50
|
+
lvl6: string | null;
|
|
51
|
+
};
|
|
52
|
+
_highlightResult: DocSearchHitHighlightResult;
|
|
53
|
+
_snippetResult: DocSearchHitSnippetResult;
|
|
54
|
+
_rankingInfo?: {
|
|
55
|
+
promoted: boolean;
|
|
56
|
+
nbTypos: number;
|
|
57
|
+
firstMatchedWord: number;
|
|
58
|
+
proximityDistance?: number;
|
|
59
|
+
geoDistance: number;
|
|
60
|
+
geoPrecision?: number;
|
|
61
|
+
nbExactWords: number;
|
|
62
|
+
words: number;
|
|
63
|
+
filters: number;
|
|
64
|
+
userScore: number;
|
|
65
|
+
matchedGeoLocation?: {
|
|
66
|
+
lat: number;
|
|
67
|
+
lng: number;
|
|
68
|
+
distance: number;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
_distinctSeqID?: number;
|
|
72
|
+
__autocomplete_indexName?: string;
|
|
73
|
+
__autocomplete_queryID?: string;
|
|
74
|
+
__autocomplete_algoliaCredentials?: {
|
|
75
|
+
appId: string;
|
|
76
|
+
apiKey: string;
|
|
77
|
+
};
|
|
78
|
+
__autocomplete_id?: number;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
type DocSearchTheme = 'dark' | 'light';
|
|
82
|
+
|
|
83
|
+
type InternalDocSearchHit = DocSearchHit & {
|
|
84
|
+
__docsearch_parent: InternalDocSearchHit | null;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
interface KeyboardShortcuts {
|
|
88
|
+
/**
|
|
89
|
+
* Enable/disable the Ctrl/Cmd+K shortcut to toggle the search modal.
|
|
90
|
+
*
|
|
91
|
+
* @default true
|
|
92
|
+
*/
|
|
93
|
+
'Ctrl/Cmd+K'?: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Enable/disable the / shortcut to open the search modal.
|
|
96
|
+
*
|
|
97
|
+
* @default true
|
|
98
|
+
*/
|
|
99
|
+
'/'?: boolean;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
type StoredDocSearchHit = Omit<DocSearchHit, '_highlightResult' | '_snippetResult'>;
|
|
103
|
+
|
|
104
|
+
type ButtonTranslations = Partial<{
|
|
105
|
+
buttonText: string;
|
|
106
|
+
buttonAriaLabel: string;
|
|
107
|
+
}>;
|
|
108
|
+
|
|
109
|
+
type DocSearchTranslations = Partial<{
|
|
110
|
+
button: ButtonTranslations;
|
|
111
|
+
modal: ModalTranslations;
|
|
112
|
+
}>;
|
|
113
|
+
type DocSearchTransformClient = {
|
|
114
|
+
search: LiteClient['search'];
|
|
115
|
+
addAlgoliaAgent: LiteClient['addAlgoliaAgent'];
|
|
116
|
+
transporter: Pick<LiteClient['transporter'], 'algoliaAgent'>;
|
|
117
|
+
};
|
|
118
|
+
type AskAiSearchParameters = {
|
|
119
|
+
facetFilters?: string[];
|
|
120
|
+
filters?: string;
|
|
121
|
+
attributesToRetrieve?: string[];
|
|
122
|
+
restrictSearchableAttributes?: string[];
|
|
123
|
+
distinct?: boolean;
|
|
124
|
+
};
|
|
125
|
+
type DocSearchAskAi = {
|
|
126
|
+
/**
|
|
127
|
+
* The index name to use for the ask AI feature. Your assistant will search this index for relevant documents.
|
|
128
|
+
* If not provided, the index name will be used.
|
|
129
|
+
*/
|
|
130
|
+
indexName?: string;
|
|
131
|
+
/**
|
|
132
|
+
* The API key to use for the ask AI feature. Your assistant will use this API key to search the index.
|
|
133
|
+
* If not provided, the API key will be used.
|
|
134
|
+
*/
|
|
135
|
+
apiKey?: string;
|
|
136
|
+
/**
|
|
137
|
+
* The app ID to use for the ask AI feature. Your assistant will use this app ID to search the index.
|
|
138
|
+
* If not provided, the app ID will be used.
|
|
139
|
+
*/
|
|
140
|
+
appId?: string;
|
|
141
|
+
/**
|
|
142
|
+
* The assistant ID to use for the ask AI feature.
|
|
143
|
+
*/
|
|
144
|
+
assistantId: string | null;
|
|
145
|
+
/**
|
|
146
|
+
* The search parameters to use for the ask AI feature.
|
|
147
|
+
*/
|
|
148
|
+
searchParameters?: AskAiSearchParameters;
|
|
149
|
+
};
|
|
150
|
+
interface DocSearchIndex {
|
|
151
|
+
name: string;
|
|
152
|
+
searchParameters?: SearchParamsObject;
|
|
153
|
+
}
|
|
154
|
+
interface DocSearchProps {
|
|
155
|
+
/**
|
|
156
|
+
* Algolia application id used by the search client.
|
|
157
|
+
*/
|
|
158
|
+
appId: string;
|
|
159
|
+
/**
|
|
160
|
+
* Public api key with search permissions for the index.
|
|
161
|
+
*/
|
|
162
|
+
apiKey: string;
|
|
163
|
+
/**
|
|
164
|
+
* Name of the algolia index to query.
|
|
165
|
+
*
|
|
166
|
+
* @deprecated `indexName` will be removed in a future version. Please use `indices` property going forward.
|
|
167
|
+
*/
|
|
168
|
+
indexName?: string;
|
|
169
|
+
/**
|
|
170
|
+
* List of indices and _optional_ searchParameters to be used for search.
|
|
171
|
+
*
|
|
172
|
+
* @see {@link https://docsearch.algolia.com/docs/api#indices}
|
|
173
|
+
*/
|
|
174
|
+
indices?: Array<DocSearchIndex | string>;
|
|
175
|
+
/**
|
|
176
|
+
* Configuration or assistant id to enable ask ai mode. Pass a string assistant id or a full config object.
|
|
177
|
+
*/
|
|
178
|
+
askAi?: DocSearchAskAi | string;
|
|
179
|
+
/**
|
|
180
|
+
* Theme overrides applied to the modal and related components.
|
|
181
|
+
*/
|
|
182
|
+
theme?: DocSearchTheme;
|
|
183
|
+
/**
|
|
184
|
+
* Placeholder text for the search input.
|
|
185
|
+
*/
|
|
186
|
+
placeholder?: string;
|
|
187
|
+
/**
|
|
188
|
+
* Additional algolia search parameters to merge into each query.
|
|
189
|
+
*
|
|
190
|
+
* @deprecated `searchParameters` will be removed in a future version. Please use `indices` property going forward.
|
|
191
|
+
*/
|
|
192
|
+
searchParameters?: SearchParamsObject;
|
|
193
|
+
/**
|
|
194
|
+
* Maximum number of hits to display per source/group.
|
|
195
|
+
*/
|
|
196
|
+
maxResultsPerGroup?: number;
|
|
197
|
+
/**
|
|
198
|
+
* Hook to post-process hits before rendering.
|
|
199
|
+
*/
|
|
200
|
+
transformItems?: (items: DocSearchHit[]) => DocSearchHit[];
|
|
201
|
+
/**
|
|
202
|
+
* Custom component to render an individual hit.
|
|
203
|
+
*/
|
|
204
|
+
hitComponent?: (props: {
|
|
205
|
+
hit: InternalDocSearchHit | StoredDocSearchHit;
|
|
206
|
+
children: React.ReactNode;
|
|
207
|
+
}) => JSX.Element;
|
|
208
|
+
/**
|
|
209
|
+
* Custom component rendered at the bottom of the results panel.
|
|
210
|
+
*/
|
|
211
|
+
resultsFooterComponent?: (props: {
|
|
212
|
+
state: AutocompleteState<InternalDocSearchHit>;
|
|
213
|
+
}) => JSX.Element | null;
|
|
214
|
+
/**
|
|
215
|
+
* Hook to wrap or modify the algolia search client.
|
|
216
|
+
*/
|
|
217
|
+
transformSearchClient?: (searchClient: DocSearchTransformClient) => DocSearchTransformClient;
|
|
218
|
+
/**
|
|
219
|
+
* Disable storage and usage of recent and favorite searches.
|
|
220
|
+
*/
|
|
221
|
+
disableUserPersonalization?: boolean;
|
|
222
|
+
/**
|
|
223
|
+
* Query string to prefill when opening the modal.
|
|
224
|
+
*/
|
|
225
|
+
initialQuery?: string;
|
|
226
|
+
/**
|
|
227
|
+
* Custom navigator for controlling link navigation.
|
|
228
|
+
*/
|
|
229
|
+
navigator?: AutocompleteOptions<InternalDocSearchHit>['navigator'];
|
|
230
|
+
/**
|
|
231
|
+
* Localized strings for the button and modal ui.
|
|
232
|
+
*/
|
|
233
|
+
translations?: DocSearchTranslations;
|
|
234
|
+
/**
|
|
235
|
+
* Builds a url to report missing results for a given query.
|
|
236
|
+
*/
|
|
237
|
+
getMissingResultsUrl?: ({ query }: {
|
|
238
|
+
query: string;
|
|
239
|
+
}) => string;
|
|
240
|
+
/**
|
|
241
|
+
* Insights client integration options to send analytics events.
|
|
242
|
+
*/
|
|
243
|
+
insights?: AutocompleteOptions<InternalDocSearchHit>['insights'];
|
|
244
|
+
/**
|
|
245
|
+
* The container element where the modal should be portaled to. Defaults to document.body.
|
|
246
|
+
*/
|
|
247
|
+
portalContainer?: DocumentFragment | Element;
|
|
248
|
+
/**
|
|
249
|
+
* Limit of how many recent searches should be saved/displayed..
|
|
250
|
+
*
|
|
251
|
+
* @default 7
|
|
252
|
+
*/
|
|
253
|
+
recentSearchesLimit?: number;
|
|
254
|
+
/**
|
|
255
|
+
* Limit of how many recent searches should be saved/displayed when there are favorited searches..
|
|
256
|
+
*
|
|
257
|
+
* @default 4
|
|
258
|
+
*/
|
|
259
|
+
recentSearchesWithFavoritesLimit?: number;
|
|
260
|
+
/**
|
|
261
|
+
* Configuration for keyboard shortcuts. Allows enabling/disabling specific shortcuts.
|
|
262
|
+
*/
|
|
263
|
+
keyboardShortcuts?: KeyboardShortcuts;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
type FooterTranslations = Partial<{
|
|
267
|
+
selectText: string;
|
|
268
|
+
submitQuestionText: string;
|
|
269
|
+
selectKeyAriaLabel: string;
|
|
270
|
+
navigateText: string;
|
|
271
|
+
navigateUpKeyAriaLabel: string;
|
|
272
|
+
navigateDownKeyAriaLabel: string;
|
|
273
|
+
closeText: string;
|
|
274
|
+
backToSearchText: string;
|
|
275
|
+
closeKeyAriaLabel: string;
|
|
276
|
+
poweredByText: string;
|
|
277
|
+
}>;
|
|
278
|
+
|
|
279
|
+
type NewConversationTranslations = Partial<{
|
|
280
|
+
newConversationTitle: string;
|
|
281
|
+
newConversationDescription: string;
|
|
282
|
+
}>;
|
|
283
|
+
|
|
284
|
+
type AskAiScreenTranslations = Partial<{
|
|
285
|
+
disclaimerText: string;
|
|
286
|
+
relatedSourcesText: string;
|
|
287
|
+
thinkingText: string;
|
|
288
|
+
copyButtonText: string;
|
|
289
|
+
copyButtonCopiedText: string;
|
|
290
|
+
copyButtonTitle: string;
|
|
291
|
+
likeButtonTitle: string;
|
|
292
|
+
dislikeButtonTitle: string;
|
|
293
|
+
thanksForFeedbackText: string;
|
|
294
|
+
preToolCallText: string;
|
|
295
|
+
duringToolCallText: string;
|
|
296
|
+
afterToolCallText: string;
|
|
297
|
+
/**
|
|
298
|
+
* Build the full jsx element for the aggregated search block.
|
|
299
|
+
* If provided, completely overrides the default english renderer.
|
|
300
|
+
*/
|
|
301
|
+
aggregatedToolCallNode?: (queries: string[], onSearchQueryClick: (query: string) => void) => React.ReactNode;
|
|
302
|
+
/**
|
|
303
|
+
* Generate the list connective parts only (backwards compatibility).
|
|
304
|
+
* Receives full list of queries and should return translation parts for before/after/separators.
|
|
305
|
+
* Example: (qs) => ({ before: 'searched for ', separator: ', ', lastSeparator: ' and ', after: '' }).
|
|
306
|
+
*/
|
|
307
|
+
aggregatedToolCallText?: (queries: string[]) => {
|
|
308
|
+
before?: string;
|
|
309
|
+
separator?: string;
|
|
310
|
+
lastSeparator?: string;
|
|
311
|
+
after?: string;
|
|
312
|
+
};
|
|
313
|
+
/**
|
|
314
|
+
* Message that's shown when user has stopped the streaming of a message.
|
|
315
|
+
*/
|
|
316
|
+
stoppedStreamingText: string;
|
|
317
|
+
}>;
|
|
318
|
+
|
|
319
|
+
type ErrorScreenTranslations = Partial<{
|
|
320
|
+
titleText: string;
|
|
321
|
+
helpText: string;
|
|
322
|
+
}>;
|
|
323
|
+
|
|
324
|
+
type NoResultsScreenTranslations = Partial<{
|
|
325
|
+
noResultsText: string;
|
|
326
|
+
suggestedQueryText: string;
|
|
327
|
+
reportMissingResultsText: string;
|
|
328
|
+
reportMissingResultsLinkText: string;
|
|
329
|
+
}>;
|
|
330
|
+
|
|
331
|
+
type ResultsScreenTranslations = Partial<{
|
|
332
|
+
askAiPlaceholder: string;
|
|
333
|
+
noResultsAskAiPlaceholder: string;
|
|
334
|
+
}>;
|
|
335
|
+
|
|
336
|
+
type StartScreenTranslations = Partial<{
|
|
337
|
+
recentSearchesTitle: string;
|
|
338
|
+
noRecentSearchesText: string;
|
|
339
|
+
saveRecentSearchButtonTitle: string;
|
|
340
|
+
removeRecentSearchButtonTitle: string;
|
|
341
|
+
favoriteSearchesTitle: string;
|
|
342
|
+
removeFavoriteSearchButtonTitle: string;
|
|
343
|
+
recentConversationsTitle: string;
|
|
344
|
+
removeRecentConversationButtonTitle: string;
|
|
345
|
+
}>;
|
|
346
|
+
|
|
347
|
+
type ScreenStateTranslations = Partial<{
|
|
348
|
+
errorScreen: ErrorScreenTranslations;
|
|
349
|
+
startScreen: StartScreenTranslations;
|
|
350
|
+
noResultsScreen: NoResultsScreenTranslations;
|
|
351
|
+
resultsScreen: ResultsScreenTranslations;
|
|
352
|
+
askAiScreen: AskAiScreenTranslations;
|
|
353
|
+
newConversation: NewConversationTranslations;
|
|
354
|
+
}>;
|
|
355
|
+
|
|
356
|
+
type SearchBoxTranslations = Partial<{
|
|
357
|
+
clearButtonTitle: string;
|
|
358
|
+
clearButtonAriaLabel: string;
|
|
359
|
+
closeButtonText: string;
|
|
360
|
+
closeButtonAriaLabel: string;
|
|
361
|
+
placeholderText: string;
|
|
362
|
+
placeholderTextAskAi: string;
|
|
363
|
+
placeholderTextAskAiStreaming: string;
|
|
364
|
+
enterKeyHint: string;
|
|
365
|
+
enterKeyHintAskAi: string;
|
|
366
|
+
searchInputLabel: string;
|
|
367
|
+
backToKeywordSearchButtonText: string;
|
|
368
|
+
backToKeywordSearchButtonAriaLabel: string;
|
|
369
|
+
newConversationPlaceholder: string;
|
|
370
|
+
conversationHistoryTitle: string;
|
|
371
|
+
startNewConversationText: string;
|
|
372
|
+
viewConversationHistoryText: string;
|
|
373
|
+
}>;
|
|
374
|
+
|
|
375
|
+
type ModalTranslations = Partial<{
|
|
376
|
+
searchBox: SearchBoxTranslations;
|
|
377
|
+
newConversation: NewConversationTranslations;
|
|
378
|
+
footer: FooterTranslations;
|
|
379
|
+
}> & ScreenStateTranslations;
|
|
380
|
+
type DocSearchModalProps = DocSearchProps & {
|
|
381
|
+
initialScrollY: number;
|
|
382
|
+
onAskAiToggle: (toggle: boolean) => void;
|
|
383
|
+
onClose?: () => void;
|
|
384
|
+
isAskAiActive?: boolean;
|
|
385
|
+
canHandleAskAi?: boolean;
|
|
386
|
+
translations?: ModalTranslations;
|
|
387
|
+
};
|
|
388
|
+
declare function DocSearchModal({ appId, apiKey, placeholder, askAi, maxResultsPerGroup, theme, onClose, transformItems, hitComponent, resultsFooterComponent, navigator, initialScrollY, transformSearchClient, disableUserPersonalization, initialQuery: initialQueryFromProp, translations, getMissingResultsUrl, insights, onAskAiToggle, isAskAiActive, canHandleAskAi, recentSearchesLimit, recentSearchesWithFavoritesLimit, indices, indexName, searchParameters, }: DocSearchModalProps): JSX.Element;
|
|
389
|
+
|
|
390
|
+
export { DocSearchModal };
|
|
391
|
+
export type { DocSearchModalProps, ModalTranslations };
|