@indxsearch/intrface 2.1.0 → 3.0.0-alpha.20260617

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.es.js CHANGED
@@ -1,1712 +1,1702 @@
1
- var xt = Object.defineProperty;
2
- var vt = (r, o, u) => o in r ? xt(r, o, { enumerable: !0, configurable: !0, writable: !0, value: u }) : r[o] = u;
3
- var rt = (r, o, u) => vt(r, typeof o != "symbol" ? o + "" : o, u);
4
1
  import "@indxsearch/systm/styles.css";
5
- import te, { createContext as bt, useRef as he, useState as G, useEffect as ie, useCallback as ae, useContext as yt, memo as ct, useMemo as Ge, Component as jt } from "react";
6
- import { SearchField as St, Button as ye, FilterPanelBase as be, ToggleSwitch as re, Checkbox as nt, Slider as ut, InputField as le, Select as Ct, RadioButton as wt } from "@indxsearch/systm";
7
- var Be = { exports: {} }, Pe = {};
8
- /**
9
- * @license React
10
- * react-jsx-runtime.production.js
11
- *
12
- * Copyright (c) Meta Platforms, Inc. and affiliates.
13
- *
14
- * This source code is licensed under the MIT license found in the
15
- * LICENSE file in the root directory of this source tree.
16
- */
17
- var st;
18
- function kt() {
19
- if (st) return Pe;
20
- st = 1;
21
- var r = Symbol.for("react.transitional.element"), o = Symbol.for("react.fragment");
22
- function u(s, c, p) {
23
- var S = null;
24
- if (p !== void 0 && (S = "" + p), c.key !== void 0 && (S = "" + c.key), "key" in c) {
25
- p = {};
26
- for (var m in c)
27
- m !== "key" && (p[m] = c[m]);
28
- } else p = c;
29
- return c = p.ref, {
30
- $$typeof: r,
31
- type: s,
32
- key: S,
33
- ref: c !== void 0 ? c : null,
34
- props: p
35
- };
36
- }
37
- return Pe.Fragment = o, Pe.jsx = u, Pe.jsxs = u, Pe;
2
+ import e, { Component as t, createContext as n, memo as r, useCallback as i, useContext as a, useEffect as o, useMemo as s, useRef as c, useState as l } from "react";
3
+ import { SystemState as u } from "@indxsearch/indx-types";
4
+ import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
5
+ import { Button as m, Checkbox as h, FilterPanelBase as g, InputField as _, RadioButton as v, SearchField as y, Select as b, Slider as x, ToggleSwitch as S } from "@indxsearch/systm";
6
+ import { ArrowDown as C, ArrowRight as w, Indx as T, X_or_error as E } from "@indxsearch/pixl";
7
+ //#region src/context/useIndxAuth.ts
8
+ function D({ url: e, team: t, dataset: n, preAuthenticatedToken: r, enableDebugLogs: i = !1 }) {
9
+ let [a, s] = l(null), [c, d] = l(!0), [f, p] = l([]), [m, h] = l([]), [g, _] = l([]), [v, y] = l({}), [b, x] = l({}), [S, C] = l(0);
10
+ return o(() => {
11
+ (async () => {
12
+ try {
13
+ if (!r) throw console.error("[Auth] ❌ Missing bearer token"), console.error("[Auth] 💡 Pass preAuthenticatedToken to SearchProvider (create a token on the IndxCloudApi website)"), Error("A bearer token is required. Check console for instructions.");
14
+ if (!e) throw console.error("[Auth] ❌ Missing INDX server URL"), console.error("[Auth] 💡 Pass a url to SearchProvider"), Error("INDX server URL is required. Check console for instructions.");
15
+ if (!n) throw console.error("[Auth] ❌ Missing dataset name"), console.error("[Auth] 💡 Pass dataset=\"your-dataset-name\" to SearchProvider"), Error("Dataset name is required. Check console for instructions.");
16
+ i && console.log("[Auth] Using bearer token");
17
+ let a = r;
18
+ i && console.log("[Auth] 🔓 Opening dataset session...");
19
+ let o = await fetch(`${e}/api/teams/${t}/datasets/${n}/CreateOrOpen/400`, {
20
+ method: "PUT",
21
+ headers: {
22
+ "Content-Type": "application/json",
23
+ Authorization: `Bearer ${a}`
24
+ },
25
+ body: "\"\""
26
+ });
27
+ if (!o.ok) throw console.error("[Auth] ❌ CreateOrOpen failed:", o.status, await o.text()), Error("Failed to open dataset session.");
28
+ s(a), i && console.log("[Auth] ✅ Dataset session established");
29
+ let c = (e) => fetch(e, {
30
+ method: "GET",
31
+ headers: {
32
+ accept: "text/plain",
33
+ Authorization: `Bearer ${a}`
34
+ }
35
+ });
36
+ i && console.log("[Auth] 🔍 Checking dataset status...");
37
+ let l = await c(`${e}/api/teams/${t}/datasets/${n}/GetStatus`);
38
+ if (!l.ok) {
39
+ if (l.status === 401) throw console.error("[Auth] ❌ Authentication failed (401 Unauthorized)"), console.error("[Auth] 💡 Your token may be expired or invalid"), console.error("[Auth] 💡 Create or refresh your token on the IndxCloudApi website"), Error("Authentication failed (401). Token may be expired. Check console for instructions.");
40
+ if (l.status === 404) throw console.error("[Auth] ❌ Dataset \"" + n + "\" not found (404)"), console.error("[Auth] 💡 Available datasets can be checked with: curl -X GET \"" + e + "/api/me/datasets\" -H \"Authorization: Bearer YOUR_TOKEN\""), console.error("[Auth] 💡 Make sure you spelled the dataset name correctly"), Error("Dataset \"" + n + "\" not found. Check console for instructions.");
41
+ {
42
+ let t = await l.text();
43
+ throw console.error("[Auth] ❌ Failed to get dataset status:", l.status, t), console.error("[Auth] 💡 Check if your INDX server is running at:", e), Error("Failed to connect to INDX server. Check console for details.");
44
+ }
45
+ }
46
+ let d = await l.json();
47
+ i && console.log("[Auth] 📊 Dataset status:", d), d.systemState !== void 0 && d.systemState !== u.Ready && (console.warn("[Auth] ⚠️ Dataset is not ready yet. Current state:", u[d.systemState]), console.warn("[Auth] 💡 Wait for indexing to complete before searching"));
48
+ let f = d.documentCount ?? d.numberOfRecords ?? 0;
49
+ f === 0 ? (console.warn("[Auth] ⚠️ Dataset \"" + n + "\" is empty (0 records)"), console.warn("[Auth] 💡 Add documents to your dataset before searching"), console.warn("[Auth] 💡 Search will work but return no results")) : i && console.log("[Auth] ✅ Dataset has", f, "records");
50
+ let [m, g, v] = await Promise.all([
51
+ c(`${e}/api/teams/${t}/datasets/${n}/GetFilterableFields`),
52
+ c(`${e}/api/teams/${t}/datasets/${n}/GetFacetableFields`),
53
+ c(`${e}/api/teams/${t}/datasets/${n}/GetSortableFields`)
54
+ ]);
55
+ if (!m.ok) throw console.error("[Auth] ❌ GetFilterableFields failed:", m.status, await m.text()), Error("Failed to get filterable fields. Check console for details.");
56
+ if (!g.ok) throw console.error("[Auth] ❌ GetFacetableFields failed:", g.status, await g.text()), Error("Failed to get facetable fields. Check console for details.");
57
+ if (!v.ok) throw console.error("[Auth] ❌ GetSortableFields failed:", v.status, await v.text()), Error("Failed to get sortable fields. Check console for details.");
58
+ let [b, S, w] = await Promise.all([
59
+ m.json().catch((e) => (console.error("Failed to parse GetFilterableFields response:", e), [])),
60
+ g.json().catch((e) => (console.error("Failed to parse GetFacetableFields response:", e), [])),
61
+ v.json().catch((e) => (console.error("Failed to parse GetSortableFields response:", e), []))
62
+ ]);
63
+ p(b || []), h(S || []), _(w || []), C(f);
64
+ let T = { facets: {} };
65
+ try {
66
+ let r = await fetch(`${e}/api/teams/${t}/datasets/${n}/Search`, {
67
+ method: "POST",
68
+ headers: {
69
+ "Content-Type": "application/json",
70
+ Authorization: `Bearer ${a}`
71
+ },
72
+ body: JSON.stringify({
73
+ text: "",
74
+ maxNumberOfRecordsToReturn: 0,
75
+ enableFacets: !0
76
+ })
77
+ });
78
+ r.ok ? T = await r.json().catch((e) => (console.warn("Failed to parse blank search response:", e), { facets: {} })) : (console.warn("Blank search failed:", r.status, r.statusText), console.warn("Continuing without initial facet data - facets will be populated after first search"));
79
+ } catch (e) {
80
+ console.warn("Blank search error:", e), console.warn("Continuing without initial facet data - facets will be populated after first search");
81
+ }
82
+ let E = {};
83
+ if (T.facets) {
84
+ for (let [e, t] of Object.entries(T.facets)) if (Array.isArray(t) && t.length > 0) {
85
+ let n = t.map((e) => Number(e.key)).filter((e) => !isNaN(e));
86
+ n.length > 0 && (E[e] = {
87
+ min: Math.min(...n),
88
+ max: Math.max(...n)
89
+ });
90
+ }
91
+ }
92
+ let D = {};
93
+ if (T.facets) for (let [e, t] of Object.entries(T.facets)) Array.isArray(t) && (D[e] = t.map((e) => e.key));
94
+ y(E), x(D), i && console.log("[Auth] ✅ Initialization complete");
95
+ } catch (t) {
96
+ throw console.error("[Auth] ❌ Initialization failed:", t), (t instanceof Error || typeof t == "object" && t && "message" in t) && console.error("[Auth] 💡 Error:", t.message), t instanceof TypeError && t.message.includes("fetch") && (console.error("[Auth] ❌ Network error - cannot connect to INDX server"), console.error("[Auth] 💡 Check if the server is running at:", e), console.error("[Auth] 💡 Check the url you passed to SearchProvider"), console.error("[Auth] 💡 For local development, it should be: http://localhost:5001")), t;
97
+ } finally {
98
+ d(!1);
99
+ }
100
+ })();
101
+ }, [
102
+ e,
103
+ t,
104
+ n
105
+ ]), {
106
+ token: a,
107
+ isFetchingInitial: c,
108
+ initialFacetStats: v,
109
+ initialFacetKeys: b,
110
+ filterableFields: f,
111
+ facetableFields: m,
112
+ sortableFields: g,
113
+ totalDocumentCount: S
114
+ };
38
115
  }
39
- var He = {};
40
- /**
41
- * @license React
42
- * react-jsx-runtime.development.js
43
- *
44
- * Copyright (c) Meta Platforms, Inc. and affiliates.
45
- *
46
- * This source code is licensed under the MIT license found in the
47
- * LICENSE file in the root directory of this source tree.
48
- */
49
- var ot;
50
- function Rt() {
51
- return ot || (ot = 1, process.env.NODE_ENV !== "production" && (function() {
52
- function r(e) {
53
- if (e == null) return null;
54
- if (typeof e == "function")
55
- return e.$$typeof === Z ? null : e.displayName || e.name || null;
56
- if (typeof e == "string") return e;
57
- switch (e) {
58
- case x:
59
- return "Fragment";
60
- case g:
61
- return "Profiler";
62
- case _:
63
- return "StrictMode";
64
- case b:
65
- return "Suspense";
66
- case d:
67
- return "SuspenseList";
68
- case V:
69
- return "Activity";
70
- }
71
- if (typeof e == "object")
72
- switch (typeof e.tag == "number" && console.error(
73
- "Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
74
- ), e.$$typeof) {
75
- case L:
76
- return "Portal";
77
- case W:
78
- return e.displayName || "Context";
79
- case v:
80
- return (e._context.displayName || "Context") + ".Consumer";
81
- case h:
82
- var a = e.render;
83
- return e = e.displayName, e || (e = a.displayName || a.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
84
- case X:
85
- return a = e.displayName || null, a !== null ? a : r(e.type) || "Memo";
86
- case z:
87
- a = e._payload, e = e._init;
88
- try {
89
- return r(e(a));
90
- } catch {
91
- }
92
- }
93
- return null;
94
- }
95
- function o(e) {
96
- return "" + e;
97
- }
98
- function u(e) {
99
- try {
100
- o(e);
101
- var a = !1;
102
- } catch {
103
- a = !0;
104
- }
105
- if (a) {
106
- a = console;
107
- var y = a.error, F = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
108
- return y.call(
109
- a,
110
- "The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
111
- F
112
- ), o(e);
113
- }
114
- }
115
- function s(e) {
116
- if (e === x) return "<>";
117
- if (typeof e == "object" && e !== null && e.$$typeof === z)
118
- return "<...>";
119
- try {
120
- var a = r(e);
121
- return a ? "<" + a + ">" : "<...>";
122
- } catch {
123
- return "<...>";
124
- }
125
- }
126
- function c() {
127
- var e = O.A;
128
- return e === null ? null : e.getOwner();
129
- }
130
- function p() {
131
- return Error("react-stack-top-frame");
132
- }
133
- function S(e) {
134
- if (pe.call(e, "key")) {
135
- var a = Object.getOwnPropertyDescriptor(e, "key").get;
136
- if (a && a.isReactWarning) return !1;
137
- }
138
- return e.key !== void 0;
139
- }
140
- function m(e, a) {
141
- function y() {
142
- U || (U = !0, console.error(
143
- "%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
144
- a
145
- ));
146
- }
147
- y.isReactWarning = !0, Object.defineProperty(e, "key", {
148
- get: y,
149
- configurable: !0
150
- });
151
- }
152
- function n() {
153
- var e = r(this.type);
154
- return ce[e] || (ce[e] = !0, console.error(
155
- "Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
156
- )), e = this.props.ref, e !== void 0 ? e : null;
157
- }
158
- function C(e, a, y, F, ue, xe) {
159
- var T = y.ref;
160
- return e = {
161
- $$typeof: ne,
162
- type: e,
163
- key: a,
164
- props: y,
165
- _owner: F
166
- }, (T !== void 0 ? T : null) !== null ? Object.defineProperty(e, "ref", {
167
- enumerable: !1,
168
- get: n
169
- }) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
170
- configurable: !1,
171
- enumerable: !1,
172
- writable: !0,
173
- value: 0
174
- }), Object.defineProperty(e, "_debugInfo", {
175
- configurable: !1,
176
- enumerable: !1,
177
- writable: !0,
178
- value: null
179
- }), Object.defineProperty(e, "_debugStack", {
180
- configurable: !1,
181
- enumerable: !1,
182
- writable: !0,
183
- value: ue
184
- }), Object.defineProperty(e, "_debugTask", {
185
- configurable: !1,
186
- enumerable: !1,
187
- writable: !0,
188
- value: xe
189
- }), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
190
- }
191
- function A(e, a, y, F, ue, xe) {
192
- var T = a.children;
193
- if (T !== void 0)
194
- if (F)
195
- if (P(T)) {
196
- for (F = 0; F < T.length; F++)
197
- k(T[F]);
198
- Object.freeze && Object.freeze(T);
199
- } else
200
- console.error(
201
- "React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
202
- );
203
- else k(T);
204
- if (pe.call(a, "key")) {
205
- T = r(e);
206
- var de = Object.keys(a).filter(function(ke) {
207
- return ke !== "key";
208
- });
209
- F = 0 < de.length ? "{key: someKey, " + de.join(": ..., ") + ": ...}" : "{key: someKey}", R[T + F] || (de = 0 < de.length ? "{" + de.join(": ..., ") + ": ...}" : "{}", console.error(
210
- `A props object containing a "key" prop is being spread into JSX:
211
- let props = %s;
212
- <%s {...props} />
213
- React keys must be passed directly to JSX without using spread:
214
- let props = %s;
215
- <%s key={someKey} {...props} />`,
216
- F,
217
- T,
218
- de,
219
- T
220
- ), R[T + F] = !0);
221
- }
222
- if (T = null, y !== void 0 && (u(y), T = "" + y), S(a) && (u(a.key), T = "" + a.key), "key" in a) {
223
- y = {};
224
- for (var ve in a)
225
- ve !== "key" && (y[ve] = a[ve]);
226
- } else y = a;
227
- return T && m(
228
- y,
229
- typeof e == "function" ? e.displayName || e.name || "Unknown" : e
230
- ), C(
231
- e,
232
- T,
233
- y,
234
- c(),
235
- ue,
236
- xe
237
- );
238
- }
239
- function k(e) {
240
- q(e) ? e._store && (e._store.validated = 1) : typeof e == "object" && e !== null && e.$$typeof === z && (e._payload.status === "fulfilled" ? q(e._payload.value) && e._payload.value._store && (e._payload.value._store.validated = 1) : e._store && (e._store.validated = 1));
241
- }
242
- function q(e) {
243
- return typeof e == "object" && e !== null && e.$$typeof === ne;
244
- }
245
- var M = te, ne = Symbol.for("react.transitional.element"), L = Symbol.for("react.portal"), x = Symbol.for("react.fragment"), _ = Symbol.for("react.strict_mode"), g = Symbol.for("react.profiler"), v = Symbol.for("react.consumer"), W = Symbol.for("react.context"), h = Symbol.for("react.forward_ref"), b = Symbol.for("react.suspense"), d = Symbol.for("react.suspense_list"), X = Symbol.for("react.memo"), z = Symbol.for("react.lazy"), V = Symbol.for("react.activity"), Z = Symbol.for("react.client.reference"), O = M.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, pe = Object.prototype.hasOwnProperty, P = Array.isArray, w = console.createTask ? console.createTask : function() {
246
- return null;
247
- };
248
- M = {
249
- react_stack_bottom_frame: function(e) {
250
- return e();
251
- }
252
- };
253
- var U, ce = {}, fe = M.react_stack_bottom_frame.bind(
254
- M,
255
- p
256
- )(), f = w(s(p)), R = {};
257
- He.Fragment = x, He.jsx = function(e, a, y) {
258
- var F = 1e4 > O.recentlyCreatedOwnerStacks++;
259
- return A(
260
- e,
261
- a,
262
- y,
263
- !1,
264
- F ? Error("react-stack-top-frame") : fe,
265
- F ? w(s(e)) : f
266
- );
267
- }, He.jsxs = function(e, a, y) {
268
- var F = 1e4 > O.recentlyCreatedOwnerStacks++;
269
- return A(
270
- e,
271
- a,
272
- y,
273
- !0,
274
- F ? Error("react-stack-top-frame") : fe,
275
- F ? w(s(e)) : f
276
- );
277
- };
278
- })()), He;
116
+ //#endregion
117
+ //#region src/context/buildFilterProxy.ts
118
+ async function O(e, t, n, r, i) {
119
+ if (e.length === 0) return null;
120
+ if (e.length === 1) return e[0];
121
+ let a = e[0];
122
+ for (let o = 1; o < e.length; o++) {
123
+ let s = await i(`${t}/api/teams/${n}/datasets/${r}/CombineFilters`, {
124
+ method: "PUT",
125
+ headers: { "Content-Type": "application/json" },
126
+ body: JSON.stringify({
127
+ a,
128
+ b: e[o],
129
+ useAndOperation: !0
130
+ })
131
+ });
132
+ if (!s.ok) {
133
+ let e = await s.json();
134
+ throw console.error("CombineFilters failed:", e), Error("CombineFilters failed");
135
+ }
136
+ a = await s.json();
137
+ }
138
+ return a;
279
139
  }
280
- var at;
281
- function Mt() {
282
- return at || (at = 1, process.env.NODE_ENV === "production" ? Be.exports = kt() : Be.exports = Rt()), Be.exports;
140
+ async function k(e, t, n, r, i, a) {
141
+ let o = Object.entries(e ?? {}), s = Object.entries(t ?? {}), [c, l] = await Promise.all([Promise.all(o.map(([e, t]) => Promise.all(t.map((t) => a(`${n}/api/teams/${r}/datasets/${i}/CreateValueFilter`, {
142
+ method: "PUT",
143
+ headers: { "Content-Type": "application/json" },
144
+ body: JSON.stringify({
145
+ fieldName: e,
146
+ value: t
147
+ })
148
+ }).then((e) => e.json()))))), Promise.all(s.map(([e, { min: t, max: o }]) => a(`${n}/api/teams/${r}/datasets/${i}/CreateRangeFilter`, {
149
+ method: "PUT",
150
+ headers: { "Content-Type": "application/json" },
151
+ body: JSON.stringify({
152
+ fieldName: e,
153
+ lowerLimit: t,
154
+ upperLimit: o
155
+ })
156
+ }).then((e) => e.json())))]);
157
+ return O([...c.flat(), ...l].filter((e) => e && typeof e.hashString == "string"), n, r, i, a);
283
158
  }
284
- var t = Mt(), Le;
285
- (function(r) {
286
- r[r.Hibernated = -1] = "Hibernated", r[r.Created = 0] = "Created", r[r.Loading = 1] = "Loading", r[r.Loaded = 2] = "Loaded", r[r.Indexing = 3] = "Indexing", r[r.Ready = 4] = "Ready", r[r.Error = 255] = "Error";
287
- })(Le || (Le = {}));
288
- var it;
289
- (function(r) {
290
- r[r.Low = 1] = "Low", r[r.Medium = 2] = "Medium", r[r.High = 3] = "High";
291
- })(it || (it = {}));
292
- const dt = bt(void 0);
293
- function Ft(r, o) {
294
- let u;
295
- const s = (...c) => {
296
- clearTimeout(u), u = setTimeout(() => r(...c), o);
297
- };
298
- return s.cancel = () => clearTimeout(u), s;
159
+ //#endregion
160
+ //#region src/context/useSearchExecution.ts
161
+ function A(e, t) {
162
+ let n, r = (...r) => {
163
+ clearTimeout(n), n = setTimeout(() => e(...r), t);
164
+ };
165
+ return r.cancel = () => clearTimeout(n), r;
299
166
  }
300
- const Kt = ({
301
- children: r,
302
- email: o,
303
- password: u,
304
- url: s,
305
- dataset: c,
306
- allowEmptySearch: p = !1,
307
- maxResults: S = 10,
308
- facetDebounceDelayMillis: m = 500,
309
- // debounce faceted searches only
310
- enableFacets: n = !0,
311
- coverageDepth: C = 500,
312
- removeDuplicates: A = !0,
313
- enableCoverage: k = !0,
314
- initialCoverageSetup: q = {},
315
- enableDebugLogs: M = !1,
316
- preAuthenticatedToken: ne
317
- }) => {
318
- const L = he(0), x = he(void 0), _ = he(!1), g = he(!1), v = he(!1), W = he(!1), [h, b] = G({
319
- query: "",
320
- results: null,
321
- isLoading: !1,
322
- resultsSuppressed: !p,
323
- // Show placeholder if empty search not allowed
324
- facetDebounceDelayMillis: m,
325
- filters: {},
326
- rangeFilters: {},
327
- facetStats: {},
328
- searchSettings: {
329
- maxNumberOfRecordsToReturn: S,
330
- coverageDepth: C,
331
- enableCoverage: k,
332
- removeDuplicates: A,
333
- minimumScore: 0,
334
- showScore: !0,
335
- placeholderText: "Type to search",
336
- coverageSetup: {
337
- // Default values matching Swagger specification
338
- coverWholeQuery: !0,
339
- coverWholeWords: !0,
340
- coverFuzzyWords: !0,
341
- coverJoinedWords: !0,
342
- coverPrefixSuffix: !0,
343
- truncate: !0,
344
- includePatternMatches: !0,
345
- minWordSize: 2,
346
- levenshteinMaxWordSize: 20,
347
- truncateWordHitLimit: 1,
348
- truncateWordHitTolerance: 0,
349
- truncationScore: 255,
350
- ...q
351
- // Allow prop-based override
352
- }
353
- }
354
- });
355
- ie(() => {
356
- M && console.log("SearchContext mounted on client");
357
- }, [M]), ie(() => {
358
- b((l) => ({
359
- ...l,
360
- facetDebounceDelayMillis: m
361
- }));
362
- }, [m]);
363
- const [d, X] = G(null), [z] = G(n), V = ae((l, i = {}) => {
364
- if (!d)
365
- throw new Error("No authentication token available");
366
- return fetch(l, {
367
- ...i,
368
- headers: {
369
- ...i.headers,
370
- Authorization: `Bearer ${d}`
371
- },
372
- credentials: "include"
373
- });
374
- }, [d]), [Z, O] = G([]), [pe, P] = G([]), [w, U] = G([]), [ce, fe] = G(!0), [f, R] = G({}), [e, a] = G({}), [y, F] = G({}), [ue, xe] = G(""), [T, de] = G(""), [ve, ke] = G({}), $ = he(null), I = ae((l) => {
375
- W.current = !1, b((i) => {
376
- const j = Object.keys(i.filters).length > 0, E = Object.keys(i.rangeFilters).length > 0;
377
- return {
378
- ...i,
379
- query: l,
380
- filters: j ? {} : i.filters,
381
- rangeFilters: E ? {} : i.rangeFilters,
382
- searchSettings: {
383
- ...i.searchSettings,
384
- maxNumberOfRecordsToReturn: S
385
- }
386
- };
387
- });
388
- }, [S]), J = ae((l) => {
389
- b((i) => ({
390
- ...i,
391
- facetDebounceDelayMillis: l
392
- }));
393
- }, []), _e = ae((l) => {
394
- b((i) => {
395
- const j = { ...i.searchSettings, ...l };
396
- return l.coverageSetup ? j.coverageSetup = {
397
- ...i.searchSettings.coverageSetup,
398
- ...l.coverageSetup
399
- } : j.coverageSetup = i.searchSettings.coverageSetup, {
400
- ...i,
401
- searchSettings: j
402
- };
403
- });
404
- }, []), Te = ae((l) => {
405
- v.current = !0, b((i) => ({
406
- ...i,
407
- searchSettings: {
408
- ...i.searchSettings,
409
- maxNumberOfRecordsToReturn: l
410
- }
411
- }));
412
- }, []), Ae = ae((l, i) => {
413
- W.current = !0, b((j) => {
414
- const E = { ...j.filters }, H = E[l] || [], B = H.includes(i) ? H.filter((K) => K !== i) : [...H, i];
415
- return B.length ? E[l] = B : delete E[l], {
416
- ...j,
417
- filters: E
418
- };
419
- });
420
- }, []), qe = ae((l, i, j) => {
421
- W.current = !0, b((E) => ({
422
- ...E,
423
- rangeFilters: {
424
- ...E.rangeFilters,
425
- [l]: { min: i, max: j }
426
- }
427
- }));
428
- }, []), ze = ae(() => {
429
- W.current = !0, b((l) => ({
430
- ...l,
431
- filters: {},
432
- rangeFilters: {}
433
- }));
434
- }, []), ft = ae((l, i, j = !0) => {
435
- j && (W.current = !0), b((E) => {
436
- const H = { ...E.filters }, B = { ...E.rangeFilters };
437
- if (i !== void 0) {
438
- const se = (H[l] || []).filter((Q) => Q !== i);
439
- se.length > 0 ? H[l] = se : delete H[l];
440
- } else
441
- delete B[l];
442
- return {
443
- ...E,
444
- filters: H,
445
- rangeFilters: B
446
- };
447
- });
448
- }, []), mt = ae((l, i) => {
449
- b((j) => ({
450
- ...j,
451
- sortBy: l || void 0,
452
- sortAscending: l ? i : void 0
453
- }));
454
- }, []), Xe = ae(async (l, i, j) => {
455
- if (l.length === 0) return null;
456
- if (l.length === 1) return l[0];
457
- let E = l[0];
458
- for (let H = 1; H < l.length; H++) {
459
- const B = await V(`${i}/api/CombineFilters/${j}`, {
460
- // Combine the current filter with the next filter
461
- method: "PUT",
462
- headers: {
463
- "Content-Type": "application/json"
464
- },
465
- body: JSON.stringify({ A: E, B: l[H], useAndOperation: !0 })
466
- });
467
- if (!B.ok) {
468
- const K = await B.json();
469
- throw console.error("CombineFilters failed:", K), new Error("CombineFilters failed");
470
- }
471
- E = await B.json();
472
- }
473
- return E;
474
- }, [V]), Ue = h.searchSettings.maxNumberOfRecordsToReturn, Je = h.searchSettings.enableCoverage, Ye = h.searchSettings.removeDuplicates, Ze = h.searchSettings.coverageDepth, Qe = h.searchSettings.minimumScore, $e = h.sortBy, Ie = h.sortAscending, Ke = h.searchSettings.coverageSetup, et = ae(
475
- async ({ enableFacets: l }) => {
476
- if (!d) return;
477
- const i = ++L.current;
478
- b((j) => ({ ...j, isLoading: !0 }));
479
- try {
480
- const j = Object.entries(h.filters ?? {}), H = (await Promise.all(
481
- j.map(
482
- async ([D, Y]) => Promise.all(
483
- Y.map(
484
- (ee) => V(`${s}/api/CreateValueFilter/${c}`, {
485
- method: "PUT",
486
- headers: {
487
- "Content-Type": "application/json"
488
- },
489
- body: JSON.stringify({ FieldName: D, Value: ee })
490
- }).then((ge) => ge.json())
491
- )
492
- )
493
- )
494
- )).flat(), B = Object.entries(h.rangeFilters ?? {}), K = await Promise.all(
495
- B.map(
496
- ([D, { min: Y, max: ee }]) => V(`${s}/api/CreateRangeFilter/${c}`, {
497
- method: "PUT",
498
- headers: {
499
- "Content-Type": "application/json"
500
- },
501
- body: JSON.stringify({ FieldName: D, LowerLimit: Y, UpperLimit: ee })
502
- }).then((ge) => ge.json())
503
- )
504
- ), se = [...H, ...K].filter(
505
- (D) => D && typeof D.hashString == "string"
506
- ), Q = await Xe(se, s, c), Se = p || h.query.trim() !== "", De = {
507
- text: h.query,
508
- maxNumberOfRecordsToReturn: Se ? Ue : 0,
509
- enableFacets: l,
510
- ...Q ? { filter: Q } : {},
511
- ...$e ? { sortBy: $e } : {},
512
- ...Ie !== void 0 ? { sortAscending: Ie } : {},
513
- enableCoverage: Je,
514
- removeDuplicates: Ye,
515
- coverageDepth: Ze,
516
- coverageSetup: Ke
517
- };
518
- M && console.log("[performSearch] request body:", JSON.stringify(De, null, 2));
519
- const Re = await (await V(`${s}/api/Search/${c}`, {
520
- method: "POST",
521
- headers: {
522
- "Content-Type": "application/json"
523
- },
524
- body: JSON.stringify(De)
525
- })).json(), Ce = Re.truncationIndex ?? -1, we = Re.records || [], Me = we.map((D) => D.documentKey), N = we.map((D) => D.score);
526
- let oe = [];
527
- Se && Me.length > 0 && (oe = (await (await V(`${s}/api/GetJson/${c}`, {
528
- method: "POST",
529
- headers: {
530
- "Content-Type": "application/json"
531
- },
532
- body: JSON.stringify(Me)
533
- })).json()).map((ee, ge) => ({
534
- document: ee,
535
- documentKey: Me[ge],
536
- score: N[ge]
537
- })));
538
- let me = {};
539
- if (l && Re.facets) {
540
- for (const [D, Y] of Object.entries(Re.facets))
541
- if (Array.isArray(Y) && Y.length > 0) {
542
- const ee = Y.map((ge) => Number(ge.key)).filter((ge) => !isNaN(ge));
543
- ee.length > 0 && (me[D] = {
544
- min: Math.min(...ee),
545
- max: Math.max(...ee)
546
- });
547
- }
548
- }
549
- const Ve = h.query !== ue, gt = h.query !== T;
550
- let We = h.facetStats ?? {};
551
- if (Ve ? (We = { ...f, ...me }, F(We), xe(h.query)) : We = { ...y, ...me }, gt && l) {
552
- const D = { ...ve };
553
- for (const [Y, ee] of Object.entries(me))
554
- D[Y] = ee;
555
- ke(D), de(h.query);
556
- }
557
- let Oe = Re.facets;
558
- if (l && (!Oe || Object.keys(Oe).length === 0)) {
559
- Oe = {};
560
- for (const [D, Y] of Object.entries(e))
561
- Oe[D] = Y.map((ee) => ({ key: ee, value: null }));
562
- }
563
- if (i !== L.current)
564
- return;
565
- const pt = oe.filter((D) => {
566
- const Y = h.query.trim();
567
- return Y === "" || Y.length === 1 ? !0 : D.score >= Qe;
568
- });
569
- b((D) => ({
570
- ...D,
571
- results: pt,
572
- resultsSuppressed: !Se,
573
- ...l ? {
574
- facets: Oe,
575
- facetStats: We
576
- } : {},
577
- isLoading: !1,
578
- truncationIndex: Ce
579
- }));
580
- } catch (j) {
581
- if (console.error("[Search] ❌ Search failed:", j), j instanceof TypeError && j.message.includes("fetch") ? (console.error("[Search] ❌ Network error - cannot reach INDX server"), console.error("[Search] 💡 Check if server is running at:", s)) : j instanceof Error && (j.message.includes("401") ? (console.error("[Search] ❌ Authentication failed"), console.error("[Search] 💡 Your token may have expired. Get a fresh token with:"), console.error('[Search] 💡 curl -X POST "' + s + `/api/Login" -H "Content-Type: application/json" -d '{"userEmail":"your@email.com","userPassWord":"yourpassword"}'`)) : j.message.includes("404") ? (console.error("[Search] ❌ Dataset not found"), console.error('[Search] 💡 Check that dataset "' + c + '" exists')) : console.error("[Search] 💡 Error:", j.message)), i !== L.current)
582
- return;
583
- b((E) => ({
584
- ...E,
585
- results: null,
586
- isLoading: !1,
587
- resultsSuppressed: !1,
588
- error: j instanceof Error ? j.message : "Search failed"
589
- }));
590
- }
591
- },
592
- [
593
- h.query,
594
- h.filters,
595
- h.rangeFilters,
596
- $e,
597
- Ie,
598
- Ue,
599
- Je,
600
- Ye,
601
- Ze,
602
- Ke,
603
- Qe,
604
- V,
605
- Xe,
606
- s,
607
- c,
608
- p,
609
- d
610
- ]
611
- );
612
- ie(() => {
613
- x.current = et;
614
- }, [et]);
615
- const je = he(null);
616
- return ie(() => {
617
- var l;
618
- return (l = je.current) == null || l.cancel(), je.current = Ft(() => {
619
- var i;
620
- M && console.log("Debounced searchWithFacets fired"), (i = x.current) == null || i.call(x, { enableFacets: !0 });
621
- }, h.facetDebounceDelayMillis ?? 500), () => {
622
- var i;
623
- (i = je.current) == null || i.cancel();
624
- };
625
- }, [h.facetDebounceDelayMillis]), ie(() => {
626
- var l;
627
- !ce && d && !_.current && (p && ((l = x.current) == null || l.call(x, { enableFacets: z })), _.current = !0);
628
- }, [ce, d, p, z]), ie(() => {
629
- var E, H, B, K, se;
630
- if (!d || !_.current) return;
631
- const l = h.query.trim(), i = l === "" && p;
632
- if (l === "" && !p) {
633
- h.resultsSuppressed || b((Q) => ({
634
- ...Q,
635
- resultsSuppressed: !0
636
- }));
637
- return;
638
- }
639
- return i ? ((E = je.current) == null || E.cancel(), (H = x.current) == null || H.call(x, { enableFacets: z })) : z ? (M && console.log("Search fired"), (B = x.current) == null || B.call(x, { enableFacets: !1 }), (K = je.current) == null || K.call(je)) : (se = x.current) == null || se.call(x, { enableFacets: !1 }), () => {
640
- var Q;
641
- (Q = je.current) == null || Q.cancel();
642
- };
643
- }, [h.query, p, z]), ie(() => {
644
- var E;
645
- const l = W.current;
646
- if (W.current = !1, !_.current || !d) return;
647
- if (!g.current) {
648
- g.current = !0;
649
- return;
650
- }
651
- if (!l)
652
- return;
653
- const i = h.query.trim();
654
- z && !(!p && i === "") && ((E = x.current) == null || E.call(x, { enableFacets: !0 }));
655
- }, [h.filters, h.rangeFilters]), ie(() => {
656
- var j;
657
- if (!_.current || !d) return;
658
- const l = h.query.trim();
659
- z && !(!p && l === "") && ((j = x.current) == null || j.call(x, { enableFacets: !0 }));
660
- }, [$e, Ie]), ie(() => {
661
- var l;
662
- !_.current || !d || v.current && (v.current = !1, (l = x.current) == null || l.call(x, { enableFacets: !1 }));
663
- }, [Ue, d]), ie(() => {
664
- (async () => {
665
- try {
666
- let i;
667
- if (ne)
668
- M && console.log("[Auth] ✅ Using pre-authenticated token"), i = ne;
669
- else {
670
- if (!o || !u)
671
- throw console.error("[Auth] ❌ Missing credentials"), o || (console.error("[Auth] ❌ Missing email"), console.error('[Auth] 💡 Pass email="your@email.com" to SearchProvider')), u || (console.error("[Auth] ❌ Missing password"), console.error('[Auth] 💡 Pass password="yourpassword" to SearchProvider')), new Error("Email and password are required. Check console for instructions.");
672
- if (!s)
673
- throw console.error("[Auth] ❌ Missing INDX server URL"), console.error("[Auth] 💡 Add NEXT_PUBLIC_INDX_URL to your .env.local file"), new Error("INDX server URL is required. Check console for instructions.");
674
- if (!c)
675
- throw console.error("[Auth] ❌ Missing dataset name"), console.error('[Auth] 💡 Pass dataset="your-dataset-name" to SearchProvider'), new Error("Dataset name is required. Check console for instructions.");
676
- M && console.log("[Auth] 🔐 Logging in to get session token...");
677
- const N = await fetch(`${s}/api/Login`, {
678
- method: "POST",
679
- headers: {
680
- "Content-Type": "application/json",
681
- accept: "*/*"
682
- },
683
- credentials: "include",
684
- body: JSON.stringify({
685
- userEmail: o,
686
- userPassWord: u
687
- })
688
- });
689
- if (!N.ok)
690
- throw console.error("[Auth] ❌ Login failed:", N.status, await N.text()), new Error("Login failed. Check your email and password.");
691
- if (i = (await N.json()).token, !i)
692
- throw console.error("[Auth] ❌ No token received from login response"), new Error("No token received from login.");
693
- M && console.log("[Auth] ✅ Login successful, bearer token received (length:", i.length, ")");
694
- }
695
- M && console.log("[Auth] 🔓 Opening dataset session...");
696
- const j = await fetch(`${s}/api/CreateOrOpen/${c}/400`, {
697
- method: "PUT",
698
- headers: {
699
- "Content-Type": "application/json",
700
- Authorization: `Bearer ${i}`
701
- },
702
- body: '""'
703
- });
704
- if (!j.ok)
705
- throw console.error("[Auth] ❌ CreateOrOpen failed:", j.status, await j.text()), new Error("Failed to open dataset session.");
706
- X(i), M && console.log("[Auth] ✅ Dataset session established");
707
- const E = (N) => fetch(N, {
708
- method: "GET",
709
- headers: {
710
- accept: "text/plain",
711
- Authorization: `Bearer ${i}`
712
- },
713
- credentials: "include"
714
- });
715
- M && console.log("[Auth] 🔍 Checking dataset status...");
716
- const H = await E(`${s}/api/GetStatus/${c}`);
717
- if (!H.ok) {
718
- if (H.status === 401)
719
- throw console.error("[Auth] ❌ Authentication failed (401 Unauthorized)"), console.error("[Auth] 💡 Your token may be expired or invalid"), console.error('[Auth] 💡 Get a fresh token with: curl -X POST "' + s + `/api/Login" -H "Content-Type: application/json" -d '{"userEmail":"your@email.com","userPassWord":"yourpassword"}'`), new Error("Authentication failed (401). Token may be expired. Check console for instructions.");
720
- if (H.status === 404)
721
- throw console.error('[Auth] ❌ Dataset "' + c + '" not found (404)'), console.error('[Auth] 💡 Available datasets can be checked with: curl -X GET "' + s + '/api/GetUserDataSets" -H "Authorization: Bearer YOUR_TOKEN"'), console.error("[Auth] 💡 Make sure you spelled the dataset name correctly"), new Error('Dataset "' + c + '" not found. Check console for instructions.');
722
- {
723
- const N = await H.text();
724
- throw console.error("[Auth] ❌ Failed to get dataset status:", H.status, N), console.error("[Auth] 💡 Check if your INDX server is running at:", s), new Error("Failed to connect to INDX server. Check console for details.");
725
- }
726
- }
727
- const B = await H.json();
728
- M && console.log("[Auth] 📊 Dataset status:", B), B.systemState !== void 0 && B.systemState !== Le.Ready && (console.warn("[Auth] ⚠️ Dataset is not ready yet. Current state:", Le[B.systemState]), console.warn("[Auth] 💡 Wait for indexing to complete before searching"));
729
- const K = B.documentCount ?? B.numberOfRecords ?? 0;
730
- K === 0 ? (console.warn('[Auth] ⚠️ Dataset "' + c + '" is empty (0 records)'), console.warn("[Auth] 💡 Add documents to your dataset before searching"), console.warn("[Auth] 💡 Search will work but return no results")) : M && console.log("[Auth] ✅ Dataset has", K, "records");
731
- const [se, Q, Se] = await Promise.all([
732
- E(`${s}/api/GetFilterableFields/${c}`),
733
- E(`${s}/api/GetFacetableFields/${c}`),
734
- E(`${s}/api/GetSortableFields/${c}`)
735
- ]);
736
- if (!se.ok)
737
- throw console.error("[Auth] ❌ GetFilterableFields failed:", se.status, await se.text()), new Error("Failed to get filterable fields. Check console for details.");
738
- if (!Q.ok)
739
- throw console.error("[Auth] ❌ GetFacetableFields failed:", Q.status, await Q.text()), new Error("Failed to get facetable fields. Check console for details.");
740
- if (!Se.ok)
741
- throw console.error("[Auth] ❌ GetSortableFields failed:", Se.status, await Se.text()), new Error("Failed to get sortable fields. Check console for details.");
742
- const De = await se.json().catch((N) => (console.error("Failed to parse GetFilterableFields response:", N), [])), tt = await Q.json().catch((N) => (console.error("Failed to parse GetFacetableFields response:", N), [])), Re = await Se.json().catch((N) => (console.error("Failed to parse GetSortableFields response:", N), []));
743
- O(De || []), P(tt || []), U(Re || []);
744
- let Ce = { facets: {} };
745
- try {
746
- const N = await fetch(`${s}/api/Search/${c}`, {
747
- method: "POST",
748
- headers: {
749
- "Content-Type": "application/json",
750
- Authorization: `Bearer ${i}`
751
- },
752
- credentials: "include",
753
- body: JSON.stringify({ text: "", maxNumberOfRecordsToReturn: 0, enableFacets: !0 })
754
- });
755
- N.ok ? Ce = await N.json().catch((oe) => (console.warn("Failed to parse blank search response:", oe), { facets: {} })) : (console.warn("Blank search failed:", N.status, N.statusText), console.warn("Continuing without initial facet data - facets will be populated after first search"));
756
- } catch (N) {
757
- console.warn("Blank search error:", N), console.warn("Continuing without initial facet data - facets will be populated after first search");
758
- }
759
- const we = {};
760
- if (Ce.facets) {
761
- for (const [N, oe] of Object.entries(Ce.facets))
762
- if (Array.isArray(oe) && oe.length > 0) {
763
- const me = oe.map((Ve) => Number(Ve.key)).filter((Ve) => !isNaN(Ve));
764
- me.length > 0 && (we[N] = {
765
- min: Math.min(...me),
766
- max: Math.max(...me)
767
- });
768
- }
769
- }
770
- const Me = {};
771
- if (Ce.facets)
772
- for (const [N, oe] of Object.entries(Ce.facets))
773
- Array.isArray(oe) && (Me[N] = oe.map((me) => me.key));
774
- $.current = {
775
- facets: Ce.facets,
776
- facetStats: we,
777
- facetKeys: Me
778
- }, R(we), a(Me), ke(we), b((N) => ({
779
- ...N,
780
- facetStats: we,
781
- totalDocumentCount: K
782
- })), M && console.log("[Auth] ✅ Initialization complete");
783
- } catch (i) {
784
- throw console.error("[Auth] ❌ Initialization failed:", i), (i instanceof Error || typeof i == "object" && i !== null && "message" in i) && console.error("[Auth] 💡 Error:", i.message), i instanceof TypeError && i.message.includes("fetch") && (console.error("[Auth] ❌ Network error - cannot connect to INDX server"), console.error("[Auth] 💡 Check if the server is running at:", s), console.error("[Auth] 💡 Check your NEXT_PUBLIC_INDX_URL in .env.local"), console.error("[Auth] 💡 For local development, it should be: http://localhost:5001")), i;
785
- } finally {
786
- fe(!1);
787
- }
788
- })();
789
- }, [o, u, s, c]), /* @__PURE__ */ t.jsx(
790
- dt.Provider,
791
- {
792
- value: {
793
- state: {
794
- ...h,
795
- filterableFields: Z,
796
- facetableFields: pe,
797
- sortableFields: w,
798
- rangeBounds: ve
799
- },
800
- isFetchingInitial: ce,
801
- allowEmptySearch: p,
802
- setQuery: I,
803
- toggleFilter: Ae,
804
- setRangeFilter: qe,
805
- resetFilters: ze,
806
- resetSingleFilter: ft,
807
- setSort: mt,
808
- setDebounceDelay: J,
809
- setSearchSettings: _e,
810
- fetchMoreResults: Te
811
- },
812
- children: r
813
- }
814
- );
815
- }, Ne = () => {
816
- const r = yt(dt);
817
- if (!r)
818
- throw new Error("useSearchContext must be used within a SearchProvider");
819
- return r;
820
- }, er = ({
821
- className: r = "",
822
- autoFocus: o = !1,
823
- inputSize: u = "default",
824
- showClear: s = !0,
825
- showFocus: c = !1,
826
- ...p
827
- }) => {
828
- const { state: { query: S, filters: m, rangeFilters: n, searchSettings: C }, setQuery: A } = Ne();
829
- Object.keys(m).length > 0 || Object.keys(n).length > 0;
830
- const k = S.length > 0;
831
- return /* @__PURE__ */ t.jsx(
832
- St,
833
- {
834
- type: "text",
835
- value: S,
836
- onChange: (q) => A(q.target.value),
837
- placeholder: C.placeholderText,
838
- autoFocus: o,
839
- className: r,
840
- showSearchIcon: !0,
841
- inputSize: u,
842
- showFocusBorder: c,
843
- ...p,
844
- children: s && k && /* @__PURE__ */ t.jsx(
845
- ye,
846
- {
847
- variant: "ghost",
848
- size: "micro",
849
- onClick: () => A(""),
850
- "aria-label": "Clear search",
851
- children: "Clear"
852
- }
853
- )
854
- }
855
- );
856
- }, Et = "_placeholder_1k92x_1", Nt = "_invalid_1k92x_10", _t = "_row_1k92x_14", Tt = "_indexNumber_1k92x_38", At = "_scoreNumber_1k92x_45", Fe = {
857
- placeholder: Et,
858
- invalid: Nt,
859
- row: _t,
860
- indexNumber: Tt,
861
- scoreNumber: At
862
- }, Vt = ({ color: r = "black", size: o = 21 }) => {
863
- const u = 0.7142857142857143, s = o, c = typeof o == "number" ? o * u : `calc(${o} * 0.7142857142857143)`;
864
- return t.jsx("svg", { width: s, height: c, viewBox: "0 0 7 5", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: t.jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M4 0H3V1V2V3H2V2H1V3H2V4H3V5H4V4H5V3H6V2H5V3H4V2V1V0ZM4 3V4H3V3H4Z", fill: r }) });
865
- }, Ot = ({ color: r = "black", size: o = 21 }) => {
866
- const u = 0.7142857142857143, s = o, c = typeof o == "number" ? o * u : `calc(${o} * 0.7142857142857143)`;
867
- return t.jsx("svg", { width: s, height: c, viewBox: "0 0 7 5", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: t.jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M5 0H4V1H5V2H4H3H2H1V3H2H3H4H5V4H4V5H5V4H6V3H7V2H6V1H5V0ZM6 2H5V3H6V2Z", fill: r }) });
868
- }, Pt = ({ color: r = "black", size: o = 21 }) => {
869
- const u = 0.7142857142857143, s = o, c = typeof o == "number" ? o * u : `calc(${o} * 0.7142857142857143)`;
870
- return t.jsx("svg", { width: s, height: c, viewBox: "0 0 7 5", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: t.jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M5 0H6V1H5V0ZM6 1H7V2H6V1ZM0 1H1V2H0V1ZM1 1V0H2V1H1ZM6 3H7V4H6V3ZM6 4V5H5V4H6ZM1 4H2V5H1V4ZM1 4H0V3H1V4ZM2 2H5V3H2V2Z", fill: r }) });
871
- }, ht = ({ color: r = "black", size: o = 21 }) => {
872
- const u = 0.7142857142857143, s = o, c = typeof o == "number" ? o * u : `calc(${o} * 0.7142857142857143)`;
873
- return t.jsx("svg", { width: s, height: c, viewBox: "0 0 7 5", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: t.jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M1 0H2V1H1V0ZM3 2H2V1H3V2ZM4 2H3V3H2V4H1V5H2V4H3V3H4V4H5V5H6V4H5V3H4V2ZM5 1V2H4V1H5ZM5 1V0H6V1H5Z", fill: r }) });
874
- }, tr = ({ fields: r, resultsPerPage: o, children: u }) => {
875
- const {
876
- state: { results: s, resultsSuppressed: c, searchSettings: p, truncationIndex: S, query: m },
877
- isFetchingInitial: n,
878
- fetchMoreResults: C
879
- } = Ne(), A = o ?? 30, [k, q] = G(A), M = he(0), ne = he("");
880
- ie(() => {
881
- const _ = m !== ne.current;
882
- (!s || s.length < M.current || _) && q(A), M.current = (s == null ? void 0 : s.length) ?? 0, ne.current = m;
883
- }, [s, A, m]);
884
- const L = s && s.length > k, x = () => {
885
- const _ = k + A;
886
- q(_), s && _ >= s.length && (!S || S === -1 || S > s.length) && C(s.length + A);
887
- };
888
- return n || c || s === null ? /* @__PURE__ */ t.jsx("div", { className: Fe.placeholder, children: /* @__PURE__ */ t.jsx(Pt, { size: 200, color: "var(--lv5)" }) }) : s.length === 0 ? /* @__PURE__ */ t.jsx("div", { className: Fe.invalid, children: /* @__PURE__ */ t.jsx("p", { children: "No results found." }) }) : /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
889
- /* @__PURE__ */ t.jsx("div", { className: Fe.container, children: (s ?? []).slice(0, k).map((_, g) => {
890
- const v = _.document, W = _.score;
891
- let h;
892
- try {
893
- h = typeof v == "string" ? JSON.parse(v) : v;
894
- } catch {
895
- return /* @__PURE__ */ t.jsx("div", { className: Fe.invalid, children: /* @__PURE__ */ t.jsx("p", { children: "Invalid JSON" }) }, g);
896
- }
897
- let b;
898
- if (r && r.length > 0) {
899
- b = {};
900
- for (const d of r)
901
- d in h && (b[d] = h[d]);
902
- } else
903
- b = { ...h };
904
- for (const d in b) {
905
- const X = b[d];
906
- if (typeof X == "string" && X.startsWith("[") && X.endsWith("]")) {
907
- const V = X.replace(/^\[|\]$/g, "").split(",").map((Z) => Z.trim().replace(/^'|'$/g, "")).filter((Z) => Z.length > 0);
908
- b[d] = V;
909
- }
910
- }
911
- return /* @__PURE__ */ t.jsxs("div", { className: Fe.row, children: [
912
- /* @__PURE__ */ t.jsx("div", { className: Fe.indexNumber, children: g }),
913
- u(b),
914
- p.showScore && /* @__PURE__ */ t.jsx("div", { className: Fe.scoreNumber, children: W })
915
- ] }, g);
916
- }) }),
917
- L && /* @__PURE__ */ t.jsx("div", { style: { textAlign: "center", marginTop: "20px" }, children: /* @__PURE__ */ t.jsx(
918
- ye,
919
- {
920
- variant: "secondary",
921
- size: "micro",
922
- onClick: x,
923
- children: m.trim() === "" ? "Load more" : S !== -1 && S !== void 0 && S > 0 ? `Load results ${k + 1}-${Math.min(k + A, s.length, S)} of ${S}` : "Load more"
924
- }
925
- ) })
926
- ] });
927
- }, Ht = "_list_mwzqq_2", $t = "_count_mwzqq_7", It = "_grid_mwzqq_16", Ee = {
928
- list: Ht,
929
- count: $t,
930
- grid: It
931
- }, rr = ({
932
- field: r,
933
- label: o,
934
- preserveBlankFacetState: u = !1,
935
- preserveBlankFacetStateOrder: s = !1,
936
- sortFacetsBy: c = "histogram",
937
- limit: p = 10,
938
- collapsible: S = !0,
939
- startCollapsed: m = !1,
940
- displayType: n = "checkbox",
941
- layout: C = "list",
942
- showActivePanel: A = !1,
943
- showCount: k = !0,
944
- showNull: q = !1,
945
- displayIfEmptyQuery: M = !0,
946
- displayCondition: ne = (L) => !0
947
- }) => {
948
- const {
949
- state: { facets: L, filterableFields: x, facetableFields: _, filters: g, query: v },
950
- toggleFilter: W,
951
- isFetchingInitial: h,
952
- allowEmptySearch: b
953
- } = Ne(), d = he(null), [X, z] = G(p);
954
- if (ie(() => {
955
- z(p);
956
- }, [L == null ? void 0 : L[r], p]), !b && !v || h || !L || !ne({ query: v ?? "", filters: g, facets: L }) || !M && !v && Object.keys(g).length < 1)
957
- return null;
958
- if (!(x != null && x.includes(r)) || !(_ != null && _.includes(r))) {
959
- const f = [];
960
- return x != null && x.includes(r) || f.push("filterable"), _ != null && _.includes(r) || f.push("facetable"), /* @__PURE__ */ t.jsx(be, { collapsible: !1, children: /* @__PURE__ */ t.jsxs("div", { style: { color: "red", fontSize: "12px" }, children: [
961
- 'Cannot render filter for "',
962
- r,
963
- '": missing ',
964
- f.join(" and "),
965
- "."
966
- ] }) });
967
- }
968
- const V = L == null ? void 0 : L[r];
969
- if (!V || !Array.isArray(V)) return null;
970
- const Z = (g == null ? void 0 : g[r]) ?? [];
971
- u && !d.current && V.length > 0 && (d.current = V.reduce(
972
- (f, R) => (f[R.key] = R.value, f),
973
- {}
974
- ));
975
- const O = /* @__PURE__ */ new Map();
976
- u && d.current ? (Object.keys(d.current).forEach((f) => {
977
- O.set(f, 0);
978
- }), V.forEach((f) => {
979
- O.set(f.key, f.value);
980
- })) : V.forEach((f) => {
981
- O.set(f.key, f.value);
982
- });
983
- const pe = n === "toggle" && O.size === 2 && O.has("true") && (O.has("false") || O.has("null"));
984
- if (O.has("null")) {
985
- const f = O.get("null") ?? 0, R = O.get("false") ?? 0;
986
- O.set("false", (R ?? 0) + f), O.delete("null");
987
- }
988
- if (n === "toggle" && !pe)
989
- return /* @__PURE__ */ t.jsx(be, { collapsible: !1, children: /* @__PURE__ */ t.jsx("div", { className: Ee.count, children: /* @__PURE__ */ t.jsx(
990
- re,
991
- {
992
- label: o,
993
- checked: !1,
994
- onChange: () => {
995
- },
996
- disabled: !0
997
- }
998
- ) }) });
999
- if (pe) {
1000
- const f = O.get("true"), R = typeof f == "number" ? f : null, e = Z.includes("true"), a = R === 0, y = k && (R ?? 0) > 0 ? `${R}` : "";
1001
- return /* @__PURE__ */ t.jsx(be, { collapsible: !1, children: /* @__PURE__ */ t.jsxs("div", { className: Ee.count, children: [
1002
- /* @__PURE__ */ t.jsx(
1003
- re,
1004
- {
1005
- label: o,
1006
- checked: e,
1007
- onChange: () => W(r, "true"),
1008
- disabled: a
1009
- }
1010
- ),
1011
- " ",
1012
- y
1013
- ] }) });
1014
- }
1015
- let P = Array.from(O.entries());
1016
- if (q || (P = P.filter(([f]) => f !== "null")), P.length === 0 && !u)
1017
- return null;
1018
- if (!s) if (c === "alphabetical") {
1019
- const f = P.filter(([, e]) => typeof e == "number" && e > 0).sort(([e], [a]) => e.localeCompare(a)), R = P.filter(([, e]) => e === 0 || e === null).sort(([e], [a]) => e.localeCompare(a));
1020
- P = [...f, ...R];
1021
- } else if (c === "numeric") {
1022
- const f = (a, y) => {
1023
- const F = Number(a), ue = Number(y), xe = !isNaN(F), T = !isNaN(ue);
1024
- return xe && T ? F - ue : a.localeCompare(y);
1025
- }, R = P.filter(([, a]) => typeof a == "number" && a > 0).sort(([a], [y]) => f(a, y)), e = P.filter(([, a]) => a === 0 || a === null).sort(([a], [y]) => f(a, y));
1026
- P = [...R, ...e];
1027
- } else {
1028
- const f = P.filter(([, e]) => typeof e == "number" && e > 0), R = P.filter(([, e]) => e === 0 || e === null);
1029
- P = [...f, ...R];
1030
- }
1031
- const w = typeof p == "number" && P.length > p, U = w ? P.slice(0, X) : P, ce = (f, R) => {
1032
- const e = Z.includes(f), a = R === 0, y = k && (R ?? 0) > 0 ? ` (${R})` : "", F = k && (R ?? 0) > 0 ? R : "";
1033
- switch (n) {
1034
- case "button":
1035
- return C === "list" ? /* @__PURE__ */ t.jsxs("div", { className: Ee.count, children: [
1036
- /* @__PURE__ */ t.jsx(
1037
- ye,
1038
- {
1039
- variant: e ? "primary" : "secondary",
1040
- onClick: () => W(r, f),
1041
- disabled: a,
1042
- size: "micro",
1043
- children: f
1044
- }
1045
- ),
1046
- /* @__PURE__ */ t.jsx("span", { children: F })
1047
- ] }) : /* @__PURE__ */ t.jsx(
1048
- ye,
1049
- {
1050
- variant: e ? "primary" : "secondary",
1051
- onClick: () => W(r, f),
1052
- disabled: a,
1053
- size: "micro",
1054
- children: `${f}${y}`
1055
- }
1056
- );
1057
- case "toggle":
1058
- return /* @__PURE__ */ t.jsx(
1059
- re,
1060
- {
1061
- label: f,
1062
- checked: e,
1063
- onChange: () => W(r, f),
1064
- disabled: a
1065
- }
1066
- );
1067
- case "checkbox":
1068
- default:
1069
- return C === "list" ? /* @__PURE__ */ t.jsxs("div", { className: Ee.count, children: [
1070
- /* @__PURE__ */ t.jsx(
1071
- nt,
1072
- {
1073
- label: f,
1074
- score: "",
1075
- checked: e,
1076
- onChange: () => W(r, f),
1077
- disabled: a
1078
- }
1079
- ),
1080
- /* @__PURE__ */ t.jsx("span", { children: F })
1081
- ] }) : /* @__PURE__ */ t.jsx(
1082
- nt,
1083
- {
1084
- label: f,
1085
- score: y,
1086
- checked: e,
1087
- onChange: () => W(r, f),
1088
- disabled: a
1089
- }
1090
- );
1091
- }
1092
- }, fe = S ? m : !1;
1093
- return /* @__PURE__ */ t.jsx(
1094
- be,
1095
- {
1096
- title: o,
1097
- collapsible: S,
1098
- collapsed: fe,
1099
- children: /* @__PURE__ */ t.jsxs(
1100
- "ul",
1101
- {
1102
- className: C === "grid" ? Ee.grid : Ee.list,
1103
- style: { listStyle: "none", padding: 0, margin: 0 },
1104
- children: [
1105
- U.map(([f, R]) => /* @__PURE__ */ t.jsx("li", { children: ce(f, R) }, f)),
1106
- w && X < P.length && (() => {
1107
- const f = P.length - X, R = Math.min(50, f);
1108
- return /* @__PURE__ */ t.jsx("li", { className: Ee.toggleItem, children: /* @__PURE__ */ t.jsx(
1109
- ye,
1110
- {
1111
- variant: "ghost",
1112
- size: "micro",
1113
- onClick: () => z((e) => e + 50),
1114
- children: `Show ${R} more of ${P.length} total`
1115
- }
1116
- ) });
1117
- })()
1118
- ]
1119
- }
1120
- )
1121
- }
1122
- );
1123
- }, Dt = "_disabledMessage_o89gh_1", lt = {
1124
- disabledMessage: Dt
1125
- }, nr = ({
1126
- field: r,
1127
- label: o,
1128
- expectedMin: u = 0,
1129
- expectedMax: s = 1e3,
1130
- displayType: c = "input",
1131
- collapsible: p = !0,
1132
- startCollapsed: S = !1
1133
- }) => {
1134
- const {
1135
- state: { rangeFilters: m, rangeBounds: n, facetStats: C, query: A, facetDebounceDelayMillis: k },
1136
- setRangeFilter: q,
1137
- resetSingleFilter: M,
1138
- allowEmptySearch: ne,
1139
- isFetchingInitial: L
1140
- } = Ne(), x = (n == null ? void 0 : n[r]) !== void 0, _ = (n == null ? void 0 : n[r]) ?? { min: u, max: s }, g = _.min, v = _.max, W = (C == null ? void 0 : C[r]) ?? _, h = W.min, b = W.max, d = x && g === v, X = d ? u : g, z = d ? s : v, V = m == null ? void 0 : m[r], Z = V ? V.min : g, O = V ? V.max : v, pe = V !== void 0, P = h !== g || b !== v, [w, U] = te.useState([
1141
- Z,
1142
- O
1143
- ]), [ce, fe] = te.useState(!1), [f, R] = te.useState(!1), { finalMin: e, finalMax: a, isValidMin: y, isValidMax: F } = te.useMemo(() => {
1144
- const [$, I] = w, J = Math.max(g, Math.min(v, $)), _e = Math.max(g, Math.min(v, I)), Te = Math.min(J, _e), Ae = Math.max(J, _e), qe = Te >= g && Te < Ae, ze = Ae <= v && Ae > Te;
1145
- return { finalMin: Te, finalMax: Ae, isValidMin: qe, isValidMax: ze };
1146
- }, [w, g, v]);
1147
- te.useEffect(() => {
1148
- if (d)
1149
- return;
1150
- if (w[0] === g && w[1] === v) {
1151
- fe(!1), R(!1);
1152
- return;
1153
- }
1154
- const I = k ?? 500, J = setTimeout(() => {
1155
- fe(!y), R(!F);
1156
- }, 300), _e = setTimeout(() => {
1157
- y && F && (e === g && a === v ? M(r, void 0, !1) : q(r, e, a));
1158
- }, I);
1159
- return () => {
1160
- clearTimeout(J), clearTimeout(_e);
1161
- };
1162
- }, [e, a, y, F, g, v, r, M, q, k, d]), te.useEffect(() => {
1163
- U([Z, O]), fe(!1), R(!1);
1164
- }, [Z, O, r]);
1165
- const ue = te.useCallback(($) => {
1166
- if (d) return;
1167
- const I = Math.max(g, Math.min(b, $[0])), J = Math.max(h, Math.min(v, $[1]));
1168
- U([I, J]);
1169
- }, [d, g, v, h, b]), xe = te.useCallback(($) => {
1170
- if (d) return;
1171
- const I = Math.max(g, Math.min(b, $[0])), J = Math.max(h, Math.min(v, $[1]));
1172
- I === g && J === v ? (U([g, v]), M(r, void 0, !0)) : U([I, J]);
1173
- }, [d, g, v, h, b, r, M]), T = te.useCallback(($) => {
1174
- if (d) return;
1175
- const I = Number($.target.value);
1176
- if (!isNaN(I)) {
1177
- const J = Math.max(g, Math.min(b, I));
1178
- U([J, w[1]]);
1179
- }
1180
- }, [d, w, g, b]), de = te.useCallback(($) => {
1181
- if (d) return;
1182
- const I = Number($.target.value);
1183
- if (!isNaN(I)) {
1184
- const J = Math.max(h, Math.min(v, I));
1185
- U([w[0], J]);
1186
- }
1187
- }, [d, w, h, v]), ve = te.useCallback(() => {
1188
- const $ = w[0], I = Math.max(g, Math.min(b, $));
1189
- I < w[1] ? U([I, w[1]]) : U([g, w[1]]);
1190
- }, [w, g, b]), ke = te.useCallback(() => {
1191
- const $ = w[1], I = Math.max(h, Math.min(v, $));
1192
- I > w[0] ? U([w[0], I]) : U([w[0], v]);
1193
- }, [w, h, v]);
1194
- return L || !ne && !A ? null : c === "slider" ? /* @__PURE__ */ t.jsxs(be, { title: o, collapsed: S, collapsible: p, children: [
1195
- d && /* @__PURE__ */ t.jsxs("div", { className: lt.disabledMessage, children: [
1196
- "No adjustable range (all results have the same value: ",
1197
- g,
1198
- ")."
1199
- ] }),
1200
- /* @__PURE__ */ t.jsx("div", { style: { padding: "10px 10px 20px 10px" }, children: /* @__PURE__ */ t.jsx(
1201
- ut,
1202
- {
1203
- min: X,
1204
- max: z,
1205
- value: d ? [X, z] : [e, a],
1206
- isRange: !0,
1207
- onChange: ($) => ue($),
1208
- onFinalChange: ($) => xe($),
1209
- disabled: d,
1210
- activeMin: h,
1211
- activeMax: b,
1212
- isFaceted: P,
1213
- highlightFaceted: pe,
1214
- "aria-label": o || `Filter by ${r}`
1215
- }
1216
- ) }),
1217
- /* @__PURE__ */ t.jsxs(
1218
- "div",
1219
- {
1220
- style: {
1221
- display: "flex",
1222
- flex: "flex-grow",
1223
- gap: "10px",
1224
- alignItems: "flex-start",
1225
- justifyContent: "space-between"
1226
- },
1227
- children: [
1228
- /* @__PURE__ */ t.jsx(
1229
- le,
1230
- {
1231
- label: "Min:",
1232
- type: "number",
1233
- value: d ? g : w[0],
1234
- min: g,
1235
- max: Math.min(b, w[1] - 1),
1236
- onChange: T,
1237
- onBlur: ve,
1238
- disabled: d,
1239
- isValid: d || !ce
1240
- }
1241
- ),
1242
- /* @__PURE__ */ t.jsx(
1243
- le,
1244
- {
1245
- label: "Max:",
1246
- type: "number",
1247
- value: d ? v : w[1],
1248
- min: Math.max(h, w[0] + 1),
1249
- max: v,
1250
- onChange: de,
1251
- onBlur: ke,
1252
- disabled: d,
1253
- isValid: d || !f
1254
- }
1255
- )
1256
- ]
1257
- }
1258
- )
1259
- ] }) : /* @__PURE__ */ t.jsxs(be, { title: o, children: [
1260
- d && /* @__PURE__ */ t.jsxs("div", { className: lt.disabledMessage, children: [
1261
- "No adjustable range (all results have the same value: ",
1262
- g,
1263
- ")."
1264
- ] }),
1265
- /* @__PURE__ */ t.jsxs("div", { style: { display: "flex", gap: "10px", alignItems: "flex-start" }, children: [
1266
- /* @__PURE__ */ t.jsx(
1267
- le,
1268
- {
1269
- label: "Min:",
1270
- type: "number",
1271
- value: d ? g : w[0],
1272
- min: g,
1273
- max: Math.min(b, w[1] - 1),
1274
- onChange: T,
1275
- onBlur: ve,
1276
- disabled: d,
1277
- isValid: d || !ce
1278
- }
1279
- ),
1280
- /* @__PURE__ */ t.jsx(
1281
- le,
1282
- {
1283
- label: "Max:",
1284
- type: "number",
1285
- value: d ? v : w[1],
1286
- min: Math.max(h, w[0] + 1),
1287
- max: v,
1288
- onChange: de,
1289
- onBlur: ke,
1290
- disabled: d,
1291
- isValid: d || !f
1292
- }
1293
- )
1294
- ] })
1295
- ] });
1296
- }, Wt = "_grid_nvpmn_2", Bt = {
1297
- grid: Wt
1298
- }, Lt = ct(({ field: r, value: o, onReset: u }) => /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsxs(
1299
- ye,
1300
- {
1301
- onClick: u,
1302
- iconRight: /* @__PURE__ */ t.jsx(ht, {}),
1303
- variant: "primary",
1304
- size: "micro",
1305
- children: [
1306
- r,
1307
- ": ",
1308
- o
1309
- ]
1310
- }
1311
- ) })), qt = ct(({ field: r, min: o, max: u, onReset: s }) => /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsxs(
1312
- ye,
1313
- {
1314
- onClick: s,
1315
- iconRight: /* @__PURE__ */ t.jsx(ht, {}),
1316
- variant: "primary",
1317
- size: "micro",
1318
- children: [
1319
- r,
1320
- ": ",
1321
- o,
1322
- " – ",
1323
- u
1324
- ]
1325
- }
1326
- ) }));
1327
- function sr() {
1328
- const {
1329
- state: { filters: r, rangeFilters: o },
1330
- resetFilters: u,
1331
- resetSingleFilter: s
1332
- } = Ne(), c = Ge(
1333
- () => Object.entries(r).map(
1334
- ([m, n]) => n.map((C) => ({ field: m, value: C }))
1335
- ).flat(),
1336
- [r]
1337
- ), p = Ge(
1338
- () => Object.entries(o).map(([m, { min: n, max: C }]) => ({ field: m, min: n, max: C })),
1339
- [o]
1340
- );
1341
- return Ge(
1342
- () => Object.keys(r).length > 0 || Object.keys(o).length > 0,
1343
- [r, o]
1344
- ) ? /* @__PURE__ */ t.jsx(be, { collapsible: !1, title: "Active filters", children: /* @__PURE__ */ t.jsxs("ul", { className: Bt.grid, children: [
1345
- c.map(({ field: m, value: n }) => /* @__PURE__ */ t.jsx(
1346
- Lt,
1347
- {
1348
- field: m,
1349
- value: n,
1350
- onReset: () => s(m, n)
1351
- },
1352
- `${m}-${n}`
1353
- )),
1354
- p.map(({ field: m, min: n, max: C }) => /* @__PURE__ */ t.jsx(
1355
- qt,
1356
- {
1357
- field: m,
1358
- min: n,
1359
- max: C,
1360
- onReset: () => s(m)
1361
- },
1362
- m
1363
- )),
1364
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1365
- ye,
1366
- {
1367
- onClick: u,
1368
- size: "micro",
1369
- variant: "ghost",
1370
- children: "Reset"
1371
- }
1372
- ) })
1373
- ] }) }) : null;
167
+ function j({ state: e, setState: t, authenticatedFetch: n, auth: r, url: a, team: s, dataset: u, allowEmptySearch: d, facetsEnabled: f, enableDebugLogs: p, filtersChangedByUser: m, shouldFetchMore: h }) {
168
+ let g = c(0), _ = c(void 0), v = c(!1), [y, b] = l({}), [x, S] = l(""), [C, w] = l("");
169
+ o(() => {
170
+ r.isFetchingInitial || t((e) => ({
171
+ ...e,
172
+ facetStats: r.initialFacetStats,
173
+ rangeBounds: r.initialFacetStats,
174
+ totalDocumentCount: r.totalDocumentCount,
175
+ filterableFields: r.filterableFields,
176
+ facetableFields: r.facetableFields,
177
+ sortableFields: r.sortableFields
178
+ }));
179
+ }, [
180
+ r.isFetchingInitial,
181
+ r.initialFacetStats,
182
+ r.totalDocumentCount,
183
+ r.filterableFields,
184
+ r.facetableFields,
185
+ r.sortableFields,
186
+ t
187
+ ]);
188
+ let T = e.searchSettings.maxNumberOfRecordsToReturn, E = e.searchSettings.enableCoverage, D = e.searchSettings.removeDuplicates, O = e.searchSettings.coverageDepth, j = e.searchSettings.minimumScore, M = e.searchSettings.coverageSetup, N = e.sortBy, P = e.sortAscending, F = i(async ({ enableFacets: i }) => {
189
+ if (!r.token) return;
190
+ let o = ++g.current;
191
+ if (t((e) => ({
192
+ ...e,
193
+ isLoading: !0
194
+ })), e.query.trim() === "") {
195
+ if (!d) return;
196
+ i = !0;
197
+ }
198
+ try {
199
+ let c = await k(e.filters, e.rangeFilters, a, s, u, n), l = d || e.query.trim() !== "", f = {
200
+ text: e.query,
201
+ maxNumberOfRecordsToReturn: l ? T : 0,
202
+ enableFacets: i,
203
+ ...c ? { filter: c } : {},
204
+ ...N ? { sortBy: N } : {},
205
+ ...P === void 0 ? {} : { sortAscending: P },
206
+ enableCoverage: E,
207
+ removeDuplicates: D,
208
+ coverageDepth: O,
209
+ coverageSetup: M
210
+ };
211
+ p && console.log("[performSearch] request body:", JSON.stringify(f, null, 2));
212
+ let m = await (await n(`${a}/api/teams/${s}/datasets/${u}/Search`, {
213
+ method: "POST",
214
+ headers: { "Content-Type": "application/json" },
215
+ body: JSON.stringify(f)
216
+ })).json(), h = m.truncationIndex ?? -1, _ = m.records || [], v = _.map((e) => e.documentKey), A = _.map((e) => e.score), F = [];
217
+ l && v.length > 0 && (F = (await (await n(`${a}/api/teams/${s}/datasets/${u}/GetJson`, {
218
+ method: "POST",
219
+ headers: { "Content-Type": "application/json" },
220
+ body: JSON.stringify(v)
221
+ })).json()).map((e, t) => ({
222
+ document: e,
223
+ documentKey: v[t],
224
+ score: A[t]
225
+ })));
226
+ let I = {};
227
+ if (i && m.facets) {
228
+ for (let [e, t] of Object.entries(m.facets)) if (Array.isArray(t) && t.length > 0) {
229
+ let n = t.map((e) => Number(e.key)).filter((e) => !isNaN(e));
230
+ n.length > 0 && (I[e] = {
231
+ min: Math.min(...n),
232
+ max: Math.max(...n)
233
+ });
234
+ }
235
+ }
236
+ let L = e.query !== x, R = e.query !== C, z = e.facetStats ?? {};
237
+ if (L ? (z = {
238
+ ...r.initialFacetStats,
239
+ ...I
240
+ }, b(z), S(e.query)) : z = {
241
+ ...y,
242
+ ...I
243
+ }, R && i) {
244
+ let n = { ...e.rangeBounds };
245
+ for (let [e, t] of Object.entries(I)) n[e] = t;
246
+ t((e) => ({
247
+ ...e,
248
+ rangeBounds: n
249
+ })), w(e.query);
250
+ }
251
+ let B = m.facets;
252
+ if (i && (!B || Object.keys(B).length === 0)) {
253
+ B = {};
254
+ for (let [e, t] of Object.entries(r.initialFacetKeys)) B[e] = t.map((e) => ({
255
+ key: e,
256
+ value: null
257
+ }));
258
+ }
259
+ if (o !== g.current) return;
260
+ let V = F.filter((t) => {
261
+ let n = e.query.trim();
262
+ return n === "" || n.length === 1 ? !0 : t.score >= j;
263
+ });
264
+ t((e) => ({
265
+ ...e,
266
+ results: V,
267
+ resultsSuppressed: !l,
268
+ ...i ? {
269
+ facets: B,
270
+ facetStats: z
271
+ } : {},
272
+ isLoading: !1,
273
+ truncationIndex: h
274
+ }));
275
+ } catch (e) {
276
+ if (console.error("[Search] ❌ Search failed:", e), e instanceof TypeError && e.message.includes("fetch") ? (console.error("[Search] ❌ Network error - cannot reach INDX server"), console.error("[Search] 💡 Check if server is running at:", a)) : e instanceof Error && (e.message.includes("401") ? (console.error("[Search] ❌ Authentication failed"), console.error("[Search] 💡 Your token may have expired. Create or refresh it on the IndxCloudApi website.")) : e.message.includes("404") ? (console.error("[Search] ❌ Dataset not found"), console.error("[Search] 💡 Check that dataset \"" + u + "\" exists")) : console.error("[Search] 💡 Error:", e.message)), o !== g.current) return;
277
+ t((t) => ({
278
+ ...t,
279
+ results: null,
280
+ isLoading: !1,
281
+ resultsSuppressed: !1,
282
+ error: e instanceof Error ? e.message : "Search failed"
283
+ }));
284
+ }
285
+ }, [
286
+ e.query,
287
+ e.filters,
288
+ e.rangeFilters,
289
+ e.facetStats,
290
+ N,
291
+ P,
292
+ T,
293
+ E,
294
+ D,
295
+ O,
296
+ M,
297
+ j,
298
+ n,
299
+ r.initialFacetStats,
300
+ r.initialFacetKeys,
301
+ r.token,
302
+ y,
303
+ x,
304
+ C,
305
+ e.rangeBounds,
306
+ a,
307
+ s,
308
+ u,
309
+ d,
310
+ p,
311
+ t
312
+ ]);
313
+ o(() => {
314
+ _.current = F;
315
+ }, [F]);
316
+ let I = c(null);
317
+ o(() => (I.current?.cancel(), I.current = A(() => {
318
+ p && console.log("Debounced searchWithFacets fired"), _.current?.({ enableFacets: !0 });
319
+ }, e.facetDebounceDelayMillis ?? 500), () => {
320
+ I.current?.cancel();
321
+ }), [e.facetDebounceDelayMillis]), o(() => {
322
+ !r.isFetchingInitial && r.token && !v.current && (d && _.current?.({ enableFacets: f }), v.current = !0);
323
+ }, [
324
+ r.isFetchingInitial,
325
+ r.token,
326
+ d,
327
+ f
328
+ ]), o(() => {
329
+ if (!r.token || !v.current) return;
330
+ let n = e.query.trim(), i = n === "" && d;
331
+ if (n === "" && !d) {
332
+ e.resultsSuppressed || t((e) => ({
333
+ ...e,
334
+ resultsSuppressed: !0
335
+ }));
336
+ return;
337
+ }
338
+ return i ? (I.current?.cancel(), _.current?.({ enableFacets: f })) : f ? (p && console.log("Search fired"), _.current?.({ enableFacets: !1 }), I.current?.()) : _.current?.({ enableFacets: !1 }), () => {
339
+ I.current?.cancel();
340
+ };
341
+ }, [
342
+ e.query,
343
+ d,
344
+ f
345
+ ]), o(() => {
346
+ let t = m.current;
347
+ if (m.current = !1, !v.current || !r.token || !t) return;
348
+ let n = e.query.trim();
349
+ f && !(!d && n === "") && _.current?.({ enableFacets: !0 });
350
+ }, [e.filters, e.rangeFilters]), o(() => {
351
+ if (!v.current || !r.token) return;
352
+ let t = e.query.trim();
353
+ f && !(!d && t === "") && _.current?.({ enableFacets: !0 });
354
+ }, [N, P]), o(() => {
355
+ !v.current || !r.token || h.current && (h.current = !1, _.current?.({ enableFacets: !1 }));
356
+ }, [T, r.token]);
1374
357
  }
1375
- const zt = "_radioGroup_nwf7i_6", Ut = {
1376
- radioGroup: zt
1377
- }, or = ({ displayType: r = "dropdown", collapsible: o = !0, startCollapsed: u = !1 }) => {
1378
- const {
1379
- state: { sortableFields: s, sortBy: c, sortAscending: p },
1380
- setSort: S
1381
- } = Ne();
1382
- if (!s || s.length === 0) return null;
1383
- const m = c ? `${c}:${p ? "asc" : "desc"}` : "none", n = [
1384
- { label: "None", value: "none" },
1385
- ...s.flatMap((k) => [
1386
- { label: `${k} (asc)`, value: `${k}:asc` },
1387
- { label: `${k} (desc)`, value: `${k}:desc` }
1388
- ])
1389
- ], C = (k) => {
1390
- if (k === "none" || k === "")
1391
- S(null, !0);
1392
- else {
1393
- const [q, M] = k.split(":");
1394
- S(q, M === "asc");
1395
- }
1396
- }, A = o ? u : !1;
1397
- return /* @__PURE__ */ t.jsx(
1398
- be,
1399
- {
1400
- title: "Sort by",
1401
- collapsible: o,
1402
- collapsed: A,
1403
- children: r === "dropdown" ? /* @__PURE__ */ t.jsx(
1404
- Ct,
1405
- {
1406
- value: m,
1407
- onValueChange: C,
1408
- options: n,
1409
- placeholder: "Select sort...",
1410
- "aria-label": "Sort by"
1411
- }
1412
- ) : /* @__PURE__ */ t.jsx("div", { className: Ut.radioGroup, children: n.map((k) => /* @__PURE__ */ t.jsx(
1413
- wt,
1414
- {
1415
- id: `sort-${k.value}`,
1416
- name: "sort-by",
1417
- value: k.value,
1418
- label: k.label,
1419
- checked: m === k.value,
1420
- onChange: (q) => C(q.target.value)
1421
- },
1422
- k.value
1423
- )) })
1424
- }
1425
- );
1426
- }, Gt = "_list_1y4fk_1", Xt = {
1427
- list: Gt
1428
- };
1429
- function ar() {
1430
- const {
1431
- state: { searchSettings: r },
1432
- setSearchSettings: o
1433
- } = Ne(), [u, s] = G(!1), c = (n, C) => {
1434
- const A = parseInt(C, 10);
1435
- isNaN(A) || o({
1436
- [n]: A
1437
- });
1438
- }, p = (n, C) => {
1439
- o({
1440
- [n]: C
1441
- });
1442
- }, S = (n, C) => {
1443
- const A = parseInt(C, 10);
1444
- isNaN(A) || o({
1445
- coverageSetup: {
1446
- ...r.coverageSetup,
1447
- [n]: A
1448
- }
1449
- });
1450
- }, m = (n, C) => {
1451
- o({
1452
- coverageSetup: {
1453
- ...r.coverageSetup,
1454
- [n]: C
1455
- }
1456
- });
1457
- };
1458
- return /* @__PURE__ */ t.jsx(be, { collapsed: !0, title: "Settings", children: /* @__PURE__ */ t.jsxs("ul", { className: Xt.list, children: [
1459
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1460
- le,
1461
- {
1462
- label: "Max Results",
1463
- type: "number",
1464
- value: r.maxNumberOfRecordsToReturn.toString(),
1465
- onChange: (n) => c("maxNumberOfRecordsToReturn", n.target.value)
1466
- }
1467
- ) }),
1468
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1469
- le,
1470
- {
1471
- label: "Coverage Depth",
1472
- type: "number",
1473
- value: r.coverageDepth.toString(),
1474
- onChange: (n) => c("coverageDepth", n.target.value)
1475
- }
1476
- ) }),
1477
- /* @__PURE__ */ t.jsxs("li", { children: [
1478
- /* @__PURE__ */ t.jsx(
1479
- le,
1480
- {
1481
- label: "Minimum Score",
1482
- type: "number",
1483
- value: r.minimumScore.toString(),
1484
- onChange: (n) => {
1485
- const C = parseFloat(n.target.value);
1486
- isNaN(C) || o({ minimumScore: C });
1487
- }
1488
- }
1489
- ),
1490
- /* @__PURE__ */ t.jsx("div", { style: { padding: "10px 10px 20px 10px" }, children: /* @__PURE__ */ t.jsx(
1491
- ut,
1492
- {
1493
- min: 0,
1494
- max: 255,
1495
- step: 1,
1496
- value: r.minimumScore,
1497
- onChange: (n) => {
1498
- o({ minimumScore: n });
1499
- },
1500
- "aria-label": "Minimum score"
1501
- }
1502
- ) })
1503
- ] }),
1504
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1505
- le,
1506
- {
1507
- label: "Placeholder text",
1508
- type: "text",
1509
- value: r.placeholderText,
1510
- onChange: (n) => {
1511
- o({ placeholderText: n.target.value });
1512
- }
1513
- }
1514
- ) }),
1515
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1516
- re,
1517
- {
1518
- label: "Show score",
1519
- checked: r.showScore,
1520
- onChange: (n) => p("showScore", n)
1521
- }
1522
- ) }),
1523
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1524
- re,
1525
- {
1526
- label: "Enable Coverage",
1527
- checked: r.enableCoverage,
1528
- onChange: (n) => p("enableCoverage", n)
1529
- }
1530
- ) }),
1531
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1532
- re,
1533
- {
1534
- label: "Remove Duplicates",
1535
- checked: r.removeDuplicates,
1536
- onChange: (n) => p("removeDuplicates", n)
1537
- }
1538
- ) }),
1539
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(ye, { variant: "ghost", size: "micro", iconRight: u ? /* @__PURE__ */ t.jsx(Vt, {}) : /* @__PURE__ */ t.jsx(Ot, {}), onClick: () => s((n) => !n), children: u ? "Hide Coverage Setup" : "Show Coverage Setup" }) }),
1540
- u && /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
1541
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1542
- re,
1543
- {
1544
- label: "Cover Whole Query",
1545
- checked: r.coverageSetup.coverWholeQuery,
1546
- onChange: (n) => m("coverWholeQuery", n)
1547
- }
1548
- ) }),
1549
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1550
- re,
1551
- {
1552
- label: "Cover Whole Words",
1553
- checked: r.coverageSetup.coverWholeWords,
1554
- onChange: (n) => m("coverWholeWords", n)
1555
- }
1556
- ) }),
1557
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1558
- re,
1559
- {
1560
- label: "Cover Fuzzy Words",
1561
- checked: r.coverageSetup.coverFuzzyWords,
1562
- onChange: (n) => m("coverFuzzyWords", n)
1563
- }
1564
- ) }),
1565
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1566
- re,
1567
- {
1568
- label: "Cover Joined Words",
1569
- checked: r.coverageSetup.coverJoinedWords,
1570
- onChange: (n) => m("coverJoinedWords", n)
1571
- }
1572
- ) }),
1573
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1574
- re,
1575
- {
1576
- label: "Cover Prefix Suffix",
1577
- checked: r.coverageSetup.coverPrefixSuffix,
1578
- onChange: (n) => m("coverPrefixSuffix", n)
1579
- }
1580
- ) }),
1581
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1582
- re,
1583
- {
1584
- label: "Truncate",
1585
- checked: r.coverageSetup.truncate,
1586
- onChange: (n) => m("truncate", n)
1587
- }
1588
- ) }),
1589
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1590
- re,
1591
- {
1592
- label: "Include Pattern Matches",
1593
- checked: r.coverageSetup.includePatternMatches,
1594
- onChange: (n) => m("includePatternMatches", n)
1595
- }
1596
- ) }),
1597
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1598
- le,
1599
- {
1600
- label: "Levenshtein Max Word Size",
1601
- type: "number",
1602
- value: r.coverageSetup.levenshteinMaxWordSize.toString(),
1603
- onChange: (n) => S("levenshteinMaxWordSize", n.target.value)
1604
- }
1605
- ) }),
1606
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1607
- le,
1608
- {
1609
- label: "Min Word Size",
1610
- type: "number",
1611
- value: r.coverageSetup.minWordSize.toString(),
1612
- onChange: (n) => S("minWordSize", n.target.value)
1613
- }
1614
- ) }),
1615
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1616
- le,
1617
- {
1618
- label: "Truncate Word Hit Limit",
1619
- type: "number",
1620
- value: r.coverageSetup.truncateWordHitLimit.toString(),
1621
- onChange: (n) => S("truncateWordHitLimit", n.target.value)
1622
- }
1623
- ) }),
1624
- /* @__PURE__ */ t.jsx("li", { children: /* @__PURE__ */ t.jsx(
1625
- le,
1626
- {
1627
- label: "Truncate Word Hit Tolerance",
1628
- type: "number",
1629
- value: r.coverageSetup.truncateWordHitTolerance.toString(),
1630
- onChange: (n) => S("truncateWordHitTolerance", n.target.value)
1631
- }
1632
- ) })
1633
- ] })
1634
- ] }) });
358
+ //#endregion
359
+ //#region src/context/SearchContext.tsx
360
+ var M = n(void 0), N = ({ children: e, url: t, team: n, dataset: r, allowEmptySearch: a = !1, maxResults: s = 10, facetDebounceDelayMillis: u = 500, enableFacets: d = !0, coverageDepth: p = 500, removeDuplicates: m = !0, enableCoverage: h = !0, initialCoverageSetup: g = {}, enableDebugLogs: _ = !1, preAuthenticatedToken: v }) => {
361
+ let y = c(!1), b = c(!1), [x, S] = l({
362
+ query: "",
363
+ results: null,
364
+ isLoading: !1,
365
+ resultsSuppressed: !a,
366
+ facetDebounceDelayMillis: u,
367
+ filterableFields: [],
368
+ facetableFields: [],
369
+ sortableFields: [],
370
+ filters: {},
371
+ rangeFilters: {},
372
+ facetStats: {},
373
+ rangeBounds: {},
374
+ searchSettings: {
375
+ maxNumberOfRecordsToReturn: s,
376
+ coverageDepth: p,
377
+ enableCoverage: h,
378
+ removeDuplicates: m,
379
+ minimumScore: 0,
380
+ showScore: !0,
381
+ placeholderText: "Type to search",
382
+ coverageSetup: {
383
+ coverWholeQuery: !0,
384
+ coverWholeWords: !0,
385
+ coverFuzzyWords: !0,
386
+ coverJoinedWords: !0,
387
+ coverPrefixSuffix: !0,
388
+ truncate: !0,
389
+ includePatternMatches: !0,
390
+ minWordSize: 2,
391
+ levenshteinMaxWordSize: 20,
392
+ truncateWordHitLimit: 1,
393
+ truncateWordHitTolerance: 0,
394
+ truncationScore: 65024,
395
+ ...g
396
+ }
397
+ }
398
+ });
399
+ o(() => {
400
+ _ && console.log("SearchContext mounted on client");
401
+ }, [_]), o(() => {
402
+ S((e) => ({
403
+ ...e,
404
+ facetDebounceDelayMillis: u
405
+ }));
406
+ }, [u]);
407
+ let [C] = l(d), w = D({
408
+ url: t,
409
+ team: n,
410
+ dataset: r,
411
+ preAuthenticatedToken: v,
412
+ enableDebugLogs: _
413
+ }), T = i((e, t = {}) => {
414
+ if (!w.token) throw Error("No authentication token available");
415
+ return fetch(e, {
416
+ ...t,
417
+ headers: {
418
+ ...t.headers,
419
+ Authorization: `Bearer ${w.token}`
420
+ }
421
+ });
422
+ }, [w.token]);
423
+ j({
424
+ state: x,
425
+ setState: S,
426
+ authenticatedFetch: T,
427
+ auth: w,
428
+ url: t,
429
+ team: n,
430
+ dataset: r,
431
+ allowEmptySearch: a,
432
+ facetsEnabled: C,
433
+ enableDebugLogs: _,
434
+ filtersChangedByUser: y,
435
+ shouldFetchMore: b
436
+ });
437
+ let E = i((e) => {
438
+ y.current = !1, S((t) => {
439
+ let n = Object.keys(t.filters).length > 0, r = Object.keys(t.rangeFilters).length > 0;
440
+ return {
441
+ ...t,
442
+ query: e,
443
+ filters: n ? {} : t.filters,
444
+ rangeFilters: r ? {} : t.rangeFilters,
445
+ searchSettings: {
446
+ ...t.searchSettings,
447
+ maxNumberOfRecordsToReturn: s
448
+ }
449
+ };
450
+ });
451
+ }, [s]), O = i((e) => {
452
+ S((t) => ({
453
+ ...t,
454
+ facetDebounceDelayMillis: e
455
+ }));
456
+ }, []), k = i((e) => {
457
+ S((t) => {
458
+ let n = {
459
+ ...t.searchSettings,
460
+ ...e
461
+ };
462
+ return e.coverageSetup ? n.coverageSetup = {
463
+ ...t.searchSettings.coverageSetup,
464
+ ...e.coverageSetup
465
+ } : n.coverageSetup = t.searchSettings.coverageSetup, {
466
+ ...t,
467
+ searchSettings: n
468
+ };
469
+ });
470
+ }, []), A = i((e) => {
471
+ b.current = !0, S((t) => ({
472
+ ...t,
473
+ searchSettings: {
474
+ ...t.searchSettings,
475
+ maxNumberOfRecordsToReturn: e
476
+ }
477
+ }));
478
+ }, []), N = i((e, t) => {
479
+ y.current = !0, S((n) => {
480
+ let r = { ...n.filters }, i = r[e] || [], a = i.includes(t) ? i.filter((e) => e !== t) : [...i, t];
481
+ return a.length ? r[e] = a : delete r[e], {
482
+ ...n,
483
+ filters: r
484
+ };
485
+ });
486
+ }, []), P = i((e, t, n) => {
487
+ y.current = !0, S((r) => ({
488
+ ...r,
489
+ rangeFilters: {
490
+ ...r.rangeFilters,
491
+ [e]: {
492
+ min: t,
493
+ max: n
494
+ }
495
+ }
496
+ }));
497
+ }, []), F = i(() => {
498
+ y.current = !0, S((e) => ({
499
+ ...e,
500
+ filters: {},
501
+ rangeFilters: {}
502
+ }));
503
+ }, []), I = i((e, t, n = !0) => {
504
+ n && (y.current = !0), S((n) => {
505
+ let r = { ...n.filters }, i = (r[e] || []).filter((e) => e !== t);
506
+ return i.length > 0 ? r[e] = i : delete r[e], {
507
+ ...n,
508
+ filters: r
509
+ };
510
+ });
511
+ }, []), L = i((e, t = !0) => {
512
+ t && (y.current = !0), S((t) => {
513
+ let n = { ...t.rangeFilters };
514
+ return delete n[e], {
515
+ ...t,
516
+ rangeFilters: n
517
+ };
518
+ });
519
+ }, []), R = i((e, t) => {
520
+ S((n) => ({
521
+ ...n,
522
+ sortBy: e || void 0,
523
+ sortAscending: e ? t : void 0
524
+ }));
525
+ }, []);
526
+ return /* @__PURE__ */ f(M.Provider, {
527
+ value: {
528
+ state: x,
529
+ isFetchingInitial: w.isFetchingInitial,
530
+ allowEmptySearch: a,
531
+ url: t,
532
+ team: n,
533
+ dataset: r,
534
+ authenticatedFetch: T,
535
+ setQuery: E,
536
+ toggleFilter: N,
537
+ setRangeFilter: P,
538
+ resetFilters: F,
539
+ resetSingleFilter: I,
540
+ resetRangeFilter: L,
541
+ setSort: R,
542
+ setDebounceDelay: O,
543
+ setSearchSettings: k,
544
+ fetchMoreResults: A
545
+ },
546
+ children: e
547
+ });
548
+ }, P = () => {
549
+ let e = a(M);
550
+ if (!e) throw Error("useSearchContext must be used within a SearchProvider");
551
+ return e;
552
+ }, F = ({ className: e = "", autoFocus: t = !1, inputSize: n = "default", showClear: r = !0, showFocus: i = !1, ...a }) => {
553
+ let { state: { query: o, filters: s, rangeFilters: c, searchSettings: l }, setQuery: u } = P();
554
+ Object.keys(s).length > 0 || Object.keys(c).length;
555
+ let d = o.length > 0;
556
+ return /* @__PURE__ */ f(y, {
557
+ type: "text",
558
+ value: o,
559
+ onChange: (e) => u(e.target.value),
560
+ placeholder: l.placeholderText,
561
+ autoFocus: t,
562
+ className: e,
563
+ showSearchIcon: !0,
564
+ inputSize: n,
565
+ showFocusBorder: i,
566
+ ...a,
567
+ children: r && d && /* @__PURE__ */ f(m, {
568
+ variant: "ghost",
569
+ size: "micro",
570
+ onClick: () => u(""),
571
+ "aria-label": "Clear search",
572
+ children: "Clear"
573
+ })
574
+ });
575
+ }, I = {
576
+ placeholder: "_placeholder_ee9qi_1",
577
+ invalid: "_invalid_ee9qi_11"
578
+ }, L = {
579
+ row: "_row_1i201_1",
580
+ content: "_content_1i201_19",
581
+ indexNumber: "_indexNumber_1i201_31",
582
+ scoreNumber: "_scoreNumber_1i201_39",
583
+ skeletonBars: "_skeletonBars_1i201_53",
584
+ skeletonBarLg: "_skeletonBarLg_1i201_59",
585
+ fade: "_fade_1i201_1",
586
+ skeletonBarSm: "_skeletonBarSm_1i201_66"
587
+ }, R = ({ skeleton: e = !1, index: t, score: n, showScore: r = !1, children: i, skeletonDelay: a = 0, skeletonWidths: o = [62, 38] }) => /* @__PURE__ */ p("div", {
588
+ className: L.row,
589
+ children: [
590
+ t !== void 0 && /* @__PURE__ */ f("div", {
591
+ className: L.indexNumber,
592
+ children: t
593
+ }),
594
+ /* @__PURE__ */ f("div", {
595
+ className: L.content,
596
+ children: e ? /* @__PURE__ */ p("div", {
597
+ className: L.skeletonBars,
598
+ children: [/* @__PURE__ */ f("div", {
599
+ className: L.skeletonBarLg,
600
+ style: {
601
+ width: `${o[0]}%`,
602
+ animationDelay: `${a}s`
603
+ }
604
+ }), /* @__PURE__ */ f("div", {
605
+ className: L.skeletonBarSm,
606
+ style: {
607
+ width: `${o[1]}%`,
608
+ animationDelay: `${a + .05}s`
609
+ }
610
+ })]
611
+ }) : i
612
+ }),
613
+ r && n !== void 0 && /* @__PURE__ */ f("div", {
614
+ className: L.scoreNumber,
615
+ children: n
616
+ })
617
+ ]
618
+ }), z = {
619
+ wrapper: "_wrapper_81m3c_6",
620
+ skeletonAppear: "_skeletonAppear_81m3c_1"
621
+ }, B = [
622
+ [62, 38],
623
+ [75, 45],
624
+ [58, 33],
625
+ [70, 42],
626
+ [65, 50],
627
+ [55, 35],
628
+ [72, 40],
629
+ [60, 30]
630
+ ], V = ({ rows: e = 6 }) => /* @__PURE__ */ f("div", {
631
+ className: z.wrapper,
632
+ children: Array.from({ length: e }).map((e, t) => /* @__PURE__ */ f(R, {
633
+ skeleton: !0,
634
+ skeletonDelay: t * .1,
635
+ skeletonWidths: B[t % B.length]
636
+ }, t))
637
+ }), H = ({ fields: e, resultsPerPage: t, children: n }) => {
638
+ let { state: { results: r, resultsSuppressed: i, searchSettings: a, truncationIndex: s, query: u }, isFetchingInitial: h, allowEmptySearch: g, fetchMoreResults: _ } = P(), v = t ?? 30, [y, b] = l(v), x = c(0), S = c("");
639
+ o(() => {
640
+ let e = u !== S.current;
641
+ (!r || r.length < x.current || e) && b(v), x.current = r?.length ?? 0, S.current = u;
642
+ }, [
643
+ r,
644
+ v,
645
+ u
646
+ ]);
647
+ let C = r && r.length > y;
648
+ return h ? g ? /* @__PURE__ */ f(V, { rows: v }) : /* @__PURE__ */ f("div", {
649
+ className: I.placeholder,
650
+ children: /* @__PURE__ */ f(T, {
651
+ size: 200,
652
+ color: "var(--lv5)"
653
+ })
654
+ }) : i || r === null ? /* @__PURE__ */ f("div", {
655
+ className: I.placeholder,
656
+ children: /* @__PURE__ */ f(T, {
657
+ size: 200,
658
+ color: "var(--lv5)"
659
+ })
660
+ }) : r.length === 0 ? /* @__PURE__ */ f("div", {
661
+ className: I.invalid,
662
+ children: /* @__PURE__ */ f("p", { children: "No results found." })
663
+ }) : /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f("div", { children: (r ?? []).slice(0, y).map((t, r) => {
664
+ let i = t.document, o = t.score, s;
665
+ try {
666
+ s = typeof i == "string" ? JSON.parse(i) : i;
667
+ } catch {
668
+ return /* @__PURE__ */ f("div", {
669
+ className: I.invalid,
670
+ children: /* @__PURE__ */ f("p", { children: "Invalid JSON" })
671
+ }, r);
672
+ }
673
+ let c;
674
+ if (e && e.length > 0) {
675
+ c = {};
676
+ for (let t of e) t in s && (c[t] = s[t]);
677
+ } else c = { ...s };
678
+ for (let e in c) {
679
+ let t = c[e];
680
+ if (typeof t == "string" && t.startsWith("[") && t.endsWith("]")) {
681
+ let n = t.replace(/^\[|\]$/g, "");
682
+ c[e] = n.split(",").map((e) => e.trim().replace(/^'|'$/g, "")).filter((e) => e.length > 0);
683
+ }
684
+ }
685
+ return /* @__PURE__ */ f(R, {
686
+ index: r,
687
+ score: o,
688
+ showScore: a.showScore,
689
+ children: n(c)
690
+ }, r);
691
+ }) }), C && /* @__PURE__ */ f("div", {
692
+ style: {
693
+ textAlign: "center",
694
+ marginTop: "20px"
695
+ },
696
+ children: /* @__PURE__ */ f(m, {
697
+ variant: "secondary",
698
+ size: "micro",
699
+ onClick: () => {
700
+ let e = y + v;
701
+ b(e), r && e >= r.length && (!s || s === -1 || s > r.length) && _(r.length + v);
702
+ },
703
+ children: u.trim() === "" ? "Load more" : s !== -1 && s !== void 0 && s > 0 ? `Load results ${y + 1}-${Math.min(y + v, r.length, s)} of ${s}` : "Load more"
704
+ })
705
+ })] });
706
+ }, U = {
707
+ row: "_row_ujwhc_1",
708
+ title: "_title_ujwhc_8"
709
+ }, ee = ({ variant: e = "default", children: t }) => /* @__PURE__ */ f("div", {
710
+ className: [U.row, e === "title" ? U.title : ""].filter(Boolean).join(" "),
711
+ children: t
712
+ }), W = {
713
+ bar: "_bar_145f5_12",
714
+ skeletonAppear: "_skeletonAppear_145f5_1",
715
+ fade: "_fade_145f5_1",
716
+ listRows: "_listRows_145f5_19",
717
+ sliderArea: "_sliderArea_145f5_25",
718
+ sliderTrack: "_sliderTrack_145f5_32",
719
+ inputRow: "_inputRow_145f5_40",
720
+ inputBar: "_inputBar_145f5_45"
721
+ }, G = [
722
+ 65,
723
+ 80,
724
+ 55,
725
+ 72,
726
+ 60,
727
+ 75,
728
+ 50,
729
+ 68
730
+ ], K = ({ title: e, rows: t = 5, variant: n = "list", collapsible: r = !0, startCollapsed: i = !1 }) => /* @__PURE__ */ f(g, {
731
+ title: e,
732
+ collapsible: r,
733
+ collapsed: i,
734
+ children: n === "slider" ? /* @__PURE__ */ p("div", {
735
+ className: W.sliderArea,
736
+ children: [/* @__PURE__ */ f("div", { className: W.sliderTrack }), /* @__PURE__ */ p("div", {
737
+ className: W.inputRow,
738
+ children: [/* @__PURE__ */ f("div", {
739
+ className: W.inputBar,
740
+ style: { animationDelay: "0.1s" }
741
+ }), /* @__PURE__ */ f("div", {
742
+ className: W.inputBar,
743
+ style: { animationDelay: "0.15s" }
744
+ })]
745
+ })]
746
+ }) : /* @__PURE__ */ f("div", {
747
+ className: W.listRows,
748
+ children: Array.from({ length: t }).map((e, t) => /* @__PURE__ */ f("div", {
749
+ className: W.bar,
750
+ style: {
751
+ width: `${G[t % G.length]}%`,
752
+ animationDelay: `${t * .05}s`
753
+ }
754
+ }, t))
755
+ })
756
+ }), q = {
757
+ list: "_list_m82u6_2",
758
+ count: "_count_m82u6_7",
759
+ countValue: "_countValue_m82u6_17",
760
+ chip: "_chip_m82u6_22",
761
+ chipLabel: "_chipLabel_m82u6_32",
762
+ grid: "_grid_m82u6_40"
763
+ }, J = ({ field: e, label: t, preserveBlankFacetState: n = !1, preserveBlankFacetStateOrder: r = !1, sortFacetsBy: i = "histogram", limit: a = 10, collapsible: s = !0, startCollapsed: u = !1, displayType: d = "checkbox", layout: _ = "list", showActivePanel: v = !1, showCount: y = !0, showNull: b = !1, displayIfEmptyQuery: x = !0, displayCondition: C = (e) => !0 }) => {
764
+ let { state: { facets: w, filterableFields: T, facetableFields: E, filters: D, query: O }, toggleFilter: k, isFetchingInitial: A, allowEmptySearch: j } = P(), M = c(null), [N, F] = l(a);
765
+ if (o(() => {
766
+ F(a);
767
+ }, [w?.[e], a]), !j && !O) return null;
768
+ if (A || !w) return d === "toggle" ? /* @__PURE__ */ f(K, {
769
+ rows: 1,
770
+ collapsible: !1
771
+ }) : /* @__PURE__ */ f(K, {
772
+ title: t,
773
+ rows: Math.min(a, 6),
774
+ collapsible: s,
775
+ startCollapsed: u
776
+ });
777
+ if (!C({
778
+ query: O ?? "",
779
+ filters: D,
780
+ facets: w
781
+ }) || !x && !O && Object.keys(D).length < 1) return null;
782
+ if (!T?.includes(e) || !E?.includes(e)) {
783
+ let t = [];
784
+ return T?.includes(e) || t.push("filterable"), E?.includes(e) || t.push("facetable"), /* @__PURE__ */ f(g, {
785
+ collapsible: !1,
786
+ children: /* @__PURE__ */ p("div", {
787
+ style: {
788
+ color: "red",
789
+ fontSize: "12px"
790
+ },
791
+ children: [
792
+ "Cannot render filter for \"",
793
+ e,
794
+ "\": missing ",
795
+ t.join(" and "),
796
+ "."
797
+ ]
798
+ })
799
+ });
800
+ }
801
+ let I = w?.[e];
802
+ if (!I || !Array.isArray(I)) return null;
803
+ let L = D?.[e] ?? [];
804
+ n && !M.current && I.length > 0 && (M.current = I.reduce((e, t) => (e[t.key] = t.value, e), {}));
805
+ let R = /* @__PURE__ */ new Map();
806
+ n && M.current && Object.keys(M.current).forEach((e) => {
807
+ R.set(e, 0);
808
+ }), I.forEach((e) => {
809
+ R.set(e.key, e.value);
810
+ });
811
+ let z = d === "toggle" && R.size === 2 && R.has("true") && (R.has("false") || R.has("null"));
812
+ if (R.has("null")) {
813
+ let e = R.get("null") ?? 0, t = R.get("false") ?? 0;
814
+ R.set("false", (t ?? 0) + e), R.delete("null");
815
+ }
816
+ if (d === "toggle" && !z) return /* @__PURE__ */ f(g, {
817
+ collapsible: !1,
818
+ children: /* @__PURE__ */ f("div", {
819
+ className: q.count,
820
+ children: /* @__PURE__ */ f(S, {
821
+ label: t,
822
+ checked: !1,
823
+ onChange: () => {},
824
+ disabled: !0
825
+ })
826
+ })
827
+ });
828
+ if (z) {
829
+ let n = R.get("true"), r = typeof n == "number" ? n : null, i = L.includes("true"), a = r === 0, o = y && (r ?? 0) > 0 ? `${r}` : "";
830
+ return /* @__PURE__ */ f(g, {
831
+ collapsible: !1,
832
+ children: /* @__PURE__ */ p("div", {
833
+ className: q.count,
834
+ children: [
835
+ /* @__PURE__ */ f(S, {
836
+ label: t,
837
+ checked: i,
838
+ onChange: () => k(e, "true"),
839
+ disabled: a
840
+ }),
841
+ " ",
842
+ o
843
+ ]
844
+ })
845
+ });
846
+ }
847
+ let B = Array.from(R.entries());
848
+ if (b || (B = B.filter(([e]) => e !== "null")), B.length === 0 && !n) return null;
849
+ if (!r) if (i === "alphabetical") {
850
+ let e = B.filter(([, e]) => typeof e == "number" && e > 0).sort(([e], [t]) => e.localeCompare(t)), t = B.filter(([, e]) => e === 0 || e === null).sort(([e], [t]) => e.localeCompare(t));
851
+ B = [...e, ...t];
852
+ } else if (i === "numeric") {
853
+ let e = (e, t) => {
854
+ let n = Number(e), r = Number(t);
855
+ return !isNaN(n) && !isNaN(r) ? n - r : e.localeCompare(t);
856
+ }, t = B.filter(([, e]) => typeof e == "number" && e > 0).sort(([t], [n]) => e(t, n)), n = B.filter(([, e]) => e === 0 || e === null).sort(([t], [n]) => e(t, n));
857
+ B = [...t, ...n];
858
+ } else {
859
+ let e = B.filter(([, e]) => typeof e == "number" && e > 0), t = B.filter(([, e]) => e === 0 || e === null);
860
+ B = [...e, ...t];
861
+ }
862
+ let V = typeof a == "number" && B.length > a, H = V ? B.slice(0, N) : B, U = (t, n) => {
863
+ let r = L.includes(t), i = n === 0, a = y && (n ?? 0) > 0 ? ` (${n})` : "", o = y && (n ?? 0) > 0 ? n : "";
864
+ switch (d) {
865
+ case "button": return _ === "list" ? /* @__PURE__ */ p("div", {
866
+ className: q.count,
867
+ children: [/* @__PURE__ */ f(m, {
868
+ variant: r ? "primary" : "secondary",
869
+ onClick: () => k(e, t),
870
+ disabled: i,
871
+ size: "micro",
872
+ className: q.chip,
873
+ title: t,
874
+ children: /* @__PURE__ */ f("span", {
875
+ className: q.chipLabel,
876
+ children: t
877
+ })
878
+ }), /* @__PURE__ */ f("span", {
879
+ className: q.countValue,
880
+ children: o
881
+ })]
882
+ }) : /* @__PURE__ */ f(m, {
883
+ variant: r ? "primary" : "secondary",
884
+ onClick: () => k(e, t),
885
+ disabled: i,
886
+ size: "micro",
887
+ className: q.chip,
888
+ title: `${t}${a}`,
889
+ children: /* @__PURE__ */ f("span", {
890
+ className: q.chipLabel,
891
+ children: `${t}${a}`
892
+ })
893
+ });
894
+ case "toggle": return /* @__PURE__ */ f(S, {
895
+ label: t,
896
+ checked: r,
897
+ onChange: () => k(e, t),
898
+ disabled: i
899
+ });
900
+ default: return _ === "list" ? /* @__PURE__ */ p("div", {
901
+ className: q.count,
902
+ children: [/* @__PURE__ */ f(h, {
903
+ label: t,
904
+ score: "",
905
+ checked: r,
906
+ onChange: () => k(e, t),
907
+ disabled: i
908
+ }), /* @__PURE__ */ f("span", { children: o })]
909
+ }) : /* @__PURE__ */ f(h, {
910
+ label: t,
911
+ score: a,
912
+ checked: r,
913
+ onChange: () => k(e, t),
914
+ disabled: i
915
+ });
916
+ }
917
+ };
918
+ return /* @__PURE__ */ f(g, {
919
+ title: t,
920
+ collapsible: s,
921
+ collapsed: s ? u : !1,
922
+ children: /* @__PURE__ */ p("ul", {
923
+ className: _ === "grid" ? q.grid : q.list,
924
+ style: {
925
+ listStyle: "none",
926
+ padding: 0,
927
+ margin: 0
928
+ },
929
+ children: [H.map(([e, t]) => /* @__PURE__ */ f("li", { children: U(e, t) }, e)), V && N < B.length && (() => {
930
+ let e = B.length - N, t = Math.min(50, e);
931
+ return /* @__PURE__ */ f("li", {
932
+ className: q.toggleItem,
933
+ children: /* @__PURE__ */ f(m, {
934
+ variant: "ghost",
935
+ size: "micro",
936
+ onClick: () => F((e) => e + 50),
937
+ children: `Show ${t} more of ${B.length} total`
938
+ })
939
+ });
940
+ })()]
941
+ })
942
+ });
943
+ }, Y = {
944
+ disabledMessage: "_disabledMessage_uci6n_1",
945
+ histogram: "_histogram_uci6n_6",
946
+ histogramBar: "_histogramBar_uci6n_15"
947
+ }, X = ({ field: t, label: n, expectedMin: r = 0, expectedMax: i = 1e3, displayType: a = "input", collapsible: o = !0, startCollapsed: s = !1, showHistogram: c = !1, resolution: l }) => {
948
+ let { state: { rangeFilters: u, rangeBounds: d, facetStats: m, facets: h, facetableFields: v, query: y, facetDebounceDelayMillis: b }, setRangeFilter: S, resetRangeFilter: C, allowEmptySearch: w, isFetchingInitial: T } = P(), E = d?.[t] !== void 0, D = d?.[t] ?? {
949
+ min: r,
950
+ max: i
951
+ }, O = D.min, k = D.max, A = m?.[t] ?? D, j = Math.max(O, Math.min(k, A.min)), M = Math.max(O, Math.min(k, A.max)), N = E && O === k, F = N ? r : O, I = N ? i : k, L = u?.[t], R = L ? L.min : O, z = L ? L.max : k, B = L !== void 0, V = j !== O || M !== k, [H, U] = e.useState([R, z]), [ee, W] = e.useState(!1), [G, q] = e.useState(!1), { finalMin: J, finalMax: X, isValidMin: Z, isValidMax: Q } = e.useMemo(() => {
952
+ let [e, t] = H, n = Math.max(O, Math.min(k, e)), r = Math.max(O, Math.min(k, t)), i = Math.min(n, r), a = Math.max(n, r);
953
+ return {
954
+ finalMin: i,
955
+ finalMax: a,
956
+ isValidMin: i >= O && i < a,
957
+ isValidMax: a <= k && a > i
958
+ };
959
+ }, [
960
+ H,
961
+ O,
962
+ k
963
+ ]);
964
+ e.useEffect(() => {
965
+ if (N) return;
966
+ if (H[0] === O && H[1] === k) {
967
+ W(!1), q(!1);
968
+ return;
969
+ }
970
+ let e = b ?? 500, n = setTimeout(() => {
971
+ W(!Z), q(!Q);
972
+ }, 300), r = setTimeout(() => {
973
+ Z && Q && (J === O && X === k ? C(t, !1) : S(t, J, X));
974
+ }, e);
975
+ return () => {
976
+ clearTimeout(n), clearTimeout(r);
977
+ };
978
+ }, [
979
+ J,
980
+ X,
981
+ Z,
982
+ Q,
983
+ O,
984
+ k,
985
+ t,
986
+ C,
987
+ S,
988
+ b,
989
+ N
990
+ ]), e.useEffect(() => {
991
+ U([R, z]), W(!1), q(!1);
992
+ }, [
993
+ R,
994
+ z,
995
+ t
996
+ ]);
997
+ let te = e.useCallback((e) => {
998
+ N || U([Math.max(O, Math.min(M, e[0])), Math.max(j, Math.min(k, e[1]))]);
999
+ }, [
1000
+ N,
1001
+ O,
1002
+ k,
1003
+ j,
1004
+ M
1005
+ ]), ne = e.useCallback((e) => {
1006
+ if (N) return;
1007
+ let n = Math.max(O, Math.min(M, e[0])), r = Math.max(j, Math.min(k, e[1]));
1008
+ n === O && r === k ? (U([O, k]), C(t, !0)) : U([n, r]);
1009
+ }, [
1010
+ N,
1011
+ O,
1012
+ k,
1013
+ j,
1014
+ M,
1015
+ t,
1016
+ C
1017
+ ]), re = e.useCallback((e) => {
1018
+ if (N) return;
1019
+ let t = Number(e.target.value);
1020
+ isNaN(t) || U([Math.max(O, Math.min(M, t)), H[1]]);
1021
+ }, [
1022
+ N,
1023
+ H,
1024
+ O,
1025
+ M
1026
+ ]), ie = e.useCallback((e) => {
1027
+ if (N) return;
1028
+ let t = Number(e.target.value);
1029
+ if (!isNaN(t)) {
1030
+ let e = Math.max(j, Math.min(k, t));
1031
+ U([H[0], e]);
1032
+ }
1033
+ }, [
1034
+ N,
1035
+ H,
1036
+ j,
1037
+ k
1038
+ ]), ae = e.useCallback(() => {
1039
+ let e = H[0], t = Math.max(O, Math.min(M, e));
1040
+ t < H[1] ? U([t, H[1]]) : U([O, H[1]]);
1041
+ }, [
1042
+ H,
1043
+ O,
1044
+ M
1045
+ ]), oe = e.useCallback(() => {
1046
+ let e = H[1], t = Math.max(j, Math.min(k, e));
1047
+ t > H[0] ? U([H[0], t]) : U([H[0], k]);
1048
+ }, [
1049
+ H,
1050
+ j,
1051
+ k
1052
+ ]), [$, se] = e.useState(null), ce = e.useRef(null);
1053
+ e.useEffect(() => {
1054
+ if (!c) return;
1055
+ let e = `${O}:${k}`;
1056
+ if (e === ce.current && ce.current !== null) return;
1057
+ let n = h?.[t];
1058
+ if (!Array.isArray(n) || n.length === 0) return;
1059
+ let r = n.filter((e) => e.value != null && !isNaN(Number(e.key))).map((e) => ({
1060
+ key: e.key,
1061
+ value: e.value
1062
+ }));
1063
+ r.length > 0 && (ce.current = e, se(r));
1064
+ }, [
1065
+ O,
1066
+ k,
1067
+ h,
1068
+ t,
1069
+ c
1070
+ ]);
1071
+ let le = e.useMemo(() => {
1072
+ if (!c || !$ || $.length === 0) return [];
1073
+ let e = k - O;
1074
+ if (e <= 0) return [];
1075
+ let t = l ?? (Math.ceil(e / 20) || 1), n = Math.ceil(e / t);
1076
+ return Array.from({ length: n }, (e, n) => {
1077
+ let r = O + n * t, i = O + (n + 1) * t;
1078
+ return {
1079
+ bucketStart: r,
1080
+ bucketEnd: i,
1081
+ count: $.filter((e) => {
1082
+ let t = Number(e.key);
1083
+ return t >= r && t < i;
1084
+ }).reduce((e, t) => e + t.value, 0)
1085
+ };
1086
+ });
1087
+ }, [
1088
+ c,
1089
+ $,
1090
+ O,
1091
+ k,
1092
+ l
1093
+ ]), ue = e.useMemo(() => Math.max(...le.map((e) => e.count), 1), [le]);
1094
+ return c && !T && !v?.includes(t) && console.warn(`RangeFilterPanel: showHistogram=true but field "${t}" is not facetable. Add .Facetable = true to this field.`), T ? /* @__PURE__ */ f(K, {
1095
+ title: n,
1096
+ variant: "slider",
1097
+ collapsible: o,
1098
+ startCollapsed: s
1099
+ }) : !w && !y ? null : a === "slider" ? /* @__PURE__ */ p(g, {
1100
+ title: n,
1101
+ collapsed: s,
1102
+ collapsible: o,
1103
+ children: [
1104
+ N && /* @__PURE__ */ p("div", {
1105
+ className: Y.disabledMessage,
1106
+ children: [
1107
+ "No adjustable range (all results have the same value: ",
1108
+ O,
1109
+ ")."
1110
+ ]
1111
+ }),
1112
+ c && le.length > 0 && /* @__PURE__ */ f("div", {
1113
+ className: Y.histogram,
1114
+ children: (() => {
1115
+ let e = typeof j == "number" && typeof M == "number" && M > j && (j > O || M < k);
1116
+ return le.map((t, n) => {
1117
+ let r = Math.max(1, Math.ceil(t.count / ue * 20)), i = e ? t.bucketEnd > j && t.bucketStart < M : t.bucketEnd > J && t.bucketStart < X;
1118
+ return /* @__PURE__ */ f("div", {
1119
+ className: Y.histogramBar,
1120
+ "data-testid": "histogram-bar",
1121
+ "data-active": i,
1122
+ style: {
1123
+ height: `${r}px`,
1124
+ background: i ? "var(--lv5)" : "var(--lv3)"
1125
+ }
1126
+ }, n);
1127
+ });
1128
+ })()
1129
+ }),
1130
+ /* @__PURE__ */ f("div", {
1131
+ style: { padding: "10px 10px 20px 10px" },
1132
+ children: /* @__PURE__ */ f(x, {
1133
+ min: F,
1134
+ max: I,
1135
+ value: N ? [F, I] : [J, X],
1136
+ isRange: !0,
1137
+ onChange: (e) => te(e),
1138
+ onFinalChange: (e) => ne(e),
1139
+ disabled: N,
1140
+ activeMin: j,
1141
+ activeMax: M,
1142
+ isFaceted: V,
1143
+ highlightFaceted: B,
1144
+ "aria-label": n || `Filter by ${t}`
1145
+ })
1146
+ }),
1147
+ /* @__PURE__ */ p("div", {
1148
+ style: {
1149
+ display: "flex",
1150
+ flex: "flex-grow",
1151
+ gap: "10px",
1152
+ alignItems: "flex-start",
1153
+ justifyContent: "space-between"
1154
+ },
1155
+ children: [/* @__PURE__ */ f(_, {
1156
+ label: "Min:",
1157
+ type: "number",
1158
+ value: N ? O : H[0],
1159
+ min: O,
1160
+ max: Math.min(M, H[1] - 1),
1161
+ onChange: re,
1162
+ onBlur: ae,
1163
+ disabled: N,
1164
+ isValid: N || !ee
1165
+ }), /* @__PURE__ */ f(_, {
1166
+ label: "Max:",
1167
+ type: "number",
1168
+ value: N ? k : H[1],
1169
+ min: Math.max(j, H[0] + 1),
1170
+ max: k,
1171
+ onChange: ie,
1172
+ onBlur: oe,
1173
+ disabled: N,
1174
+ isValid: N || !G
1175
+ })]
1176
+ })
1177
+ ]
1178
+ }) : /* @__PURE__ */ p(g, {
1179
+ title: n,
1180
+ children: [N && /* @__PURE__ */ p("div", {
1181
+ className: Y.disabledMessage,
1182
+ children: [
1183
+ "No adjustable range (all results have the same value: ",
1184
+ O,
1185
+ ")."
1186
+ ]
1187
+ }), /* @__PURE__ */ p("div", {
1188
+ style: {
1189
+ display: "flex",
1190
+ gap: "10px",
1191
+ alignItems: "flex-start"
1192
+ },
1193
+ children: [/* @__PURE__ */ f(_, {
1194
+ label: "Min:",
1195
+ type: "number",
1196
+ value: N ? O : H[0],
1197
+ min: O,
1198
+ max: Math.min(M, H[1] - 1),
1199
+ onChange: re,
1200
+ onBlur: ae,
1201
+ disabled: N,
1202
+ isValid: N || !ee
1203
+ }), /* @__PURE__ */ f(_, {
1204
+ label: "Max:",
1205
+ type: "number",
1206
+ value: N ? k : H[1],
1207
+ min: Math.max(j, H[0] + 1),
1208
+ max: k,
1209
+ onChange: ie,
1210
+ onBlur: oe,
1211
+ disabled: N,
1212
+ isValid: N || !G
1213
+ })]
1214
+ })]
1215
+ });
1216
+ }, Z = {
1217
+ grid: "_grid_xm2uh_2",
1218
+ chip: "_chip_xm2uh_17",
1219
+ chipLabel: "_chipLabel_xm2uh_28"
1220
+ }, Q = r(({ field: e, value: t, onReset: n }) => /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(m, {
1221
+ onClick: n,
1222
+ iconRight: /* @__PURE__ */ f(E, {}),
1223
+ variant: "primary",
1224
+ size: "micro",
1225
+ className: Z.chip,
1226
+ title: `${e}: ${t}`,
1227
+ children: /* @__PURE__ */ p("span", {
1228
+ className: Z.chipLabel,
1229
+ children: [
1230
+ e,
1231
+ ": ",
1232
+ t
1233
+ ]
1234
+ })
1235
+ }) })), te = r(({ field: e, min: t, max: n, onReset: r }) => /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(m, {
1236
+ onClick: r,
1237
+ iconRight: /* @__PURE__ */ f(E, {}),
1238
+ variant: "primary",
1239
+ size: "micro",
1240
+ className: Z.chip,
1241
+ title: `${e}: ${t} – ${n}`,
1242
+ children: /* @__PURE__ */ p("span", {
1243
+ className: Z.chipLabel,
1244
+ children: [
1245
+ e,
1246
+ ": ",
1247
+ t,
1248
+ " – ",
1249
+ n
1250
+ ]
1251
+ })
1252
+ }) }));
1253
+ function ne() {
1254
+ let { state: { filters: e, rangeFilters: t }, resetFilters: n, resetSingleFilter: r, resetRangeFilter: i } = P(), a = s(() => Object.entries(e).map(([e, t]) => t.map((t) => ({
1255
+ field: e,
1256
+ value: t
1257
+ }))).flat(), [e]), o = s(() => Object.entries(t).map(([e, { min: t, max: n }]) => ({
1258
+ field: e,
1259
+ min: t,
1260
+ max: n
1261
+ })), [t]);
1262
+ return s(() => Object.keys(e).length > 0 || Object.keys(t).length > 0, [e, t]) ? /* @__PURE__ */ f(g, {
1263
+ collapsible: !1,
1264
+ title: "Active filters",
1265
+ children: /* @__PURE__ */ p("ul", {
1266
+ className: Z.grid,
1267
+ children: [
1268
+ a.map(({ field: e, value: t }) => /* @__PURE__ */ f(Q, {
1269
+ field: e,
1270
+ value: t,
1271
+ onReset: () => r(e, t)
1272
+ }, `${e}-${t}`)),
1273
+ o.map(({ field: e, min: t, max: n }) => /* @__PURE__ */ f(te, {
1274
+ field: e,
1275
+ min: t,
1276
+ max: n,
1277
+ onReset: () => i(e)
1278
+ }, e)),
1279
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(m, {
1280
+ onClick: n,
1281
+ size: "micro",
1282
+ variant: "ghost",
1283
+ children: "Reset"
1284
+ }) })
1285
+ ]
1286
+ })
1287
+ }) : null;
1635
1288
  }
