@docsearch/js 5.0.0-beta.2 → 5.0.0-beta.4

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.
@@ -1,6 +1,6 @@
1
- /*! @docsearch/js 5.0.0-beta.2 (UNRELEASED c7e1a88) | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
2
- import { DocSearchProps as DocSearchProps$1 } from "@docsearch/react";
1
+ /*! @docsearch/js 5.0.0-beta.4 (UNRELEASED 11d6ed4) | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
3
2
  import { InitialAskAiMessage } from "@docsearch/core";
3
+ import { DocSearchProps as DocSearchProps$1, HitComponentProps, ResultsFooterComponentProps } from "@docsearch/react";
4
4
  //#region ../../node_modules/.bun/preact@11.0.0-beta.0/node_modules/preact/src/index.d.ts
5
5
  import JSX = JSXInternal;
6
6
  //#endregion
@@ -19,18 +19,49 @@ interface DocSearchCallbacks {
19
19
  onClose?: () => void;
20
20
  interceptAskAiEvent?: (initialMessage: InitialAskAiMessage) => boolean | void;
21
21
  }
22
- type DocSearchProps$2<TProps> = DocSearchCallbacks & Omit<TProps, 'onSidepanelClose' | 'onSidepanelOpen'> & {
22
+ type TemplateHelpers = {
23
+ html: typeof html;
24
+ };
25
+ type TemplateFnReturnType = JSX.Element | string | (() => JSX.Element) | null;
26
+ type HitComponentFn = (props: HitComponentProps, helpers: TemplateHelpers) => TemplateFnReturnType;
27
+ type ResultsFooterComponentFn = (props: ResultsFooterComponentProps, helpers: TemplateHelpers) => TemplateFnReturnType;
28
+ type FooterActionFn = (props: never, helpers: TemplateHelpers) => TemplateFnReturnType;
29
+ type DocSearchProps$2<TProps> = DocSearchCallbacks & Omit<TProps, 'onSidepanelClose' | 'onSidepanelOpen' | 'hitComponent' | 'resultsFooterComponent' | 'footerAction'> & {
23
30
  container: HTMLElement | string;
24
31
  environment?: typeof window;
32
+ /**
33
+ * Custom component to render an individual hit. Supports template patterns:
34
+ *
35
+ * - HTML strings with html helper: (props, { html }) => html`<div>...</div>`
36
+ * - JSX templates: (props) => <div>...</div>
37
+ * - Function-based templates: (props) => string | JSX.Element | Function.
38
+ */
39
+ hitComponent?: HitComponentFn;
40
+ /**
41
+ * Custom component rendered at the bottom of the results panel. Supports
42
+ * template patterns:
43
+ *
44
+ * - HTML strings with html helper: (props, { html }) => html`<div>...</div>`
45
+ * - JSX templates: (props) => <div>...</div>
46
+ * - Function-based templates: (props) => string | JSX.Element | Function.
47
+ */
48
+ resultsFooterComponent?: ResultsFooterComponentFn;
49
+ /**
50
+ * A custom action that can be rendered in the Modal's footer before the
51
+ * Algolia logo. The component will be rendered as a child of `<div
52
+ * className="DocSearch-Footer-Action" />`. Supports template patterns:
53
+ *
54
+ * - HTML strings with html helper: (props, { html }) => html`<div>...</div>`
55
+ * - JSX templates: (props) => <div>...</div>
56
+ * - Function-based templates: (props) => string | JSX.Element | Function.
57
+ */
58
+ footerAction?: FooterActionFn;
25
59
  };
26
60
  declare const html: (strings: TemplateStringsArray, ...values: unknown[]) => JSX.Element;
27
- type TemplateHelpers = Record<string, unknown> & {
28
- html: typeof html;
29
- };
30
61
  //#endregion
31
62
  //#region src/docsearchComponent.d.ts
32
63
  type DocSearchProps = DocSearchProps$2<DocSearchProps$1>;
33
64
  declare const docsearch: (allProps: DocSearchProps) => DocSearchInstance;
34
65
  //#endregion
