@searchcraft/react-sdk 0.1.0 → 0.1.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.
package/dist/index.js CHANGED
@@ -1,75 +1,68 @@
1
- import { jsx as n, jsxs as l, Fragment as T } from "react/jsx-runtime";
2
- import z, { useMemo as W, useState as y, useContext as Q, useEffect as Z } from "react";
3
- var K = Object.defineProperty, J = (t, e, s) => e in t ? K(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s, S = (t, e, s) => J(t, typeof e != "symbol" ? e + "" : e, s);
4
- class G {
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 {
5
5
  constructor(e) {
6
- if (S(this, "config"), S(this, "searchResult"), S(this, "search", async (s, c) => {
6
+ if (N(this, "config"), N(this, "search", async (s) => {
7
7
  try {
8
- this.config.setIsRequestingTrue();
9
- const o = `http://localhost:3000${this.config.endpointPath}`, r = {
10
- query: s,
11
- mode: c,
8
+ const i = this.config.index.join(","), o = `${this.config.endpointURL}/index/${i}/search`, r = {
9
+ query: s.query,
10
+ mode: s.mode,
12
11
  app: this.config.index
13
12
  }, a = {
14
13
  method: "POST",
15
14
  headers: {
16
15
  "Content-Type": "application/json",
17
- Authorization: `${this.config.apiKey}`
16
+ "Access-Control-Allow-Origin": "*",
17
+ Authorization: this.config.apiKey ? `${this.config.apiKey}` : ""
18
18
  },
19
19
  body: JSON.stringify(r)
20
- }, i = await (await fetch(o, a)).json();
21
- return this.searchResult = i.data, i;
22
- } catch (o) {
23
- return o;
24
- } finally {
25
- this.config.setIsRequestingFalse();
20
+ };
21
+ return await (await fetch(o, a)).json();
22
+ } catch (i) {
23
+ return i;
26
24
  }
27
- }), !e.apiKey || !e.endpointPath || !e.index)
28
- throw new Error(
29
- "API key, endpoint path, and index value(s) must be provided"
30
- );
31
- this.config = e, this.searchResult = null;
25
+ }), !e.endpointURL || !e.index)
26
+ throw new Error("Endpoint URL and Index value(s) must be provided");
27
+ this.config = e;
32
28
  }
33
29
  }
34
- const H = {
30
+ const J = {
35
31
  error: null,
36
- index: "",
32
+ index: [""],
37
33
  isRequesting: !1,
38
34
  mode: "fuzzy",
39
35
  query: "",
40
36
  setQuery: (t) => t,
41
37
  search: async () => null
42
- }, $ = z.createContext(H), Kn = ({
38
+ }, F = Q.createContext(J), Gn = ({
43
39
  children: t,
44
- config: e
40
+ searchcraft: e
45
41
  }) => {
46
- const s = W(
47
- () => new G({
48
- ...e,
49
- setIsRequestingFalse: () => a(!1),
50
- setIsRequestingTrue: () => a(!0)
51
- }),
52
- [e]
53
- ), [c, o] = y(""), [r, a] = y(!1), i = {
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 = {
54
47
  error: null,
55
- index: s.config.index,
56
- isRequesting: r,
48
+ index: e.config.index,
49
+ isRequesting: o,
57
50
  mode: "fuzzy",
58
- query: c,
59
- search: s.search,
60
- searchResult: s.searchResult,
61
- setQuery: o
51
+ query: s,
52
+ search: c,
53
+ searchResults: a,
54
+ setQuery: i
62
55
  };
63
- return /* @__PURE__ */ n($.Provider, { value: i, children: t });
64
- }, D = () => Q($), U = "_formLTR_dvuqa_5", X = "_formRTL_dvuqa_9", Y = "_searchContainer_dvuqa_13", g = {
65
- formLTR: U,
66
- formRTL: X,
67
- searchContainer: Y
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
68
61
  };
69
- function V(t) {
62
+ function Y(t) {
70
63
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
71
64
  }
72
- var F = { exports: {} };
65
+ var D = { exports: {} };
73
66
  /*!
74
67
  Copyright (c) 2018 Jed Watson.
75
68
  Licensed under the MIT License (MIT), see
@@ -80,12 +73,12 @@ var F = { exports: {} };
80
73
  var e = {}.hasOwnProperty;
81
74
  function s() {
82
75
  for (var r = "", a = 0; a < arguments.length; a++) {
83
- var i = arguments[a];
84
- i && (r = o(r, c(i)));
76
+ var l = arguments[a];
77
+ l && (r = o(r, i(l)));
85
78
  }
86
79
  return r;
87
80
  }
88
- function c(r) {
81
+ function i(r) {
89
82
  if (typeof r == "string" || typeof r == "number")
90
83
  return r;
91
84
  if (typeof r != "object")
@@ -95,8 +88,8 @@ var F = { exports: {} };
95
88
  if (r.toString !== Object.prototype.toString && !r.toString.toString().includes("[native code]"))
96
89
  return r.toString();
97
90
  var a = "";
98
- for (var i in r)
99
- e.call(r, i) && r[i] && (a = o(a, i));
91
+ for (var l in r)
92
+ e.call(r, l) && r[l] && (a = o(a, l));
100
93
  return a;
101
94
  }
102
95
  function o(r, a) {
@@ -104,79 +97,149 @@ var F = { exports: {} };
104
97
  }
105
98
  t.exports ? (s.default = s, t.exports = s) : window.classNames = s;
106
99
  })();
107
- })(F);
108
- var O = F.exports;
109
- const _ = /* @__PURE__ */ V(O), nn = "_spinnerContainer_1noam_1", tn = "_spinnerDark_1noam_7", en = "_spinning_1noam_1", rn = "_spinnerLight_1noam_16", I = {
110
- spinnerContainer: nn,
111
- spinnerDark: tn,
112
- spinning: en,
113
- spinnerLight: rn
114
- }, N = () => /* @__PURE__ */ n("div", { className: I.spinnerContainer, children: /* @__PURE__ */ n("div", { className: I.spinnerLight }) }), k = () => /* @__PURE__ */ n("div", { className: I.spinnerContainer, children: /* @__PURE__ */ n("div", { className: I.spinnerDark }) }), sn = "_button_8jqm2_5", an = "_spinnerMarginRight_8jqm2_26", on = "_spinnerMarginLeft_8jqm2_32", cn = "_buttonLabel_8jqm2_38", ln = "_rightandback_8jqm2_1", b = {
115
- button: sn,
116
- spinnerMarginRight: an,
117
- spinnerMarginLeft: on,
118
- buttonLabel: cn,
119
- rightandback: ln
120
- }, E = ({
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 = ({
121
114
  className: t,
122
115
  iconElement: e,
123
116
  iconOnly: s = !1,
124
- iconPosition: c = "left",
125
- isRequesting: o = !1,
126
- label: r = "Search",
127
- onClick: a
128
- }) => /* @__PURE__ */ l(T, { children: [
129
- s && /* @__PURE__ */ n(
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(
179
+ "path",
180
+ {
181
+ 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",
182
+ stroke: "black",
183
+ strokeWidth: "1.5",
184
+ strokeLinecap: "round",
185
+ strokeLinejoin: "round"
186
+ }
187
+ )
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(
191
+ "path",
192
+ {
193
+ d: "M7.5 15.0444L12.5 10.0444L7.5 5.04443",
194
+ stroke: "#737373",
195
+ strokeWidth: "1.5",
196
+ strokeLinecap: "round",
197
+ strokeLinejoin: "round"
198
+ }
199
+ )
200
+ ] }), B = ({
201
+ onClearInput: t,
202
+ rightToLeftOrientation: e = !1
203
+ }) => {
204
+ const { isRequesting: s } = v();
205
+ return e ? /* @__PURE__ */ n(
130
206
  "button",
131
207
  {
132
- className: _(b.button, t),
133
- onClick: a,
134
- type: "submit",
135
- children: o ? /* @__PURE__ */ n(k, {}) : e
208
+ className: p(
209
+ E.inputClearButtonRTL,
210
+ ".sc-clear-input-button-rtl"
211
+ ),
212
+ onClick: t,
213
+ type: "button",
214
+ children: s ? /* @__PURE__ */ n(x, {}) : /* @__PURE__ */ n(M, {})
136
215
  }
137
- ),
138
- !s && /* @__PURE__ */ l(
216
+ ) : /* @__PURE__ */ n(
139
217
  "button",
140
218
  {
141
- className: _(b.button, t),
142
- onClick: a,
143
- type: "submit",
144
- children: [
145
- c === "left" && o ? /* @__PURE__ */ n("div", { className: b.spinnerMarginRight, children: /* @__PURE__ */ n(k, {}) }) : e,
146
- /* @__PURE__ */ n(
147
- "span",
148
- {
149
- className: _(
150
- o && b.buttonLabel,
151
- t
152
- ),
153
- children: r
154
- }
155
- ),
156
- c === "right" && o ? /* @__PURE__ */ n("div", { className: b.spinnerMarginLeft, children: /* @__PURE__ */ n(k, {}) }) : e
157
- ]
219
+ className: p(
220
+ E.inputClearButtonLTR,
221
+ ".sc-clear-input-button-ltr"
222
+ ),
223
+ onClick: t,
224
+ type: "button",
225
+ children: s ? /* @__PURE__ */ n(x, {}) : /* @__PURE__ */ n(M, {})
158
226
  }
159
- )
160
- ] }), un = "_errorMessage_12dc9_5", hn = {
161
- errorMessage: un
162
- }, pn = ({
163
- className: t,
164
- errorMessage: e
165
- }) => /* @__PURE__ */ n("p", { className: _(hn.errorMessage, t), children: e || "Search term is required." }), dn = "_inputCaption_hmjqk_5", _n = "_inputCaptionError_hmjqk_14", mn = "_inputCaptionRTL_hmjqk_24", Cn = "_inputCaptionErrorRTL_hmjqk_34", v = {
166
- inputCaption: dn,
167
- inputCaptionError: _n,
168
- inputCaptionRTL: mn,
169
- inputCaptionErrorRTL: Cn
170
- }, M = ({
227
+ );
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 = ({
171
234
  error: t = !1,
172
235
  inputCaptionClassName: e,
173
236
  inputCaptionValue: s = "Enter Search",
174
- rightToLeftOrientation: c = !1
175
- }) => c ? /* @__PURE__ */ n(
237
+ rightToLeftOrientation: i = !1
238
+ }) => i ? /* @__PURE__ */ n(
176
239
  "p",
177
240
  {
178
- className: _(
179
- t ? v.inputCaptionErrorRTL : v.inputCaptionRTL,
241
+ className: p(
242
+ t ? T.inputCaptionErrorRTL : T.inputCaptionRTL,
180
243
  e
181
244
  ),
182
245
  children: s
@@ -184,16 +247,16 @@ const _ = /* @__PURE__ */ V(O), nn = "_spinnerContainer_1noam_1", tn = "_spinner
184
247
  ) : /* @__PURE__ */ n(
185
248
  "p",
186
249
  {
187
- className: _(
188
- t ? v.inputCaptionError : v.inputCaption,
250
+ className: p(
251
+ t ? T.inputCaptionErrorLTR : T.inputCaptionLTR,
189
252
  e
190
253
  ),
191
254
  children: s
192
255
  }
193
- ), fn = "_inputIcon_101v2_5", gn = "_inputIconRTL_101v2_13", R = {
194
- inputIcon: fn,
195
- inputIconRTL: gn
196
- }, Ln = () => /* @__PURE__ */ l("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: [
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: [
197
260
  /* @__PURE__ */ n("title", { children: "Searchcraft Search Icon" }),
198
261
  /* @__PURE__ */ n(
199
262
  "path",
@@ -205,7 +268,7 @@ const _ = /* @__PURE__ */ V(O), nn = "_spinnerContainer_1noam_1", tn = "_spinner
205
268
  strokeLinejoin: "round"
206
269
  }
207
270
  )
208
- ] }), bn = () => /* @__PURE__ */ l("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: [
271
+ ] }), Nn = () => /* @__PURE__ */ u("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: [
209
272
  /* @__PURE__ */ n("title", { children: "Searchcraft Error Search Icon" }),
210
273
  /* @__PURE__ */ n(
211
274
  "path",
@@ -217,246 +280,224 @@ const _ = /* @__PURE__ */ V(O), nn = "_spinnerContainer_1noam_1", tn = "_spinner
217
280
  strokeLinejoin: "round"
218
281
  }
219
282
  )
220
- ] }), x = ({
283
+ ] }), $ = ({
221
284
  error: t = !1,
222
285
  rightToLeftOrientation: e = !1
223
286
  }) => t ? /* @__PURE__ */ n(
224
287
  "div",
225
288
  {
226
- className: e ? R.inputIconRTL : R.inputIcon,
227
- children: /* @__PURE__ */ n(bn, {})
289
+ className: e ? y.inputIconRTL : y.inputIconLTR,
290
+ children: /* @__PURE__ */ n(Nn, {})
228
291
  }
229
292
  ) : /* @__PURE__ */ n(
230
293
  "div",
231
294
  {
232
- className: e ? R.inputIconRTL : R.inputIcon,
233
- children: /* @__PURE__ */ n(Ln, {})
234
- }
235
- ), w = () => /* @__PURE__ */ l("svg", { width: "22", height: "22", viewBox: "0 0 22 22", fill: "none", children: [
236
- /* @__PURE__ */ n("title", { children: "Searchcraft Clear Input Icon" }),
237
- /* @__PURE__ */ n(
238
- "path",
239
- {
240
- 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",
241
- stroke: "black",
242
- strokeWidth: "1.5",
243
- strokeLinecap: "round",
244
- strokeLinejoin: "round"
245
- }
246
- )
247
- ] }), j = () => /* @__PURE__ */ l("svg", { width: "20", height: "21", viewBox: "0 0 20 21", fill: "none", children: [
248
- /* @__PURE__ */ n("title", { children: "Searchcraft Arrow Right Icon" }),
249
- /* @__PURE__ */ n(
250
- "path",
251
- {
252
- d: "M7.5 15.0444L12.5 10.0444L7.5 5.04443",
253
- stroke: "#737373",
254
- strokeWidth: "1.5",
255
- strokeLinecap: "round",
256
- strokeLinejoin: "round"
257
- }
258
- )
259
- ] }), vn = "_inputClearButton_xi5sa_5", Rn = "_inputClearButtonRTL_xi5sa_19", q = {
260
- inputClearButton: vn,
261
- inputClearButtonRTL: Rn
262
- }, B = ({
263
- isAutoSearch: t = !1,
264
- isRequesting: e = !1,
265
- onClearInput: s,
266
- rightToLeftOrientation: c = !1
267
- }) => c ? /* @__PURE__ */ n(
268
- "button",
269
- {
270
- className: q.inputClearButtonRTL,
271
- onClick: s,
272
- type: "button",
273
- children: e ? /* @__PURE__ */ n(N, {}) : /* @__PURE__ */ n(w, {})
295
+ className: e ? y.inputIconRTL : y.inputIconLTR,
296
+ children: /* @__PURE__ */ n(kn, {})
274
297
  }
275
- ) : /* @__PURE__ */ n(
276
- "button",
277
- {
278
- className: q.inputClearButton,
279
- onClick: s,
280
- type: "button",
281
- children: e ? /* @__PURE__ */ n(N, {}) : /* @__PURE__ */ n(w, {})
282
- }
283
- ), yn = "_inputContainer_17hag_5", In = "_inputContainerRTL_17hag_9", Sn = "_input_17hag_5", kn = "_inputRTL_17hag_35", Tn = "_inputError_17hag_57", Nn = "_inputErrorRTL_17hag_82", f = {
284
- inputContainer: yn,
285
- inputContainerRTL: In,
286
- input: Sn,
287
- inputRTL: kn,
288
- inputError: Tn,
289
- inputErrorRTL: Nn
290
- }, P = ({
298
+ ), A = ({
291
299
  error: t = !1,
292
300
  formClassName: e = "",
293
301
  inputCaptionClassName: s = "",
294
- inputClassName: c = "",
302
+ inputClassName: i = "",
295
303
  inputCaptionValue: o = "",
296
- isRequesting: r = !1,
297
- onClearInput: a,
298
- onSearchInputChange: i,
299
- placeholderValue: d = "Enter Search",
300
- rightToLeftOrientation: u = !1,
304
+ onClearInput: r,
305
+ onSearchInputChange: a,
306
+ placeholderValue: l = "Enter Search",
307
+ rightToLeftOrientation: c = !1,
301
308
  query: h = ""
302
309
  }) => {
303
- const C = u ? f.inputContainerRTL : f.inputContainer;
304
- return /* @__PURE__ */ n("div", { className: _(C, e), children: u ? /* @__PURE__ */ l(T, { children: [
305
- /* @__PURE__ */ n(
306
- "input",
307
- {
308
- className: _(
309
- t ? f.inputErrorRTL : f.inputRTL,
310
- c
310
+ const _ = c ? m.inputContainerRTL : m.inputContainerLTR;
311
+ return /* @__PURE__ */ n(
312
+ "div",
313
+ {
314
+ className: p(
315
+ _,
316
+ e,
317
+ "searchcraft-input-form"
318
+ ),
319
+ children: c ? /* @__PURE__ */ u(k, { children: [
320
+ /* @__PURE__ */ n(
321
+ "input",
322
+ {
323
+ className: p(
324
+ t ? m.inputErrorRTL : m.inputRTL,
325
+ i,
326
+ "searchcraft-input"
327
+ ),
328
+ id: "searchcraft-input-id",
329
+ onChange: a,
330
+ placeholder: l,
331
+ type: "text",
332
+ value: h
333
+ }
311
334
  ),
312
- id: "sc-input",
313
- onChange: i,
314
- placeholder: d,
315
- type: "text",
316
- value: h
317
- }
318
- ),
319
- o && /* @__PURE__ */ n(
320
- M,
321
- {
322
- inputCaptionClassName: s,
323
- inputCaptionValue: o,
324
- rightToLeftOrientation: u
325
- }
326
- ),
327
- h.length > 0 && /* @__PURE__ */ n(
328
- B,
329
- {
330
- isRequesting: r,
331
- onClearInput: a,
332
- rightToLeftOrientation: u
333
- }
334
- ),
335
- /* @__PURE__ */ n(
336
- x,
337
- {
338
- error: t,
339
- rightToLeftOrientation: u
340
- }
341
- )
342
- ] }) : /* @__PURE__ */ l(T, { children: [
343
- /* @__PURE__ */ n(
344
- "input",
345
- {
346
- className: _(
347
- t ? f.inputError : f.input,
348
- c
335
+ o && /* @__PURE__ */ n(
336
+ j,
337
+ {
338
+ inputCaptionClassName: s,
339
+ inputCaptionValue: o,
340
+ rightToLeftOrientation: c
341
+ }
349
342
  ),
350
- id: "sc-input",
351
- onChange: i,
352
- placeholder: d,
353
- type: "text",
354
- value: h
355
- }
356
- ),
357
- o && /* @__PURE__ */ n(
358
- M,
359
- {
360
- inputCaptionClassName: s,
361
- inputCaptionValue: o,
362
- rightToLeftOrientation: u
363
- }
364
- ),
365
- h.length > 0 && /* @__PURE__ */ n(
366
- B,
367
- {
368
- onClearInput: a,
369
- isRequesting: r,
370
- rightToLeftOrientation: u
371
- }
372
- ),
373
- /* @__PURE__ */ n(x, { error: t })
374
- ] }) });
375
- }, En = "_label_1euwf_5", Mn = {
376
- label: En
377
- }, A = ({
343
+ h.length > 0 && /* @__PURE__ */ n(
344
+ B,
345
+ {
346
+ onClearInput: r,
347
+ rightToLeftOrientation: c
348
+ }
349
+ ),
350
+ /* @__PURE__ */ n(
351
+ $,
352
+ {
353
+ error: t,
354
+ rightToLeftOrientation: c
355
+ }
356
+ )
357
+ ] }) : /* @__PURE__ */ u(k, { children: [
358
+ /* @__PURE__ */ n(
359
+ "input",
360
+ {
361
+ className: p(
362
+ t ? m.inputErrorLTR : m.inputLTR,
363
+ i,
364
+ "searchcraft-input"
365
+ ),
366
+ id: "searchcraft-input-id",
367
+ onChange: a,
368
+ placeholder: l,
369
+ type: "text",
370
+ value: h
371
+ }
372
+ ),
373
+ o && /* @__PURE__ */ n(
374
+ j,
375
+ {
376
+ inputCaptionClassName: s,
377
+ inputCaptionValue: o,
378
+ rightToLeftOrientation: c
379
+ }
380
+ ),
381
+ h.length > 0 && /* @__PURE__ */ n(
382
+ B,
383
+ {
384
+ onClearInput: r,
385
+ rightToLeftOrientation: c
386
+ }
387
+ ),
388
+ /* @__PURE__ */ n($, { error: t })
389
+ ] })
390
+ }
391
+ );
392
+ }, xn = "_label_1euwf_5", wn = {
393
+ label: xn
394
+ }, z = ({
378
395
  className: t,
379
396
  label: e = "Enter Search"
380
- }) => /* @__PURE__ */ n("label", { className: _(Mn.label, t), htmlFor: "sc-input", children: e }), Jn = ({
397
+ }) => /* @__PURE__ */ n(
398
+ "label",
399
+ {
400
+ className: p(wn.label, t),
401
+ htmlFor: "searchcraft-input-id",
402
+ children: e
403
+ }
404
+ ), Vn = ({
381
405
  errorMessage: t,
382
406
  handleSubmit: e,
383
407
  labelForInput: s = "Search",
384
- placeholderValue: c = "Enter Search Term",
408
+ placeholderValue: i = "Enter Search Term",
385
409
  rightToLeftOrientation: o = !1
386
410
  }) => {
387
- const { query: r, isRequesting: a, setQuery: i } = D(), [d, u] = y(!1), h = (m) => {
388
- m.preventDefault(), r.trim() === "" ? u(!0) : (u(!1), e(r));
389
- }, C = (m) => i(m.target.value), L = () => i("");
390
- return /* @__PURE__ */ l(
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(
391
415
  "form",
392
416
  {
393
- className: o ? g.formRTL : g.formLTR,
417
+ className: o ? L.formRTL : L.formLTR,
394
418
  onSubmit: h,
395
419
  children: [
396
- /* @__PURE__ */ n(A, { label: s }),
397
- /* @__PURE__ */ l("div", { className: g.searchContainer, children: [
398
- o && /* @__PURE__ */ n(E, { isRequesting: a }),
420
+ /* @__PURE__ */ n(z, { label: s }),
421
+ /* @__PURE__ */ u("div", { className: L.searchContainer, children: [
422
+ o && /* @__PURE__ */ n(w, {}),
399
423
  /* @__PURE__ */ n(
400
- P,
424
+ A,
401
425
  {
402
- error: d,
403
- onClearInput: L,
404
- onSearchInputChange: C,
405
- placeholderValue: c,
426
+ error: l,
427
+ onClearInput: f,
428
+ onSearchInputChange: _,
429
+ placeholderValue: i,
406
430
  query: r,
407
431
  rightToLeftOrientation: o
408
432
  }
409
433
  ),
410
- !o && /* @__PURE__ */ n(E, { isRequesting: a })
434
+ !o && /* @__PURE__ */ n(w, {})
411
435
  ] }),
412
- d && /* @__PURE__ */ n(pn, { errorMessage: t })
436
+ l && /* @__PURE__ */ n(hn, { errorMessage: t })
413
437
  ]
414
438
  }
415
439
  );
416
- }, Gn = ({
417
- handleSubmit: t,
418
- inputCaptionValue: e = "",
419
- labelForInput: s = "Search",
420
- onClearedInput: c = () => {
440
+ }, Xn = ({
441
+ autoSearchFormClass: t = "",
442
+ handleSubmit: e,
443
+ inputCaptionValue: s = "",
444
+ labelForInput: i = "Search",
445
+ onClearedInput: o = () => {
421
446
  },
422
- placeholderValue: o = "Search here",
423
- rightToLeftOrientation: r = !1
447
+ placeholderValue: r = "Search here",
448
+ rightToLeftOrientation: a = !1,
449
+ searchContainerClass: l = ""
424
450
  }) => {
425
- const { isRequesting: a, query: i, setQuery: d } = D(), [u, h] = y(!1), C = (m) => {
426
- m.preventDefault(), d(m.currentTarget.value), i !== m.currentTarget.value && h(!0);
427
- }, L = () => {
428
- d(""), c();
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();
429
455
  };
430
- return Z(() => {
431
- if (u)
432
- t(i), h(!1);
456
+ K(() => {
457
+ if (_)
458
+ e(c), f(!1);
433
459
  else
434
460
  return;
435
- }, [u, t, i]), /* @__PURE__ */ l(
461
+ }, [_, e, c]);
462
+ const W = a ? L.formRTL : L.formLTR;
463
+ return /* @__PURE__ */ u(
436
464
  "form",
437
465
  {
438
- className: r ? g.formRTL : g.formLTR,
439
- onSubmit: (m) => {
440
- m.preventDefault();
466
+ className: p(
467
+ W,
468
+ t,
469
+ "searchcraft-auto-search-form"
470
+ ),
471
+ onSubmit: (R) => {
472
+ R.preventDefault();
441
473
  },
442
474
  children: [
443
- /* @__PURE__ */ n(A, { label: s }),
444
- /* @__PURE__ */ n("div", { className: g.searchContainer, children: /* @__PURE__ */ n(
445
- P,
475
+ /* @__PURE__ */ n(z, { label: i }),
476
+ /* @__PURE__ */ n(
477
+ "div",
446
478
  {
447
- inputCaptionValue: e,
448
- isRequesting: a,
449
- onClearInput: L,
450
- onSearchInputChange: C,
451
- placeholderValue: o,
452
- query: i,
453
- rightToLeftOrientation: r
479
+ className: p(
480
+ L.searchContainer,
481
+ l,
482
+ "searchcraft-input-container"
483
+ ),
484
+ children: /* @__PURE__ */ n(
485
+ A,
486
+ {
487
+ inputCaptionValue: s,
488
+ onClearInput: P,
489
+ onSearchInputChange: C,
490
+ placeholderValue: r,
491
+ query: c,
492
+ rightToLeftOrientation: a
493
+ }
494
+ )
454
495
  }
455
- ) })
496
+ )
456
497
  ]
457
498
  }
458
499
  );
459
- }, xn = () => /* @__PURE__ */ l("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: [
500
+ }, En = () => /* @__PURE__ */ u("svg", { width: "20", height: "20", viewBox: "0 0 20 20", fill: "none", children: [
460
501
  /* @__PURE__ */ n("title", { children: "Searchcraft Button Icon" }),
461
502
  /* @__PURE__ */ n(
462
503
  "path",
@@ -468,77 +509,105 @@ const _ = /* @__PURE__ */ V(O), nn = "_spinnerContainer_1noam_1", tn = "_spinner
468
509
  strokeLinejoin: "round"
469
510
  }
470
511
  )
471
- ] }), wn = "_resultContainer_10d68_5", jn = "_interactiveResultContainer_10d68_17", qn = "_interactiveIconLarge_10d68_33", Bn = "_interactiveIconSmall_10d68_45", $n = "_imageContainer_10d68_57", Dn = "_contentContainer_10d68_68", Fn = "_image_10d68_57", Pn = "_heading_10d68_86", An = "_subheading_10d68_97", zn = "_bodyContent_10d68_107", Wn = "_button_10d68_117", p = {
472
- resultContainer: wn,
473
- interactiveResultContainer: jn,
474
- interactiveIconLarge: qn,
475
- interactiveIconSmall: Bn,
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,
476
517
  imageContainer: $n,
477
- contentContainer: Dn,
478
- image: Fn,
479
- heading: Pn,
480
- subheading: An,
481
- bodyContent: zn,
518
+ contentContainer: Fn,
519
+ image: Dn,
520
+ heading: An,
521
+ subheading: zn,
522
+ bodyContent: Pn,
482
523
  button: Wn
483
- }, Hn = ({
524
+ }, Qn = ({
484
525
  buttonCallbackFn: t = () => {
485
526
  },
486
527
  buttonLabel: e = "",
487
528
  callbackFn: s = () => {
488
529
  },
489
- keyDownCallbackFn: c = () => {
530
+ keyDownCallbackFn: i = () => {
490
531
  },
491
532
  imageAltText: o = "",
492
533
  interactiveResult: r = !1,
493
534
  imageSrc: a = "",
494
- resultBodyContent: i = "",
495
- resultHeading: d = "",
496
- resultSubheading: u = ""
535
+ resultBodyContent: l = "",
536
+ resultHeading: c = "",
537
+ resultSubheading: h = ""
497
538
  }) => {
498
- const h = (L) => {
499
- L.stopPropagation(), t();
500
- }, C = () => {
539
+ const _ = (C) => {
540
+ C.stopPropagation(), t();
541
+ }, f = () => {
501
542
  if (r)
502
543
  s();
503
544
  else
504
545
  return;
505
546
  };
506
- return /* @__PURE__ */ l(
547
+ return /* @__PURE__ */ u(
507
548
  "div",
508
549
  {
509
- className: r ? p.interactiveResultContainer : p.resultContainer,
550
+ className: r ? d.interactiveResultContainer : d.resultContainer,
510
551
  id: "searchcraft-item",
511
- onClick: C,
512
- onKeyDown: c,
552
+ onClick: f,
553
+ onKeyDown: i,
513
554
  children: [
514
- r && /* @__PURE__ */ n("div", { className: p.interactiveIconLarge, children: /* @__PURE__ */ n(j, {}) }),
515
- /* @__PURE__ */ n("div", { className: p.imageContainer, children: /* @__PURE__ */ n("img", { alt: o, className: p.image, src: a }) }),
516
- /* @__PURE__ */ l("div", { className: p.contentContainer, children: [
517
- /* @__PURE__ */ l("h2", { className: p.heading, children: [
518
- d,
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,
519
560
  " ",
520
- r && /* @__PURE__ */ n("div", { className: p.interactiveIconSmall, children: /* @__PURE__ */ n(j, {}) })
561
+ r && /* @__PURE__ */ n("div", { className: d.interactiveIconSmall, children: /* @__PURE__ */ n(q, {}) })
521
562
  ] }),
522
- /* @__PURE__ */ n("h3", { className: p.subheading, children: u }),
523
- /* @__PURE__ */ n("p", { className: p.bodyContent, children: i }),
524
- /* @__PURE__ */ l("button", { className: p.button, onClick: h, type: "button", children: [
525
- /* @__PURE__ */ n(xn, {}),
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, {}),
526
567
  /* @__PURE__ */ n("span", { children: e })
527
568
  ] })
528
569
  ] })
529
570
  ]
530
571
  }
531
572
  );
573
+ }, Zn = "_resultsContainer_pfxt4_5", Kn = {
574
+ resultsContainer: Zn
575
+ }, 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");
589
+ },
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" }) });
532
599
  };
533
600
  export {
534
- Gn as AutoSearchForm,
535
- Jn as BaseSearchForm,
536
- Hn as BaseSearchResult,
537
- E as Button,
538
- pn as ErrorMessage,
539
- P as Input,
540
- A as InputLabel,
541
- Kn as SearchcraftProvider,
542
- D as useSearchcraft
601
+ Xn as AutoSearchForm,
602
+ Vn as BaseSearchForm,
603
+ Qn as BaseSearchResult,
604
+ 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
543
612
  };
544
613
  //# sourceMappingURL=index.js.map