@verdnatura/vn-front-lib 0.1.8 → 0.2.0

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 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./composables-BTfGi73U.cjs");exports.fetchLocalData=e.n,exports.focusFirstInput=e.p,exports.getObjectByKeys=e.a,exports.getObjectDifferences=e.o,exports.getRemoteAndLocalParams=e.r,Object.defineProperty(exports,"i18n",{enumerable:!0,get:function(){return e.d}}),exports.isComparableObject=e.s,exports.isSameValue=e.c,exports.requestData=e.i,exports.tMobile=e.h,exports.useArrayData=e.m,exports.useGlobalMessages=e.f,exports.useNotify=e.u,exports.useObjectComparison=e.l,exports.useRequired=e.g,exports.useState=e.t,exports.useValidator=e._;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./composables-DMmrQNdc.cjs");exports.fetchLocalData=e.n,exports.focusFirstInput=e.p,exports.getObjectByKeys=e.a,exports.getObjectDifferences=e.o,exports.getRemoteAndLocalParams=e.r,Object.defineProperty(exports,"i18n",{enumerable:!0,get:function(){return e.d}}),exports.isComparableObject=e.s,exports.isSameValue=e.c,exports.requestData=e.i,exports.tMobile=e.h,exports.useArrayData=e.m,exports.useGlobalMessages=e.f,exports.useNotify=e.u,exports.useObjectComparison=e.l,exports.useRequired=e.g,exports.useState=e.t,exports.useValidator=e._;
@@ -1,2 +1,2 @@
1
- import { _ as e, a as t, c as n, d as r, f as i, g as a, h as o, i as s, l as c, m as l, n as u, o as d, p as f, r as p, s as m, t as h, u as g } from "./composables-xGr9z2hA.js";
1
+ import { _ as e, a as t, c as n, d as r, f as i, g as a, h as o, i as s, l as c, m as l, n as u, o as d, p as f, r as p, s as m, t as h, u as g } from "./composables-CWY0-8uj.js";
2
2
  export { u as fetchLocalData, f as focusFirstInput, t as getObjectByKeys, d as getObjectDifferences, p as getRemoteAndLocalParams, r as i18n, m as isComparableObject, n as isSameValue, s as requestData, o as tMobile, l as useArrayData, i as useGlobalMessages, g as useNotify, c as useObjectComparison, a as useRequired, h as useState, e as useValidator };
