@netlify/spark-ui 0.0.23 → 0.0.24
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/{compat.module.BPxt-oTe.js → compat.module.AxtqoZMv.js} +1 -1
- package/dist/chunks/{hooks.module.ExpuRnbo.js → hooks.module.BFfOesdf.js} +1 -0
- package/dist/components/preact/Modal/Modal.js +1 -1
- package/dist/components/preact/SearchModal/components/SearchInput.js +1 -1
- package/dist/components/preact/SearchModal/components/SearchModal/SearchModal.js +1 -1
- package/dist/components/preact/SearchModal/components/SearchToggle/SearchToggle.js +1 -1
- package/dist/components/preact/SearchModal/components/SearchWindow.js +28 -20
- package/dist/components/preact/SearchModal/hooks/useKeyboardNav.js +1 -1
- package/dist/components/preact/SearchModal/hooks/useSearch.js +25 -18
- 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/index.js +1 -1
- package/package.json +1 -1
- package/packages/components/preact/SearchModal/components/SearchWindow.tsx +10 -5
- package/packages/components/preact/SearchModal/hooks/useSearch.ts +13 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { u as l } from "../../../chunks/jsxRuntime.module.Bzuv3cXw.js";
|
|
2
|
-
import { D as d } from "../../../chunks/compat.module.
|
|
2
|
+
import { D as d } from "../../../chunks/compat.module.AxtqoZMv.js";
|
|
3
3
|
const u = d(function({ children: o, className: r, ...a }, t) {
|
|
4
4
|
return /* @__PURE__ */ l("dialog", { ref: t, className: r, role: "dialog", "aria-modal": "true", ...a, children: o });
|
|
5
5
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { u as e } from "../../../../chunks/jsxRuntime.module.Bzuv3cXw.js";
|
|
2
|
-
import { d as i, y as s } from "../../../../chunks/hooks.module.
|
|
2
|
+
import { d as i, y as s } from "../../../../chunks/hooks.module.BFfOesdf.js";
|
|
3
3
|
import h from "../../Icon/index.js";
|
|
4
4
|
const m = (a) => {
|
|
5
5
|
const [t, l] = i(""), c = (r) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { u as s } from "../../../../../chunks/jsxRuntime.module.Bzuv3cXw.js";
|
|
2
|
-
import { A as h, y as S, d as v } from "../../../../../chunks/hooks.module.
|
|
2
|
+
import { A as h, y as S, d as v } from "../../../../../chunks/hooks.module.BFfOesdf.js";
|
|
3
3
|
import N from "../../../Modal/Modal.js";
|
|
4
4
|
import f from "../../../KeyboardKey/KeyboardKey.js";
|
|
5
5
|
import O from "../SearchWindow.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { u as e } from "../../../../../chunks/jsxRuntime.module.Bzuv3cXw.js";
|
|
2
|
-
import { D as t } from "../../../../../chunks/compat.module.
|
|
2
|
+
import { D as t } from "../../../../../chunks/compat.module.AxtqoZMv.js";
|
|
3
3
|
import o from "../../../Icon/index.js";
|
|
4
4
|
import '../../../../../assets/SearchToggle.css';const s = t(function(r, a) {
|
|
5
5
|
return /* @__PURE__ */ e("button", { id: r.id, ref: a, class: "n-search-toggle", disabled: !0, "data-ntl-search-toggle": !0, children: [
|
|
@@ -1,33 +1,41 @@
|
|
|
1
1
|
import { u as e } from "../../../../chunks/jsxRuntime.module.Bzuv3cXw.js";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { T as o } from "../../../../chunks/hooks.module.BFfOesdf.js";
|
|
3
|
+
import t from "./SearchHeading/SearchHeading.js";
|
|
4
|
+
import a from "./SearchLink/SearchLink.js";
|
|
5
|
+
const h = ({
|
|
6
|
+
searchLoading: i,
|
|
7
|
+
searchTerm: n,
|
|
7
8
|
results: r
|
|
8
|
-
}) =>
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
}) => {
|
|
10
|
+
if (i)
|
|
11
|
+
return /* @__PURE__ */ e(t, { children: [
|
|
12
|
+
"Searching for ",
|
|
13
|
+
/* @__PURE__ */ e("span", { className: "n-search-term", children: n }),
|
|
14
|
+
" ..."
|
|
15
|
+
] });
|
|
16
|
+
if (!r || r.length === 0)
|
|
17
|
+
return /* @__PURE__ */ e(t, { children: [
|
|
18
|
+
"0 results for ",
|
|
19
|
+
/* @__PURE__ */ e("span", { className: "n-search-term", children: n })
|
|
20
|
+
] });
|
|
21
|
+
const l = o(() => r.map((s, c) => /* @__PURE__ */ e("li", { className: "n-results-list-item", children: /* @__PURE__ */ e(a, { ...s }) }, c)), [r]);
|
|
22
|
+
return /* @__PURE__ */ e("ul", { className: "n-results-list", role: "list", children: l });
|
|
23
|
+
};
|
|
24
|
+
function N({
|
|
25
|
+
searchLoading: i,
|
|
26
|
+
searchTerm: n,
|
|
19
27
|
results: r,
|
|
20
|
-
children:
|
|
28
|
+
children: l
|
|
21
29
|
}) {
|
|
22
30
|
return /* @__PURE__ */ e("div", { className: "n-search-window", children: /* @__PURE__ */ e("div", { className: "search-links", children: [
|
|
23
|
-
/* @__PURE__ */ e(
|
|
31
|
+
/* @__PURE__ */ e(a, { ...{
|
|
24
32
|
icon: "askNetlify",
|
|
25
33
|
label: "Ask Netlify AI",
|
|
26
34
|
url: "https://docs.netlify.com/ask-netlify/"
|
|
27
35
|
} }),
|
|
28
|
-
|
|
36
|
+
n ? /* @__PURE__ */ e(h, { searchLoading: i, searchTerm: n, results: r }) : l || null
|
|
29
37
|
] }) });
|
|
30
38
|
}
|
|
31
39
|
export {
|
|
32
|
-
|
|
40
|
+
N as default
|
|
33
41
|
};
|
|
@@ -1,36 +1,43 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as u, y as p, d as w } from "../../../../chunks/hooks.module.BFfOesdf.js";
|
|
2
2
|
import { getSiteIcon as S } from "../utils/index.js";
|
|
3
|
-
function
|
|
4
|
-
const t =
|
|
3
|
+
function T(s, r) {
|
|
4
|
+
const t = u(null), c = u("");
|
|
5
5
|
return p(() => () => {
|
|
6
6
|
t.current && clearTimeout(t.current);
|
|
7
7
|
}, []), { reset: () => {
|
|
8
8
|
t.current && clearTimeout(t.current);
|
|
9
|
-
}, run: (
|
|
10
|
-
c.current =
|
|
9
|
+
}, run: (h) => {
|
|
10
|
+
c.current = h, t.current = setTimeout(
|
|
11
11
|
() => s(c.current),
|
|
12
12
|
r
|
|
13
13
|
);
|
|
14
14
|
} };
|
|
15
15
|
}
|
|
16
|
-
function
|
|
17
|
-
const [s, r] =
|
|
16
|
+
function R() {
|
|
17
|
+
const [s, r] = w({
|
|
18
18
|
searchTerm: "",
|
|
19
19
|
results: [],
|
|
20
20
|
isLoading: !1
|
|
21
|
-
}), { reset:
|
|
21
|
+
}), t = u(/* @__PURE__ */ new Map()), { reset: c, run: l } = T((e) => {
|
|
22
22
|
(e.length > 2 || e.length === 0) && o(e);
|
|
23
23
|
}, 150), o = async (e) => {
|
|
24
24
|
if (!(window != null && window.pagefind)) return;
|
|
25
|
-
r((n) => ({ ...n, isLoading: !0 }))
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
if (r((n) => ({ ...n, isLoading: !0 })), t.current.has(e)) {
|
|
26
|
+
r((n) => ({
|
|
27
|
+
...n,
|
|
28
|
+
results: t.current.get(e),
|
|
29
|
+
isLoading: !1
|
|
30
|
+
}));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const i = await window.pagefind.search(e), g = await Promise.all(
|
|
34
|
+
i.results.slice(0, 15).map(async (n) => {
|
|
35
|
+
var m, f, d;
|
|
29
36
|
const a = await n.data();
|
|
30
37
|
return {
|
|
31
|
-
icon: S((
|
|
32
|
-
content_type: (
|
|
33
|
-
label: (
|
|
38
|
+
icon: S((m = a.meta) == null ? void 0 : m.content_type),
|
|
39
|
+
content_type: (f = a.meta) == null ? void 0 : f.content_type,
|
|
40
|
+
label: (d = a.meta) == null ? void 0 : d.title,
|
|
34
41
|
url: a.url,
|
|
35
42
|
excerpt: a.excerpt
|
|
36
43
|
};
|
|
@@ -38,7 +45,7 @@ function y() {
|
|
|
38
45
|
);
|
|
39
46
|
r((n) => ({
|
|
40
47
|
...n,
|
|
41
|
-
results:
|
|
48
|
+
results: g,
|
|
42
49
|
isLoading: !1
|
|
43
50
|
}));
|
|
44
51
|
};
|
|
@@ -46,12 +53,12 @@ function y() {
|
|
|
46
53
|
state: s,
|
|
47
54
|
actions: {
|
|
48
55
|
setSearchTerm: (e) => {
|
|
49
|
-
r((i) => ({ ...i, searchTerm: e })),
|
|
56
|
+
r((i) => ({ ...i, searchTerm: e })), c(), l(e);
|
|
50
57
|
},
|
|
51
58
|
submitSearch: o
|
|
52
59
|
}
|
|
53
60
|
};
|
|
54
61
|
}
|
|
55
62
|
export {
|
|
56
|
-
|
|
63
|
+
R as useSearch
|
|
57
64
|
};
|
|
@@ -5,7 +5,7 @@ import { default as s } from "./SearchModal/components/SearchLink/SearchLink.js"
|
|
|
5
5
|
import { default as x } from "./SearchModal/components/SearchHeading/SearchHeading.js";
|
|
6
6
|
import { default as h } from "./SearchModal/components/SearchToggle/SearchToggle.js";
|
|
7
7
|
import "preact";
|
|
8
|
-
import "../../chunks/hooks.module.
|
|
8
|
+
import "../../chunks/hooks.module.BFfOesdf.js";
|
|
9
9
|
import { default as S } from "./SearchModal/components/SearchModal/SearchModal.js";
|
|
10
10
|
export {
|
|
11
11
|
m as Icon,
|
package/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { FunctionComponent } from 'preact';
|
|
2
2
|
import type { SearchLinkProps, SearchResultsProps, SearchWindowProps } from '../types/search.types';
|
|
3
|
+
import { useMemo } from 'preact/hooks';
|
|
3
4
|
import SearchHeading from './SearchHeading/SearchHeading';
|
|
4
5
|
import SearchLink from './SearchLink/SearchLink';
|
|
5
6
|
|
|
@@ -25,13 +26,17 @@ const SearchResults: FunctionComponent<SearchResultsProps> = ({
|
|
|
25
26
|
);
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
const renderedResults = useMemo(() => {
|
|
30
|
+
return results.map((result, i) => (
|
|
31
|
+
<li key={i} className="n-results-list-item">
|
|
32
|
+
<SearchLink {...result} />
|
|
33
|
+
</li>
|
|
34
|
+
));
|
|
35
|
+
}, [results]);
|
|
36
|
+
|
|
28
37
|
return (
|
|
29
38
|
<ul className="n-results-list" role="list">
|
|
30
|
-
{
|
|
31
|
-
<li key={idx} className="n-results-list-item">
|
|
32
|
-
<SearchLink {...result} />
|
|
33
|
-
</li>
|
|
34
|
-
))}
|
|
39
|
+
{renderedResults}
|
|
35
40
|
</ul>
|
|
36
41
|
);
|
|
37
42
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState } from 'preact/hooks';
|
|
1
|
+
import { useState, useRef } from 'preact/hooks';
|
|
2
2
|
import type { SearchState } from '../types/search.types';
|
|
3
3
|
import { useTimeout } from '../../../../utils/useTimeout';
|
|
4
4
|
import { getSiteIcon } from '../utils';
|
|
@@ -19,6 +19,7 @@ export function useSearch() {
|
|
|
19
19
|
results: [],
|
|
20
20
|
isLoading: false,
|
|
21
21
|
});
|
|
22
|
+
const cacheRef = useRef(new Map());
|
|
22
23
|
|
|
23
24
|
const { reset, run } = useTimeout((query: string) => {
|
|
24
25
|
if (query.length > 2 || query.length === 0) {
|
|
@@ -29,11 +30,20 @@ export function useSearch() {
|
|
|
29
30
|
const submitSearch = async (query: string) => {
|
|
30
31
|
if (!window?.pagefind) return;
|
|
31
32
|
|
|
32
|
-
setSearchState(prev => ({ ...prev, isLoading: true }));
|
|
33
33
|
|
|
34
|
+
setSearchState(prev => ({ ...prev, isLoading: true }));
|
|
35
|
+
|
|
36
|
+
if (cacheRef.current.has(query)) {
|
|
37
|
+
setSearchState(prev => ({
|
|
38
|
+
...prev,
|
|
39
|
+
results: cacheRef.current.get(query),
|
|
40
|
+
isLoading: false,
|
|
41
|
+
}));
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
34
44
|
const search = await window.pagefind.search(query);
|
|
35
45
|
const results = await Promise.all(
|
|
36
|
-
search.results.map(async (result: any) => {
|
|
46
|
+
search.results.slice(0, 15).map(async (result: any) => {
|
|
37
47
|
const data = await result.data();
|
|
38
48
|
return {
|
|
39
49
|
icon: getSiteIcon(data.meta?.content_type),
|