@netlify/spark-ui 0.0.42-alpha.1 → 0.0.42-alpha.2

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.
@@ -1,61 +1,61 @@
1
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("");
2
+ function L(u, s) {
3
+ const e = i(null), a = i("");
4
4
  return S(() => () => {
5
5
  e.current && clearTimeout(e.current);
6
6
  }, []), { reset: () => {
7
7
  e.current && clearTimeout(e.current);
8
- }, run: (h) => {
9
- s.current = h, e.current = setTimeout(
10
- () => o(s.current),
11
- n
8
+ }, run: (m) => {
9
+ a.current = m, e.current = setTimeout(
10
+ () => u(a.current),
11
+ s
12
12
  );
13
13
  } };
14
14
  }
15
15
  function x() {
16
- const [o, n] = T({
16
+ const [u, s] = T({
17
17
  searchTerm: "",
18
18
  results: [],
19
19
  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;
20
+ }), e = i(/* @__PURE__ */ new Map()), { reset: a, run: l } = L((t) => {
21
+ o(t);
22
+ }, 150), o = async (t) => {
23
+ var d;
24
24
  if (!(window != null && window.pagefind)) return;
25
- if (n((r) => ({ ...r, isLoading: !0 })), e.current.has(t)) {
26
- n((r) => ({
27
- ...r,
25
+ if (s((n) => ({ ...n, isLoading: !0 })), e.current.has(t)) {
26
+ s((n) => ({
27
+ ...n,
28
28
  results: e.current.get(t),
29
29
  isLoading: !1
30
30
  }));
31
31
  return;
32
32
  }
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("#", "");
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("#", "");
37
37
  return {
38
38
  icon: "pageWithLines",
39
- resource: (d = c.meta) == null ? void 0 : d.resource,
40
- label: (f = c.meta) == null ? void 0 : f.title,
39
+ resource: (f = c.meta) == null ? void 0 : f.resource,
40
+ label: (h = c.meta) == null ? void 0 : h.title,
41
41
  url: c.url,
42
42
  excerpt: p(c.excerpt)
43
43
  };
44
44
  })
45
45
  );
46
- n((r) => ({
47
- ...r,
46
+ s((n) => ({
47
+ ...n,
48
48
  results: g,
49
49
  isLoading: !1
50
50
  }));
51
51
  };
52
52
  return {
53
- state: o,
53
+ state: u,
54
54
  actions: {
55
55
  setSearchTerm: (t) => {
56
- n((a) => ({ ...a, searchTerm: t })), s(), l(t);
56
+ s((r) => ({ ...r, searchTerm: t })), a(), l(t);
57
57
  },
58
- submitSearch: u
58
+ submitSearch: o
59
59
  }
60
60
  };
61
61
  }
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.2",
5
5
  "type": "module",
6
6
  "main": "dist/components/preact/index.js",
7
7
  "types": "dist/components/preact/index.d.ts",
@@ -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("#", '')