@netlify/spark-ui 0.0.42-alpha.1 → 0.0.42-alpha.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.
@@ -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 i, y as s } from "../../../../chunks/hooks.module.CNV9mxng.js";
3
- import h from "../../Icon/index.js";
4
- const m = (a) => {
5
- const [t, l] = i(""), c = (r) => {
6
- const n = r.target;
7
- l(n.value), a.setSearchTerm(n.value);
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 s(() => {
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(h, { name: "search" }) })
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: t,
24
+ value: n,
22
25
  placeholder: a.placeholder || "Search...",
23
- onInput: c
26
+ onInput: i
24
27
  }
25
28
  )
26
29
  ] });
27
30
  };
28
31
  export {
29
- m as default
32
+ I as default
30
33
  };
@@ -1,61 +1,49 @@
1
- import { A as i, y as S, d as T } from "../../../../chunks/hooks.module.CNV9mxng.js";
2
- function L(o, n) {
3
- const e = i(null), s = i("");
4
- return S(() => () => {
5
- e.current && clearTimeout(e.current);
6
- }, []), { reset: () => {
7
- e.current && clearTimeout(e.current);
8
- }, run: (h) => {
9
- s.current = h, e.current = setTimeout(
10
- () => o(s.current),
11
- n
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 [o, n] = T({
4
+ const [l, r] = g({
17
5
  searchTerm: "",
18
6
  results: [],
19
7
  isLoading: !1
20
- }), e = i(/* @__PURE__ */ new Map()), { reset: s, run: l } = L((t) => {
21
- u(t);
22
- }, 150), u = async (t) => {
23
- var m;
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 (n((r) => ({ ...r, isLoading: !0 })), e.current.has(t)) {
26
- n((r) => ({
27
- ...r,
28
- results: e.current.get(t),
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 a = await window.pagefind.debouncedSearch(t), g = await Promise.all(
34
- (m = a == null ? void 0 : a.results) == null ? void 0 : m.slice(0, 15).map(async (r) => {
35
- var d, f;
36
- const c = await r.data(), p = (w) => w.replace("#", "");
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: (d = c.meta) == null ? void 0 : d.resource,
40
- label: (f = c.meta) == null ? void 0 : f.title,
41
- url: c.url,
42
- excerpt: p(c.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
- n((r) => ({
47
- ...r,
48
- results: g,
34
+ r((a) => ({
35
+ ...a,
36
+ results: m,
49
37
  isLoading: !1
50
38
  }));
51
39
  };
52
40
  return {
53
- state: o,
41
+ state: l,
54
42
  actions: {
55
- setSearchTerm: (t) => {
56
- n((a) => ({ ...a, searchTerm: t })), s(), l(t);
43
+ setSearchTerm: (e) => {
44
+ r((t) => ({ ...t, searchTerm: e })), d(), h(e);
57
45
  },
58
- submitSearch: u
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-alpha.1",
4
+ "version": "0.0.42-alpha.3",
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
- setValue(target.value);
16
- props.setSearchTerm(target.value);
21
+ reset()
22
+ run(target.value)
17
23
  };
18
24
 
19
25
  useEffect(() => {
@@ -38,7 +38,7 @@ export function useSearch() {
38
38
  return;
39
39
  }
40
40
  const search = await window.pagefind.debouncedSearch(query);
41
- const results = await Promise.all(
41
+ const results = search?.results && await Promise.all(
42
42
  search?.results?.slice(0, 15).map(async (result: any) => {
43
43
  const data = await result.data();
44
44
  const removeAnchorLink = (text: string) => text.replace("#", '')