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

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/README.md CHANGED
@@ -34,7 +34,7 @@ import '@docsearch/css';
34
34
  docsearch({
35
35
  container: '#docsearch',
36
36
  appId: 'YOUR_APP_ID',
37
- indexName: 'YOUR_INDEX_NAME',
37
+ indices: ['YOUR_INDEX_NAME'],
38
38
  apiKey: 'YOUR_SEARCH_API_KEY',
39
39
  });
40
40
  ```
@@ -53,7 +53,7 @@ import '@docsearch/css';
53
53
  docsearch({
54
54
  container: '#docsearch',
55
55
  appId: 'YOUR_APP_ID',
56
- indexName: 'YOUR_INDEX_NAME',
56
+ indices: ['YOUR_INDEX_NAME'],
57
57
  apiKey: 'YOUR_SEARCH_API_KEY',
58
58
  });
59
59
  ```
@@ -66,7 +66,7 @@ For a standalone keyword-only script, load the explicit UMD file:
66
66
  window.docsearch({
67
67
  container: '#docsearch',
68
68
  appId: 'YOUR_APP_ID',
69
- indexName: 'YOUR_INDEX_NAME',
69
+ indices: ['YOUR_INDEX_NAME'],
70
70
  apiKey: 'YOUR_SEARCH_API_KEY',
71
71
  });
72
72
  </script>
@@ -1,4 +1,4 @@
1
- /*! @docsearch/js 5.0.0-beta.0 (UNRELEASED 1b6607c) | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
1
+ /*! @docsearch/js 5.0.0-beta.2 (UNRELEASED c7e1a88) | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
2
2
  import { DocSearchProps as DocSearchProps$1 } from "@docsearch/react";
3
3
  import { InitialAskAiMessage } from "@docsearch/core";
4
4
  //#region ../../node_modules/.bun/preact@11.0.0-beta.0/node_modules/preact/src/index.d.ts
@@ -1,4 +1,4 @@
1
- /*! @docsearch/js 5.0.0-beta.0 (UNRELEASED 1b6607c) | MIT License | © Algolia, Inc. and contributors | https://docsearch.algolia.com */
1
+ /*! @docsearch/js 5.0.0-beta.2 (UNRELEASED c7e1a88) | 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.0";
1185
+ const version$1 = "5.0.0-beta.2";
1186
1186
 
1187
1187
  //#endregion
1188
1188
  //#region \0@oxc-project+runtime@0.139.0/helpers/esm/OverloadYield.js
@@ -12159,7 +12159,7 @@ function useMixedToggleClickHandler(params) {
12159
12159
  //#endregion
12160
12160
  //#region ../../node_modules/.bun/@base-ui+react@1.6.0+fce4ea6354698f9c/node_modules/@base-ui/react/menu/trigger/MenuTrigger.mjs
12161
12161
  init_compat();
12162
- const _excluded$10 = [
12162
+ const _excluded$9 = [
12163
12163
  "render",
12164
12164
  "className",
12165
12165
  "style",
@@ -12179,9 +12179,9 @@ const BOUNDARY_OFFSET = 2;
12179
12179
  *
12180
12180
  * Documentation: [Base UI Menu](https://base-ui.com/react/components/menu)
12181
12181
  */
