@searchcraft/react-sdk 0.1.1 → 0.1.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.
package/dist/index.js CHANGED
@@ -1,24 +1,23 @@
1
- import { jsx as n, jsxs as u, Fragment as k } from "react/jsx-runtime";
2
- import Q, { useState as g, useContext as Z, useEffect as K } from "react";
3
- var U = Object.defineProperty, H = (t, e, s) => e in t ? U(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s, N = (t, e, s) => H(t, typeof e != "symbol" ? e + "" : e, s);
4
- class Jn {
1
+ import { jsx as t, jsxs as h, Fragment as x } from "react/jsx-runtime";
2
+ import K, { useContext as J, useState as T, useMemo as H, useEffect as z } from "react";
3
+ var V = Object.defineProperty, X = (n, e, o) => e in n ? V(n, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : n[e] = o, E = (n, e, o) => X(n, typeof e != "symbol" ? e + "" : e, o);
4
+ class et {
5
5
  constructor(e) {
6
- if (N(this, "config"), N(this, "search", async (s) => {
6
+ if (E(this, "config"), E(this, "search", async (o) => {
7
7
  try {
8
- const i = this.config.index.join(","), o = `${this.config.endpointURL}/index/${i}/search`, r = {
9
- query: s.query,
10
- mode: s.mode,
11
- app: this.config.index
8
+ const i = this.config.index.join(","), c = `${this.config.endpointURL}/search`, r = {
9
+ query: o.query,
10
+ mode: o.mode,
11
+ app: i
12
12
  }, a = {
13
13
  method: "POST",
14
14
  headers: {
15
15
  "Content-Type": "application/json",
16
- "Access-Control-Allow-Origin": "*",
17
16
  Authorization: this.config.apiKey ? `${this.config.apiKey}` : ""
18
17
  },
19
18
  body: JSON.stringify(r)
20
19
  };
21
- return await (await fetch(o, a)).json();
20
+ return await (await fetch(c, a)).json();
22
21
  } catch (i) {
23
22
  return i;
24
23
  }
@@ -27,54 +26,112 @@ class Jn {
27
26
  this.config = e;
28
27
  }
29
28
  }
30
- const J = {
29
+ var _ = /* @__PURE__ */ ((n) => (n[n.DEBUG = 0] = "DEBUG", n[n.INFO = 1] = "INFO", n[n.WARN = 2] = "WARN", n[n.ERROR = 3] = "ERROR", n))(_ || {});
30
+ class Y {
31
+ constructor(e) {
32
+ E(this, "logLevel"), E(this, "logFormatter"), this.logLevel = e.logLevel || 1, this.logFormatter = e.logFormatter || this.defaultFormatter;
33
+ }
34
+ defaultFormatter(e, o) {
35
+ return `[${_[e]}] ${(/* @__PURE__ */ new Date()).toISOString()}: ${o}`;
36
+ }
37
+ debug(e) {
38
+ this.logLevel <= 0 && console.log(this.logFormatter(0, e));
39
+ }
40
+ info(e) {
41
+ this.logLevel <= 1 && console.info(this.logFormatter(1, e));
42
+ }
43
+ warn(e) {
44
+ this.logLevel <= 2 && console.warn(this.logFormatter(2, e));
45
+ }
46
+ error(e) {
47
+ this.logLevel <= 3 && console.error(this.logFormatter(3, e));
48
+ }
49
+ }
50
+ const nn = {
31
51
  error: null,
32
52
  index: [""],
33
53
  isRequesting: !1,
34
54
  mode: "fuzzy",
35
55
  query: "",
36
- setQuery: (t) => t,
56
+ setQuery: (n) => n,
37
57
  search: async () => null
38
- }, F = Q.createContext(J), Gn = ({
39
- children: t,
40
- searchcraft: e
58
+ }, G = K.createContext(nn), tn = ({
59
+ children: n,
60
+ searchcraft: e,
61
+ debug: o = !1
41
62
  }) => {
42
- const [s, i] = g(""), [o, r] = g(!1), [a, l] = g(null), c = async () => {
43
- r(!0);
44
- const _ = await e.search({ query: s, mode: "fuzzy" });
45
- l(_), r(!1);
46
- }, h = {
63
+ const [i, c] = T(""), [r, a] = T(!1), [l, s] = T(null), u = H(() => o ? new Y({ logLevel: _.DEBUG }) : null, [o]), p = (f, R) => {
64
+ if (u)
65
+ switch (f) {
66
+ case _.DEBUG:
67
+ u.debug(R);
68
+ break;
69
+ case _.INFO:
70
+ u.info(R);
71
+ break;
72
+ case _.WARN:
73
+ u.warn(R);
74
+ break;
75
+ case _.ERROR:
76
+ u.error(R);
77
+ break;
78
+ }
79
+ }, L = async () => {
80
+ p(_.INFO, `Starting search with query: "${i}"`), a(!0);
81
+ try {
82
+ const f = await e.search({ query: i, mode: "fuzzy" });
83
+ s(f), p(_.DEBUG, `Search results: ${JSON.stringify(f)}`);
84
+ } catch (f) {
85
+ p(
86
+ _.ERROR,
87
+ `Search failed with error: ${f.message}`
88
+ );
89
+ } finally {
90
+ a(!1);
91
+ }
92
+ };
93
+ z(() => (p(_.INFO, "SearchcraftProvider mounted."), () => {
94
+ p(_.INFO, "SearchcraftProvider unmounted.");
95
+ }), [u]);
96
+ const g = {
47
97
  error: null,
48
98
  index: e.config.index,
49
- isRequesting: o,
99
+ isRequesting: r,
50
100
  mode: "fuzzy",
51
- query: s,
52
- search: c,
53
- searchResults: a,
54
- setQuery: i
101
+ query: i,
102
+ search: L,
103
+ searchResults: l,
104
+ setQuery: c
55
105
  };
56
- return /* @__PURE__ */ n(F.Provider, { value: h, children: t });
57
- }, v = () => Z(F), G = "_formLTR_dvuqa_5", V = "_formRTL_dvuqa_9", X = "_searchContainer_dvuqa_13", L = {
58
- formLTR: G,
59
- formRTL: V,
60
- searchContainer: X
106
+ return /* @__PURE__ */ t(G.Provider, { value: g, children: n });
107
+ }, I = () => {
108
+ const n = J(G);
109
+ if (!n)
110
+ throw new Error(
111
+ "Searchcraft compound components must be used within Searchcraft.Provider"
112
+ );
113
+ return n;
114
+ }, en = "_formLTR_dvuqa_5", rn = "_formRTL_dvuqa_9", on = "_searchContainer_dvuqa_13", v = {
115
+ formLTR: en,
116
+ formRTL: rn,
117
+ searchContainer: on
61
118
  };
62
- function Y(t) {
63
- return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
119
+ function an(n) {
120
+ return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n;
64
121
  }
65
- var D = { exports: {} };
122
+ var Q = { exports: {} };
66
123
  /*!
67
124
  Copyright (c) 2018 Jed Watson.
68
125
  Licensed under the MIT License (MIT), see
69
126
  http://jedwatson.github.io/classnames
70
127
  */
71
- (function(t) {
128
+ (function(n) {
72
129
  (function() {
73
130
  var e = {}.hasOwnProperty;
74
- function s() {
131
+ function o() {
75
132
  for (var r = "", a = 0; a < arguments.length; a++) {
76
133
  var l = arguments[a];
77
- l && (r = o(r, i(l)));
134
+ l && (r = c(r, i(l)));
78
135
  }
79
136
  return r;
80
137
  }
@@ -84,98 +141,34 @@ var D = { exports: {} };
84
141
  if (typeof r != "object")
85
142
  return "";
86
143
  if (Array.isArray(r))
87
- return s.apply(null, r);
144
+ return o.apply(null, r);
88
145
  if (r.toString !== Object.prototype.toString && !r.toString.toString().includes("[native code]"))
89
146
  return r.toString();
90
147
  var a = "";
91
148
  for (var l in r)
92
- e.call(r, l) && r[l] && (a = o(a, l));
149
+ e.call(r, l) && r[l] && (a = c(a, l));
93
150
  return a;
94
151
  }
95
- function o(r, a) {
152
+ function c(r, a) {
96
153
  return a ? r ? r + " " + a : r + a : r;
97
154
  }
98
- t.exports ? (s.default = s, t.exports = s) : window.classNames = s;
155
+ n.exports ? (o.default = o, n.exports = o) : window.classNames = o;
99
156
  })();
100
- })(D);
101
- var O = D.exports;
102
- const p = /* @__PURE__ */ Y(O), nn = "_button_8jqm2_5", tn = "_spinnerMarginRight_8jqm2_26", en = "_spinnerMarginLeft_8jqm2_32", rn = "_buttonLabel_8jqm2_38", on = "_rightandback_8jqm2_1", b = {
103
- button: nn,
104
- spinnerMarginRight: tn,
105
- spinnerMarginLeft: en,
106
- buttonLabel: rn,
107
- rightandback: on
108
- }, sn = "_spinnerContainer_1noam_1", an = "_spinnerDark_1noam_7", cn = "_spinning_1noam_1", ln = "_spinnerLight_1noam_16", S = {
109
- spinnerContainer: sn,
110
- spinnerDark: an,
111
- spinning: cn,
112
- spinnerLight: ln
113
- }, x = () => /* @__PURE__ */ n("div", { className: S.spinnerContainer, children: /* @__PURE__ */ n("div", { className: S.spinnerLight }) }), I = () => /* @__PURE__ */ n("div", { className: S.spinnerContainer, children: /* @__PURE__ */ n("div", { className: S.spinnerDark }) }), w = ({
114
- className: t,
115
- iconElement: e,
116
- iconOnly: s = !1,
117
- iconPosition: i = "left",
118
- label: o = "Search",
119
- onClick: r
120
- }) => {
121
- const { isRequesting: a } = v();
122
- return /* @__PURE__ */ u(k, { children: [
123
- s && /* @__PURE__ */ n(
124
- "button",
125
- {
126
- className: p(
127
- b.button,
128
- t,
129
- ".searchcraft-button"
130
- ),
131
- onClick: r,
132
- type: "submit",
133
- children: a ? /* @__PURE__ */ n(I, {}) : e
134
- }
135
- ),
136
- !s && /* @__PURE__ */ u(
137
- "button",
138
- {
139
- className: p(
140
- b.button,
141
- t,
142
- ".searchcraft-button"
143
- ),
144
- onClick: r,
145
- type: "submit",
146
- children: [
147
- i === "left" && a ? /* @__PURE__ */ n("div", { className: b.spinnerMarginRight, children: /* @__PURE__ */ n(I, {}) }) : e,
148
- /* @__PURE__ */ n(
149
- "span",
150
- {
151
- className: p(
152
- a && b.buttonLabel,
153
- t,
154
- ".searchcraft-button-label"
155
- ),
156
- children: o
157
- }
158
- ),
159
- i === "right" && a ? /* @__PURE__ */ n("div", { className: b.spinnerMarginLeft, children: /* @__PURE__ */ n(I, {}) }) : e
160
- ]
161
- }
162
- )
163
- ] });
164
- }, un = "_errorMessage_12dc9_5", pn = {
165
- errorMessage: un
166
- }, hn = ({ className: t, errorMessage: e }) => /* @__PURE__ */ n("p", { className: p(pn.errorMessage, t), children: e || "Search term is required." }), dn = "_inputContainerLTR_s1rq8_5", _n = "_inputContainerRTL_s1rq8_9", Cn = "_inputLTR_s1rq8_14", fn = "_inputRTL_s1rq8_35", mn = "_inputErrorLTR_s1rq8_57", Ln = "_inputErrorRTL_s1rq8_82", m = {
167
- inputContainerLTR: dn,
168
- inputContainerRTL: _n,
169
- inputLTR: Cn,
170
- inputRTL: fn,
171
- inputErrorLTR: mn,
172
- inputErrorRTL: Ln
173
- }, Rn = "_inputClearButtonLTR_t63ei_5", bn = "_inputClearButtonRTL_t63ei_19", E = {
174
- inputClearButtonLTR: Rn,
175
- inputClearButtonRTL: bn
176
- }, M = () => /* @__PURE__ */ u("svg", { width: "22", height: "22", viewBox: "0 0 22 22", fill: "none", children: [
177
- /* @__PURE__ */ n("title", { children: "Searchcraft Clear Input Icon" }),
178
- /* @__PURE__ */ n(
157
+ })(Q);
158
+ var sn = Q.exports;
159
+ const d = /* @__PURE__ */ an(sn), cn = "_inputContainerLTR_s1rq8_5", ln = "_inputContainerRTL_s1rq8_9", un = "_inputLTR_s1rq8_14", hn = "_inputRTL_s1rq8_35", pn = "_inputErrorLTR_s1rq8_57", dn = "_inputErrorRTL_s1rq8_82", b = {
160
+ inputContainerLTR: cn,
161
+ inputContainerRTL: ln,
162
+ inputLTR: un,
163
+ inputRTL: hn,
164
+ inputErrorLTR: pn,
165
+ inputErrorRTL: dn
166
+ }, fn = "_inputClearButtonLTR_t63ei_5", _n = "_inputClearButtonRTL_t63ei_19", P = {
167
+ inputClearButtonLTR: fn,
168
+ inputClearButtonRTL: _n
169
+ }, O = () => /* @__PURE__ */ h("svg", { width: "22", height: "22", viewBox: "0 0 22 22", fill: "none", children: [
170
+ /* @__PURE__ */ t("title", { children: "Searchcraft Clear Input Icon" }),
171
+ /* @__PURE__ */ t(
179
172
  "path",
180
173
  {
181
174
  d: "M14 8L8 14M8 8L14 14M21 11C21 16.5228 16.5228 21 11 21C5.47715 21 1 16.5228 1 11C1 5.47715 5.47715 1 11 1C16.5228 1 21 5.47715 21 11Z",
@@ -185,9 +178,9 @@ const p = /* @__PURE__ */ Y(O), nn = "_button_8jqm2_5", tn = "_spinnerMarginRigh
185
178
  strokeLinejoin: "round"
186
179
  }
187
180
  )
188
- ] }), q = () => /* @__PURE__ */ u("svg", { width: "20", height: "21", viewBox: "0 0 20 21", fill: "none", children: [
189
- /* @__PURE__ */ n("title", { children: "Searchcraft Arrow Right Icon" }),
190
- /* @__PURE__ */ n(
181
+ ] }), U = () => /* @__PURE__ */ h("svg", { width: "20", height: "21", viewBox: "0 0 20 21", fill: "none", children: [
182
+ /* @__PURE__ */ t("title", { children: "Searchcraft Arrow Right Icon" }),
183
+ /* @__PURE__ */ t(
191
184
  "path",
192
185
  {
193
186
  d: "M7.5 15.0444L12.5 10.0444L7.5 5.04443",
@@ -197,68 +190,73 @@ const p = /* @__PURE__ */ Y(O), nn = "_button_8jqm2_5", tn = "_spinnerMarginRigh
197
190
  strokeLinejoin: "round"
198
191
  }
199
192
  )
200
- ] }), B = ({
201
- onClearInput: t,
193
+ ] }), mn = "_spinnerContainer_1noam_1", Cn = "_spinnerDark_1noam_7", Ln = "_spinning_1noam_1", gn = "_spinnerLight_1noam_16", w = {
194
+ spinnerContainer: mn,
195
+ spinnerDark: Cn,
196
+ spinning: Ln,
197
+ spinnerLight: gn
198
+ }, W = () => /* @__PURE__ */ t("div", { className: w.spinnerContainer, children: /* @__PURE__ */ t("div", { className: w.spinnerLight }) }), B = () => /* @__PURE__ */ t("div", { className: w.spinnerContainer, children: /* @__PURE__ */ t("div", { className: w.spinnerDark }) }), M = ({
199
+ onClearInput: n,
202
200
  rightToLeftOrientation: e = !1
203
201
  }) => {
204
- const { isRequesting: s } = v();
205
- return e ? /* @__PURE__ */ n(
202
+ const { isRequesting: o } = I();
203
+ return e ? /* @__PURE__ */ t(
206
204
  "button",
207
205
  {
208
- className: p(
209
- E.inputClearButtonRTL,
206
+ className: d(
207
+ P.inputClearButtonRTL,
210
208
  ".sc-clear-input-button-rtl"
211
209
  ),
212
- onClick: t,
210
+ onClick: n,
213
211
  type: "button",
214
- children: s ? /* @__PURE__ */ n(x, {}) : /* @__PURE__ */ n(M, {})
212
+ children: o ? /* @__PURE__ */ t(W, {}) : /* @__PURE__ */ t(O, {})
215
213
  }
216
- ) : /* @__PURE__ */ n(
214
+ ) : /* @__PURE__ */ t(
217
215
  "button",
218
216
  {
219
- className: p(
220
- E.inputClearButtonLTR,
217
+ className: d(
218
+ P.inputClearButtonLTR,
221
219
  ".sc-clear-input-button-ltr"
222
220
  ),
223
- onClick: t,
221
+ onClick: n,
224
222
  type: "button",
225
- children: s ? /* @__PURE__ */ n(x, {}) : /* @__PURE__ */ n(M, {})
223
+ children: o ? /* @__PURE__ */ t(W, {}) : /* @__PURE__ */ t(O, {})
226
224
  }
227
225
  );
228
- }, gn = "_inputCaptionLTR_xoy9r_5", vn = "_inputCaptionErrorLTR_xoy9r_14", Tn = "_inputCaptionRTL_xoy9r_24", yn = "_inputCaptionErrorRTL_xoy9r_34", T = {
229
- inputCaptionLTR: gn,
230
- inputCaptionErrorLTR: vn,
231
- inputCaptionRTL: Tn,
232
- inputCaptionErrorRTL: yn
233
- }, j = ({
234
- error: t = !1,
226
+ }, Rn = "_inputCaptionLTR_xoy9r_5", bn = "_inputCaptionErrorLTR_xoy9r_14", vn = "_inputCaptionRTL_xoy9r_24", Sn = "_inputCaptionErrorRTL_xoy9r_34", N = {
227
+ inputCaptionLTR: Rn,
228
+ inputCaptionErrorLTR: bn,
229
+ inputCaptionRTL: vn,
230
+ inputCaptionErrorRTL: Sn
231
+ }, F = ({
232
+ error: n = !1,
235
233
  inputCaptionClassName: e,
236
- inputCaptionValue: s = "Enter Search",
234
+ inputCaptionValue: o = "Enter Search",
237
235
  rightToLeftOrientation: i = !1
238
- }) => i ? /* @__PURE__ */ n(
236
+ }) => i ? /* @__PURE__ */ t(
239
237
  "p",
240
238
  {
241
- className: p(
242
- t ? T.inputCaptionErrorRTL : T.inputCaptionRTL,
239
+ className: d(
240
+ n ? N.inputCaptionErrorRTL : N.inputCaptionRTL,
243
241
  e
244
242
  ),
245
- children: s
243
+ children: o
246
244
  }
247
- ) : /* @__PURE__ */ n(
245
+ ) : /* @__PURE__ */ t(
248
246
  "p",
249
247
  {
250
- className: p(
251
- t ? T.inputCaptionErrorLTR : T.inputCaptionLTR,
248
+ className: d(
249
+ n ? N.inputCaptionErrorLTR : N.inputCaptionLTR,
252
250
  e
253
251
  ),
254
- children: s
252
+ children: o
255
253
  }
256
- ), Sn = "_inputIconLTR_cusap_5", In = "_inputIconRTL_cusap_13", y = {
257
- inputIconLTR: Sn,
258
- inputIconRTL: In
259
- }, kn = () => /* @__PURE__ */ u("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: [
260
- /* @__PURE__ */ n("title", { children: "Searchcraft Search Icon" }),
261
- /* @__PURE__ */ n(
254
+ ), yn = "_inputIconLTR_cusap_5", Tn = "_inputIconRTL_cusap_13", k = {
255
+ inputIconLTR: yn,
256
+ inputIconRTL: Tn
257
+ }, In = () => /* @__PURE__ */ h("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: [
258
+ /* @__PURE__ */ t("title", { children: "Searchcraft Search Icon" }),
259
+ /* @__PURE__ */ t(
262
260
  "path",
263
261
  {
264
262
  d: "M17.5 17.5L13.875 13.875M15.8333 9.16667C15.8333 12.8486 12.8486 15.8333 9.16667 15.8333C5.48477 15.8333 2.5 12.8486 2.5 9.16667C2.5 5.48477 5.48477 2.5 9.16667 2.5C12.8486 2.5 15.8333 5.48477 15.8333 9.16667Z",
@@ -268,9 +266,9 @@ const p = /* @__PURE__ */ Y(O), nn = "_button_8jqm2_5", tn = "_spinnerMarginRigh
268
266
  strokeLinejoin: "round"
269
267
  }
270
268
  )
271
- ] }), Nn = () => /* @__PURE__ */ u("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: [
272
- /* @__PURE__ */ n("title", { children: "Searchcraft Error Search Icon" }),
273
- /* @__PURE__ */ n(
269
+ ] }), Nn = () => /* @__PURE__ */ h("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: [
270
+ /* @__PURE__ */ t("title", { children: "Searchcraft Error Search Icon" }),
271
+ /* @__PURE__ */ t(
274
272
  "path",
275
273
  {
276
274
  d: "M17.5 17.5L13.875 13.875M15.8333 9.16667C15.8333 12.8486 12.8486 15.8333 9.16667 15.8333C5.48477 15.8333 2.5 12.8486 2.5 9.16667C2.5 5.48477 5.48477 2.5 9.16667 2.5C12.8486 2.5 15.8333 5.48477 15.8333 9.16667Z",
@@ -280,48 +278,48 @@ const p = /* @__PURE__ */ Y(O), nn = "_button_8jqm2_5", tn = "_spinnerMarginRigh
280
278
  strokeLinejoin: "round"
281
279
  }
282
280
  )
283
- ] }), $ = ({
284
- error: t = !1,
281
+ ] }), q = ({
282
+ error: n = !1,
285
283
  rightToLeftOrientation: e = !1
286
- }) => t ? /* @__PURE__ */ n(
284
+ }) => n ? /* @__PURE__ */ t(
287
285
  "div",
288
286
  {
289
- className: e ? y.inputIconRTL : y.inputIconLTR,
290
- children: /* @__PURE__ */ n(Nn, {})
287
+ className: e ? k.inputIconRTL : k.inputIconLTR,
288
+ children: /* @__PURE__ */ t(Nn, {})
291
289
  }
292
- ) : /* @__PURE__ */ n(
290
+ ) : /* @__PURE__ */ t(
293
291
  "div",
294
292
  {
295
- className: e ? y.inputIconRTL : y.inputIconLTR,
296
- children: /* @__PURE__ */ n(kn, {})
293
+ className: e ? k.inputIconRTL : k.inputIconLTR,
294
+ children: /* @__PURE__ */ t(In, {})
297
295
  }
298
- ), A = ({
299
- error: t = !1,
296
+ ), j = ({
297
+ error: n = !1,
300
298
  formClassName: e = "",
301
- inputCaptionClassName: s = "",
299
+ inputCaptionClassName: o = "",
302
300
  inputClassName: i = "",
303
- inputCaptionValue: o = "",
301
+ inputCaptionValue: c = "",
304
302
  onClearInput: r,
305
303
  onSearchInputChange: a,
306
304
  placeholderValue: l = "Enter Search",
307
- rightToLeftOrientation: c = !1,
308
- query: h = ""
305
+ rightToLeftOrientation: s = !1,
306
+ query: u = ""
309
307
  }) => {
310
- const _ = c ? m.inputContainerRTL : m.inputContainerLTR;
311
- return /* @__PURE__ */ n(
308
+ const p = s ? b.inputContainerRTL : b.inputContainerLTR;
309
+ return /* @__PURE__ */ t(
312
310
  "div",
313
311
  {
314
- className: p(
315
- _,
312
+ className: d(
313
+ p,
316
314
  e,
317
315
  "searchcraft-input-form"
318
316
  ),
319
- children: c ? /* @__PURE__ */ u(k, { children: [
320
- /* @__PURE__ */ n(
317
+ children: s ? /* @__PURE__ */ h(x, { children: [
318
+ /* @__PURE__ */ t(
321
319
  "input",
322
320
  {
323
- className: p(
324
- t ? m.inputErrorRTL : m.inputRTL,
321
+ className: d(
322
+ n ? b.inputErrorRTL : b.inputRTL,
325
323
  i,
326
324
  "searchcraft-input"
327
325
  ),
@@ -329,37 +327,37 @@ const p = /* @__PURE__ */ Y(O), nn = "_button_8jqm2_5", tn = "_spinnerMarginRigh
329
327
  onChange: a,
330
328
  placeholder: l,
331
329
  type: "text",
332
- value: h
330
+ value: u
333
331
  }
334
332
  ),
335
- o && /* @__PURE__ */ n(
336
- j,
333
+ c && /* @__PURE__ */ t(
334
+ F,
337
335
  {
338
- inputCaptionClassName: s,
339
- inputCaptionValue: o,
340
- rightToLeftOrientation: c
336
+ inputCaptionClassName: o,
337
+ inputCaptionValue: c,
338
+ rightToLeftOrientation: s
341
339
  }
342
340
  ),
343
- h.length > 0 && /* @__PURE__ */ n(
344
- B,
341
+ u.length > 0 && /* @__PURE__ */ t(
342
+ M,
345
343
  {
346
344
  onClearInput: r,
347
- rightToLeftOrientation: c
345
+ rightToLeftOrientation: s
348
346
  }
349
347
  ),
350
- /* @__PURE__ */ n(
351
- $,
348
+ /* @__PURE__ */ t(
349
+ q,
352
350
  {
353
- error: t,
354
- rightToLeftOrientation: c
351
+ error: n,
352
+ rightToLeftOrientation: s
355
353
  }
356
354
  )
357
- ] }) : /* @__PURE__ */ u(k, { children: [
358
- /* @__PURE__ */ n(
355
+ ] }) : /* @__PURE__ */ h(x, { children: [
356
+ /* @__PURE__ */ t(
359
357
  "input",
360
358
  {
361
- className: p(
362
- t ? m.inputErrorLTR : m.inputLTR,
359
+ className: d(
360
+ n ? b.inputErrorLTR : b.inputLTR,
363
361
  i,
364
362
  "searchcraft-input"
365
363
  ),
@@ -367,128 +365,90 @@ const p = /* @__PURE__ */ Y(O), nn = "_button_8jqm2_5", tn = "_spinnerMarginRigh
367
365
  onChange: a,
368
366
  placeholder: l,
369
367
  type: "text",
370
- value: h
368
+ value: u
371
369
  }
372
370
  ),
373
- o && /* @__PURE__ */ n(
374
- j,
371
+ c && /* @__PURE__ */ t(
372
+ F,
375
373
  {
376
- inputCaptionClassName: s,
377
- inputCaptionValue: o,
378
- rightToLeftOrientation: c
374
+ inputCaptionClassName: o,
375
+ inputCaptionValue: c,
376
+ rightToLeftOrientation: s
379
377
  }
380
378
  ),
381
- h.length > 0 && /* @__PURE__ */ n(
382
- B,
379
+ u.length > 0 && /* @__PURE__ */ t(
380
+ M,
383
381
  {
384
382
  onClearInput: r,
385
- rightToLeftOrientation: c
383
+ rightToLeftOrientation: s
386
384
  }
387
385
  ),
388
- /* @__PURE__ */ n($, { error: t })
386
+ /* @__PURE__ */ t(q, { error: n })
389
387
  ] })
390
388
  }
391
389
  );
392
- }, xn = "_label_1euwf_5", wn = {
393
- label: xn
394
- }, z = ({
395
- className: t,
390
+ }, kn = "_label_1euwf_5", En = {
391
+ label: kn
392
+ }, D = ({
393
+ className: n,
396
394
  label: e = "Enter Search"
397
- }) => /* @__PURE__ */ n(
395
+ }) => /* @__PURE__ */ t(
398
396
  "label",
399
397
  {
400
- className: p(wn.label, t),
398
+ className: d(En.label, n),
401
399
  htmlFor: "searchcraft-input-id",
402
400
  children: e
403
401
  }
404
- ), Vn = ({
405
- errorMessage: t,
402
+ ), wn = ({
403
+ autoSearchFormClass: n = "",
406
404
  handleSubmit: e,
407
- labelForInput: s = "Search",
408
- placeholderValue: i = "Enter Search Term",
409
- rightToLeftOrientation: o = !1
410
- }) => {
411
- const { query: r, setQuery: a } = v(), [l, c] = g(!1), h = (C) => {
412
- C.preventDefault(), r.trim() === "" ? c(!0) : (c(!1), e(r));
413
- }, _ = (C) => a(C.target.value), f = () => a("");
414
- return /* @__PURE__ */ u(
415
- "form",
416
- {
417
- className: o ? L.formRTL : L.formLTR,
418
- onSubmit: h,
419
- children: [
420
- /* @__PURE__ */ n(z, { label: s }),
421
- /* @__PURE__ */ u("div", { className: L.searchContainer, children: [
422
- o && /* @__PURE__ */ n(w, {}),
423
- /* @__PURE__ */ n(
424
- A,
425
- {
426
- error: l,
427
- onClearInput: f,
428
- onSearchInputChange: _,
429
- placeholderValue: i,
430
- query: r,
431
- rightToLeftOrientation: o
432
- }
433
- ),
434
- !o && /* @__PURE__ */ n(w, {})
435
- ] }),
436
- l && /* @__PURE__ */ n(hn, { errorMessage: t })
437
- ]
438
- }
439
- );
440
- }, Xn = ({
441
- autoSearchFormClass: t = "",
442
- handleSubmit: e,
443
- inputCaptionValue: s = "",
405
+ inputCaptionValue: o = "",
444
406
  labelForInput: i = "Search",
445
- onClearedInput: o = () => {
407
+ onClearInput: c = () => {
446
408
  },
447
409
  placeholderValue: r = "Search here",
448
410
  rightToLeftOrientation: a = !1,
449
411
  searchContainerClass: l = ""
450
412
  }) => {
451
- const { query: c, setQuery: h } = v(), [_, f] = g(!1), C = (R) => {
452
- R.preventDefault(), h(R.currentTarget.value), c !== R.currentTarget.value && f(!0);
453
- }, P = () => {
454
- h(""), o();
413
+ const { query: s, setQuery: u } = I(), [p, L] = T(!1), g = a ? v.formRTL : v.formLTR, f = (S) => {
414
+ S.preventDefault(), u(S.currentTarget.value), s !== S.currentTarget.value && L(!0);
415
+ }, R = () => {
416
+ u(""), c();
455
417
  };
456
- K(() => {
457
- if (_)
458
- e(c), f(!1);
418
+ return z(() => {
419
+ if (p)
420
+ e(s), L(!1);
459
421
  else
460
422
  return;
461
- }, [_, e, c]);
462
- const W = a ? L.formRTL : L.formLTR;
463
- return /* @__PURE__ */ u(
423
+ }, [p, e, s]), /* @__PURE__ */ h(
464
424
  "form",
465
425
  {
466
- className: p(
467
- W,
468
- t,
426
+ className: d(
427
+ g,
428
+ n,
469
429
  "searchcraft-auto-search-form"
470
430
  ),
471
- onSubmit: (R) => {
472
- R.preventDefault();
431
+ onSubmit: (S) => {
432
+ S.preventDefault();
473
433
  },
474
434
  children: [
475
- /* @__PURE__ */ n(z, { label: i }),
476
- /* @__PURE__ */ n(
435
+ /* @__PURE__ */ t(D, { label: i }),
436
+ /* @__PURE__ */ t(
477
437
  "div",
478
438
  {
479
- className: p(
480
- L.searchContainer,
439
+ className: d(
440
+ v.searchContainer,
481
441
  l,
482
442
  "searchcraft-input-container"
483
443
  ),
484
- children: /* @__PURE__ */ n(
485
- A,
444
+ children: /* @__PURE__ */ t(
445
+ j,
486
446
  {
487
- inputCaptionValue: s,
488
- onClearInput: P,
489
- onSearchInputChange: C,
447
+ inputCaptionValue: o,
448
+ onClearInput: R,
449
+ onSearchInputChange: f,
490
450
  placeholderValue: r,
491
- query: c,
451
+ query: s,
492
452
  rightToLeftOrientation: a
493
453
  }
494
454
  )
@@ -497,9 +457,108 @@ const p = /* @__PURE__ */ Y(O), nn = "_button_8jqm2_5", tn = "_spinnerMarginRigh
497
457
  ]
498
458
  }
499
459
  );
500
- }, En = () => /* @__PURE__ */ u("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: [
501
- /* @__PURE__ */ n("title", { children: "Searchcraft Button Icon" }),
502
- /* @__PURE__ */ n(
460
+ }, Bn = "_button_8jqm2_5", xn = "_spinnerMarginRight_8jqm2_26", Mn = "_spinnerMarginLeft_8jqm2_32", Fn = "_buttonLabel_8jqm2_38", qn = "_rightandback_8jqm2_1", y = {
461
+ button: Bn,
462
+ spinnerMarginRight: xn,
463
+ spinnerMarginLeft: Mn,
464
+ buttonLabel: Fn,
465
+ rightandback: qn
466
+ }, $ = ({
467
+ className: n,
468
+ iconElement: e,
469
+ iconOnly: o = !1,
470
+ iconPosition: i = "left",
471
+ label: c = "Search",
472
+ onClick: r
473
+ }) => {
474
+ const { isRequesting: a } = I();
475
+ return /* @__PURE__ */ h(x, { children: [
476
+ o && /* @__PURE__ */ t(
477
+ "button",
478
+ {
479
+ className: d(
480
+ y.button,
481
+ n,
482
+ ".searchcraft-button"
483
+ ),
484
+ onClick: r,
485
+ type: "submit",
486
+ children: a ? /* @__PURE__ */ t(B, {}) : e
487
+ }
488
+ ),
489
+ !o && /* @__PURE__ */ h(
490
+ "button",
491
+ {
492
+ className: d(
493
+ y.button,
494
+ n,
495
+ ".searchcraft-button"
496
+ ),
497
+ onClick: r,
498
+ type: "submit",
499
+ children: [
500
+ i === "left" && a ? /* @__PURE__ */ t("div", { className: y.spinnerMarginRight, children: /* @__PURE__ */ t(B, {}) }) : e,
501
+ /* @__PURE__ */ t(
502
+ "span",
503
+ {
504
+ className: d(
505
+ a && y.buttonLabel,
506
+ n,
507
+ ".searchcraft-button-label"
508
+ ),
509
+ children: c
510
+ }
511
+ ),
512
+ i === "right" && a ? /* @__PURE__ */ t("div", { className: y.spinnerMarginLeft, children: /* @__PURE__ */ t(B, {}) }) : e
513
+ ]
514
+ }
515
+ )
516
+ ] });
517
+ }, $n = "_errorMessage_12dc9_5", jn = {
518
+ errorMessage: $n
519
+ }, A = ({ className: n, errorMessage: e }) => /* @__PURE__ */ t("p", { className: d(jn.errorMessage, n), children: e || "Search term is required." }), Dn = ({
520
+ errorMessage: n,
521
+ handleSubmit: e,
522
+ labelForInput: o = "Search",
523
+ onClearInput: i = () => {
524
+ },
525
+ placeholderValue: c = "Enter Search Term",
526
+ rightToLeftOrientation: r = !1
527
+ }) => {
528
+ const { query: a, setQuery: l } = I(), [s, u] = T(!1), p = (f) => {
529
+ f.preventDefault(), a.trim() === "" ? u(!0) : (u(!1), e(a));
530
+ }, L = (f) => l(f.target.value), g = () => {
531
+ l(""), i();
532
+ };
533
+ return /* @__PURE__ */ h(
534
+ "form",
535
+ {
536
+ className: r ? v.formRTL : v.formLTR,
537
+ onSubmit: p,
538
+ children: [
539
+ /* @__PURE__ */ t(D, { label: o }),
540
+ /* @__PURE__ */ h("div", { className: v.searchContainer, children: [
541
+ r && /* @__PURE__ */ t($, {}),
542
+ /* @__PURE__ */ t(
543
+ j,
544
+ {
545
+ error: s,
546
+ onClearInput: g,
547
+ onSearchInputChange: L,
548
+ placeholderValue: c,
549
+ query: a,
550
+ rightToLeftOrientation: r
551
+ }
552
+ ),
553
+ !r && /* @__PURE__ */ t($, {})
554
+ ] }),
555
+ s && /* @__PURE__ */ t(A, { errorMessage: n })
556
+ ]
557
+ }
558
+ );
559
+ }, An = () => /* @__PURE__ */ h("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: [
560
+ /* @__PURE__ */ t("title", { children: "Searchcraft Button Icon" }),
561
+ /* @__PURE__ */ t(
503
562
  "path",
504
563
  {
505
564
  d: "M2.725 5.79959L10 10.0079L17.275 5.79959M10 18.3996V9.99959M17.5 13.3329V6.66626C17.4997 6.37399 17.4225 6.08693 17.2763 5.8339C17.13 5.58086 16.9198 5.37073 16.6667 5.22459L10.8333 1.89126C10.58 1.74498 10.2926 1.66797 10 1.66797C9.70744 1.66797 9.42003 1.74498 9.16667 1.89126L3.33333 5.22459C3.08022 5.37073 2.86998 5.58086 2.72372 5.8339C2.57745 6.08693 2.5003 6.37399 2.5 6.66626V13.3329C2.5003 13.6252 2.57745 13.9123 2.72372 14.1653C2.86998 14.4183 3.08022 14.6285 3.33333 14.7746L9.16667 18.1079C9.42003 18.2542 9.70744 18.3312 10 18.3312C10.2926 18.3312 10.58 18.2542 10.8333 18.1079L16.6667 14.7746C16.9198 14.6285 17.13 14.4183 17.2763 14.1653C17.4225 13.9123 17.4997 13.6252 17.5 13.3329Z",
@@ -509,105 +568,125 @@ const p = /* @__PURE__ */ Y(O), nn = "_button_8jqm2_5", tn = "_spinnerMarginRigh
509
568
  strokeLinejoin: "round"
510
569
  }
511
570
  )
512
- ] }), Mn = "_resultContainer_10d68_5", qn = "_interactiveResultContainer_10d68_17", Bn = "_interactiveIconLarge_10d68_33", jn = "_interactiveIconSmall_10d68_45", $n = "_imageContainer_10d68_57", Fn = "_contentContainer_10d68_68", Dn = "_image_10d68_57", An = "_heading_10d68_86", zn = "_subheading_10d68_97", Pn = "_bodyContent_10d68_107", Wn = "_button_10d68_117", d = {
513
- resultContainer: Mn,
514
- interactiveResultContainer: qn,
515
- interactiveIconLarge: Bn,
516
- interactiveIconSmall: jn,
517
- imageContainer: $n,
518
- contentContainer: Fn,
519
- image: Dn,
520
- heading: An,
521
- subheading: zn,
522
- bodyContent: Pn,
523
- button: Wn
524
- }, Qn = ({
525
- buttonCallbackFn: t = () => {
571
+ ] }), Pn = "_resultContainer_10d68_5", On = "_interactiveResultContainer_10d68_17", Un = "_interactiveIconLarge_10d68_33", Wn = "_interactiveIconSmall_10d68_45", zn = "_imageContainer_10d68_57", Gn = "_contentContainer_10d68_68", Qn = "_image_10d68_57", Zn = "_heading_10d68_86", Kn = "_subheading_10d68_97", Jn = "_bodyContent_10d68_107", Hn = "_button_10d68_117", C = {
572
+ resultContainer: Pn,
573
+ interactiveResultContainer: On,
574
+ interactiveIconLarge: Un,
575
+ interactiveIconSmall: Wn,
576
+ imageContainer: zn,
577
+ contentContainer: Gn,
578
+ image: Qn,
579
+ heading: Zn,
580
+ subheading: Kn,
581
+ bodyContent: Jn,
582
+ button: Hn
583
+ }, Z = ({
584
+ buttonCallbackFn: n = () => {
526
585
  },
527
586
  buttonLabel: e = "",
528
- callbackFn: s = () => {
587
+ callbackFn: o = () => {
529
588
  },
530
589
  keyDownCallbackFn: i = () => {
531
590
  },
532
- imageAltText: o = "",
591
+ imageAltText: c = "",
533
592
  interactiveResult: r = !1,
534
593
  imageSrc: a = "",
535
594
  resultBodyContent: l = "",
536
- resultHeading: c = "",
537
- resultSubheading: h = ""
595
+ resultHeading: s = "",
596
+ resultSubheading: u = ""
538
597
  }) => {
539
- const _ = (C) => {
540
- C.stopPropagation(), t();
541
- }, f = () => {
598
+ const p = (g) => {
599
+ g.stopPropagation(), n();
600
+ }, L = () => {
542
601
  if (r)
543
- s();
602
+ o();
544
603
  else
545
604
  return;
546
605
  };
547
- return /* @__PURE__ */ u(
606
+ return /* @__PURE__ */ h(
548
607
  "div",
549
608
  {
550
- className: r ? d.interactiveResultContainer : d.resultContainer,
609
+ className: r ? C.interactiveResultContainer : C.resultContainer,
551
610
  id: "searchcraft-item",
552
- onClick: f,
611
+ onClick: L,
553
612
  onKeyDown: i,
554
613
  children: [
555
- r && /* @__PURE__ */ n("div", { className: d.interactiveIconLarge, children: /* @__PURE__ */ n(q, {}) }),
556
- /* @__PURE__ */ n("div", { className: d.imageContainer, children: /* @__PURE__ */ n("img", { alt: o, className: d.image, src: a }) }),
557
- /* @__PURE__ */ u("div", { className: d.contentContainer, children: [
558
- /* @__PURE__ */ u("h2", { className: d.heading, children: [
559
- c,
614
+ r && /* @__PURE__ */ t("div", { className: C.interactiveIconLarge, children: /* @__PURE__ */ t(U, {}) }),
615
+ /* @__PURE__ */ t("div", { className: C.imageContainer, children: /* @__PURE__ */ t("img", { alt: c, className: C.image, src: a }) }),
616
+ /* @__PURE__ */ h("div", { className: C.contentContainer, children: [
617
+ /* @__PURE__ */ h("h2", { className: C.heading, children: [
618
+ s,
560
619
  " ",
561
- r && /* @__PURE__ */ n("div", { className: d.interactiveIconSmall, children: /* @__PURE__ */ n(q, {}) })
620
+ r && /* @__PURE__ */ t("div", { className: C.interactiveIconSmall, children: /* @__PURE__ */ t(U, {}) })
562
621
  ] }),
563
- /* @__PURE__ */ n("h3", { className: d.subheading, children: h }),
564
- /* @__PURE__ */ n("p", { className: d.bodyContent, children: l }),
565
- /* @__PURE__ */ u("button", { className: d.button, onClick: _, type: "button", children: [
566
- /* @__PURE__ */ n(En, {}),
567
- /* @__PURE__ */ n("span", { children: e })
622
+ /* @__PURE__ */ t("h3", { className: C.subheading, children: u }),
623
+ /* @__PURE__ */ t("p", { className: C.bodyContent, children: l }),
624
+ /* @__PURE__ */ h("button", { className: C.button, onClick: p, type: "button", children: [
625
+ /* @__PURE__ */ t(An, {}),
626
+ /* @__PURE__ */ t("span", { children: e })
568
627
  ] })
569
628
  ] })
570
629
  ]
571
630
  }
572
631
  );
573
- }, Zn = "_resultsContainer_pfxt4_5", Kn = {
574
- resultsContainer: Zn
632
+ }, Vn = "_resultsContainer_684vx_5", Xn = {
633
+ resultsContainer: Vn
575
634
  }, Yn = () => {
576
- var e;
577
- const { searchResults: t } = v();
578
- return /* @__PURE__ */ n("div", { className: Kn.resultsContainer, children: t != null && t.hits ? (e = t == null ? void 0 : t.hits) == null ? void 0 : e.map((s, i) => {
579
- const { doc: o } = s;
580
- return /* @__PURE__ */ n(
581
- Qn,
582
- {
583
- buttonLabel: "View More",
584
- buttonCallbackFn: () => {
585
- console.log("button callback");
586
- },
587
- callbackFn: () => {
588
- console.log("interactive");
635
+ var o, i, c, r;
636
+ const { searchResults: n, query: e } = I();
637
+ return /* @__PURE__ */ h("div", { className: Xn.resultsContainer, children: [
638
+ (i = (o = n == null ? void 0 : n.data) == null ? void 0 : o.hits) == null ? void 0 : i.map((a, l) => {
639
+ const { doc: s } = a;
640
+ return /* @__PURE__ */ t(
641
+ Z,
642
+ {
643
+ buttonLabel: "View More",
644
+ buttonCallbackFn: () => {
645
+ console.log("button callback");
646
+ },
647
+ callbackFn: () => {
648
+ console.log("interactive element");
649
+ },
650
+ interactiveResult: !0,
651
+ imageSrc: s == null ? void 0 : s.poster,
652
+ resultBodyContent: s == null ? void 0 : s.overview,
653
+ resultHeading: s == null ? void 0 : s.title,
654
+ resultSubheading: s == null ? void 0 : s.release_date
589
655
  },
590
- interactiveResult: !0,
591
- imageSrc: o == null ? void 0 : o.poster,
592
- resultBodyContent: o == null ? void 0 : o.overview,
593
- resultHeading: o == null ? void 0 : o.title,
594
- resultSubheading: o == null ? void 0 : o.release_date
595
- },
596
- `${o == null ? void 0 : o.id}-${i}`
597
- );
598
- }) : /* @__PURE__ */ n("div", { children: "no results found" }) });
599
- };
656
+ `${s == null ? void 0 : s.id}-${l}`
657
+ );
658
+ }),
659
+ e.length > 0 && ((r = (c = n == null ? void 0 : n.data) == null ? void 0 : c.hits) == null ? void 0 : r.length) === 0 && /* @__PURE__ */ t(
660
+ A,
661
+ {
662
+ errorMessage: `No search results found for ${e} query`
663
+ }
664
+ )
665
+ ] });
666
+ }, m = () => null;
667
+ m.AutoSearchForm = wn;
668
+ m.BaseSearchForm = Dn;
669
+ m.BaseSearchResult = Z;
670
+ m.BaseSearchResults = Yn;
671
+ m.Button = $;
672
+ m.ClearInputButton = M;
673
+ m.ErrorMessage = A;
674
+ m.Input = j;
675
+ m.InputCaption = F;
676
+ m.InputIcon = q;
677
+ m.InputLabel = D;
678
+ m.Provider = tn;
600
679
  export {
601
- Xn as AutoSearchForm,
602
- Vn as BaseSearchForm,
603
- Qn as BaseSearchResult,
680
+ wn as AutoSearchForm,
681
+ Dn as BaseSearchForm,
682
+ Z as BaseSearchResult,
604
683
  Yn as BaseSearchResults,
605
- w as Button,
606
- hn as ErrorMessage,
607
- A as Input,
608
- z as InputLabel,
609
- Jn as Searchcraft,
610
- Gn as SearchcraftProvider,
611
- v as useSearchcraft
684
+ $ as Button,
685
+ A as ErrorMessage,
686
+ j as Input,
687
+ D as InputLabel,
688
+ et as SearchcraftCore,
689
+ m as default,
690
+ I as useSearchcraft
612
691
  };
613
692
  //# sourceMappingURL=index.js.map