Skip to content

Commit

Permalink
Final fix for search
Browse files Browse the repository at this point in the history
  • Loading branch information
ElijahFowler committed Oct 9, 2024
1 parent 217ae1d commit e553977
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 61 deletions.
120 changes: 60 additions & 60 deletions dist/MultiSelect.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function tt(e) {
for (var n = 0; n < e.length; n++)
e[n]();
}
const q = 2, pn = 4, ue = 8, mn = 16, K = 32, Se = 64, G = 128, de = 256, P = 512, Y = 1024, ie = 2048, L = 4096, fe = 8192, rt = 16384, He = 32768, lt = 65536, ut = 1 << 18, wn = 1 << 19, xe = Symbol("$state");
const q = 2, pn = 4, ue = 8, wn = 16, K = 32, Se = 64, G = 128, de = 256, P = 512, Y = 1024, ie = 2048, L = 4096, fe = 8192, rt = 16384, He = 32768, lt = 65536, ut = 1 << 18, mn = 1 << 19, xe = Symbol("$state");
function En(e) {
return e === this.v;
}
Expand Down Expand Up @@ -69,14 +69,14 @@ function pt(e) {
function C(e, n) {
return b !== null && ge() && b.f & q && // If the source was created locally within the current derived, then
// we allow the mutation.
(M === null || !M.includes(e)) && ht(), e.equals(n) || (e.v = n, e.version = Dn(), yn(e, Y), ge() && w !== null && w.f & P && !(w.f & K) && (I !== null && I.includes(e) ? (F(w, Y), Te(w)) : U === null ? Ct([e]) : U.push(e))), n;
(M === null || !M.includes(e)) && ht(), e.equals(n) || (e.v = n, e.version = Dn(), yn(e, Y), ge() && m !== null && m.f & P && !(m.f & K) && (I !== null && I.includes(e) ? (F(m, Y), Te(m)) : U === null ? Ct([e]) : U.push(e))), n;
}
function yn(e, n) {
var t = e.reactions;
if (t !== null)
for (var r = ge(), l = t.length, u = 0; u < l; u++) {
var i = t[u], _ = i.f;
_ & Y || !r && i === w || (F(i, n), _ & (P | G) && (_ & q ? yn(
_ & Y || !r && i === m || (F(i, n), _ & (P | G) && (_ & q ? yn(
/** @type {Derived} */
i,
ie
Expand All @@ -86,15 +86,15 @@ function yn(e, n) {
)));
}
}
function mt(e) {
w === null && b === null && ot(), b !== null && b.f & G && at(), Ke && ft();
function wt(e) {
m === null && b === null && ot(), b !== null && b.f & G && at(), Ke && ft();
}
function wt(e, n) {
function mt(e, n) {
var t = n.last;
t === null ? n.last = n.first = e : (t.next = e, e.prev = t, n.last = e);
}
function ae(e, n, t, r = !0) {
var l = (e & Se) !== 0, u = w, i = {
var l = (e & Se) !== 0, u = m, i = {
ctx: x,
deps: null,
nodes_start: null,
Expand All @@ -120,8 +120,8 @@ function ae(e, n, t, r = !0) {
Qe(_);
}
} else n !== null && Te(i);
var s = t && i.deps === null && i.first === null && i.nodes_start === null && i.teardown === null && (i.f & wn) === 0;
if (!s && !l && r && (u !== null && wt(i, u), b !== null && b.f & q)) {
var s = t && i.deps === null && i.first === null && i.nodes_start === null && i.teardown === null && (i.f & mn) === 0;
if (!s && !l && r && (u !== null && mt(i, u), b !== null && b.f & q)) {
var f = (
/** @type {Derived} */
b
Expand All @@ -131,8 +131,8 @@ function ae(e, n, t, r = !0) {
return i;
}
function Et(e) {
mt();
var n = w !== null && (w.f & ue) !== 0 && // TODO do we actually need this? removing them changes nothing
wt();
var n = m !== null && (m.f & ue) !== 0 && // TODO do we actually need this? removing them changes nothing
x !== null && !x.m;
if (n) {
var t = (
Expand All @@ -141,7 +141,7 @@ function Et(e) {
);
(t.e ?? (t.e = [])).push({
fn: e,
effect: w,
effect: m,
reaction: b
});
} else {
Expand All @@ -165,7 +165,7 @@ function J(e) {
return Sn(e);
}
function kn(e, n = 0) {
return ae(ue | mn | n, e, !0);
return ae(ue | wn | n, e, !0);
}
function re(e, n = !0) {
return ae(ue | K, e, !0, n);
Expand All @@ -174,11 +174,11 @@ function Tn(e) {
var n = e.teardown;
if (n !== null) {
const t = Ke, r = b;
$e(!0), we(null);
$e(!0), me(null);
try {
n.call(null);
} finally {
$e(t), we(r);
$e(t), me(r);
}
}
}
Expand Down Expand Up @@ -260,7 +260,7 @@ function bt(e) {
// @__NO_SIDE_EFFECTS__
function pe(e) {
let n = q | Y;
w === null ? n |= G : w.f |= wn;
m === null ? n |= G : m.f |= mn;
const t = {
children: null,
deps: null,
Expand All @@ -273,7 +273,7 @@ function pe(e) {
null
),
version: 0,
parent: w
parent: m
};
if (b !== null && b.f & q) {
var r = (
Expand Down Expand Up @@ -306,7 +306,7 @@ function In(e) {
}
}
function Nn(e) {
var n, t = w;
var n, t = m;
Ee(e.parent);
try {
In(e), n = Pn(e);
Expand All @@ -320,7 +320,7 @@ function kt(e) {
In(e), le(e, 0), F(e, fe), e.children = e.deps = e.reactions = // @ts-expect-error `signal.fn` cannot be `null` while the signal is alive
e.fn = null;
}
let me = !1, $ = !1, Ke = !1;
let we = !1, $ = !1, Ke = !1;
function Qe(e) {
$ = e;
}
Expand All @@ -329,12 +329,12 @@ function $e(e) {
}
let Le = [], te = 0;
let b = null;
function we(e) {
function me(e) {
b = e;
}
let w = null;
let m = null;
function Ee(e) {
w = e;
m = e;
}
let M = null;
function Tt(e) {
Expand Down Expand Up @@ -373,7 +373,7 @@ function oe(e) {
) && Nn(
/** @type {Derived} */
u
), r && w !== null && !X && !((_ = u == null ? void 0 : u.reactions) != null && _.includes(e)) && (u.reactions ?? (u.reactions = [])).push(e), u.version > e.version)
), r && m !== null && !X && !((_ = u == null ? void 0 : u.reactions) != null && _.includes(e)) && (u.reactions ?? (u.reactions = [])).push(e), u.version > e.version)
return !0;
}
}
Expand Down Expand Up @@ -445,10 +445,10 @@ function ke(e) {
var n = e.f;
if (!(n & fe)) {
F(e, P);
var t = w, r = x;
w = e, x = e.ctx;
var t = m, r = x;
m = e, x = e.ctx;
try {
n & mn || Rn(e), Tn(e);
n & wn || Rn(e), Tn(e);
var l = Pn(e);
e.teardown = typeof l == "function" ? l : null, e.version = On;
} catch (u) {
Expand All @@ -457,7 +457,7 @@ function ke(e) {
u
);
} finally {
w = t, x = r;
m = t, x = r;
}
}
}
Expand Down Expand Up @@ -491,13 +491,13 @@ function Ot(e) {
}
}
function Dt() {
if (me = !1, te > 1001)
if (we = !1, te > 1001)
return;
const e = Le;
Le = [], Nt(e), me || (te = 0);
Le = [], Nt(e), we || (te = 0);
}
function Te(e) {
me || (me = !0, queueMicrotask(Dt));
we || (we = !0, queueMicrotask(Dt));
for (var n = e; n.parent !== null; ) {
n = n.parent;
var t = n.f;
Expand Down Expand Up @@ -547,7 +547,7 @@ function g(e) {
if (b !== null) {
M !== null && M.includes(e) && dt();
var t = b.deps;
I === null && t !== null && t[O] === e ? O++ : I === null ? I = [e] : I.push(e), U !== null && w !== null && w.f & P && !(w.f & K) && U.includes(e) && (F(w, Y), Te(w));
I === null && t !== null && t[O] === e ? O++ : I === null ? I = [e] : I.push(e), U !== null && m !== null && m.f & P && !(m.f & K) && U.includes(e) && (F(m, Y), Te(m));
}
if (n & q) {
var r = (
Expand Down Expand Up @@ -591,15 +591,15 @@ function qn(e) {
if (n !== null) {
const i = n.e;
if (i !== null) {
var t = w, r = b;
var t = m, r = b;
n.e = null;
try {
for (var l = 0; l < i.length; l++) {
var u = i[l];
Ee(u.effect), we(u.reaction), bn(u.fn);
Ee(u.effect), me(u.reaction), bn(u.fn);
}
} finally {
Ee(t), we(r);
Ee(t), me(r);
}
}
x = n.p, n.m = !0;
Expand Down Expand Up @@ -667,7 +667,7 @@ function H(e, n = null, t) {
if (f === xe)
return !0;
var a = l.get(f), o = a !== void 0 && a.v !== N || Reflect.has(s, f);
if (a !== void 0 || w !== null && (!o || (c = Q(s, f)) != null && c.writable)) {
if (a !== void 0 || m !== null && (!o || (c = Q(s, f)) != null && c.writable)) {
a === void 0 && (a = D(o ? H(s[f], _) : N), l.set(f, a));
var v = g(a);
if (v === N)
Expand Down Expand Up @@ -837,7 +837,7 @@ function Ft(e) {
function Fe(e, n) {
var t = (
/** @type {Effect} */
w
m
);
t.nodes_start === null && (t.nodes_start = e, t.nodes_end = n);
}
Expand Down Expand Up @@ -1046,12 +1046,12 @@ function an(e, n, t, r, l, u = null) {
}
function Yt(e, n, t, r, l, u) {
var Ge, Je, Ze, ze;
var i = (l & Yn) !== 0, _ = (l & (Ve | je)) !== 0, s = e.length, f = n.items, a = n.first, o = a, v, c = null, h, E = [], S = [], k, p, d, m;
var i = (l & Yn) !== 0, _ = (l & (Ve | je)) !== 0, s = e.length, f = n.items, a = n.first, o = a, v, c = null, h, E = [], S = [], k, p, d, w;
if (i)
for (m = 0; m < s; m += 1)
k = e[m], p = u(k, m), d = f.get(p), d !== void 0 && ((Ge = d.a) == null || Ge.measure(), (h ?? (h = /* @__PURE__ */ new Set())).add(d));
for (m = 0; m < s; m += 1) {
if (k = e[m], p = u(k, m), d = f.get(p), d === void 0) {
for (w = 0; w < s; w += 1)
k = e[w], p = u(k, w), d = f.get(p), d !== void 0 && ((Ge = d.a) == null || Ge.measure(), (h ?? (h = /* @__PURE__ */ new Set())).add(d));
for (w = 0; w < s; w += 1) {
if (k = e[w], p = u(k, w), d = f.get(p), d === void 0) {
var y = o ? (
/** @type {TemplateNode} */
o.e.nodes_start
Expand All @@ -1063,13 +1063,13 @@ function Yt(e, n, t, r, l, u) {
c === null ? n.first : c.next,
k,
p,
m,
w,
r,
l
), f.set(p, c), E = [], S = [], o = c.next;
continue;
}
if (_ && Kt(d, k, m, l), d.e.f & L && (he(d.e), i && ((Je = d.a) == null || Je.unfix(), (h ?? (h = /* @__PURE__ */ new Set())).delete(d))), d !== o) {
if (_ && Kt(d, k, w, l), d.e.f & L && (he(d.e), i && ((Je = d.a) == null || Je.unfix(), (h ?? (h = /* @__PURE__ */ new Set())).delete(d))), d !== o) {
if (v !== void 0 && v.has(d)) {
if (E.length < S.length) {
var A = S[0], T;
Expand All @@ -1079,7 +1079,7 @@ function Yt(e, n, t, r, l, u) {
on(E[T], A, t);
for (T = 0; T < S.length; T += 1)
v.delete(S[T]);
B(n, R.prev, V.next), B(n, c, R), B(n, V, A), o = A, c = V, m -= 1, E = [], S = [];
B(n, R.prev, V.next), B(n, c, R), B(n, V, A), o = A, c = V, w -= 1, E = [], S = [];
} else
v.delete(d), on(d, o, t), B(n, d.prev, d.next), B(n, d, c === null ? n.first : c.next), B(n, c, d), c = d;
continue;
Expand All @@ -1099,10 +1099,10 @@ function Yt(e, n, t, r, l, u) {
if (ne > 0) {
var Hn = l & vn && s === 0 ? t : null;
if (i) {
for (m = 0; m < ne; m += 1)
(Ze = j[m].a) == null || Ze.measure();
for (m = 0; m < ne; m += 1)
(ze = j[m].a) == null || ze.fix();
for (w = 0; w < ne; w += 1)
(Ze = j[w].a) == null || Ze.measure();
for (w = 0; w < ne; w += 1)
(ze = j[w].a) == null || ze.fix();
}
Ut(n, j, Hn, f);
}
Expand All @@ -1112,7 +1112,7 @@ function Yt(e, n, t, r, l, u) {
if (h !== void 0)
for (d of h)
(Xe = d.a) == null || Xe.apply();
}), w.first = n.first && n.first.e, w.last = c && c.e;
}), m.first = n.first && n.first.e, m.last = c && c.e;
}
function Kt(e, n, t, r) {
r & Ve && C(e.v, n), r & je ? C(
Expand Down Expand Up @@ -1212,11 +1212,11 @@ function cn(e) {
return e === "" ? null : +e;
}
function ce(e, n, t, r) {
var m;
var w;
var l = (t & Wn) !== 0, u = (t & Gn) !== 0, i = (t & Zn) !== 0, _ = (t & zn) !== 0, s = (
/** @type {V} */
e[n]
), f = (m = Q(e, n)) == null ? void 0 : m.set, a = (
), f = (w = Q(e, n)) == null ? void 0 : w.set, a = (
/** @type {V} */
r
), o = !0, v = !1, c = () => (v = !0, o && (o = !1, _ ? a = Pt(
Expand Down Expand Up @@ -1275,10 +1275,10 @@ var Qt = (e, n) => n(), $t = () => {
}, er = (e, n, t) => n(e, g(t)), nr = /* @__PURE__ */ se('<span> <button class="multi-select__remove svelte-7bij7h">&times;</button></span>'), tr = /* @__PURE__ */ se('<span class="multi-select__placeholder svelte-7bij7h"> </span>'), rr = (e, n, t) => n(g(t)), lr = /* @__PURE__ */ se('<li><button class="svelte-7bij7h"> </button></li>'), ur = /* @__PURE__ */ se('<div class="multi-select__items svelte-7bij7h"><div class="multi-select__search-box svelte-7bij7h"><input type="search" placeholder="Search"></div> <ul class="svelte-7bij7h"></ul></div>'), ir = /* @__PURE__ */ se('<div tabindex="1" role="button"><!></div> <!>', 1);
function ar(e, n) {
Ln(n, !0);
let t = ce(n, "options", 19, () => []), r = ce(n, "inputCssClass", 3, "form-control"), l = ce(n, "selectedOptionCssClass", 3, "badge"), u = ce(n, "placeholder", 3, "Select an option"), i = Ae(H([])), _ = Ae(""), s = /* @__PURE__ */ pe(() => t().filter((p) => !g(i).some((d) => d == p)).filter((p) => g(_).trim() === "" || p.some((d) => d.toLowerCase() === g(_).toLowerCase()))), f = Ae(!1);
let t = ce(n, "options", 19, () => []), r = ce(n, "inputCssClass", 3, "form-control"), l = ce(n, "selectedOptionCssClass", 3, "badge"), u = ce(n, "placeholder", 3, "Select an option"), i = Ae(H([])), _ = Ae(""), s = /* @__PURE__ */ pe(() => t().filter((p) => !g(i).some((d) => d == p)).filter((p) => g(_).trim() === "" || p.toLowerCase().includes(g(_).toLowerCase()))), f = Ae(!1);
function a(p, d) {
var m;
p.preventDefault(), p.stopPropagation(), C(i, H(g(i).filter((y) => y !== d))), (m = n.oninput) == null || m.call(n, ln(g(i))), C(f, !1);
var w;
p.preventDefault(), p.stopPropagation(), C(i, H(g(i).filter((y) => y !== d))), (w = n.oninput) == null || w.call(n, ln(g(i))), C(f, !1);
}
function o(p) {
var d;
Expand All @@ -1302,24 +1302,24 @@ function ar(e, n) {
S,
() => g(i).length,
(p) => {
var d = Vt(), m = tn(d);
an(m, 17, () => g(i), fn, (y, A) => {
var d = Vt(), w = tn(d);
an(w, 17, () => g(i), fn, (y, A) => {
var T = nr();
J(() => De(T, `${(l() + " multi-select__selected").trim() ?? ""} svelte-7bij7h`));
var R = W(T), V = Ie(R);
V.__click = [er, a, A], J(() => Ne(R, `${g(A) ?? ""} `)), Z(y, T);
}), Z(p, d);
},
(p) => {
var d = tr(), m = W(d);
J(() => Ne(m, u())), Z(p, d);
var d = tr(), w = W(d);
J(() => Ne(w, u())), Z(p, d);
}
);
var k = Ie(E, 2);
un(k, () => g(f), (p) => {
var d = ur(), m = W(d), y = W(m);
var d = ur(), w = W(d), y = W(w);
J(() => De(y, `${(r() + " multi-select__search").trim() ?? ""} svelte-7bij7h`)), y.__keydown = [Xt];
var A = Ie(m, 2);
var A = Ie(w, 2);
an(A, 21, () => g(s), fn, (T, R) => {
var V = lr(), j = W(V);
j.__click = [rr, o, R];
Expand Down
2 changes: 1 addition & 1 deletion src/MultiSelect.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
let menuItems = $derived(
options
.filter((x) => !selectedItems.some((si) => si == x))
.filter((x) => search.trim() === '' || x.some(i => i.toLowerCase() === search.toLowerCase()))
.filter((x) => search.trim() === '' || x.toLowerCase().includes(search.toLowerCase()))
);
let showMenu = $state(false);
Expand Down

0 comments on commit e553977

Please sign in to comment.