golden-logic-ui 1.3.10 → 1.3.11
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.
|
@@ -1,27 +1,30 @@
|
|
|
1
|
-
import { ref as
|
|
1
|
+
import { ref as v, shallowRef as Y, onMounted as ve, onBeforeUnmount as me, watch as I, createElementBlock as c, openBlock as f, Fragment as Z, createCommentVNode as h, normalizeClass as O, createElementVNode as s, toDisplayString as w, withDirectives as F, withModifiers as ee, vShow as te, vModelText as ge, renderList as he, nextTick as pe } from "vue";
|
|
2
2
|
const ye = { class: "font-bold ptext-lg dark:text-white" }, xe = { class: "mt-3 mb-4" }, we = {
|
|
3
3
|
key: 0,
|
|
4
4
|
class: "bg-blue-100 text-blue-800 text-sm font-medium mb-2 mt-2 me-2 px-2.5 py-0.5 rounded-sm dark:bg-blue-900 dark:text-blue-300"
|
|
5
5
|
}, be = ["name", "id", "value"], ke = {
|
|
6
6
|
key: 0,
|
|
7
7
|
class: "dropdown"
|
|
8
|
-
}, Se = { class: "relative focus:ring-blue-500 focus:border-blue-500 dark:border-gray-600 dark:focus:ring-blue-500 dark:focus:border-blue-500" }, _e = { class: "relative showOptions" }, Ce = ["value", "placeholder"
|
|
8
|
+
}, Se = { class: "relative focus:ring-blue-500 focus:border-blue-500 dark:border-gray-600 dark:focus:ring-blue-500 dark:focus:border-blue-500" }, _e = { class: "relative showOptions" }, Ce = ["value", "placeholder", "disabled"], De = {
|
|
9
9
|
key: 0,
|
|
10
10
|
class: "border-b border-gray-200 dark:border-gray-700"
|
|
11
|
-
},
|
|
11
|
+
}, Oe = { class: "relative" }, Ee = ["id", "placeholder"], Be = { class: "flex items-center py-2 pr-4" }, $e = ["onClick", "onMousedown", "id"], Le = { class: "flex justify-between items-center py-2" }, Me = { class: "min-w-0" }, Ie = ["innerHTML"], je = {
|
|
12
|
+
key: 0,
|
|
13
|
+
class: "ms-2 text-gray-500 dark:text-gray-400"
|
|
14
|
+
}, Te = {
|
|
12
15
|
key: 0,
|
|
13
16
|
class: "flex items-center shrink-0 w-4 h-4 text-green-500 ltr:right-2 rtl:left-2 dark:text-green-400",
|
|
14
17
|
"aria-hidden": "true",
|
|
15
18
|
xmlns: "http://www.w3.org/2000/svg",
|
|
16
19
|
fill: "none",
|
|
17
20
|
viewBox: "0 0 16 12"
|
|
18
|
-
},
|
|
21
|
+
}, Ue = {
|
|
19
22
|
key: 2,
|
|
20
23
|
class: "p-2 text-center text-gray-500"
|
|
21
|
-
},
|
|
24
|
+
}, Ae = {
|
|
22
25
|
key: 3,
|
|
23
26
|
class: "p-2 text-gray-500"
|
|
24
|
-
},
|
|
27
|
+
}, qe = { class: "block mt-1 text-sm font-normal leading-5 text-red-500" }, Ve = { class: "block mt-1 text-sm font-normal leading-5 text-gray-500" }, Pe = {
|
|
25
28
|
__name: "GlDropdown",
|
|
26
29
|
props: {
|
|
27
30
|
modelValue: {
|
|
@@ -106,46 +109,60 @@ const ye = { class: "font-bold ptext-lg dark:text-white" }, xe = { class: "mt-3
|
|
|
106
109
|
custom_option_label: {
|
|
107
110
|
type: String,
|
|
108
111
|
default: "Use:"
|
|
112
|
+
},
|
|
113
|
+
/** Extra classes on the field itself, e.g. to square a corner when it sits against another field. */
|
|
114
|
+
input_class: {
|
|
115
|
+
type: String,
|
|
116
|
+
default: ""
|
|
117
|
+
},
|
|
118
|
+
/** Extra classes on the open list, e.g. a minimum width wider than a narrow field. */
|
|
119
|
+
options_class: {
|
|
120
|
+
type: String,
|
|
121
|
+
default: ""
|
|
122
|
+
},
|
|
123
|
+
disabled: {
|
|
124
|
+
type: Boolean,
|
|
125
|
+
default: !1
|
|
109
126
|
}
|
|
110
127
|
},
|
|
111
128
|
emits: ["update:modelValue", "selected", "selectionChanged"],
|
|
112
|
-
setup(
|
|
113
|
-
const
|
|
114
|
-
let
|
|
129
|
+
setup(o, { emit: le }) {
|
|
130
|
+
const r = o, k = le, a = v({}), T = v(!1), y = v(0), x = v(!1), m = v(""), g = v(""), $ = v(!1), S = v(1), _ = v(null), L = v(1), i = Y([]), E = v(!1), j = Y([]), U = v([]), ne = v(null), H = v(null);
|
|
131
|
+
let B = !1, p = null, A = 0, C = null;
|
|
115
132
|
const z = (e) => e?.name === "CanceledError" || e?.name === "AbortError" || typeof axios < "u" && axios.isCancel?.(e), q = async (e = "down") => {
|
|
116
|
-
if ($.value || !
|
|
133
|
+
if ($.value || !r.api_url) return;
|
|
117
134
|
p && p.abort(), p = new AbortController();
|
|
118
135
|
const t = ++A;
|
|
119
136
|
$.value = !0;
|
|
120
137
|
try {
|
|
121
|
-
const l = e === "up" ? Math.max(S.value - 1, L.value) : S.value, { data: n } = await axios.get(
|
|
138
|
+
const l = e === "up" ? Math.max(S.value - 1, L.value) : S.value, { data: n } = await axios.get(r.api_url, {
|
|
122
139
|
params: { search: m.value, page: l, per_page: 20 },
|
|
123
140
|
signal: p.signal
|
|
124
141
|
});
|
|
125
|
-
if (
|
|
142
|
+
if (B || t !== A) return;
|
|
126
143
|
if (!n || !n.data) {
|
|
127
|
-
i.value = [],
|
|
144
|
+
i.value = [], E.value = !1;
|
|
128
145
|
return;
|
|
129
146
|
}
|
|
130
147
|
const u = W(n.data);
|
|
131
148
|
if (e === "down") {
|
|
132
149
|
const d = i.value.length ? i.value.concat(u) : u, D = a.value;
|
|
133
|
-
|
|
150
|
+
b(D) && D.id !== void 0 && D.name && !d.some((M) => String(M.id) === String(D.id)) && d.unshift(D), i.value = d, S.value++, _.value = n.last_page, E.value = !0;
|
|
134
151
|
}
|
|
135
152
|
_.value || (_.value = n.last_page), L.value || (L.value = 1);
|
|
136
153
|
} catch (l) {
|
|
137
154
|
if (z(l)) return;
|
|
138
155
|
console.error("Error fetching data:", l);
|
|
139
156
|
} finally {
|
|
140
|
-
!
|
|
157
|
+
!B && t === A && ($.value = !1, p = null);
|
|
141
158
|
}
|
|
142
159
|
}, ae = async (e) => {
|
|
143
|
-
if (!
|
|
160
|
+
if (!r.api_url || e === null || e === void 0 || e === "") return null;
|
|
144
161
|
try {
|
|
145
|
-
const { data: t } = await axios.get(
|
|
162
|
+
const { data: t } = await axios.get(r.api_url, {
|
|
146
163
|
params: { search: e, per_page: 20 }
|
|
147
164
|
});
|
|
148
|
-
if (
|
|
165
|
+
if (B) return null;
|
|
149
166
|
const l = t?.data;
|
|
150
167
|
if (!l || !l.length) return null;
|
|
151
168
|
const n = String(e);
|
|
@@ -167,56 +184,56 @@ const ye = { class: "font-bold ptext-lg dark:text-white" }, xe = { class: "mt-3
|
|
|
167
184
|
return;
|
|
168
185
|
}
|
|
169
186
|
const u = await ae(t);
|
|
170
|
-
|
|
187
|
+
B || (u ? (a.value = u, i.value.some((d) => String(d.id) === String(u.id)) || (i.value = [u, ...i.value])) : r.allow_custom ? a.value = { id: t, name: t } : a.value = { id: t, name: "" });
|
|
171
188
|
}, re = (e) => {
|
|
172
189
|
const t = e.target;
|
|
173
190
|
t && t.scrollHeight - t.clientHeight <= t.scrollTop + 10 && S.value <= _.value && q("down");
|
|
174
191
|
}, K = (e) => {
|
|
175
|
-
e.target && (document.activeElement.classList.contains("showOptions" + g.value) ? x.value || V() : e.target.id !=
|
|
192
|
+
e.target && (document.activeElement.classList.contains("showOptions" + g.value) ? x.value || V() : e.target.id != r.field_name + "search" + g.value && e.target.id != r.field_name && !e.target.classList.contains("showOptions" + g.value) && (R(), y.value = 0, x.value = !1));
|
|
176
193
|
}, V = () => {
|
|
177
|
-
if (!
|
|
194
|
+
if (!(r.show || r.disabled)) {
|
|
178
195
|
if (x.value) {
|
|
179
196
|
x.value = !1;
|
|
180
197
|
return;
|
|
181
198
|
}
|
|
182
|
-
m.value = "", x.value = !0,
|
|
199
|
+
m.value = "", x.value = !0, r.api_url && (!E.value || i.value.length === 0) && (S.value = 1, _.value = null, i.value = [], E.value = !1, q("down")), pe(() => {
|
|
183
200
|
const e = document.getElementById(
|
|
184
|
-
`${
|
|
201
|
+
`${r.field_name}search${g.value}`
|
|
185
202
|
);
|
|
186
203
|
e && e.focus();
|
|
187
204
|
});
|
|
188
205
|
}
|
|
189
206
|
}, N = () => {
|
|
190
207
|
const e = (t) => {
|
|
191
|
-
if (
|
|
208
|
+
if (r.allow_custom && t) {
|
|
192
209
|
const l = typeof t == "object" ? t.id : t;
|
|
193
210
|
return { id: l, name: l };
|
|
194
211
|
}
|
|
195
212
|
return {};
|
|
196
213
|
};
|
|
197
|
-
return
|
|
214
|
+
return b(a.value) ? typeof a.value == "object" ? i.value.find(
|
|
198
215
|
(t) => String(t.id) === String(a.value.id)
|
|
199
216
|
) || e(a.value) : i.value.find(
|
|
200
217
|
(t) => String(t.id) === String(a.value)
|
|
201
|
-
) || e(a.value) :
|
|
202
|
-
(t) => String(t.id) === String(
|
|
203
|
-
) || e(
|
|
204
|
-
(t) => String(t.id) === String(
|
|
205
|
-
) || e(
|
|
218
|
+
) || e(a.value) : r.modelValue ? typeof r.modelValue == "object" ? i.value.find(
|
|
219
|
+
(t) => String(t.id) === String(r.modelValue.id)
|
|
220
|
+
) || e(r.modelValue) : i.value.find(
|
|
221
|
+
(t) => String(t.id) === String(r.modelValue)
|
|
222
|
+
) || e(r.modelValue) : {};
|
|
206
223
|
};
|
|
207
224
|
ve(() => {
|
|
208
|
-
g.value = ue(),
|
|
225
|
+
g.value = ue(), r.show || (document.body.addEventListener("click", G), document.addEventListener("focusin", K));
|
|
209
226
|
}), me(() => {
|
|
210
|
-
|
|
227
|
+
B = !0, p && (p.abort(), p = null), C && (clearTimeout(C), C = null), document.body.removeEventListener("click", G), document.removeEventListener("focusin", K);
|
|
211
228
|
});
|
|
212
229
|
function ie() {
|
|
213
|
-
const e =
|
|
230
|
+
const e = j.value, t = r.maxItem, l = m.value;
|
|
214
231
|
if (!l)
|
|
215
232
|
return e.length > t ? e.slice(0, t) : e;
|
|
216
233
|
const n = l.toLowerCase(), u = [];
|
|
217
234
|
for (let d = 0, D = e.length; d < D && u.length < t; d++) {
|
|
218
|
-
const
|
|
219
|
-
String(
|
|
235
|
+
const M = e[d];
|
|
236
|
+
(String(M.name).toLowerCase().includes(n) || String(M.keywords ?? "").toLowerCase().includes(n)) && u.push(M);
|
|
220
237
|
}
|
|
221
238
|
return u;
|
|
222
239
|
}
|
|
@@ -240,11 +257,11 @@ const ye = { class: "font-bold ptext-lg dark:text-white" }, xe = { class: "mt-3
|
|
|
240
257
|
return e = Math.floor(e / 16), (t === "x" ? l : l & 3 | 8).toString(16);
|
|
241
258
|
});
|
|
242
259
|
}
|
|
243
|
-
function
|
|
260
|
+
function b(e) {
|
|
244
261
|
return e && typeof e == "object" && Object.keys(e).length > 0;
|
|
245
262
|
}
|
|
246
263
|
function G(e) {
|
|
247
|
-
e.target.id !=
|
|
264
|
+
e.target.id != r.field_name + "search" + g.value && e.target.id != r.field_name && !e.target.classList.contains("showOptions" + g.value) && (R(), y.value = 0, x.value = !1);
|
|
248
265
|
}
|
|
249
266
|
function J(e) {
|
|
250
267
|
const t = `${e}${g.value}`, l = document.getElementById(t), n = H.value;
|
|
@@ -269,7 +286,7 @@ const ye = { class: "font-bold ptext-lg dark:text-white" }, xe = { class: "mt-3
|
|
|
269
286
|
return t;
|
|
270
287
|
}
|
|
271
288
|
function ce() {
|
|
272
|
-
const e =
|
|
289
|
+
const e = r.options, t = new Array(e.length);
|
|
273
290
|
for (let l = 0; l < e.length; l++) {
|
|
274
291
|
const n = e[l];
|
|
275
292
|
t[l] = typeof n == "object" ? n : { id: n, name: n };
|
|
@@ -278,104 +295,107 @@ const ye = { class: "font-bold ptext-lg dark:text-white" }, xe = { class: "mt-3
|
|
|
278
295
|
}
|
|
279
296
|
function X() {
|
|
280
297
|
const e = m.value, t = { id: e, name: e }, l = String(e);
|
|
281
|
-
U.value.some((n) => String(n.id) === l) || U.value.push(t), i.value.some((n) => String(n.id) === l) || (i.value = [...i.value, t],
|
|
298
|
+
U.value.some((n) => String(n.id) === l) || U.value.push(t), i.value.some((n) => String(n.id) === l) || (i.value = [...i.value, t], j.value = [...j.value, t]), P(t);
|
|
282
299
|
}
|
|
283
300
|
function P(e) {
|
|
284
301
|
T.value = !0, a.value = e, x.value = !1, k("update:modelValue", a.value.id), k("selected", a.value), k("selectionChanged", a.value);
|
|
285
302
|
}
|
|
286
303
|
function fe() {
|
|
287
|
-
|
|
304
|
+
r.show || (a.value = {}, m.value = "", k("update:modelValue", ""), k("selected", a.value), k("selectionChanged", a.value), V());
|
|
288
305
|
}
|
|
289
306
|
function R() {
|
|
290
307
|
(!a.value || !a.value.id) && (a.value = {}, m.value = "");
|
|
291
308
|
}
|
|
292
|
-
return
|
|
293
|
-
if (!
|
|
309
|
+
return I(m, () => {
|
|
310
|
+
if (!r.api_url) {
|
|
294
311
|
i.value = ie(), i.value.length === 0 && (a.value = {});
|
|
295
312
|
return;
|
|
296
313
|
}
|
|
297
314
|
C && clearTimeout(C), C = setTimeout(() => {
|
|
298
|
-
C = null, !
|
|
315
|
+
C = null, !B && (S.value = 1, _.value = null, L.value = 1, i.value = [], E.value = !1, q("down"));
|
|
299
316
|
}, 250);
|
|
300
|
-
}),
|
|
301
|
-
|
|
302
|
-
}),
|
|
303
|
-
() =>
|
|
317
|
+
}), I(a, (e) => {
|
|
318
|
+
b(e) && e.id !== r.modelValue && k("update:modelValue", e.id);
|
|
319
|
+
}), I(
|
|
320
|
+
() => r.api_url,
|
|
304
321
|
() => {
|
|
305
|
-
p && (p.abort(), p = null), S.value = 1, _.value = null, L.value = 1, i.value = [],
|
|
322
|
+
p && (p.abort(), p = null), S.value = 1, _.value = null, L.value = 1, i.value = [], E.value = !1;
|
|
306
323
|
},
|
|
307
324
|
{ immediate: !0 }
|
|
308
|
-
),
|
|
309
|
-
() =>
|
|
325
|
+
), I(
|
|
326
|
+
() => r.modelValue,
|
|
310
327
|
async (e) => {
|
|
311
328
|
if (!e) {
|
|
312
329
|
a.value = {};
|
|
313
330
|
return;
|
|
314
331
|
}
|
|
315
332
|
const t = typeof e == "object" ? e.id : e;
|
|
316
|
-
|
|
333
|
+
b(a.value) && String(a.value.id) !== String(t) && (a.value = {}, T.value = !1), r.api_url ? T.value ? a.value = N() : await oe(e) : a.value = N();
|
|
317
334
|
},
|
|
318
335
|
{ immediate: !0 }
|
|
319
|
-
),
|
|
320
|
-
() =>
|
|
336
|
+
), I(
|
|
337
|
+
() => r.options,
|
|
321
338
|
() => {
|
|
322
|
-
if (!
|
|
339
|
+
if (!r.api_url) {
|
|
323
340
|
const e = ce(), t = new Set(e.map((n) => String(n.id))), l = e;
|
|
324
341
|
for (const n of U.value) {
|
|
325
342
|
const u = String(n.id);
|
|
326
343
|
t.has(u) || (l.push(n), t.add(u));
|
|
327
344
|
}
|
|
328
|
-
|
|
345
|
+
j.value = l, i.value = l, a.value = N();
|
|
329
346
|
}
|
|
330
347
|
},
|
|
331
348
|
// deep so the list still updates when options load late by mutating the SAME
|
|
332
349
|
// array in place (e.g. column.options.push(...)) — a reference-only watch
|
|
333
350
|
// would miss that and leave the dropdown list empty.
|
|
334
351
|
{ immediate: !0, deep: !0 }
|
|
335
|
-
), (e, t) => (
|
|
336
|
-
|
|
352
|
+
), (e, t) => (f(), c(Z, null, [
|
|
353
|
+
o.show ? (f(), c("div", {
|
|
337
354
|
key: 0,
|
|
338
|
-
class:
|
|
355
|
+
class: O(o.field_name)
|
|
339
356
|
}, [
|
|
340
|
-
s("h3", ye,
|
|
357
|
+
s("h3", ye, w(o.label_name), 1),
|
|
341
358
|
s("p", xe, [
|
|
342
|
-
|
|
359
|
+
b(a.value) ? (f(), c("span", we, w(a.value?.name), 1)) : h("", !0)
|
|
343
360
|
]),
|
|
344
361
|
t[6] || (t[6] = s("hr", { class: "opacity-100! bg-gray-200 border-0 dark:bg-gray-700" }, null, -1))
|
|
345
362
|
], 2)) : h("", !0),
|
|
346
|
-
|
|
363
|
+
o.show ? h("", !0) : (f(), c("div", {
|
|
347
364
|
key: 1,
|
|
348
|
-
class:
|
|
365
|
+
class: O(o.field_name)
|
|
349
366
|
}, [
|
|
350
367
|
s("input", {
|
|
351
368
|
type: "hidden",
|
|
352
|
-
name:
|
|
353
|
-
id:
|
|
369
|
+
name: o.field_name,
|
|
370
|
+
id: o.field_name,
|
|
354
371
|
value: a.value?.id
|
|
355
372
|
}, null, 8, be),
|
|
356
|
-
|
|
357
|
-
|
|
373
|
+
o.options ? (f(), c("div", ke, [
|
|
374
|
+
o.label_name ? (f(), c("label", {
|
|
358
375
|
key: 0,
|
|
359
|
-
class:
|
|
360
|
-
"gl-label-form":
|
|
361
|
-
"gl-label-form-invalid":
|
|
362
|
-
required:
|
|
376
|
+
class: O({
|
|
377
|
+
"gl-label-form": o.error_message == "",
|
|
378
|
+
"gl-label-form-invalid": o.error_message !== "",
|
|
379
|
+
required: o.is_required
|
|
363
380
|
})
|
|
364
|
-
},
|
|
381
|
+
}, w(o.label_name), 3)) : h("", !0),
|
|
365
382
|
s("div", Se, [
|
|
366
383
|
s("div", _e, [
|
|
367
384
|
s("input", {
|
|
368
385
|
ref_key: "myDivDropDown",
|
|
369
386
|
ref: ne,
|
|
370
|
-
class:
|
|
371
|
-
"gl-input-form":
|
|
372
|
-
"gl-input-form-invalid":
|
|
387
|
+
class: O([{
|
|
388
|
+
"gl-input-form": o.error_message == "",
|
|
389
|
+
"gl-input-form-invalid": o.error_message !== "",
|
|
373
390
|
[`showOptions${g.value}`]: !0,
|
|
374
|
-
"pr-14!":
|
|
375
|
-
"pr-8!": !(
|
|
391
|
+
"pr-14!": b(a.value) && o.has_cancel,
|
|
392
|
+
"pr-8!": !(b(a.value) && o.has_cancel),
|
|
393
|
+
"opacity-70 cursor-not-allowed": o.disabled,
|
|
394
|
+
[o.input_class]: o.input_class !== ""
|
|
376
395
|
}, "truncate showOptions1"]),
|
|
377
396
|
value: a.value?.name,
|
|
378
|
-
placeholder:
|
|
397
|
+
placeholder: o.placeholder,
|
|
398
|
+
disabled: o.disabled,
|
|
379
399
|
autocomplete: "off",
|
|
380
400
|
readonly: ""
|
|
381
401
|
}, null, 10, Ce),
|
|
@@ -400,15 +420,15 @@ const ye = { class: "font-bold ptext-lg dark:text-white" }, xe = { class: "mt-3
|
|
|
400
420
|
})
|
|
401
421
|
], -1)
|
|
402
422
|
]), 512), [
|
|
403
|
-
[te,
|
|
423
|
+
[te, b(a.value) && o.has_cancel]
|
|
404
424
|
]),
|
|
405
425
|
s("i", {
|
|
406
426
|
onClick: t[1] || (t[1] = ee((l) => V(), ["stop"])),
|
|
407
427
|
class: "absolute text-xl text-gray-500 cursor-pointer ltr:right-2 rtl:left-2 hover:text-gray-700 dark:hover:text-gray-700 showOptions",
|
|
408
428
|
style: { top: "14px" }
|
|
409
429
|
}, [
|
|
410
|
-
(
|
|
411
|
-
class:
|
|
430
|
+
(f(), c("svg", {
|
|
431
|
+
class: O([x.value ? "" : "rotate-180", "w-3 h-3 shrink-0"]),
|
|
412
432
|
"aria-hidden": "true",
|
|
413
433
|
xmlns: "http://www.w3.org/2000/svg",
|
|
414
434
|
fill: "none",
|
|
@@ -423,24 +443,26 @@ const ye = { class: "font-bold ptext-lg dark:text-white" }, xe = { class: "mt-3
|
|
|
423
443
|
}, null, -1)
|
|
424
444
|
]), 2))
|
|
425
445
|
]),
|
|
426
|
-
F(s("div",
|
|
427
|
-
|
|
446
|
+
F(s("div", {
|
|
447
|
+
class: O(["text-gray-700 bg-white border dark:border-gray-700 dark:bg-gray-800 dark:text-gray-200 absolute w-full z-999999999 rounded-md mt-1 pt-1", o.options_class])
|
|
448
|
+
}, [
|
|
449
|
+
o.hide_search ? h("", !0) : (f(), c("div", De, [
|
|
428
450
|
t[10] || (t[10] = s("label", {
|
|
429
451
|
for: "default-search",
|
|
430
452
|
class: "mb-2 text-sm font-medium text-gray-900 sr-only dark:text-white"
|
|
431
453
|
}, "Search", -1)),
|
|
432
|
-
s("div",
|
|
454
|
+
s("div", Oe, [
|
|
433
455
|
t[9] || (t[9] = s("div", { class: "absolute inset-y-0 flex items-center pointer-events-none start-0 ps-3" }, null, -1)),
|
|
434
456
|
F(s("input", {
|
|
435
457
|
type: "search",
|
|
436
458
|
"onUpdate:modelValue": t[2] || (t[2] = (l) => m.value = l),
|
|
437
|
-
id: `${
|
|
459
|
+
id: `${o.field_name}search${g.value}`,
|
|
438
460
|
onKeydown: se,
|
|
439
461
|
onBlur: t[3] || (t[3] = (l) => R()),
|
|
440
462
|
autocomplete: "off",
|
|
441
463
|
class: "block w-full p-2 text-sm text-gray-900 outline-hidden dark:bg-gray-800 dark:text-white",
|
|
442
|
-
placeholder:
|
|
443
|
-
}, null, 40,
|
|
464
|
+
placeholder: o.search_input_placeholder
|
|
465
|
+
}, null, 40, Ee), [
|
|
444
466
|
[ge, m.value]
|
|
445
467
|
])
|
|
446
468
|
])
|
|
@@ -451,18 +473,18 @@ const ye = { class: "font-bold ptext-lg dark:text-white" }, xe = { class: "mt-3
|
|
|
451
473
|
ref_key: "dropdownRef",
|
|
452
474
|
ref: H
|
|
453
475
|
}, [
|
|
454
|
-
|
|
476
|
+
o.allow_custom && m.value && !i.value.find((l) => String(l.name) === String(m.value)) ? (f(), c("div", {
|
|
455
477
|
key: 0,
|
|
456
478
|
class: "relative px-2 py-0.5 text-xs leading-4 text-gray-700 no-underline cursor-pointer dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-700 dark:hover:text-white hover:rounded-sm",
|
|
457
479
|
onClick: t[4] || (t[4] = (l) => X()),
|
|
458
480
|
onMousedown: t[5] || (t[5] = (l) => X())
|
|
459
481
|
}, [
|
|
460
|
-
s("div",
|
|
461
|
-
s("span", null,
|
|
482
|
+
s("div", Be, [
|
|
483
|
+
s("span", null, w(o.custom_option_label) + ' "' + w(m.value) + '"', 1)
|
|
462
484
|
])
|
|
463
485
|
], 32)) : h("", !0),
|
|
464
|
-
i.value.length ? (
|
|
465
|
-
class:
|
|
486
|
+
i.value.length ? (f(!0), c(Z, { key: 1 }, he(i.value, (l, n) => (f(), c("div", {
|
|
487
|
+
class: O([
|
|
466
488
|
"relative px-2 py-0.5 text-xs leading-4 text-gray-700 no-underline cursor-pointer dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-700 dark:hover:text-white hover:rounded-sm",
|
|
467
489
|
n + 1 == y.value ? "bg-gray-100 dark:bg-gray-700 rounded-sm" : ""
|
|
468
490
|
]),
|
|
@@ -471,11 +493,14 @@ const ye = { class: "font-bold ptext-lg dark:text-white" }, xe = { class: "mt-3
|
|
|
471
493
|
key: n,
|
|
472
494
|
id: `${n + 1}${g.value}`
|
|
473
495
|
}, [
|
|
474
|
-
s("div",
|
|
475
|
-
s("span",
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
496
|
+
s("div", Le, [
|
|
497
|
+
s("span", Me, [
|
|
498
|
+
s("span", {
|
|
499
|
+
innerHTML: l.name || l.id || "-"
|
|
500
|
+
}, null, 8, Ie),
|
|
501
|
+
l.hint ? (f(), c("span", je, w(l.hint), 1)) : h("", !0)
|
|
502
|
+
]),
|
|
503
|
+
a.value?.id === l.id ? (f(), c("svg", Te, t[11] || (t[11] = [
|
|
479
504
|
s("path", {
|
|
480
505
|
stroke: "currentColor",
|
|
481
506
|
"stroke-linecap": "round",
|
|
@@ -485,22 +510,22 @@ const ye = { class: "font-bold ptext-lg dark:text-white" }, xe = { class: "mt-3
|
|
|
485
510
|
}, null, -1)
|
|
486
511
|
]))) : h("", !0)
|
|
487
512
|
])
|
|
488
|
-
], 42,
|
|
489
|
-
$.value ? (
|
|
490
|
-
!$.value && i.value.length === 0 && !(
|
|
513
|
+
], 42, $e))), 128)) : h("", !0),
|
|
514
|
+
$.value ? (f(), c("div", Ue, " Loading... ")) : h("", !0),
|
|
515
|
+
!$.value && i.value.length === 0 && !(o.allow_custom && m.value) ? (f(), c("div", Ae, w(o.no_results_found_placeholder), 1)) : h("", !0)
|
|
491
516
|
], 544)
|
|
492
|
-
],
|
|
517
|
+
], 2), [
|
|
493
518
|
[te, x.value]
|
|
494
519
|
])
|
|
495
520
|
])
|
|
496
521
|
])
|
|
497
522
|
])) : h("", !0),
|
|
498
|
-
s("span",
|
|
499
|
-
s("small",
|
|
523
|
+
s("span", qe, w(o.error_message), 1),
|
|
524
|
+
s("small", Ve, w(o.description), 1)
|
|
500
525
|
], 2))
|
|
501
526
|
], 64));
|
|
502
527
|
}
|
|
503
528
|
};
|
|
504
529
|
export {
|
|
505
|
-
|
|
530
|
+
Pe as default
|
|
506
531
|
};
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { ref as
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { ref as E, computed as d, watch as I, createElementBlock as s, openBlock as u, normalizeClass as S, createCommentVNode as x, createElementVNode as b, toDisplayString as f, Fragment as T, createTextVNode as U, createBlock as z } from "vue";
|
|
2
|
+
import G from "./GlDropdown.vue.js";
|
|
3
|
+
import { PHONE_PREFERRED as L, PHONE_COUNTRIES as j, PHONE_CODE_DEFAULTS as J } from "./phoneCountries.js";
|
|
4
|
+
const K = {
|
|
4
5
|
key: 0,
|
|
5
6
|
class: "gl-label-form"
|
|
6
|
-
},
|
|
7
|
+
}, M = {
|
|
7
8
|
class: "mt-1 text-gray-900 dark:text-white tabular-nums",
|
|
8
9
|
dir: "ltr"
|
|
9
|
-
},
|
|
10
|
+
}, Q = ["for"], X = {
|
|
10
11
|
class: "flex",
|
|
11
12
|
dir: "ltr"
|
|
12
|
-
},
|
|
13
|
+
}, Y = {
|
|
13
14
|
key: 0,
|
|
14
15
|
class: "h-10 inline-flex shrink-0 items-center rounded-s-lg border border-e-0 border-gray-200 bg-gray-100 px-3 text-sm font-medium text-gray-700 tabular-nums dark:border-gray-700 dark:bg-gray-700 dark:text-gray-200"
|
|
15
|
-
},
|
|
16
|
+
}, Z = ["id", "name", "value", "placeholder", "required", "disabled", "aria-invalid"], ee = { class: "gl-span-form-error" }, te = {
|
|
16
17
|
key: 1,
|
|
17
18
|
class: "block mt-1 text-sm font-normal leading-5 text-gray-500"
|
|
18
|
-
},
|
|
19
|
+
}, re = {
|
|
19
20
|
__name: "GlPhoneInput",
|
|
20
21
|
props: {
|
|
21
22
|
/** The number without its country code, digits only. */
|
|
@@ -29,9 +30,9 @@ const j = {
|
|
|
29
30
|
* length is the digits after the code, used to warn on a short or long
|
|
30
31
|
* number; leave it out where numbers vary. Defaults to every country.
|
|
31
32
|
*/
|
|
32
|
-
countries: { type: Array, default: () =>
|
|
33
|
-
/** ISO codes listed first
|
|
34
|
-
preferred: { type: Array, default: () =>
|
|
33
|
+
countries: { type: Array, default: () => j },
|
|
34
|
+
/** ISO codes listed first; the rest follow alphabetically. */
|
|
35
|
+
preferred: { type: Array, default: () => L },
|
|
35
36
|
/** Show the code as fixed text instead of a picker. */
|
|
36
37
|
lock_country: { type: Boolean, default: !1 },
|
|
37
38
|
field_name: { type: String, default: "" },
|
|
@@ -44,144 +45,138 @@ const j = {
|
|
|
44
45
|
placeholder: { type: String, default: "" },
|
|
45
46
|
/** Shown when the length is off. :country and :length are filled in. */
|
|
46
47
|
length_message: { type: String, default: ":country numbers have :length digits." },
|
|
47
|
-
|
|
48
|
-
preferred_label: { type: String, default: "Common" },
|
|
49
|
-
all_label: { type: String, default: "All countries" }
|
|
48
|
+
search_placeholder: { type: String, default: "Search country or code" }
|
|
50
49
|
},
|
|
51
50
|
emits: ["update:modelValue", "update:country_code", "update:country", "change", "blur"],
|
|
52
|
-
setup(a, { expose:
|
|
53
|
-
const n = a,
|
|
51
|
+
setup(a, { expose: $, emit: C }) {
|
|
52
|
+
const n = a, g = C, h = E(null), B = E(!1), i = (e) => e.code || e.dial, c = d(() => {
|
|
54
53
|
const e = n.countries;
|
|
55
|
-
return !n.country_code || e.some((
|
|
56
|
-
}),
|
|
57
|
-
() => n.preferred.map((e) =>
|
|
58
|
-
),
|
|
59
|
-
|
|
54
|
+
return !n.country_code || e.some((t) => t.dial === n.country_code) ? e : [...e, { code: "", dial: n.country_code, name: n.country_code }];
|
|
55
|
+
}), O = d(
|
|
56
|
+
() => n.preferred.map((e) => c.value.find((t) => t.code === e)).filter(Boolean)
|
|
57
|
+
), q = d(() => [
|
|
58
|
+
...O.value,
|
|
59
|
+
...c.value.filter((e) => !n.preferred.includes(e.code)).sort((e, t) => e.name.localeCompare(t.name))
|
|
60
|
+
]), D = d(
|
|
61
|
+
() => q.value.map((e) => ({
|
|
62
|
+
id: i(e),
|
|
63
|
+
name: e.code ? `${e.dial} ${e.code}` : e.dial,
|
|
64
|
+
hint: e.code ? e.name : "",
|
|
65
|
+
keywords: `${e.name} ${e.dial} ${e.code}`
|
|
66
|
+
}))
|
|
60
67
|
);
|
|
61
|
-
function
|
|
62
|
-
const
|
|
63
|
-
return
|
|
68
|
+
function w(e, t = "") {
|
|
69
|
+
const l = c.value.filter((r) => r.dial === e);
|
|
70
|
+
return l.find((r) => t && r.code === t) || O.value.find((r) => r.dial === e) || l.find((r) => r.code === J[e]) || l[0] || null;
|
|
64
71
|
}
|
|
65
|
-
const
|
|
66
|
-
|
|
72
|
+
const v = E(i(w(n.country_code, n.country) || { dial: n.country_code }));
|
|
73
|
+
I(
|
|
67
74
|
() => [n.country_code, n.country],
|
|
68
|
-
([e,
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
75
|
+
([e, t]) => {
|
|
76
|
+
const l = c.value.find((k) => i(k) === v.value);
|
|
77
|
+
if (l && l.dial === e && (!t || l.code === t))
|
|
71
78
|
return;
|
|
72
|
-
const r =
|
|
73
|
-
|
|
79
|
+
const r = w(e, t);
|
|
80
|
+
v.value = r ? i(r) : e;
|
|
74
81
|
}
|
|
75
82
|
);
|
|
76
|
-
const
|
|
77
|
-
const e =
|
|
78
|
-
return !
|
|
79
|
-
}),
|
|
83
|
+
const o = d(() => c.value.find((e) => i(e) === v.value) || null), m = d(() => String(n.modelValue ?? "")), P = d(() => {
|
|
84
|
+
const e = o.value?.length;
|
|
85
|
+
return !B.value || !e || m.value === "" || m.value.length === e ? "" : n.length_message.replace(":country", o.value.name).replace(":length", String(e));
|
|
86
|
+
}), y = d(() => n.error_message || P.value), W = (e) => String(e ?? "").replace(/\D/g, ""), p = (e) => e.replace(/\D/g, "");
|
|
80
87
|
function F(e) {
|
|
81
|
-
return [...new Set(
|
|
88
|
+
return [...new Set(c.value.map((l) => l.dial).filter(Boolean))].sort((l, r) => p(r).length - p(l).length).find((l) => e.startsWith(p(l)));
|
|
82
89
|
}
|
|
83
90
|
function N(e) {
|
|
84
|
-
|
|
91
|
+
v.value = i(e), e.dial !== n.country_code && g("update:country_code", e.dial), e.code && e.code !== n.country && g("update:country", e.code);
|
|
85
92
|
}
|
|
86
|
-
function
|
|
87
|
-
const
|
|
88
|
-
|
|
93
|
+
function V(e) {
|
|
94
|
+
const t = o.value?.dial || n.country_code;
|
|
95
|
+
g("change", { country_code: t, country: o.value?.code || "", number: e, full: e ? `${t}${e}` : "" });
|
|
89
96
|
}
|
|
90
97
|
function H(e) {
|
|
91
|
-
const
|
|
92
|
-
let
|
|
93
|
-
if (!n.lock_country && (
|
|
94
|
-
const
|
|
95
|
-
|
|
98
|
+
const t = String(e ?? "").trim();
|
|
99
|
+
let l = W(t);
|
|
100
|
+
if (!n.lock_country && (t.startsWith("+") || t.startsWith("00"))) {
|
|
101
|
+
const k = t.startsWith("00") ? l.slice(2) : l, _ = F(k);
|
|
102
|
+
_ && (N(o.value?.dial === _ ? o.value : w(_)), l = k.slice(p(_).length));
|
|
96
103
|
}
|
|
97
|
-
const r =
|
|
98
|
-
r &&
|
|
104
|
+
const r = o.value?.length;
|
|
105
|
+
r && l.length === r + 1 && l.startsWith("0") && (l = l.slice(1)), g("update:modelValue", l), V(l), h.value && h.value.value !== l && (h.value.value = l);
|
|
99
106
|
}
|
|
100
107
|
function R(e) {
|
|
101
|
-
const
|
|
102
|
-
|
|
108
|
+
const t = e?.id ? c.value.find((l) => i(l) === e.id) : null;
|
|
109
|
+
t && (N(t), V(m.value));
|
|
103
110
|
}
|
|
104
|
-
function
|
|
105
|
-
|
|
111
|
+
function A(e) {
|
|
112
|
+
B.value = !0, g("blur", e);
|
|
106
113
|
}
|
|
107
|
-
return
|
|
114
|
+
return $({ focus: () => h.value?.focus() }), (e, t) => a.show ? (u(), s("div", {
|
|
108
115
|
key: 0,
|
|
109
116
|
class: S(a.field_name)
|
|
110
117
|
}, [
|
|
111
|
-
a.label_name ? (u(),
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
], 64)) :
|
|
118
|
+
a.label_name ? (u(), s("label", K, f(a.label_name), 1)) : x("", !0),
|
|
119
|
+
b("p", M, [
|
|
120
|
+
m.value ? (u(), s(T, { key: 0 }, [
|
|
121
|
+
U(f(o.value?.dial || a.country_code) + " " + f(m.value), 1)
|
|
122
|
+
], 64)) : x("", !0)
|
|
116
123
|
]),
|
|
117
|
-
|
|
118
|
-
], 2)) : (u(),
|
|
124
|
+
t[1] || (t[1] = b("hr", { class: "opacity-100! bg-gray-200 border-0 dark:bg-gray-700" }, null, -1))
|
|
125
|
+
], 2)) : (u(), s("div", {
|
|
119
126
|
key: 1,
|
|
120
127
|
class: S(a.field_name)
|
|
121
128
|
}, [
|
|
122
|
-
a.label_name ? (u(),
|
|
129
|
+
a.label_name ? (u(), s("label", {
|
|
123
130
|
key: 0,
|
|
124
131
|
for: a.field_name,
|
|
125
132
|
class: S({
|
|
126
|
-
"gl-label-form": !
|
|
127
|
-
"gl-label-form-invalid":
|
|
133
|
+
"gl-label-form": !y.value,
|
|
134
|
+
"gl-label-form-invalid": y.value,
|
|
128
135
|
required: a.is_required
|
|
129
136
|
})
|
|
130
|
-
},
|
|
131
|
-
|
|
132
|
-
a.lock_country ? (u(),
|
|
137
|
+
}, f(a.label_name), 11, Q)) : x("", !0),
|
|
138
|
+
b("div", X, [
|
|
139
|
+
a.lock_country ? (u(), s("span", Y, f(o.value?.dial || a.country_code), 1)) : (u(), z(G, {
|
|
133
140
|
key: 1,
|
|
134
|
-
|
|
141
|
+
class: "w-32 shrink-0",
|
|
142
|
+
field_name: `${a.field_name}_country`,
|
|
143
|
+
options: D.value,
|
|
144
|
+
modelValue: v.value,
|
|
145
|
+
has_cancel: !1,
|
|
135
146
|
disabled: a.disabled,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
}, [
|
|
141
|
-
|
|
142
|
-
key: 0,
|
|
143
|
-
label: a.preferred_label
|
|
144
|
-
}, [
|
|
145
|
-
(u(!0), o(B, null, V(w.value, (t) => (u(), o("option", {
|
|
146
|
-
key: "p-" + i(t),
|
|
147
|
-
value: i(t)
|
|
148
|
-
}, c(t.code ? `${t.code} ${t.dial}` : t.dial), 9, Z))), 128))
|
|
149
|
-
], 8, Y)) : p("", !0),
|
|
150
|
-
g("optgroup", { label: a.all_label }, [
|
|
151
|
-
(u(!0), o(B, null, V(P.value, (t) => (u(), o("option", {
|
|
152
|
-
key: i(t),
|
|
153
|
-
value: i(t)
|
|
154
|
-
}, c(t.code ? `${t.code} ${t.dial}` : t.dial), 9, te))), 128))
|
|
155
|
-
], 8, ee)
|
|
156
|
-
], 40, X)),
|
|
157
|
-
g("input", {
|
|
147
|
+
search_input_placeholder: a.search_placeholder,
|
|
148
|
+
input_class: "rounded-e-none! border-e-0! bg-gray-100! dark:bg-gray-700! font-medium tabular-nums",
|
|
149
|
+
options_class: "min-w-72",
|
|
150
|
+
onSelectionChanged: R
|
|
151
|
+
}, null, 8, ["field_name", "options", "modelValue", "disabled", "search_input_placeholder"])),
|
|
152
|
+
b("input", {
|
|
158
153
|
ref_key: "input",
|
|
159
|
-
ref:
|
|
154
|
+
ref: h,
|
|
160
155
|
type: "tel",
|
|
161
156
|
inputmode: "numeric",
|
|
162
157
|
autocomplete: "tel-national",
|
|
163
158
|
id: a.field_name,
|
|
164
159
|
name: a.field_name,
|
|
165
|
-
value:
|
|
166
|
-
placeholder: a.placeholder || (
|
|
160
|
+
value: m.value,
|
|
161
|
+
placeholder: a.placeholder || (o.value?.length ? "0".repeat(o.value.length) : ""),
|
|
167
162
|
maxlength: "24",
|
|
168
163
|
required: a.is_required,
|
|
169
164
|
disabled: a.disabled,
|
|
170
|
-
"aria-invalid":
|
|
165
|
+
"aria-invalid": y.value ? "true" : "false",
|
|
171
166
|
class: S(["min-w-0 rounded-s-none! tabular-nums", {
|
|
172
|
-
"gl-input-form": !
|
|
173
|
-
"gl-input-form-invalid":
|
|
167
|
+
"gl-input-form": !y.value,
|
|
168
|
+
"gl-input-form-invalid": y.value,
|
|
174
169
|
"opacity-70 cursor-not-allowed bg-gray-100 dark:bg-gray-700": a.disabled
|
|
175
170
|
}]),
|
|
176
|
-
onInput:
|
|
177
|
-
onBlur:
|
|
178
|
-
}, null, 42,
|
|
171
|
+
onInput: t[0] || (t[0] = (l) => H(l.target.value)),
|
|
172
|
+
onBlur: A
|
|
173
|
+
}, null, 42, Z)
|
|
179
174
|
]),
|
|
180
|
-
|
|
181
|
-
a.description ? (u(),
|
|
175
|
+
b("span", ee, f(y.value), 1),
|
|
176
|
+
a.description ? (u(), s("small", te, f(a.description), 1)) : x("", !0)
|
|
182
177
|
], 2));
|
|
183
178
|
}
|
|
184
179
|
};
|
|
185
180
|
export {
|
|
186
|
-
|
|
181
|
+
re as default
|
|
187
182
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "The most popular library of interactive components built with Vuejs && Tailwind CSS",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"private": false,
|
|
6
|
-
"version": "1.3.
|
|
6
|
+
"version": "1.3.11",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
9
9
|
"url": "git+https://github.com/mrgiant/GoldenLogicUi.git"
|