35
- export { type DocSearchCallbacks, type DocSearchInstance, type DocSearchProps, type TemplateHelpers, docsearch as default };
66
+ export { type DocSearchCallbacks, type DocSearchInstance, type DocSearchProps, type FooterActionFn, type HitComponentFn, type ResultsFooterComponentFn, type TemplateHelpers, docsearch as default };
36
67
  //# sourceMappingURL=docsearch.d.ts.map
@@ -1,4 +1,4 @@
1
- /*! @docsearch/js 5.0.0-beta.2 (UNRELEASED c7e1a88) | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
1
+ /*! @docsearch/js 5.0.0-beta.4 (UNRELEASED 11d6ed4) | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
2
2
  //#region \0rolldown/runtime.js
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1182,7 +1182,7 @@ function DocSearchButtonKey({ reactsToKey, children }) {
1182
1182
 
1183
1183
  //#endregion
1184
1184
  //#region ../docsearch-react/dist/esm/version.js
1185
- const version$1 = "5.0.0-beta.2";
1185
+ const version$1 = "5.0.0-beta.4";
1186
1186
 
1187
1187
  //#endregion
1188
1188
  //#region \0@oxc-project+runtime@0.139.0/helpers/esm/OverloadYield.js
@@ -12380,7 +12380,7 @@ function useMenuParent() {
12380
12380
  }
12381
12381
 
12382
12382
  //#endregion
12383
- //#region ../docsearch-react/dist/esm/normalizeDocSearchIndexes-D8P3VEXa.js
12383
+ //#region ../docsearch-react/dist/esm/normalizeDocSearchIndexes-ChnVvoVt.js
12384
12384
  init_compat();
12385
12385
  function capitalize(text) {
12386
12386
  return `${text.charAt(0).toLocaleUpperCase()}${text.substring(1)}`;
@@ -12836,12 +12836,13 @@ function CommandIcon(props) {
12836
12836
  strokeWidth: "1.4"
12837
12837
  }, props.children));
12838
12838
  }
12839
- function Footer({ translations = {}, isAskAiActive = false }) {
12839
+ function Footer({ translations = {}, isAskAiActive = false, footerAction }) {
12840
12840
  const { selectText = "Select", selectKeyAriaLabel = "Enter key", submitQuestionText = "Submit question", navigateText = "Navigate", navigateUpKeyAriaLabel = "Arrow up", navigateDownKeyAriaLabel = "Arrow down", closeText = "Close", backToSearchText = "Back to search", closeKeyAriaLabel = "Escape key", poweredByText = "Powered by" } = translations;
12841
- return /* @__PURE__ */ En.createElement(En.Fragment, null, /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Logo" }, /* @__PURE__ */ En.createElement(AlgoliaLogo, { translations: { poweredByText } })), /* @__PURE__ */ En.createElement("ul", { className: "DocSearch-Commands" }, /* @__PURE__ */ En.createElement("li", null, /* @__PURE__ */ En.createElement("kbd", { className: "DocSearch-Commands-Key" }, /* @__PURE__ */ En.createElement(CommandIcon, { ariaLabel: navigateDownKeyAriaLabel }, /* @__PURE__ */ En.createElement("path", { d: "M12 5v14" }), /* @__PURE__ */ En.createElement("path", { d: "m19 12-7 7-7-7" }))), /* @__PURE__ */ En.createElement("kbd", { className: "DocSearch-Commands-Key" }, /* @__PURE__ */ En.createElement(CommandIcon, { ariaLabel: navigateUpKeyAriaLabel }, /* @__PURE__ */ En.createElement("path", { d: "m5 12 7-7 7 7" }), /* @__PURE__ */ En.createElement("path", { d: "M12 19V5" }))), /* @__PURE__ */ En.createElement("span", { className: "DocSearch-Label" }, navigateText)), /* @__PURE__ */ En.createElement("li", null, /* @__PURE__ */ En.createElement("kbd", { className: "DocSearch-Commands-Key" }, /* @__PURE__ */ En.createElement(CommandIcon, { ariaLabel: selectKeyAriaLabel }, /* @__PURE__ */ En.createElement("polyline", { points: "9 10 4 15 9 20" }), /* @__PURE__ */ En.createElement("path", { d: "M20 4v7a4 4 0 0 1-4 4H4" }))), /* @__PURE__ */ En.createElement("span", { className: "DocSearch-Label" }, isAskAiActive ? submitQuestionText : selectText)), /* @__PURE__ */ En.createElement("li", null, /* @__PURE__ */ En.createElement("kbd", { className: "DocSearch-Commands-Key" }, /* @__PURE__ */ En.createElement("span", { className: "DocSearch-Escape-Key" }, "ESC")), /* @__PURE__ */ En.createElement("span", {
12841
+ const hasFooterAction = footerAction !== null && footerAction !== void 0 && typeof footerAction !== "boolean";
12842
+ return /* @__PURE__ */ En.createElement(En.Fragment, null, /* @__PURE__ */ En.createElement("ul", { className: "DocSearch-Commands" }, /* @__PURE__ */ En.createElement("li", null, /* @__PURE__ */ En.createElement("kbd", { className: "DocSearch-Commands-Key" }, /* @__PURE__ */ En.createElement(CommandIcon, { ariaLabel: navigateDownKeyAriaLabel }, /* @__PURE__ */ En.createElement("path", { d: "M12 5v14" }), /* @__PURE__ */ En.createElement("path", { d: "m19 12-7 7-7-7" }))), /* @__PURE__ */ En.createElement("kbd", { className: "DocSearch-Commands-Key" }, /* @__PURE__ */ En.createElement(CommandIcon, { ariaLabel: navigateUpKeyAriaLabel }, /* @__PURE__ */ En.createElement("path", { d: "m5 12 7-7 7 7" }), /* @__PURE__ */ En.createElement("path", { d: "M12 19V5" }))), /* @__PURE__ */ En.createElement("span", { className: "DocSearch-Label" }, navigateText)), /* @__PURE__ */ En.createElement("li", null, /* @__PURE__ */ En.createElement("kbd", { className: "DocSearch-Commands-Key" }, /* @__PURE__ */ En.createElement(CommandIcon, { ariaLabel: selectKeyAriaLabel }, /* @__PURE__ */ En.createElement("polyline", { points: "9 10 4 15 9 20" }), /* @__PURE__ */ En.createElement("path", { d: "M20 4v7a4 4 0 0 1-4 4H4" }))), /* @__PURE__ */ En.createElement("span", { className: "DocSearch-Label" }, isAskAiActive ? submitQuestionText : selectText)), /* @__PURE__ */ En.createElement("li", null, /* @__PURE__ */ En.createElement("kbd", { className: "DocSearch-Commands-Key" }, /* @__PURE__ */ En.createElement("span", { className: "DocSearch-Escape-Key" }, "ESC")), /* @__PURE__ */ En.createElement("span", {
12842
12843
  className: "DocSearch-Label",
12843
12844
  "aria-label": closeKeyAriaLabel
12844
- }, isAskAiActive ? backToSearchText : closeText))));
12845
+ }, isAskAiActive ? backToSearchText : closeText))), /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Footer-Actions" }, hasFooterAction && /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Footer-Action" }, footerAction), /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Logo" }, /* @__PURE__ */ En.createElement(AlgoliaLogo, { translations: { poweredByText } }))));
12845
12846
  }
