@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.
@@ -1,5 +1,5 @@
1
1
  import { Component as f, options as a, createElement as d, Fragment as h, toChildArray as v } from "preact";
2
- import "./hooks.module.ExpuRnbo.js";
2
+ import "./hooks.module.BFfOesdf.js";
3
3
  function C(e, t) {
4
4
  for (var r in t) e[r] = t[r];
5
5
  return e;
@@ -126,6 +126,7 @@ function W(_, t) {
126
126
  }
127
127
  export {
128
128
  I as A,
129
+ z as T,
129
130
  S as d,
130
131
  G as y
131
132
  };
@@ -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.BPxt-oTe.js";
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.ExpuRnbo.js";
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.ExpuRnbo.js";
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.BPxt-oTe.js";
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 a from "./SearchHeading/SearchHeading.js";
3
- import c from "./SearchLink/SearchLink.js";
4
- const t = ({
5
- searchLoading: s,
6
- searchTerm: l,
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
- }) => s ? /* @__PURE__ */ e(a, { children: [
9
- "Searching for ",
10
- /* @__PURE__ */ e("span", { className: "n-search-term", children: l }),
11
- " ..."
12
- ] }) : !r || r.length === 0 ? /* @__PURE__ */ e(a, { children: [
13
- "0 results for ",
14
- /* @__PURE__ */ e("span", { className: "n-search-term", children: l })
15
- ] }) : /* @__PURE__ */ e("ul", { className: "n-results-list", role: "list", children: r.slice(0, 15).map((i, n) => /* @__PURE__ */ e("li", { className: "n-results-list-item", children: /* @__PURE__ */ e(c, { ...i }) }, n)) });
16
- function m({
17
- searchLoading: s,
18
- searchTerm: l,
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: i
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(c, { ...{
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
- l ? /* @__PURE__ */ e(t, { searchLoading: s, searchTerm: l, results: r }) : i || null
36
+ n ? /* @__PURE__ */ e(h, { searchLoading: i, searchTerm: n, results: r }) : l || null
29
37
  ] }) });
30
38
  }
31
39
  export {
32
- m as default
40
+ N as default
33
41
  };
@@ -1,4 +1,4 @@
1
- import { y as a } from "../../../../chunks/hooks.module.ExpuRnbo.js";
1
+ import { y as a } from "../../../../chunks/hooks.module.BFfOesdf.js";
2
2
  function l(r, t, o) {
3
3
  a(() => {
4
4
  const c = (e) => {
@@ -1,36 +1,43 @@
1
- import { A as h, y as p, d as g } from "../../../../chunks/hooks.module.ExpuRnbo.js";
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 w(s, r) {
4
- const t = h(null), c = h("");
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: (e) => {
10
- c.current = e, t.current = setTimeout(
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 y() {
17
- const [s, r] = g({
16
+ function R() {
17
+ const [s, r] = w({
18
18
  searchTerm: "",
19
19
  results: [],
20
20
  isLoading: !1
21
- }), { reset: t, run: c } = w((e) => {
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
- const i = await window.pagefind.search(e), d = await Promise.all(
27
- i.results.map(async (n) => {
28
- var u, l, m;
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((u = a.meta) == null ? void 0 : u.content_type),
32
- content_type: (l = a.meta) == null ? void 0 : l.content_type,
33
- label: (m = a.meta) == null ? void 0 : m.title,
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: d,
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 })), t(), c(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
- y as useSearch
63
+ R as useSearch
57
64
  };
@@ -1,4 +1,4 @@
1
- import { y as d } from "../../../../chunks/hooks.module.ExpuRnbo.js";
1
+ import { y as d } from "../../../../chunks/hooks.module.BFfOesdf.js";
2
2
  function m(t, n, o) {
3
3
  d(() => {
4
4
  const r = (e) => {
@@ -1,4 +1,4 @@
1
- import { y as e } from "../../../../chunks/hooks.module.ExpuRnbo.js";
1
+ import { y as e } from "../../../../chunks/hooks.module.BFfOesdf.js";
2
2
  function t(a, o) {
3
3
  e(() => {
4
4
  if (typeof location > "u") return;
@@ -1,4 +1,4 @@
1
- import { y as c } from "../../../../chunks/hooks.module.ExpuRnbo.js";
1
+ import { y as c } from "../../../../chunks/hooks.module.BFfOesdf.js";
2
2
  function l(t) {
3
3
  c(() => {
4
4
  const r = document.querySelectorAll("[data-ntl-search-toggle]");
@@ -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.ExpuRnbo.js";
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,7 +1,7 @@
1
1
  {
2
2
  "name": "@netlify/spark-ui",
3
3
  "description": "Assets, design tokens, components, and utilities",
4
- "version": "0.0.23",
4
+ "version": "0.0.24",
5
5
  "type": "module",
6
6
  "main": "dist/components/preact/index.js",
7
7
  "types": "dist/components/preact/index.d.ts",
@@ -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
- {results.slice(0, 15).map((result, idx) => (
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),