@netlify/spark-ui 1.13.3 → 1.14.1

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.
@@ -12,7 +12,7 @@ var ta = (e, a, t, i) => ({
12
12
  }
13
13
  });
14
14
  import { u as O } from "./jsxRuntime.module.Bzuv3cXw.js";
15
- import { A as oe, T as ot, q as W, y as ye, x as Fa, d as ze, h as Qn } from "./hooks.module.DGkdD5n9.js";
15
+ import { A as te, T as ot, q as W, y as ye, x as Fa, d as ze, h as Qn } from "./hooks.module.DGkdD5n9.js";
16
16
  import { _ as Hn, C as Bn, R as Vn } from "./compat.module.BNbXPLVY.js";
17
17
  import { createElement as Wn, createRef as Jn, Component as Kt, createContext as ma } from "preact";
18
18
  import { questions as Yn } from "../components/preact/AskNetlify/components/QuestionList/questions.js";
@@ -972,26 +972,26 @@ let Yi = class {
972
972
  return [];
973
973
  }
974
974
  };
975
- var te;
975
+ var ne;
976
976
  (function(e) {
977
977
  e.Memory = "memory", e.LocalStorage = "localstorage", e.SessionStorage = "sessionstorage", e.NoCache = "nocache";
978
- })(te || (te = {}));
978
+ })(ne || (ne = {}));
979
979
  var Zi = "1.3.2";