12182
- const MenuTrigger$1 = fastComponentRef(function MenuTrigger(componentProps, forwardedRef) {
12182
+ const MenuTrigger = fastComponentRef(function MenuTrigger(componentProps, forwardedRef) {
12183
12183
  var _handle$store;
12184
- const { render, className, style, disabled: disabledProp = false, nativeButton = true, id: idProp, openOnHover: openOnHoverProp, delay = 100, closeDelay = 0, handle, payload } = componentProps, elementProps = _objectWithoutProperties$5(componentProps, _excluded$10);
12184
+ const { render, className, style, disabled: disabledProp = false, nativeButton = true, id: idProp, openOnHover: openOnHoverProp, delay = 100, closeDelay = 0, handle, payload } = componentProps, elementProps = _objectWithoutProperties$5(componentProps, _excluded$9);
12185
12185
  const rootContext = useMenuRootContext(true);
12186
12186
  const store = (_handle$store = handle === null || handle === void 0 ? void 0 : handle.store) !== null && _handle$store !== void 0 ? _handle$store : rootContext === null || rootContext === void 0 ? void 0 : rootContext.store;
12187
12187
  if (!store) throw new Error(formatErrorMessage(85));
@@ -12380,7 +12380,7 @@ function useMenuParent() {
12380
12380
  }
12381
12381
 
12382
12382
  //#endregion
12383
- //#region ../docsearch-react/dist/esm/normalizeDocSearchIndexes-DAzlMybx.js
12383
+ //#region ../docsearch-react/dist/esm/normalizeDocSearchIndexes-D8P3VEXa.js
12384
12384
  init_compat();
12385
12385
  function capitalize(text) {
12386
12386
  return `${text.charAt(0).toLocaleUpperCase()}${text.substring(1)}`;
@@ -12441,6 +12441,10 @@ function identity(x) {
12441
12441
  function isModifierEvent(event) {
12442
12442
  return event.button === 1 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
12443
12443
  }
12444
+ function isQueryEmpty(query) {
12445
+ if (!query || query.trim().length === 0) return true;
12446
+ return false;
12447
+ }
12444
12448
  function noop$1(..._args) {}
12445
12449
  const regexHighlightTags = /(<mark>|<\/mark>)/g;
12446
12450
  const regexHasHighlightTags = RegExp(regexHighlightTags.source);
@@ -12556,6 +12560,22 @@ function getFacetLabel(facet) {
12556
12560
  if (facet.label) return facet.label;
12557
12561
  return facet.key.replace(/[._-]+/g, " ").replace(/\b\w/g, (letter) => letter.toUpperCase());
12558
12562
  }
12563
+ function deriveDefaultSelectedFacetsFromIndex(indices) {
12564
+ const defaultFacets = {};
12565
+ for (const index of indices) {
12566
+ var _index$searchParamete;
12567
+ const facetFilters = (_index$searchParamete = index.searchParameters) === null || _index$searchParamete === void 0 ? void 0 : _index$searchParamete.facetFilters;
12568
+ for (const facetFilter of Array.isArray(facetFilters) ? facetFilters : [facetFilters]) {
12569
+ if (typeof facetFilter !== "string") continue;
12570
+ const separatorIndex = facetFilter.indexOf(":");
12571
+ if (separatorIndex <= 0) continue;
12572
+ const key = facetFilter.slice(0, separatorIndex);
12573
+ const value = facetFilter.slice(separatorIndex + 1);
12574
+ if (key && value) defaultFacets[key] = value;
12575
+ }
12576
+ }
12577
+ return defaultFacets;
12578
+ }
12559
12579
  const _excluded$6$4 = ["className", "type"];
12560
12580
  function Chip({ children }) {
12561
12581
  return /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Chip" }, children);
@@ -12585,12 +12605,14 @@ function Menu$1(_ref) {
12585
12605
  let props = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
12586
12606
  return /* @__PURE__ */ En.createElement(MenuRoot, props);
12587
12607
  }
12588
- function MenuTrigger(_ref2) {
12608
+ Menu$1.Trigger = En.forwardRef((_ref2, ref) => {
12589
12609
  let { className } = _ref2, props = _objectWithoutProperties$6(_ref2, _excluded$5$4);
12590
12610
  const cn = `DocSearch-Menu-Trigger${className ? ` ${className}` : ""}`;
12591
- return /* @__PURE__ */ En.createElement(MenuTrigger$1, _objectSpread2$2({ className: cn }, props));
12592
- }
12593
- Menu$1.Trigger = MenuTrigger;
12611
+ return /* @__PURE__ */ En.createElement(MenuTrigger, _objectSpread2$2({
12612
+ className: cn,
12613
+ ref
12614
+ }, props));
12615
+ });
12594
12616
  function MenuPopup(_ref3) {
12595
12617
  let { align = "start", alignOffset = 0, side = "bottom", sideOffset = 4, collisionBoundary = "clipping-ancestors", container } = _ref3, props = _objectWithoutProperties$6(_ref3, _excluded2$3);
12596
12618
  return /* @__PURE__ */ En.createElement(MenuPortal, { container }, /* @__PURE__ */ En.createElement(MenuPositioner, {
@@ -12658,9 +12680,10 @@ const SelectedFacetChip = En.memo(function SelectedFacetChip({ facetKey, facetLa
12658
12680
  });
12659
12681
  const FacetBar = En.memo(function FacetBar({ facets, selections, onSelectionChange, clearSelections, translations = {} }) {
12660
12682
  const { defaultValueLabel = "All", facetMenuTriggerAriaLabel = "selected", clearAllLabel = "Clear all", facetsAriaLabel = "Search filters", selectedFacetsAriaLabel = "Selected search filters", clearFacetAriaLabel = "Clear filter:" } = translations;
12683
+ const visibleFacetKeys = En.useMemo(() => new Set(facets.map((f) => f.key)), [facets]);
12661
12684
  const selectionsToDisplay = En.useMemo(() => {
12662
- return Object.entries(selections).filter(([_, value]) => Boolean(value));
12663
- }, [selections]);
12685
+ return Object.entries(selections).filter(([key, value]) => Boolean(value) && visibleFacetKeys.has(key));
12686
+ }, [selections, visibleFacetKeys]);
12664
12687
  const triggerRefs = En.useRef(/* @__PURE__ */ new Map());
12665
12688
  const registerTrigger = En.useCallback((facetKey, el) => {
12666
12689
  if (el) triggerRefs.current.set(facetKey, el);
@@ -12833,21 +12856,15 @@ function useFacetValues({ facets, indexes, searchClient }) {
12833
12856
  En.useEffect(() => {
12834
12857
  let isMounted = true;
12835
12858
  const facetKeys = stableFacetKeys ? stableFacetKeys.split(",") : [];
12836
- if (facetKeys.length === 0 || indexes.length === 0) {
12837
- setFacetValues({});
12838
- return () => {
12839
- isMounted = false;
12840
- };
12841
- }
12842
- searchClient.search({ requests: indexes.map((index) => {
12843
- var _index$searchParamete2;
12844
- return _objectSpread2$2(_objectSpread2$2({}, (_index$searchParamete2 = index.searchParameters) !== null && _index$searchParamete2 !== void 0 ? _index$searchParamete2 : {}), {}, {
12845
- indexName: index.name,
12846
- query: "",
12847
- hitsPerPage: 0,
12848
- facets: facetKeys
12849
- });
12850
- }) }).then(({ results }) => {
12859
+ if (facetKeys.length === 0 || indexes.length === 0) return () => {
12860
+ isMounted = false;
12861
+ };
12862
+ searchClient.search({ requests: indexes.map((index) => ({
12863
+ indexName: index.name,
12864
+ query: "",
12865
+ hitsPerPage: 0,
12866
+ facets: facetKeys
12867
+ })) }).then(({ results }) => {
12851
12868
  if (!isMounted) return;
12852
12869
  const valuesByFacet = facetKeys.reduce((acc, facet) => {
12853
12870
  acc[facet] = [];
@@ -12876,19 +12893,23 @@ function useFacetValues({ facets, indexes, searchClient }) {
12876
12893
  }
12877
12894
  function useDocSearchFacets({ facets, indexes, searchClient, onSelectionsChange }) {
12878
12895
  const normalizedFacets = En.useMemo(() => normalizeFacets(facets), [facets]);
12896
+ const normalizedFacetsRef = En.useRef(normalizedFacets);
12879
12897
  const facetValues = useFacetValues({
12880
12898
  facets: normalizedFacets,
12881
12899
  indexes,
12882
12900
  searchClient
12883
12901
  });
12884
- const [facetSelections, setFacetSelections] = En.useState({});
12902
+ const [facetSelections, setFacetSelections] = En.useState(() => deriveDefaultSelectedFacetsFromIndex(indexes));
12885
12903
  const facetSelectionsRef = En.useRef(facetSelections);
12886
12904
  const onSelectionsChangeRef = En.useRef(onSelectionsChange);
12887
- onSelectionsChangeRef.current = onSelectionsChange;
12888
12905
  const visibleFacets = En.useMemo(() => normalizedFacets.map((facet) => {
12889
12906
  var _facetValues$facet$ke;
12890
12907
  return _objectSpread2$2(_objectSpread2$2({}, facet), {}, { values: (_facetValues$facet$ke = facetValues[facet.key]) !== null && _facetValues$facet$ke !== void 0 ? _facetValues$facet$ke : [] });
12891
12908
  }).filter((facet) => facet.values.length > 0), [facetValues, normalizedFacets]);
12909
+ En.useLayoutEffect(() => {
12910
+ normalizedFacetsRef.current = normalizedFacets;
12911
+ onSelectionsChangeRef.current = onSelectionsChange;
12912
+ });
12892
12913
  const applySelections = En.useCallback((next) => {
12893
12914
  var _onSelectionsChangeRe;
12894
12915
  facetSelectionsRef.current = next;
@@ -12902,13 +12923,14 @@ function useDocSearchFacets({ facets, indexes, searchClient, onSelectionsChange
12902
12923
  handleFacetSelectionChange: En.useCallback((facet, value) => {
12903
12924
  if (facetSelectionsRef.current[facet] === value) return;
12904
12925
  const next = _objectSpread2$2({}, facetSelectionsRef.current);
12905
- if (value === "") delete next[facet];
12906
- else next[facet] = value;
12926
+ next[facet] = value;
12907
12927
  applySelections(next);
12908
12928
  }, [applySelections]),
12909
12929
  clearFacetSelections: En.useCallback(() => {
12910
12930
  if (Object.keys(facetSelectionsRef.current).length === 0) return;
12911
- applySelections({});
12931
+ const next = {};
12932
+ for (const facet of normalizedFacetsRef.current) if (facetSelectionsRef.current[facet.key]) next[facet.key] = "";
12933
+ applySelections(next);
12912
12934
  }, [applySelections])
12913
12935
  };
12914
12936
  }
@@ -13270,9 +13292,9 @@ function ErrorScreen({ translations = {} }) {
13270
13292
  const { titleText = "Unable to fetch results", helpText = "You might want to check your network connection." } = translations;
13271
13293
  return /* @__PURE__ */ En.createElement("div", { className: "DocSearch-ErrorScreen" }, /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Screen-Icon" }, /* @__PURE__ */ En.createElement(ErrorIcon, null)), /* @__PURE__ */ En.createElement("p", { className: "DocSearch-Title" }, titleText), /* @__PURE__ */ En.createElement("p", { className: "DocSearch-Help" }, helpText));
13272
13294
  }
13273
- const _excluded$1$8 = ["translations"];
13295
+ const _excluded$1$7 = ["translations"];
13274
13296
  function NoResultsScreen(_ref) {
13275
- let { translations = {} } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$1$8);
13297
+ let { translations = {} } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$1$7);
13276
13298
  const { noResultsText = "No results found for", suggestedQueryText = "Try searching for", reportMissingResultsText = "Believe this query should return results?", reportMissingResultsLinkText = "Let us know." } = translations;
13277
13299
  const searchSuggestions = props.state.context.searchSuggestions;
13278
13300
  return /* @__PURE__ */ En.createElement("div", { className: `DocSearch-NoResults ${props.canHandleAskAi ? "DocSearch-NoResults--withAskAi" : ""}` }, /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Screen-Icon" }, /* @__PURE__ */ En.createElement(NoResultsIcon, null)), /* @__PURE__ */ En.createElement("p", { className: "DocSearch-Title" }, noResultsText, " \"", /* @__PURE__ */ En.createElement("strong", null, props.state.query), "\""), searchSuggestions && searchSuggestions.length > 0 && /* @__PURE__ */ En.createElement("div", { className: "DocSearch-NoResults-Prefill-List" }, /* @__PURE__ */ En.createElement("p", { className: "DocSearch-Help" }, suggestedQueryText, ":"), /* @__PURE__ */ En.createElement("div", { className: "DocSearch-NoResults-Prefill-List-Items" }, searchSuggestions.slice(0, 3).reduce((acc, search) => [...acc, /* @__PURE__ */ En.createElement("p", { key: search }, /* @__PURE__ */ En.createElement(SearchIcon, { size: 16 }), /* @__PURE__ */ En.createElement("button", {
@@ -13307,13 +13329,9 @@ function HitResultBadge({ item, resultBadgeKey, translations = {} }) {
13307
13329
  if (badgeValue === null || badgeValue.length === 0) return null;
13308
13330
  return /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Hit-badge" }, /* @__PURE__ */ En.createElement("span", { className: "DocSearch-VisuallyHiddenForAccessibility" }, `${resultBadgeLabelText}: ${badgeValue}`), /* @__PURE__ */ En.createElement("span", { "aria-hidden": "true" }, badgeValue));
13309
13331
  }
13310
- const _excluded$9 = ["translations", "resultBadgeKey"];
13332
+ const _excluded$10 = ["translations", "resultBadgeKey"];
13311
13333
  function ResultsScreen(_ref) {
13312
- let { translations = {}, resultBadgeKey } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$9);
13313
- const { resultsSectionTitle = "Results" } = translations;
13314
- const renderIcon = En.useCallback(({ item }) => {
13315
- return /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Hit-icon" }, /* @__PURE__ */ En.createElement(SourceIcon, { type: item.type }));
13316
- }, []);
13334
+ let { translations = {}, resultBadgeKey } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$10);
13317
13335
  const renderAction = En.useCallback(() => {
13318
13336
  return /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Hit-action" }, /* @__PURE__ */ En.createElement(SelectIcon, null));
13319
13337
  }, []);
@@ -13326,22 +13344,45 @@ function ResultsScreen(_ref) {
13326
13344
  }, [resultBadgeKey, translations.resultBadgeLabelText]);
13327
13345
  return /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Dropdown-Container" }, props.state.collections.map((collection) => {
13328
13346
  if (collection.items.length === 0) return null;
13347
+ const title = removeHighlightTags(collection.items[0]);
13329
13348
  return /* @__PURE__ */ En.createElement(Results, _objectSpread2$2(_objectSpread2$2({}, props), {}, {
13330
13349
  key: collection.source.sourceId,
13331
13350
  translations,
13332
- title: resultsSectionTitle,
13351
+ title,
13333
13352
  collection,
13334
- renderIcon,
13353
+ renderIcon: ({ item, index }) => {
13354
+ var _collection$items;
13355
+ return /* @__PURE__ */ En.createElement(En.Fragment, null, item.__docsearch_parent && /* @__PURE__ */ En.createElement("svg", {
13356
+ className: "DocSearch-Hit-Tree",
13357
+ viewBox: "0 0 24 54"
13358
+ }, /* @__PURE__ */ En.createElement("g", {
13359
+ stroke: "currentColor",
13360
+ fill: "none",
13361
+ fillRule: "evenodd",
13362
+ strokeLinecap: "round",
13363
+ strokeLinejoin: "round"
13364
+ }, item.__docsearch_parent !== ((_collection$items = collection.items[index + 1]) === null || _collection$items === void 0 ? void 0 : _collection$items.__docsearch_parent) ? /* @__PURE__ */ En.createElement("path", { d: "M8 6v21M20 27H8.3" }) : /* @__PURE__ */ En.createElement("path", { d: "M8 6v42M20 27H8.3" }))), /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Hit-icon" }, /* @__PURE__ */ En.createElement(SourceIcon, { type: item.type })));
13365
+ },
13335
13366
  renderAction,
13336
13367
  renderResultBadge
13337
13368
  }));
13338
13369
  }), props.resultsFooterComponent && /* @__PURE__ */ En.createElement("section", { className: "DocSearch-HitsFooter" }, /* @__PURE__ */ En.createElement(props.resultsFooterComponent, { state: props.state })));
13339
13370
  }
13340
13371
  function createFacetFilters(searchParametersFacetFilters, facetSelections) {
13341
- const dynamicFacetFilters = Object.entries(facetSelections).filter(([, value]) => value).map(([facet, value]) => `${facet}:${value}`);
13342
- if (dynamicFacetFilters.length === 0) return searchParametersFacetFilters;
13343
- if (!searchParametersFacetFilters) return dynamicFacetFilters;
13344
- return [...searchParametersFacetFilters, ...dynamicFacetFilters];
13372
+ const selections = Object.entries(facetSelections);
13373
+ const selectedFacets = new Set(selections.map(([facet]) => facet));
13374
+ const dynamicFacetFilters = [];
13375
+ for (const [facet, selection] of selections) if (selection !== "") dynamicFacetFilters.push(`${facet}:${selection}`);
13376
+ if (selectedFacets.size === 0) return searchParametersFacetFilters;
13377
+ let configuredFacetFilters = [];
13378
+ if (searchParametersFacetFilters && Array.isArray(searchParametersFacetFilters)) configuredFacetFilters = searchParametersFacetFilters;
13379
+ else if (searchParametersFacetFilters) configuredFacetFilters = [searchParametersFacetFilters];
13380
+ return [...configuredFacetFilters.filter((facetFilter) => {
13381
+ if (typeof facetFilter !== "string") return true;
13382
+ const separatorIndex = facetFilter.indexOf(":");
13383
+ const facet = facetFilter.slice(0, separatorIndex);
13384
+ return separatorIndex <= 0 || !selectedFacets.has(facet);
13385
+ }), ...dynamicFacetFilters];
13345
13386
  }
13346
13387
  function buildNoQuerySources({ recentSearches, favoriteSearches, saveRecentSearch, onClose, disableUserPersonalization }) {
13347
13388
  if (disableUserPersonalization) return [];
@@ -13408,7 +13449,7 @@ async function buildQuerySources({ query, state: sourcesState, setContext, setSt
13408
13449
  highlightPostTag: (_searchParams$highlig2 = searchParams === null || searchParams === void 0 ? void 0 : searchParams.highlightPostTag) !== null && _searchParams$highlig2 !== void 0 ? _searchParams$highlig2 : "</mark>",
13409
13450
  hitsPerPage: (_searchParams$hitsPer = searchParams === null || searchParams === void 0 ? void 0 : searchParams.hitsPerPage) !== null && _searchParams$hitsPer !== void 0 ? _searchParams$hitsPer : 20,
13410
13451
  clickAnalytics: (_searchParams$clickAn = searchParams === null || searchParams === void 0 ? void 0 : searchParams.clickAnalytics) !== null && _searchParams$clickAn !== void 0 ? _searchParams$clickAn : insightsActive
13411
- }, searchParams !== null && searchParams !== void 0 ? searchParams : {}), facetFilters ? { facetFilters } : {});
13452
+ }, searchParams), facetFilters ? { facetFilters } : {});
13412
13453
  }) });
13413
13454
  return results.flatMap((res) => {
13414
13455
  const result = res;
@@ -13431,9 +13472,8 @@ async function buildQuerySources({ query, state: sourcesState, setContext, setSt
13431
13472
  apiKey
13432
13473
  }
13433
13474
  };
13434
- const items = Object.values(sources).flat();
13435
- return {
13436
- sourceId: `hits_${result.index}`,
13475
+ return Object.values(sources).map((items, index) => ({
13476
+ sourceId: `hits_${result.index}_${index}`,
13437
13477
  onSelect({ item, event }) {
13438
13478
  saveRecentSearch(item);
13439
13479
  if (!isModifierEvent(event)) onClose();
@@ -13447,26 +13487,18 @@ async function buildQuerySources({ query, state: sourcesState, setContext, setSt
13447
13487
  const potentialParent = groupedHits.find((siblingItem) => siblingItem.type === "lvl1" && siblingItem.hierarchy.lvl1 === item.hierarchy.lvl1);
13448
13488
  if (item.type !== "lvl1" && potentialParent) parent = potentialParent;
13449
13489
  return _objectSpread2$2(_objectSpread2$2({}, item), {}, { __docsearch_parent: parent }, insightsParams);
13450
- }).flat()).flat();
13490
+ })).flat();
13451
13491
  }
13452
- };
13492
+ }));
13453
13493
  });
13454
13494
  } catch (error) {
13455
13495
  if (error.name === "RetryError") setStatus("error");
13456
13496
  throw error;
13457
13497
  }
13458
13498
  }
13459
- function normalizeDocSearchIndexes({ indexName, indices = [], searchParameters }) {
13460
- const indexes = [];
13461
- if (indexName && indexName !== "") indexes.push({
13462
- name: indexName,
13463
- searchParameters
13464
- });
13465
- if (indices.length > 0) indices.forEach((index) => {
13466
- indexes.push(typeof index === "string" ? { name: index } : index);
13467
- });
13468
- if (indexes.length < 1) throw new Error("Must supply either `indexName` or `indices` for DocSearch to work");
13469
- return indexes;
13499
+ function normalizeDocSearchIndexes({ indices }) {
13500
+ if (!Array.isArray(indices) || indices.length < 1) throw new Error("Must supply at least one `indices` entry for DocSearch");
13501
+ return indices.map((index) => typeof index === "string" ? { name: index } : index);
13470
13502
  }
13471
13503
 
13472
13504
  //#endregion
@@ -16277,7 +16309,7 @@ function createAutocomplete(options) {
16277
16309
  }
16278
16310
 
16279
16311
  //#endregion
16280
- //#region ../docsearch-react/dist/esm/DocSearchModal-CpvDjo1O.js
16312
+ //#region ../docsearch-react/dist/esm/DocSearchModal-D_tfhoN1.js
16281
16313
  init_compat();
16282
16314
  const _excluded$3 = ["translations"];
16283
16315
  function KeywordSearchBox(_ref) {
@@ -16301,9 +16333,9 @@ function KeywordSearchBox(_ref) {
16301
16333
  actionsBeforeClose
16302
16334
  }));
16303
16335
  }
16304
- const _excluded$2 = ["translations"];
16336
+ const _excluded$2$1 = ["translations"];
16305
16337
  function KeywordStartScreen(_ref) {
16306
- let { translations = {} } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$2);
16338
+ let { translations = {} } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$2$1);
16307
16339
  return /* @__PURE__ */ En.createElement("div", { className: "DocSearch-Dropdown-Container" }, /* @__PURE__ */ En.createElement(StoredSearchesSections, _objectSpread2$2(_objectSpread2$2({}, props), {}, { translations })));
16308
16340
  }
16309
16341
  const _excluded$1$1 = ["translations"];
@@ -16311,14 +16343,16 @@ const ScreenState = En.memo((_ref) => {
16311
16343
  var _props$state;
16312
16344
  let { translations = {} } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$1$1);
16313
16345
  if (((_props$state = props.state) === null || _props$state === void 0 ? void 0 : _props$state.status) === "error") return /* @__PURE__ */ En.createElement(ErrorScreen, { translations: translations === null || translations === void 0 ? void 0 : translations.errorScreen });
16314
- if (!props.state.query) return /* @__PURE__ */ En.createElement(KeywordStartScreen, _objectSpread2$2(_objectSpread2$2({}, props), {}, {
16346
+ if (isQueryEmpty(props.state.query)) return /* @__PURE__ */ En.createElement(KeywordStartScreen, _objectSpread2$2(_objectSpread2$2({}, props), {}, {
16315
16347
  hasCollections: props.hasCollections,
16316
16348
  translations: translations === null || translations === void 0 ? void 0 : translations.startScreen
16317
16349
  }));
16318
16350
  if (!props.hasCollections) return /* @__PURE__ */ En.createElement(NoResultsScreen, _objectSpread2$2(_objectSpread2$2({}, props), {}, { translations: translations === null || translations === void 0 ? void 0 : translations.noResultsScreen }));
16319
16351
  return /* @__PURE__ */ En.createElement(ResultsScreen, _objectSpread2$2(_objectSpread2$2({}, props), {}, { translations: translations === null || translations === void 0 ? void 0 : translations.resultsScreen }));
16320
- }, function areEqual(_prevProps, nextProps) {
16321
- return nextProps.state.status === "loading" || nextProps.state.status === "stalled";
16352
+ }, function areEqual(prevProps, nextProps) {
16353
+ const isLoading = nextProps.state.status === "loading" || nextProps.state.status === "stalled";
16354
+ const isWaitingForCollections = nextProps.state.status === "idle" && !isQueryEmpty(nextProps.state.query) && prevProps.state.query !== nextProps.state.query && prevProps.state.collections === nextProps.state.collections;
16355
+ return isLoading || isWaitingForCollections;
16322
16356
  });
16323
16357
  const _excluded$4 = [
16324
16358
  "appId",
@@ -16340,8 +16374,6 @@ const _excluded$4 = [
16340
16374
  "recentSearchesLimit",
16341
16375
  "recentSearchesWithFavoritesLimit",
16342
16376
  "indices",
16343
- "indexName",
16344
- "searchParameters",
16345
16377
  "facets"
16346
16378
  ];
16347
16379
  const _excluded2 = [
@@ -16351,7 +16383,7 @@ const _excluded2 = [
16351
16383
  ];
16352
16384
  function DocSearchModal(_ref) {
16353
16385
  var _translations$searchB;
16354
- 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 = [], indexName, searchParameters, facets } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$4);
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);
16355
16387
  const { footer: footerTranslations, searchBox: searchBoxTranslations, facets: facetBarTranslations } = translations, screenStateTranslations = _objectWithoutProperties$6(translations, _excluded2);
16356
16388
  const [state, setState] = En.useState({
16357
16389
  query: "",
@@ -16366,15 +16398,7 @@ function DocSearchModal(_ref) {
16366
16398
  const { containerRef, modalRef, formElementRef, dropdownRef, inputRef, snippetLength } = useModalRefs();
16367
16399
  const { initialQuery, initialQueryFromSelection } = useInitialModalQuery(initialQueryFromProp);
16368
16400
  const searchClient = useSearchClient(appId, apiKey, transformSearchClient);
16369
- const indexes = En.useMemo(() => normalizeDocSearchIndexes({
16370
- indexName,
16371
- indices,
16372
- searchParameters
16373
- }), [
16374
- indexName,
16375
- indices,
16376
- searchParameters
16377
- ]);
16401
+ const indexes = En.useMemo(() => normalizeDocSearchIndexes({ indices }), [indices]);
16378
16402
  const defaultIndexName = indexes[0].name;
16379
16403
  const autocompleteRef = En.useRef(void 0);
16380
16404
  const { visibleFacets, facetSelections, facetSelectionsRef, handleFacetSelectionChange, clearFacetSelections } = useDocSearchFacets({
@@ -16411,7 +16435,7 @@ function DocSearchModal(_ref) {
16411
16435
  setState(changes.state);
16412
16436
  },
16413
16437
  getSources({ query, state: sourcesState, setContext, setStatus }) {
16414
- if (!query) return buildNoQuerySources({
16438
+ if (isQueryEmpty(query)) return buildNoQuerySources({
16415
16439
  recentSearches,
16416
16440
  favoriteSearches,
16417
16441
  saveRecentSearch,
@@ -16460,7 +16484,7 @@ function DocSearchModal(_ref) {
16460
16484
  });
16461
16485
  let showDocsearchDropdown = true;
16462
16486
  const hasCollections = state.collections.some((collection) => collection.items.length > 0);
16463
- if (state.status === "idle" && hasCollections === false && state.query.length === 0) showDocsearchDropdown = false;
16487
+ if (state.status === "idle" && hasCollections === false && isQueryEmpty(state.query)) showDocsearchDropdown = false;
16464
16488
  return /* @__PURE__ */ En.createElement(ModalShell, {
16465
16489
  state,
16466
16490
  containerRef,
@@ -16472,13 +16496,13 @@ function DocSearchModal(_ref) {
16472
16496
  searchBox: /* @__PURE__ */ En.createElement(KeywordSearchBox, _objectSpread2$2(_objectSpread2$2({}, autocomplete), {}, {
16473
16497
  state,
16474
16498
  placeholder: placeholder || "Search docs",
16475
- autoFocus: initialQuery.length === 0,
16499
+ autoFocus: isQueryEmpty(initialQuery),
16476
16500
  inputRef,
16477
16501
  isFromSelection: Boolean(initialQuery) && initialQuery === initialQueryFromSelection,
16478
16502
  translations: searchBoxTranslations,
16479
16503
  onClose
16480
16504
  })),
16481
- filterBar: state.query !== "" ? /* @__PURE__ */ En.createElement(FacetBar, {
16505
+ filterBar: !isQueryEmpty(state.query) ? /* @__PURE__ */ En.createElement(FacetBar, {
16482
16506
  facets: visibleFacets,
16483
16507
  selections: facetSelections,
16484
16508
  translations: facetBarTranslations,
@@ -16656,8 +16680,10 @@ function _objectWithoutProperties(e, t) {
16656
16680
  }
16657
16681
  return i;
16658
16682
  }
16659
- const _excluded$1 = [
16683
+ const _excluded$2 = [
16660
16684
  "children",
16685
+ "appId",
16686
+ "apiKey",
16661
16687
  "theme",
16662
16688
  "onReady",
16663
16689
  "onOpen",
@@ -16668,7 +16694,7 @@ const _excluded$1 = [
16668
16694
  const Context = En.createContext(void 0);
16669
16695
  Context.displayName = "DocSearchContext";
16670
16696
  function DocSearchInner$1(_ref, ref) {
16671
- let { children, theme, onReady, onOpen, onClose, onSidepanelOpen, onSidepanelClose } = _ref, props = _objectWithoutProperties(_ref, _excluded$1);
16697
+ let { children, appId, apiKey, theme, onReady, onOpen, onClose, onSidepanelOpen, onSidepanelClose } = _ref, props = _objectWithoutProperties(_ref, _excluded$2);
16672
16698
  const [docsearchState, setDocsearchState] = En.useState("ready");
16673
16699
  const [initialQuery, setInitialQuery] = En.useState(props.initialQuery || "");
16674
16700
  const searchButtonRef = En.useRef(null);
@@ -16775,6 +16801,8 @@ function DocSearchInner$1(_ref, ref) {
16775
16801
  keyboardShortcuts
16776
16802
  });
16777
16803
  const value = En.useMemo(() => ({
16804
+ appId,
16805
+ apiKey,
16778
16806
  docsearchState,
16779
16807
  setDocsearchState,
16780
16808
  searchButtonRef,
@@ -16789,6 +16817,8 @@ function DocSearchInner$1(_ref, ref) {
16789
16817
  registerView,
16790
16818
  isHybridModeSupported
16791
16819
  }), [
16820
+ appId,
16821
+ apiKey,
16792
16822
  docsearchState,
16793
16823
  searchButtonRef,
16794
16824
  initialQuery,
@@ -16815,19 +16845,28 @@ function useDocSearch() {
16815
16845
  //#endregion
16816
16846
  //#region ../docsearch-react/dist/esm/index.js
16817
16847
  init_compat();
16818
- function DocSearchComponent(props, ref) {
16819
- return /* @__PURE__ */ En.createElement(DocSearch$1, _objectSpread2$2(_objectSpread2$2({}, props), {}, { ref }), /* @__PURE__ */ En.createElement(DocSearchInner, props));
16848
+ const _excluded$1 = ["appId", "apiKey"];
16849
+ function DocSearchComponent(_ref, ref) {
16850
+ let { appId, apiKey } = _ref, props = _objectWithoutProperties$6(_ref, _excluded$1);
16851
+ return /* @__PURE__ */ En.createElement(DocSearch$1, _objectSpread2$2(_objectSpread2$2({}, props), {}, {
16852
+ appId,
16853
+ apiKey,
16854
+ ref
16855
+ }), /* @__PURE__ */ En.createElement(DocSearchInner, props));
16820
16856
  }
16821
16857
  const DocSearch = En.forwardRef(DocSearchComponent);
16822
16858
  function DocSearchInner(props) {
16823
16859
  var _props$translations, _props$translations2, _props$portalContaine;
16824
- const { searchButtonRef, keyboardShortcuts, isModalActive, initialQuery, openModal, closeModal } = useDocSearch();
16860
+ const { searchButtonRef, keyboardShortcuts, isModalActive, initialQuery, openModal, closeModal, appId, apiKey } = useDocSearch();
16861
+ if (!appId || !apiKey) throw new Error("`DocSearch` requires `appId` and `apiKey` props.");
16825
16862
  return /* @__PURE__ */ En.createElement(En.Fragment, null, /* @__PURE__ */ En.createElement(DocSearchButton, {
16826
16863
  keyboardShortcuts,
16827
16864
  ref: searchButtonRef,
16828
16865
  translations: (_props$translations = props.translations) === null || _props$translations === void 0 ? void 0 : _props$translations.button,
16829
16866
  onClick: openModal
16830
16867
  }), isModalActive && H(/* @__PURE__ */ En.createElement(DocSearchModal, _objectSpread2$2(_objectSpread2$2({}, props), {}, {
16868
+ appId,
16869
+ apiKey,
16831
16870
  initialScrollY: window.scrollY,
16832
16871
  initialQuery,
16833
16872
  translations: props === null || props === void 0 || (_props$translations2 = props.translations) === null || _props$translations2 === void 0 ? void 0 : _props$translations2.modal,