@docsearch/react 5.0.0-beta.1 → 5.0.0-beta.3
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 +1 -1
- package/dist/esm/{AskAiScreenState-CRHicWbN.d.ts → AskAiScreenState-Sqbn60f2.d.ts} +5 -2
- package/dist/esm/{DocSearch-HJsNvtZr.d.ts → DocSearch-BVqxFxTw.d.ts} +20 -43
- package/dist/esm/{DocSearchAskAiModal-KaA6fBV4.js → DocSearchAskAiModal-C_sH1j8Y.js} +31 -38
- package/dist/esm/DocSearchAskAiModal-C_sH1j8Y.js.map +1 -0
- package/dist/esm/{DocSearchAskAiModal-B7vpLudE.d.ts → DocSearchAskAiModal-DpB7pLCC.d.ts} +4 -4
- package/dist/esm/{DocSearchModal-CpvDjo1O.js → DocSearchModal-CITTG0fe.js} +20 -26
- package/dist/esm/DocSearchModal-CITTG0fe.js.map +1 -0
- package/dist/esm/askaiModal.d.ts +1 -1
- package/dist/esm/askaiModal.js +1 -1
- package/dist/esm/docsearchAi.d.ts +13 -110
- package/dist/esm/docsearchAi.js +14 -4
- package/dist/esm/docsearchAi.js.map +1 -1
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +15 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/modal.d.ts +1 -1
- package/dist/esm/modal.js +1 -1
- package/dist/esm/{normalizeDocSearchIndexes-DAzlMybx.js → normalizeDocSearchIndexes-ChnVvoVt.js} +105 -74
- package/dist/esm/normalizeDocSearchIndexes-ChnVvoVt.js.map +1 -0
- package/dist/esm/sidepanel.d.ts +31 -27
- package/dist/esm/sidepanel.js +14 -11
- package/dist/esm/sidepanel.js.map +1 -1
- package/dist/esm/useDocSearchKeyboardEvents.js +1 -1
- package/dist/esm/useDocSearchKeyboardEvents.js.map +1 -1
- package/dist/esm/useSearchClient-mIHVB6ga.js.map +1 -1
- package/dist/esm/{useSuggestedQuestions-CG2H3qm4.js → useSuggestedQuestions-DwcUPOf_.js} +107 -50
- package/dist/esm/useSuggestedQuestions-DwcUPOf_.js.map +1 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/umd/index.js +44 -42
- package/dist/umd/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/esm/DocSearchAskAiModal-KaA6fBV4.js.map +0 -1
- package/dist/esm/DocSearchModal-CpvDjo1O.js.map +0 -1
- package/dist/esm/normalizeDocSearchIndexes-DAzlMybx.js.map +0 -1
- package/dist/esm/useSuggestedQuestions-CG2H3qm4.js.map +0 -1
package/dist/esm/{normalizeDocSearchIndexes-DAzlMybx.js → normalizeDocSearchIndexes-ChnVvoVt.js}
RENAMED
|
@@ -87,6 +87,13 @@ function isModifierEvent(event) {
|
|
|
87
87
|
return event.button === 1 || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
//#endregion
|
|
91
|
+
//#region src/utils/isQueryEmpty.ts
|
|
92
|
+
function isQueryEmpty(query) {
|
|
93
|
+
if (!query || query.trim().length === 0) return true;
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
|
|
90
97
|
//#endregion
|
|
91
98
|
//#region src/utils/noop.ts
|
|
92
99
|
function noop(..._args) {}
|
|
@@ -232,6 +239,22 @@ function getFacetLabel(facet) {
|
|
|
232
239
|
if (facet.label) return facet.label;
|
|
233
240
|
return facet.key.replace(/[._-]+/g, " ").replace(/\b\w/g, (letter) => letter.toUpperCase());
|
|
234
241
|
}
|
|
242
|
+
function deriveDefaultSelectedFacetsFromIndex(indices) {
|
|
243
|
+
const defaultFacets = {};
|
|
244
|
+
for (const index of indices) {
|
|
245
|
+
var _index$searchParamete;
|
|
246
|
+
const facetFilters = (_index$searchParamete = index.searchParameters) === null || _index$searchParamete === void 0 ? void 0 : _index$searchParamete.facetFilters;
|
|
247
|
+
for (const facetFilter of Array.isArray(facetFilters) ? facetFilters : [facetFilters]) {
|
|
248
|
+
if (typeof facetFilter !== "string") continue;
|
|
249
|
+
const separatorIndex = facetFilter.indexOf(":");
|
|
250
|
+
if (separatorIndex <= 0) continue;
|
|
251
|
+
const key = facetFilter.slice(0, separatorIndex);
|
|
252
|
+
const value = facetFilter.slice(separatorIndex + 1);
|
|
253
|
+
if (key && value) defaultFacets[key] = value;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return defaultFacets;
|
|
257
|
+
}
|
|
235
258
|
|
|
236
259
|
//#endregion
|
|
237
260
|
//#region src/components/ui/Chip.tsx
|
|
@@ -267,12 +290,14 @@ function Menu$1(_ref) {
|
|
|
267
290
|
let props = _extends({}, (_objectDestructuringEmpty(_ref), _ref));
|
|
268
291
|
return /* @__PURE__ */ React.createElement(Menu.Root, props);
|
|
269
292
|
}
|
|
270
|
-
|
|
293
|
+
Menu$1.Trigger = React.forwardRef((_ref2, ref) => {
|
|
271
294
|
let { className } = _ref2, props = _objectWithoutProperties(_ref2, _excluded$5);
|
|
272
295
|
const cn = `DocSearch-Menu-Trigger${className ? ` ${className}` : ""}`;
|
|
273
|
-
return /* @__PURE__ */ React.createElement(Menu.Trigger, _objectSpread2({
|
|
274
|
-
|
|
275
|
-
|
|
296
|
+
return /* @__PURE__ */ React.createElement(Menu.Trigger, _objectSpread2({
|
|
297
|
+
className: cn,
|
|
298
|
+
ref
|
|
299
|
+
}, props));
|
|
300
|
+
});
|
|
276
301
|
function MenuPopup(_ref3) {
|
|
277
302
|
let { align = "start", alignOffset = 0, side = "bottom", sideOffset = 4, collisionBoundary = "clipping-ancestors", container } = _ref3, props = _objectWithoutProperties(_ref3, _excluded2);
|
|
278
303
|
return /* @__PURE__ */ React.createElement(Menu.Portal, { container }, /* @__PURE__ */ React.createElement(Menu.Positioner, {
|
|
@@ -343,9 +368,10 @@ const SelectedFacetChip = React.memo(function SelectedFacetChip({ facetKey, face
|
|
|
343
368
|
});
|
|
344
369
|
const FacetBar = React.memo(function FacetBar({ facets, selections, onSelectionChange, clearSelections, translations = {} }) {
|
|
345
370
|
const { defaultValueLabel = "All", facetMenuTriggerAriaLabel = "selected", clearAllLabel = "Clear all", facetsAriaLabel = "Search filters", selectedFacetsAriaLabel = "Selected search filters", clearFacetAriaLabel = "Clear filter:" } = translations;
|
|
371
|
+
const visibleFacetKeys = React.useMemo(() => new Set(facets.map((f) => f.key)), [facets]);
|
|
346
372
|
const selectionsToDisplay = React.useMemo(() => {
|
|
347
|
-
return Object.entries(selections).filter(([
|
|
348
|
-
}, [selections]);
|
|
373
|
+
return Object.entries(selections).filter(([key, value]) => Boolean(value) && visibleFacetKeys.has(key));
|
|
374
|
+
}, [selections, visibleFacetKeys]);
|
|
349
375
|
const triggerRefs = React.useRef(/* @__PURE__ */ new Map());
|
|
350
376
|
const registerTrigger = React.useCallback((facetKey, el) => {
|
|
351
377
|
if (el) triggerRefs.current.set(facetKey, el);
|
|
@@ -507,12 +533,13 @@ function CommandIcon(props) {
|
|
|
507
533
|
strokeWidth: "1.4"
|
|
508
534
|
}, props.children));
|
|
509
535
|
}
|
|
510
|
-
function Footer({ translations = {}, isAskAiActive = false }) {
|
|
536
|
+
function Footer({ translations = {}, isAskAiActive = false, footerAction }) {
|
|
511
537
|
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;
|
|
512
|
-
|
|
538
|
+
const hasFooterAction = footerAction !== null && footerAction !== void 0 && typeof footerAction !== "boolean";
|
|
539
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__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: navigateDownKeyAriaLabel }, /* @__PURE__ */ React.createElement("path", { d: "M12 5v14" }), /* @__PURE__ */ React.createElement("path", { d: "m19 12-7 7-7-7" }))), /* @__PURE__ */ React.createElement("kbd", { className: "DocSearch-Commands-Key" }, /* @__PURE__ */ React.createElement(CommandIcon, { ariaLabel: navigateUpKeyAriaLabel }, /* @__PURE__ */ React.createElement("path", { d: "m5 12 7-7 7 7" }), /* @__PURE__ */ React.createElement("path", { d: "M12 19V5" }))), /* @__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: selectKeyAriaLabel }, /* @__PURE__ */ React.createElement("polyline", { points: "9 10 4 15 9 20" }), /* @__PURE__ */ React.createElement("path", { d: "M20 4v7a4 4 0 0 1-4 4H4" }))), /* @__PURE__ */ React.createElement("span", { className: "DocSearch-Label" }, isAskAiActive ? submitQuestionText : selectText)), /* @__PURE__ */ React.createElement("li", null, /* @__PURE__ */ React.createElement("kbd", { className: "DocSearch-Commands-Key" }, /* @__PURE__ */ React.createElement("span", { className: "DocSearch-Escape-Key" }, "ESC")), /* @__PURE__ */ React.createElement("span", {
|
|
513
540
|
className: "DocSearch-Label",
|
|
514
541
|
"aria-label": closeKeyAriaLabel
|
|
515
|
-
}, isAskAiActive ? backToSearchText : closeText))));
|
|
542
|
+
}, isAskAiActive ? backToSearchText : closeText))), /* @__PURE__ */ React.createElement("div", { className: "DocSearch-Footer-Actions" }, hasFooterAction && /* @__PURE__ */ React.createElement("div", { className: "DocSearch-Footer-Action" }, footerAction), /* @__PURE__ */ React.createElement("div", { className: "DocSearch-Logo" }, /* @__PURE__ */ React.createElement(AlgoliaLogo, { translations: { poweredByText } }))));
|
|
516
543
|
}
|
|
517
544
|
|
|
518
545
|
//#endregion
|
|
@@ -533,21 +560,15 @@ function useFacetValues({ facets, indexes, searchClient }) {
|
|
|
533
560
|
React.useEffect(() => {
|
|
534
561
|
let isMounted = true;
|
|
535
562
|
const facetKeys = stableFacetKeys ? stableFacetKeys.split(",") : [];
|
|
536
|
-
if (facetKeys.length === 0 || indexes.length === 0) {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
indexName: index.name,
|
|
546
|
-
query: "",
|
|
547
|
-
hitsPerPage: 0,
|
|
548
|
-
facets: facetKeys
|
|
549
|
-
});
|
|
550
|
-
}) }).then(({ results }) => {
|
|
563
|
+
if (facetKeys.length === 0 || indexes.length === 0) return () => {
|
|
564
|
+
isMounted = false;
|
|
565
|
+
};
|
|
566
|
+
searchClient.search({ requests: indexes.map((index) => ({
|
|
567
|
+
indexName: index.name,
|
|
568
|
+
query: "",
|
|
569
|
+
hitsPerPage: 0,
|
|
570
|
+
facets: facetKeys
|
|
571
|
+
})) }).then(({ results }) => {
|
|
551
572
|
if (!isMounted) return;
|
|
552
573
|
const valuesByFacet = facetKeys.reduce((acc, facet) => {
|
|
553
574
|
acc[facet] = [];
|
|
@@ -579,19 +600,23 @@ function useFacetValues({ facets, indexes, searchClient }) {
|
|
|
579
600
|
//#region src/hooks/useDocSearchFacets.ts
|
|
580
601
|
function useDocSearchFacets({ facets, indexes, searchClient, onSelectionsChange }) {
|
|
581
602
|
const normalizedFacets = React.useMemo(() => normalizeFacets(facets), [facets]);
|
|
603
|
+
const normalizedFacetsRef = React.useRef(normalizedFacets);
|
|
582
604
|
const facetValues = useFacetValues({
|
|
583
605
|
facets: normalizedFacets,
|
|
584
606
|
indexes,
|
|
585
607
|
searchClient
|
|
586
608
|
});
|
|
587
|
-
const [facetSelections, setFacetSelections] = React.useState(
|
|
609
|
+
const [facetSelections, setFacetSelections] = React.useState(() => deriveDefaultSelectedFacetsFromIndex(indexes));
|
|
588
610
|
const facetSelectionsRef = React.useRef(facetSelections);
|
|
589
611
|
const onSelectionsChangeRef = React.useRef(onSelectionsChange);
|
|
590
|
-
onSelectionsChangeRef.current = onSelectionsChange;
|
|
591
612
|
const visibleFacets = React.useMemo(() => normalizedFacets.map((facet) => {
|
|
592
613
|
var _facetValues$facet$ke;
|
|
593
614
|
return _objectSpread2(_objectSpread2({}, facet), {}, { values: (_facetValues$facet$ke = facetValues[facet.key]) !== null && _facetValues$facet$ke !== void 0 ? _facetValues$facet$ke : [] });
|
|
594
615
|
}).filter((facet) => facet.values.length > 0), [facetValues, normalizedFacets]);
|
|
616
|
+
React.useLayoutEffect(() => {
|
|
617
|
+
normalizedFacetsRef.current = normalizedFacets;
|
|
618
|
+
onSelectionsChangeRef.current = onSelectionsChange;
|
|
619
|
+
});
|
|
595
620
|
const applySelections = React.useCallback((next) => {
|
|
596
621
|
var _onSelectionsChangeRe;
|
|
597
622
|
facetSelectionsRef.current = next;
|
|
@@ -605,13 +630,14 @@ function useDocSearchFacets({ facets, indexes, searchClient, onSelectionsChange
|
|
|
605
630
|
handleFacetSelectionChange: React.useCallback((facet, value) => {
|
|
606
631
|
if (facetSelectionsRef.current[facet] === value) return;
|
|
607
632
|
const next = _objectSpread2({}, facetSelectionsRef.current);
|
|
608
|
-
|
|
609
|
-
else next[facet] = value;
|
|
633
|
+
next[facet] = value;
|
|
610
634
|
applySelections(next);
|
|
611
635
|
}, [applySelections]),
|
|
612
636
|
clearFacetSelections: React.useCallback(() => {
|
|
613
637
|
if (Object.keys(facetSelectionsRef.current).length === 0) return;
|
|
614
|
-
|
|
638
|
+
const next = {};
|
|
639
|
+
for (const facet of normalizedFacetsRef.current) if (facetSelectionsRef.current[facet.key]) next[facet.key] = "";
|
|
640
|
+
applySelections(next);
|
|
615
641
|
}, [applySelections])
|
|
616
642
|
};
|
|
617
643
|
}
|
|
@@ -695,7 +721,7 @@ function useTrapFocus({ container }) {
|
|
|
695
721
|
|
|
696
722
|
//#endregion
|
|
697
723
|
//#region src/hooks/useDocSearchModalEffects.ts
|
|
698
|
-
function useDocSearchModalEffects({ initialScrollY, modalRef,
|
|
724
|
+
function useDocSearchModalEffects({ initialScrollY, modalRef, theme }) {
|
|
699
725
|
useTheme({ theme });
|
|
700
726
|
React.useEffect(() => {
|
|
701
727
|
document.body.classList.add("DocSearch--active");
|
|
@@ -715,9 +741,6 @@ function useDocSearchModalEffects({ initialScrollY, modalRef, snippetLength, the
|
|
|
715
741
|
document.body.style.marginInlineEnd = "0px";
|
|
716
742
|
};
|
|
717
743
|
}, []);
|
|
718
|
-
React.useEffect(() => {
|
|
719
|
-
if (window.matchMedia("(max-width: 768px)").matches) snippetLength.current = 5;
|
|
720
|
-
}, [snippetLength]);
|
|
721
744
|
React.useEffect(() => {
|
|
722
745
|
function setFullViewportHeight() {
|
|
723
746
|
if (modalRef.current) {
|
|
@@ -735,7 +758,7 @@ function useDocSearchModalEffects({ initialScrollY, modalRef, snippetLength, the
|
|
|
735
758
|
|
|
736
759
|
//#endregion
|
|
737
760
|
//#region src/hooks/useModalEnvironment.ts
|
|
738
|
-
function useModalEnvironment({ getEnvironmentProps, containerRef, dropdownRef, formElementRef, inputRef, initialScrollY, modalRef,
|
|
761
|
+
function useModalEnvironment({ getEnvironmentProps, containerRef, dropdownRef, formElementRef, inputRef, initialScrollY, modalRef, theme }) {
|
|
739
762
|
useTouchEvents({
|
|
740
763
|
getEnvironmentProps,
|
|
741
764
|
panelElement: dropdownRef.current,
|
|
@@ -746,7 +769,6 @@ function useModalEnvironment({ getEnvironmentProps, containerRef, dropdownRef, f
|
|
|
746
769
|
useDocSearchModalEffects({
|
|
747
770
|
initialScrollY,
|
|
748
771
|
modalRef,
|
|
749
|
-
snippetLength,
|
|
750
772
|
theme
|
|
751
773
|
});
|
|
752
774
|
}
|
|
@@ -759,8 +781,7 @@ function useModalRefs() {
|
|
|
759
781
|
modalRef: React.useRef(null),
|
|
760
782
|
formElementRef: React.useRef(null),
|
|
761
783
|
dropdownRef: React.useRef(null),
|
|
762
|
-
inputRef: React.useRef(null)
|
|
763
|
-
snippetLength: React.useRef(15)
|
|
784
|
+
inputRef: React.useRef(null)
|
|
764
785
|
};
|
|
765
786
|
}
|
|
766
787
|
|
|
@@ -1070,10 +1091,6 @@ function HitResultBadge({ item, resultBadgeKey, translations = {} }) {
|
|
|
1070
1091
|
const _excluded = ["translations", "resultBadgeKey"];
|
|
1071
1092
|
function ResultsScreen(_ref) {
|
|
1072
1093
|
let { translations = {}, resultBadgeKey } = _ref, props = _objectWithoutProperties(_ref, _excluded);
|
|
1073
|
-
const { resultsSectionTitle = "Results" } = translations;
|
|
1074
|
-
const renderIcon = React.useCallback(({ item }) => {
|
|
1075
|
-
return /* @__PURE__ */ React.createElement("div", { className: "DocSearch-Hit-icon" }, /* @__PURE__ */ React.createElement(SourceIcon, { type: item.type }));
|
|
1076
|
-
}, []);
|
|
1077
1094
|
const renderAction = React.useCallback(() => {
|
|
1078
1095
|
return /* @__PURE__ */ React.createElement("div", { className: "DocSearch-Hit-action" }, /* @__PURE__ */ React.createElement(SelectIcon, null));
|
|
1079
1096
|
}, []);
|
|
@@ -1086,12 +1103,25 @@ function ResultsScreen(_ref) {
|
|
|
1086
1103
|
}, [resultBadgeKey, translations.resultBadgeLabelText]);
|
|
1087
1104
|
return /* @__PURE__ */ React.createElement("div", { className: "DocSearch-Dropdown-Container" }, props.state.collections.map((collection) => {
|
|
1088
1105
|
if (collection.items.length === 0) return null;
|
|
1106
|
+
const title = removeHighlightTags(collection.items[0]);
|
|
1089
1107
|
return /* @__PURE__ */ React.createElement(Results, _objectSpread2(_objectSpread2({}, props), {}, {
|
|
1090
1108
|
key: collection.source.sourceId,
|
|
1091
1109
|
translations,
|
|
1092
|
-
title
|
|
1110
|
+
title,
|
|
1093
1111
|
collection,
|
|
1094
|
-
renderIcon,
|
|
1112
|
+
renderIcon: ({ item, index }) => {
|
|
1113
|
+
var _collection$items;
|
|
1114
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, item.__docsearch_parent && /* @__PURE__ */ React.createElement("svg", {
|
|
1115
|
+
className: "DocSearch-Hit-Tree",
|
|
1116
|
+
viewBox: "0 0 24 54"
|
|
1117
|
+
}, /* @__PURE__ */ React.createElement("g", {
|
|
1118
|
+
stroke: "currentColor",
|
|
1119
|
+
fill: "none",
|
|
1120
|
+
fillRule: "evenodd",
|
|
1121
|
+
strokeLinecap: "round",
|
|
1122
|
+
strokeLinejoin: "round"
|
|
1123
|
+
}, 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 })));
|
|
1124
|
+
},
|
|
1095
1125
|
renderAction,
|
|
1096
1126
|
renderResultBadge
|
|
1097
1127
|
}));
|
|
@@ -1101,10 +1131,20 @@ function ResultsScreen(_ref) {
|
|
|
1101
1131
|
//#endregion
|
|
1102
1132
|
//#region src/utils/createDocSearchSources.ts
|
|
1103
1133
|
function createFacetFilters(searchParametersFacetFilters, facetSelections) {
|
|
1104
|
-
const
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1134
|
+
const selections = Object.entries(facetSelections);
|
|
1135
|
+
const selectedFacets = new Set(selections.map(([facet]) => facet));
|
|
1136
|
+
const dynamicFacetFilters = [];
|
|
1137
|
+
for (const [facet, selection] of selections) if (selection !== "") dynamicFacetFilters.push(`${facet}:${selection}`);
|
|
1138
|
+
if (selectedFacets.size === 0) return searchParametersFacetFilters;
|
|
1139
|
+
let configuredFacetFilters = [];
|
|
1140
|
+
if (searchParametersFacetFilters && Array.isArray(searchParametersFacetFilters)) configuredFacetFilters = searchParametersFacetFilters;
|
|
1141
|
+
else if (searchParametersFacetFilters) configuredFacetFilters = [searchParametersFacetFilters];
|
|
1142
|
+
return [...configuredFacetFilters.filter((facetFilter) => {
|
|
1143
|
+
if (typeof facetFilter !== "string") return true;
|
|
1144
|
+
const separatorIndex = facetFilter.indexOf(":");
|
|
1145
|
+
const facet = facetFilter.slice(0, separatorIndex);
|
|
1146
|
+
return separatorIndex <= 0 || !selectedFacets.has(facet);
|
|
1147
|
+
}), ...dynamicFacetFilters];
|
|
1108
1148
|
}
|
|
1109
1149
|
function buildNoQuerySources({ recentSearches, favoriteSearches, saveRecentSearch, onClose, disableUserPersonalization }) {
|
|
1110
1150
|
if (disableUserPersonalization) return [];
|
|
@@ -1134,7 +1174,7 @@ function buildNoQuerySources({ recentSearches, favoriteSearches, saveRecentSearc
|
|
|
1134
1174
|
}
|
|
1135
1175
|
}];
|
|
1136
1176
|
}
|
|
1137
|
-
async function buildQuerySources({ query, state: sourcesState, setContext, setStatus, searchClient, indexes,
|
|
1177
|
+
async function buildQuerySources({ query, state: sourcesState, setContext, setStatus, searchClient, indexes, insights, appId, apiKey, maxResultsPerGroup, transformItems = identity, saveRecentSearch, onClose, facetSelections }) {
|
|
1138
1178
|
const insightsActive = insights;
|
|
1139
1179
|
try {
|
|
1140
1180
|
const { results } = await searchClient.search({ requests: indexes.map((index) => {
|
|
@@ -1158,20 +1198,20 @@ async function buildQuerySources({ query, state: sourcesState, setContext, setSt
|
|
|
1158
1198
|
"url"
|
|
1159
1199
|
],
|
|
1160
1200
|
attributesToSnippet: (_searchParams$attribu2 = searchParams === null || searchParams === void 0 ? void 0 : searchParams.attributesToSnippet) !== null && _searchParams$attribu2 !== void 0 ? _searchParams$attribu2 : [
|
|
1161
|
-
`hierarchy.lvl1:${
|
|
1162
|
-
`hierarchy.lvl2:${
|
|
1163
|
-
`hierarchy.lvl3:${
|
|
1164
|
-
`hierarchy.lvl4:${
|
|
1165
|
-
`hierarchy.lvl5:${
|
|
1166
|
-
`hierarchy.lvl6:${
|
|
1167
|
-
`content:${
|
|
1201
|
+
`hierarchy.lvl1:${15}`,
|
|
1202
|
+
`hierarchy.lvl2:${15}`,
|
|
1203
|
+
`hierarchy.lvl3:${15}`,
|
|
1204
|
+
`hierarchy.lvl4:${15}`,
|
|
1205
|
+
`hierarchy.lvl5:${15}`,
|
|
1206
|
+
`hierarchy.lvl6:${15}`,
|
|
1207
|
+
`content:${15}`
|
|
1168
1208
|
],
|
|
1169
1209
|
snippetEllipsisText: (_searchParams$snippet = searchParams === null || searchParams === void 0 ? void 0 : searchParams.snippetEllipsisText) !== null && _searchParams$snippet !== void 0 ? _searchParams$snippet : "…",
|
|
1170
1210
|
highlightPreTag: (_searchParams$highlig = searchParams === null || searchParams === void 0 ? void 0 : searchParams.highlightPreTag) !== null && _searchParams$highlig !== void 0 ? _searchParams$highlig : "<mark>",
|
|
1171
1211
|
highlightPostTag: (_searchParams$highlig2 = searchParams === null || searchParams === void 0 ? void 0 : searchParams.highlightPostTag) !== null && _searchParams$highlig2 !== void 0 ? _searchParams$highlig2 : "</mark>",
|
|
1172
1212
|
hitsPerPage: (_searchParams$hitsPer = searchParams === null || searchParams === void 0 ? void 0 : searchParams.hitsPerPage) !== null && _searchParams$hitsPer !== void 0 ? _searchParams$hitsPer : 20,
|
|
1173
1213
|
clickAnalytics: (_searchParams$clickAn = searchParams === null || searchParams === void 0 ? void 0 : searchParams.clickAnalytics) !== null && _searchParams$clickAn !== void 0 ? _searchParams$clickAn : insightsActive
|
|
1174
|
-
}, searchParams
|
|
1214
|
+
}, searchParams), facetFilters ? { facetFilters } : {});
|
|
1175
1215
|
}) });
|
|
1176
1216
|
return results.flatMap((res) => {
|
|
1177
1217
|
const result = res;
|
|
@@ -1194,9 +1234,8 @@ async function buildQuerySources({ query, state: sourcesState, setContext, setSt
|
|
|
1194
1234
|
apiKey
|
|
1195
1235
|
}
|
|
1196
1236
|
};
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
sourceId: `hits_${result.index}`,
|
|
1237
|
+
return Object.values(sources).map((items, index) => ({
|
|
1238
|
+
sourceId: `hits_${result.index}_${index}`,
|
|
1200
1239
|
onSelect({ item, event }) {
|
|
1201
1240
|
saveRecentSearch(item);
|
|
1202
1241
|
if (!isModifierEvent(event)) onClose();
|
|
@@ -1210,9 +1249,9 @@ async function buildQuerySources({ query, state: sourcesState, setContext, setSt
|
|
|
1210
1249
|
const potentialParent = groupedHits.find((siblingItem) => siblingItem.type === "lvl1" && siblingItem.hierarchy.lvl1 === item.hierarchy.lvl1);
|
|
1211
1250
|
if (item.type !== "lvl1" && potentialParent) parent = potentialParent;
|
|
1212
1251
|
return _objectSpread2(_objectSpread2({}, item), {}, { __docsearch_parent: parent }, insightsParams);
|
|
1213
|
-
})
|
|
1252
|
+
})).flat();
|
|
1214
1253
|
}
|
|
1215
|
-
};
|
|
1254
|
+
}));
|
|
1216
1255
|
});
|
|
1217
1256
|
} catch (error) {
|
|
1218
1257
|
if (error.name === "RetryError") setStatus("error");
|
|
@@ -1222,19 +1261,11 @@ async function buildQuerySources({ query, state: sourcesState, setContext, setSt
|
|
|
1222
1261
|
|
|
1223
1262
|
//#endregion
|
|
1224
1263
|
//#region src/utils/normalizeDocSearchIndexes.ts
|
|
1225
|
-
function normalizeDocSearchIndexes({
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
name: indexName,
|
|
1229
|
-
searchParameters
|
|
1230
|
-
});
|
|
1231
|
-
if (indices.length > 0) indices.forEach((index) => {
|
|
1232
|
-
indexes.push(typeof index === "string" ? { name: index } : index);
|
|
1233
|
-
});
|
|
1234
|
-
if (indexes.length < 1) throw new Error("Must supply either `indexName` or `indices` for DocSearch to work");
|
|
1235
|
-
return indexes;
|
|
1264
|
+
function normalizeDocSearchIndexes({ indices }) {
|
|
1265
|
+
if (!Array.isArray(indices) || indices.length < 1) throw new Error("Must supply at least one `indices` entry for DocSearch");
|
|
1266
|
+
return indices.map((index) => typeof index === "string" ? { name: index } : index);
|
|
1236
1267
|
}
|
|
1237
1268
|
|
|
1238
1269
|
//#endregion
|
|
1239
|
-
export { noop as C,
|
|
1240
|
-
//# sourceMappingURL=normalizeDocSearchIndexes-
|
|
1270
|
+
export { noop as C, SOURCE_IDS as D, identity as E, getCollection as O, scrollTo as S, isModifierEvent as T, Hit as _, NoResultsScreen as a, SearchBoxForm as b, Results as c, useRefreshOnInitialQuery as d, useModalRefs as f, useDocSearchFacets as g, useSendItemClickEvent as h, ResultsScreen as i, useStoredDocSearches as l, useInitialModalQuery as m, buildNoQuerySources as n, ErrorScreen as o, useModalEnvironment as p, buildQuerySources as r, StoredSearchesSections as s, normalizeDocSearchIndexes as t, useSaveRecentSearch as u, Footer as v, isQueryEmpty as w, FacetBar as x, ModalShell as y };
|
|
1271
|
+
//# sourceMappingURL=normalizeDocSearchIndexes-ChnVvoVt.js.map
|