12846
12847
  function Hit({ hit, children }) {
12847
12848
  return /* @__PURE__ */ En.createElement("a", { href: hit.url }, children);
@@ -12999,7 +13000,7 @@ function useTrapFocus({ container }) {
12999
13000
  };
13000
13001
  }, [container]);
13001
13002
  }
13002
- function useDocSearchModalEffects({ initialScrollY, modalRef, snippetLength, theme }) {
13003
+ function useDocSearchModalEffects({ initialScrollY, modalRef, theme }) {
13003
13004
  useTheme({ theme });
13004
13005
  En.useEffect(() => {
13005
13006
  document.body.classList.add("DocSearch--active");
@@ -13019,9 +13020,6 @@ function useDocSearchModalEffects({ initialScrollY, modalRef, snippetLength, the
13019
13020
  document.body.style.marginInlineEnd = "0px";
13020
13021
  };
13021
13022
  }, []);
13022
- En.useEffect(() => {
13023
- if (window.matchMedia("(max-width: 768px)").matches) snippetLength.current = 5;
13024
- }, [snippetLength]);
13025
13023
  En.useEffect(() => {
13026
13024
  function setFullViewportHeight() {
13027
13025
  if (modalRef.current) {
@@ -13036,7 +13034,7 @@ function useDocSearchModalEffects({ initialScrollY, modalRef, snippetLength, the
13036
13034
  };
13037
13035
  }, [modalRef]);
13038
13036
  }
13039
- function useModalEnvironment({ getEnvironmentProps, containerRef, dropdownRef, formElementRef, inputRef, initialScrollY, modalRef, snippetLength, theme }) {
13037
+ function useModalEnvironment({ getEnvironmentProps, containerRef, dropdownRef, formElementRef, inputRef, initialScrollY, modalRef, theme }) {
13040
13038
  useTouchEvents({
13041
13039
  getEnvironmentProps,
13042
13040
  panelElement: dropdownRef.current,
@@ -13047,7 +13045,6 @@ function useModalEnvironment({ getEnvironmentProps, containerRef, dropdownRef, f
13047
13045
  useDocSearchModalEffects({
13048
13046
  initialScrollY,
13049
13047
  modalRef,
13050
- snippetLength,
13051
13048
  theme
13052
13049
  });
13053
13050
  }
@@ -13057,8 +13054,7 @@ function useModalRefs() {
13057
13054
  modalRef: En.useRef(null),
13058
13055
  formElementRef: En.useRef(null),
13059
13056
  dropdownRef: En.useRef(null),
13060
- inputRef: En.useRef(null),
13061
- snippetLength: En.useRef(15)
13057
+ inputRef: En.useRef(null)
13062
13058
  };
13063
13059
  }
13064
13060
  function useRefreshOnInitialQuery({ initialQuery, inputRef, refresh }) {
@@ -13412,7 +13408,7 @@ function buildNoQuerySources({ recentSearches, favoriteSearches, saveRecentSearc
13412
13408
  }
13413
13409
  }];
13414
13410
  }
13415
- async function buildQuerySources({ query, state: sourcesState, setContext, setStatus, searchClient, indexes, snippetLength, insights, appId, apiKey, maxResultsPerGroup, transformItems = identity, saveRecentSearch, onClose, facetSelections }) {
13411
+ async function buildQuerySources({ query, state: sourcesState, setContext, setStatus, searchClient, indexes, insights, appId, apiKey, maxResultsPerGroup, transformItems = identity, saveRecentSearch, onClose, facetSelections }) {
13416
13412
  const insightsActive = insights;
13417
13413
  try {
13418
13414
  const { results } = await searchClient.search({ requests: indexes.map((index) => {
@@ -13436,13 +13432,13 @@ async function buildQuerySources({ query, state: sourcesState, setContext, setSt
13436
13432
  "url"
13437
13433
  ],
13438
13434
  attributesToSnippet: (_searchParams$attribu2 = searchParams === null || searchParams === void 0 ? void 0 : searchParams.attributesToSnippet) !== null && _searchParams$attribu2 !== void 0 ? _searchParams$attribu2 : [
13439
- `hierarchy.lvl1:${snippetLength.current}`,
13440
- `hierarchy.lvl2:${snippetLength.current}`,
13441
- `hierarchy.lvl3:${snippetLength.current}`,
13442
- `hierarchy.lvl4:${snippetLength.current}`,
13443
- `hierarchy.lvl5:${snippetLength.current}`,
13444
- `hierarchy.lvl6:${snippetLength.current}`,
13445
- `content:${snippetLength.current}`
13435
+ `hierarchy.lvl1:15`,
13436
+ `hierarchy.lvl2:15`,
13437
+ `hierarchy.lvl3:15`,
13438
+ `hierarchy.lvl4:15`,
13439
+ `hierarchy.lvl5:15`,
13440
+ `hierarchy.lvl6:15`,
13441
+ `content:15`
13446
13442
  ],
13447
13443
  snippetEllipsisText: (_searchParams$snippet = searchParams === null || searchParams === void 0 ? void 0 : searchParams.snippetEllipsisText) !== null && _searchParams$snippet !== void 0 ? _searchParams$snippet : "…",
13448
13444
  highlightPreTag: (_searchParams$highlig = searchParams === null || searchParams === void 0 ? void 0 : searchParams.highlightPreTag) !== null && _searchParams$highlig !== void 0 ? _searchParams$highlig : "<mark>",
@@ -16309,7 +16305,7 @@ function createAutocomplete(options) {
16309
16305
  }
16310
16306
 
16311
16307
  //#endregion
16312
- //#region ../docsearch-react/dist/esm/DocSearchModal-D_tfhoN1.js
16308
+ //#region ../docsearch-react/dist/esm/DocSearchModal-CITTG0fe.js
16313
16309
  init_compat();
16314
16310
  const _excluded$3 = ["translations"];
16315
16311
  function KeywordSearchBox(_ref) {
@@ -16374,7 +16370,8 @@ const _excluded$4 = [
16374
16370
  "recentSearchesLimit",
16375
16371
  "recentSearchesWithFavoritesLimit",
16376
16372
  "indices",
16377
- "facets"
16373
+ "facets",
16374
+ "footerAction"
16378
16375
  ];
16379
16376
  const _excluded2 = [
16380
16377
  "footer",
@@ -16383,7 +16380,7 @@ const _excluded2 = [
16383
16380
  ];
16384
16381
  function DocSearchModal(_ref) {
16385
16382
  var _translations$searchB;
16386
- let { appId, apiKey, maxResultsPerGroup, theme, onClose = noop$1, transformItems = identity, hitComponent = Hit, resultsFooterComponent = () => null, navigator, initialScrollY = 0, transformSearchClient = identity, disableUserPersonalization = false, initialQuery: initialQueryFromProp = "", translations = {}, getMissingResultsUrl, insights = false, recentSearchesLimit = 7, recentSearchesWithFavoritesLimit = 4, indices, facets } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$4);
16383
+ let { appId, apiKey, maxResultsPerGroup, theme, onClose = noop$1, transformItems = identity, hitComponent = Hit, resultsFooterComponent = () => null, navigator, initialScrollY = 0, transformSearchClient = identity, disableUserPersonalization = false, initialQuery: initialQueryFromProp = "", translations = {}, getMissingResultsUrl, insights = false, recentSearchesLimit = 7, recentSearchesWithFavoritesLimit = 4, indices, facets, footerAction } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$4);
16387
16384
  const { footer: footerTranslations, searchBox: searchBoxTranslations, facets: facetBarTranslations } = translations, screenStateTranslations = _objectWithoutProperties$6(translations, _excluded2);
16388
16385
  const [state, setState] = En.useState({
16389
16386
  query: "",
@@ -16395,7 +16392,7 @@ function DocSearchModal(_ref) {
16395
16392
  status: "idle"
16396
16393
  });
16397
16394
  const placeholder = (translations === null || translations === void 0 || (_translations$searchB = translations.searchBox) === null || _translations$searchB === void 0 ? void 0 : _translations$searchB.placeholderText) || props.placeholder || "Search docs";
16398
- const { containerRef, modalRef, formElementRef, dropdownRef, inputRef, snippetLength } = useModalRefs();
16395
+ const { containerRef, modalRef, formElementRef, dropdownRef, inputRef } = useModalRefs();
16399
16396
  const { initialQuery, initialQueryFromSelection } = useInitialModalQuery(initialQueryFromProp);
16400
16397
  const searchClient = useSearchClient(appId, apiKey, transformSearchClient);
16401
16398
  const indexes = En.useMemo(() => normalizeDocSearchIndexes({ indices }), [indices]);
@@ -16449,7 +16446,6 @@ function DocSearchModal(_ref) {
16449
16446
  setStatus,
16450
16447
  searchClient,
16451
16448
  indexes,
16452
- snippetLength,
16453
16449
  insights: Boolean(insights),
16454
16450
  appId,
16455
16451
  apiKey,
@@ -16471,7 +16467,6 @@ function DocSearchModal(_ref) {
16471
16467
  inputRef,
16472
16468
  initialScrollY,
16473
16469
  modalRef,
16474
- snippetLength,
16475
16470
  theme
16476
16471
  });
16477
16472
  En.useEffect(() => {
@@ -16528,7 +16523,10 @@ function DocSearchModal(_ref) {
16528
16523
  if (!isModifierEvent(event)) onClose();
16529
16524
  }
16530
16525
  })),
16531
- footer: /* @__PURE__ */ En.createElement(Footer, { translations: footerTranslations }),
16526
+ footer: /* @__PURE__ */ En.createElement(Footer, {
16527
+ translations: footerTranslations,
16528
+ footerAction
16529
+ }),
16532
16530
  onClose
16533
16531
  });
16534
16532
  }
@@ -16612,7 +16610,7 @@ init_compat();
16612
16610
  function isEditingContent(event) {
16613
16611
  const element = event.composedPath()[0];
16614
16612
  const tagName = element.tagName;
16615
- return element.isContentEditable || tagName === "INPUT" || tagName === "SELECT" || tagName === "TEXTAREA";
16613
+ return element.isContentEditable || tagName === "INPUT" || tagName === "SELECT" || tagName === "TEXTAREA" || tagName === "BUTTON";
16616
16614
  }
16617
16615
  function useDocSearchKeyboardEvents({ isOpen, isAskAiActive, onAskAiToggle, onClose, onOpen, keyboardShortcuts = DEFAULT_KEYBOARD_SHORTCUTS }) {
16618
16616
  En.useEffect(() => {
@@ -16907,7 +16905,8 @@ const _excluded = [
16907
16905
  "environment",
16908
16906
  "transformSearchClient",
16909
16907
  "hitComponent",
16910
- "resultsFooterComponent"
16908
+ "resultsFooterComponent",
16909
+ "footerAction"
16911
16910
  ];
16912
16911
  function getHTMLElement(value, env) {
16913
16912
  if (typeof value !== "string") return value;
@@ -16930,14 +16929,16 @@ function createTemplateFunction(original) {
16930
16929
  function createDocSearch(Component, version) {
16931
16930
  return (allProps) => {
16932
16931
  const input = allProps;
16933
- const { container, environment, transformSearchClient, hitComponent, resultsFooterComponent } = input, rest = _objectWithoutProperties$5(input, _excluded);
16932
+ const { container, environment, transformSearchClient, hitComponent, resultsFooterComponent, footerAction } = input, rest = _objectWithoutProperties$5(input, _excluded);
16934
16933
  const containerElement = getHTMLElement(container, environment || (typeof window !== "undefined" ? window : void 0));
16935
16934
  const ref = b$1();
16936
16935
  let isReady = false;
16936
+ const FooterAction = createTemplateFunction(footerAction);
16937
16937
  J(_$1(Component, _objectSpread2$1(_objectSpread2$1({}, rest), {}, {
16938
16938
  ref,
16939
16939
  hitComponent: createTemplateFunction(hitComponent),
16940
16940
  resultsFooterComponent: createTemplateFunction(resultsFooterComponent),
16941
+ footerAction: FooterAction ? _$1(FooterAction, null) : void 0,
16941
16942
  transformSearchClient: (searchClient) => {
16942
16943
  if (typeof searchClient === "object" && searchClient !== null && "addAlgoliaAgent" in searchClient && typeof searchClient.addAlgoliaAgent === "function") searchClient.addAlgoliaAgent("docsearch.js", version);
16943
16944
  return typeof transformSearchClient === "function" ? transformSearchClient(searchClient) : searchClient;