@@ -0,0 +1,20 @@
1
+ //#region \0rolldown/runtime.js
2
+ var e = Object.create, t = Object.defineProperty, n = Object.getOwnPropertyDescriptor, r = Object.getOwnPropertyNames, i = Object.getPrototypeOf, a = Object.prototype.hasOwnProperty, o = (e, t) => () => (t || (e((t = { exports: {} }).exports, t), e = null), t.exports), s = (e, n) => {
3
+ let r = {};
4
+ for (var i in e) t(r, i, {
5
+ get: e[i],
6
+ enumerable: !0
7
+ });
8
+ return n || t(r, Symbol.toStringTag, { value: "Module" }), r;
9
+ }, c = (e, i, o, s) => {
10
+ if (i && typeof i == "object" || typeof i == "function") for (var c = r(i), l = 0, u = c.length, d; l < u; l++) d = c[l], !a.call(e, d) && d !== o && t(e, d, {
11
+ get: ((e) => i[e]).bind(null, d),
12
+ enumerable: !(s = n(i, d)) || s.enumerable
13
+ });
14
+ return e;
15
+ }, l = (n, r, o) => (o = n == null ? {} : e(i(n)), c(r || !n || !n.__esModule || !a.call(n, "default") ? t(o, "default", {
16
+ value: n,
17
+ enumerable: !0
18
+ }) : o, n));
19
+ //#endregion
20
+ export { s as n, l as r, o as t };
@@ -1 +1 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./components-DH7vFPBF.cjs"),t=require("./composables-BTfGi73U.cjs");function n(n,r={}){for(let t in e.t)n.component(t,e.t[t]);t.f(r.i18n)}var r={install:n};exports.VnConfirm=e.l,exports.VnDate=e.o,exports.VnFetch=e.r,exports.VnForm=e.n,exports.VnInput=e.a,exports.VnInputDate=e.i,exports.VnSkeletonForm=e.c,exports.VnSpinner=e.s,exports.default=r,exports.fetchLocalData=t.n,exports.focusFirstInput=t.p,exports.getObjectByKeys=t.a,exports.getObjectDifferences=t.o,exports.getRemoteAndLocalParams=t.r,Object.defineProperty(exports,"i18n",{enumerable:!0,get:function(){return t.d}}),exports.isComparableObject=t.s,exports.isSameValue=t.c,exports.requestData=t.i,exports.tMobile=t.h,exports.useArrayData=t.m,exports.useGlobalMessages=t.f,exports.useNotify=t.u,exports.useObjectComparison=t.l,exports.useRequired=t.g,exports.useState=t.t,exports.useValidator=t._;
1
+ Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./components-DmGc4N0k.cjs"),t=require("./composables-DMmrQNdc.cjs");function n(n,r={}){for(let t in e.t)n.component(t,e.t[t]);t.f(r.i18n)}var r={install:n};exports.VnConfirm=e.u,exports.VnDate=e.s,exports.VnFetch=e.i,exports.VnForm=e.r,exports.VnInput=e.o,exports.VnInputDate=e.a,exports.VnSelect=e.n,exports.VnSkeletonForm=e.l,exports.VnSpinner=e.c,exports.default=r,exports.fetchLocalData=t.n,exports.focusFirstInput=t.p,exports.getObjectByKeys=t.a,exports.getObjectDifferences=t.o,exports.getRemoteAndLocalParams=t.r,Object.defineProperty(exports,"i18n",{enumerable:!0,get:function(){return t.d}}),exports.isComparableObject=t.s,exports.isSameValue=t.c,exports.requestData=t.i,exports.tMobile=t.h,exports.useArrayData=t.m,exports.useGlobalMessages=t.f,exports.useNotify=t.u,exports.useObjectComparison=t.l,exports.useRequired=t.g,exports.useState=t.t,exports.useValidator=t._;
@@ -1,2 +1,2 @@
1
- .q-card[data-v-087d2dc1]{white-space:pre-line;min-width:350px}.vn-spinner[data-v-e5edebae]{border:3px solid color-mix(in srgb, var(--vn-label-color) 15%, transparent);border-top-color:var(--q-primary);box-sizing:border-box;border-radius:50%;min-width:16px;min-height:16px;animation:.7s cubic-bezier(.4,.15,.6,.85) infinite vn-spin-e5edebae}@keyframes vn-spin-e5edebae{to{transform:rotate(360deg)}}.vn-spinner-fade-enter-active[data-v-e5edebae],.vn-spinner-fade-leave-active[data-v-e5edebae]{transition:opacity .3s,transform .3s}.vn-spinner-fade-enter-from[data-v-e5edebae],.vn-spinner-fade-leave-to[data-v-e5edebae]{opacity:0;transform:scale(.6)}.q-date[data-v-8338d4d1]{width:245px;min-width:unset}.q-date[data-v-8338d4d1] .q-date__calendar{padding-bottom:0}.q-date[data-v-8338d4d1] .q-date__view{min-height:245px;padding:8px}.q-date[data-v-8338d4d1] .q-date__calendar-days-container{min-height:160px;height:unset}.q-date[data-v-8338d4d1] .q-date__header{height:60px;padding:2px 2px 5px 12px}.uppercase-icon{cursor:pointer;transition:color .3s,transform .2s}.uppercase-icon:hover{color:var(--q-color-primary);transform:scale(1.2)}.q-notifications[data-v-addfa85d]{color:#000}.q-card[data-v-addfa85d]{padding:32px}
1
+ .q-card[data-v-087d2dc1]{white-space:pre-line;min-width:350px}.vn-spinner[data-v-e5edebae]{border:3px solid color-mix(in srgb, var(--vn-label-color) 15%, transparent);border-top-color:var(--q-primary);box-sizing:border-box;border-radius:50%;min-width:16px;min-height:16px;animation:.7s cubic-bezier(.4,.15,.6,.85) infinite vn-spin-e5edebae}@keyframes vn-spin-e5edebae{to{transform:rotate(360deg)}}.vn-spinner-fade-enter-active[data-v-e5edebae],.vn-spinner-fade-leave-active[data-v-e5edebae]{transition:opacity .3s,transform .3s}.vn-spinner-fade-enter-from[data-v-e5edebae],.vn-spinner-fade-leave-to[data-v-e5edebae]{opacity:0;transform:scale(.6)}.q-date[data-v-8338d4d1]{width:245px;min-width:unset}.q-date[data-v-8338d4d1] .q-date__calendar{padding-bottom:0}.q-date[data-v-8338d4d1] .q-date__view{min-height:245px;padding:8px}.q-date[data-v-8338d4d1] .q-date__calendar-days-container{min-height:160px;height:unset}.q-date[data-v-8338d4d1] .q-date__header{height:60px;padding:2px 2px 5px 12px}.uppercase-icon{cursor:pointer;transition:color .3s,transform .2s}.uppercase-icon:hover{color:var(--q-color-primary);transform:scale(1.2)}.q-notifications[data-v-addfa85d]{color:#000}.q-card[data-v-addfa85d]{padding:32px}.q-field--outlined[data-v-e5953317]{max-width:100%}.nowrap[data-v-e5953317],.q-field__native[data-v-e5953317]{text-overflow:ellipsis;white-space:nowrap;max-width:100%;display:flex;overflow:hidden;flex-wrap:nowrap!important}.chip-scroll[data-v-e5953317]{scrollbar-width:none;-ms-overflow-style:none;flex-wrap:nowrap;max-width:100%;overflow:auto hidden}.vn-chip[data-v-e5953317]{color:var(--vn-text-color);background-color:var(--vn-page-color);max-width:none}
2
2
  /*$vite$:1*/
@@ -1,10 +1,10 @@
1
- import { _ as e, a as t, c as n, d as r, f as i, g as a, h as o, i as s, l as c, m as l, n as u, o as d, p as f, r as p, s as m, t as h, u as g } from "./composables-xGr9z2hA.js";
2
- import { a as _, c as v, i as y, l as b, n as x, o as S, r as C, s as w, t as T } from "./components-BVCHOTDW.js";
1
+ import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c, u as l } from "./components-C8Wdf_CB.js";
2
+ import { _ as u, a as d, c as f, d as p, f as m, g as h, h as g, i as _, l as v, m as y, n as b, o as x, p as S, r as C, s as w, t as T, u as E } from "./composables-CWY0-8uj.js";
3
3
  //#region lib/main.js
4
- function E(e, t = {}) {
5
- for (let t in T) e.component(t, T[t]);
6
- i(t.i18n);
4
+ function D(e, t = {}) {
5
+ for (let t in c) e.component(t, c[t]);
6
+ m(t.i18n);
7
7
  }
8
- var D = { install: E };
8
+ var O = { install: D };
9
9
  //#endregion
10
- export { b as VnConfirm, S as VnDate, C as VnFetch, x as VnForm, _ as VnInput, y as VnInputDate, v as VnSkeletonForm, w as VnSpinner, D as default, u as fetchLocalData, f as focusFirstInput, t as getObjectByKeys, d as getObjectDifferences, p as getRemoteAndLocalParams, r as i18n, m as isComparableObject, n as isSameValue, s as requestData, o as tMobile, l as useArrayData, i as useGlobalMessages, g as useNotify, c as useObjectComparison, a as useRequired, h as useState, e as useValidator };
10
+ export { l as VnConfirm, s as VnDate, n as VnFetch, o as VnForm, a as VnInput, e as VnInputDate, i as VnSelect, r as VnSkeletonForm, t as VnSpinner, O as default, b as fetchLocalData, S as focusFirstInput, d as getObjectByKeys, x as getObjectDifferences, C as getRemoteAndLocalParams, p as i18n, w as isComparableObject, f as isSameValue, _ as requestData, g as tMobile, y as useArrayData, m as useGlobalMessages, E as useNotify, v as useObjectComparison, h as useRequired, T as useState, u as useValidator };
@@ -6,3 +6,4 @@ export { default as VnInput } from './inputs/VnInput.vue';
6
6
  export { default as VnInputDate } from './inputs/VnInputDate.vue';
7
7
  export { default as VnFetch } from './models/VnFetch.vue';
8
8
  export { default as VnForm } from './models/VnForm.vue';
9
+ export { default as VnSelect } from './selects/VnSelect.vue';
@@ -0,0 +1,612 @@
1
+ <script setup>
2
+ import { ref, toRefs, computed, watch, onMounted, useAttrs, nextTick } from 'vue';
3
+ import { useI18n } from 'vue-i18n';
4
+ import { useArrayData } from 'lib/composables/useArrayData';
5
+ import { useRequired } from 'lib/composables/useRequired';
6
+ import dataByOrder from 'lib/utils/dataByOrder';
7
+
8
+ const emit = defineEmits(['update:modelValue', 'update:options', 'remove']);
9
+ const $attrs = useAttrs();
10
+ const { t } = useI18n();
11
+
12
+ const isRequired = computed(() => {
13
+ return useRequired($attrs).isRequired;
14
+ });
15
+ const requiredFieldRule = computed(() => {
16
+ return useRequired($attrs).requiredFieldRule;
17
+ });
18
+
19
+ const $props = defineProps({
20
+ modelValue: {
21
+ type: [String, Number, Object],
22
+ default: null,
23
+ },
24
+ options: {
25
+ type: [Array, Object],
26
+ default: () => [],
27
+ },
28
+ optionLabel: {
29
+ type: [String, Function],
30
+ default: 'name',
31
+ },
32
+ optionValue: {
33
+ type: String,
34
+ default: 'id',
35
+ },
36
+ optionCaption: {
37
+ type: String,
38
+ default: null,
39
+ },
40
+ optionFilter: {
41
+ type: String,
42
+ default: null,
43
+ },
44
+ optionFilterValue: {
45
+ type: String,
46
+ default: null,
47
+ },
48
+ url: {
49
+ type: String,
50
+ default: null,
51
+ },
52
+ filterOptions: {
53
+ type: [Array],
54
+ default: () => [],
55
+ },
56
+ exprBuilder: {
57
+ type: Function,
58
+ default: null,
59
+ },
60
+ isClearable: {
61
+ type: Boolean,
62
+ default: true,
63
+ },
64
+ fields: {
65
+ type: Array,
66
+ default: null,
67
+ },
68
+ include: {
69
+ type: [Object, Array, String],
70
+ default: null,
71
+ },
72
+ where: {
73
+ type: Object,
74
+ default: null,
75
+ },
76
+ sortBy: {
77
+ type: [String, Array],
78
+ default: null,
79
+ },
80
+ limit: {
81
+ type: [Number, String],
82
+ default: '30',
83
+ },
84
+ focusOnMount: {
85
+ type: Boolean,
86
+ default: false,
87
+ },
88
+ openOnMount: {
89
+ type: Boolean,
90
+ default: false,
91
+ },
92
+ useLike: {
93
+ type: Boolean,
94
+ default: true,
95
+ },
96
+ filterBuilder: {
97
+ type: Function,
98
+ },
99
+ params: {
100
+ type: Object,
101
+ default: null,
102
+ },
103
+ noOne: {
104
+ type: Boolean,
105
+ default: false,
106
+ },
107
+ dataKey: {
108
+ type: String,
109
+ default: null,
110
+ },
111
+ isOutlined: {
112
+ type: Boolean,
113
+ default: false,
114
+ },
115
+ paramsBuilder: {
116
+ type: Function,
117
+ default: () => ({}),
118
+ },
119
+ sortOptions: {
120
+ type: Boolean,
121
+ default: true,
122
+ },
123
+ noWhere: {
124
+ type: Boolean,
125
+ default: false,
126
+ },
127
+ });
128
+ const mixinRules = [requiredFieldRule, ...($attrs.rules ?? [])];
129
+ const {
130
+ optionLabel,
131
+ optionValue,
132
+ optionCaption,
133
+ optionFilter,
134
+ optionFilterValue,
135
+ options,
136
+ modelValue,
137
+ } = toRefs($props);
138
+ const myOptions = ref([]);
139
+ const myOptionsOriginal = ref([]);
140
+ const myOptionsMap = ref(new Map());
141
+ const vnSelectRef = ref();
142
+ const lastVal = ref();
143
+ const noOneText = t('globals.noOne');
144
+ const noOneOpt = ref({
145
+ [optionValue.value]: false,
146
+ [optionLabel.value]: noOneText,
147
+ });
148
+ const styleAttrs = computed(() => {
149
+ return $props.isOutlined
150
+ ? {
151
+ dense: true,
152
+ outlined: true,
153
+ rounded: true,
154
+ }
155
+ : {};
156
+ });
157
+ const hasFocus = ref(false);
158
+ const isLoading = ref(false);
159
+ const useURL = computed(() => $props.url);
160
+ const value = computed({
161
+ get() {
162
+ return $props.modelValue;
163
+ },
164
+ set(value) {
165
+ setOptions(myOptionsOriginal.value);
166
+ emit('update:modelValue', value);
167
+ },
168
+ });
169
+ const isMultiple = computed(() => {
170
+ return Array.isArray($props.modelValue) || 'multiple' in $attrs || $attrs.isAdvanced;
171
+ });
172
+
173
+ const arrayDataKey =
174
+ $props.dataKey ??
175
+ ($props.url?.length > 0 ? $props.url : ($attrs.name ?? $attrs.label));
176
+
177
+ const arrayData = useArrayData(arrayDataKey, {
178
+ url: $props.url,
179
+ searchUrl: false,
180
+ mapKey: $attrs['map-key'],
181
+ });
182
+ const isMenuOpened = ref(false);
183
+ const computedSortBy = computed(() => {
184
+ if ($props.sortBy) return $props.sortBy;
185
+ return typeof $props.optionLabel == 'string' ? $props.optionLabel + ' ASC' : '';
186
+ });
187
+
188
+ function getVal(val) {
189
+ if (typeof $props.filterBuilder === 'function') return $props.filterBuilder(val);
190
+
191
+ return $props.useLike ? { like: `%${val}%` } : val;
192
+ }
193
+
194
+ watch(options, (newValue) => {
195
+ setOptions(newValue);
196
+ });
197
+
198
+ watch(modelValue, async (newValue) => {
199
+ newValue = (newValue?.neq || newValue?.nin || newValue) ?? [];
200
+ if (!Array.isArray(newValue)) newValue = [newValue];
201
+
202
+ for (const val of newValue)
203
+ if (!myOptionsMap.value.get(val)) await fetchFilter(val, true);
204
+
205
+ if ($props.noOne) myOptions.value.unshift(noOneOpt.value);
206
+ });
207
+
208
+ watch(
209
+ () => myOptionsOriginal.value,
210
+ (newValue) => {
211
+ for (const item of newValue) {
212
+ myOptionsMap.value.set(item[optionValue.value], item);
213
+ }
214
+ },
215
+ );
216
+
217
+ onMounted(() => {
218
+ setOptions(options.value);
219
+ if (useURL.value && $props.modelValue && !findKeyInOptions())
220
+ fetchFilter($props.modelValue);
221
+ if ($props.focusOnMount || $props.openOnMount)
222
+ setTimeout(() => componentFocus(true, $props.openOnMount), 300);
223
+ });
224
+
225
+ function findKeyInOptions() {
226
+ if (!$props.options) return;
227
+ return filter($props.modelValue, $props.options)?.length;
228
+ }
229
+
230
+ function setOptions(data) {
231
+ if ($props.sortOptions) data = dataByOrder(data, computedSortBy.value);
232
+ myOptions.value = JSON.parse(JSON.stringify(data));
233
+ myOptionsOriginal.value = JSON.parse(JSON.stringify(data));
234
+ emit('update:options', data);
235
+ }
236
+
237
+ function filter(val, options) {
238
+ const search = val?.toString()?.toLowerCase();
239
+
240
+ if (!search) return options;
241
+
242
+ return options.filter((row) => {
243
+ if ($props.filterOptions.length) {
244
+ return $props.filterOptions.some((prop) => {
245
+ const propValue = String(row[prop]).toLowerCase();
246
+ return propValue.includes(search);
247
+ });
248
+ }
249
+
250
+ if (!row) return;
251
+ const id = String(row[$props.optionValue]).toLowerCase();
252
+ const optionLabel = String(row[$props.optionLabel]).toLowerCase();
253
+
254
+ return id.includes(search) || optionLabel.includes(search);
255
+ });
256
+ }
257
+
258
+ async function fetchFilter(val, isValue = false) {
259
+ if (!$props.url) return;
260
+ if (val && typeof val == 'object') {
261
+ val = val.neq;
262
+ }
263
+
264
+ const { fields, include, limit } = $props;
265
+ const sortBy = computedSortBy.value;
266
+ const key =
267
+ optionFilterValue.value ??
268
+ (isValue || new RegExp(/^\d+$/).test(val)
269
+ ? optionValue.value
270
+ : (optionFilter.value ?? optionLabel.value));
271
+
272
+ let defaultWhere = {};
273
+ if ($props.filterOptions.length) {
274
+ defaultWhere = $props.filterOptions.reduce((obj, prop) => {
275
+ if (!obj.or) obj.or = [];
276
+ obj.or.push({ [prop]: getVal(val) });
277
+ return obj;
278
+ }, {});
279
+ } else defaultWhere = { [key]: getVal(val) };
280
+ const where = $props.noWhere ? {} : { ...(val ? defaultWhere : {}), ...$props.where };
281
+ $props.exprBuilder && Object.assign(where, $props.exprBuilder(key, val));
282
+ const filterOptions = { where, include, limit };
283
+ if (fields) filterOptions.fields = fields;
284
+ if (sortBy) arrayData.store.order = sortBy;
285
+ isLoading.value = true;
286
+
287
+ arrayData.resetPagination();
288
+ let data;
289
+ try {
290
+ const res = await arrayData.applyFilter(
291
+ {
292
+ filter: filterOptions,
293
+ params: $props.params ?? $props.paramsBuilder?.(val),
294
+ },
295
+ { updateRouter: false },
296
+ );
297
+ data = res?.data;
298
+ } finally {
299
+ isLoading.value = false;
300
+ }
301
+ setOptions(data);
302
+ return data;
303
+ }
304
+
305
+ async function filterHandler(val, update) {
306
+ let newOptions;
307
+ if (isMultipleAndEmpty(val)) {
308
+ val = null;
309
+ }
310
+
311
+ if (!val && lastVal.value === val) update();
312
+ else {
313
+ const makeRequest =
314
+ ($props.url && $props.limit) ||
315
+ (!$props.limit && Object.keys(myOptions.value).length === 0);
316
+ newOptions = makeRequest
317
+ ? await fetchFilter(val)
318
+ : filter(val, myOptionsOriginal.value);
319
+
320
+ update(
321
+ () => {
322
+ if ($props.noOne && noOneText.toLowerCase().includes(val.toLowerCase()))
323
+ newOptions.unshift(noOneOpt.value);
324
+
325
+ myOptions.value = newOptions;
326
+ },
327
+ (ref) => {
328
+ if (val !== '' && ref.options.length > 0) {
329
+ ref.setOptionIndex(-1);
330
+ ref.moveOptionSelection(1, true);
331
+ }
332
+ },
333
+ );
334
+ }
335
+
336
+ lastVal.value = val;
337
+ }
338
+
339
+ function nullishToTrue(value) {
340
+ return value ?? true;
341
+ }
342
+
343
+ async function onScroll({ to, direction, from, index }) {
344
+ const lastIndex = myOptions.value.length - 1;
345
+
346
+ if (from === 0 && index === 0) return;
347
+ if (!useURL.value && !$props.fetchRef) return;
348
+ if (direction === 'decrease') return;
349
+ if (to === lastIndex && arrayData.store.hasMoreData) {
350
+ await arrayData.loadMore();
351
+ setOptions(arrayData.store.data);
352
+ vnSelectRef.value.scrollTo(lastIndex);
353
+ await nextTick();
354
+ }
355
+ }
356
+
357
+ defineExpose({ opts: myOptions, vnSelectRef, myOptionsMap });
358
+
359
+ function getCaption(opt) {
360
+ if (optionCaption.value === false) return;
361
+ return opt[optionCaption.value] || opt[optionValue.value];
362
+ }
363
+
364
+ function getOptionLabel(currentValue) {
365
+ if (Array.isArray(currentValue)) currentValue = currentValue[0];
366
+ if (currentValue && typeof currentValue == 'object')
367
+ currentValue = currentValue[optionValue.value];
368
+ const selectModel = myOptionsMap.value.get(currentValue);
369
+
370
+ if (typeof optionLabel.value == 'function')
371
+ return optionLabel.value(selectModel ?? {});
372
+
373
+ return selectModel?.[optionLabel.value] ?? currentValue;
374
+ }
375
+
376
+ function handleEnter(event) {
377
+ if (event?.code !== 'Enter') return;
378
+ if (event.type === 'keydown' && event.ctrlKey && isMultiple.value) {
379
+ event.stopPropagation();
380
+ } else if (event.type === 'keyup' && !event.ctrlKey) {
381
+ event.preventDefault();
382
+ event.stopPropagation();
383
+ }
384
+ }
385
+
386
+ async function componentFocus(force, open) {
387
+ if (!hasFocus.value && !force) return;
388
+ hasFocus.value = false;
389
+ await nextTick();
390
+ vnSelectRef.value?.focus();
391
+ if (!isMenuOpened.value && open) vnSelectRef.value?.showPopup();
392
+ }
393
+
394
+ function isMultipleAndEmpty(val) {
395
+ return isMultiple.value && Array.isArray(val) && !val.length;
396
+ }
397
+ </script>
398
+
399
+ <template>
400
+ <QSelect
401
+ ref="vnSelectRef"
402
+ v-model="value"
403
+ for="vnSelectFor"
404
+ :options="myOptions"
405
+ :option-label="optionLabel"
406
+ :option-value="optionValue"
407
+ v-bind="{
408
+ ...$attrs,
409
+ ...styleAttrs,
410
+ hideSelected: hasFocus,
411
+ useInput: hasFocus || !value,
412
+ }"
413
+ @filter="filterHandler"
414
+ :emit-value="nullishToTrue($attrs['emit-value'])"
415
+ :map-options="nullishToTrue($attrs['map-options'])"
416
+ no-option-prefetch
417
+ :use-input="hasFocus || !value"
418
+ :fill-input="false"
419
+ lazy-rules
420
+ :class="{ required: isRequired }"
421
+ :rules="mixinRules"
422
+ virtual-scroll-slice-size="options.length"
423
+ hide-bottom-space
424
+ :input-debounce="useURL ? '300' : '0'"
425
+ :loading="isLoading"
426
+ @virtual-scroll="onScroll"
427
+ @popup-hide="
428
+ async () => {
429
+ isMenuOpened = false;
430
+ if (!isLoading) await componentFocus();
431
+ }
432
+ "
433
+ @popup-show="
434
+ async () => {
435
+ isMenuOpened = true;
436
+ hasFocus = true;
437
+ await $nextTick();
438
+ vnSelectRef?.$el?.querySelector('input')?.focus();
439
+ }
440
+ "
441
+ @keyup.enter="handleEnter"
442
+ :data-cy="$attrs.dataCy ?? $attrs.label + '_select'"
443
+ :data-url="url"
444
+ @blur="
445
+ async () => {
446
+ hasFocus = false;
447
+ await nextTick();
448
+ }
449
+ "
450
+ @update:model-value="
451
+ async (val) => {
452
+ await componentFocus();
453
+ if (isMultipleAndEmpty(val)) {
454
+ value = null;
455
+ emit('remove');
456
+ }
457
+ }
458
+ "
459
+ :is-required="false"
460
+ class="nowrap"
461
+ autocomplete="off"
462
+ :multiple="isMultiple"
463
+ @keydown.capture="handleEnter"
464
+ >
465
+ <template #append>
466
+ <QIcon
467
+ v-show="isClearable && value != null && value !== ''"
468
+ name="close"
469
+ @click="
470
+ () => {
471
+ value = null;
472
+ emit('remove');
473
+ }
474
+ "
475
+ class="cursor-pointer"
476
+ size="xs"
477
+ :data-cy="$attrs.dataCy ?? $attrs.label + '_select_clear'"
478
+ >
479
+ <QTooltip>{{ t('Remove') }}</QTooltip>
480
+ </QIcon>
481
+ </template>
482
+ <template v-for="(_, slotName) in $slots" #[slotName]="slotData" :key="slotName">
483
+ <div v-if="slotName == 'append'">
484
+ <QIcon
485
+ v-show="isClearable && value != null && value !== ''"
486
+ name="close"
487
+ @click.stop="
488
+ () => {
489
+ value = null;
490
+ emit('remove');
491
+ }
492
+ "
493
+ class="cursor-pointer"
494
+ size="xs"
495
+ >
496
+ <QTooltip>{{ t('Remove') }}</QTooltip>
497
+ </QIcon>
498
+ <slot name="append" v-if="$slots.append" v-bind="slotData ?? {}" />
499
+ </div>
500
+ <slot v-else :name="slotName" v-bind="slotData ?? {}" :key="slotName" />
501
+ </template>
502
+ <template #option="{ itemProps, opt, selected, toggleOption }">
503
+ <QItem v-bind="itemProps">
504
+ <QItemSection v-if="typeof optionLabel === 'function'">{{
505
+ optionLabel(opt)
506
+ }}</QItemSection>
507
+ <QItemSection v-else-if="typeof opt !== 'object'">
508
+ {{ opt }}</QItemSection
509
+ >
510
+ <QItemSection v-else-if="opt[optionValue] == opt[optionLabel]">
511
+ <QItemLabel>{{ opt[optionLabel] }}</QItemLabel>
512
+ </QItemSection>
513
+ <QItemSection v-else>
514
+ <QItemLabel>
515
+ {{ opt[optionLabel] }}
516
+ </QItemLabel>
517
+ <QItemLabel caption v-if="getCaption(opt) !== false">
518
+ {{ `#${getCaption(opt)}` }}
519
+ </QItemLabel>
520
+ </QItemSection>
521
+ <QItemSection side v-if="isMultiple">
522
+ <QCheckbox
523
+ dense
524
+ :model-value="selected"
525
+ @update:model-value="toggleOption(opt)"
526
+ />
527
+ </QItemSection>
528
+ </QItem>
529
+ </template>
530
+ <template #selected>
531
+ <span
532
+ v-if="!isMultiple && modelValue != null"
533
+ class="nowrap"
534
+ :title="getOptionLabel(modelValue)"
535
+ v-text="getOptionLabel(modelValue)"
536
+ />
537
+ <div class="no-wrap chip-scroll" v-else-if="modelValue?.length">
538
+ <QChip
539
+ removable
540
+ dense
541
+ class="vn-chip"
542
+ :style="{ maxWidth: modelValue.length > 1 ? '100px' : '120px' }"
543
+ @remove="
544
+ () => {
545
+ modelValue.shift();
546
+ if (!modelValue.length) value = null;
547
+ emit('remove');
548
+ }
549
+ "
550
+ :title="getOptionLabel(modelValue[0])"
551
+ data-cy="vn-select_chip"
552
+ >
553
+ <span class="ellipsis" v-text="getOptionLabel(modelValue[0])" />
554
+ </QChip>
555
+ <QChip
556
+ dense
557
+ v-if="modelValue.length > 1"
558
+ data-cy="vn-select_chip-counter"
559
+ class="vn-chip q-mx-none"
560
+ >
561
+ +{{ modelValue.length - 1 }}
562
+ <QTooltip>
563
+ <div
564
+ v-for="(scope, index) in modelValue.slice(1)"
565
+ :key="index"
566
+ v-text="getOptionLabel(scope)"
567
+ />
568
+ </QTooltip>
569
+ </QChip>
570
+ </div>
571
+ </template>
572
+ <template #loading>
573
+ <VnSpinner size="xs" data-cy="vnSelectSpinner" />
574
+ </template>
575
+ </QSelect>
576
+ </template>
577
+
578
+ <style scoped lang="scss">
579
+ .q-field--outlined {
580
+ max-width: 100%;
581
+ }
582
+ .q-field__native {
583
+ @extend .nowrap;
584
+ }
585
+
586
+ .nowrap {
587
+ flex-wrap: nowrap !important;
588
+ text-overflow: ellipsis;
589
+ overflow: hidden;
590
+ white-space: nowrap;
591
+ display: flex;
592
+ max-width: 100%;
593
+ }
594
+ .chip-scroll {
595
+ overflow-x: auto;
596
+ overflow-y: hidden;
597
+ flex-wrap: nowrap;
598
+ max-width: 100%;
599
+ scrollbar-width: none;
600
+ -ms-overflow-style: none;
601
+ }
602
+
603
+ .vn-chip {
604
+ color: var(--vn-text-color);
605
+ background-color: var(--vn-page-color);
606
+ max-width: none;
607
+ }
608
+ </style>
609
+ <i18n>
610
+ es:
611
+ Remove: Eliminar
612
+ </i18n>