@aiquants/select-box 0.2.0 → 0.2.2
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/README.md +2 -2
- package/dist/index.cjs +6 -6
- package/dist/index.js +997 -348
- package/package.json +11 -9
package/dist/index.js
CHANGED
|
@@ -1,450 +1,1099 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
props: i
|
|
1
|
+
import * as P from "react";
|
|
2
|
+
import ve, { useState as A, useMemo as H, useRef as N, useEffect as $, useCallback as D } from "react";
|
|
3
|
+
import { VirtualScroll as ke, tapScrollCircleSampleVisual as xe } from "@aiquants/virtualscroll";
|
|
4
|
+
var Z = { exports: {} }, V = {};
|
|
5
|
+
var oe;
|
|
6
|
+
function be() {
|
|
7
|
+
if (oe) return V;
|
|
8
|
+
oe = 1;
|
|
9
|
+
var e = /* @__PURE__ */ Symbol.for("react.transitional.element"), t = /* @__PURE__ */ Symbol.for("react.fragment");
|
|
10
|
+
function r(s, a, o) {
|
|
11
|
+
var n = null;
|
|
12
|
+
if (o !== void 0 && (n = "" + o), a.key !== void 0 && (n = "" + a.key), "key" in a) {
|
|
13
|
+
o = {};
|
|
14
|
+
for (var l in a)
|
|
15
|
+
l !== "key" && (o[l] = a[l]);
|
|
16
|
+
} else o = a;
|
|
17
|
+
return a = o.ref, {
|
|
18
|
+
$$typeof: e,
|
|
19
|
+
type: s,
|
|
20
|
+
key: n,
|
|
21
|
+
ref: a !== void 0 ? a : null,
|
|
22
|
+
props: o
|
|
24
23
|
};
|
|
25
24
|
}
|
|
26
|
-
return
|
|
25
|
+
return V.Fragment = t, V.jsx = r, V.jsxs = r, V;
|
|
27
26
|
}
|
|
28
|
-
var
|
|
29
|
-
var
|
|
30
|
-
function
|
|
31
|
-
return
|
|
32
|
-
function
|
|
33
|
-
if (
|
|
34
|
-
if (typeof
|
|
35
|
-
return
|
|
36
|
-
if (typeof
|
|
37
|
-
switch (
|
|
38
|
-
case
|
|
27
|
+
var G = {};
|
|
28
|
+
var le;
|
|
29
|
+
function we() {
|
|
30
|
+
return le || (le = 1, process.env.NODE_ENV !== "production" && (function() {
|
|
31
|
+
function e(i) {
|
|
32
|
+
if (i == null) return null;
|
|
33
|
+
if (typeof i == "function")
|
|
34
|
+
return i.$$typeof === ie ? null : i.displayName || i.name || null;
|
|
35
|
+
if (typeof i == "string") return i;
|
|
36
|
+
switch (i) {
|
|
37
|
+
case y:
|
|
39
38
|
return "Fragment";
|
|
40
|
-
case
|
|
39
|
+
case c:
|
|
41
40
|
return "Profiler";
|
|
42
|
-
case
|
|
41
|
+
case v:
|
|
43
42
|
return "StrictMode";
|
|
44
|
-
case
|
|
43
|
+
case j:
|
|
45
44
|
return "Suspense";
|
|
46
45
|
case te:
|
|
47
46
|
return "SuspenseList";
|
|
48
|
-
case
|
|
47
|
+
case se:
|
|
49
48
|
return "Activity";
|
|
50
49
|
}
|
|
51
|
-
if (typeof
|
|
52
|
-
switch (typeof
|
|
50
|
+
if (typeof i == "object")
|
|
51
|
+
switch (typeof i.tag == "number" && console.error(
|
|
53
52
|
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
54
|
-
),
|
|
55
|
-
case
|
|
53
|
+
), i.$$typeof) {
|
|
54
|
+
case R:
|
|
56
55
|
return "Portal";
|
|
57
|
-
case K:
|
|
58
|
-
return e.displayName || "Context";
|
|
59
|
-
case q:
|
|
60
|
-
return (e._context.displayName || "Context") + ".Consumer";
|
|
61
|
-
case ee:
|
|
62
|
-
var n = e.render;
|
|
63
|
-
return e = e.displayName, e || (e = n.displayName || n.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
64
|
-
case ne:
|
|
65
|
-
return n = e.displayName || null, n !== null ? n : r(e.type) || "Memo";
|
|
66
56
|
case C:
|
|
67
|
-
|
|
57
|
+
return i.displayName || "Context";
|
|
58
|
+
case b:
|
|
59
|
+
return (i._context.displayName || "Context") + ".Consumer";
|
|
60
|
+
case z:
|
|
61
|
+
var f = i.render;
|
|
62
|
+
return i = i.displayName, i || (i = f.displayName || f.name || "", i = i !== "" ? "ForwardRef(" + i + ")" : "ForwardRef"), i;
|
|
63
|
+
case re:
|
|
64
|
+
return f = i.displayName || null, f !== null ? f : e(i.type) || "Memo";
|
|
65
|
+
case U:
|
|
66
|
+
f = i._payload, i = i._init;
|
|
68
67
|
try {
|
|
69
|
-
return
|
|
68
|
+
return e(i(f));
|
|
70
69
|
} catch {
|
|
71
70
|
}
|
|
72
71
|
}
|
|
73
72
|
return null;
|
|
74
73
|
}
|
|
75
|
-
function t(
|
|
76
|
-
return "" +
|
|
74
|
+
function t(i) {
|
|
75
|
+
return "" + i;
|
|
77
76
|
}
|
|
78
|
-
function
|
|
77
|
+
function r(i) {
|
|
79
78
|
try {
|
|
80
|
-
t(
|
|
81
|
-
var
|
|
79
|
+
t(i);
|
|
80
|
+
var f = !1;
|
|
82
81
|
} catch {
|
|
83
|
-
|
|
82
|
+
f = !0;
|
|
84
83
|
}
|
|
85
|
-
if (
|
|
86
|
-
|
|
87
|
-
var
|
|
88
|
-
return
|
|
89
|
-
|
|
84
|
+
if (f) {
|
|
85
|
+
f = console;
|
|
86
|
+
var S = f.error, L = typeof Symbol == "function" && Symbol.toStringTag && i[Symbol.toStringTag] || i.constructor.name || "Object";
|
|
87
|
+
return S.call(
|
|
88
|
+
f,
|
|
90
89
|
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
91
|
-
|
|
92
|
-
), t(
|
|
90
|
+
L
|
|
91
|
+
), t(i);
|
|
93
92
|
}
|
|
94
93
|
}
|
|
95
|
-
function
|
|
96
|
-
if (
|
|
97
|
-
if (typeof
|
|
94
|
+
function s(i) {
|
|
95
|
+
if (i === y) return "<>";
|
|
96
|
+
if (typeof i == "object" && i !== null && i.$$typeof === U)
|
|
98
97
|
return "<...>";
|
|
99
98
|
try {
|
|
100
|
-
var
|
|
101
|
-
return
|
|
99
|
+
var f = e(i);
|
|
100
|
+
return f ? "<" + f + ">" : "<...>";
|
|
102
101
|
} catch {
|
|
103
102
|
return "<...>";
|
|
104
103
|
}
|
|
105
104
|
}
|
|
106
|
-
function
|
|
107
|
-
var
|
|
108
|
-
return
|
|
105
|
+
function a() {
|
|
106
|
+
var i = Y.A;
|
|
107
|
+
return i === null ? null : i.getOwner();
|
|
109
108
|
}
|
|
110
|
-
function
|
|
109
|
+
function o() {
|
|
111
110
|
return Error("react-stack-top-frame");
|
|
112
111
|
}
|
|
113
|
-
function
|
|
114
|
-
if (
|
|
115
|
-
var
|
|
116
|
-
if (
|
|
112
|
+
function n(i) {
|
|
113
|
+
if (u.call(i, "key")) {
|
|
114
|
+
var f = Object.getOwnPropertyDescriptor(i, "key").get;
|
|
115
|
+
if (f && f.isReactWarning) return !1;
|
|
117
116
|
}
|
|
118
|
-
return
|
|
117
|
+
return i.key !== void 0;
|
|
119
118
|
}
|
|
120
|
-
function
|
|
121
|
-
function
|
|
122
|
-
|
|
119
|
+
function l(i, f) {
|
|
120
|
+
function S() {
|
|
121
|
+
T || (T = !0, console.error(
|
|
123
122
|
"%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)",
|
|
124
|
-
|
|
123
|
+
f
|
|
125
124
|
));
|
|
126
125
|
}
|
|
127
|
-
|
|
128
|
-
get:
|
|
126
|
+
S.isReactWarning = !0, Object.defineProperty(i, "key", {
|
|
127
|
+
get: S,
|
|
129
128
|
configurable: !0
|
|
130
129
|
});
|
|
131
130
|
}
|
|
132
|
-
function
|
|
133
|
-
var
|
|
134
|
-
return
|
|
131
|
+
function d() {
|
|
132
|
+
var i = e(this.type);
|
|
133
|
+
return W[i] || (W[i] = !0, console.error(
|
|
135
134
|
"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."
|
|
136
|
-
)),
|
|
137
|
-
}
|
|
138
|
-
function
|
|
139
|
-
var
|
|
140
|
-
return
|
|
141
|
-
$$typeof:
|
|
142
|
-
type:
|
|
143
|
-
key:
|
|
144
|
-
props:
|
|
145
|
-
_owner:
|
|
146
|
-
}, (
|
|
135
|
+
)), i = this.props.ref, i !== void 0 ? i : null;
|
|
136
|
+
}
|
|
137
|
+
function p(i, f, S, L, X, ne) {
|
|
138
|
+
var F = S.ref;
|
|
139
|
+
return i = {
|
|
140
|
+
$$typeof: E,
|
|
141
|
+
type: i,
|
|
142
|
+
key: f,
|
|
143
|
+
props: S,
|
|
144
|
+
_owner: L
|
|
145
|
+
}, (F !== void 0 ? F : null) !== null ? Object.defineProperty(i, "ref", {
|
|
147
146
|
enumerable: !1,
|
|
148
|
-
get:
|
|
149
|
-
}) : Object.defineProperty(
|
|
147
|
+
get: d
|
|
148
|
+
}) : Object.defineProperty(i, "ref", { enumerable: !1, value: null }), i._store = {}, Object.defineProperty(i._store, "validated", {
|
|
150
149
|
configurable: !1,
|
|
151
150
|
enumerable: !1,
|
|
152
151
|
writable: !0,
|
|
153
152
|
value: 0
|
|
154
|
-
}), Object.defineProperty(
|
|
153
|
+
}), Object.defineProperty(i, "_debugInfo", {
|
|
155
154
|
configurable: !1,
|
|
156
155
|
enumerable: !1,
|
|
157
156
|
writable: !0,
|
|
158
157
|
value: null
|
|
159
|
-
}), Object.defineProperty(
|
|
158
|
+
}), Object.defineProperty(i, "_debugStack", {
|
|
160
159
|
configurable: !1,
|
|
161
160
|
enumerable: !1,
|
|
162
161
|
writable: !0,
|
|
163
|
-
value:
|
|
164
|
-
}), Object.defineProperty(
|
|
162
|
+
value: X
|
|
163
|
+
}), Object.defineProperty(i, "_debugTask", {
|
|
165
164
|
configurable: !1,
|
|
166
165
|
enumerable: !1,
|
|
167
166
|
writable: !0,
|
|
168
|
-
value:
|
|
169
|
-
}), Object.freeze && (Object.freeze(
|
|
170
|
-
}
|
|
171
|
-
function
|
|
172
|
-
var
|
|
173
|
-
if (
|
|
174
|
-
if (
|
|
175
|
-
if (
|
|
176
|
-
for (
|
|
177
|
-
|
|
178
|
-
Object.freeze && Object.freeze(
|
|
167
|
+
value: ne
|
|
168
|
+
}), Object.freeze && (Object.freeze(i.props), Object.freeze(i)), i;
|
|
169
|
+
}
|
|
170
|
+
function g(i, f, S, L, X, ne) {
|
|
171
|
+
var F = f.children;
|
|
172
|
+
if (F !== void 0)
|
|
173
|
+
if (L)
|
|
174
|
+
if (w(F)) {
|
|
175
|
+
for (L = 0; L < F.length; L++)
|
|
176
|
+
x(F[L]);
|
|
177
|
+
Object.freeze && Object.freeze(F);
|
|
179
178
|
} else
|
|
180
179
|
console.error(
|
|
181
180
|
"React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."
|
|
182
181
|
);
|
|
183
|
-
else
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
var
|
|
187
|
-
return
|
|
182
|
+
else x(F);
|
|
183
|
+
if (u.call(f, "key")) {
|
|
184
|
+
F = e(i);
|
|
185
|
+
var B = Object.keys(f).filter(function(pe) {
|
|
186
|
+
return pe !== "key";
|
|
188
187
|
});
|
|
189
|
-
|
|
188
|
+
L = 0 < B.length ? "{key: someKey, " + B.join(": ..., ") + ": ...}" : "{key: someKey}", Q[F + L] || (B = 0 < B.length ? "{" + B.join(": ..., ") + ": ...}" : "{}", console.error(
|
|
190
189
|
`A props object containing a "key" prop is being spread into JSX:
|
|
191
190
|
let props = %s;
|
|
192
191
|
<%s {...props} />
|
|
193
192
|
React keys must be passed directly to JSX without using spread:
|
|
194
193
|
let props = %s;
|
|
195
194
|
<%s key={someKey} {...props} />`,
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
),
|
|
195
|
+
L,
|
|
196
|
+
F,
|
|
197
|
+
B,
|
|
198
|
+
F
|
|
199
|
+
), Q[F + L] = !0);
|
|
201
200
|
}
|
|
202
|
-
if (
|
|
203
|
-
|
|
204
|
-
for (var
|
|
205
|
-
|
|
206
|
-
} else
|
|
207
|
-
return
|
|
208
|
-
|
|
209
|
-
typeof
|
|
210
|
-
),
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
201
|
+
if (F = null, S !== void 0 && (r(S), F = "" + S), n(f) && (r(f.key), F = "" + f.key), "key" in f) {
|
|
202
|
+
S = {};
|
|
203
|
+
for (var ae in f)
|
|
204
|
+
ae !== "key" && (S[ae] = f[ae]);
|
|
205
|
+
} else S = f;
|
|
206
|
+
return F && l(
|
|
207
|
+
S,
|
|
208
|
+
typeof i == "function" ? i.displayName || i.name || "Unknown" : i
|
|
209
|
+
), p(
|
|
210
|
+
i,
|
|
211
|
+
F,
|
|
212
|
+
S,
|
|
213
|
+
a(),
|
|
214
|
+
X,
|
|
215
|
+
ne
|
|
217
216
|
);
|
|
218
217
|
}
|
|
219
|
-
function
|
|
220
|
-
|
|
218
|
+
function x(i) {
|
|
219
|
+
m(i) ? i._store && (i._store.validated = 1) : typeof i == "object" && i !== null && i.$$typeof === U && (i._payload.status === "fulfilled" ? m(i._payload.value) && i._payload.value._store && (i._payload.value._store.validated = 1) : i._store && (i._store.validated = 1));
|
|
221
220
|
}
|
|
222
|
-
function
|
|
223
|
-
return typeof
|
|
221
|
+
function m(i) {
|
|
222
|
+
return typeof i == "object" && i !== null && i.$$typeof === E;
|
|
224
223
|
}
|
|
225
|
-
var
|
|
224
|
+
var h = ve, E = /* @__PURE__ */ Symbol.for("react.transitional.element"), R = /* @__PURE__ */ Symbol.for("react.portal"), y = /* @__PURE__ */ Symbol.for("react.fragment"), v = /* @__PURE__ */ Symbol.for("react.strict_mode"), c = /* @__PURE__ */ Symbol.for("react.profiler"), b = /* @__PURE__ */ Symbol.for("react.consumer"), C = /* @__PURE__ */ Symbol.for("react.context"), z = /* @__PURE__ */ Symbol.for("react.forward_ref"), j = /* @__PURE__ */ Symbol.for("react.suspense"), te = /* @__PURE__ */ Symbol.for("react.suspense_list"), re = /* @__PURE__ */ Symbol.for("react.memo"), U = /* @__PURE__ */ Symbol.for("react.lazy"), se = /* @__PURE__ */ Symbol.for("react.activity"), ie = /* @__PURE__ */ Symbol.for("react.client.reference"), Y = h.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE, u = Object.prototype.hasOwnProperty, w = Array.isArray, I = console.createTask ? console.createTask : function() {
|
|
226
225
|
return null;
|
|
227
226
|
};
|
|
228
|
-
|
|
229
|
-
react_stack_bottom_frame: function(
|
|
230
|
-
return
|
|
227
|
+
h = {
|
|
228
|
+
react_stack_bottom_frame: function(i) {
|
|
229
|
+
return i();
|
|
231
230
|
}
|
|
232
231
|
};
|
|
233
|
-
var
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
)(),
|
|
237
|
-
|
|
238
|
-
var
|
|
239
|
-
return
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
232
|
+
var T, W = {}, O = h.react_stack_bottom_frame.bind(
|
|
233
|
+
h,
|
|
234
|
+
o
|
|
235
|
+
)(), J = I(s(o)), Q = {};
|
|
236
|
+
G.Fragment = y, G.jsx = function(i, f, S) {
|
|
237
|
+
var L = 1e4 > Y.recentlyCreatedOwnerStacks++;
|
|
238
|
+
return g(
|
|
239
|
+
i,
|
|
240
|
+
f,
|
|
241
|
+
S,
|
|
243
242
|
!1,
|
|
244
|
-
|
|
245
|
-
|
|
243
|
+
L ? Error("react-stack-top-frame") : O,
|
|
244
|
+
L ? I(s(i)) : J
|
|
246
245
|
);
|
|
247
|
-
},
|
|
248
|
-
var
|
|
249
|
-
return
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
246
|
+
}, G.jsxs = function(i, f, S) {
|
|
247
|
+
var L = 1e4 > Y.recentlyCreatedOwnerStacks++;
|
|
248
|
+
return g(
|
|
249
|
+
i,
|
|
250
|
+
f,
|
|
251
|
+
S,
|
|
253
252
|
!0,
|
|
254
|
-
|
|
255
|
-
|
|
253
|
+
L ? Error("react-stack-top-frame") : O,
|
|
254
|
+
L ? I(s(i)) : J
|
|
256
255
|
);
|
|
257
256
|
};
|
|
258
|
-
})()),
|
|
257
|
+
})()), G;
|
|
259
258
|
}
|
|
260
|
-
var
|
|
261
|
-
function
|
|
262
|
-
return
|
|
259
|
+
var ue;
|
|
260
|
+
function ye() {
|
|
261
|
+
return ue || (ue = 1, process.env.NODE_ENV === "production" ? Z.exports = be() : Z.exports = we()), Z.exports;
|
|
262
|
+
}
|
|
263
|
+
var k = ye(), ee = class {
|
|
264
|
+
constructor(e = 2, t = "[fuzzy-search]", r = console) {
|
|
265
|
+
this.level = e, this.prefix = t, this.impl = r;
|
|
266
|
+
}
|
|
267
|
+
setLevel(e) {
|
|
268
|
+
this.level = e;
|
|
269
|
+
}
|
|
270
|
+
setImplementation(e) {
|
|
271
|
+
this.impl = e;
|
|
272
|
+
}
|
|
273
|
+
setPrefix(e) {
|
|
274
|
+
this.prefix = e;
|
|
275
|
+
}
|
|
276
|
+
formatMessage(e) {
|
|
277
|
+
return typeof e == "string" ? [`${this.prefix} ${e}`] : [this.prefix, e];
|
|
278
|
+
}
|
|
279
|
+
debug(e, ...t) {
|
|
280
|
+
this.level <= 0 && this.impl.debug(...this.formatMessage(e), ...t);
|
|
281
|
+
}
|
|
282
|
+
info(e, ...t) {
|
|
283
|
+
this.level <= 1 && this.impl.info(...this.formatMessage(e), ...t);
|
|
284
|
+
}
|
|
285
|
+
warn(e, ...t) {
|
|
286
|
+
this.level <= 2 && this.impl.warn(...this.formatMessage(e), ...t);
|
|
287
|
+
}
|
|
288
|
+
error(e, ...t) {
|
|
289
|
+
this.level <= 3 && this.impl.error(...this.formatMessage(e), ...t);
|
|
290
|
+
}
|
|
291
|
+
}, _ = { threshold: 0.4, caseSensitive: !1, learningWeight: 1.2, debounceMs: 300, multiTermOperator: "or", autoSearchOnIndexRebuild: !0, customWeights: {}, ngramSize: 2, minNgramOverlap: 1, sortBy: "relevance", sortOrder: "desc", enableIndexFiltering: !0, enableLevenshtein: !0, parallelSearchStrategy: "balanced", logLevel: 2, indexWorkerOptions: { strategy: "hybrid", threshold: 0.4, ngramOverlapThreshold: 0.3, minCandidatesRatio: 0.1, maxCandidatesRatio: 0.5, jaroWinklerPrefix: 0.1, maxResults: 1e3, relevanceFieldWeight: 0.2, relevancePerfectMatchBonus: 0.1 }, levenshteinWorkerOptions: { threshold: 0.3, lengthSimilarityThreshold: 0.1, partialMatchBonus: 0.1, lengthDiffPenalty: 1, maxResults: 1e3, relevanceFieldWeight: 0.15 } }, he = "INDEX_DATA_MISMATCH", Ee = "LEVENSHTEIN_DATA_MISMATCH", de = /* @__PURE__ */ new WeakMap(), Se = 0, We = (e) => {
|
|
292
|
+
let t = de.get(e);
|
|
293
|
+
if (t) return t;
|
|
294
|
+
let r;
|
|
295
|
+
try {
|
|
296
|
+
let s = JSON.stringify(e), a = 2166136261, o = -624069552;
|
|
297
|
+
for (let n = 0; n < s.length; n++) {
|
|
298
|
+
let l = s.charCodeAt(n);
|
|
299
|
+
a = Math.imul(a ^ l, 16777619) >>> 0, o = Math.imul(o ^ l, 16777619) >>> 0;
|
|
300
|
+
}
|
|
301
|
+
r = `${a.toString(36)}-${o.toString(36)}`;
|
|
302
|
+
} catch {
|
|
303
|
+
r = `ref-${++Se}`;
|
|
304
|
+
}
|
|
305
|
+
return de.set(e, r), r;
|
|
306
|
+
}, ce = (e, t) => {
|
|
307
|
+
if (!e) return null;
|
|
308
|
+
let r = e.includes(".ts") ? `../worker/${t}.ts` : `./worker/${t}.mjs`;
|
|
309
|
+
return new URL(r, e);
|
|
310
|
+
}, fe = class K {
|
|
311
|
+
constructor(t) {
|
|
312
|
+
this.indexWorker = null, this.levenshteinWorker = null, this.initializationPromise = null, this.referenceCount = 0, this.lastIndexedDataHash = null, this.buildingDataHash = null, this.buildingPromise = null, this.lastLevenshteinDataHash = null, this.id = t;
|
|
313
|
+
let r = t !== "default" ? `[GlobalWorkerManager:${t}]` : "[GlobalWorkerManager]";
|
|
314
|
+
this.logger = new ee(2, r);
|
|
315
|
+
}
|
|
316
|
+
static getInstance(t = "default") {
|
|
317
|
+
let r = K.instances.get(t);
|
|
318
|
+
return r || (r = new K(t), K.instances.set(t, r)), r;
|
|
319
|
+
}
|
|
320
|
+
getLastIndexedDataHash() {
|
|
321
|
+
return this.lastIndexedDataHash;
|
|
322
|
+
}
|
|
323
|
+
getLastLevenshteinDataHash() {
|
|
324
|
+
return this.lastLevenshteinDataHash;
|
|
325
|
+
}
|
|
326
|
+
setLastLevenshteinDataHash(t) {
|
|
327
|
+
this.lastLevenshteinDataHash = t;
|
|
328
|
+
}
|
|
329
|
+
setLastIndexedDataHash(t) {
|
|
330
|
+
this.lastIndexedDataHash = t;
|
|
331
|
+
}
|
|
332
|
+
getBuildingPromise(t) {
|
|
333
|
+
return this.buildingDataHash === t ? this.buildingPromise : null;
|
|
334
|
+
}
|
|
335
|
+
setBuildingPromise(t, r) {
|
|
336
|
+
this.buildingDataHash = t, this.buildingPromise = r, r.finally(() => {
|
|
337
|
+
this.buildingDataHash === t && (this.buildingDataHash = null, this.buildingPromise = null);
|
|
338
|
+
}).catch(() => {
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
async getWorkers(t) {
|
|
342
|
+
return t.logLevel !== void 0 && this.logger.setLevel(t.logLevel), t.logger && this.logger.setImplementation(t.logger), this.referenceCount++, this.indexWorker && this.levenshteinWorker ? (this.logger.debug(`🔧 Using existing global Workers (ref count: ${this.referenceCount})`), t.logLevel !== void 0 && (this.indexWorker.postMessage({ type: "setLogLevel", id: "system", logLevel: t.logLevel, workerId: this.id }), this.levenshteinWorker.postMessage({ type: "setLogLevel", id: "system", logLevel: t.logLevel, workerId: this.id })), { indexWorker: this.indexWorker, levenshteinWorker: this.levenshteinWorker }) : (this.initializationPromise || (this.initializationPromise = this.initializeWorkers(t)), await this.initializationPromise, this.indexWorker && this.levenshteinWorker || (this.initializationPromise = null), this.indexWorker && this.levenshteinWorker && t.logLevel !== void 0 && (this.indexWorker.postMessage({ type: "setLogLevel", id: "system", logLevel: t.logLevel, workerId: this.id }), this.levenshteinWorker.postMessage({ type: "setLogLevel", id: "system", logLevel: t.logLevel, workerId: this.id })), { indexWorker: this.indexWorker, levenshteinWorker: this.levenshteinWorker });
|
|
343
|
+
}
|
|
344
|
+
async initializeWorkers(t) {
|
|
345
|
+
if (typeof Worker > "u") return;
|
|
346
|
+
let r = import.meta.url;
|
|
347
|
+
try {
|
|
348
|
+
if (!this.indexWorker) {
|
|
349
|
+
let s = t.workerUrls?.indexWorker ? new URL(t.workerUrls.indexWorker, window.location.origin) : ce(r, "indexWorker");
|
|
350
|
+
s ? (this.logger.debug("🔧 Global Index Worker URL:", s.toString()), this.indexWorker = new Worker(s, { type: "module" }), this.logger.info("🔧 Global Index Worker: Initialized successfully")) : this.logger.warn("⚠️ Global Index Worker: default worker URL cannot be resolved in a CJS build. Specify options.workerUrls.indexWorker explicitly.");
|
|
351
|
+
}
|
|
352
|
+
if (!this.levenshteinWorker) {
|
|
353
|
+
let s = t.workerUrls?.levenshteinWorker ? new URL(t.workerUrls.levenshteinWorker, window.location.origin) : ce(r, "levenshteinWorker");
|
|
354
|
+
s ? (this.logger.debug("🔧 Global Levenshtein Worker URL:", s.toString()), this.levenshteinWorker = new Worker(s, { type: "module" }), this.logger.info("🔧 Global Levenshtein Worker: Initialized successfully")) : this.logger.warn("⚠️ Global Levenshtein Worker: default worker URL cannot be resolved in a CJS build. Specify options.workerUrls.levenshteinWorker explicitly.");
|
|
355
|
+
}
|
|
356
|
+
} catch (s) {
|
|
357
|
+
this.logger.warn("⚠️ Failed to initialize global Workers:", s);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
releaseReference() {
|
|
361
|
+
this.referenceCount--, this.logger.debug(`🔧 Worker reference released (ref count: ${this.referenceCount})`);
|
|
362
|
+
}
|
|
363
|
+
dispose() {
|
|
364
|
+
this.indexWorker && (this.indexWorker.terminate(), this.indexWorker = null), this.levenshteinWorker && (this.levenshteinWorker.terminate(), this.levenshteinWorker = null), this.initializationPromise = null, this.referenceCount = 0, this.lastIndexedDataHash = null, this.lastLevenshteinDataHash = null, this.logger.info("🔧 Global Workers disposed");
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
fe.instances = /* @__PURE__ */ new Map();
|
|
368
|
+
var M = fe, Ie = class {
|
|
369
|
+
constructor() {
|
|
370
|
+
this.listeners = /* @__PURE__ */ new Map(), this.logger = new ee(2);
|
|
371
|
+
}
|
|
372
|
+
setLogger(e) {
|
|
373
|
+
this.logger = e;
|
|
374
|
+
}
|
|
375
|
+
on(e, t) {
|
|
376
|
+
this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e)?.add(t);
|
|
377
|
+
}
|
|
378
|
+
off(e, t) {
|
|
379
|
+
let r = this.listeners.get(e);
|
|
380
|
+
r && r.delete(t);
|
|
381
|
+
}
|
|
382
|
+
emit(e, t) {
|
|
383
|
+
let r = this.listeners.get(e);
|
|
384
|
+
r && r.forEach((s) => {
|
|
385
|
+
try {
|
|
386
|
+
s(t);
|
|
387
|
+
} catch (a) {
|
|
388
|
+
this.logger.error(`❌ Error in event listener for ${e}:`, a);
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
removeAllListeners() {
|
|
393
|
+
this.listeners.clear();
|
|
394
|
+
}
|
|
395
|
+
}, Le = class {
|
|
396
|
+
constructor(e = {}) {
|
|
397
|
+
this.indexWorker = null, this.levenshteinWorker = null, this.searchHistory = [], this.learningData = { fieldWeights: {}, queryPatterns: {}, userPreferences: { preferredThreshold: 0.4, frequentFields: [], searchStyle: "fuzzy", lastUsedOptions: {} }, performanceMetrics: { averageSearchTime: {}, indexBuildTime: 0 } }, this.instanceId = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 8)}`, this.requestId = 0, this.pendingRequests = /* @__PURE__ */ new Map(), this.eventEmitter = new Ie(), this.isIndexBuilt = !1, this.lastIndexedDataHash = null, this.stats = { totalSearches: 0, averageSearchTime: 0, popularQueries: [], performanceBySize: {}, workers: { index: { stats: {} }, levenshtein: { stats: {} } } }, this.isDisposed = !1, this.cleanupTimerId = null, this.defaultOptions = { ..._, ...e, indexWorkerOptions: { ..._.indexWorkerOptions, ...e.indexWorkerOptions }, levenshteinWorkerOptions: { ..._.levenshteinWorkerOptions, ...e.levenshteinWorkerOptions } }, e.threshold !== void 0 && (e.levenshteinWorkerOptions || (this.defaultOptions.levenshteinWorkerOptions = { ...this.defaultOptions.levenshteinWorkerOptions, threshold: e.threshold }), e.indexWorkerOptions || (this.defaultOptions.indexWorkerOptions = { ...this.defaultOptions.indexWorkerOptions, threshold: e.threshold }));
|
|
398
|
+
let t = this.defaultOptions, r = "[fuzzy-search]";
|
|
399
|
+
t.instanceName ? r = `[fuzzy-search:${t.instanceName}]` : t.workerId && (r = `[fuzzy-search:${t.workerId}]`), this.logger = new ee(t.logLevel ?? 2, r, t.logger ?? console), this.eventEmitter.setLogger(this.logger), this.handleIndexWorkerMessageBound = this.handleIndexWorkerMessage.bind(this), this.handleIndexWorkerErrorBound = this.handleIndexWorkerError.bind(this), this.handleLevenshteinWorkerMessageBound = this.handleLevenshteinWorkerMessage.bind(this), this.handleLevenshteinWorkerErrorBound = this.handleLevenshteinWorkerError.bind(this), this.loadLearningData(), this.workersInitialized = this.initializeWorkers(), this.cleanupTimerId = setInterval(() => this.cleanupPendingRequests(), 3e4);
|
|
400
|
+
}
|
|
401
|
+
async initializeWorkers() {
|
|
402
|
+
if (!(typeof Worker > "u")) try {
|
|
403
|
+
let e = await M.getInstance(this.defaultOptions.workerId).getWorkers(this.defaultOptions);
|
|
404
|
+
if (this.isDisposed) {
|
|
405
|
+
this.logger.debug("🔧 Manager disposed before worker initialization completed");
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
this.indexWorker = e.indexWorker, this.levenshteinWorker = e.levenshteinWorker, this.indexWorker && (this.indexWorker.addEventListener("message", this.handleIndexWorkerMessageBound), this.indexWorker.addEventListener("error", this.handleIndexWorkerErrorBound), this.indexWorker.addEventListener("error", (t) => {
|
|
409
|
+
this.logger.error("🔧 Index Worker Error (Event Listener):", t);
|
|
410
|
+
})), this.levenshteinWorker && (this.levenshteinWorker.addEventListener("message", this.handleLevenshteinWorkerMessageBound), this.levenshteinWorker.addEventListener("error", this.handleLevenshteinWorkerErrorBound), this.levenshteinWorker.addEventListener("error", (t) => {
|
|
411
|
+
this.logger.error("🔧 Levenshtein Worker Error (Event Listener):", t);
|
|
412
|
+
})), this.eventEmitter.emit("workers:initialized", { indexWorker: !!this.indexWorker, levenshteinWorker: !!this.levenshteinWorker }), await this.testWorkerConnectivity();
|
|
413
|
+
} catch (e) {
|
|
414
|
+
this.logger.warn("⚠️ Failed to initialize Workers:", e);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
async testWorkerConnectivity() {
|
|
418
|
+
try {
|
|
419
|
+
let e = [];
|
|
420
|
+
this.indexWorker && e.push(this.pingWorker(this.indexWorker, "index")), this.levenshteinWorker && e.push(this.pingWorker(this.levenshteinWorker, "levenshtein")), await Promise.all(e);
|
|
421
|
+
} catch (e) {
|
|
422
|
+
this.logger.error("🔧 Worker connectivity test failed:", e);
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
async pingWorker(e, t) {
|
|
426
|
+
let r = `ping-${t}-${this.instanceId}-${Date.now()}`;
|
|
427
|
+
await new Promise((s, a) => {
|
|
428
|
+
let o = setTimeout(() => {
|
|
429
|
+
this.logger.warn(`🔧 ${t === "index" ? "Index" : "Levenshtein"} Worker: Ping timeout`), e.removeEventListener("message", n), a(new Error(`${t === "index" ? "Index" : "Levenshtein"} Worker ping timeout`));
|
|
430
|
+
}, 5e3), n = (l) => {
|
|
431
|
+
let d = l.data;
|
|
432
|
+
d.type === "pong" && d.id === r && (clearTimeout(o), e.removeEventListener("message", n), this.logger.debug(`🔧 ${t === "index" ? "Index" : "Levenshtein"} Worker: Ping successful`), s());
|
|
433
|
+
};
|
|
434
|
+
e.addEventListener("message", n), this.logger.debug(`🔧 ${t === "index" ? "Index" : "Levenshtein"} Worker: Sending ping message:`, r), e.postMessage({ type: "ping", id: r });
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
handleIndexWorkerMessage(e) {
|
|
438
|
+
let t = e.data;
|
|
439
|
+
if (this.logger.debug("🔧 Index Worker message received:", t.type, t), t.type === "indexSearchResults") {
|
|
440
|
+
let r = this.pendingRequests.get(t.id);
|
|
441
|
+
r && (this.pendingRequests.delete(t.id), t.error ? r.reject(new Error(t.error)) : r.resolve(t.results || [])), t.stats && (this.stats.workers.index.stats = t.stats, this.eventEmitter.emit("worker:statsUpdated", { worker: "index", stats: this.stats.workers.index.stats })), this.eventEmitter.emit("indexWorker:searchCompleted", { requestId: t.id, resultsCount: t.results?.length || 0, processingTime: t.processingTime });
|
|
442
|
+
} else if (t.type === "error") {
|
|
443
|
+
let r = this.pendingRequests.get(t.id);
|
|
444
|
+
r && (this.pendingRequests.delete(t.id), r.reject(new Error(t.error || "Index Worker error"))), this.logger.error("❌ Index Worker reported error:", { requestId: t.id, message: t.error, processingTime: t.processingTime }), this.eventEmitter.emit("indexWorker:error", { requestId: t.id, error: t.error, processingTime: t.processingTime });
|
|
445
|
+
} else t.type === "indexReady" ? (this.logger.info("✅ Index Worker: Index ready notification received", t), t.stats && (this.stats.workers.index.stats = t.stats, this.eventEmitter.emit("worker:statsUpdated", { worker: "index", stats: this.stats.workers.index.stats }))) : t.type === "pong" || t.type === "stats" && t.stats && (this.stats.workers.index.stats = t.stats, this.eventEmitter.emit("worker:statsUpdated", { worker: "index", stats: this.stats.workers.index.stats }));
|
|
446
|
+
this.eventEmitter.emit("indexWorker:message", t);
|
|
447
|
+
}
|
|
448
|
+
handleIndexWorkerError(e) {
|
|
449
|
+
this.logger.error("🔧 Index Worker Error:", { message: e.message, filename: e.filename, lineno: e.lineno, colno: e.colno, error: e.error, type: e.type }), this.eventEmitter.emit("indexWorker:error", e);
|
|
450
|
+
}
|
|
451
|
+
handleLevenshteinWorkerMessage(e) {
|
|
452
|
+
let t = e.data;
|
|
453
|
+
if (this.logger.debug("🔧 Levenshtein Worker message received:", t.type, "stats present:", !!t.stats), t.type === "levenshteinSearch") {
|
|
454
|
+
let r = this.pendingRequests.get(t.id);
|
|
455
|
+
r && (this.pendingRequests.delete(t.id), t.error ? r.reject(new Error(t.error)) : r.resolve(t.results || [])), t.stats && (this.stats.workers.levenshtein.stats = t.stats, this.eventEmitter.emit("worker:statsUpdated", { worker: "levenshtein", stats: this.stats.workers.levenshtein.stats })), this.eventEmitter.emit("levenshteinWorker:searchCompleted", { requestId: t.id, processingTime: t.processingTime, workerType: t.workerType, operationMeta: t.operationMeta });
|
|
456
|
+
} else if (t.type === "error") {
|
|
457
|
+
let r = this.pendingRequests.get(t.id);
|
|
458
|
+
r && (this.pendingRequests.delete(t.id), r.reject(new Error(t.error || "Levenshtein Worker error"))), this.logger.error("❌ Levenshtein Worker reported error:", { requestId: t.id, message: t.error, processingTime: t.processingTime }), this.eventEmitter.emit("levenshteinWorker:error", { requestId: t.id, error: t.error, processingTime: t.processingTime });
|
|
459
|
+
} else t.type === "pong" || t.type === "stats" && t.stats && (this.stats.workers.levenshtein.stats = t.stats, this.eventEmitter.emit("worker:statsUpdated", { worker: "levenshtein", stats: this.stats.workers.levenshtein.stats }));
|
|
460
|
+
this.eventEmitter.emit("levenshteinWorker:message", t);
|
|
461
|
+
}
|
|
462
|
+
handleLevenshteinWorkerError(e) {
|
|
463
|
+
this.logger.error("🔧 Levenshtein Worker Error:", { message: e.message, filename: e.filename, lineno: e.lineno, colno: e.colno, error: e.error, type: e.type }), this.eventEmitter.emit("levenshteinWorker:error", e);
|
|
464
|
+
}
|
|
465
|
+
isLocalStorageAvailable() {
|
|
466
|
+
try {
|
|
467
|
+
return typeof window < "u" && window.localStorage !== void 0;
|
|
468
|
+
} catch {
|
|
469
|
+
return !1;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
loadLearningData() {
|
|
473
|
+
try {
|
|
474
|
+
if (this.isLocalStorageAvailable()) {
|
|
475
|
+
let e = localStorage.getItem("fuzzy-search-learning-data");
|
|
476
|
+
if (e) {
|
|
477
|
+
let t = JSON.parse(e);
|
|
478
|
+
t && typeof t == "object" && t.queryPatterns && typeof t.queryPatterns == "object" && t.userPreferences && t.performanceMetrics && typeof t.performanceMetrics.averageSearchTime == "object" ? this.learningData = t : (this.logger.warn("⚠️ Stored learning data has an unexpected shape. Reinitializing with defaults."), this.initializeDefaultLearningData());
|
|
479
|
+
} else this.initializeDefaultLearningData();
|
|
480
|
+
} else this.initializeDefaultLearningData();
|
|
481
|
+
} catch (e) {
|
|
482
|
+
this.logger.warn("⚠️ Failed to load learning data:", e), this.initializeDefaultLearningData();
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
initializeDefaultLearningData() {
|
|
486
|
+
this.learningData = { fieldWeights: {}, queryPatterns: {}, userPreferences: { preferredThreshold: this.defaultOptions.threshold, frequentFields: [], searchStyle: "fuzzy", lastUsedOptions: {} }, performanceMetrics: { averageSearchTime: {}, indexBuildTime: 0 } };
|
|
487
|
+
}
|
|
488
|
+
saveLearningData() {
|
|
489
|
+
try {
|
|
490
|
+
this.isLocalStorageAvailable() && localStorage.setItem("fuzzy-search-learning-data", JSON.stringify(this.learningData));
|
|
491
|
+
} catch (e) {
|
|
492
|
+
this.logger.warn("⚠️ Failed to save learning data:", e);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
async search(e, t, r, s) {
|
|
496
|
+
if (!e.trim()) return this.logger.debug("🚫 search skipped for empty query"), [];
|
|
497
|
+
let a = performance.now(), o = { ...this.defaultOptions, ...s };
|
|
498
|
+
s?.threshold !== void 0 && (s.levenshteinWorkerOptions || (o.levenshteinWorkerOptions = { ...o.levenshteinWorkerOptions, threshold: s.threshold }), s.indexWorkerOptions || (o.indexWorkerOptions = { ...o.indexWorkerOptions, threshold: s.threshold })), this.logger.debug(`🚀 FuzzySearchManager.search called: query="${e}", items.length=${t.length}`), this.eventEmitter.emit("search:start", { query: e, options: o });
|
|
499
|
+
try {
|
|
500
|
+
if (await this.workersInitialized, this.isDisposed) return this.logger.debug("🚫 search skipped because manager is disposed"), [];
|
|
501
|
+
let n = this.generateDataHash(t, r), l = M.getInstance(this.defaultOptions.workerId), d = l.getLastIndexedDataHash();
|
|
502
|
+
if (d !== n) {
|
|
503
|
+
let m = l.getBuildingPromise(n);
|
|
504
|
+
if (m) this.logger.debug("🔧 Index build already in progress globally, waiting..."), await m, this.isIndexBuilt = !0, this.lastIndexedDataHash = n;
|
|
505
|
+
else {
|
|
506
|
+
this.logger.debug(`🔧 Building index: isIndexBuilt=${this.isIndexBuilt}, dataChanged=${d !== n}`);
|
|
507
|
+
let h = (async () => {
|
|
508
|
+
await this.buildIndex(t, r, o), this.isIndexBuilt = !0, this.lastIndexedDataHash = n, l.setLastIndexedDataHash(n);
|
|
509
|
+
})();
|
|
510
|
+
l.setBuildingPromise(n, h), await h;
|
|
511
|
+
}
|
|
512
|
+
} else this.isIndexBuilt ? this.logger.debug("🔧 Index already built for current data, skipping rebuild") : (this.logger.debug("🔧 Index already built globally for current data, skipping rebuild"), this.isIndexBuilt = !0, this.lastIndexedDataHash = n);
|
|
513
|
+
if (!(this.indexWorker && this.levenshteinWorker)) {
|
|
514
|
+
if (this.isDisposed) return this.logger.debug("🚫 search skipped because manager is disposed"), [];
|
|
515
|
+
throw new Error("Web Workers are not available or not initialized.");
|
|
516
|
+
}
|
|
517
|
+
let p = await this.searchParallel(e, t, r, o, n), g = performance.now() - a;
|
|
518
|
+
this.updateStats(e, g), this.updateLearningData(e, t.length, g);
|
|
519
|
+
let x = { results: p, totalItems: t.length, processingTime: g, query: e, options: o };
|
|
520
|
+
return this.eventEmitter.emit("search:complete", x), p;
|
|
521
|
+
} catch (n) {
|
|
522
|
+
let l = n instanceof Error ? n : new Error("Unknown search error");
|
|
523
|
+
throw this.eventEmitter.emit("search:error", { error: l, query: e }), l;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
async buildIndex(e, t, r) {
|
|
527
|
+
if (this.isDisposed) {
|
|
528
|
+
this.logger.debug("🚫 buildIndex skipped because manager is disposed");
|
|
529
|
+
return;
|
|
530
|
+
}
|
|
531
|
+
if (!this.indexWorker) {
|
|
532
|
+
if (this.isDisposed) {
|
|
533
|
+
this.logger.debug("🚫 buildIndex skipped because manager is disposed");
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
throw new Error("Index Worker not available");
|
|
537
|
+
}
|
|
538
|
+
let s = `build-index-${this.instanceId}-${++this.requestId}`;
|
|
539
|
+
this.logger.debug(`📤 Building index: requestId=${s}`);
|
|
540
|
+
let a = { type: "buildIndex", id: s, items: e, searchFields: t, options: this.toWorkerSafeOptions(r), dataHash: this.generateDataHash(e, t) };
|
|
541
|
+
return new Promise((o, n) => {
|
|
542
|
+
let l = null, d = (g) => {
|
|
543
|
+
let x = g;
|
|
544
|
+
x.type === "indexReady" && x.id === s && (this.logger.info(`✅ Index Worker: Index built successfully (requestId=${s})`), this.logger.debug(`🎯 buildIndex: Match found! Resolving promise for requestId=${s}`), this.eventEmitter.off("indexWorker:message", d), this.eventEmitter.off("indexWorker:message", p), l && (clearTimeout(l), l = null), o());
|
|
545
|
+
}, p = (g) => {
|
|
546
|
+
let x = g;
|
|
547
|
+
x.type === "error" && x.id === s && (this.logger.warn(`❌ buildIndex: Worker reported error for requestId=${s}`, x.error), this.eventEmitter.off("indexWorker:message", d), this.eventEmitter.off("indexWorker:message", p), l && (clearTimeout(l), l = null), n(new Error(x.error || "Index Worker error")));
|
|
548
|
+
};
|
|
549
|
+
this.eventEmitter.on("indexWorker:message", d), this.eventEmitter.on("indexWorker:message", p), this.indexWorker?.postMessage(a), l = setTimeout(() => {
|
|
550
|
+
this.eventEmitter.off("indexWorker:message", d), this.eventEmitter.off("indexWorker:message", p), l = null, n(new Error("Index build timeout"));
|
|
551
|
+
}, 6e4);
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
async searchParallel(e, t, r, s, a) {
|
|
555
|
+
if (this.isDisposed) return this.logger.debug("🚫 searchParallel skipped because manager is disposed"), [];
|
|
556
|
+
this.logger.debug(`🌐 searchParallel: query="${e}", items.length=${t.length}`);
|
|
557
|
+
let { enableIndexFiltering: o, enableLevenshtein: n } = s;
|
|
558
|
+
if (!(o || n)) return this.logger.warn("⚠️ Both search stages are disabled. Returning empty results."), [];
|
|
559
|
+
let l = o ? this.runIndexStage(e, t, r, s, a) : Promise.resolve({ stage: "index", results: [], processingTime: 0, confidence: 0, candidatesProcessed: 0 }), d = n ? this.runLevenshteinStage(e, t, r, s, a) : Promise.resolve({ stage: "levenshtein", results: [], processingTime: 0, confidence: 0, candidatesProcessed: 0 }), [p, g] = await Promise.all([l, d]), x = this.mergeParallelResults(p, g, s.parallelSearchStrategy || "balanced", s);
|
|
560
|
+
return this.logger.debug(`🔧 Parallel search completed: Index=${p.results.length}, Levenshtein=${g.results.length}, Merged=${x.results.length}`), x.results;
|
|
561
|
+
}
|
|
562
|
+
async runIndexStage(e, t, r, s, a) {
|
|
563
|
+
let o = () => {
|
|
564
|
+
let n = `index-${this.instanceId}-${++this.requestId}`;
|
|
565
|
+
this.logger.debug(`📤 Index Stage: requestId=${n}`);
|
|
566
|
+
let l = { type: "indexSearch", id: n, query: e, searchFields: r, options: this.toWorkerSafeOptions(s), dataHash: a };
|
|
567
|
+
return this.executeWorkerStage(this.indexWorker, l, { stage: "index", confidence: 0.8, timeoutMessage: "Index search timeout", unavailableMessage: "Index Worker not available" });
|
|
568
|
+
};
|
|
569
|
+
try {
|
|
570
|
+
return await o();
|
|
571
|
+
} catch (n) {
|
|
572
|
+
if (!(n instanceof Error ? n.message : String(n)).includes(he)) throw n;
|
|
573
|
+
this.logger.warn("⚠️ Index Stage: shared index was replaced by another dataset. Rebuilding and retrying..."), await this.rebuildSharedIndex(t, r, s, a);
|
|
574
|
+
try {
|
|
575
|
+
return await o();
|
|
576
|
+
} catch (l) {
|
|
577
|
+
if (!(l instanceof Error ? l.message : String(l)).includes(he)) throw l;
|
|
578
|
+
return this.logger.warn("⚠️ Index Stage: index is still contended by another dataset. Continuing without index results."), { stage: "index", results: [], processingTime: 0, confidence: 0, candidatesProcessed: 0 };
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
async rebuildSharedIndex(e, t, r, s) {
|
|
583
|
+
let a = M.getInstance(this.defaultOptions.workerId), o = a.getBuildingPromise(s);
|
|
584
|
+
if (o) {
|
|
585
|
+
await o;
|
|
586
|
+
return;
|
|
587
|
+
}
|
|
588
|
+
let n = (async () => {
|
|
589
|
+
await this.buildIndex(e, t, r), a.setLastIndexedDataHash(s);
|
|
590
|
+
})();
|
|
591
|
+
a.setBuildingPromise(s, n), await n;
|
|
592
|
+
}
|
|
593
|
+
async runLevenshteinStage(e, t, r, s, a) {
|
|
594
|
+
let o = M.getInstance(this.defaultOptions.workerId), n = (d) => {
|
|
595
|
+
let p = `levenshtein-${this.instanceId}-${++this.requestId}`;
|
|
596
|
+
this.logger.debug(`📤 Levenshtein Stage: requestId=${p}, includeItems=${d}`);
|
|
597
|
+
let g = { type: "levenshteinSearch", id: p, query: e, items: d ? t : void 0, searchFields: r, options: this.toWorkerSafeOptions(s), dataHash: a };
|
|
598
|
+
return this.executeWorkerStage(this.levenshteinWorker, g, { stage: "levenshtein", confidence: 0.9, timeoutMessage: "Levenshtein search timeout", unavailableMessage: "Levenshtein Worker not available" });
|
|
599
|
+
}, l = o.getLastLevenshteinDataHash() !== a;
|
|
600
|
+
try {
|
|
601
|
+
let d = await n(l);
|
|
602
|
+
return l && o.setLastLevenshteinDataHash(a), d;
|
|
603
|
+
} catch (d) {
|
|
604
|
+
let p = d instanceof Error ? d.message : String(d);
|
|
605
|
+
if (l || !p.includes(Ee)) throw d;
|
|
606
|
+
this.logger.warn("⚠️ Levenshtein Stage: worker dataset cache was replaced by another dataset. Retrying with items...");
|
|
607
|
+
let g = await n(!0);
|
|
608
|
+
return o.setLastLevenshteinDataHash(a), g;
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
executeWorkerStage(e, t, r) {
|
|
612
|
+
if (!e) throw new Error(r.unavailableMessage);
|
|
613
|
+
return new Promise((s, a) => {
|
|
614
|
+
let o = setTimeout(() => {
|
|
615
|
+
this.pendingRequests.has(t.id) && (this.pendingRequests.delete(t.id), a(new Error(r.timeoutMessage)));
|
|
616
|
+
}, 3e4);
|
|
617
|
+
this.pendingRequests.set(t.id, { resolve: (n) => {
|
|
618
|
+
clearTimeout(o), s({ stage: r.stage, results: n, processingTime: 0, confidence: r.confidence, candidatesProcessed: n.length });
|
|
619
|
+
}, reject: (n) => {
|
|
620
|
+
clearTimeout(o), a(n);
|
|
621
|
+
}, timestamp: Date.now() }), e.postMessage(t);
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
mergeParallelResults(e, t, r, s) {
|
|
625
|
+
let a = [];
|
|
626
|
+
switch (r) {
|
|
627
|
+
case "index-first":
|
|
628
|
+
a = e.results.length > 0 ? e.results : t.results;
|
|
629
|
+
break;
|
|
630
|
+
case "levenshtein-first":
|
|
631
|
+
a = t.results.length > 0 ? t.results : e.results;
|
|
632
|
+
break;
|
|
633
|
+
default:
|
|
634
|
+
a = this.mergeByScore([...e.results, ...t.results], s);
|
|
635
|
+
break;
|
|
636
|
+
}
|
|
637
|
+
return { results: a, totalProcessingTime: e.processingTime + t.processingTime, indexStage: e, levenshteinStage: t, mergeStrategy: r, mergeQuality: 0.8 };
|
|
638
|
+
}
|
|
639
|
+
mergeByScore(e, t) {
|
|
640
|
+
let r = /* @__PURE__ */ new Map();
|
|
641
|
+
e.forEach((n) => {
|
|
642
|
+
if (n.originalIndex !== void 0) {
|
|
643
|
+
let l = r.get(n.originalIndex);
|
|
644
|
+
(!l || n.score > l.score) && r.set(n.originalIndex, n);
|
|
645
|
+
}
|
|
646
|
+
});
|
|
647
|
+
let s = Array.from(r.values()), a = t.sortBy || _.sortBy, o = t.sortOrder || _.sortOrder;
|
|
648
|
+
return a === "original" ? s.sort((n, l) => (n.originalIndex ?? 0) - (l.originalIndex ?? 0)) : s.sort((n, l) => o === "asc" ? n.score - l.score : l.score - n.score);
|
|
649
|
+
}
|
|
650
|
+
generateDataHash(e, t) {
|
|
651
|
+
return `${e.length}|${t.join(",")}|${We(e)}`;
|
|
652
|
+
}
|
|
653
|
+
toWorkerSafeOptions(e) {
|
|
654
|
+
if (!e.logger) return e;
|
|
655
|
+
let { logger: t, ...r } = e;
|
|
656
|
+
return r;
|
|
657
|
+
}
|
|
658
|
+
updateStats(e, t) {
|
|
659
|
+
this.stats.totalSearches++, this.stats.averageSearchTime = (this.stats.averageSearchTime * (this.stats.totalSearches - 1) + t) / this.stats.totalSearches;
|
|
660
|
+
}
|
|
661
|
+
updateLearningData(e, t, r) {
|
|
662
|
+
if (this.learningData.queryPatterns[e] = (this.learningData.queryPatterns[e] ?? 0) + 1, Object.keys(this.learningData.queryPatterns).length > 200) {
|
|
663
|
+
let o = Object.entries(this.learningData.queryPatterns).sort((n, l) => l[1] - n[1]).slice(0, 100);
|
|
664
|
+
this.learningData.queryPatterns = Object.fromEntries(o);
|
|
665
|
+
}
|
|
666
|
+
let s = this.getPerformanceSizeKey(t);
|
|
667
|
+
this.learningData.performanceMetrics.averageSearchTime[s] = r, this.stats.popularQueries = Object.entries(this.learningData.queryPatterns).sort((o, n) => n[1] - o[1]).slice(0, 10).map(([o, n]) => ({ query: o, count: n }));
|
|
668
|
+
let a = this.stats.performanceBySize[s] ?? { averageTime: 0, sampleSize: 0 };
|
|
669
|
+
a.averageTime = (a.averageTime * a.sampleSize + r) / (a.sampleSize + 1), a.sampleSize += 1, this.stats.performanceBySize[s] = a, this.stats.totalSearches % 10 === 0 && this.saveLearningData();
|
|
670
|
+
}
|
|
671
|
+
getPerformanceSizeKey(e) {
|
|
672
|
+
return e < 1e3 ? "small" : e < 1e4 ? "medium" : e < 1e5 ? "large" : "xlarge";
|
|
673
|
+
}
|
|
674
|
+
cleanupPendingRequests() {
|
|
675
|
+
let e = Date.now(), t = 3e4;
|
|
676
|
+
this.pendingRequests.forEach((r, s) => {
|
|
677
|
+
e - r.timestamp > t && (r.reject(new Error("Request timeout")), this.pendingRequests.delete(s));
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
updateSearchHistory(e, t, r = 0, s = 0) {
|
|
681
|
+
let a = { query: e, timestamp: Date.now(), selectedItemId: t, resultCount: r, processingTime: s, searchTime: s, successful: r > 0 };
|
|
682
|
+
this.searchHistory.unshift(a), this.searchHistory.length > 1e3 && (this.searchHistory = this.searchHistory.slice(0, 500));
|
|
683
|
+
}
|
|
684
|
+
async getStats(e = 5e3) {
|
|
685
|
+
return await Promise.all([this.waitForWorkerStats(this.indexWorker, "index", e), this.waitForWorkerStats(this.levenshteinWorker, "levenshtein", e)]), this.stats;
|
|
686
|
+
}
|
|
687
|
+
getCurrentStats() {
|
|
688
|
+
return this.stats;
|
|
689
|
+
}
|
|
690
|
+
async resetStats(e = 5e3) {
|
|
691
|
+
let t = [this.resetWorkerStats(this.indexWorker, "index", e), this.resetWorkerStats(this.levenshteinWorker, "levenshtein", e)];
|
|
692
|
+
this.stats = { totalSearches: 0, averageSearchTime: 0, popularQueries: [], performanceBySize: {}, workers: { index: { stats: this.createEmptyWorkerStats("index") }, levenshtein: { stats: this.createEmptyWorkerStats("levenshtein") } } }, this.searchHistory = [], await Promise.all(t), this.logger.info("📊 FuzzySearchManager: All statistics have been reset"), this.eventEmitter.emit("stats:reset", { timestamp: Date.now(), resetBy: "manager" });
|
|
693
|
+
}
|
|
694
|
+
waitForWorkerStats(e, t, r) {
|
|
695
|
+
return e ? new Promise((s) => {
|
|
696
|
+
let a = setTimeout(() => {
|
|
697
|
+
this.logger.warn(`⚠️ getStats: Timeout waiting for ${t} worker.`), this.eventEmitter.off("worker:statsUpdated", o), s();
|
|
698
|
+
}, r), o = (n) => {
|
|
699
|
+
let { worker: l } = n;
|
|
700
|
+
l === t && (clearTimeout(a), this.eventEmitter.off("worker:statsUpdated", o), s());
|
|
701
|
+
};
|
|
702
|
+
this.eventEmitter.on("worker:statsUpdated", o), e.postMessage({ type: "getStats" });
|
|
703
|
+
}) : Promise.resolve();
|
|
704
|
+
}
|
|
705
|
+
resetWorkerStats(e, t, r) {
|
|
706
|
+
if (!e) return Promise.resolve();
|
|
707
|
+
let s = `resetStats-${this.instanceId}-${++this.requestId}-${t}`;
|
|
708
|
+
return new Promise((a) => {
|
|
709
|
+
let o = setTimeout(() => {
|
|
710
|
+
this.logger.warn(`⚠️ resetStats: Timeout waiting for ${t} worker.`), e.removeEventListener("message", n), a();
|
|
711
|
+
}, r), n = (d) => {
|
|
712
|
+
let p = d.data;
|
|
713
|
+
p.type === "resetStats" && p.id === s && (clearTimeout(o), e.removeEventListener("message", n), this.logger.info(`📊 ${t} worker statistics have been reset`), a());
|
|
714
|
+
};
|
|
715
|
+
e.addEventListener("message", n);
|
|
716
|
+
let l = { type: "resetStats", id: s };
|
|
717
|
+
e.postMessage(l);
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
createEmptyWorkerStats(e) {
|
|
721
|
+
return { basic: { totalSearches: 0, totalProcessingTime: 0, averageSearchTime: 0, lastSearchTime: 0, errorCount: 0, timestamp: Date.now() }, workerSpecific: { workerType: e, operationCount: 0, operationDistribution: {}, specificMetrics: {} }, analysis: { fieldPerformance: {}, performanceInsights: { recentAverageProcessingTime: 0, recentAverageResultCount: 0, throughputPerSecond: 0, totalHistoryEntries: 0, mostCommonQueryLength: 0, bestPerformingField: "", similarityDistribution: { highSimilarity: 0, mediumSimilarity: 0, lowSimilarity: 0, veryLowSimilarity: 0 } }, recentHistory: [] } };
|
|
722
|
+
}
|
|
723
|
+
getSearchHistory() {
|
|
724
|
+
return [...this.searchHistory];
|
|
725
|
+
}
|
|
726
|
+
on(e, t) {
|
|
727
|
+
this.eventEmitter.on(e, t);
|
|
728
|
+
}
|
|
729
|
+
off(e, t) {
|
|
730
|
+
this.eventEmitter.off(e, t);
|
|
731
|
+
}
|
|
732
|
+
async prebuildIndex(e, t, r) {
|
|
733
|
+
this.logger.info(`🏗️ Pre-building index for ${e.length} items`);
|
|
734
|
+
try {
|
|
735
|
+
if (await this.workersInitialized, this.isDisposed) {
|
|
736
|
+
this.logger.debug("🚫 prebuildIndex skipped because manager is disposed");
|
|
737
|
+
return;
|
|
738
|
+
}
|
|
739
|
+
let s = this.generateDataHash(e, t), a = M.getInstance(this.defaultOptions.workerId), o = a.getLastIndexedDataHash();
|
|
740
|
+
if (this.logger.debug(`🔧 Checking index status: globalHash=${o}, currentHash=${s}`), !this.isIndexBuilt || this.lastIndexedDataHash !== s) {
|
|
741
|
+
if (o === s) {
|
|
742
|
+
this.logger.debug("🔧 Index already built globally for current data, skipping pre-build"), this.isIndexBuilt = !0, this.lastIndexedDataHash = s;
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
let n = a.getBuildingPromise(s);
|
|
746
|
+
if (n) {
|
|
747
|
+
this.logger.debug("🔧 Index build already in progress globally, waiting..."), await n, this.isIndexBuilt = !0, this.lastIndexedDataHash = s;
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
this.logger.debug(`🔧 Pre-building index: isIndexBuilt=${this.isIndexBuilt}, dataChanged=${this.lastIndexedDataHash !== s}`);
|
|
751
|
+
let l = (async () => {
|
|
752
|
+
await this.rebuildIndex(e, t, r);
|
|
753
|
+
})();
|
|
754
|
+
a.setBuildingPromise(s, l), await l, this.logger.info(`✅ Index pre-built successfully for ${e.length} items`);
|
|
755
|
+
} else this.logger.debug("🔧 Index already built for current data, skipping pre-build");
|
|
756
|
+
} catch (s) {
|
|
757
|
+
throw this.logger.error("🔧 Error during index pre-building:", s), s;
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
async rebuildIndex(e, t, r) {
|
|
761
|
+
this.logger.info(`🔄 Starting forced index rebuild for ${e.length} items`);
|
|
762
|
+
let s = { ...this.defaultOptions, ...r };
|
|
763
|
+
try {
|
|
764
|
+
if (await this.workersInitialized, this.isDisposed) {
|
|
765
|
+
this.logger.debug("🚫 rebuildIndex skipped because manager is disposed");
|
|
766
|
+
return;
|
|
767
|
+
}
|
|
768
|
+
this.isIndexBuilt = !1, this.lastIndexedDataHash = null, await this.buildIndex(e, t, s), this.logger.info(`✅ Index rebuild completed successfully for ${e.length} items`), this.isIndexBuilt = !0, this.lastIndexedDataHash = this.generateDataHash(e, t);
|
|
769
|
+
let a = M.getInstance(this.defaultOptions.workerId);
|
|
770
|
+
a.setLastIndexedDataHash(this.lastIndexedDataHash), a.setLastLevenshteinDataHash(null), this.eventEmitter.emit("index:rebuilt", { itemCount: e.length, searchFields: t, timestamp: Date.now() });
|
|
771
|
+
} catch (a) {
|
|
772
|
+
throw this.logger.error("❌ Failed to rebuild index:", a), this.eventEmitter.emit("index:rebuildError", { error: a instanceof Error ? a.message : String(a), timestamp: Date.now() }), a;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
dispose() {
|
|
776
|
+
this.isDisposed = !0, this.cleanupTimerId && (clearInterval(this.cleanupTimerId), this.cleanupTimerId = null), this.indexWorker && (this.indexWorker.removeEventListener("message", this.handleIndexWorkerMessageBound), this.indexWorker.removeEventListener("error", this.handleIndexWorkerErrorBound)), this.levenshteinWorker && (this.levenshteinWorker.removeEventListener("message", this.handleLevenshteinWorkerMessageBound), this.levenshteinWorker.removeEventListener("error", this.handleLevenshteinWorkerErrorBound)), M.getInstance(this.defaultOptions.workerId).releaseReference(), this.indexWorker = null, this.levenshteinWorker = null, this.pendingRequests.forEach((e) => {
|
|
777
|
+
e.reject(new Error("FuzzySearchManager disposed"));
|
|
778
|
+
}), this.pendingRequests.clear(), this.eventEmitter.removeAllListeners(), this.saveLearningData();
|
|
779
|
+
}
|
|
780
|
+
}, q = (e, t) => {
|
|
781
|
+
if (typeof e == "string" && e.trim()) return e;
|
|
782
|
+
if (e instanceof Error && e.message.trim()) return e.message;
|
|
783
|
+
if (typeof e == "object" && e !== null) {
|
|
784
|
+
if ("error" in e) return q(e.error, t);
|
|
785
|
+
if ("message" in e) return q(e.message, t);
|
|
786
|
+
}
|
|
787
|
+
return t;
|
|
788
|
+
};
|
|
789
|
+
function Fe(e, t, r) {
|
|
790
|
+
let [s, a] = A(""), [o, n] = A([]), [l, d] = A(!1), [p, g] = A(!1), [x, m] = A(null), [h, E] = A([]), [R, y] = A({ totalSearches: 0, averageSearchTime: 0, itemCount: e.length, resultsCount: 0, workerStats: void 0 }), v = H(() => {
|
|
791
|
+
let u = { ..._, ...r };
|
|
792
|
+
return r?.threshold !== void 0 && (r.levenshteinWorkerOptions || (u.levenshteinWorkerOptions = { ...u.levenshteinWorkerOptions, threshold: r.threshold }), r.indexWorkerOptions || (u.indexWorkerOptions = { ...u.indexWorkerOptions, threshold: r.threshold })), u;
|
|
793
|
+
}, [r]), c = H(() => {
|
|
794
|
+
let u = "[fuzzy-search-react]";
|
|
795
|
+
return v.instanceName ? u = `[fuzzy-search-react:${v.instanceName}]` : v.workerId && (u = `[fuzzy-search-react:${v.workerId}]`), new ee(v.logLevel ?? 2, u, v.logger ?? console);
|
|
796
|
+
}, [v.logLevel, v.logger, v.workerId, v.instanceName]), b = N(null), C = N(s);
|
|
797
|
+
$(() => {
|
|
798
|
+
C.current = s;
|
|
799
|
+
}, [s]);
|
|
800
|
+
let z = H(() => t.map((u) => String(u)), [t]);
|
|
801
|
+
$(() => (b.current = new Le(v), c.debug("🔧 FuzzySearchManager created (initial setup)"), () => {
|
|
802
|
+
c.debug("🔧 FuzzySearchManager disposed (component unmount)"), b.current?.dispose(), b.current = null;
|
|
803
|
+
}), [v, c]), $(() => {
|
|
804
|
+
if (!b.current) return;
|
|
805
|
+
let u = () => {
|
|
806
|
+
if (b.current) {
|
|
807
|
+
let W = b.current.getCurrentStats(), O = { totalSearches: W?.totalSearches ?? 0, averageSearchTime: W?.averageSearchTime ?? 0, itemCount: e.length, resultsCount: o.length, workerStats: { index: W?.workers.index.stats, levenshtein: W?.workers.levenshtein.stats } };
|
|
808
|
+
y(O);
|
|
809
|
+
}
|
|
810
|
+
}, w = (W) => {
|
|
811
|
+
let O = q(W, "Index Worker error");
|
|
812
|
+
c.error("❌ Index worker error event", W), m(O), g(!1);
|
|
813
|
+
}, I = (W) => {
|
|
814
|
+
let O = q(W, "Index rebuild error");
|
|
815
|
+
c.error("❌ Index rebuild error event", W), m(O), g(!1);
|
|
816
|
+
}, T = (W) => {
|
|
817
|
+
let O = q(W, "Search execution failed");
|
|
818
|
+
c.error("❌ Search error event", W), m(O);
|
|
819
|
+
};
|
|
820
|
+
return b.current.on("worker:statsUpdated", u), b.current.on("search:complete", u), b.current.on("indexWorker:error", w), b.current.on("index:rebuildError", I), b.current.on("search:error", T), () => {
|
|
821
|
+
b.current && (b.current.off("worker:statsUpdated", u), b.current.off("search:complete", u), b.current.off("indexWorker:error", w), b.current.off("index:rebuildError", I), b.current.off("search:error", T));
|
|
822
|
+
};
|
|
823
|
+
}, [e.length, o.length, c, v]);
|
|
824
|
+
let j = D(async (u) => {
|
|
825
|
+
if (b.current) {
|
|
826
|
+
if (c.debug(`🔍 performSearch called with query: "${u}"`), u !== C.current) {
|
|
827
|
+
c.debug(`🚫 performSearch skipped for stale query: "${u}" (current: "${C.current}")`);
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
try {
|
|
831
|
+
if (c.debug(`📈 Setting isSearching to true for query: "${u}"`), d(!0), m(null), !u.trim()) {
|
|
832
|
+
c.debug(`📈 Setting isSearching to false for empty query: "${u}"`), d(!1);
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
c.info(`🚀 Starting search with query: "${u}", items count: ${e.length}`);
|
|
836
|
+
let w = performance.now(), I = await b.current.search(u, e, z, v), T = performance.now() - w;
|
|
837
|
+
if (u !== C.current) {
|
|
838
|
+
c.debug(`🚫 Search result ignored for stale query: "${u}" (current: "${C.current}")`);
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
841
|
+
c.info(`✅ Search completed with ${I.length} results in ${T}ms`), n(I);
|
|
842
|
+
let W = { query: u, timestamp: Date.now(), resultCount: I.length, processingTime: T, searchTime: T, successful: I.length > 0 };
|
|
843
|
+
E((O) => {
|
|
844
|
+
let J = O.filter((Q) => Q.query !== u);
|
|
845
|
+
return [W, ...J].slice(0, 50);
|
|
846
|
+
});
|
|
847
|
+
} catch (w) {
|
|
848
|
+
if (u !== C.current) return;
|
|
849
|
+
c.error(`❌ Search error for query: "${u}"`, w), m(w instanceof Error ? w.message : "Search failed"), n([]);
|
|
850
|
+
} finally {
|
|
851
|
+
u === C.current && (c.debug(`📈 Setting isSearching to false (finally) for query: "${u}"`), d(!1));
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}, [e, z, v, c.info, c.error, c.debug]);
|
|
855
|
+
$(() => {
|
|
856
|
+
if (!b.current || e.length === 0) {
|
|
857
|
+
g(!1);
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
let u = !1, w = v.autoSearchOnIndexRebuild ?? !0;
|
|
861
|
+
return c.info(`🏗️ Data changed, pre-building index for ${e.length} items`), g(!0), b.current.prebuildIndex(e, z, v).then(() => {
|
|
862
|
+
!u && w && (c.debug("🔁 Re-running search after index rebuild"), j(C.current));
|
|
863
|
+
}).catch((I) => {
|
|
864
|
+
c.warn("🔧 Failed to pre-build index:", I), u || m(q(I, "インデックスの事前構築中にエラーが発生しました"));
|
|
865
|
+
}).finally(() => {
|
|
866
|
+
u || g(!1);
|
|
867
|
+
}), () => {
|
|
868
|
+
u = !0;
|
|
869
|
+
};
|
|
870
|
+
}, [e, z, v, j, c.warn, c.info, c.debug]), $(() => {
|
|
871
|
+
c.debug(`🎯 useEffect triggered - searchTerm: "${s}", debounceMs: ${v.debounceMs}`);
|
|
872
|
+
let u = setTimeout(() => {
|
|
873
|
+
c.debug(`⏰ Timeout executing performSearch for: "${s}"`), j(s);
|
|
874
|
+
}, v.debounceMs);
|
|
875
|
+
return () => {
|
|
876
|
+
c.debug(`🚫 Timeout cleared for: "${s}"`), clearTimeout(u);
|
|
877
|
+
};
|
|
878
|
+
}, [s, v, j, c]), $(() => {
|
|
879
|
+
s.trim() || n(e.map((u, w) => ({ item: u, score: 1, baseScore: 1, matchedFields: [], relevanceReason: "全件表示", originalIndex: w })));
|
|
880
|
+
}, [e, s]);
|
|
881
|
+
let te = D((u, w) => {
|
|
882
|
+
c.info("🎯 Selected item:", u, "at index:", w);
|
|
883
|
+
}, [c]), re = D(() => {
|
|
884
|
+
a(""), m(null);
|
|
885
|
+
}, []), U = D(() => {
|
|
886
|
+
E([]);
|
|
887
|
+
}, []), se = D(async () => {
|
|
888
|
+
if (b.current) {
|
|
889
|
+
await b.current.resetStats(), E([]), m(null);
|
|
890
|
+
let u = b.current.getCurrentStats(), w = { totalSearches: u?.totalSearches ?? 0, averageSearchTime: u?.averageSearchTime ?? 0, itemCount: e.length, resultsCount: o.length, workerStats: { index: u?.workers.index.stats, levenshtein: u?.workers.levenshtein.stats } };
|
|
891
|
+
y(w), c.info("📊 useFuzzySearch: Statistics have been reset and refreshed");
|
|
892
|
+
}
|
|
893
|
+
}, [e.length, o.length, c]), ie = D((u, w = 5) => {
|
|
894
|
+
let I = h.filter((T) => T.query.toLowerCase().includes(u.toLowerCase()) && T.query !== u).sort((T, W) => W.timestamp - T.timestamp).slice(0, w).map((T) => T.query);
|
|
895
|
+
return Array.from(new Set(I));
|
|
896
|
+
}, [h]), Y = D(async (u) => {
|
|
897
|
+
if (!b.current) {
|
|
898
|
+
c.warn("⚠️ Search manager is not initialized");
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
c.info(`🔄 Rebuilding index for ${e.length} items`), g(!0), m(null);
|
|
902
|
+
try {
|
|
903
|
+
let w = u ? { ...v, ...u } : v;
|
|
904
|
+
await b.current.rebuildIndex(e, z, w), c.info("✅ Index rebuild completed successfully");
|
|
905
|
+
} catch (w) {
|
|
906
|
+
let I = w instanceof Error ? w.message : "インデックス再構築中にエラーが発生しました";
|
|
907
|
+
throw c.error("❌ Index rebuild failed:", I), m(I), w;
|
|
908
|
+
} finally {
|
|
909
|
+
g(!1);
|
|
910
|
+
}
|
|
911
|
+
}, [e, z, v, c]);
|
|
912
|
+
return { searchTerm: s, setSearchTerm: a, filteredItems: o, isSearching: l, isIndexBuilding: p, error: x, searchHistory: h, options: v, selectItem: te, clearSearch: re, clearHistory: U, resetStats: se, getSearchSuggestions: ie, performanceMetrics: R, rebuildIndex: Y };
|
|
263
913
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const c = $(
|
|
914
|
+
function Te(e, t, r) {
|
|
915
|
+
const s = H(
|
|
267
916
|
() => ({
|
|
268
917
|
threshold: 0.3,
|
|
269
918
|
sortBy: "score",
|
|
270
919
|
sortOrder: "desc",
|
|
271
|
-
workerUrls:
|
|
920
|
+
workerUrls: r
|
|
272
921
|
}),
|
|
273
|
-
[
|
|
274
|
-
),
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}, [t,
|
|
278
|
-
const
|
|
279
|
-
if (!t) return
|
|
280
|
-
const
|
|
281
|
-
for (const
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
}
|
|
285
|
-
return [...
|
|
286
|
-
}, [
|
|
922
|
+
[r]
|
|
923
|
+
), a = H(() => ["label"], []), { setSearchTerm: o, filteredItems: n, isSearching: l } = Fe(e, a, s);
|
|
924
|
+
$(() => {
|
|
925
|
+
o(t);
|
|
926
|
+
}, [t, o]);
|
|
927
|
+
const d = H(() => {
|
|
928
|
+
if (!t) return e;
|
|
929
|
+
const p = t.toLowerCase(), g = [], x = [];
|
|
930
|
+
for (const m of n) {
|
|
931
|
+
const h = m.item;
|
|
932
|
+
h.label.toLowerCase() === p ? g.push(h) : x.push(h);
|
|
933
|
+
}
|
|
934
|
+
return [...g, ...x];
|
|
935
|
+
}, [n, t, e]);
|
|
287
936
|
return {
|
|
288
|
-
filteredOptions: t ?
|
|
289
|
-
isSearching:
|
|
937
|
+
filteredOptions: t ? d : e,
|
|
938
|
+
isSearching: l
|
|
290
939
|
};
|
|
291
940
|
}
|
|
292
|
-
function
|
|
293
|
-
const [
|
|
294
|
-
|
|
295
|
-
const
|
|
296
|
-
|
|
941
|
+
function Re({ value: e, onChange: t, multiple: r }) {
|
|
942
|
+
const [s, a] = A(!1), [o, n] = A(""), l = N(null);
|
|
943
|
+
$(() => {
|
|
944
|
+
const m = (h) => {
|
|
945
|
+
l.current && !l.current.contains(h.target) && (a(!1), n(""));
|
|
297
946
|
};
|
|
298
|
-
return document.addEventListener("mousedown",
|
|
299
|
-
document.removeEventListener("mousedown",
|
|
947
|
+
return document.addEventListener("mousedown", m), () => {
|
|
948
|
+
document.removeEventListener("mousedown", m);
|
|
300
949
|
};
|
|
301
950
|
}, []);
|
|
302
|
-
const
|
|
303
|
-
(
|
|
304
|
-
if (
|
|
305
|
-
const
|
|
306
|
-
let
|
|
307
|
-
|
|
951
|
+
const d = D(
|
|
952
|
+
(m) => {
|
|
953
|
+
if (r) {
|
|
954
|
+
const h = Array.isArray(e) ? e : e ? [e] : [], E = h.some((y) => y.value === m.value);
|
|
955
|
+
let R;
|
|
956
|
+
E ? R = h.filter((y) => y.value !== m.value) : R = [...h, m], t?.(R);
|
|
308
957
|
} else
|
|
309
|
-
t?.(
|
|
958
|
+
t?.(m), a(!1), n("");
|
|
310
959
|
},
|
|
311
|
-
[
|
|
312
|
-
),
|
|
313
|
-
(
|
|
314
|
-
if (!
|
|
315
|
-
const
|
|
316
|
-
t?.(
|
|
960
|
+
[r, e, t]
|
|
961
|
+
), p = D(
|
|
962
|
+
(m) => {
|
|
963
|
+
if (!r) return;
|
|
964
|
+
const E = (Array.isArray(e) ? e : e ? [e] : []).filter((R) => R.value !== m.value);
|
|
965
|
+
t?.(E);
|
|
317
966
|
},
|
|
318
|
-
[
|
|
319
|
-
),
|
|
320
|
-
t?.(
|
|
321
|
-
}, [
|
|
322
|
-
|
|
967
|
+
[r, e, t]
|
|
968
|
+
), g = D(() => {
|
|
969
|
+
t?.(r ? [] : null), n(""), a(!1);
|
|
970
|
+
}, [r, t]), x = D(() => {
|
|
971
|
+
a((m) => (m && n(""), !m));
|
|
323
972
|
}, []);
|
|
324
973
|
return {
|
|
325
|
-
isOpen:
|
|
326
|
-
setIsOpen:
|
|
327
|
-
query:
|
|
328
|
-
setQuery:
|
|
329
|
-
containerRef:
|
|
330
|
-
handleSelect:
|
|
331
|
-
handleRemove:
|
|
332
|
-
handleClear:
|
|
333
|
-
toggleOpen:
|
|
974
|
+
isOpen: s,
|
|
975
|
+
setIsOpen: a,
|
|
976
|
+
query: o,
|
|
977
|
+
setQuery: n,
|
|
978
|
+
containerRef: l,
|
|
979
|
+
handleSelect: d,
|
|
980
|
+
handleRemove: p,
|
|
981
|
+
handleClear: g,
|
|
982
|
+
toggleOpen: x
|
|
334
983
|
};
|
|
335
984
|
}
|
|
336
|
-
function
|
|
337
|
-
title:
|
|
985
|
+
function De({
|
|
986
|
+
title: e,
|
|
338
987
|
titleId: t,
|
|
339
|
-
...
|
|
340
|
-
},
|
|
341
|
-
return /* @__PURE__ */
|
|
988
|
+
...r
|
|
989
|
+
}, s) {
|
|
990
|
+
return /* @__PURE__ */ P.createElement("svg", Object.assign({
|
|
342
991
|
xmlns: "http://www.w3.org/2000/svg",
|
|
343
992
|
viewBox: "0 0 20 20",
|
|
344
993
|
fill: "currentColor",
|
|
345
994
|
"aria-hidden": "true",
|
|
346
995
|
"data-slot": "icon",
|
|
347
|
-
ref:
|
|
996
|
+
ref: s,
|
|
348
997
|
"aria-labelledby": t
|
|
349
|
-
},
|
|
998
|
+
}, r), e ? /* @__PURE__ */ P.createElement("title", {
|
|
350
999
|
id: t
|
|
351
|
-
},
|
|
1000
|
+
}, e) : null, /* @__PURE__ */ P.createElement("path", {
|
|
352
1001
|
fillRule: "evenodd",
|
|
353
1002
|
d: "M16.704 4.153a.75.75 0 0 1 .143 1.052l-8 10.5a.75.75 0 0 1-1.127.075l-4.5-4.5a.75.75 0 0 1 1.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 0 1 1.05-.143Z",
|
|
354
1003
|
clipRule: "evenodd"
|
|
355
1004
|
}));
|
|
356
1005
|
}
|
|
357
|
-
const
|
|
358
|
-
function
|
|
359
|
-
title:
|
|
1006
|
+
const ge = /* @__PURE__ */ P.forwardRef(De);
|
|
1007
|
+
function Oe({
|
|
1008
|
+
title: e,
|
|
360
1009
|
titleId: t,
|
|
361
|
-
...
|
|
362
|
-
},
|
|
363
|
-
return /* @__PURE__ */
|
|
1010
|
+
...r
|
|
1011
|
+
}, s) {
|
|
1012
|
+
return /* @__PURE__ */ P.createElement("svg", Object.assign({
|
|
364
1013
|
xmlns: "http://www.w3.org/2000/svg",
|
|
365
1014
|
viewBox: "0 0 20 20",
|
|
366
1015
|
fill: "currentColor",
|
|
367
1016
|
"aria-hidden": "true",
|
|
368
1017
|
"data-slot": "icon",
|
|
369
|
-
ref:
|
|
1018
|
+
ref: s,
|
|
370
1019
|
"aria-labelledby": t
|
|
371
|
-
},
|
|
1020
|
+
}, r), e ? /* @__PURE__ */ P.createElement("title", {
|
|
372
1021
|
id: t
|
|
373
|
-
},
|
|
1022
|
+
}, e) : null, /* @__PURE__ */ P.createElement("path", {
|
|
374
1023
|
fillRule: "evenodd",
|
|
375
1024
|
d: "M5.22 8.22a.75.75 0 0 1 1.06 0L10 11.94l3.72-3.72a.75.75 0 1 1 1.06 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L5.22 9.28a.75.75 0 0 1 0-1.06Z",
|
|
376
1025
|
clipRule: "evenodd"
|
|
377
1026
|
}));
|
|
378
1027
|
}
|
|
379
|
-
const
|
|
380
|
-
function
|
|
381
|
-
title:
|
|
1028
|
+
const Pe = /* @__PURE__ */ P.forwardRef(Oe);
|
|
1029
|
+
function Ce({
|
|
1030
|
+
title: e,
|
|
382
1031
|
titleId: t,
|
|
383
|
-
...
|
|
384
|
-
},
|
|
385
|
-
return /* @__PURE__ */
|
|
1032
|
+
...r
|
|
1033
|
+
}, s) {
|
|
1034
|
+
return /* @__PURE__ */ P.createElement("svg", Object.assign({
|
|
386
1035
|
xmlns: "http://www.w3.org/2000/svg",
|
|
387
1036
|
viewBox: "0 0 20 20",
|
|
388
1037
|
fill: "currentColor",
|
|
389
1038
|
"aria-hidden": "true",
|
|
390
1039
|
"data-slot": "icon",
|
|
391
|
-
ref:
|
|
1040
|
+
ref: s,
|
|
392
1041
|
"aria-labelledby": t
|
|
393
|
-
},
|
|
1042
|
+
}, r), e ? /* @__PURE__ */ P.createElement("title", {
|
|
394
1043
|
id: t
|
|
395
|
-
},
|
|
1044
|
+
}, e) : null, /* @__PURE__ */ P.createElement("path", {
|
|
396
1045
|
d: "M6.28 5.22a.75.75 0 0 0-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 1 0 1.06 1.06L10 11.06l3.72 3.72a.75.75 0 1 0 1.06-1.06L11.06 10l3.72-3.72a.75.75 0 0 0-1.06-1.06L10 8.94 6.28 5.22Z"
|
|
397
1046
|
}));
|
|
398
1047
|
}
|
|
399
|
-
const
|
|
1048
|
+
const me = /* @__PURE__ */ P.forwardRef(Ce), Ae = ({ option: e, isSelected: t, isFocused: r, onClick: s, multiple: a, style: o }) => /* @__PURE__ */ k.jsxs(
|
|
400
1049
|
"div",
|
|
401
1050
|
{
|
|
402
1051
|
role: "option",
|
|
403
1052
|
"aria-selected": t,
|
|
404
1053
|
tabIndex: 0,
|
|
405
|
-
onKeyDown: (
|
|
406
|
-
(
|
|
1054
|
+
onKeyDown: (n) => {
|
|
1055
|
+
(n.key === "Enter" || n.key === " ") && s(e);
|
|
407
1056
|
},
|
|
408
|
-
style:
|
|
409
|
-
onClick: () =>
|
|
410
|
-
className: `sb-option ${
|
|
411
|
-
${t && !
|
|
1057
|
+
style: o,
|
|
1058
|
+
onClick: () => s(e),
|
|
1059
|
+
className: `sb-option ${r ? "sb-option--focused" : ""}
|
|
1060
|
+
${t && !a ? "sb-option--selected" : "sb-option--not-selected"}
|
|
412
1061
|
`,
|
|
413
1062
|
children: [
|
|
414
|
-
|
|
1063
|
+
a && /* @__PURE__ */ k.jsx(
|
|
415
1064
|
"div",
|
|
416
1065
|
{
|
|
417
1066
|
className: `sb-checkbox ${t ? "sb-checkbox--checked" : "sb-checkbox--unchecked"}
|
|
418
1067
|
`,
|
|
419
|
-
children: t && /* @__PURE__ */
|
|
1068
|
+
children: t && /* @__PURE__ */ k.jsx(ge, { className: "sb-check-icon-white" })
|
|
420
1069
|
}
|
|
421
1070
|
),
|
|
422
|
-
/* @__PURE__ */
|
|
423
|
-
!
|
|
1071
|
+
/* @__PURE__ */ k.jsx("span", { className: "sb-option-label", children: e.label }),
|
|
1072
|
+
!a && t && /* @__PURE__ */ k.jsx(ge, { className: "sb-check-icon-blue" })
|
|
424
1073
|
]
|
|
425
1074
|
}
|
|
426
|
-
),
|
|
427
|
-
const [
|
|
428
|
-
|
|
429
|
-
},
|
|
430
|
-
if (!(
|
|
431
|
-
const
|
|
432
|
-
|
|
433
|
-
}, []),
|
|
434
|
-
|
|
1075
|
+
), $e = ({ options: e, value: t, multiple: r, onSelect: s, className: a }) => {
|
|
1076
|
+
const [o, n] = A(300), l = N(null), d = N(!1), p = (h) => {
|
|
1077
|
+
d.current = !0, h.currentTarget.setPointerCapture(h.pointerId), h.preventDefault();
|
|
1078
|
+
}, g = D((h) => {
|
|
1079
|
+
if (!(d.current && l.current)) return;
|
|
1080
|
+
const E = l.current.getBoundingClientRect(), R = h.clientY - E.top;
|
|
1081
|
+
n(Math.max(100, Math.min(R, 600)));
|
|
1082
|
+
}, []), x = D(() => {
|
|
1083
|
+
d.current = !1;
|
|
435
1084
|
}, []);
|
|
436
|
-
|
|
437
|
-
document.removeEventListener("pointermove",
|
|
438
|
-
}), [
|
|
439
|
-
const
|
|
440
|
-
return /* @__PURE__ */
|
|
441
|
-
|
|
442
|
-
|
|
1085
|
+
$(() => (document.addEventListener("pointermove", g), document.addEventListener("pointerup", x), () => {
|
|
1086
|
+
document.removeEventListener("pointermove", g), document.removeEventListener("pointerup", x);
|
|
1087
|
+
}), [g, x]);
|
|
1088
|
+
const m = (h) => r ? (Array.isArray(t) ? t : t ? [t] : []).some((R) => R.value === h.value) : t?.value === h.value;
|
|
1089
|
+
return /* @__PURE__ */ k.jsxs("div", { ref: l, className: `sb-dropdown ${a || ""}`, style: { height: o }, children: [
|
|
1090
|
+
e.length > 0 ? /* @__PURE__ */ k.jsx(
|
|
1091
|
+
ke,
|
|
443
1092
|
{
|
|
444
|
-
itemCount:
|
|
445
|
-
getItem: (
|
|
1093
|
+
itemCount: e.length,
|
|
1094
|
+
getItem: (h) => e[h],
|
|
446
1095
|
getItemHeight: () => 36,
|
|
447
|
-
viewportSize:
|
|
1096
|
+
viewportSize: o,
|
|
448
1097
|
className: "h-full w-full",
|
|
449
1098
|
scrollBarOptions: {
|
|
450
1099
|
width: 10,
|
|
@@ -452,112 +1101,112 @@ const Z = /* @__PURE__ */ x.forwardRef(ge), we = ({ option: r, isSelected: t, is
|
|
|
452
1101
|
enableTrackClick: !0,
|
|
453
1102
|
tapScrollCircleOptions: {
|
|
454
1103
|
enabled: !0,
|
|
455
|
-
renderVisual:
|
|
1104
|
+
renderVisual: xe
|
|
456
1105
|
}
|
|
457
1106
|
},
|
|
458
1107
|
behaviorOptions: {
|
|
459
1108
|
enableKeyboardNavigation: !0
|
|
460
1109
|
},
|
|
461
|
-
children: (
|
|
1110
|
+
children: (h, E) => h ? /* @__PURE__ */ k.jsx(Ae, { option: h, isSelected: m(h), onClick: s, multiple: r, style: { height: 36 } }, h.value) : null
|
|
462
1111
|
}
|
|
463
|
-
) : /* @__PURE__ */
|
|
464
|
-
/* @__PURE__ */
|
|
465
|
-
/* @__PURE__ */
|
|
466
|
-
/* @__PURE__ */
|
|
1112
|
+
) : /* @__PURE__ */ k.jsx("div", { className: "sb-no-options", children: "No options found" }),
|
|
1113
|
+
/* @__PURE__ */ k.jsx("div", { onPointerDown: p, className: "sb-resize-handle", children: /* @__PURE__ */ k.jsxs("svg", { viewBox: "0 0 10 10", className: "sb-resize-icon", children: [
|
|
1114
|
+
/* @__PURE__ */ k.jsx("title", { children: "Resize handle" }),
|
|
1115
|
+
/* @__PURE__ */ k.jsx("path", { d: "M10 10L10 0L0 10Z" })
|
|
467
1116
|
] }) })
|
|
468
1117
|
] });
|
|
469
|
-
},
|
|
470
|
-
const
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
}, [
|
|
474
|
-
const
|
|
475
|
-
|
|
1118
|
+
}, ze = ({ value: e, multiple: t, query: r, onQueryChange: s, onRemove: a, onFocus: o, placeholder: n = "Select...", disabled: l, isLoading: d, clearable: p, onClear: g, onToggle: x, autoFocus: m }) => {
|
|
1119
|
+
const h = N(null);
|
|
1120
|
+
$(() => {
|
|
1121
|
+
m && h.current?.focus();
|
|
1122
|
+
}, [m]);
|
|
1123
|
+
const E = Array.isArray(e) ? e : e ? [e] : [], R = (y) => {
|
|
1124
|
+
y.key === "Backspace" && !r && E.length > 0 && t && a(E[E.length - 1]);
|
|
476
1125
|
};
|
|
477
|
-
return /* @__PURE__ */
|
|
1126
|
+
return /* @__PURE__ */ k.jsxs(
|
|
478
1127
|
"fieldset",
|
|
479
1128
|
{
|
|
480
|
-
className: `sb-input-area ${
|
|
1129
|
+
className: `sb-input-area ${l ? "sb-input-area--disabled" : "sb-input-area--active"}
|
|
481
1130
|
`,
|
|
482
|
-
onMouseDown: (
|
|
483
|
-
const
|
|
484
|
-
|
|
1131
|
+
onMouseDown: (y) => {
|
|
1132
|
+
const v = y.target;
|
|
1133
|
+
v !== h.current && !v.closest("button") && (y.preventDefault(), h.current?.focus());
|
|
485
1134
|
},
|
|
486
1135
|
children: [
|
|
487
|
-
t &&
|
|
488
|
-
|
|
489
|
-
/* @__PURE__ */
|
|
1136
|
+
t && E.map((y) => /* @__PURE__ */ k.jsxs("span", { className: "sb-tag", children: [
|
|
1137
|
+
y.label,
|
|
1138
|
+
/* @__PURE__ */ k.jsx(
|
|
490
1139
|
"button",
|
|
491
1140
|
{
|
|
492
1141
|
type: "button",
|
|
493
|
-
onClick: (
|
|
494
|
-
|
|
1142
|
+
onClick: (v) => {
|
|
1143
|
+
v.stopPropagation(), a(y);
|
|
495
1144
|
},
|
|
496
1145
|
className: "sb-tag-remove",
|
|
497
|
-
children: /* @__PURE__ */
|
|
1146
|
+
children: /* @__PURE__ */ k.jsx(me, { className: "h-3 w-3" })
|
|
498
1147
|
}
|
|
499
1148
|
)
|
|
500
|
-
] },
|
|
501
|
-
!t &&
|
|
502
|
-
/* @__PURE__ */
|
|
503
|
-
/* @__PURE__ */
|
|
504
|
-
|
|
1149
|
+
] }, y.value)),
|
|
1150
|
+
!t && E.length > 0 && !r && /* @__PURE__ */ k.jsx("span", { className: "sb-single-value", children: E[0].label }),
|
|
1151
|
+
/* @__PURE__ */ k.jsx("input", { ref: h, type: "text", value: r, onChange: (y) => s(y.target.value), onFocus: o, onKeyDown: R, placeholder: E.length === 0 ? n : "", disabled: l, className: "sb-input" }),
|
|
1152
|
+
/* @__PURE__ */ k.jsxs("div", { className: "sb-indicators", children: [
|
|
1153
|
+
p && E.length > 0 && !l && /* @__PURE__ */ k.jsx(
|
|
505
1154
|
"button",
|
|
506
1155
|
{
|
|
507
1156
|
type: "button",
|
|
508
|
-
onClick: (
|
|
509
|
-
|
|
1157
|
+
onClick: (y) => {
|
|
1158
|
+
y.stopPropagation(), g();
|
|
510
1159
|
},
|
|
511
1160
|
className: "sb-clear-button",
|
|
512
|
-
children: /* @__PURE__ */
|
|
1161
|
+
children: /* @__PURE__ */ k.jsx(me, { className: "h-4 w-4" })
|
|
513
1162
|
}
|
|
514
1163
|
),
|
|
515
|
-
|
|
516
|
-
/* @__PURE__ */
|
|
517
|
-
/* @__PURE__ */
|
|
518
|
-
/* @__PURE__ */
|
|
519
|
-
] }) : /* @__PURE__ */
|
|
1164
|
+
d ? /* @__PURE__ */ k.jsxs("svg", { className: "sb-loading-icon", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
|
|
1165
|
+
/* @__PURE__ */ k.jsx("title", { children: "Loading" }),
|
|
1166
|
+
/* @__PURE__ */ k.jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
|
|
1167
|
+
/* @__PURE__ */ k.jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })
|
|
1168
|
+
] }) : /* @__PURE__ */ k.jsx(
|
|
520
1169
|
"button",
|
|
521
1170
|
{
|
|
522
1171
|
type: "button",
|
|
523
|
-
disabled:
|
|
524
|
-
onClick: (
|
|
525
|
-
|
|
1172
|
+
disabled: l,
|
|
1173
|
+
onClick: (y) => {
|
|
1174
|
+
y.stopPropagation(), x();
|
|
526
1175
|
},
|
|
527
1176
|
className: "sb-chevron-button",
|
|
528
|
-
children: /* @__PURE__ */
|
|
1177
|
+
children: /* @__PURE__ */ k.jsx(Pe, { className: "sb-chevron-icon" })
|
|
529
1178
|
}
|
|
530
1179
|
)
|
|
531
1180
|
] })
|
|
532
1181
|
]
|
|
533
1182
|
}
|
|
534
1183
|
);
|
|
535
|
-
},
|
|
536
|
-
const { isOpen: t, setIsOpen:
|
|
537
|
-
return /* @__PURE__ */
|
|
538
|
-
/* @__PURE__ */
|
|
539
|
-
|
|
1184
|
+
}, Be = (e) => {
|
|
1185
|
+
const { isOpen: t, setIsOpen: r, query: s, setQuery: a, containerRef: o, handleSelect: n, handleRemove: l, handleClear: d, toggleOpen: p } = Re(e), { filteredOptions: g, isSearching: x } = Te(e.options, s, e.workerUrls);
|
|
1186
|
+
return /* @__PURE__ */ k.jsxs("div", { ref: o, className: `sb-container ${e.className || ""}`, children: [
|
|
1187
|
+
/* @__PURE__ */ k.jsx(
|
|
1188
|
+
ze,
|
|
540
1189
|
{
|
|
541
|
-
value:
|
|
542
|
-
multiple:
|
|
543
|
-
query:
|
|
544
|
-
onQueryChange: (
|
|
545
|
-
|
|
1190
|
+
value: e.value,
|
|
1191
|
+
multiple: e.multiple,
|
|
1192
|
+
query: s,
|
|
1193
|
+
onQueryChange: (m) => {
|
|
1194
|
+
a(m), t || r(!0);
|
|
546
1195
|
},
|
|
547
|
-
onRemove:
|
|
548
|
-
onClear:
|
|
549
|
-
onFocus: () =>
|
|
550
|
-
placeholder:
|
|
551
|
-
disabled:
|
|
552
|
-
isLoading:
|
|
553
|
-
clearable:
|
|
554
|
-
onToggle:
|
|
555
|
-
autoFocus:
|
|
1196
|
+
onRemove: l,
|
|
1197
|
+
onClear: d,
|
|
1198
|
+
onFocus: () => r(!0),
|
|
1199
|
+
placeholder: e.placeholder,
|
|
1200
|
+
disabled: e.disabled,
|
|
1201
|
+
isLoading: x,
|
|
1202
|
+
clearable: e.clearable,
|
|
1203
|
+
onToggle: p,
|
|
1204
|
+
autoFocus: e.autoFocus
|
|
556
1205
|
}
|
|
557
1206
|
),
|
|
558
|
-
t && !
|
|
1207
|
+
t && !e.disabled && /* @__PURE__ */ k.jsx($e, { options: g, value: e.value, multiple: e.multiple, onSelect: n })
|
|
559
1208
|
] });
|
|
560
1209
|
};
|
|
561
1210
|
export {
|
|
562
|
-
|
|
1211
|
+
Be as SelectBox
|
|
563
1212
|
};
|