@loop8/vue-select 0.1.3 → 0.1.4
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/loop8-select.es.js +262 -257
- package/dist/loop8-select.umd.js +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/styles/loop-select.css +5 -1
package/dist/loop8-select.es.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
const Ne = { class: "loop-select-selection" }, _e = { class: "loop-select-single-selection" },
|
|
1
|
+
import { defineComponent as Ee, ref as x, computed as F, nextTick as R, onMounted as Ue, onBeforeUnmount as $e, watch as Q, openBlock as y, createElementBlock as V, normalizeClass as Ae, withModifiers as T, createElementVNode as k, Fragment as le, renderSlot as oe, toDisplayString as K, renderList as de, withKeys as N, createCommentVNode as ne, unref as Be, isRef as Fe, createTextVNode as qe, toRaw as Ke } from "vue";
|
|
2
|
+
const Ne = { class: "loop-select-selection" }, _e = { class: "loop-select-single-selection" }, He = { class: "loop-select-selected-text" }, Ge = {
|
|
3
3
|
key: 1,
|
|
4
4
|
class: "loop-select-placeholder"
|
|
5
|
-
},
|
|
5
|
+
}, De = {
|
|
6
6
|
key: 0,
|
|
7
7
|
class: "loop-select-tags-container"
|
|
8
|
-
},
|
|
8
|
+
}, Me = ["onClick"], Je = {
|
|
9
9
|
key: 1,
|
|
10
10
|
class: "loop-select-placeholder"
|
|
11
|
-
},
|
|
11
|
+
}, Qe = { class: "loop-select-search-container" }, ze = ["onKeydown"], We = {
|
|
12
12
|
key: 0,
|
|
13
13
|
class: "loop-select-search-spinner"
|
|
14
|
-
},
|
|
14
|
+
}, Xe = ["tabindex", "onKeydown"], Ye = {
|
|
15
15
|
key: 0,
|
|
16
16
|
class: "loop-select-no-results"
|
|
17
|
-
},
|
|
17
|
+
}, Ze = ["onClick", "onMouseover"], el = {
|
|
18
18
|
key: 0,
|
|
19
19
|
class: "loop-select-loading-more"
|
|
20
|
-
},
|
|
20
|
+
}, ll = ["multiple", "name", "required", "disabled"], tl = {
|
|
21
21
|
key: 0,
|
|
22
22
|
value: "",
|
|
23
23
|
disabled: "",
|
|
24
24
|
selected: ""
|
|
25
|
-
},
|
|
25
|
+
}, al = ["value"], sl = ["value"], Oe = /* @__PURE__ */ Ee({
|
|
26
26
|
name: "Loop8Select",
|
|
27
27
|
__name: "Loop8Select",
|
|
28
28
|
props: {
|
|
@@ -72,39 +72,41 @@ const Ne = { class: "loop-select-selection" }, _e = { class: "loop-select-single
|
|
|
72
72
|
}
|
|
73
73
|
},
|
|
74
74
|
emits: ["update:modelValue", "invalid-option", "update:selectedOptions"],
|
|
75
|
-
setup(S, { emit:
|
|
76
|
-
const l = S, I =
|
|
75
|
+
setup(S, { emit: ke }) {
|
|
76
|
+
const l = S, I = ke, _ = x(!1), L = x(""), c = x(-1), ie = x(null), z = x(null), d = x(null), j = x(null), H = x(l.loading), p = x([]), E = x(null), ue = x({}), W = x(1), X = x(!1), U = x(!1), A = x({});
|
|
77
|
+
let Y = !1, G = null;
|
|
78
|
+
const $ = F(() => !!l.ajax), te = F(() => {
|
|
77
79
|
var e;
|
|
78
80
|
return $.value && !!((e = l.ajax) != null && e.pagination);
|
|
79
|
-
}),
|
|
81
|
+
}), re = F(() => {
|
|
80
82
|
var a;
|
|
81
83
|
if (!$.value)
|
|
82
84
|
return !0;
|
|
83
85
|
const e = ((a = l.ajax) == null ? void 0 : a.minimumInputLength) || 0;
|
|
84
86
|
return L.value.length >= e;
|
|
85
|
-
}),
|
|
86
|
-
const e = $.value ? [...l.options, ...p.value] : l.options, a = Object.values(
|
|
87
|
+
}), Z = F(() => {
|
|
88
|
+
const e = $.value ? [...l.options, ...p.value] : l.options, a = Object.values(A.value);
|
|
87
89
|
if (a.length > 0) {
|
|
88
90
|
const t = a.filter(
|
|
89
|
-
(o) => !e.some((s) =>
|
|
91
|
+
(o) => !e.some((s) => i(s) === i(o))
|
|
90
92
|
);
|
|
91
93
|
return [...e, ...t];
|
|
92
94
|
}
|
|
93
95
|
return e;
|
|
94
|
-
}), B =
|
|
96
|
+
}), B = F(() => {
|
|
95
97
|
if (l.multiple) {
|
|
96
98
|
if (!l.modelValue || !Array.isArray(l.modelValue))
|
|
97
99
|
return [];
|
|
98
100
|
const e = Array.isArray(l.modelValue) ? l.modelValue : [l.modelValue], a = [], t = e.map((o) => {
|
|
99
|
-
if (o != null &&
|
|
100
|
-
return
|
|
101
|
-
const s =
|
|
101
|
+
if (o != null && A.value[String(o)])
|
|
102
|
+
return A.value[String(o)];
|
|
103
|
+
const s = Z.value.find((u) => i(u) === o);
|
|
102
104
|
if (s)
|
|
103
|
-
return
|
|
104
|
-
const n = p.value.find((
|
|
105
|
-
return n ? (
|
|
105
|
+
return A.value[String(o)] = s, s;
|
|
106
|
+
const n = p.value.find((u) => i(u) === o);
|
|
107
|
+
return n ? (A.value[String(o)] = n, n) : (a.push(o), null);
|
|
106
108
|
}).filter((o) => o !== null);
|
|
107
|
-
return a.length > 0 && (I("invalid-option", a),
|
|
109
|
+
return a.length > 0 && (I("invalid-option", a), R(() => {
|
|
108
110
|
const o = e.filter((s) => !a.includes(s));
|
|
109
111
|
I("update:modelValue", o);
|
|
110
112
|
})), t;
|
|
@@ -112,269 +114,273 @@ const Ne = { class: "loop-select-selection" }, _e = { class: "loop-select-single
|
|
|
112
114
|
if (l.modelValue === null || l.modelValue === void 0)
|
|
113
115
|
return [];
|
|
114
116
|
const e = l.modelValue;
|
|
115
|
-
if (e != null &&
|
|
116
|
-
return [
|
|
117
|
-
const a =
|
|
118
|
-
(o) =>
|
|
117
|
+
if (e != null && A.value[String(e)])
|
|
118
|
+
return [A.value[String(e)]];
|
|
119
|
+
const a = Z.value.find(
|
|
120
|
+
(o) => i(o) === e
|
|
119
121
|
);
|
|
120
122
|
if (a)
|
|
121
|
-
return
|
|
122
|
-
const t = p.value.find((o) =>
|
|
123
|
-
return t ? (
|
|
123
|
+
return A.value[String(e)] = a, [a];
|
|
124
|
+
const t = p.value.find((o) => i(o) === e);
|
|
125
|
+
return t ? (A.value[String(e)] = t, [t]) : (I("invalid-option", e), R(() => {
|
|
124
126
|
I("update:modelValue", null);
|
|
125
127
|
}), []);
|
|
126
128
|
}
|
|
127
|
-
}),
|
|
128
|
-
|
|
129
|
+
}), D = F(() => B.value.length > 0 ? B.value[0] : null), ve = F(() => D.value ? i(D.value) : null);
|
|
130
|
+
F(() => {
|
|
129
131
|
const e = B.value[0];
|
|
130
|
-
return e ?
|
|
132
|
+
return e ? M(e) : "";
|
|
131
133
|
});
|
|
132
|
-
const P =
|
|
134
|
+
const P = F(() => {
|
|
133
135
|
if ($.value)
|
|
134
|
-
return
|
|
136
|
+
return re.value ? p.value : [];
|
|
135
137
|
if (!L.value)
|
|
136
138
|
return l.options;
|
|
137
139
|
const e = L.value.toLowerCase();
|
|
138
|
-
return l.options.filter((a) =>
|
|
139
|
-
}),
|
|
140
|
-
const a =
|
|
140
|
+
return l.options.filter((a) => M(a).toLowerCase().includes(e));
|
|
141
|
+
}), i = (e) => typeof e == "object" && e !== null ? e[l.valueKey] : e, M = (e) => typeof e == "object" && e !== null ? e[l.labelKey] || e[l.valueKey] || "" : String(e), pe = (e) => {
|
|
142
|
+
const a = i(e);
|
|
141
143
|
return l.multiple && Array.isArray(l.modelValue) ? l.modelValue.includes(a) : l.modelValue === a;
|
|
142
|
-
},
|
|
143
|
-
const a =
|
|
144
|
-
if (
|
|
144
|
+
}, me = (e) => {
|
|
145
|
+
const a = i(e);
|
|
146
|
+
if (A.value[String(a)] = e, l.multiple) {
|
|
145
147
|
let t = [];
|
|
146
148
|
Array.isArray(l.modelValue) ? l.modelValue.includes(a) ? t = l.modelValue.filter((s) => s !== a) : t = [...l.modelValue, a] : t = [a], I("update:modelValue", t);
|
|
147
|
-
const o = t.map((s) => s === a ? e : Ke(
|
|
149
|
+
const o = t.map((s) => s === a ? e : Ke(A.value[String(s)]) || Z.value.find((n) => i(n) === s)).filter(Boolean);
|
|
148
150
|
I("update:selectedOptions", o);
|
|
149
151
|
} else
|
|
150
|
-
I("update:modelValue", a), I("update:selectedOptions", [e]),
|
|
151
|
-
L.value = "", d.value && (d.value.value = ""), $.value && (p.value.some((t) =>
|
|
152
|
+
I("update:modelValue", a), I("update:selectedOptions", [e]), ae();
|
|
153
|
+
L.value = "", d.value && (d.value.value = ""), $.value && (p.value.some((t) => i(t) === a) || (p.value = [...p.value, e])), l.multiple && R(() => {
|
|
152
154
|
d.value && d.value.focus();
|
|
153
155
|
});
|
|
154
|
-
},
|
|
155
|
-
const a =
|
|
156
|
+
}, he = (e) => {
|
|
157
|
+
const a = i(e);
|
|
156
158
|
if (l.multiple && Array.isArray(l.modelValue)) {
|
|
157
159
|
const t = l.modelValue.filter((o) => o !== a);
|
|
158
|
-
I("update:modelValue", t), I("update:selectedOptions", B.value), t.includes(a) || delete
|
|
160
|
+
I("update:modelValue", t), I("update:selectedOptions", B.value), t.includes(a) || delete A.value[String(a)];
|
|
159
161
|
}
|
|
160
|
-
},
|
|
161
|
-
l.disabled || (
|
|
162
|
-
|
|
163
|
-
|
|
162
|
+
}, be = () => {
|
|
163
|
+
l.disabled || (!_.value && !G ? (z.value && (z.value.style.display = "flex"), G = requestAnimationFrame(() => {
|
|
164
|
+
G = requestAnimationFrame(() => {
|
|
165
|
+
G = null, Y = !0, _.value = !0, L.value = "", ce(), R(() => {
|
|
166
|
+
Y = !1, d.value && !C && (d.value.value = "", d.value.focus()), P.value.length > 0 ? (c.value = 0, q()) : c.value = -1;
|
|
167
|
+
});
|
|
164
168
|
});
|
|
165
|
-
})));
|
|
166
|
-
},
|
|
167
|
-
|
|
168
|
-
},
|
|
169
|
-
|
|
169
|
+
})) : (G && (cancelAnimationFrame(G), G = null, Y = !1), ae()));
|
|
170
|
+
}, ae = () => {
|
|
171
|
+
z.value && (z.value.style.display = ""), _.value = !1, L.value = "", d.value && (d.value.value = ""), ce();
|
|
172
|
+
}, ce = () => {
|
|
173
|
+
W.value = 1, X.value = !1, (!te.value || !l.modelValue) && (p.value = []), U.value = !1;
|
|
170
174
|
};
|
|
171
|
-
let
|
|
172
|
-
const
|
|
173
|
-
U.value || (
|
|
174
|
-
},
|
|
175
|
-
if (!$.value || !
|
|
175
|
+
let ee = -1, g = !1, C = !1;
|
|
176
|
+
const ge = () => {
|
|
177
|
+
U.value || (ee = c.value, g = ee >= 0, g && (C = !0), console.log(`Loading more results, page ${W.value + 1}`), W.value++, U.value = !0, ye(L.value, !0));
|
|
178
|
+
}, ye = async (e, a = !1) => {
|
|
179
|
+
if (!$.value || !re.value)
|
|
176
180
|
return Promise.resolve();
|
|
177
|
-
const t = l.ajax, o =
|
|
181
|
+
const t = l.ajax, o = te.value ? `${e}_${W.value}` : e;
|
|
178
182
|
let s = [];
|
|
179
|
-
if (l.modelValue && (s = [...B.value]), t.cache &&
|
|
180
|
-
const w =
|
|
183
|
+
if (l.modelValue && (s = [...B.value]), t.cache && ue.value[o]) {
|
|
184
|
+
const w = ue.value[o];
|
|
181
185
|
if (a)
|
|
182
186
|
p.value = [...p.value, ...w.results];
|
|
183
187
|
else {
|
|
184
|
-
const h = w.results, r = l.multiple && Array.isArray(l.modelValue) ? l.modelValue : l.modelValue ? [l.modelValue] : [],
|
|
185
|
-
(
|
|
186
|
-
const b =
|
|
187
|
-
return r.includes(b) && !h.some((
|
|
188
|
+
const h = w.results, r = l.multiple && Array.isArray(l.modelValue) ? l.modelValue : l.modelValue ? [l.modelValue] : [], v = s.filter(
|
|
189
|
+
(O) => {
|
|
190
|
+
const b = i(O);
|
|
191
|
+
return r.includes(b) && !h.some((J) => i(J) === b);
|
|
188
192
|
}
|
|
189
193
|
);
|
|
190
|
-
p.value = [...
|
|
194
|
+
p.value = [...v, ...h];
|
|
191
195
|
}
|
|
192
|
-
return
|
|
196
|
+
return X.value = w.more, U.value = !1, Promise.resolve();
|
|
193
197
|
}
|
|
194
198
|
!a && E.value !== null && (window.clearTimeout(E.value), E.value = null);
|
|
195
199
|
const n = t.method || "GET";
|
|
196
|
-
let
|
|
197
|
-
t.urlBuilder && typeof t.urlBuilder == "function" && (
|
|
200
|
+
let u = t.url;
|
|
201
|
+
t.urlBuilder && typeof t.urlBuilder == "function" && (u = t.urlBuilder(e, u), console.log("Using dynamically built URL:", u));
|
|
198
202
|
const m = t.headers || {
|
|
199
203
|
"Content-Type": "application/json",
|
|
200
204
|
Accept: "application/json"
|
|
201
205
|
};
|
|
202
|
-
let
|
|
206
|
+
let f = {};
|
|
203
207
|
if (t.params)
|
|
204
208
|
if (typeof t.params == "function") {
|
|
205
|
-
const w =
|
|
206
|
-
page:
|
|
209
|
+
const w = te.value ? {
|
|
210
|
+
page: W.value,
|
|
207
211
|
limit: t.limit || 10
|
|
208
212
|
} : void 0;
|
|
209
|
-
|
|
213
|
+
f = t.params(e, w);
|
|
210
214
|
} else
|
|
211
|
-
|
|
215
|
+
f = { ...t.params, query: e };
|
|
212
216
|
else
|
|
213
|
-
|
|
214
|
-
if (
|
|
217
|
+
f = t.urlBuilder ? {} : { query: e };
|
|
218
|
+
if (te.value) {
|
|
215
219
|
const w = t.limit || 10;
|
|
216
|
-
if (!("page" in
|
|
220
|
+
if (!("page" in f) && !("per_page" in f)) {
|
|
217
221
|
const h = t.pageParam || "page", r = t.limitParam || "per_page";
|
|
218
|
-
|
|
222
|
+
f[h] = W.value, f[r] = w;
|
|
219
223
|
}
|
|
220
224
|
}
|
|
221
225
|
return a || (H.value = !0), new Promise((w) => {
|
|
222
226
|
let h;
|
|
223
227
|
if (n === "GET") {
|
|
224
|
-
const r = new URLSearchParams(
|
|
225
|
-
console.log("Making request to:",
|
|
228
|
+
const r = new URLSearchParams(f).toString(), v = r ? `${u}?${r}` : u;
|
|
229
|
+
console.log("Making request to:", v), h = fetch(v, {
|
|
226
230
|
method: n,
|
|
227
231
|
headers: m
|
|
228
232
|
});
|
|
229
233
|
} else
|
|
230
|
-
h = fetch(
|
|
234
|
+
h = fetch(u, {
|
|
231
235
|
method: n,
|
|
232
236
|
headers: m,
|
|
233
|
-
body: JSON.stringify(
|
|
237
|
+
body: JSON.stringify(f)
|
|
234
238
|
});
|
|
235
239
|
h.then((r) => r.json()).then((r) => {
|
|
236
|
-
let
|
|
240
|
+
let v = [], O = !1;
|
|
237
241
|
if (t.processResults) {
|
|
238
242
|
const b = t.processResults(r);
|
|
239
|
-
|
|
243
|
+
v = b.results, O = b.more;
|
|
240
244
|
} else
|
|
241
|
-
Array.isArray(r) ? (
|
|
242
|
-
if (console.log(`Fetched ${
|
|
243
|
-
p.value = [...p.value, ...
|
|
245
|
+
Array.isArray(r) ? (v = r, O = !1) : r.results && Array.isArray(r.results) ? (v = r.results, O = !!r.more) : (v = [], O = !1);
|
|
246
|
+
if (console.log(`Fetched ${v.length} results, more: ${O}`), a)
|
|
247
|
+
p.value = [...p.value, ...v], R(() => {
|
|
244
248
|
if (g) {
|
|
245
|
-
const b = Math.min(
|
|
246
|
-
c.value = b,
|
|
249
|
+
const b = Math.min(ee, P.value.length - 1);
|
|
250
|
+
c.value = b, q(), j.value && j.value.focus(), setTimeout(() => {
|
|
247
251
|
C = !1;
|
|
248
252
|
}, 100);
|
|
249
253
|
}
|
|
250
254
|
});
|
|
251
255
|
else {
|
|
252
|
-
const b = l.multiple && Array.isArray(l.modelValue) ? l.modelValue : l.modelValue ? [l.modelValue] : [],
|
|
253
|
-
(
|
|
254
|
-
const
|
|
255
|
-
return b.includes(
|
|
256
|
+
const b = l.multiple && Array.isArray(l.modelValue) ? l.modelValue : l.modelValue ? [l.modelValue] : [], J = s.filter(
|
|
257
|
+
(se) => {
|
|
258
|
+
const xe = i(se);
|
|
259
|
+
return b.includes(xe) && !v.some((Ie) => i(Ie) === xe);
|
|
256
260
|
}
|
|
257
261
|
);
|
|
258
|
-
p.value = [...
|
|
262
|
+
p.value = [...J, ...v];
|
|
259
263
|
}
|
|
260
|
-
|
|
264
|
+
X.value = O, t.cache && (ue.value[o] = { results: v, more: O }), w();
|
|
261
265
|
}).catch((r) => {
|
|
262
|
-
console.error("Error fetching options:", r), a || (p.value = s),
|
|
266
|
+
console.error("Error fetching options:", r), a || (p.value = s), X.value = !1, w();
|
|
263
267
|
}).finally(() => {
|
|
264
|
-
H.value = !1, U.value = !1, a && g &&
|
|
268
|
+
H.value = !1, U.value = !1, a && g && R(() => {
|
|
265
269
|
setTimeout(() => {
|
|
266
270
|
C = !1;
|
|
267
271
|
}, 100);
|
|
268
272
|
});
|
|
269
273
|
});
|
|
270
274
|
});
|
|
271
|
-
},
|
|
275
|
+
}, Re = (e) => {
|
|
272
276
|
g = !1, C = !1, e.stopPropagation();
|
|
273
|
-
},
|
|
277
|
+
}, Te = () => {
|
|
274
278
|
g = !1, C = !1;
|
|
275
|
-
},
|
|
279
|
+
}, Pe = (e) => {
|
|
276
280
|
var t;
|
|
277
281
|
L.value;
|
|
278
282
|
const a = e.target.value;
|
|
279
283
|
if (L.value = a, g = !1, $.value) {
|
|
280
|
-
if (
|
|
284
|
+
if (ce(), E.value !== null && (window.clearTimeout(E.value), E.value = null), !re.value) {
|
|
281
285
|
p.value = [];
|
|
282
286
|
return;
|
|
283
287
|
}
|
|
284
288
|
const o = ((t = l.ajax) == null ? void 0 : t.delay) || 300;
|
|
285
289
|
E.value = window.setTimeout(() => {
|
|
286
290
|
const s = document.activeElement === d.value;
|
|
287
|
-
s && (g = !1, C = !1),
|
|
288
|
-
|
|
289
|
-
P.value.length > 0 && (c.value = 0,
|
|
291
|
+
s && (g = !1, C = !1), ye(L.value).then(() => {
|
|
292
|
+
R(() => {
|
|
293
|
+
P.value.length > 0 && (c.value = 0, q());
|
|
290
294
|
const n = document.activeElement === d.value;
|
|
291
295
|
(s || n) && d.value ? d.value.focus() : g && P.value.length > 0 && j.value && j.value.focus();
|
|
292
296
|
});
|
|
293
297
|
});
|
|
294
298
|
}, o);
|
|
295
299
|
}
|
|
296
|
-
},
|
|
297
|
-
|
|
298
|
-
if (c.value < 0 || !
|
|
300
|
+
}, q = () => {
|
|
301
|
+
R(() => {
|
|
302
|
+
if (c.value < 0 || !z.value || !j.value)
|
|
299
303
|
return;
|
|
300
304
|
const e = j.value.querySelector(".loop-select-option-highlighted");
|
|
301
305
|
if (e) {
|
|
302
|
-
const a = j.value, t = a.clientHeight, o = e, s = o.offsetTop, n = o.clientHeight,
|
|
303
|
-
m ? a.scrollTop = s :
|
|
306
|
+
const a = j.value, t = a.clientHeight, o = e, s = o.offsetTop, n = o.clientHeight, u = a.scrollTop, m = s < u, f = s + n > u + t;
|
|
307
|
+
m ? a.scrollTop = s : f && (a.scrollTop = s + n - t);
|
|
304
308
|
}
|
|
305
309
|
});
|
|
306
310
|
};
|
|
307
|
-
|
|
308
|
-
document.addEventListener("click",
|
|
309
|
-
}),
|
|
310
|
-
document.removeEventListener("click",
|
|
311
|
-
}),
|
|
311
|
+
Ue(() => {
|
|
312
|
+
document.addEventListener("click", Ve), $.value && l.modelValue && Z.value.length === 0 && (l.multiple ? Array.isArray(l.modelValue) && l.modelValue.length > 0 : l.modelValue !== null && l.modelValue !== void 0) && (console.log("Initial value present, fetching option data"), Ce());
|
|
313
|
+
}), $e(() => {
|
|
314
|
+
document.removeEventListener("click", Ve), E.value !== null && (window.clearTimeout(E.value), E.value = null);
|
|
315
|
+
}), Q(() => l.loading, (e) => {
|
|
312
316
|
H.value = e;
|
|
313
|
-
}),
|
|
314
|
-
if (!
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
A(() => {
|
|
321
|
-
if (g && X >= 0 && e.length > a.length) {
|
|
322
|
-
const t = Math.min(X, e.length - 1);
|
|
323
|
-
c.value = t, _();
|
|
317
|
+
}), Q(P, (e, a) => {
|
|
318
|
+
if (!Y) {
|
|
319
|
+
if (!U.value) {
|
|
320
|
+
e.length > 0 ? (c.value = 0, g && R(() => {
|
|
321
|
+
j.value && j.value.focus();
|
|
322
|
+
})) : c.value = -1;
|
|
323
|
+
return;
|
|
324
324
|
}
|
|
325
|
-
|
|
326
|
-
|
|
325
|
+
R(() => {
|
|
326
|
+
if (g && ee >= 0 && e.length > a.length) {
|
|
327
|
+
const t = Math.min(ee, e.length - 1);
|
|
328
|
+
c.value = t, q();
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}), Q(L, (e) => {
|
|
327
333
|
d.value && d.value.value !== e && (d.value.value = e);
|
|
328
|
-
}),
|
|
329
|
-
c.value >= 0 &&
|
|
330
|
-
}),
|
|
334
|
+
}), Q(c, () => {
|
|
335
|
+
Y || c.value >= 0 && q();
|
|
336
|
+
}), Q(() => l.modelValue, (e) => {
|
|
331
337
|
$.value && e && (l.multiple && Array.isArray(e) ? e : [e]).forEach((t) => {
|
|
332
|
-
if (!
|
|
333
|
-
const s = B.value.find((n) =>
|
|
334
|
-
s && (p.value.find((n) =>
|
|
338
|
+
if (!Z.value.find((s) => i(s) === t) && B.value) {
|
|
339
|
+
const s = B.value.find((n) => i(n) === t);
|
|
340
|
+
s && (p.value.find((n) => i(n) === t) || p.value.push(s));
|
|
335
341
|
}
|
|
336
342
|
});
|
|
337
343
|
}, { immediate: !0 });
|
|
338
|
-
const
|
|
339
|
-
|
|
340
|
-
},
|
|
341
|
-
if (!
|
|
344
|
+
const Ve = (e) => {
|
|
345
|
+
ie.value && !ie.value.contains(e.target) && _.value && ae();
|
|
346
|
+
}, Le = () => {
|
|
347
|
+
if (!te.value || !X.value || U.value)
|
|
342
348
|
return;
|
|
343
349
|
const e = j.value;
|
|
344
350
|
if (!e)
|
|
345
351
|
return;
|
|
346
352
|
const a = e.scrollTop + e.clientHeight, t = 20;
|
|
347
|
-
a >= e.scrollHeight - t && (console.log("Reached bottom of options list, loading more results..."),
|
|
348
|
-
},
|
|
349
|
-
P.value.length !== 0 && (g = !0, c.value < P.value.length - 1 ? (c.value++,
|
|
353
|
+
a >= e.scrollHeight - t && (console.log("Reached bottom of options list, loading more results..."), ge());
|
|
354
|
+
}, Se = () => {
|
|
355
|
+
P.value.length !== 0 && (g = !0, c.value < P.value.length - 1 ? (c.value++, q(), R(() => {
|
|
350
356
|
j.value && j.value.focus();
|
|
351
|
-
})) :
|
|
352
|
-
},
|
|
353
|
-
P.value.length !== 0 && (g = !0, c.value > 0 && (c.value--,
|
|
357
|
+
})) : X.value && !U.value && (g = !0, C = !0, ee = c.value, ge()));
|
|
358
|
+
}, je = () => {
|
|
359
|
+
P.value.length !== 0 && (g = !0, c.value > 0 && (c.value--, q(), R(() => {
|
|
354
360
|
j.value && j.value.focus();
|
|
355
361
|
})));
|
|
356
|
-
},
|
|
357
|
-
c.value >= 0 && P.value[c.value] && (
|
|
358
|
-
|
|
362
|
+
}, we = () => {
|
|
363
|
+
c.value >= 0 && P.value[c.value] && (me(P.value[c.value]), l.multiple && R(() => {
|
|
364
|
+
_.value && d.value && d.value.focus();
|
|
359
365
|
}));
|
|
360
366
|
};
|
|
361
|
-
|
|
362
|
-
e &&
|
|
367
|
+
Q(_, (e) => {
|
|
368
|
+
Y || e && requestAnimationFrame(() => {
|
|
363
369
|
d.value && !C && d.value.focus();
|
|
364
370
|
});
|
|
365
|
-
}),
|
|
371
|
+
}), Q(() => U.value, (e, a) => {
|
|
366
372
|
a === !0 && e === !1 && setTimeout(() => {
|
|
367
373
|
C && !g && (C = !1);
|
|
368
374
|
}, 200);
|
|
369
375
|
});
|
|
370
|
-
const
|
|
376
|
+
const Ce = async () => {
|
|
371
377
|
var t, o;
|
|
372
378
|
if (!$.value)
|
|
373
379
|
return;
|
|
374
380
|
const e = l.multiple && Array.isArray(l.modelValue) ? l.modelValue : [l.modelValue];
|
|
375
381
|
if (e.length === 0)
|
|
376
382
|
return;
|
|
377
|
-
const a = e.filter((s) => !(s == null ||
|
|
383
|
+
const a = e.filter((s) => !(s == null || A.value[String(s)] || Z.value.some((n) => i(n) === s)));
|
|
378
384
|
if (a.length !== 0) {
|
|
379
385
|
H.value = !0;
|
|
380
386
|
try {
|
|
@@ -382,27 +388,27 @@ const Ne = { class: "loop-select-selection" }, _e = { class: "loop-select-single
|
|
|
382
388
|
if ((t = l.ajax) != null && t.initialValueResolver) {
|
|
383
389
|
console.log("Using custom initialValueResolver to fetch option details");
|
|
384
390
|
const n = a.map(async (m) => {
|
|
385
|
-
const
|
|
386
|
-
return
|
|
391
|
+
const f = await l.ajax.initialValueResolver(m);
|
|
392
|
+
return f || null;
|
|
387
393
|
});
|
|
388
394
|
s = (await Promise.all(n)).filter((m) => m !== null);
|
|
389
395
|
} else if ((o = l.ajax) != null && o.initialValueUrl) {
|
|
390
396
|
console.log("Using initialValueUrl to fetch option details");
|
|
391
|
-
const n = l.ajax.initialValueUrl,
|
|
397
|
+
const n = l.ajax.initialValueUrl, u = l.ajax.method || "GET";
|
|
392
398
|
let m = {};
|
|
393
399
|
l.ajax.initialValueParams ? typeof l.ajax.initialValueParams == "function" ? m = l.ajax.initialValueParams(a) : m = l.ajax.initialValueParams : m = { ids: a.join(",") };
|
|
394
|
-
const
|
|
400
|
+
const f = l.ajax.headers || {
|
|
395
401
|
"Content-Type": "application/json",
|
|
396
402
|
Accept: "application/json"
|
|
397
403
|
};
|
|
398
404
|
let w;
|
|
399
|
-
if (
|
|
400
|
-
const r = new URLSearchParams(m).toString(),
|
|
401
|
-
console.log("Fetching initial values from:",
|
|
405
|
+
if (u === "GET") {
|
|
406
|
+
const r = new URLSearchParams(m).toString(), v = r ? `${n}?${r}` : n;
|
|
407
|
+
console.log("Fetching initial values from:", v), w = await fetch(v, { method: u, headers: f });
|
|
402
408
|
} else
|
|
403
409
|
w = await fetch(n, {
|
|
404
|
-
method:
|
|
405
|
-
headers:
|
|
410
|
+
method: u,
|
|
411
|
+
headers: f,
|
|
406
412
|
body: JSON.stringify(m)
|
|
407
413
|
});
|
|
408
414
|
const h = await w.json();
|
|
@@ -410,32 +416,32 @@ const Ne = { class: "loop-select-selection" }, _e = { class: "loop-select-single
|
|
|
410
416
|
} else {
|
|
411
417
|
console.log("Using regular ajax URL with id parameter to fetch option details");
|
|
412
418
|
const n = l.multiple ? a : [a[0]];
|
|
413
|
-
for (const
|
|
414
|
-
const m = l.ajax.url,
|
|
415
|
-
let h = { [l.ajax.idParam || "id"]:
|
|
419
|
+
for (const u of n) {
|
|
420
|
+
const m = l.ajax.url, f = l.ajax.method || "GET";
|
|
421
|
+
let h = { [l.ajax.idParam || "id"]: u };
|
|
416
422
|
l.ajax.params && (typeof l.ajax.params == "function" ? h = { ...h, ...l.ajax.params("") } : h = { ...h, ...l.ajax.params });
|
|
417
423
|
const r = l.ajax.headers || {
|
|
418
424
|
"Content-Type": "application/json",
|
|
419
425
|
Accept: "application/json"
|
|
420
426
|
};
|
|
421
|
-
let
|
|
422
|
-
if (
|
|
423
|
-
const
|
|
424
|
-
console.log("Fetching initial value from:",
|
|
427
|
+
let v;
|
|
428
|
+
if (f === "GET") {
|
|
429
|
+
const J = new URLSearchParams(h).toString(), se = J ? `${m}?${J}` : m;
|
|
430
|
+
console.log("Fetching initial value from:", se), v = await fetch(se, { method: f, headers: r });
|
|
425
431
|
} else
|
|
426
|
-
|
|
427
|
-
method:
|
|
432
|
+
v = await fetch(m, {
|
|
433
|
+
method: f,
|
|
428
434
|
headers: r,
|
|
429
435
|
body: JSON.stringify(h)
|
|
430
436
|
});
|
|
431
|
-
const
|
|
437
|
+
const O = await v.json();
|
|
432
438
|
let b = [];
|
|
433
|
-
l.ajax.processResults ? b = l.ajax.processResults(
|
|
439
|
+
l.ajax.processResults ? b = l.ajax.processResults(O).results : b = Array.isArray(O) ? O : O.results || [], s = [...s, ...b];
|
|
434
440
|
}
|
|
435
441
|
}
|
|
436
442
|
console.log("Resolved initial options:", s), s.forEach((n) => {
|
|
437
|
-
const
|
|
438
|
-
|
|
443
|
+
const u = i(n);
|
|
444
|
+
u != null && (A.value[String(u)] = n, p.value.some((m) => i(m) === u) || p.value.push(n));
|
|
439
445
|
});
|
|
440
446
|
} catch (s) {
|
|
441
447
|
console.error("Error fetching initial value details:", s);
|
|
@@ -445,125 +451,124 @@ const Ne = { class: "loop-select-selection" }, _e = { class: "loop-select-single
|
|
|
445
451
|
}
|
|
446
452
|
};
|
|
447
453
|
return (e, a) => (y(), V("div", {
|
|
448
|
-
class:
|
|
454
|
+
class: Ae([
|
|
449
455
|
"loop-select-container",
|
|
450
|
-
{ "loop-select-open":
|
|
456
|
+
{ "loop-select-open": _.value, "loop-select-disabled": S.disabled }
|
|
451
457
|
]),
|
|
452
|
-
onClick:
|
|
458
|
+
onClick: T(be, ["stop"]),
|
|
453
459
|
ref_key: "containerRef",
|
|
454
|
-
ref:
|
|
460
|
+
ref: ie
|
|
455
461
|
}, [
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
S.multiple ? (y(), V(
|
|
459
|
-
B.value.length ? (y(), V("div",
|
|
460
|
-
(y(!0), V(
|
|
461
|
-
key:
|
|
462
|
+
k("div", Ne, [
|
|
463
|
+
k("div", _e, [
|
|
464
|
+
S.multiple ? (y(), V(le, { key: 1 }, [
|
|
465
|
+
B.value.length ? (y(), V("div", De, [
|
|
466
|
+
(y(!0), V(le, null, de(B.value, (t) => (y(), V("div", {
|
|
467
|
+
key: i(t),
|
|
462
468
|
class: "loop-select-selected-item"
|
|
463
469
|
}, [
|
|
464
|
-
|
|
470
|
+
oe(e.$slots, "selected-option", {
|
|
465
471
|
option: t,
|
|
466
|
-
remove: () =>
|
|
472
|
+
remove: () => he(t)
|
|
467
473
|
}, () => [
|
|
468
|
-
|
|
469
|
-
|
|
474
|
+
k("span", null, K(M(t)), 1),
|
|
475
|
+
k("button", {
|
|
470
476
|
class: "loop-select-remove-item",
|
|
471
|
-
onClick:
|
|
477
|
+
onClick: T((o) => he(t), ["stop"]),
|
|
472
478
|
type: "button"
|
|
473
|
-
}, " × ", 8,
|
|
479
|
+
}, " × ", 8, Me)
|
|
474
480
|
])
|
|
475
481
|
]))), 128))
|
|
476
|
-
])) : (y(), V("span",
|
|
477
|
-
], 64)) : (y(), V(
|
|
478
|
-
|
|
482
|
+
])) : (y(), V("span", Je, K(S.placeholder), 1))
|
|
483
|
+
], 64)) : (y(), V(le, { key: 0 }, [
|
|
484
|
+
D.value ? oe(e.$slots, "selected-option", {
|
|
479
485
|
key: 0,
|
|
480
|
-
option:
|
|
486
|
+
option: D.value,
|
|
481
487
|
remove: () => {
|
|
482
488
|
}
|
|
483
489
|
}, () => [
|
|
484
|
-
|
|
485
|
-
]) : (y(), V("span",
|
|
490
|
+
k("span", He, K(M(D.value)), 1)
|
|
491
|
+
]) : (y(), V("span", Ge, K(S.placeholder), 1))
|
|
486
492
|
], 64))
|
|
487
493
|
]),
|
|
488
|
-
a[1] || (a[1] =
|
|
489
|
-
|
|
494
|
+
a[1] || (a[1] = k("div", { class: "loop-select-arrow" }, [
|
|
495
|
+
k("span", null, "▼")
|
|
490
496
|
], -1))
|
|
491
497
|
]),
|
|
492
|
-
|
|
493
|
-
key: 0,
|
|
498
|
+
k("div", {
|
|
494
499
|
class: "loop-select-dropdown",
|
|
495
500
|
ref_key: "dropdownRef",
|
|
496
|
-
ref:
|
|
501
|
+
ref: z
|
|
497
502
|
}, [
|
|
498
|
-
|
|
499
|
-
|
|
503
|
+
k("div", Qe, [
|
|
504
|
+
k("input", {
|
|
500
505
|
ref_key: "searchInputRef",
|
|
501
506
|
ref: d,
|
|
502
507
|
class: "loop-select-search",
|
|
503
508
|
type: "text",
|
|
504
|
-
onInput:
|
|
509
|
+
onInput: Pe,
|
|
505
510
|
onKeydown: [
|
|
506
|
-
a[0] || (a[0] =
|
|
511
|
+
a[0] || (a[0] = T(() => {
|
|
507
512
|
}, ["stop"])),
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
513
|
+
N(T(Se, ["prevent"]), ["down"]),
|
|
514
|
+
N(T(je, ["prevent"]), ["up"]),
|
|
515
|
+
N(T(we, ["prevent"]), ["enter"]),
|
|
516
|
+
N(T(ae, ["prevent"]), ["esc"])
|
|
512
517
|
],
|
|
513
|
-
onClick:
|
|
514
|
-
onFocus:
|
|
518
|
+
onClick: T(Re, ["stop"]),
|
|
519
|
+
onFocus: Te,
|
|
515
520
|
placeholder: "Search..."
|
|
516
|
-
}, null, 40,
|
|
517
|
-
S.loading || H.value ? (y(), V("div",
|
|
518
|
-
|
|
519
|
-
]))) :
|
|
521
|
+
}, null, 40, ze),
|
|
522
|
+
S.loading || H.value ? (y(), V("div", We, a[2] || (a[2] = [
|
|
523
|
+
k("div", { class: "lds-dual-ring" }, null, -1)
|
|
524
|
+
]))) : ne("", !0)
|
|
520
525
|
]),
|
|
521
|
-
|
|
526
|
+
k("ul", {
|
|
522
527
|
class: "loop-select-options",
|
|
523
|
-
onScroll:
|
|
528
|
+
onScroll: Le,
|
|
524
529
|
ref_key: "optionsListRef",
|
|
525
530
|
ref: j,
|
|
526
|
-
tabindex:
|
|
531
|
+
tabindex: Be(g) ? 0 : -1,
|
|
527
532
|
onKeydown: [
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
533
|
+
N(T(Se, ["prevent"]), ["down"]),
|
|
534
|
+
N(T(je, ["prevent"]), ["up"]),
|
|
535
|
+
N(T(we, ["prevent"]), ["enter"]),
|
|
536
|
+
N(T(ae, ["prevent"]), ["esc"])
|
|
532
537
|
]
|
|
533
538
|
}, [
|
|
534
|
-
P.value.length === 0 && !S.loading && !H.value ? (y(), V("li",
|
|
535
|
-
(y(!0), V(
|
|
536
|
-
key:
|
|
537
|
-
class:
|
|
539
|
+
P.value.length === 0 && !S.loading && !H.value ? (y(), V("li", Ye, "No results found")) : (y(), V(le, { key: 1 }, [
|
|
540
|
+
(y(!0), V(le, null, de(P.value, (t, o) => (y(), V("li", {
|
|
541
|
+
key: i(t),
|
|
542
|
+
class: Ae([
|
|
538
543
|
"loop-select-option",
|
|
539
544
|
{
|
|
540
|
-
"loop-select-option-selected":
|
|
545
|
+
"loop-select-option-selected": pe(t),
|
|
541
546
|
"loop-select-option-highlighted": o === c.value
|
|
542
547
|
}
|
|
543
548
|
]),
|
|
544
|
-
onClick:
|
|
549
|
+
onClick: T((s) => me(t), ["stop"]),
|
|
545
550
|
onMouseover: () => {
|
|
546
|
-
c.value = o,
|
|
551
|
+
c.value = o, q(), Fe(g) ? g.value = !1 : g = !1;
|
|
547
552
|
}
|
|
548
553
|
}, [
|
|
549
|
-
|
|
554
|
+
oe(e.$slots, "option", {
|
|
550
555
|
option: t,
|
|
551
|
-
selected:
|
|
556
|
+
selected: pe(t),
|
|
552
557
|
highlighted: o === c.value,
|
|
553
558
|
index: o
|
|
554
559
|
}, () => [
|
|
555
|
-
|
|
560
|
+
qe(K(M(t)), 1)
|
|
556
561
|
])
|
|
557
|
-
], 42,
|
|
558
|
-
U.value ? (y(), V("li",
|
|
559
|
-
|
|
560
|
-
a[3] || (a[3] =
|
|
562
|
+
], 42, Ze))), 128)),
|
|
563
|
+
U.value ? (y(), V("li", el, [
|
|
564
|
+
oe(e.$slots, "loading-more", {}, () => [
|
|
565
|
+
a[3] || (a[3] = k("div", { class: "lds-dual-ring" }, null, -1))
|
|
561
566
|
])
|
|
562
|
-
])) :
|
|
567
|
+
])) : ne("", !0)
|
|
563
568
|
], 64))
|
|
564
|
-
], 40,
|
|
565
|
-
], 512)
|
|
566
|
-
|
|
569
|
+
], 40, Xe)
|
|
570
|
+
], 512),
|
|
571
|
+
k("select", {
|
|
567
572
|
multiple: S.multiple,
|
|
568
573
|
name: S.name,
|
|
569
574
|
required: S.required,
|
|
@@ -572,29 +577,29 @@ const Ne = { class: "loop-select-selection" }, _e = { class: "loop-select-single
|
|
|
572
577
|
class: "loop-select-hidden",
|
|
573
578
|
"aria-hidden": "true"
|
|
574
579
|
}, [
|
|
575
|
-
!S.multiple && !
|
|
576
|
-
S.multiple ? (y(!0), V(
|
|
577
|
-
key:
|
|
578
|
-
value:
|
|
580
|
+
!S.multiple && !ve.value ? (y(), V("option", tl, K(S.placeholder), 1)) : ne("", !0),
|
|
581
|
+
S.multiple ? (y(!0), V(le, { key: 1 }, de(B.value, (t) => (y(), V("option", {
|
|
582
|
+
key: i(t),
|
|
583
|
+
value: i(t),
|
|
579
584
|
selected: ""
|
|
580
|
-
},
|
|
585
|
+
}, K(M(t)), 9, al))), 128)) : D.value ? (y(), V("option", {
|
|
581
586
|
key: 2,
|
|
582
|
-
value:
|
|
587
|
+
value: ve.value,
|
|
583
588
|
selected: ""
|
|
584
|
-
},
|
|
585
|
-
], 8,
|
|
589
|
+
}, K(M(D.value)), 9, sl)) : ne("", !0)
|
|
590
|
+
], 8, ll)
|
|
586
591
|
], 2));
|
|
587
592
|
}
|
|
588
593
|
});
|
|
589
|
-
let
|
|
590
|
-
typeof window < "u" && (
|
|
591
|
-
|
|
592
|
-
const
|
|
594
|
+
let fe = null;
|
|
595
|
+
typeof window < "u" && (fe = window.Vue);
|
|
596
|
+
fe && fe.component("Loop8Select", Oe);
|
|
597
|
+
const nl = {
|
|
593
598
|
install: (S) => {
|
|
594
|
-
S.component("Loop8Select",
|
|
599
|
+
S.component("Loop8Select", Oe);
|
|
595
600
|
}
|
|
596
601
|
};
|
|
597
602
|
export {
|
|
598
|
-
|
|
599
|
-
|
|
603
|
+
Oe as Loop8Select,
|
|
604
|
+
nl as default
|
|
600
605
|
};
|
package/dist/loop8-select.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(C,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(C=typeof globalThis<"u"?globalThis:C||self,e(C.Loop8Select={},C.Vue))})(this,function(C,e){"use strict";const Me="",Ue="",de={class:"loop-select-selection"},fe={class:"loop-select-single-selection"},pe={class:"loop-select-selected-text"},me={key:1,class:"loop-select-placeholder"},he={key:0,class:"loop-select-tags-container"},ge=["onClick"],ve={key:1,class:"loop-select-placeholder"},ye={class:"loop-select-search-container"},ke=["onKeydown"],Ve={key:0,class:"loop-select-search-spinner"},we=["tabindex","onKeydown"],Se={key:0,class:"loop-select-no-results"},xe=["onClick","onMouseover"],Be={key:0,class:"loop-select-loading-more"},je=["multiple","name","required","disabled"],Ee={key:0,value:"",disabled:"",selected:""},Te=["value"],Ae=["value"],J=e.defineComponent({name:"Loop8Select",__name:"Loop8Select",props:{modelValue:{type:[Array,String,Number,Object,Boolean],default:null},options:{type:Array,default:()=>[]},placeholder:{type:String,default:"Select an option"},multiple:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},required:{type:Boolean,default:!1},name:{type:String,default:""},loading:{type:Boolean,default:!1},valueKey:{type:String,default:"value"},labelKey:{type:String,default:"text"},ajax:{type:Object,default:null}},emits:["update:modelValue","invalid-option","update:selectedOptions"],setup(k,{emit:be}){const t=k,A=be,P=e.ref(!1),E=e.ref(""),d=e.ref(-1),Q=e.ref(null),Z=e.ref(null),f=e.ref(null),V=e.ref(null),I=e.ref(t.loading),h=e.ref([]),O=e.ref(null),W=e.ref({}),$=e.ref(1),F=e.ref(!1),b=e.ref(!1),S=e.ref({}),R=e.computed(()=>!!t.ajax),q=e.computed(()=>{var l;return R.value&&!!((l=t.ajax)!=null&&l.pagination)}),X=e.computed(()=>{var o;if(!R.value)return!0;const l=((o=t.ajax)==null?void 0:o.minimumInputLength)||0;return E.value.length>=l}),_=e.computed(()=>{const l=R.value?[...t.options,...h.value]:t.options,o=Object.values(S.value);if(o.length>0){const a=o.filter(s=>!l.some(n=>r(n)===r(s)));return[...l,...a]}return l}),N=e.computed(()=>{if(t.multiple){if(!t.modelValue||!Array.isArray(t.modelValue))return[];const l=Array.isArray(t.modelValue)?t.modelValue:[t.modelValue],o=[],a=l.map(s=>{if(s!=null&&S.value[String(s)])return S.value[String(s)];const n=_.value.find(c=>r(c)===s);if(n)return S.value[String(s)]=n,n;const i=h.value.find(c=>r(c)===s);return i?(S.value[String(s)]=i,i):(o.push(s),null)}).filter(s=>s!==null);return o.length>0&&(A("invalid-option",o),e.nextTick(()=>{const s=l.filter(n=>!o.includes(n));A("update:modelValue",s)})),a}else{if(t.modelValue===null||t.modelValue===void 0)return[];const l=t.modelValue;if(l!=null&&S.value[String(l)])return[S.value[String(l)]];const o=_.value.find(s=>r(s)===l);if(o)return S.value[String(l)]=o,[o];const a=h.value.find(s=>r(s)===l);return a?(S.value[String(l)]=a,[a]):(A("invalid-option",l),e.nextTick(()=>{A("update:modelValue",null)}),[])}}),K=e.computed(()=>N.value.length>0?N.value[0]:null),ee=e.computed(()=>K.value?r(K.value):null);e.computed(()=>{const l=N.value[0];return l?M(l):""});const j=e.computed(()=>{if(R.value)return X.value?h.value:[];if(!E.value)return t.options;const l=E.value.toLowerCase();return t.options.filter(o=>M(o).toLowerCase().includes(l))}),r=l=>typeof l=="object"&&l!==null?l[t.valueKey]:l,M=l=>typeof l=="object"&&l!==null?l[t.labelKey]||l[t.valueKey]||"":String(l),le=l=>{const o=r(l);return t.multiple&&Array.isArray(t.modelValue)?t.modelValue.includes(o):t.modelValue===o},te=l=>{const o=r(l);if(S.value[String(o)]=l,t.multiple){let a=[];Array.isArray(t.modelValue)?t.modelValue.includes(o)?a=t.modelValue.filter(n=>n!==o):a=[...t.modelValue,o]:a=[o],A("update:modelValue",a);const s=a.map(n=>n===o?l:e.toRaw(S.value[String(n)])||_.value.find(i=>r(i)===n)).filter(Boolean);A("update:selectedOptions",s)}else A("update:modelValue",o),A("update:selectedOptions",[l]),H();E.value="",f.value&&(f.value.value=""),R.value&&(h.value.some(a=>r(a)===o)||(h.value=[...h.value,l])),t.multiple&&e.nextTick(()=>{f.value&&f.value.focus()})},ae=l=>{const o=r(l);if(t.multiple&&Array.isArray(t.modelValue)){const a=t.modelValue.filter(s=>s!==o);A("update:modelValue",a),A("update:selectedOptions",N.value),a.includes(o)||delete S.value[String(o)]}},Re=()=>{t.disabled||(P.value=!P.value,P.value&&(E.value="",Y(),e.nextTick(()=>{f.value&&!T&&(f.value.value="",f.value.focus()),e.nextTick(()=>{j.value.length>0?(d.value=0,L()):d.value=-1})})))},H=()=>{P.value=!1,E.value="",f.value&&(f.value.value=""),Y()},Y=()=>{$.value=1,F.value=!1,(!q.value||!t.modelValue)&&(h.value=[]),b.value=!1};let D=-1,y=!1,T=!1;const oe=()=>{b.value||(D=d.value,y=D>=0,y&&(T=!0),console.log(`Loading more results, page ${$.value+1}`),$.value++,b.value=!0,ne(E.value,!0))},ne=async(l,o=!1)=>{if(!R.value||!X.value)return Promise.resolve();const a=t.ajax,s=q.value?`${l}_${$.value}`:l;let n=[];if(t.modelValue&&(n=[...N.value]),a.cache&&W.value[s]){const w=W.value[s];if(o)h.value=[...h.value,...w.results];else{const v=w.results,u=t.multiple&&Array.isArray(t.modelValue)?t.modelValue:t.modelValue?[t.modelValue]:[],m=n.filter(x=>{const B=r(x);return u.includes(B)&&!v.some(U=>r(U)===B)});h.value=[...m,...v]}return F.value=w.more,b.value=!1,Promise.resolve()}!o&&O.value!==null&&(window.clearTimeout(O.value),O.value=null);const i=a.method||"GET";let c=a.url;a.urlBuilder&&typeof a.urlBuilder=="function"&&(c=a.urlBuilder(l,c),console.log("Using dynamically built URL:",c));const g=a.headers||{"Content-Type":"application/json",Accept:"application/json"};let p={};if(a.params)if(typeof a.params=="function"){const w=q.value?{page:$.value,limit:a.limit||10}:void 0;p=a.params(l,w)}else p={...a.params,query:l};else p=a.urlBuilder?{}:{query:l};if(q.value){const w=a.limit||10;if(!("page"in p)&&!("per_page"in p)){const v=a.pageParam||"page",u=a.limitParam||"per_page";p[v]=$.value,p[u]=w}}return o||(I.value=!0),new Promise(w=>{let v;if(i==="GET"){const u=new URLSearchParams(p).toString(),m=u?`${c}?${u}`:c;console.log("Making request to:",m),v=fetch(m,{method:i,headers:g})}else v=fetch(c,{method:i,headers:g,body:JSON.stringify(p)});v.then(u=>u.json()).then(u=>{let m=[],x=!1;if(a.processResults){const B=a.processResults(u);m=B.results,x=B.more}else Array.isArray(u)?(m=u,x=!1):u.results&&Array.isArray(u.results)?(m=u.results,x=!!u.more):(m=[],x=!1);if(console.log(`Fetched ${m.length} results, more: ${x}`),o)h.value=[...h.value,...m],e.nextTick(()=>{if(y){const B=Math.min(D,j.value.length-1);d.value=B,L(),V.value&&V.value.focus(),setTimeout(()=>{T=!1},100)}});else{const B=t.multiple&&Array.isArray(t.modelValue)?t.modelValue:t.modelValue?[t.modelValue]:[],U=n.filter(G=>{const ue=r(G);return B.includes(ue)&&!m.some(Ke=>r(Ke)===ue)});h.value=[...U,...m]}F.value=x,a.cache&&(W.value[s]={results:m,more:x}),w()}).catch(u=>{console.error("Error fetching options:",u),o||(h.value=n),F.value=!1,w()}).finally(()=>{I.value=!1,b.value=!1,o&&y&&e.nextTick(()=>{setTimeout(()=>{T=!1},100)})})})},Ne=l=>{y=!1,T=!1,l.stopPropagation()},Pe=()=>{y=!1,T=!1},Ce=l=>{var a;E.value;const o=l.target.value;if(E.value=o,y=!1,R.value){if(Y(),O.value!==null&&(window.clearTimeout(O.value),O.value=null),!X.value){h.value=[];return}const s=((a=t.ajax)==null?void 0:a.delay)||300;O.value=window.setTimeout(()=>{const n=document.activeElement===f.value;n&&(y=!1,T=!1),ne(E.value).then(()=>{e.nextTick(()=>{j.value.length>0&&(d.value=0,L());const i=document.activeElement===f.value;(n||i)&&f.value?f.value.focus():y&&j.value.length>0&&V.value&&V.value.focus()})})},s)}},L=()=>{e.nextTick(()=>{if(d.value<0||!Z.value||!V.value)return;const l=V.value.querySelector(".loop-select-option-highlighted");if(l){const o=V.value,a=o.clientHeight,s=l,n=s.offsetTop,i=s.clientHeight,c=o.scrollTop,g=n<c,p=n+i>c+a;g?o.scrollTop=n:p&&(o.scrollTop=n+i-a)}})};e.onMounted(()=>{document.addEventListener("click",se),R.value&&t.modelValue&&_.value.length===0&&(t.multiple?Array.isArray(t.modelValue)&&t.modelValue.length>0:t.modelValue!==null&&t.modelValue!==void 0)&&(console.log("Initial value present, fetching option data"),Ie())}),e.onBeforeUnmount(()=>{document.removeEventListener("click",se),O.value!==null&&(window.clearTimeout(O.value),O.value=null)}),e.watch(()=>t.loading,l=>{I.value=l}),e.watch(j,(l,o)=>{if(!b.value){l.length>0?(d.value=0,y&&e.nextTick(()=>{V.value&&V.value.focus()})):d.value=-1;return}e.nextTick(()=>{if(y&&D>=0&&l.length>o.length){const a=Math.min(D,l.length-1);d.value=a,L()}})}),e.watch(E,l=>{f.value&&f.value.value!==l&&(f.value.value=l)}),e.watch(d,()=>{d.value>=0&&L()}),e.watch(()=>t.modelValue,l=>{R.value&&l&&(t.multiple&&Array.isArray(l)?l:[l]).forEach(a=>{if(!_.value.find(n=>r(n)===a)&&N.value){const n=N.value.find(i=>r(i)===a);n&&(h.value.find(i=>r(i)===a)||h.value.push(n))}})},{immediate:!0});const se=l=>{Q.value&&!Q.value.contains(l.target)&&P.value&&H()},Le=()=>{if(!q.value||!F.value||b.value)return;const l=V.value;if(!l)return;const o=l.scrollTop+l.clientHeight,a=20;o>=l.scrollHeight-a&&(console.log("Reached bottom of options list, loading more results..."),oe())},ie=()=>{j.value.length!==0&&(y=!0,d.value<j.value.length-1?(d.value++,L(),e.nextTick(()=>{V.value&&V.value.focus()})):F.value&&!b.value&&(y=!0,T=!0,D=d.value,oe()))},re=()=>{j.value.length!==0&&(y=!0,d.value>0&&(d.value--,L(),e.nextTick(()=>{V.value&&V.value.focus()})))},ce=()=>{d.value>=0&&j.value[d.value]&&(te(j.value[d.value]),t.multiple&&e.nextTick(()=>{P.value&&f.value&&f.value.focus()}))};e.watch(P,l=>{l&&e.nextTick(()=>{f.value&&!T&&f.value.focus()})}),e.watch(()=>b.value,(l,o)=>{o===!0&&l===!1&&setTimeout(()=>{T&&!y&&(T=!1)},200)});const Ie=async()=>{var a,s;if(!R.value)return;const l=t.multiple&&Array.isArray(t.modelValue)?t.modelValue:[t.modelValue];if(l.length===0)return;const o=l.filter(n=>!(n==null||S.value[String(n)]||_.value.some(i=>r(i)===n)));if(o.length!==0){I.value=!0;try{let n=[];if((a=t.ajax)!=null&&a.initialValueResolver){console.log("Using custom initialValueResolver to fetch option details");const i=o.map(async g=>{const p=await t.ajax.initialValueResolver(g);return p||null});n=(await Promise.all(i)).filter(g=>g!==null)}else if((s=t.ajax)!=null&&s.initialValueUrl){console.log("Using initialValueUrl to fetch option details");const i=t.ajax.initialValueUrl,c=t.ajax.method||"GET";let g={};t.ajax.initialValueParams?typeof t.ajax.initialValueParams=="function"?g=t.ajax.initialValueParams(o):g=t.ajax.initialValueParams:g={ids:o.join(",")};const p=t.ajax.headers||{"Content-Type":"application/json",Accept:"application/json"};let w;if(c==="GET"){const u=new URLSearchParams(g).toString(),m=u?`${i}?${u}`:i;console.log("Fetching initial values from:",m),w=await fetch(m,{method:c,headers:p})}else w=await fetch(i,{method:c,headers:p,body:JSON.stringify(g)});const v=await w.json();t.ajax.processResults?n=t.ajax.processResults(v).results:n=Array.isArray(v)?v:v.results||[]}else{console.log("Using regular ajax URL with id parameter to fetch option details");const i=t.multiple?o:[o[0]];for(const c of i){const g=t.ajax.url,p=t.ajax.method||"GET";let v={[t.ajax.idParam||"id"]:c};t.ajax.params&&(typeof t.ajax.params=="function"?v={...v,...t.ajax.params("")}:v={...v,...t.ajax.params});const u=t.ajax.headers||{"Content-Type":"application/json",Accept:"application/json"};let m;if(p==="GET"){const U=new URLSearchParams(v).toString(),G=U?`${g}?${U}`:g;console.log("Fetching initial value from:",G),m=await fetch(G,{method:p,headers:u})}else m=await fetch(g,{method:p,headers:u,body:JSON.stringify(v)});const x=await m.json();let B=[];t.ajax.processResults?B=t.ajax.processResults(x).results:B=Array.isArray(x)?x:x.results||[],n=[...n,...B]}}console.log("Resolved initial options:",n),n.forEach(i=>{const c=r(i);c!=null&&(S.value[String(c)]=i,h.value.some(g=>r(g)===c)||h.value.push(i))})}catch(n){console.error("Error fetching initial value details:",n)}finally{I.value=!1}}};return(l,o)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["loop-select-container",{"loop-select-open":P.value,"loop-select-disabled":k.disabled}]),onClick:e.withModifiers(Re,["stop"]),ref_key:"containerRef",ref:Q},[e.createElementVNode("div",de,[e.createElementVNode("div",fe,[k.multiple?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[N.value.length?(e.openBlock(),e.createElementBlock("div",he,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(N.value,a=>(e.openBlock(),e.createElementBlock("div",{key:r(a),class:"loop-select-selected-item"},[e.renderSlot(l.$slots,"selected-option",{option:a,remove:()=>ae(a)},()=>[e.createElementVNode("span",null,e.toDisplayString(M(a)),1),e.createElementVNode("button",{class:"loop-select-remove-item",onClick:e.withModifiers(s=>ae(a),["stop"]),type:"button"}," × ",8,ge)])]))),128))])):(e.openBlock(),e.createElementBlock("span",ve,e.toDisplayString(k.placeholder),1))],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[K.value?e.renderSlot(l.$slots,"selected-option",{key:0,option:K.value,remove:()=>{}},()=>[e.createElementVNode("span",pe,e.toDisplayString(M(K.value)),1)]):(e.openBlock(),e.createElementBlock("span",me,e.toDisplayString(k.placeholder),1))],64))]),o[1]||(o[1]=e.createElementVNode("div",{class:"loop-select-arrow"},[e.createElementVNode("span",null,"▼")],-1))]),P.value?(e.openBlock(),e.createElementBlock("div",{key:0,class:"loop-select-dropdown",ref_key:"dropdownRef",ref:Z},[e.createElementVNode("div",ye,[e.createElementVNode("input",{ref_key:"searchInputRef",ref:f,class:"loop-select-search",type:"text",onInput:Ce,onKeydown:[o[0]||(o[0]=e.withModifiers(()=>{},["stop"])),e.withKeys(e.withModifiers(ie,["prevent"]),["down"]),e.withKeys(e.withModifiers(re,["prevent"]),["up"]),e.withKeys(e.withModifiers(ce,["prevent"]),["enter"]),e.withKeys(e.withModifiers(H,["prevent"]),["esc"])],onClick:e.withModifiers(Ne,["stop"]),onFocus:Pe,placeholder:"Search..."},null,40,ke),k.loading||I.value?(e.openBlock(),e.createElementBlock("div",Ve,o[2]||(o[2]=[e.createElementVNode("div",{class:"lds-dual-ring"},null,-1)]))):e.createCommentVNode("",!0)]),e.createElementVNode("ul",{class:"loop-select-options",onScroll:Le,ref_key:"optionsListRef",ref:V,tabindex:e.unref(y)?0:-1,onKeydown:[e.withKeys(e.withModifiers(ie,["prevent"]),["down"]),e.withKeys(e.withModifiers(re,["prevent"]),["up"]),e.withKeys(e.withModifiers(ce,["prevent"]),["enter"]),e.withKeys(e.withModifiers(H,["prevent"]),["esc"])]},[j.value.length===0&&!k.loading&&!I.value?(e.openBlock(),e.createElementBlock("li",Se,"No results found")):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(j.value,(a,s)=>(e.openBlock(),e.createElementBlock("li",{key:r(a),class:e.normalizeClass(["loop-select-option",{"loop-select-option-selected":le(a),"loop-select-option-highlighted":s===d.value}]),onClick:e.withModifiers(n=>te(a),["stop"]),onMouseover:()=>{d.value=s,L(),e.isRef(y)?y.value=!1:y=!1}},[e.renderSlot(l.$slots,"option",{option:a,selected:le(a),highlighted:s===d.value,index:s},()=>[e.createTextVNode(e.toDisplayString(M(a)),1)])],42,xe))),128)),b.value?(e.openBlock(),e.createElementBlock("li",Be,[e.renderSlot(l.$slots,"loading-more",{},()=>[o[3]||(o[3]=e.createElementVNode("div",{class:"lds-dual-ring"},null,-1))])])):e.createCommentVNode("",!0)],64))],40,we)],512)):e.createCommentVNode("",!0),e.createElementVNode("select",{multiple:k.multiple,name:k.name,required:k.required,disabled:k.disabled,tabindex:"-1",class:"loop-select-hidden","aria-hidden":"true"},[!k.multiple&&!ee.value?(e.openBlock(),e.createElementBlock("option",Ee,e.toDisplayString(k.placeholder),1)):e.createCommentVNode("",!0),k.multiple?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(N.value,a=>(e.openBlock(),e.createElementBlock("option",{key:r(a),value:r(a),selected:""},e.toDisplayString(M(a)),9,Te))),128)):K.value?(e.openBlock(),e.createElementBlock("option",{key:2,value:ee.value,selected:""},e.toDisplayString(M(K.value)),9,Ae)):e.createCommentVNode("",!0)],8,je)],2))}});let z=null;typeof window<"u"&&(z=window.Vue),z&&z.component("Loop8Select",J);const Oe={install:k=>{k.component("Loop8Select",J)}};C.Loop8Select=J,C.default=Oe,Object.defineProperties(C,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
1
|
+
(function(P,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],e):(P=typeof globalThis<"u"?globalThis:P||self,e(P.Loop8Select={},P.Vue))})(this,function(P,e){"use strict";const Ue="",$e="",pe={class:"loop-select-selection"},me={class:"loop-select-single-selection"},he={class:"loop-select-selected-text"},ge={key:1,class:"loop-select-placeholder"},ve={key:0,class:"loop-select-tags-container"},ye=["onClick"],Ve={key:1,class:"loop-select-placeholder"},ke={class:"loop-select-search-container"},we=["onKeydown"],Se={key:0,class:"loop-select-search-spinner"},xe=["tabindex","onKeydown"],je={key:0,class:"loop-select-no-results"},Be=["onClick","onMouseover"],Ee={key:0,class:"loop-select-loading-more"},Te=["multiple","name","required","disabled"],Ae={key:0,value:"",disabled:"",selected:""},Oe=["value"],be=["value"],W=e.defineComponent({name:"Loop8Select",__name:"Loop8Select",props:{modelValue:{type:[Array,String,Number,Object,Boolean],default:null},options:{type:Array,default:()=>[]},placeholder:{type:String,default:"Select an option"},multiple:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},required:{type:Boolean,default:!1},name:{type:String,default:""},loading:{type:Boolean,default:!1},valueKey:{type:String,default:"value"},labelKey:{type:String,default:"text"},ajax:{type:Object,default:null}},emits:["update:modelValue","invalid-option","update:selectedOptions"],setup(V,{emit:Ne}){const t=V,A=Ne,L=e.ref(!1),E=e.ref(""),d=e.ref(-1),Y=e.ref(null),$=e.ref(null),f=e.ref(null),k=e.ref(null),F=e.ref(t.loading),h=e.ref([]),O=e.ref(null),Z=e.ref({}),q=e.ref(1),_=e.ref(!1),b=e.ref(!1),S=e.ref({});let D=!1,I=null;const R=e.computed(()=>!!t.ajax),J=e.computed(()=>{var l;return R.value&&!!((l=t.ajax)!=null&&l.pagination)}),ee=e.computed(()=>{var o;if(!R.value)return!0;const l=((o=t.ajax)==null?void 0:o.minimumInputLength)||0;return E.value.length>=l}),H=e.computed(()=>{const l=R.value?[...t.options,...h.value]:t.options,o=Object.values(S.value);if(o.length>0){const a=o.filter(s=>!l.some(n=>r(n)===r(s)));return[...l,...a]}return l}),N=e.computed(()=>{if(t.multiple){if(!t.modelValue||!Array.isArray(t.modelValue))return[];const l=Array.isArray(t.modelValue)?t.modelValue:[t.modelValue],o=[],a=l.map(s=>{if(s!=null&&S.value[String(s)])return S.value[String(s)];const n=H.value.find(c=>r(c)===s);if(n)return S.value[String(s)]=n,n;const i=h.value.find(c=>r(c)===s);return i?(S.value[String(s)]=i,i):(o.push(s),null)}).filter(s=>s!==null);return o.length>0&&(A("invalid-option",o),e.nextTick(()=>{const s=l.filter(n=>!o.includes(n));A("update:modelValue",s)})),a}else{if(t.modelValue===null||t.modelValue===void 0)return[];const l=t.modelValue;if(l!=null&&S.value[String(l)])return[S.value[String(l)]];const o=H.value.find(s=>r(s)===l);if(o)return S.value[String(l)]=o,[o];const a=h.value.find(s=>r(s)===l);return a?(S.value[String(l)]=a,[a]):(A("invalid-option",l),e.nextTick(()=>{A("update:modelValue",null)}),[])}}),K=e.computed(()=>N.value.length>0?N.value[0]:null),te=e.computed(()=>K.value?r(K.value):null);e.computed(()=>{const l=N.value[0];return l?M(l):""});const B=e.computed(()=>{if(R.value)return ee.value?h.value:[];if(!E.value)return t.options;const l=E.value.toLowerCase();return t.options.filter(o=>M(o).toLowerCase().includes(l))}),r=l=>typeof l=="object"&&l!==null?l[t.valueKey]:l,M=l=>typeof l=="object"&&l!==null?l[t.labelKey]||l[t.valueKey]||"":String(l),ae=l=>{const o=r(l);return t.multiple&&Array.isArray(t.modelValue)?t.modelValue.includes(o):t.modelValue===o},oe=l=>{const o=r(l);if(S.value[String(o)]=l,t.multiple){let a=[];Array.isArray(t.modelValue)?t.modelValue.includes(o)?a=t.modelValue.filter(n=>n!==o):a=[...t.modelValue,o]:a=[o],A("update:modelValue",a);const s=a.map(n=>n===o?l:e.toRaw(S.value[String(n)])||H.value.find(i=>r(i)===n)).filter(Boolean);A("update:selectedOptions",s)}else A("update:modelValue",o),A("update:selectedOptions",[l]),z();E.value="",f.value&&(f.value.value=""),R.value&&(h.value.some(a=>r(a)===o)||(h.value=[...h.value,l])),t.multiple&&e.nextTick(()=>{f.value&&f.value.focus()})},ne=l=>{const o=r(l);if(t.multiple&&Array.isArray(t.modelValue)){const a=t.modelValue.filter(s=>s!==o);A("update:modelValue",a),A("update:selectedOptions",N.value),a.includes(o)||delete S.value[String(o)]}},Pe=()=>{t.disabled||(!L.value&&!I?($.value&&($.value.style.display="flex"),I=requestAnimationFrame(()=>{I=requestAnimationFrame(()=>{I=null,D=!0,L.value=!0,E.value="",le(),e.nextTick(()=>{D=!1,f.value&&!T&&(f.value.value="",f.value.focus()),B.value.length>0?(d.value=0,C()):d.value=-1})})})):(I&&(cancelAnimationFrame(I),I=null,D=!1),z()))},z=()=>{$.value&&($.value.style.display=""),L.value=!1,E.value="",f.value&&(f.value.value=""),le()},le=()=>{q.value=1,_.value=!1,(!J.value||!t.modelValue)&&(h.value=[]),b.value=!1};let G=-1,y=!1,T=!1;const se=()=>{b.value||(G=d.value,y=G>=0,y&&(T=!0),console.log(`Loading more results, page ${q.value+1}`),q.value++,b.value=!0,ie(E.value,!0))},ie=async(l,o=!1)=>{if(!R.value||!ee.value)return Promise.resolve();const a=t.ajax,s=J.value?`${l}_${q.value}`:l;let n=[];if(t.modelValue&&(n=[...N.value]),a.cache&&Z.value[s]){const w=Z.value[s];if(o)h.value=[...h.value,...w.results];else{const v=w.results,u=t.multiple&&Array.isArray(t.modelValue)?t.modelValue:t.modelValue?[t.modelValue]:[],m=n.filter(x=>{const j=r(x);return u.includes(j)&&!v.some(U=>r(U)===j)});h.value=[...m,...v]}return _.value=w.more,b.value=!1,Promise.resolve()}!o&&O.value!==null&&(window.clearTimeout(O.value),O.value=null);const i=a.method||"GET";let c=a.url;a.urlBuilder&&typeof a.urlBuilder=="function"&&(c=a.urlBuilder(l,c),console.log("Using dynamically built URL:",c));const g=a.headers||{"Content-Type":"application/json",Accept:"application/json"};let p={};if(a.params)if(typeof a.params=="function"){const w=J.value?{page:q.value,limit:a.limit||10}:void 0;p=a.params(l,w)}else p={...a.params,query:l};else p=a.urlBuilder?{}:{query:l};if(J.value){const w=a.limit||10;if(!("page"in p)&&!("per_page"in p)){const v=a.pageParam||"page",u=a.limitParam||"per_page";p[v]=q.value,p[u]=w}}return o||(F.value=!0),new Promise(w=>{let v;if(i==="GET"){const u=new URLSearchParams(p).toString(),m=u?`${c}?${u}`:c;console.log("Making request to:",m),v=fetch(m,{method:i,headers:g})}else v=fetch(c,{method:i,headers:g,body:JSON.stringify(p)});v.then(u=>u.json()).then(u=>{let m=[],x=!1;if(a.processResults){const j=a.processResults(u);m=j.results,x=j.more}else Array.isArray(u)?(m=u,x=!1):u.results&&Array.isArray(u.results)?(m=u.results,x=!!u.more):(m=[],x=!1);if(console.log(`Fetched ${m.length} results, more: ${x}`),o)h.value=[...h.value,...m],e.nextTick(()=>{if(y){const j=Math.min(G,B.value.length-1);d.value=j,C(),k.value&&k.value.focus(),setTimeout(()=>{T=!1},100)}});else{const j=t.multiple&&Array.isArray(t.modelValue)?t.modelValue:t.modelValue?[t.modelValue]:[],U=n.filter(Q=>{const fe=r(Q);return j.includes(fe)&&!m.some(Me=>r(Me)===fe)});h.value=[...U,...m]}_.value=x,a.cache&&(Z.value[s]={results:m,more:x}),w()}).catch(u=>{console.error("Error fetching options:",u),o||(h.value=n),_.value=!1,w()}).finally(()=>{F.value=!1,b.value=!1,o&&y&&e.nextTick(()=>{setTimeout(()=>{T=!1},100)})})})},Ce=l=>{y=!1,T=!1,l.stopPropagation()},Le=()=>{y=!1,T=!1},Fe=l=>{var a;E.value;const o=l.target.value;if(E.value=o,y=!1,R.value){if(le(),O.value!==null&&(window.clearTimeout(O.value),O.value=null),!ee.value){h.value=[];return}const s=((a=t.ajax)==null?void 0:a.delay)||300;O.value=window.setTimeout(()=>{const n=document.activeElement===f.value;n&&(y=!1,T=!1),ie(E.value).then(()=>{e.nextTick(()=>{B.value.length>0&&(d.value=0,C());const i=document.activeElement===f.value;(n||i)&&f.value?f.value.focus():y&&B.value.length>0&&k.value&&k.value.focus()})})},s)}},C=()=>{e.nextTick(()=>{if(d.value<0||!$.value||!k.value)return;const l=k.value.querySelector(".loop-select-option-highlighted");if(l){const o=k.value,a=o.clientHeight,s=l,n=s.offsetTop,i=s.clientHeight,c=o.scrollTop,g=n<c,p=n+i>c+a;g?o.scrollTop=n:p&&(o.scrollTop=n+i-a)}})};e.onMounted(()=>{document.addEventListener("click",re),R.value&&t.modelValue&&H.value.length===0&&(t.multiple?Array.isArray(t.modelValue)&&t.modelValue.length>0:t.modelValue!==null&&t.modelValue!==void 0)&&(console.log("Initial value present, fetching option data"),Ke())}),e.onBeforeUnmount(()=>{document.removeEventListener("click",re),O.value!==null&&(window.clearTimeout(O.value),O.value=null)}),e.watch(()=>t.loading,l=>{F.value=l}),e.watch(B,(l,o)=>{if(!D){if(!b.value){l.length>0?(d.value=0,y&&e.nextTick(()=>{k.value&&k.value.focus()})):d.value=-1;return}e.nextTick(()=>{if(y&&G>=0&&l.length>o.length){const a=Math.min(G,l.length-1);d.value=a,C()}})}}),e.watch(E,l=>{f.value&&f.value.value!==l&&(f.value.value=l)}),e.watch(d,()=>{D||d.value>=0&&C()}),e.watch(()=>t.modelValue,l=>{R.value&&l&&(t.multiple&&Array.isArray(l)?l:[l]).forEach(a=>{if(!H.value.find(n=>r(n)===a)&&N.value){const n=N.value.find(i=>r(i)===a);n&&(h.value.find(i=>r(i)===a)||h.value.push(n))}})},{immediate:!0});const re=l=>{Y.value&&!Y.value.contains(l.target)&&L.value&&z()},Ie=()=>{if(!J.value||!_.value||b.value)return;const l=k.value;if(!l)return;const o=l.scrollTop+l.clientHeight,a=20;o>=l.scrollHeight-a&&(console.log("Reached bottom of options list, loading more results..."),se())},ce=()=>{B.value.length!==0&&(y=!0,d.value<B.value.length-1?(d.value++,C(),e.nextTick(()=>{k.value&&k.value.focus()})):_.value&&!b.value&&(y=!0,T=!0,G=d.value,se()))},ue=()=>{B.value.length!==0&&(y=!0,d.value>0&&(d.value--,C(),e.nextTick(()=>{k.value&&k.value.focus()})))},de=()=>{d.value>=0&&B.value[d.value]&&(oe(B.value[d.value]),t.multiple&&e.nextTick(()=>{L.value&&f.value&&f.value.focus()}))};e.watch(L,l=>{D||l&&requestAnimationFrame(()=>{f.value&&!T&&f.value.focus()})}),e.watch(()=>b.value,(l,o)=>{o===!0&&l===!1&&setTimeout(()=>{T&&!y&&(T=!1)},200)});const Ke=async()=>{var a,s;if(!R.value)return;const l=t.multiple&&Array.isArray(t.modelValue)?t.modelValue:[t.modelValue];if(l.length===0)return;const o=l.filter(n=>!(n==null||S.value[String(n)]||H.value.some(i=>r(i)===n)));if(o.length!==0){F.value=!0;try{let n=[];if((a=t.ajax)!=null&&a.initialValueResolver){console.log("Using custom initialValueResolver to fetch option details");const i=o.map(async g=>{const p=await t.ajax.initialValueResolver(g);return p||null});n=(await Promise.all(i)).filter(g=>g!==null)}else if((s=t.ajax)!=null&&s.initialValueUrl){console.log("Using initialValueUrl to fetch option details");const i=t.ajax.initialValueUrl,c=t.ajax.method||"GET";let g={};t.ajax.initialValueParams?typeof t.ajax.initialValueParams=="function"?g=t.ajax.initialValueParams(o):g=t.ajax.initialValueParams:g={ids:o.join(",")};const p=t.ajax.headers||{"Content-Type":"application/json",Accept:"application/json"};let w;if(c==="GET"){const u=new URLSearchParams(g).toString(),m=u?`${i}?${u}`:i;console.log("Fetching initial values from:",m),w=await fetch(m,{method:c,headers:p})}else w=await fetch(i,{method:c,headers:p,body:JSON.stringify(g)});const v=await w.json();t.ajax.processResults?n=t.ajax.processResults(v).results:n=Array.isArray(v)?v:v.results||[]}else{console.log("Using regular ajax URL with id parameter to fetch option details");const i=t.multiple?o:[o[0]];for(const c of i){const g=t.ajax.url,p=t.ajax.method||"GET";let v={[t.ajax.idParam||"id"]:c};t.ajax.params&&(typeof t.ajax.params=="function"?v={...v,...t.ajax.params("")}:v={...v,...t.ajax.params});const u=t.ajax.headers||{"Content-Type":"application/json",Accept:"application/json"};let m;if(p==="GET"){const U=new URLSearchParams(v).toString(),Q=U?`${g}?${U}`:g;console.log("Fetching initial value from:",Q),m=await fetch(Q,{method:p,headers:u})}else m=await fetch(g,{method:p,headers:u,body:JSON.stringify(v)});const x=await m.json();let j=[];t.ajax.processResults?j=t.ajax.processResults(x).results:j=Array.isArray(x)?x:x.results||[],n=[...n,...j]}}console.log("Resolved initial options:",n),n.forEach(i=>{const c=r(i);c!=null&&(S.value[String(c)]=i,h.value.some(g=>r(g)===c)||h.value.push(i))})}catch(n){console.error("Error fetching initial value details:",n)}finally{F.value=!1}}};return(l,o)=>(e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["loop-select-container",{"loop-select-open":L.value,"loop-select-disabled":V.disabled}]),onClick:e.withModifiers(Pe,["stop"]),ref_key:"containerRef",ref:Y},[e.createElementVNode("div",pe,[e.createElementVNode("div",me,[V.multiple?(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[N.value.length?(e.openBlock(),e.createElementBlock("div",ve,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(N.value,a=>(e.openBlock(),e.createElementBlock("div",{key:r(a),class:"loop-select-selected-item"},[e.renderSlot(l.$slots,"selected-option",{option:a,remove:()=>ne(a)},()=>[e.createElementVNode("span",null,e.toDisplayString(M(a)),1),e.createElementVNode("button",{class:"loop-select-remove-item",onClick:e.withModifiers(s=>ne(a),["stop"]),type:"button"}," × ",8,ye)])]))),128))])):(e.openBlock(),e.createElementBlock("span",Ve,e.toDisplayString(V.placeholder),1))],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[K.value?e.renderSlot(l.$slots,"selected-option",{key:0,option:K.value,remove:()=>{}},()=>[e.createElementVNode("span",he,e.toDisplayString(M(K.value)),1)]):(e.openBlock(),e.createElementBlock("span",ge,e.toDisplayString(V.placeholder),1))],64))]),o[1]||(o[1]=e.createElementVNode("div",{class:"loop-select-arrow"},[e.createElementVNode("span",null,"▼")],-1))]),e.createElementVNode("div",{class:"loop-select-dropdown",ref_key:"dropdownRef",ref:$},[e.createElementVNode("div",ke,[e.createElementVNode("input",{ref_key:"searchInputRef",ref:f,class:"loop-select-search",type:"text",onInput:Fe,onKeydown:[o[0]||(o[0]=e.withModifiers(()=>{},["stop"])),e.withKeys(e.withModifiers(ce,["prevent"]),["down"]),e.withKeys(e.withModifiers(ue,["prevent"]),["up"]),e.withKeys(e.withModifiers(de,["prevent"]),["enter"]),e.withKeys(e.withModifiers(z,["prevent"]),["esc"])],onClick:e.withModifiers(Ce,["stop"]),onFocus:Le,placeholder:"Search..."},null,40,we),V.loading||F.value?(e.openBlock(),e.createElementBlock("div",Se,o[2]||(o[2]=[e.createElementVNode("div",{class:"lds-dual-ring"},null,-1)]))):e.createCommentVNode("",!0)]),e.createElementVNode("ul",{class:"loop-select-options",onScroll:Ie,ref_key:"optionsListRef",ref:k,tabindex:e.unref(y)?0:-1,onKeydown:[e.withKeys(e.withModifiers(ce,["prevent"]),["down"]),e.withKeys(e.withModifiers(ue,["prevent"]),["up"]),e.withKeys(e.withModifiers(de,["prevent"]),["enter"]),e.withKeys(e.withModifiers(z,["prevent"]),["esc"])]},[B.value.length===0&&!V.loading&&!F.value?(e.openBlock(),e.createElementBlock("li",je,"No results found")):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(B.value,(a,s)=>(e.openBlock(),e.createElementBlock("li",{key:r(a),class:e.normalizeClass(["loop-select-option",{"loop-select-option-selected":ae(a),"loop-select-option-highlighted":s===d.value}]),onClick:e.withModifiers(n=>oe(a),["stop"]),onMouseover:()=>{d.value=s,C(),e.isRef(y)?y.value=!1:y=!1}},[e.renderSlot(l.$slots,"option",{option:a,selected:ae(a),highlighted:s===d.value,index:s},()=>[e.createTextVNode(e.toDisplayString(M(a)),1)])],42,Be))),128)),b.value?(e.openBlock(),e.createElementBlock("li",Ee,[e.renderSlot(l.$slots,"loading-more",{},()=>[o[3]||(o[3]=e.createElementVNode("div",{class:"lds-dual-ring"},null,-1))])])):e.createCommentVNode("",!0)],64))],40,xe)],512),e.createElementVNode("select",{multiple:V.multiple,name:V.name,required:V.required,disabled:V.disabled,tabindex:"-1",class:"loop-select-hidden","aria-hidden":"true"},[!V.multiple&&!te.value?(e.openBlock(),e.createElementBlock("option",Ae,e.toDisplayString(V.placeholder),1)):e.createCommentVNode("",!0),V.multiple?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(N.value,a=>(e.openBlock(),e.createElementBlock("option",{key:r(a),value:r(a),selected:""},e.toDisplayString(M(a)),9,Oe))),128)):K.value?(e.openBlock(),e.createElementBlock("option",{key:2,value:te.value,selected:""},e.toDisplayString(M(K.value)),9,be)):e.createCommentVNode("",!0)],8,Te)],2))}});let X=null;typeof window<"u"&&(X=window.Vue),X&&X.component("Loop8Select",W);const Re={install:V=>{V.component("Loop8Select",W)}};P.Loop8Select=W,P.default=Re,Object.defineProperties(P,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/dist/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.loop-select-container{position:relative;width:100%;border:1px solid #ccc;border-radius:4px;box-sizing:border-box;cursor:pointer}.loop-select-disabled{opacity:.6;cursor:not-allowed}.loop-select-selection{min-height:36px;padding:4px 8px;display:flex;align-items:center;flex-wrap:nowrap}.loop-select-single-selection{flex:1;display:flex;align-items:center;overflow:hidden;min-width:0}.loop-select-tags-container{display:flex;flex-wrap:wrap;gap:4px;max-width:100%;overflow:hidden;align-items:center}.loop-select-selected-item{display:inline-flex;align-items:center;background-color:#e4e4e4;border-radius:3px;padding:2px 6px;margin-right:4px;margin-bottom:2px;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.loop-select-remove-item{background:none;border:none;color:#666;cursor:pointer;margin-left:4px;padding:0;line-height:1;font-size:16px;flex-shrink:0}.loop-select-remove-item:hover{color:#333}.loop-select-search-container{padding:6px 8px;border-bottom:1px solid #eee;position:relative;display:flex;align-items:center}.loop-select-search{border:1px solid #ccc;border-radius:3px;outline:none;background:transparent;width:100%;padding:6px 8px;margin:0;font-size:14px;box-sizing:border-box}.loop-select-search-spinner{position:absolute;right:14px;top:50%;transform:translateY(-50%);pointer-events:none;display:flex;align-items:center;justify-content:center;height:20px;line-height:0}.loop-select-search-spinner .lds-dual-ring{width:18px;height:18px;line-height:0;vertical-align:middle}.loop-select-search-spinner .lds-dual-ring:after{width:14px;height:14px;margin:2px;border-width:1.5px;vertical-align:middle}.loop-select-placeholder{color:#999;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.loop-select-selected-text{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.loop-select-arrow{display:flex;align-items:center;margin-left:8px;flex-shrink:0}.loop-select-dropdown{position:absolute;width:100%;max-height:250px;background:white;border:1px solid #ccc;border-top:none;border-radius:0 0 4px 4px;z-index:1000;box-shadow:0 2px 4px #0000001a;box-sizing:border-box;display:
|
|
1
|
+
.loop-select-container{position:relative;width:100%;border:1px solid #ccc;border-radius:4px;box-sizing:border-box;cursor:pointer}.loop-select-disabled{opacity:.6;cursor:not-allowed}.loop-select-selection{min-height:36px;padding:4px 8px;display:flex;align-items:center;flex-wrap:nowrap}.loop-select-single-selection{flex:1;display:flex;align-items:center;overflow:hidden;min-width:0}.loop-select-tags-container{display:flex;flex-wrap:wrap;gap:4px;max-width:100%;overflow:hidden;align-items:center}.loop-select-selected-item{display:inline-flex;align-items:center;background-color:#e4e4e4;border-radius:3px;padding:2px 6px;margin-right:4px;margin-bottom:2px;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.loop-select-remove-item{background:none;border:none;color:#666;cursor:pointer;margin-left:4px;padding:0;line-height:1;font-size:16px;flex-shrink:0}.loop-select-remove-item:hover{color:#333}.loop-select-search-container{padding:6px 8px;border-bottom:1px solid #eee;position:relative;display:flex;align-items:center}.loop-select-search{border:1px solid #ccc;border-radius:3px;outline:none;background:transparent;width:100%;padding:6px 8px;margin:0;font-size:14px;box-sizing:border-box}.loop-select-search-spinner{position:absolute;right:14px;top:50%;transform:translateY(-50%);pointer-events:none;display:flex;align-items:center;justify-content:center;height:20px;line-height:0}.loop-select-search-spinner .lds-dual-ring{width:18px;height:18px;line-height:0;vertical-align:middle}.loop-select-search-spinner .lds-dual-ring:after{width:14px;height:14px;margin:2px;border-width:1.5px;vertical-align:middle}.loop-select-placeholder{color:#999;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.loop-select-selected-text{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.loop-select-arrow{display:flex;align-items:center;margin-left:8px;flex-shrink:0}.loop-select-dropdown{position:absolute;width:100%;max-height:250px;background:white;border:1px solid #ccc;border-top:none;border-radius:0 0 4px 4px;z-index:1000;box-shadow:0 2px 4px #0000001a;box-sizing:border-box;display:none;flex-direction:column}.loop-select-open .loop-select-dropdown{display:flex}.loop-select-options{list-style:none;margin:0;padding:0;overflow-y:auto;max-height:200px;flex:1;outline:none}.loop-select-options:focus{box-shadow:inset 0 0 2px #0003}.loop-select-option{padding:8px 12px;cursor:pointer}.loop-select-option:hover{background-color:#f5f5f5}.loop-select-option-selected{background-color:#e6f7ff}.loop-select-option-highlighted{background-color:#f0f0f0}.loop-select-loading,.loop-select-no-results{padding:8px 12px;text-align:center;color:#999}.loop-select-loading-more{padding:8px 12px;text-align:center;color:#999;font-style:italic;font-size:.9em;background-color:#f9f9f9;display:flex;justify-content:center;align-items:center;line-height:0}.loop-select-loading-more .lds-dual-ring{width:24px;height:24px;vertical-align:middle;line-height:0}.loop-select-loading-more .lds-dual-ring:after{width:18px;height:18px;margin:3px;border-width:2px;vertical-align:middle}.loop-select-hidden{position:absolute;width:0;height:0;overflow:hidden;clip:rect(0 0 0 0);margin:-1px;padding:0;border:0}.lds-dual-ring{display:inline-block;width:24px;height:24px}.lds-dual-ring:after{content:" ";display:block;width:18px;height:18px;margin:3px;border-radius:50%;border:2px solid #666;border-color:#666 transparent #666 transparent;animation:lds-dual-ring 1.2s linear infinite}@keyframes lds-dual-ring{0%{transform:rotate(0)}to{transform:rotate(360deg)}}
|
package/package.json
CHANGED
|
@@ -147,10 +147,14 @@
|
|
|
147
147
|
z-index: 1000;
|
|
148
148
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
|
|
149
149
|
box-sizing: border-box;
|
|
150
|
-
display:
|
|
150
|
+
display: none;
|
|
151
151
|
flex-direction: column;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
.loop-select-open .loop-select-dropdown {
|
|
155
|
+
display: flex;
|
|
156
|
+
}
|
|
157
|
+
|
|
154
158
|
.loop-select-options {
|
|
155
159
|
list-style: none;
|
|
156
160
|
margin: 0;
|