1636
- class ir extends jt {
1637
- constructor(u) {
1638
- super(u);
1639
- rt(this, "reset", () => {
1640
- this.setState({ hasError: !1, error: null });
1641
- });
1642
- this.state = { hasError: !1, error: null };
1643
- }
1644
- static getDerivedStateFromError(u) {
1645
- return { hasError: !0, error: u };
1646
- }
1647
- componentDidCatch(u, s) {
1648
- console.error("[SearchErrorBoundary] Caught error:", u, s);
1649
- }
1650
- render() {
1651
- return this.state.hasError && this.state.error ? this.props.fallback ? this.props.fallback(this.state.error, this.reset) : /* @__PURE__ */ t.jsxs("div", { style: {
1652
- padding: "2rem",
1653
- backgroundColor: "#fee",
1654
- border: "2px solid #c33",
1655
- borderRadius: "8px",
1656
- maxWidth: "600px",
1657
- margin: "2rem auto"
1658
- }, children: [
1659
- /* @__PURE__ */ t.jsx("h2", { style: { color: "#c33", marginTop: 0 }, children: "⚠️ Search Initialization Error" }),
1660
- /* @__PURE__ */ t.jsxs("p", { style: { marginBottom: "1rem" }, children: [
1661
- /* @__PURE__ */ t.jsx("strong", { children: "Error:" }),
1662
- " ",
1663
- this.state.error.message
1664
- ] }),
1665
- /* @__PURE__ */ t.jsxs("div", { style: {
1666
- backgroundColor: "#fff",
1667
- padding: "1rem",
1668
- borderRadius: "4px",
1669
- marginBottom: "1rem",
1670
- fontSize: "0.9rem"
1671
- }, children: [
1672
- /* @__PURE__ */ t.jsx("strong", { children: "💡 Common fixes:" }),
1673
- /* @__PURE__ */ t.jsxs("ul", { style: { marginBottom: 0, paddingLeft: "1.5rem" }, children: [
1674
- /* @__PURE__ */ t.jsx("li", { children: "Check browser console for detailed error messages" }),
1675
- /* @__PURE__ */ t.jsx("li", { children: "Verify NEXT_PUBLIC_INDX_URL is correct in .env.local" }),
1676
- /* @__PURE__ */ t.jsx("li", { children: "Verify NEXT_PUBLIC_INDX_EMAIL and NEXT_PUBLIC_INDX_PASSWORD are correct" }),
1677
- /* @__PURE__ */ t.jsx("li", { children: "Ensure INDX server is running" }),
1678
- /* @__PURE__ */ t.jsx("li", { children: "Check dataset name spelling" })
1679
- ] })
1680
- ] }),
1681
- /* @__PURE__ */ t.jsx(
1682
- "button",
1683
- {
1684
- onClick: this.reset,
1685
- style: {
1686
- padding: "0.5rem 1rem",
1687
- backgroundColor: "#c33",
1688
- color: "white",
1689
- border: "none",
1690
- borderRadius: "4px",
1691
- cursor: "pointer",
1692
- fontWeight: "bold"
1693
- },
1694
- children: "Try Again"
1695
- }
1696
- )
1697
- ] }) : this.props.children;
1698
- }
1289
+ var re = {
1290
+ select: "_select_nwf7i_1",
1291
+ radioGroup: "_radioGroup_nwf7i_6"
1292
+ }, ie = ({ displayType: e = "dropdown", collapsible: t = !0, startCollapsed: n = !1 }) => {
1293
+ let { state: { sortableFields: r, sortBy: i, sortAscending: a }, setSort: o, isFetchingInitial: s } = P();
1294
+ if (s) return /* @__PURE__ */ f(K, {
1295
+ title: "Sort by",
1296
+ rows: e === "radio" ? 3 : 1,
1297
+ collapsible: t,
1298
+ startCollapsed: n
1299
+ });
1300
+ if (!r || r.length === 0) return null;
1301
+ let c = i ? `${i}:${a ? "asc" : "desc"}` : "none", l = [{
1302
+ label: "None",
1303
+ value: "none"
1304
+ }, ...r.flatMap((e) => [{
1305
+ label: `${e} (asc)`,
1306
+ value: `${e}:asc`
1307
+ }, {
1308
+ label: `${e} (desc)`,
1309
+ value: `${e}:desc`
1310
+ }])], u = (e) => {
1311
+ if (e === "none" || e === "") o(null, !0);
1312
+ else {
1313
+ let [t, n] = e.split(":");
1314
+ o(t, n === "asc");
1315
+ }
1316
+ };
1317
+ return /* @__PURE__ */ f(g, {
1318
+ title: "Sort by",
1319
+ collapsible: t,
1320
+ collapsed: t ? n : !1,
1321
+ children: e === "dropdown" ? /* @__PURE__ */ f(b, {
1322
+ value: c,
1323
+ onValueChange: u,
1324
+ options: l,
1325
+ placeholder: "Select sort...",
1326
+ "aria-label": "Sort by"
1327
+ }) : /* @__PURE__ */ f("div", {
1328
+ className: re.radioGroup,
1329
+ children: l.map((e) => /* @__PURE__ */ f(v, {
1330
+ id: `sort-${e.value}`,
1331
+ name: "sort-by",
1332
+ value: e.value,
1333
+ label: e.label,
1334
+ checked: c === e.value,
1335
+ onChange: (e) => u(e.target.value)
1336
+ }, e.value))
1337
+ })
1338
+ });
1339
+ }, ae = { list: "_list_1y4fk_1" };
1340
+ //#endregion
1341
+ //#region src/components/SearchSettingsPanel.tsx
1342
+ function oe() {
1343
+ let { state: { searchSettings: e }, setSearchSettings: t } = P(), [n, r] = l(!1), i = (e, n) => {
1344
+ let r = parseInt(n, 10);
1345
+ isNaN(r) || t({ [e]: r });
1346
+ }, a = (e, n) => {
1347
+ t({ [e]: n });
1348
+ }, o = (n, r) => {
1349
+ let i = parseInt(r, 10);
1350
+ isNaN(i) || t({ coverageSetup: {
1351
+ ...e.coverageSetup,
1352
+ [n]: i
1353
+ } });
1354
+ }, s = (n, r) => {
1355
+ t({ coverageSetup: {
1356
+ ...e.coverageSetup,
1357
+ [n]: r
1358
+ } });
1359
+ };
1360
+ return /* @__PURE__ */ f(g, {
1361
+ collapsed: !0,
1362
+ title: "Settings",
1363
+ children: /* @__PURE__ */ p("ul", {
1364
+ className: ae.list,
1365
+ children: [
1366
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(_, {
1367
+ label: "Max Results",
1368
+ type: "number",
1369
+ value: e.maxNumberOfRecordsToReturn.toString(),
1370
+ onChange: (e) => i("maxNumberOfRecordsToReturn", e.target.value)
1371
+ }) }),
1372
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(_, {
1373
+ label: "Coverage Depth",
1374
+ type: "number",
1375
+ value: e.coverageDepth.toString(),
1376
+ onChange: (e) => i("coverageDepth", e.target.value)
1377
+ }) }),
1378
+ /* @__PURE__ */ p("li", { children: [/* @__PURE__ */ f(_, {
1379
+ label: "Minimum Score (16 bit)",
1380
+ type: "number",
1381
+ value: e.minimumScore.toString(),
1382
+ min: "0",
1383
+ max: "65535",
1384
+ onChange: (e) => {
1385
+ let n = parseFloat(e.target.value);
1386
+ isNaN(n) || t({ minimumScore: n });
1387
+ }
1388
+ }), /* @__PURE__ */ f("div", {
1389
+ style: { padding: "10px 10px 20px 10px" },
1390
+ children: /* @__PURE__ */ f(x, {
1391
+ min: 0,
1392
+ max: 65535,
1393
+ step: 5e3,
1394
+ value: e.minimumScore,
1395
+ onChange: (e) => {
1396
+ t({ minimumScore: e });
1397
+ },
1398
+ "aria-label": "Minimum score"
1399
+ })
1400
+ })] }),
1401
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(_, {
1402
+ label: "Placeholder text",
1403
+ type: "text",
1404
+ value: e.placeholderText,
1405
+ onChange: (e) => {
1406
+ t({ placeholderText: e.target.value });
1407
+ }
1408
+ }) }),
1409
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(S, {
1410
+ label: "Show score",
1411
+ checked: e.showScore,
1412
+ onChange: (e) => a("showScore", e)
1413
+ }) }),
1414
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(S, {
1415
+ label: "Enable Coverage",
1416
+ checked: e.enableCoverage,
1417
+ onChange: (e) => a("enableCoverage", e)
1418
+ }) }),
1419
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(S, {
1420
+ label: "Remove Duplicates",
1421
+ checked: e.removeDuplicates,
1422
+ onChange: (e) => a("removeDuplicates", e)
1423
+ }) }),
1424
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(m, {
1425
+ variant: "ghost",
1426
+ size: "micro",
1427
+ iconRight: f(n ? C : w, {}),
1428
+ onClick: () => r((e) => !e),
1429
+ children: n ? "Hide Coverage Setup" : "Show Coverage Setup"
1430
+ }) }),
1431
+ n && /* @__PURE__ */ p(d, { children: [
1432
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(S, {
1433
+ label: "Cover Whole Query",
1434
+ checked: e.coverageSetup.coverWholeQuery,
1435
+ onChange: (e) => s("coverWholeQuery", e)
1436
+ }) }),
1437
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(S, {
1438
+ label: "Cover Whole Words",
1439
+ checked: e.coverageSetup.coverWholeWords,
1440
+ onChange: (e) => s("coverWholeWords", e)
1441
+ }) }),
1442
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(S, {
1443
+ label: "Cover Fuzzy Words",
1444
+ checked: e.coverageSetup.coverFuzzyWords,
1445
+ onChange: (e) => s("coverFuzzyWords", e)
1446
+ }) }),
1447
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(S, {
1448
+ label: "Cover Joined Words",
1449
+ checked: e.coverageSetup.coverJoinedWords,
1450
+ onChange: (e) => s("coverJoinedWords", e)
1451
+ }) }),
1452
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(S, {
1453
+ label: "Cover Prefix Suffix",
1454
+ checked: e.coverageSetup.coverPrefixSuffix,
1455
+ onChange: (e) => s("coverPrefixSuffix", e)
1456
+ }) }),
1457
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(S, {
1458
+ label: "Truncate",
1459
+ checked: e.coverageSetup.truncate,
1460
+ onChange: (e) => s("truncate", e)
1461
+ }) }),
1462
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(S, {
1463
+ label: "Include Pattern Matches",
1464
+ checked: e.coverageSetup.includePatternMatches,
1465
+ onChange: (e) => s("includePatternMatches", e)
1466
+ }) }),
1467
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(_, {
1468
+ label: "Levenshtein Max Word Size",
1469
+ type: "number",
1470
+ value: e.coverageSetup.levenshteinMaxWordSize.toString(),
1471
+ onChange: (e) => o("levenshteinMaxWordSize", e.target.value)
1472
+ }) }),
1473
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(_, {
1474
+ label: "Min Word Size",
1475
+ type: "number",
1476
+ value: e.coverageSetup.minWordSize.toString(),
1477
+ onChange: (e) => o("minWordSize", e.target.value)
1478
+ }) }),
1479
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(_, {
1480
+ label: "Truncate Word Hit Limit",
1481
+ type: "number",
1482
+ value: e.coverageSetup.truncateWordHitLimit.toString(),
1483
+ onChange: (e) => o("truncateWordHitLimit", e.target.value)
1484
+ }) }),
1485
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f(_, {
1486
+ label: "Truncate Word Hit Tolerance",
1487
+ type: "number",
1488
+ value: e.coverageSetup.truncateWordHitTolerance.toString(),
1489
+ onChange: (e) => o("truncateWordHitTolerance", e.target.value)
1490
+ }) })
1491
+ ] })
1492
+ ]
1493
+ })
1494
+ });
1699
1495
  }
