@netlify/spark-ui 1.23.0 → 1.24.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/dist/chunks/AskNetlify.BiMhcpol.js +2795 -0
- package/dist/chunks/compat.module.BaLKWB4y.js +300 -0
- package/dist/chunks/hooks.module.DRcxknIz.js +180 -0
- package/dist/chunks/{useTimeout.Cq4aqnDe.js → useTimeout.w16oNznN.js} +1 -1
- package/dist/components/preact/AskNetlify/AskNetlify.js +2 -2
- package/dist/components/preact/AskNetlify/hooks/useAskAnalytics.js +1 -1
- package/dist/components/preact/Modal/Modal.js +1 -1
- package/dist/components/preact/Popover/Popover.js +1 -1
- package/dist/components/preact/SearchModal/components/SearchInput.js +2 -2
- package/dist/components/preact/SearchModal/components/SearchLink/SearchLink.js +1 -1
- package/dist/components/preact/SearchModal/components/SearchModal/SearchModal.d.ts +2 -0
- package/dist/components/preact/SearchModal/components/SearchModal/SearchModal.js +44 -38
- package/dist/components/preact/SearchModal/components/SearchToggle/SearchToggle.js +1 -1
- package/dist/components/preact/SearchModal/hooks/useKeyboardNav.js +1 -1
- package/dist/components/preact/SearchModal/hooks/useSearch.d.ts +2 -2
- package/dist/components/preact/SearchModal/hooks/useSearch.js +29 -27
- package/dist/components/preact/SearchModal/hooks/useSearchAnalytics.js +1 -1
- package/dist/components/preact/SearchModal/hooks/useSearchHotkeys.js +1 -1
- package/dist/components/preact/SearchModal/hooks/useSearchParams.js +1 -1
- package/dist/components/preact/SearchModal/hooks/useSearchToggles.js +1 -1
- package/dist/components/preact/SearchModal/types/search.types.d.ts +19 -0
- package/dist/components/preact/index.js +2 -2
- package/package.json +4 -4
- package/packages/components/YoutubeVideo.astro +2 -1
- package/packages/components/preact/SearchModal/components/SearchModal/SearchModal.tsx +11 -3
- package/packages/components/preact/SearchModal/hooks/useSearch.ts +8 -6
- package/packages/components/preact/SearchModal/types/search.types.tsx +24 -0
- package/packages/components/preact/index.ts +1 -1
- package/dist/chunks/AskNetlify.CpaPeYsd.js +0 -4389
- package/dist/chunks/compat.module.8cuvf1_R.js +0 -298
- package/dist/chunks/hooks.module.DGkdD5n9.js +0 -177
|
@@ -1,34 +1,40 @@
|
|
|
1
1
|
import { u as e } from "../../../../../chunks/jsxRuntime.module.Bzuv3cXw.js";
|
|
2
|
-
import { A as g, y as f, d } from "../../../../../chunks/hooks.module.
|
|
3
|
-
import { A as
|
|
4
|
-
import
|
|
2
|
+
import { A as g, y as f, d } from "../../../../../chunks/hooks.module.DRcxknIz.js";
|
|
3
|
+
import { A as L, K as P } from "../../../../../chunks/AskNetlify.BiMhcpol.js";
|
|
4
|
+
import M from "../../../Modal/Modal.js";
|
|
5
5
|
import h from "../../../KeyboardKey/KeyboardKey.js";
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import { useSearch as
|
|
10
|
-
import { useSearchAnalytics as
|
|
11
|
-
import { useKeyboardNav as
|
|
12
|
-
import { useSearchHotkeys as
|
|
13
|
-
import { useSearchParams as
|
|
14
|
-
import { useSearchToggles as
|
|
15
|
-
import { useAskAnalytics as
|
|
6
|
+
import O from "../SearchWindow.js";
|
|
7
|
+
import Q from "../SearchInput.js";
|
|
8
|
+
import C from "../AskNetlifyLink.js";
|
|
9
|
+
import { useSearch as E } from "../../hooks/useSearch.js";
|
|
10
|
+
import { useSearchAnalytics as R } from "../../hooks/useSearchAnalytics.js";
|
|
11
|
+
import { useKeyboardNav as q } from "../../hooks/useKeyboardNav.js";
|
|
12
|
+
import { useSearchHotkeys as x } from "../../hooks/useSearchHotkeys.js";
|
|
13
|
+
import { useSearchParams as D } from "../../hooks/useSearchParams.js";
|
|
14
|
+
import { useSearchToggles as F } from "../../hooks/useSearchToggles.js";
|
|
15
|
+
import { useAskAnalytics as G } from "../../../AskNetlify/hooks/useAskAnalytics.js";
|
|
16
16
|
import { Fragment as N } from "preact";
|
|
17
|
-
import '../../../../../assets/SearchModal.css';function
|
|
18
|
-
const
|
|
17
|
+
import '../../../../../assets/SearchModal.css';function H(a) {
|
|
18
|
+
const s = g(null);
|
|
19
19
|
return f(() => {
|
|
20
|
-
function
|
|
21
|
-
|
|
20
|
+
function n(m) {
|
|
21
|
+
s.current && !s.current.contains(m.target) && a();
|
|
22
22
|
}
|
|
23
|
-
return document.addEventListener("mousedown",
|
|
24
|
-
document.removeEventListener("mousedown",
|
|
23
|
+
return document.addEventListener("mousedown", n), () => {
|
|
24
|
+
document.removeEventListener("mousedown", n);
|
|
25
25
|
};
|
|
26
|
-
}, [a]),
|
|
26
|
+
}, [a]), s;
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
function se(a = {
|
|
29
|
+
className: "",
|
|
30
|
+
children: void 0,
|
|
31
|
+
debug: !1,
|
|
32
|
+
kapaIntegrationId: void 0,
|
|
33
|
+
filters: void 0
|
|
34
|
+
}) {
|
|
35
|
+
const { children: s, className: n, debug: m, filters: T, ...v } = a, [c, o] = d({ current: "search" }), [i, p] = d(!1), [A, I] = d(""), l = () => p(!0), u = () => p(!1), t = g(null), w = H(u), { state: r, actions: S } = E(T);
|
|
36
|
+
F(l, o), D(l, S.setSearchTerm, I, o), x(i, l, u), q(t, i, u), R(r, m);
|
|
37
|
+
const { handleNewQuery: b, handleAnswer: K } = G();
|
|
32
38
|
return f(() => {
|
|
33
39
|
t.current && (i ? t.current.showModal() : t.current.close());
|
|
34
40
|
}, [i]), f(() => {
|
|
@@ -36,43 +42,43 @@ function te(a = { className: "", children: void 0, debug: !1, kapaIntegrationId:
|
|
|
36
42
|
const y = (k = t.current) == null ? void 0 : k.querySelector("input");
|
|
37
43
|
y && y.focus();
|
|
38
44
|
}, [c.current]), /* @__PURE__ */ e(
|
|
39
|
-
|
|
45
|
+
P,
|
|
40
46
|
{
|
|
41
47
|
integrationId: a.kapaIntegrationId || "",
|
|
42
48
|
callbacks: {
|
|
43
49
|
askAI: {
|
|
44
|
-
onQuerySubmit:
|
|
45
|
-
onAnswerGenerationCompleted:
|
|
50
|
+
onQuerySubmit: b,
|
|
51
|
+
onAnswerGenerationCompleted: K
|
|
46
52
|
}
|
|
47
53
|
},
|
|
48
54
|
children: /* @__PURE__ */ e(
|
|
49
|
-
|
|
55
|
+
M,
|
|
50
56
|
{
|
|
51
57
|
ref: t,
|
|
52
|
-
className: `n-search-modal ${
|
|
58
|
+
className: `n-search-modal ${n || ""}`,
|
|
53
59
|
"data-state": c.current,
|
|
54
|
-
...
|
|
55
|
-
children: /* @__PURE__ */ e("div", { ref:
|
|
60
|
+
...v,
|
|
61
|
+
children: /* @__PURE__ */ e("div", { ref: w, className: "n-search-container", children: [
|
|
56
62
|
c.current === "ask" && /* @__PURE__ */ e(
|
|
57
|
-
|
|
63
|
+
L,
|
|
58
64
|
{
|
|
59
65
|
setModalState: o,
|
|
60
66
|
searchQuery: r.searchTerm,
|
|
61
|
-
urlParamQuery:
|
|
67
|
+
urlParamQuery: A
|
|
62
68
|
}
|
|
63
69
|
),
|
|
64
70
|
c.current === "search" && /* @__PURE__ */ e(N, { children: [
|
|
65
|
-
/* @__PURE__ */ e(
|
|
71
|
+
/* @__PURE__ */ e(Q, { setSearchTerm: S.setSearchTerm, initialValue: r.searchTerm }),
|
|
66
72
|
/* @__PURE__ */ e(
|
|
67
|
-
|
|
73
|
+
O,
|
|
68
74
|
{
|
|
69
75
|
setModalState: o,
|
|
70
76
|
searchLoading: r.isLoading,
|
|
71
77
|
searchTerm: r.searchTerm,
|
|
72
78
|
results: r.results,
|
|
73
79
|
children: /* @__PURE__ */ e(N, { children: [
|
|
74
|
-
a.kapaIntegrationId && /* @__PURE__ */ e(
|
|
75
|
-
|
|
80
|
+
a.kapaIntegrationId && /* @__PURE__ */ e(C, { searchTerm: r.searchTerm, setModalState: o }),
|
|
81
|
+
s
|
|
76
82
|
] })
|
|
77
83
|
}
|
|
78
84
|
),
|
|
@@ -96,5 +102,5 @@ function te(a = { className: "", children: void 0, debug: !1, kapaIntegrationId:
|
|
|
96
102
|
);
|
|
97
103
|
}
|
|
98
104
|
export {
|
|
99
|
-
|
|
105
|
+
se as default
|
|
100
106
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { u as e } from "../../../../../chunks/jsxRuntime.module.Bzuv3cXw.js";
|
|
2
|
-
import { D as a } from "../../../../../chunks/compat.module.
|
|
2
|
+
import { D as a } from "../../../../../chunks/compat.module.BaLKWB4y.js";
|
|
3
3
|
import o from "../../../Icon/index.js";
|
|
4
4
|
import '../../../../../assets/SearchToggle.css';const s = a(function(r, t) {
|
|
5
5
|
return /* @__PURE__ */ e("button", { id: r.id, ref: t, class: "n-search-toggle button", disabled: !0, "data-ntl-search-toggle": !0, children: [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SearchState } from '../types/search.types';
|
|
1
|
+
import { PagefindFilters, SearchState } from '../types/search.types';
|
|
2
2
|
/**
|
|
3
3
|
* Hook that encapsulates client-side search logic:
|
|
4
4
|
*
|
|
@@ -8,7 +8,7 @@ import { SearchState } from '../types/search.types';
|
|
|
8
8
|
* - Maps and formats raw search results into a consistent shape with title, excerpt, url, and icon
|
|
9
9
|
* - Exposes `setSearchTerm` for live input handling and `submitSearch` for manual triggering
|
|
10
10
|
*/
|
|
11
|
-
export declare function useSearch(): {
|
|
11
|
+
export declare function useSearch(filters?: PagefindFilters): {
|
|
12
12
|
state: SearchState;
|
|
13
13
|
actions: {
|
|
14
14
|
setSearchTerm: (query: string) => void;
|
|
@@ -1,52 +1,54 @@
|
|
|
1
|
-
import { d as
|
|
2
|
-
import { u as
|
|
3
|
-
function
|
|
4
|
-
const [
|
|
1
|
+
import { d as w, A as L } from "../../../../chunks/hooks.module.DRcxknIz.js";
|
|
2
|
+
import { u as T } from "../../../../chunks/useTimeout.w16oNznN.js";
|
|
3
|
+
function A(s) {
|
|
4
|
+
const [m, r] = w({
|
|
5
5
|
searchTerm: "",
|
|
6
6
|
results: [],
|
|
7
7
|
isLoading: !1
|
|
8
|
-
}),
|
|
9
|
-
e && e.length >= 2 &&
|
|
10
|
-
}, 150),
|
|
11
|
-
var
|
|
8
|
+
}), o = L(/* @__PURE__ */ new Map()), { reset: g, run: p } = T((e) => {
|
|
9
|
+
e && e.length >= 2 && i(e);
|
|
10
|
+
}, 150), i = async (e) => {
|
|
11
|
+
var l;
|
|
12
12
|
if (!(window != null && window.pagefind)) return;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
r((t) => ({ ...t, isLoading: !0 }));
|
|
14
|
+
const n = s ? `${e}::${JSON.stringify(s)}` : e;
|
|
15
|
+
if (o.current.has(n)) {
|
|
16
|
+
r((t) => ({
|
|
17
|
+
...t,
|
|
18
|
+
results: o.current.get(n),
|
|
17
19
|
isLoading: !1
|
|
18
20
|
}));
|
|
19
21
|
return;
|
|
20
22
|
}
|
|
21
|
-
const
|
|
22
|
-
(
|
|
23
|
-
var
|
|
24
|
-
const
|
|
23
|
+
const a = await window.pagefind.debouncedSearch(e, s ? { filters: s } : void 0), u = (a == null ? void 0 : a.results) && await Promise.all(
|
|
24
|
+
(l = a == null ? void 0 : a.results) == null ? void 0 : l.slice(0, 15).map(async (t) => {
|
|
25
|
+
var d, h;
|
|
26
|
+
const c = await t.data(), f = (S) => S.replace("#", "");
|
|
25
27
|
return {
|
|
26
28
|
icon: "pageWithLines",
|
|
27
|
-
resource: (
|
|
28
|
-
label: (
|
|
29
|
-
url:
|
|
30
|
-
excerpt: f(
|
|
29
|
+
resource: (d = c.meta) == null ? void 0 : d.resource,
|
|
30
|
+
label: (h = c.meta) == null ? void 0 : h.title,
|
|
31
|
+
url: c.url,
|
|
32
|
+
excerpt: f(c.excerpt)
|
|
31
33
|
};
|
|
32
34
|
})
|
|
33
35
|
);
|
|
34
|
-
|
|
35
|
-
...
|
|
36
|
-
results:
|
|
36
|
+
o.current.set(n, u), r((t) => ({
|
|
37
|
+
...t,
|
|
38
|
+
results: u,
|
|
37
39
|
isLoading: !1
|
|
38
40
|
}));
|
|
39
41
|
};
|
|
40
42
|
return {
|
|
41
|
-
state:
|
|
43
|
+
state: m,
|
|
42
44
|
actions: {
|
|
43
45
|
setSearchTerm: (e) => {
|
|
44
|
-
|
|
46
|
+
r((n) => ({ ...n, searchTerm: e })), g(), p(e);
|
|
45
47
|
},
|
|
46
|
-
submitSearch:
|
|
48
|
+
submitSearch: i
|
|
47
49
|
}
|
|
48
50
|
};
|
|
49
51
|
}
|
|
50
52
|
export {
|
|
51
|
-
|
|
53
|
+
A as useSearch
|
|
52
54
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as y, y as h, q as d } from "../../../../chunks/hooks.module.
|
|
1
|
+
import { A as y, y as h, q as d } from "../../../../chunks/hooks.module.DRcxknIz.js";
|
|
2
2
|
import { A as T } from "../../../../chunks/analytics.D_dJH08O.js";
|
|
3
3
|
function A(r, l) {
|
|
4
4
|
const n = y(new T()).current, e = (c) => c.debug_mode = !0;
|
|
@@ -38,3 +38,22 @@ export interface SearchGTMObjectProps {
|
|
|
38
38
|
query?: string;
|
|
39
39
|
debug_mode?: boolean;
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* A single Pagefind filter value. Either a direct match (string / array of
|
|
43
|
+
* strings) or an operator object for compound matching and exclusion.
|
|
44
|
+
*
|
|
45
|
+
* @see https://pagefind.app/docs/js-api-filtering/
|
|
46
|
+
*/
|
|
47
|
+
export type PagefindFilterValue = string | string[] | {
|
|
48
|
+
any?: string[];
|
|
49
|
+
all?: string[];
|
|
50
|
+
none?: string[];
|
|
51
|
+
not?: string[];
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Pagefind filters passed to a search, keyed by filter name.
|
|
55
|
+
*
|
|
56
|
+
* @example { resource: 'docs' } // only docs
|
|
57
|
+
* @example { tags: { none: ['blog'] } } // everything except blog posts
|
|
58
|
+
*/
|
|
59
|
+
export type PagefindFilters = Record<string, PagefindFilterValue>;
|
|
@@ -4,9 +4,9 @@ import { default as m } from "./Icon/index.js";
|
|
|
4
4
|
import { default as s } from "./SearchModal/components/SearchLink/SearchLink.js";
|
|
5
5
|
import { default as u } from "./SearchModal/components/SearchHeading/SearchHeading.js";
|
|
6
6
|
import { default as i } from "./SearchModal/components/SearchToggle/SearchToggle.js";
|
|
7
|
-
import { A as S } from "../../chunks/AskNetlify.
|
|
7
|
+
import { A as S } from "../../chunks/AskNetlify.BiMhcpol.js";
|
|
8
8
|
import "preact";
|
|
9
|
-
import "../../chunks/hooks.module.
|
|
9
|
+
import "../../chunks/hooks.module.DRcxknIz.js";
|
|
10
10
|
import { default as n } from "./SearchModal/components/SearchModal/SearchModal.js";
|
|
11
11
|
export {
|
|
12
12
|
S as AskNetlify,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/spark-ui",
|
|
3
3
|
"description": "Assets, design tokens, components, and utilities",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.24.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/components/preact/index.js",
|
|
7
7
|
"types": "dist/components/preact/index.d.ts",
|
|
@@ -51,11 +51,11 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@semantic-release/changelog": "^6.0.3",
|
|
53
53
|
"@semantic-release/git": "^10.0.1",
|
|
54
|
-
"@semantic-release/npm": "^
|
|
54
|
+
"@semantic-release/npm": "^13.0.0",
|
|
55
55
|
"@terrazzo/cli": "^0.10.3",
|
|
56
56
|
"@terrazzo/plugin-css": "^0.10.0",
|
|
57
57
|
"@types/gtag.js": "^0.0.20",
|
|
58
|
-
"semantic-release": "^
|
|
58
|
+
"semantic-release": "^25.0.0",
|
|
59
59
|
"tslib": "^2.8.1",
|
|
60
60
|
"typescript": "^5.8.2"
|
|
61
61
|
},
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"@typescript-eslint/eslint-plugin": "^8.26.0",
|
|
64
64
|
"@typescript-eslint/parser": "^8.26.0",
|
|
65
65
|
"astro-eslint-parser": "^1.2.1",
|
|
66
|
-
"eslint": "^
|
|
66
|
+
"eslint": "^10.0.0",
|
|
67
67
|
"eslint-config-prettier": "^10.1.1",
|
|
68
68
|
"eslint-plugin-astro": "^1.3.1",
|
|
69
69
|
"preact": "^10.26.4",
|
|
@@ -37,7 +37,7 @@ const hasPreviewVideo = previewVideo || previewVideoWebm;
|
|
|
37
37
|
</div>
|
|
38
38
|
)
|
|
39
39
|
}
|
|
40
|
-
<div class="n-youtube-video__play-icon" aria-hidden="true"
|
|
40
|
+
<div class="n-youtube-video__play-icon" aria-hidden="true"></div>
|
|
41
41
|
</div>
|
|
42
42
|
|
|
43
43
|
<style>
|
|
@@ -49,6 +49,7 @@ const hasPreviewVideo = previewVideo || previewVideoWebm;
|
|
|
49
49
|
overflow: hidden;
|
|
50
50
|
width: 100%;
|
|
51
51
|
aspect-ratio: 16 / 9;
|
|
52
|
+
isolation: isolate;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
.n-youtube-video :global(lite-youtube) {
|
|
@@ -9,6 +9,7 @@ import SearchWindow from '../../components/SearchWindow';
|
|
|
9
9
|
import SearchInput from '../../components/SearchInput';
|
|
10
10
|
import AskNetlifyLink from '../AskNetlifyLink';
|
|
11
11
|
import { useClickOutside } from '../../../../../utils/useClickOutside';
|
|
12
|
+
import type { PagefindFilters } from '../../types/search.types';
|
|
12
13
|
import {
|
|
13
14
|
useSearch,
|
|
14
15
|
useKeyboardNav,
|
|
@@ -28,12 +29,19 @@ interface Props {
|
|
|
28
29
|
className?: string;
|
|
29
30
|
debug?: boolean;
|
|
30
31
|
kapaIntegrationId?: string;
|
|
32
|
+
filters?: PagefindFilters;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
function SearchModal(
|
|
34
|
-
props: Props = {
|
|
36
|
+
props: Props = {
|
|
37
|
+
className: '',
|
|
38
|
+
children: undefined,
|
|
39
|
+
debug: false,
|
|
40
|
+
kapaIntegrationId: undefined,
|
|
41
|
+
filters: undefined,
|
|
42
|
+
}
|
|
35
43
|
) {
|
|
36
|
-
const { children, className, debug, ...rest } = props;
|
|
44
|
+
const { children, className, debug, filters, ...rest } = props;
|
|
37
45
|
|
|
38
46
|
const [modalState, setModalState] = useState({ current: 'search' });
|
|
39
47
|
const [searchOpen, setSearchOpen] = useState(false);
|
|
@@ -44,7 +52,7 @@ function SearchModal(
|
|
|
44
52
|
const modalRef = useRef<HTMLDialogElement>(null);
|
|
45
53
|
const containerRef = useClickOutside<HTMLDivElement>(closeSearch);
|
|
46
54
|
|
|
47
|
-
const { state, actions } = useSearch();
|
|
55
|
+
const { state, actions } = useSearch(filters);
|
|
48
56
|
useSearchToggles(openSearch, setModalState);
|
|
49
57
|
useSearchParams(openSearch, actions.setSearchTerm, setUrlParamTerm, setModalState);
|
|
50
58
|
useSearchHotkeys(searchOpen, openSearch, closeSearch);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState, useRef } from 'preact/hooks';
|
|
2
|
-
import type { SearchState } from '../types/search.types';
|
|
2
|
+
import type { PagefindFilters, SearchState } from '../types/search.types';
|
|
3
3
|
import { useTimeout } from '../../../../utils/useTimeout';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -12,7 +12,7 @@ import { useTimeout } from '../../../../utils/useTimeout';
|
|
|
12
12
|
* - Exposes `setSearchTerm` for live input handling and `submitSearch` for manual triggering
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
-
export function useSearch() {
|
|
15
|
+
export function useSearch(filters?: PagefindFilters) {
|
|
16
16
|
const [state, setSearchState] = useState<SearchState>({
|
|
17
17
|
searchTerm: '',
|
|
18
18
|
results: [],
|
|
@@ -29,15 +29,17 @@ export function useSearch() {
|
|
|
29
29
|
|
|
30
30
|
setSearchState(prev => ({ ...prev, isLoading: true }));
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
const cacheKey = filters ? `${query}::${JSON.stringify(filters)}` : query;
|
|
33
|
+
|
|
34
|
+
if (cacheRef.current.has(cacheKey)) {
|
|
33
35
|
setSearchState(prev => ({
|
|
34
36
|
...prev,
|
|
35
|
-
results: cacheRef.current.get(
|
|
37
|
+
results: cacheRef.current.get(cacheKey),
|
|
36
38
|
isLoading: false,
|
|
37
39
|
}));
|
|
38
40
|
return;
|
|
39
41
|
}
|
|
40
|
-
const search = await window.pagefind.debouncedSearch(query);
|
|
42
|
+
const search = await window.pagefind.debouncedSearch(query, filters ? { filters } : undefined);
|
|
41
43
|
const results =
|
|
42
44
|
search?.results &&
|
|
43
45
|
(await Promise.all(
|
|
@@ -55,7 +57,7 @@ export function useSearch() {
|
|
|
55
57
|
})
|
|
56
58
|
));
|
|
57
59
|
|
|
58
|
-
cacheRef.current.set(
|
|
60
|
+
cacheRef.current.set(cacheKey, results);
|
|
59
61
|
|
|
60
62
|
setSearchState(prev => ({
|
|
61
63
|
...prev,
|
|
@@ -39,3 +39,27 @@ export interface SearchGTMObjectProps {
|
|
|
39
39
|
query?: string;
|
|
40
40
|
debug_mode?: boolean;
|
|
41
41
|
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A single Pagefind filter value. Either a direct match (string / array of
|
|
45
|
+
* strings) or an operator object for compound matching and exclusion.
|
|
46
|
+
*
|
|
47
|
+
* @see https://pagefind.app/docs/js-api-filtering/
|
|
48
|
+
*/
|
|
49
|
+
export type PagefindFilterValue =
|
|
50
|
+
| string
|
|
51
|
+
| string[]
|
|
52
|
+
| {
|
|
53
|
+
any?: string[];
|
|
54
|
+
all?: string[];
|
|
55
|
+
none?: string[];
|
|
56
|
+
not?: string[];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Pagefind filters passed to a search, keyed by filter name.
|
|
61
|
+
*
|
|
62
|
+
* @example { resource: 'docs' } // only docs
|
|
63
|
+
* @example { tags: { none: ['blog'] } } // everything except blog posts
|
|
64
|
+
*/
|
|
65
|
+
export type PagefindFilters = Record<string, PagefindFilterValue>;
|
|
@@ -4,7 +4,7 @@ export { default as Icon } from './Icon';
|
|
|
4
4
|
export { default as SearchLink } from './SearchModal/components/SearchLink/SearchLink';
|
|
5
5
|
export { default as SearchHeading } from './SearchModal/components/SearchHeading/SearchHeading';
|
|
6
6
|
export { default as SearchToggle } from './SearchModal/components/SearchToggle/SearchToggle';
|
|
7
|
-
export { default as AskNetlify } from
|
|
7
|
+
export { default as AskNetlify } from './AskNetlify/AskNetlify';
|
|
8
8
|
export { SearchModal } from './SearchModal';
|
|
9
9
|
|
|
10
10
|
export { type IconName } from './Icon';
|