@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.
@@ -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(u, s) {
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 [u, s] = T({
4
+ const [l, r] = g({
17
5
  searchTerm: "",
18
6
  results: [],
19
7
  isLoading: !1
20
- }), e = i(/* @__PURE__ */ new Map()), { reset: a, run: l } = L((t) => {
21
- o(t);
22
- }, 150), o = async (t) => {
23
- var d;
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 (s((n) => ({ ...n, isLoading: !0 })), e.current.has(t)) {
26
- s((n) => ({
27
- ...n,
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 r = await window.pagefind.debouncedSearch(t), g = (r == null ? void 0 : r.results) && await Promise.all(
34
- (d = r == null ? void 0 : r.results) == null ? void 0 : d.slice(0, 15).map(async (n) => {
35
- var f, h;
36
- const c = await n.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: (f = c.meta) == null ? void 0 : f.resource,
40
- label: (h = c.meta) == null ? void 0 : h.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
- s((n) => ({
47
- ...n,
48
- results: g,
34
+ r((a) => ({
35
+ ...a,
36
+ results: m,
49
37
  isLoading: !1
50
38
  }));
51
39
  };
52
40
  return {
53
- state: u,
41
+ state: l,
54
42
  actions: {
55
- setSearchTerm: (t) => {
56
- s((r) => ({ ...r, searchTerm: t })), a(), l(t);
43
+ setSearchTerm: (e) => {
44
+ r((t) => ({ ...t, searchTerm: e })), d(), h(e);
57
45
  },
58
- submitSearch: o
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.2",
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
- setValue(target.value);
16
- props.setSearchTerm(target.value);
21
+ reset()
22
+ run(target.value)
17
23
  };
18
24
 
19
25
  useEffect(() => {