1700
- export {
1701
- sr as ActiveFiltersPanel,
1702
- nr as RangeFilterPanel,
1703
- ir as SearchErrorBoundary,
1704
- er as SearchInput,
1705
- Kt as SearchProvider,
1706
- tr as SearchResults,
1707
- ar as SearchSettingsPanel,
1708
- or as SortByPanel,
1709
- rr as ValueFilterPanel,
1710
- Ne as useSearch,
1711
- Ne as useSearchContext
1496
+ //#endregion
1497
+ //#region src/components/SearchErrorBoundary.tsx
1498
+ var $ = class extends t {
1499
+ constructor(e) {
1500
+ super(e), this.state = {
1501
+ hasError: !1,
1502
+ error: null
1503
+ };
1504
+ }
1505
+ static getDerivedStateFromError(e) {
1506
+ return {
1507
+ hasError: !0,
1508
+ error: e
1509
+ };
1510
+ }
1511
+ componentDidCatch(e, t) {
1512
+ console.error("[SearchErrorBoundary] Caught error:", e, t);
1513
+ }
1514
+ reset = () => {
1515
+ this.setState({
1516
+ hasError: !1,
1517
+ error: null
1518
+ });
1519
+ };
1520
+ render() {
1521
+ return this.state.hasError && this.state.error ? this.props.fallback ? this.props.fallback(this.state.error, this.reset) : /* @__PURE__ */ p("div", {
1522
+ style: {
1523
+ padding: "2rem",
1524
+ backgroundColor: "#fee",
1525
+ border: "2px solid #c33",
1526
+ borderRadius: "8px",
1527
+ maxWidth: "600px",
1528
+ margin: "2rem auto"
1529
+ },
1530
+ children: [
1531
+ /* @__PURE__ */ f("h2", {
1532
+ style: {
1533
+ color: "#c33",
1534
+ marginTop: 0
1535
+ },
1536
+ children: "⚠️ Search Initialization Error"
1537
+ }),
1538
+ /* @__PURE__ */ p("p", {
1539
+ style: { marginBottom: "1rem" },
1540
+ children: [
1541
+ /* @__PURE__ */ f("strong", { children: "Error:" }),
1542
+ " ",
1543
+ this.state.error.message
1544
+ ]
1545
+ }),
1546
+ /* @__PURE__ */ p("div", {
1547
+ style: {
1548
+ backgroundColor: "#fff",
1549
+ padding: "1rem",
1550
+ borderRadius: "4px",
1551
+ marginBottom: "1rem",
1552
+ fontSize: "0.9rem"
1553
+ },
1554
+ children: [/* @__PURE__ */ f("strong", { children: "💡 Common fixes:" }), /* @__PURE__ */ p("ul", {
1555
+ style: {
1556
+ marginBottom: 0,
1557
+ paddingLeft: "1.5rem"
1558
+ },
1559
+ children: [
1560
+ /* @__PURE__ */ f("li", { children: "Check browser console for detailed error messages" }),
1561
+ /* @__PURE__ */ f("li", { children: "Verify the url passed to SearchProvider is correct" }),
1562
+ /* @__PURE__ */ f("li", { children: "Verify your bearer token is valid (create or check it on the IndxCloudApi website)" }),
1563
+ /* @__PURE__ */ f("li", { children: "Ensure INDX server is running" }),
1564
+ /* @__PURE__ */ f("li", { children: "Check dataset name spelling" })
1565
+ ]
1566
+ })]
1567
+ }),
1568
+ /* @__PURE__ */ f("button", {
1569
+ onClick: this.reset,
1570
+ style: {
1571
+ padding: "0.5rem 1rem",
1572
+ backgroundColor: "#c33",
1573
+ color: "white",
1574
+ border: "none",
1575
+ borderRadius: "4px",
1576
+ cursor: "pointer",
1577
+ fontWeight: "bold"
1578
+ },
1579
+ children: "Try Again"
1580
+ })
1581
+ ]
1582
+ }) : this.props.children;
1583
+ }
1712
1584
  };
1585
+ //#endregion
1586
+ //#region src/hooks/useVectorSearch.ts
1587
+ function se(e, t) {
1588
+ let { url: n, team: r, dataset: a, authenticatedFetch: o } = P(), [s, c] = l(null), [u, d] = l(!1), [f, p] = l(void 0);
1589
+ return {
1590
+ results: s,
1591
+ isLoading: u,
1592
+ error: f,
1593
+ search: i(async (i) => {
1594
+ d(!0), p(void 0);
1595
+ try {
1596
+ let s = await e(i), l = {
1597
+ fieldName: t.fieldName,
1598
+ vector: s,
1599
+ maxResults: t.maxResults ?? 10
1600
+ };
1601
+ t.filter && (l.filter = t.filter);
1602
+ let u = await o(`${n}/api/teams/${r}/datasets/${a}/VectorSearch`, {
1603
+ method: "POST",
1604
+ headers: { "Content-Type": "application/json" },
1605
+ body: JSON.stringify(l)
1606
+ });
1607
+ if (!u.ok) throw Error(`VectorSearch failed: ${u.status}`);
1608
+ let d = await u.json();
1609
+ if (d.length === 0) {
1610
+ c([]);
1611
+ return;
1612
+ }
1613
+ let f = d.map((e) => e.documentKey), p = await o(`${n}/api/teams/${r}/datasets/${a}/GetJson`, {
1614
+ method: "POST",
1615
+ headers: { "Content-Type": "application/json" },
1616
+ body: JSON.stringify(f)
1617
+ });
1618
+ if (!p.ok) throw Error(`GetJson failed: ${p.status}`);
1619
+ c((await p.json()).map((e, t) => ({
1620
+ document: e,
1621
+ documentKey: f[t],
1622
+ score: d[t].score
1623
+ })));
1624
+ } catch (e) {
1625
+ p(e instanceof Error ? e.message : "Vector search failed"), c(null);
1626
+ } finally {
1627
+ d(!1);
1628
+ }
1629
+ }, [
1630
+ e,
1631
+ t.fieldName,
1632
+ t.maxResults,
1633
+ t.filter,
1634
+ n,
1635
+ r,
1636
+ a,
1637
+ o
1638
+ ])
1639
+ };
1640
+ }
1641
+ //#endregion
1642
+ //#region src/hooks/useHybridSearch.ts
1643
+ function ce(e, t) {
1644
+ let { url: n, team: r, dataset: a, authenticatedFetch: o } = P(), [s, c] = l(null), [u, d] = l(!1), [f, p] = l(void 0);
1645
+ return {
1646
+ results: s,
1647
+ isLoading: u,
1648
+ error: f,
1649
+ search: i(async (i) => {
1650
+ d(!0), p(void 0);
1651
+ try {
1652
+ let s = await e(i), l = {
1653
+ text: i,
1654
+ embeddingField: t.fieldName,
1655
+ vector: s,
1656
+ maxNumberOfRecordsToReturn: t.maxResults ?? 10,
1657
+ alpha: t.alpha ?? .5
1658
+ };
1659
+ t.filter && (l.filter = t.filter), t.timeoutMs && (l.timeOutLimitMilliseconds = t.timeoutMs);
1660
+ let u = await o(`${n}/api/teams/${r}/datasets/${a}/HybridSearch`, {
1661
+ method: "POST",
1662
+ headers: { "Content-Type": "application/json" },
1663
+ body: JSON.stringify(l)
1664
+ });
1665
+ if (!u.ok) throw Error(`HybridSearch failed: ${u.status}`);
1666
+ let d = await u.json();
1667
+ if (d.length === 0) {
1668
+ c([]);
1669
+ return;
1670
+ }
1671
+ let f = d.map((e) => e.documentKey), p = await o(`${n}/api/teams/${r}/datasets/${a}/GetJson`, {
1672
+ method: "POST",
1673
+ headers: { "Content-Type": "application/json" },
1674
+ body: JSON.stringify(f)
1675
+ });
1676
+ if (!p.ok) throw Error(`GetJson failed: ${p.status}`);
1677
+ c((await p.json()).map((e, t) => ({
1678
+ document: e,
1679
+ documentKey: f[t],
1680
+ score: d[t].score
1681
+ })));
1682
+ } catch (e) {
1683
+ p(e instanceof Error ? e.message : "Hybrid search failed"), c(null);
1684
+ } finally {
1685
+ d(!1);
1686
+ }
1687
+ }, [
1688
+ e,
1689
+ t.fieldName,
1690
+ t.alpha,
1691
+ t.maxResults,
1692
+ t.filter,
1693
+ t.timeoutMs,
1694
+ n,
1695
+ r,
1696
+ a,
1697
+ o
1698
+ ])
1699
+ };
1700
+ }
1701
+ //#endregion
1702
+ export { ne as ActiveFiltersPanel, K as FilterPanelSkeleton, X as RangeFilterPanel, M as SearchContext, $ as SearchErrorBoundary, F as SearchInput, N as SearchProvider, R as SearchResult, ee as SearchResultRow, H as SearchResults, V as SearchResultsSkeleton, oe as SearchSettingsPanel, ie as SortByPanel, J as ValueFilterPanel, ce as useHybridSearch, P as useSearch, P as useSearchContext, se as useVectorSearch };