@verdnatura/vn-front-lib 0.1.9 → 0.2.1

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