980
980
  const er = {
981
- [te.Memory]: () => new Yi().enclosedCache,
982
- [te.LocalStorage]: (e) => new Vi(e),
983
- [te.SessionStorage]: (e) => new Wi(e),
984
- [te.NoCache]: () => new Xi()
981
+ [ne.Memory]: () => new Yi().enclosedCache,
982
+ [ne.LocalStorage]: (e) => new Vi(e),
983
+ [ne.SessionStorage]: (e) => new Wi(e),
984
+ [ne.NoCache]: () => new Xi()
985
985
  }, ar = (e) => {
986
986
  switch (e) {
987
- case te.SessionStorage:
987
+ case ne.SessionStorage:
988
988
  try {
989
989
  window.sessionStorage.getItem("item");
990
990
  } catch {
991
991
  return !1;
992
992
  }
993
993
  return !0;
994
- case te.LocalStorage:
994
+ case ne.LocalStorage:
995
995
  try {
996
996
  window.localStorage.getItem("item");
997
997
  } catch {
@@ -1014,9 +1014,9 @@ class Qe {
1014
1014
  if (a != null && a.cache)
1015
1015
  i = a.cache;
1016
1016
  else {
1017
- if (this.cacheLocation = (a == null ? void 0 : a.cacheLocation) || te.SessionStorage, !ht(this.cacheLocation))
1017
+ if (this.cacheLocation = (a == null ? void 0 : a.cacheLocation) || ne.SessionStorage, !ht(this.cacheLocation))
1018
1018
  throw new Error(`Invalid cache location "${this.cacheLocation}"`);
1019
- ar(this.cacheLocation) || (this.cacheLocation = te.Memory), i = ht(this.cacheLocation)(a == null ? void 0 : a.cachePrefix);
1019
+ ar(this.cacheLocation) || (this.cacheLocation = ne.Memory), i = ht(this.cacheLocation)(a == null ? void 0 : a.cachePrefix);
1020
1020
  }
1021
1021
  if (a != null && a.cacheTimeInSeconds && a.cacheTimeInSeconds > Qi)
1022
1022
  throw new Error("Cache time cannot exceed 86400 seconds (24 hours)");
@@ -1367,7 +1367,7 @@ function xr(e) {
1367
1367
  return O(vr, { children: O(jr, F({}, a)) });
1368
1368
  }
1369
1369
  function jr(e) {
1370
- var a = this, t = e.children, i = e.forceRebuild, n = e.cache, r = e.cacheTimeInSeconds, o = e.cachePrefix, u = e.cacheLocation, c = e.customAgent, s = e.loadOptions, l = e.env, h = oe(), p = oe(), k = ot(function() {
1370
+ var a = this, t = e.children, i = e.forceRebuild, n = e.cache, r = e.cacheTimeInSeconds, o = e.cachePrefix, u = e.cacheLocation, c = e.customAgent, s = e.loadOptions, l = e.env, h = te(), p = te(), k = ot(function() {
1371
1371
  return {
1372
1372
  cache: n,
1373
1373
  cacheTimeInSeconds: r,
@@ -1924,7 +1924,7 @@ var L = Kr(), xe, Tt, Pn = (Tt = class {
1924
1924
  clearGcTimeout() {
1925
1925
  d(this, xe) && (clearTimeout(d(this, xe)), j(this, xe, void 0));
1926
1926
  }
1927
- }, xe = new WeakMap(), Tt), Te, De, B, je, U, Be, Ee, J, ne, Dt, $r = (Dt = class extends Pn {
1927
+ }, xe = new WeakMap(), Tt), Te, De, B, je, U, Be, Ee, J, ie, Dt, $r = (Dt = class extends Pn {
1928
1928
  constructor(a) {
1929
1929
  super();
1930
1930
  E(this, J);
@@ -1952,7 +1952,7 @@ var L = Kr(), xe, Tt, Pn = (Tt = class {
1952
1952
  }
1953
1953
  setData(a, t) {
1954
1954
  const i = Pr(this.state.data, a, this.options);
1955
- return D(this, J, ne).call(this, {
1955
+ return D(this, J, ie).call(this, {
1956
1956
  data: i,
1957
1957
  type: "success",
1958
1958
  dataUpdatedAt: t == null ? void 0 : t.updatedAt,
@@ -1960,7 +1960,7 @@ var L = Kr(), xe, Tt, Pn = (Tt = class {
1960
1960
  }), i;
1961
1961
  }
1962
1962
  setState(a, t) {
1963
- D(this, J, ne).call(this, { type: "setState", state: a, setStateOptions: t });
1963
+ D(this, J, ie).call(this, { type: "setState", state: a, setStateOptions: t });
1964
1964
  }
1965
1965
  cancel(a) {
1966
1966
  var i, n;
@@ -2014,7 +2014,7 @@ var L = Kr(), xe, Tt, Pn = (Tt = class {
2014
2014
  return this.observers.length;
2015
2015
  }
2016
2016
  invalidate() {
2017
- this.state.isInvalidated || D(this, J, ne).call(this, { type: "invalidate" });
2017
+ this.state.isInvalidated || D(this, J, ie).call(this, { type: "invalidate" });
2018
2018
  }
2019
2019
  fetch(a, t) {
2020
2020
  var s, l, h;
@@ -2061,10 +2061,10 @@ var L = Kr(), xe, Tt, Pn = (Tt = class {
2061
2061
  };
2062
2062
  return n(p), p;
2063
2063
  })();
2064
- (s = this.options.behavior) == null || s.onFetch(u, this), j(this, De, this.state), (this.state.fetchStatus === "idle" || this.state.fetchMeta !== ((l = u.fetchOptions) == null ? void 0 : l.meta)) && D(this, J, ne).call(this, { type: "fetch", meta: (h = u.fetchOptions) == null ? void 0 : h.meta });
2064
+ (s = this.options.behavior) == null || s.onFetch(u, this), j(this, De, this.state), (this.state.fetchStatus === "idle" || this.state.fetchMeta !== ((l = u.fetchOptions) == null ? void 0 : l.meta)) && D(this, J, ie).call(this, { type: "fetch", meta: (h = u.fetchOptions) == null ? void 0 : h.meta });
2065
2065
  const c = (p) => {
2066
2066
  var k, f, m, g;
2067
- _a(p) && p.silent || D(this, J, ne).call(this, {
2067
+ _a(p) && p.silent || D(this, J, ie).call(this, {
2068
2068
  type: "error",
2069
2069
  error: p
2070
2070
  }), _a(p) || ((f = (k = d(this, B).config).onError) == null || f.call(
@@ -2105,13 +2105,13 @@ var L = Kr(), xe, Tt, Pn = (Tt = class {
2105
2105
  },
2106
2106
  onError: c,
2107
2107
  onFail: (p, k) => {
2108
- D(this, J, ne).call(this, { type: "failed", failureCount: p, error: k });
2108
+ D(this, J, ie).call(this, { type: "failed", failureCount: p, error: k });
2109
2109
  },
2110
2110
  onPause: () => {
2111
- D(this, J, ne).call(this, { type: "pause" });
2111
+ D(this, J, ie).call(this, { type: "pause" });
2112
2112
  },
2113
2113
  onContinue: () => {
2114
- D(this, J, ne).call(this, { type: "continue" });
2114
+ D(this, J, ie).call(this, { type: "continue" });
2115
2115
  },
2116
2116
  retry: u.options.retry,
2117
2117
  retryDelay: u.options.retryDelay,
@@ -2119,7 +2119,7 @@ var L = Kr(), xe, Tt, Pn = (Tt = class {
2119
2119
  canRun: () => !0
2120
2120
  })), d(this, U).start();
2121
2121
  }
2122
- }, Te = new WeakMap(), De = new WeakMap(), B = new WeakMap(), je = new WeakMap(), U = new WeakMap(), Be = new WeakMap(), Ee = new WeakMap(), J = new WeakSet(), ne = function(a) {
2122
+ }, Te = new WeakMap(), De = new WeakMap(), B = new WeakMap(), je = new WeakMap(), U = new WeakMap(), Be = new WeakMap(), Ee = new WeakMap(), J = new WeakSet(), ie = function(a) {
2123
2123
  const t = (i) => {
2124
2124
  switch (a.type) {
2125
2125
  case "failed":
@@ -2489,13 +2489,13 @@ function qn() {
2489
2489
  submittedAt: 0
2490
2490
  };
2491
2491
  }
2492
- var ie, Y, Ve, Lt, Vr = (Lt = class extends Je {
2492
+ var re, Y, Ve, Lt, Vr = (Lt = class extends Je {
2493
2493
  constructor(a = {}) {
2494
2494
  super();
2495
- E(this, ie);
2495
+ E(this, re);
2496
2496
  E(this, Y);
2497
2497
  E(this, Ve);
2498
- this.config = a, j(this, ie, /* @__PURE__ */ new Set()), j(this, Y, /* @__PURE__ */ new Map()), j(this, Ve, 0);
2498
+ this.config = a, j(this, re, /* @__PURE__ */ new Set()), j(this, Y, /* @__PURE__ */ new Map()), j(this, Ve, 0);
2499
2499
  }
2500
2500
  build(a, t, i) {
2501
2501
  const n = new Br({
@@ -2507,7 +2507,7 @@ var ie, Y, Ve, Lt, Vr = (Lt = class extends Je {
2507
2507
  return this.add(n), n;
2508
2508
  }
2509
2509
  add(a) {
2510
- d(this, ie).add(a);
2510
+ d(this, re).add(a);
2511
2511
  const t = ra(a);
2512
2512
  if (typeof t == "string") {
2513
2513
  const i = d(this, Y).get(t);
@@ -2516,7 +2516,7 @@ var ie, Y, Ve, Lt, Vr = (Lt = class extends Je {
2516
2516
  this.notify({ type: "added", mutation: a });
2517
2517
  }
2518
2518
  remove(a) {
2519
- if (d(this, ie).delete(a)) {
2519
+ if (d(this, re).delete(a)) {
2520
2520
  const t = ra(a);
2521
2521
  if (typeof t == "string") {
2522
2522
  const i = d(this, Y).get(t);
@@ -2550,13 +2550,13 @@ var ie, Y, Ve, Lt, Vr = (Lt = class extends Je {
2550
2550
  }
2551
2551
  clear() {
2552
2552
  L.batch(() => {
2553
- d(this, ie).forEach((a) => {
2553
+ d(this, re).forEach((a) => {
2554
2554
  this.notify({ type: "removed", mutation: a });
2555
- }), d(this, ie).clear(), d(this, Y).clear();
2555
+ }), d(this, re).clear(), d(this, Y).clear();
2556
2556
  });
2557
2557
  }
2558
2558
  getAll() {
2559
- return Array.from(d(this, ie));
2559
+ return Array.from(d(this, re));
2560
2560
  }
2561
2561
  find(a) {
2562
2562
  const t = { exact: !0, ...a };
@@ -2582,7 +2582,7 @@ var ie, Y, Ve, Lt, Vr = (Lt = class extends Je {
2582
2582
  )
2583
2583
  );
2584
2584
  }
2585
- }, ie = new WeakMap(), Y = new WeakMap(), Ve = new WeakMap(), Lt);
2585
+ }, re = new WeakMap(), Y = new WeakMap(), Ve = new WeakMap(), Lt);
2586
2586
  function ra(e) {
2587
2587
  var a;
2588
2588
  return (a = e.options.scope) == null ? void 0 : a.id;
@@ -2875,14 +2875,14 @@ var A, me, pe, Ne, Fe, ge, Le, Me, Mt, Jr = (Mt = class {
2875
2875
  clear() {
2876
2876
  d(this, A).clear(), d(this, me).clear();
2877
2877
  }
2878
- }, A = new WeakMap(), me = new WeakMap(), pe = new WeakMap(), Ne = new WeakMap(), Fe = new WeakMap(), ge = new WeakMap(), Le = new WeakMap(), Me = new WeakMap(), Mt), fe, ke, G, re, se, ua, Da, Ut, Yr = (Ut = class extends Je {
2878
+ }, A = new WeakMap(), me = new WeakMap(), pe = new WeakMap(), Ne = new WeakMap(), Fe = new WeakMap(), ge = new WeakMap(), Le = new WeakMap(), Me = new WeakMap(), Mt), fe, ke, G, oe, se, ua, Da, Ut, Yr = (Ut = class extends Je {
2879
2879
  constructor(a, t) {
2880
2880
  super();
2881
2881
  E(this, se);
2882
2882
  E(this, fe);
2883
2883
  E(this, ke);
2884
2884
  E(this, G);
2885
- E(this, re);
2885
+ E(this, oe);
2886
2886
  j(this, fe, a), this.setOptions(t), this.bindMethods(), D(this, se, ua).call(this);
2887
2887
  }
2888
2888
  bindMethods() {
@@ -2913,9 +2913,9 @@ var A, me, pe, Ne, Fe, ge, Le, Me, Mt, Jr = (Mt = class {
2913
2913
  }
2914
2914
  mutate(a, t) {
2915
2915
  var i;
2916
- return j(this, re, t), (i = d(this, G)) == null || i.removeObserver(this), j(this, G, d(this, fe).getMutationCache().build(d(this, fe), this.options)), d(this, G).addObserver(this), d(this, G).execute(a);
2916
+ return j(this, oe, t), (i = d(this, G)) == null || i.removeObserver(this), j(this, G, d(this, fe).getMutationCache().build(d(this, fe), this.options)), d(this, G).addObserver(this), d(this, G).execute(a);
2917
2917
  }
2918
- }, fe = new WeakMap(), ke = new WeakMap(), G = new WeakMap(), re = new WeakMap(), se = new WeakSet(), ua = function() {
2918
+ }, fe = new WeakMap(), ke = new WeakMap(), G = new WeakMap(), oe = new WeakMap(), se = new WeakSet(), ua = function() {
2919
2919
  var t;
2920
2920
  const a = ((t = d(this, G)) == null ? void 0 : t.state) ?? qn();
2921
2921
  j(this, ke, {
@@ -2930,9 +2930,9 @@ var A, me, pe, Ne, Fe, ge, Le, Me, Mt, Jr = (Mt = class {
2930
2930
  }, Da = function(a) {
2931
2931
  L.batch(() => {
2932
2932
  var t, i, n, r, o, u, c, s;
2933
- if (d(this, re) && this.hasListeners()) {
2933
+ if (d(this, oe) && this.hasListeners()) {
2934
2934
  const l = d(this, ke).variables, h = d(this, ke).context;
2935
- (a == null ? void 0 : a.type) === "success" ? ((i = (t = d(this, re)).onSuccess) == null || i.call(t, a.data, l, h), (r = (n = d(this, re)).onSettled) == null || r.call(n, a.data, null, l, h)) : (a == null ? void 0 : a.type) === "error" && ((u = (o = d(this, re)).onError) == null || u.call(o, a.error, l, h), (s = (c = d(this, re)).onSettled) == null || s.call(
2935
+ (a == null ? void 0 : a.type) === "success" ? ((i = (t = d(this, oe)).onSuccess) == null || i.call(t, a.data, l, h), (r = (n = d(this, oe)).onSettled) == null || r.call(n, a.data, null, l, h)) : (a == null ? void 0 : a.type) === "error" && ((u = (o = d(this, oe)).onError) == null || u.call(o, a.error, l, h), (s = (c = d(this, oe)).onSettled) == null || s.call(
2936
2936
  c,
2937
2937
  void 0,
2938
2938
  a.error,
@@ -3355,7 +3355,7 @@ var Ct = "kapa-recaptcha-script", wo = ({ siteKey: e, config: a, onLoad: t }) =>
3355
3355
  }
3356
3356
  }, [n, t]), null;
3357
3357
  }, xo = wo, jo = "565487b2-a67c-4aac-bb92-3fb64732c7b8", St = "6Lck4YwlAAAAAEIE1hR--varWp0qu9F-8-emQn2v", Fn = ma(void 0), Eo = ({ children: e, provider: a, hasConsent: t }) => {
3358
- const i = oe(null), n = oe(null), [r, o] = ze(!1), u = W(
3358
+ const i = te(null), n = te(null), [r, o] = ze(!1), u = W(
3359
3359
  async (s) => {
3360
3360
  var l;
3361
3361
  if (!r)
@@ -3913,7 +3913,7 @@ var Lo = "MHIUVE6Y4VV6H5lpgMyI", $n = ma(void 0), At = ({
3913
3913
  callbacks: i,
3914
3914
  apiService: n = new zo(_o)
3915
3915
  }) => {
3916
- const o = oe(n).current, u = {
3916
+ const o = te(n).current, u = {
3917
3917
  isGenerating: !1,
3918
3918
  isPreparing: !1,
3919
3919
  threadId: null,
@@ -3921,7 +3921,7 @@ var Lo = "MHIUVE6Y4VV6H5lpgMyI", $n = ma(void 0), At = ({
3921
3921
  error: null
3922
3922
  }, [c, s] = Qn(Fo, u), { executeCaptcha: l } = Ro(), { buildIdentifiers: h } = Ao({
3923
3923
  mode: t
3924
- }), p = oe({
3924
+ }), p = te({
3925
3925
  onRelevantSources: (b) => s({ type: "SET_RELEVANT_SOURCES", sources: b }),
3926
3926
  onPartialAnswer: (b) => s({ type: "SET_PARTIAL_ANSWER", answer: b }),
3927
3927
  onError: (b) => {
@@ -4128,36 +4128,42 @@ function Uo() {
4128
4128
  threadId: a.threadId
4129
4129
  };
4130
4130
  }
4131
- function is({ setModalState: e, initialQuery: a }) {
4132
- const [t, i] = ze(""), [n, r] = ze(!1), o = oe(null), u = oe(null), c = oe(null), { conversation: s, submitQuery: l, isGeneratingAnswer: h, isPreparingAnswer: p, stopGeneration: k } = Uo(), f = (m) => {
4133
- m.preventDefault();
4134
- const g = m.target, y = g == null ? void 0 : g.getAttribute("data-question-id"), b = y ? Yn[y] : t;
4135
- b.trim() && l(b.trim()), y || i(""), r(!0);
4131
+ function is({ setModalState: e, searchQuery: a, urlParamQuery: t }) {
4132
+ const [i, n] = ze(""), [r, o] = ze(!1), u = te(null), c = te(null), s = te(null), l = te(null), { conversation: h, submitQuery: p, isGeneratingAnswer: k, isPreparingAnswer: f, stopGeneration: m } = Uo(), g = (y) => {
4133
+ y.preventDefault();
4134
+ const b = y.target, v = b == null ? void 0 : b.getAttribute("data-question-id"), w = v ? Yn[v] : i;
4135
+ w.trim() && p(w.trim()), v || n(""), o(!0);
4136
4136
  };
4137
4137
  return ye(() => {
4138
- n && c.current && (c.current.scrollIntoView({ behavior: "smooth" }), r(!1));
4139
- }, [n]), ye(() => {
4140
- a && (l(a.trim()), r(!0));
4141
- }, [a]), /* @__PURE__ */ O("div", { className: "n-ask-chat-container", children: [
4138
+ r && l.current && (l.current.scrollIntoView({ behavior: "smooth" }), o(!1));
4139
+ }, [r]), ye(() => {
4140
+ var b;
4141
+ const y = (t ?? a ?? "").trim();
4142
+ t && n(y), a && p(y), (b = s == null ? void 0 : s.current) == null || b.focus(), o(!0);
4143
+ }, [n, o, p, n, t, a]), /* @__PURE__ */ O("div", { className: "n-ask-chat-container", children: [
4142
4144
  /* @__PURE__ */ O(Zn, { onClick: () => e == null ? void 0 : e({ current: "search" }) }),
4143
- /* @__PURE__ */ O("div", { ref: o, className: "n-ask-conversation n-search-window", children: s.length ? /* @__PURE__ */ O(
4144
- ei,
4145
- {
4146
- isPreparingAnswer: p,
4147
- conversation: s,
4148
- lastMessageRef: c
4149
- }
4150
- ) : /* @__PURE__ */ O(Xn, { onClick: f, menuRef: u }) }),
4151
- /* @__PURE__ */ O("form", { onSubmit: f, className: "n-ask-form n-search-input-wrapper", children: [
4145
+ /* @__PURE__ */ O("div", { ref: u, className: "n-ask-conversation n-search-window", children: [
4146
+ !h.length && !t && !a && /* @__PURE__ */ O(Xn, { onClick: g, menuRef: c }),
4147
+ h.length > 0 && /* @__PURE__ */ O(
4148
+ ei,
4149
+ {
4150
+ isPreparingAnswer: f,
4151
+ conversation: h,
4152
+ lastMessageRef: l
4153
+ }
4154
+ )
4155
+ ] }),
4156
+ /* @__PURE__ */ O("form", { onSubmit: g, className: "n-ask-form n-search-input-wrapper", children: [
4152
4157
  /* @__PURE__ */ O(
4153
4158
  "input",
4154
4159
  {
4160
+ ref: s,
4155
4161
  className: "n-ask-input n-search-input",
4156
4162
  type: "text",
4157
- value: t,
4158
- onInput: (m) => i(m.currentTarget.value),
4163
+ value: i,
4164
+ onInput: (y) => n(y.currentTarget.value),
4159
4165
  placeholder: "Ask a question...",
4160
- disabled: p || h
4166
+ disabled: f || k
4161
4167
  }
4162
4168
  ),
4163
4169
  /* @__PURE__ */ O(
@@ -4172,12 +4178,12 @@ function is({ setModalState: e, initialQuery: a }) {
4172
4178
  children: "protected by reCAPTCHA"
4173
4179
  }
4174
4180
  ),
4175
- h ? /* @__PURE__ */ O(
4181
+ k ? /* @__PURE__ */ O(
4176
4182
  "button",
4177
4183
  {
4178
4184
  type: "button",
4179
4185
  className: "n-ask-form-submit",
4180
- onClick: k,
4186
+ onClick: m,
4181
4187
  "aria-label": "Stop generation",
4182
4188
  children: /* @__PURE__ */ O("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", fill: "var(--neutral-100)", children: /* @__PURE__ */ O("rect", { x: "0", y: "0", width: "16", height: "16" }) })
4183
4189
  }
@@ -4186,7 +4192,7 @@ function is({ setModalState: e, initialQuery: a }) {
4186
4192
  {
4187
4193
  type: "submit",
4188
4194
  className: "n-ask-form-submit",
4189
- disabled: !t.trim() || p,
4195
+ disabled: !i.trim() || f,
4190
4196
  "aria-label": "Send message",
4191
4197
  children: /* @__PURE__ */ O("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 448 512", fill: "var(--neutral-100)", children: /* @__PURE__ */ O("path", { d: "M438.6 278.6c12.5-12.5 12.5-32.8 0-45.3l-160-160c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L338.8 224 32 224c-17.7 0-32 14.3-32 32s14.3 32 32 32l306.7 0L233.4 393.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0l160-160z" }) })
4192
4198
  }
@@ -2,7 +2,8 @@ interface Props {
2
2
  setModalState?: (e: {
3
3
  current: string;
4
4
  }) => void;
5
- initialQuery?: string;
5
+ searchQuery?: string;
6
+ urlParamQuery?: string;
6
7
  }
7
- export default function AskNetlify({ setModalState, initialQuery }: Props): import("preact").JSX.Element;
8
+ export default function AskNetlify({ setModalState, searchQuery, urlParamQuery }: Props): import("preact").JSX.Element;
8
9
  export {};
@@ -1,6 +1,6 @@
1
1
  import "../../../chunks/jsxRuntime.module.Bzuv3cXw.js";
2
2
  import "../../../chunks/hooks.module.DGkdD5n9.js";
3
- import { A as d } from "../../../chunks/AskNetlify.CNYCiNSp.js";
3
+ import { A as d } from "../../../chunks/AskNetlify.WwftmboN.js";
4
4
  import "./components/QuestionList/questions.js";
5
5
  import "./components/QuestionList/QuestionList.js";
6
6
  import "./components/BackButton.js";
@@ -1,83 +1,90 @@
1
1
  import { u as e } from "../../../../../chunks/jsxRuntime.module.Bzuv3cXw.js";
2
- import { A as g, y as h, d as k } from "../../../../../chunks/hooks.module.DGkdD5n9.js";
3
- import { A as w, K as b } from "../../../../../chunks/AskNetlify.CNYCiNSp.js";
4
- import K from "../../../Modal/Modal.js";
5
- import d from "../../../KeyboardKey/KeyboardKey.js";
6
- import L from "../SearchWindow.js";
7
- import M from "../SearchInput.js";
8
- import O from "../AskNetlifyLink.js";
2
+ import { A as g, y as f, d } from "../../../../../chunks/hooks.module.DGkdD5n9.js";
3
+ import { A as K, K as L } from "../../../../../chunks/AskNetlify.WwftmboN.js";
4
+ import P from "../../../Modal/Modal.js";
5
+ import h from "../../../KeyboardKey/KeyboardKey.js";
6
+ import M from "../SearchWindow.js";
7
+ import O from "../SearchInput.js";
8
+ import Q from "../AskNetlifyLink.js";
9
9
  import { useSearch as C } from "../../hooks/useSearch.js";
10
10
  import { useSearchAnalytics as E } from "../../hooks/useSearchAnalytics.js";
11
- import { useKeyboardNav as Q } from "../../hooks/useKeyboardNav.js";
12
- import { useSearchHotkeys as P } from "../../hooks/useSearchHotkeys.js";
13
- import { useSearchParams as R } from "../../hooks/useSearchParams.js";
14
- import { useSearchToggles as q } from "../../hooks/useSearchToggles.js";
15
- import { useAskAnalytics as x } from "../../../AskNetlify/hooks/useAskAnalytics.js";
11
+ import { useKeyboardNav as R } from "../../hooks/useKeyboardNav.js";
12
+ import { useSearchHotkeys as q } from "../../hooks/useSearchHotkeys.js";
13
+ import { useSearchParams as x } from "../../hooks/useSearchParams.js";
14
+ import { useSearchToggles as D } from "../../hooks/useSearchToggles.js";
15
+ import { useAskAnalytics as F } from "../../../AskNetlify/hooks/useAskAnalytics.js";
16
16
  import { Fragment as N } from "preact";
17
- import '../../../../../assets/SearchModal.css';function D(t) {
17
+ import '../../../../../assets/SearchModal.css';function G(a) {
18
18
  const n = g(null);
19
- return h(() => {
20
- function o(m) {
21
- n.current && !n.current.contains(m.target) && t();
19
+ return f(() => {
20
+ function s(m) {
21
+ n.current && !n.current.contains(m.target) && a();
22
22
  }
23
- return document.addEventListener("mousedown", o), () => {
24
- document.removeEventListener("mousedown", o);
23
+ return document.addEventListener("mousedown", s), () => {
24
+ document.removeEventListener("mousedown", s);
25
25
  };
26
- }, [t]), n;
26
+ }, [a]), n;
27
27
  }
28
- function re(t = { className: "", children: void 0, debug: !1, kapaIntegrationId: void 0 }) {
29
- const { children: n, className: o, debug: m, ...T } = t, [s, c] = k({ current: "search" }), [i, f] = k(!1), l = () => f(!0), u = () => f(!1), a = g(null), v = D(u), { state: r, actions: p } = C();
30
- q(l, c), R(p.setSearchTerm, l), P(i, l, u), Q(a, i, u), E(r, m);
31
- const { handleNewQuery: A, handleAnswer: I } = x();
32
- return h(() => {
33
- a.current && (i ? a.current.showModal() : a.current.close());
34
- }, [i]), h(() => {
35
- var y;
36
- const S = (y = a.current) == null ? void 0 : y.querySelector("input");
37
- S && S.focus();
38
- }, [s.current]), /* @__PURE__ */ e(
39
- b,
28
+ function te(a = { className: "", children: void 0, debug: !1, kapaIntegrationId: void 0 }) {
29
+ const { children: n, className: s, debug: m, ...T } = a, [c, o] = d({ current: "search" }), [i, p] = d(!1), [v, A] = d(""), l = () => p(!0), u = () => p(!1), t = g(null), I = G(u), { state: r, actions: S } = C();
30
+ D(l, o), x(l, S.setSearchTerm, A, o), q(i, l, u), R(t, i, u), E(r, m);
31
+ const { handleNewQuery: w, handleAnswer: b } = F();
32
+ return f(() => {
33
+ t.current && (i ? t.current.showModal() : t.current.close());
34
+ }, [i]), f(() => {
35
+ var k;
36
+ const y = (k = t.current) == null ? void 0 : k.querySelector("input");
37
+ y && y.focus();
38
+ }, [c.current]), /* @__PURE__ */ e(
39
+ L,
40
40
  {
41
- integrationId: t.kapaIntegrationId || "",
41
+ integrationId: a.kapaIntegrationId || "",
42
42
  callbacks: {
43
43
  askAI: {
44
- onQuerySubmit: A,
45
- onAnswerGenerationCompleted: I
44
+ onQuerySubmit: w,
45
+ onAnswerGenerationCompleted: b
46
46
  }
47
47
  },
48
48
  children: /* @__PURE__ */ e(
49
- K,
49
+ P,
50
50
  {
51
- ref: a,
52
- className: `n-search-modal ${o || ""}`,
53
- "data-state": s.current,
51
+ ref: t,
52
+ className: `n-search-modal ${s || ""}`,
53
+ "data-state": c.current,
54
54
  ...T,
55
- children: /* @__PURE__ */ e("div", { ref: v, className: "n-search-container", children: [
56
- s.current === "ask" && /* @__PURE__ */ e(w, { setModalState: c, initialQuery: r.searchTerm }),
57
- s.current === "search" && /* @__PURE__ */ e(N, { children: [
58
- /* @__PURE__ */ e(M, { setSearchTerm: p.setSearchTerm, initialValue: r.searchTerm }),
55
+ children: /* @__PURE__ */ e("div", { ref: I, className: "n-search-container", children: [
56
+ c.current === "ask" && /* @__PURE__ */ e(
57
+ K,
58
+ {
59
+ setModalState: o,
60
+ searchQuery: r.searchTerm,
61
+ urlParamQuery: v
62
+ }
63
+ ),
64
+ c.current === "search" && /* @__PURE__ */ e(N, { children: [
65
+ /* @__PURE__ */ e(O, { setSearchTerm: S.setSearchTerm, initialValue: r.searchTerm }),
59
66
  /* @__PURE__ */ e(
60
- L,
67
+ M,
61
68
  {
62
- setModalState: c,
69
+ setModalState: o,
63
70
  searchLoading: r.isLoading,
64
71
  searchTerm: r.searchTerm,
65
72
  results: r.results,
66
73
  children: /* @__PURE__ */ e(N, { children: [
67
- t.kapaIntegrationId && /* @__PURE__ */ e(O, { searchTerm: r.searchTerm, setModalState: c }),
74
+ a.kapaIntegrationId && /* @__PURE__ */ e(Q, { searchTerm: r.searchTerm, setModalState: o }),
68
75
  n
69
76
  ] })
70
77
  }
71
78
  ),
72
79
  /* @__PURE__ */ e("div", { className: "n-search-footer", children: [
73
80
  /* @__PURE__ */ e("p", { className: "n-search-footer-tip", children: [
74
- /* @__PURE__ */ e(d, { keyNames: ["Esc"] }),
81
+ /* @__PURE__ */ e(h, { keyNames: ["Esc"] }),
75
82
  "to close"
76
83
  ] }),
77
84
  /* @__PURE__ */ e("p", { className: "n-search-footer-tip", children: [
78
- /* @__PURE__ */ e(d, { keyNames: ["Tab"] }),
85
+ /* @__PURE__ */ e(h, { keyNames: ["Tab"] }),
79
86
  /* @__PURE__ */ e("span", { children: "or" }),
80
- /* @__PURE__ */ e(d, { keyNames: ["↑", "↓"] }),
87
+ /* @__PURE__ */ e(h, { keyNames: ["↑", "↓"] }),
81
88
  "to navigate"
82
89
  ] })
83
90
  ] })
@@ -89,5 +96,5 @@ function re(t = { className: "", children: void 0, debug: !1, kapaIntegrationId:
89
96
  );
90
97
  }
91
98
  export {
92
- re as default
99
+ te as default
93
100
  };
@@ -1,11 +1,20 @@
1
1
  /**
2
- * Custom hook that checks the current URL for a `search` query parameter
3
- * and, if found, updates the search term and opens the search interface.
2
+ * Custom hook that checks the current URL for query parameters and updates
3
+ * search state or modal state accordingly:
4
4
  *
5
- * Useful for enabling deep linking to a search view with a pre-filled term,
6
- * such as when sharing URLs like `?search=netlify`.
5
+ * - If `?ask` is present (optionally with `?msg` or `?message`), it opens the modal and
6
+ * optionally pre-fills the search term.
7
+ * - If only `?msg` or `?message` is present, it behaves similarly, opening the modal
8
+ * and pre-filling the search term.
9
+ * - If only `?search` is present, it pre-fills the search input and opens the search view.
10
+ *
11
+ * The hook also waits for `window.pagefind` to load before evaluating parameters,
12
+ * ensuring deep linking doesn't interfere with pagefind initialization.
7
13
  *
8
- * @param setSearchTerm - Function to update the search input state.
9
14
  * @param onOpen - Function to trigger opening of the search interface (e.g., modal or drawer).
15
+ * @param setSearchTerm - Function to update the search input state.
16
+ * @param setModalState - (Optional) Function to set modal state, useful for distinguishing modal views.
10
17
  */
11
- export declare function useSearchParams(setSearchTerm: (term: string) => void, onOpen: () => void): void;
18
+ export declare function useSearchParams(onOpen: () => void, setSearchTerm: (term: string) => void, setUrlParamTerm: (term: string) => void, setModalState?: (e: {
19
+ current: string;
20
+ }) => void): void;
@@ -1,18 +1,24 @@
1
- import { d as c, y as n } from "../../../../chunks/hooks.module.DGkdD5n9.js";
2
- function d(t, o) {
3
- const [a, i] = c(!1);
4
- n(() => {
5
- let e;
6
- const r = () => {
7
- window.pagefind && (i(!0), e && clearInterval(e));
1
+ import { d as h, y as t } from "../../../../chunks/hooks.module.DGkdD5n9.js";
2
+ function l(r, a, c, s) {
3
+ const [i, d] = h(!1);
4
+ t(() => {
5
+ let n;
6
+ const e = () => {
7
+ window.pagefind && (d(!0), n && clearInterval(n));
8
8
  };
9
- return r(), e = setInterval(r, 100), () => clearInterval(e);
10
- }, []), n(() => {
11
- if (typeof location > "u" || a) return;
12
- const e = (location == null ? void 0 : location.search) && new URLSearchParams(location.search).get("search");
13
- e && (t(e), o());
14
- }, [a]);
9
+ return e(), n = setInterval(e, 100), () => clearInterval(n);
10
+ }, []), t(() => {
11
+ if (typeof location > "u" || i) return;
12
+ const n = new URLSearchParams(location.search), e = n.has("ask"), f = n.get("msg") || n.get("message"), o = n.get("search"), u = (g) => {
13
+ g && c(g), s == null || s({ current: "ask" }), r();
14
+ };
15
+ if (e || f) {
16
+ u(f);
17
+ return;
18
+ }
19
+ o && (a(o), r());
20
+ }, [i, r, s, a, c]);
15
21
  }
16
22
  export {
17
- d as useSearchParams
23
+ l as useSearchParams
18
24
  };
@@ -4,7 +4,7 @@ import { default as m } from "./Icon/index.js";
4
4
  import { default as s } from "./SearchModal/components/SearchLink/SearchLink.js";
5
5
  import { default as u } from "./SearchModal/components/SearchHeading/SearchHeading.js";
6
6
  import { default as i } from "./SearchModal/components/SearchToggle/SearchToggle.js";
7
- import { A as S } from "../../chunks/AskNetlify.CNYCiNSp.js";
7
+ import { A as S } from "../../chunks/AskNetlify.WwftmboN.js";
8
8
  import "preact";
9
9
  import "../../chunks/hooks.module.DGkdD5n9.js";
10
10
  import { default as n } from "./SearchModal/components/SearchModal/SearchModal.js";
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": "1.13.3",
4
+ "version": "1.14.1",
5
5
  "type": "module",
6
6
  "main": "dist/components/preact/index.js",
7
7
  "types": "dist/components/preact/index.d.ts",
@@ -11,14 +11,16 @@ import './AskNetlify.css';
11
11
 
12
12
  interface Props {
13
13
  setModalState?: (e: { current: string }) => void;
14
- initialQuery?: string;
14
+ searchQuery?: string;
15
+ urlParamQuery?: string;
15
16
  }
16
17
 
17
- export default function AskNetlify({ setModalState, initialQuery }: Props) {
18
+ export default function AskNetlify({ setModalState, searchQuery, urlParamQuery }: Props) {
18
19
  const [message, setMessage] = useState('');
19
20
  const [newMessageReady, setNewMessageReady] = useState(false);
20
21
  const chatRef = useRef<HTMLDivElement>(null);
21
22
  const menuRef = useRef<HTMLUListElement>(null);
23
+ const inputRef = useRef<HTMLInputElement>(null);
22
24
  const lastMessageRef = useRef<HTMLDivElement | null>(null);
23
25
 
24
26
  const { conversation, submitQuery, isGeneratingAnswer, isPreparingAnswer, stopGeneration } =
@@ -49,20 +51,38 @@ export default function AskNetlify({ setModalState, initialQuery }: Props) {
49
51
  }
50
52
  }, [newMessageReady]);
51
53
 
54
+ /**
55
+ * Populates and handles the input when a query is present.
56
+ *
57
+ * - If `urlParamQuery` exists, pre-fills the input and waits for user action.
58
+ * - If `searchQuery` exists, auto-submits the query.
59
+ *
60
+ * Focuses the input and marks the message as ready in both cases.
61
+ */
52
62
  useEffect(() => {
53
- if (initialQuery) {
54
- submitQuery(initialQuery.trim());
55
- setNewMessageReady(true);
63
+ const trimmedQuery = (urlParamQuery ?? searchQuery ?? '').trim();
64
+
65
+ if (urlParamQuery) {
66
+ setMessage(trimmedQuery);
56
67
  }
57
- }, [initialQuery]);
68
+
69
+ if (searchQuery) {
70
+ submitQuery(trimmedQuery);
71
+ }
72
+
73
+ inputRef?.current?.focus();
74
+ setNewMessageReady(true);
75
+ }, [setMessage, setNewMessageReady, submitQuery, setMessage, urlParamQuery, searchQuery]);
58
76
 
59
77
  return (
60
78
  <div className="n-ask-chat-container">
61
79
  <BackButton onClick={() => setModalState?.({ current: 'search' })} />
62
80
  <div ref={chatRef} className="n-ask-conversation n-search-window">
63
- {!conversation.length ? (
81
+ {!conversation.length && !urlParamQuery && !searchQuery && (
64
82
  <QuestionList onClick={handleSubmit} menuRef={menuRef} />
65
- ) : (
83
+ )}
84
+
85
+ {conversation.length > 0 && (
66
86
  <ChatMessages
67
87
  isPreparingAnswer={isPreparingAnswer}
68
88
  conversation={conversation}
@@ -73,6 +93,7 @@ export default function AskNetlify({ setModalState, initialQuery }: Props) {
73
93
 
74
94
  <form onSubmit={handleSubmit} className="n-ask-form n-search-input-wrapper">
75
95
  <input
96
+ ref={inputRef}
76
97
  className="n-ask-input n-search-input"
77
98
  type="text"
78
99
  value={message}
@@ -1,5 +1,5 @@
1
1
  import { type ComponentChildren } from 'preact';
2
- import { useState, useEffect, useRef } from 'preact/hooks';
2
+ import { useState, useEffect, useRef, useMemo } from 'preact/hooks';
3
3
 
4
4
  import { KapaProvider } from '@kapaai/react-sdk';
5
5
 
@@ -37,6 +37,7 @@ function SearchModal(
37
37
 
38
38
  const [modalState, setModalState] = useState({ current: 'search' });
39
39
  const [searchOpen, setSearchOpen] = useState(false);
40
+ const [urlParamTerm, setUrlParamTerm] = useState('');
40
41
  const openSearch = () => setSearchOpen(true);
41
42
  const closeSearch = () => setSearchOpen(false);
42
43
 
@@ -45,7 +46,7 @@ function SearchModal(
45
46
 
46
47
  const { state, actions } = useSearch();
47
48
  useSearchToggles(openSearch, setModalState);
48
- useSearchParams(actions.setSearchTerm, openSearch);
49
+ useSearchParams(openSearch, actions.setSearchTerm, setUrlParamTerm, setModalState);
49
50
  useSearchHotkeys(searchOpen, openSearch, closeSearch);
50
51
  useKeyboardNav(modalRef, searchOpen, closeSearch);
51
52
  useSearchAnalytics(state, debug);
@@ -79,7 +80,11 @@ function SearchModal(
79
80
  >
80
81
  <div ref={containerRef} className="n-search-container">
81
82
  {modalState.current === 'ask' && (
82
- <AskNetlify setModalState={setModalState} initialQuery={state.searchTerm} />
83
+ <AskNetlify
84
+ setModalState={setModalState}
85
+ searchQuery={state.searchTerm}
86
+ urlParamQuery={urlParamTerm}
87
+ />
83
88
  )}
84
89
  {modalState.current === 'search' && (
85
90
  <>
@@ -1,17 +1,29 @@
1
1
  import { useEffect, useState } from 'preact/hooks';
2
2
 
3
3
  /**
4
- * Custom hook that checks the current URL for a `search` query parameter
5
- * and, if found, updates the search term and opens the search interface.
4
+ * Custom hook that checks the current URL for query parameters and updates
5
+ * search state or modal state accordingly:
6
6
  *
7
- * Useful for enabling deep linking to a search view with a pre-filled term,
8
- * such as when sharing URLs like `?search=netlify`.
7
+ * - If `?ask` is present (optionally with `?msg` or `?message`), it opens the modal and
8
+ * optionally pre-fills the search term.
9
+ * - If only `?msg` or `?message` is present, it behaves similarly, opening the modal
10
+ * and pre-filling the search term.
11
+ * - If only `?search` is present, it pre-fills the search input and opens the search view.
12
+ *
13
+ * The hook also waits for `window.pagefind` to load before evaluating parameters,
14
+ * ensuring deep linking doesn't interfere with pagefind initialization.
9
15
  *
10
- * @param setSearchTerm - Function to update the search input state.
11
16
  * @param onOpen - Function to trigger opening of the search interface (e.g., modal or drawer).
17
+ * @param setSearchTerm - Function to update the search input state.
18
+ * @param setModalState - (Optional) Function to set modal state, useful for distinguishing modal views.
12
19
  */
13
20
 
14
- export function useSearchParams(setSearchTerm: (term: string) => void, onOpen: () => void) {
21
+ export function useSearchParams(
22
+ onOpen: () => void,
23
+ setSearchTerm: (term: string) => void,
24
+ setUrlParamTerm: (term: string) => void,
25
+ setModalState?: (e: { current: string }) => void
26
+ ) {
15
27
  const [isPagefindLoaded, setIsPagefindLoaded] = useState(false);
16
28
 
17
29
  // Poll for the existence of window.pagefind.
@@ -34,12 +46,28 @@ export function useSearchParams(setSearchTerm: (term: string) => void, onOpen: (
34
46
  }, []);
35
47
 
36
48
  useEffect(() => {
37
- // Cleanup the interval when the component unmounts.
38
49
  if (typeof location === 'undefined' || isPagefindLoaded) return;
39
- const query = location?.search && new URLSearchParams(location.search).get('search');
40
- if (query) {
41
- setSearchTerm(query);
50
+
51
+ const params = new URLSearchParams(location.search);
52
+
53
+ const hasAsk = params.has('ask');
54
+ const msg = params.get('msg') || params.get('message');
55
+ const search = params.get('search');
56
+
57
+ const openAskModal = (term?: string | null) => {
58
+ if (term) setUrlParamTerm(term);
59
+ setModalState?.({ current: 'ask' });
60
+ onOpen();
61
+ };
62
+
63
+ if (hasAsk || msg) {
64
+ openAskModal(msg);
65
+ return;
66
+ }
67
+
68
+ if (search) {
69
+ setSearchTerm(search);
42
70
  onOpen();
43
71
  }
44
- }, [isPagefindLoaded]);
72
+ }, [isPagefindLoaded, onOpen, setModalState, setSearchTerm, setUrlParamTerm]);
45
73
  }