@netlify/spark-ui 0.0.42-alpha.2 → 0.0.42
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/useTimeout.DOkYFG64.js +17 -0
- package/dist/components/preact/SearchModal/components/SearchInput.js +14 -11
- package/dist/components/preact/SearchModal/hooks/useSearch.js +26 -38
- package/package.json +1 -1
- package/packages/components/preact/SearchModal/components/SearchInput.tsx +8 -2
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { A as t, y as o } from "./hooks.module.CNV9mxng.js";
|
|
2
|
+
function f(u, n) {
|
|
3
|
+
const e = t(null), r = t("");
|
|
4
|
+
return o(() => () => {
|
|
5
|
+
e.current && clearTimeout(e.current);
|
|
6
|
+
}, []), { reset: () => {
|
|
7
|
+
e.current && clearTimeout(e.current);
|
|
8
|
+
}, run: (c) => {
|
|
9
|
+
r.current = c, e.current = setTimeout(
|
|
10
|
+
() => u(r.current),
|
|
11
|
+
n
|
|
12
|
+
);
|
|
13
|
+
} };
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
f as u
|
|
17
|
+
};
|
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
import { u as e } from "../../../../chunks/jsxRuntime.module.Bzuv3cXw.js";
|
|
2
|
-
import { d as
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
l(
|
|
2
|
+
import { d as h, y as u } from "../../../../chunks/hooks.module.CNV9mxng.js";
|
|
3
|
+
import { u as o } from "../../../../chunks/useTimeout.DOkYFG64.js";
|
|
4
|
+
import d from "../../Icon/index.js";
|
|
5
|
+
const I = (a) => {
|
|
6
|
+
const [n, l] = h(""), { reset: r, run: c } = o((t) => {
|
|
7
|
+
l(t), a.setSearchTerm(t);
|
|
8
|
+
}, 300), i = (t) => {
|
|
9
|
+
const s = t.target;
|
|
10
|
+
r(), c(s.value);
|
|
8
11
|
};
|
|
9
|
-
return
|
|
12
|
+
return u(() => {
|
|
10
13
|
a.initialValue && l(a.initialValue);
|
|
11
14
|
}, [a.initialValue, l]), /* @__PURE__ */ e("div", { class: "n-search-input-wrapper", children: [
|
|
12
15
|
/* @__PURE__ */ e("label", { class: "n-search-label", htmlFor: "search", children: [
|
|
13
16
|
/* @__PURE__ */ e("span", { class: "visually-hidden", children: "Search" }),
|
|
14
|
-
/* @__PURE__ */ e("div", { class: "n-search-icon", children: /* @__PURE__ */ e(
|
|
17
|
+
/* @__PURE__ */ e("div", { class: "n-search-icon", children: /* @__PURE__ */ e(d, { name: "search" }) })
|
|
15
18
|
] }),
|
|
16
19
|
/* @__PURE__ */ e(
|
|
17
20
|
"input",
|
|
18
21
|
{
|
|
19
22
|
class: "n-search-input",
|
|
20
23
|
type: "text",
|
|
21
|
-
value:
|
|
24
|
+
value: n,
|
|
22
25
|
placeholder: a.placeholder || "Search...",
|
|
23
|
-
onInput:
|
|
26
|
+
onInput: i
|
|
24
27
|
}
|
|
25
28
|
)
|
|
26
29
|
] });
|
|
27
30
|
};
|
|
28
31
|
export {
|
|
29
|
-
|
|
32
|
+
I as default
|
|
30
33
|
};
|
|
@@ -1,61 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
const e = i(null), a = i("");
|
|
4
|
-
return S(() => () => {
|
|
5
|
-
e.current && clearTimeout(e.current);
|
|
6
|
-
}, []), { reset: () => {
|
|
7
|
-
e.current && clearTimeout(e.current);
|
|
8
|
-
}, run: (m) => {
|
|
9
|
-
a.current = m, e.current = setTimeout(
|
|
10
|
-
() => u(a.current),
|
|
11
|
-
s
|
|
12
|
-
);
|
|
13
|
-
} };
|
|
14
|
-
}
|
|
1
|
+
import { d as g, A as w } from "../../../../chunks/hooks.module.CNV9mxng.js";
|
|
2
|
+
import { u as S } from "../../../../chunks/useTimeout.DOkYFG64.js";
|
|
15
3
|
function x() {
|
|
16
|
-
const [
|
|
4
|
+
const [l, r] = g({
|
|
17
5
|
searchTerm: "",
|
|
18
6
|
results: [],
|
|
19
7
|
isLoading: !1
|
|
20
|
-
}),
|
|
21
|
-
|
|
22
|
-
}, 150),
|
|
23
|
-
var
|
|
8
|
+
}), n = w(/* @__PURE__ */ new Map()), { reset: d, run: h } = S((e) => {
|
|
9
|
+
c(e);
|
|
10
|
+
}, 150), c = async (e) => {
|
|
11
|
+
var i;
|
|
24
12
|
if (!(window != null && window.pagefind)) return;
|
|
25
|
-
if (
|
|
26
|
-
|
|
27
|
-
...
|
|
28
|
-
results:
|
|
13
|
+
if (r((a) => ({ ...a, isLoading: !0 })), n.current.has(e)) {
|
|
14
|
+
r((a) => ({
|
|
15
|
+
...a,
|
|
16
|
+
results: n.current.get(e),
|
|
29
17
|
isLoading: !1
|
|
30
18
|
}));
|
|
31
19
|
return;
|
|
32
20
|
}
|
|
33
|
-
const
|
|
34
|
-
(
|
|
35
|
-
var
|
|
36
|
-
const
|
|
21
|
+
const t = await window.pagefind.debouncedSearch(e), m = (t == null ? void 0 : t.results) && await Promise.all(
|
|
22
|
+
(i = t == null ? void 0 : t.results) == null ? void 0 : i.slice(0, 15).map(async (a) => {
|
|
23
|
+
var o, u;
|
|
24
|
+
const s = await a.data(), f = (p) => p.replace("#", "");
|
|
37
25
|
return {
|
|
38
26
|
icon: "pageWithLines",
|
|
39
|
-
resource: (
|
|
40
|
-
label: (
|
|
41
|
-
url:
|
|
42
|
-
excerpt:
|
|
27
|
+
resource: (o = s.meta) == null ? void 0 : o.resource,
|
|
28
|
+
label: (u = s.meta) == null ? void 0 : u.title,
|
|
29
|
+
url: s.url,
|
|
30
|
+
excerpt: f(s.excerpt)
|
|
43
31
|
};
|
|
44
32
|
})
|
|
45
33
|
);
|
|
46
|
-
|
|
47
|
-
...
|
|
48
|
-
results:
|
|
34
|
+
r((a) => ({
|
|
35
|
+
...a,
|
|
36
|
+
results: m,
|
|
49
37
|
isLoading: !1
|
|
50
38
|
}));
|
|
51
39
|
};
|
|
52
40
|
return {
|
|
53
|
-
state:
|
|
41
|
+
state: l,
|
|
54
42
|
actions: {
|
|
55
|
-
setSearchTerm: (
|
|
56
|
-
|
|
43
|
+
setSearchTerm: (e) => {
|
|
44
|
+
r((t) => ({ ...t, searchTerm: e })), d(), h(e);
|
|
57
45
|
},
|
|
58
|
-
submitSearch:
|
|
46
|
+
submitSearch: c
|
|
59
47
|
}
|
|
60
48
|
};
|
|
61
49
|
}
|
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": "0.0.42
|
|
4
|
+
"version": "0.0.42",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/components/preact/index.js",
|
|
7
7
|
"types": "dist/components/preact/index.d.ts",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useState, useEffect } from 'preact/hooks';
|
|
2
|
+
import { useTimeout } from '../../../../utils/useTimeout';
|
|
2
3
|
import Icon from '../../Icon';
|
|
3
4
|
|
|
4
5
|
interface Props {
|
|
@@ -10,10 +11,15 @@ interface Props {
|
|
|
10
11
|
const SearchInput = (props: Props) => {
|
|
11
12
|
const [value, setValue] = useState<string>('');
|
|
12
13
|
|
|
14
|
+
const { reset, run } = useTimeout((query: string) => {
|
|
15
|
+
setValue(query);
|
|
16
|
+
props.setSearchTerm(query);
|
|
17
|
+
}, 300);
|
|
18
|
+
|
|
13
19
|
const handleInput = (e: InputEvent) => {
|
|
14
20
|
const target = e.target as HTMLInputElement;
|
|
15
|
-
|
|
16
|
-
|
|
21
|
+
reset()
|
|
22
|
+
run(target.value)
|
|
17
23
|
};
|
|
18
24
|
|
|
19
25
|
useEffect(() => {
|