quasar-ui-danx 0.3.48 → 0.3.49
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/danx.es.js +108 -106
- package/dist/danx.es.js.map +1 -1
- package/dist/danx.umd.js +1 -1
- package/dist/danx.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ActionTable/Form/Fields/SelectField.vue +140 -138
package/package.json
CHANGED
@@ -24,10 +24,12 @@
|
|
24
24
|
@update:model-value="onUpdate"
|
25
25
|
>
|
26
26
|
<template #append>
|
27
|
-
<
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
<slot name="append">
|
28
|
+
<DropDownIcon
|
29
|
+
class="w-4 transition"
|
30
|
+
:class="isShowing ? 'rotate-180' : ''"
|
31
|
+
/>
|
32
|
+
</slot>
|
31
33
|
</template>
|
32
34
|
<template #selected>
|
33
35
|
<div
|
@@ -71,40 +73,40 @@ import { computed, isRef, nextTick, ref } from "vue";
|
|
71
73
|
|
72
74
|
const emit = defineEmits(["update:model-value", "search", "update"]);
|
73
75
|
const props = defineProps({
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
76
|
+
...QSelect.props,
|
77
|
+
modelValue: {
|
78
|
+
type: [Array, String, Number, Object],
|
79
|
+
default: undefined
|
80
|
+
},
|
81
|
+
placeholder: {
|
82
|
+
type: String,
|
83
|
+
default: ""
|
84
|
+
},
|
85
|
+
selectionLabel: {
|
86
|
+
type: String,
|
87
|
+
default: null
|
88
|
+
},
|
89
|
+
chipLimit: {
|
90
|
+
type: Number,
|
91
|
+
default: 3
|
92
|
+
},
|
93
|
+
inputClass: {
|
94
|
+
type: String,
|
95
|
+
default: ""
|
96
|
+
},
|
97
|
+
selectionClass: {
|
98
|
+
type: String,
|
99
|
+
default: ""
|
100
|
+
},
|
101
|
+
options: {
|
102
|
+
type: Array,
|
103
|
+
default: () => []
|
104
|
+
},
|
105
|
+
filterable: Boolean,
|
106
|
+
filterFn: {
|
107
|
+
type: Function,
|
108
|
+
default: null
|
109
|
+
}
|
108
110
|
});
|
109
111
|
|
110
112
|
const selectField = ref(null);
|
@@ -119,27 +121,27 @@ const isShowing = ref(false);
|
|
119
121
|
* @type {ComputedRef<{selectionLabel: string, label: string, value: string|*}[]>}
|
120
122
|
*/
|
121
123
|
const computedOptions = computed(() => {
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
124
|
+
let options = props.options;
|
125
|
+
if (props.placeholder && !props.multiple && !props.filterable) {
|
126
|
+
options = [{ label: props.placeholder, value: null }, ...props.options];
|
127
|
+
}
|
128
|
+
options = options.map((o) => {
|
129
|
+
let opt = isRef(o) ? o.value : o;
|
130
|
+
return {
|
131
|
+
label: resolveLabel(opt),
|
132
|
+
value: resolveValue(opt),
|
133
|
+
selectionLabel: resolveSelectionLabel(opt)
|
134
|
+
};
|
135
|
+
});
|
136
|
+
return options;
|
135
137
|
});
|
136
138
|
|
137
139
|
const filteredOptions = computed(() => {
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
140
|
+
if (filter.value && !props.filterFn) {
|
141
|
+
return computedOptions.value.filter(o => o.label.toLocaleLowerCase().indexOf(filter.value.toLowerCase()) > -1);
|
142
|
+
} else {
|
143
|
+
return computedOptions.value;
|
144
|
+
}
|
143
145
|
});
|
144
146
|
|
145
147
|
/**
|
@@ -147,14 +149,14 @@ const filteredOptions = computed(() => {
|
|
147
149
|
* @type {ComputedRef<unknown>}
|
148
150
|
*/
|
149
151
|
const selectedValue = computed(() => {
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
152
|
+
if (props.multiple) {
|
153
|
+
const arrVal = Array.isArray(props.modelValue) ? props.modelValue : [];
|
154
|
+
return arrVal.map((v) => {
|
155
|
+
return v === null ? "__null__" : v;
|
156
|
+
}) || [];
|
157
|
+
} else {
|
158
|
+
return props.modelValue === null ? "__null__" : props.modelValue;
|
159
|
+
}
|
158
160
|
});
|
159
161
|
|
160
162
|
/**
|
@@ -162,13 +164,13 @@ const selectedValue = computed(() => {
|
|
162
164
|
* @type {ComputedRef<*>}
|
163
165
|
*/
|
164
166
|
const selectedOptions = computed(() => {
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
167
|
+
let values = selectedValue.value;
|
168
|
+
if (!props.multiple) {
|
169
|
+
values = (values || values === 0) ? [values] : [];
|
170
|
+
}
|
171
|
+
return computedOptions.value.filter((o) => {
|
172
|
+
return values.includes(o.value) || values.map(v => typeof v === "object" && v.id).includes(o.value?.id);
|
173
|
+
});
|
172
174
|
});
|
173
175
|
|
174
176
|
/**
|
@@ -177,12 +179,12 @@ const selectedOptions = computed(() => {
|
|
177
179
|
* @type {ComputedRef<unknown>}
|
178
180
|
*/
|
179
181
|
const selectedLabel = computed(() => {
|
180
|
-
|
182
|
+
if (props.filterable && isShowing.value) return "";
|
181
183
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
184
|
+
if (!selectedOptions.value || selectedOptions.value.length === 0) {
|
185
|
+
return props.placeholder || "(Select Option)";
|
186
|
+
}
|
187
|
+
return selectedOptions.value[0].selectionLabel;
|
186
188
|
});
|
187
189
|
|
188
190
|
/**
|
@@ -190,7 +192,7 @@ const selectedLabel = computed(() => {
|
|
190
192
|
* @type {ComputedRef<*>}
|
191
193
|
*/
|
192
194
|
const chipOptions = computed(() => {
|
193
|
-
|
195
|
+
return selectedOptions.value.slice(0, props.chipLimit);
|
194
196
|
});
|
195
197
|
|
196
198
|
/**
|
@@ -199,16 +201,16 @@ const chipOptions = computed(() => {
|
|
199
201
|
* @returns {*|string}
|
200
202
|
*/
|
201
203
|
function resolveLabel(option) {
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
204
|
+
if (typeof option === "string") {
|
205
|
+
return option;
|
206
|
+
}
|
207
|
+
if (typeof props.optionLabel === "string") {
|
208
|
+
return option[props.optionLabel];
|
209
|
+
}
|
210
|
+
if (typeof props.optionLabel === "function") {
|
211
|
+
return props.optionLabel(option);
|
212
|
+
}
|
213
|
+
return option?.label;
|
212
214
|
}
|
213
215
|
|
214
216
|
/**
|
@@ -218,16 +220,16 @@ function resolveLabel(option) {
|
|
218
220
|
* @returns {*|{default: null, type: String | StringConstructor}|string}
|
219
221
|
*/
|
220
222
|
function resolveSelectionLabel(option) {
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
223
|
+
if (typeof option === "string") {
|
224
|
+
return option;
|
225
|
+
}
|
226
|
+
if (typeof props.selectionLabel === "string") {
|
227
|
+
return option[props.selectionLabel];
|
228
|
+
}
|
229
|
+
if (typeof props.selectionLabel === "function") {
|
230
|
+
return props.selectionLabel(option);
|
231
|
+
}
|
232
|
+
return option?.selectionLabel || option?.label;
|
231
233
|
}
|
232
234
|
|
233
235
|
/**
|
@@ -236,17 +238,17 @@ function resolveSelectionLabel(option) {
|
|
236
238
|
* @returns {string|*|string}
|
237
239
|
*/
|
238
240
|
function resolveValue(option) {
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
241
|
+
if (!option || typeof option === "string") {
|
242
|
+
return option;
|
243
|
+
}
|
244
|
+
let value = option.value;
|
245
|
+
if (typeof props.optionValue === "string") {
|
246
|
+
value = option[props.optionValue];
|
247
|
+
} else if (typeof props.optionValue === "function") {
|
248
|
+
value = props.optionValue(option);
|
249
|
+
}
|
250
|
+
// Note the __null__ special case here. See the onUpdate function for more details
|
251
|
+
return value === null ? "__null__" : value;
|
250
252
|
}
|
251
253
|
|
252
254
|
/**
|
@@ -256,14 +258,14 @@ function resolveValue(option) {
|
|
256
258
|
* @param value
|
257
259
|
*/
|
258
260
|
function onUpdate(value) {
|
259
|
-
|
260
|
-
|
261
|
-
|
261
|
+
if (Array.isArray(value)) {
|
262
|
+
value = value.map((v) => v === "__null__" ? null : v);
|
263
|
+
}
|
262
264
|
|
263
|
-
|
265
|
+
value = value === "__null__" ? null : value;
|
264
266
|
|
265
|
-
|
266
|
-
|
267
|
+
emit("update", value);
|
268
|
+
emit("update:model-value", value);
|
267
269
|
}
|
268
270
|
|
269
271
|
/** XXX: This tells us when we should apply the filter. QSelect likes to trigger a new filter everytime you open the dropdown
|
@@ -277,19 +279,19 @@ const shouldFilter = ref(false);
|
|
277
279
|
* @param update
|
278
280
|
*/
|
279
281
|
async function onFilter(val, update) {
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
282
|
+
if (!props.filterFn) {
|
283
|
+
filter.value = val;
|
284
|
+
await nextTick(update);
|
285
|
+
} else {
|
286
|
+
update();
|
287
|
+
if (shouldFilter.value === false) return;
|
288
|
+
if (val !== null && val !== filter.value) {
|
289
|
+
filter.value = val;
|
290
|
+
if (props.filterFn) {
|
291
|
+
await props.filterFn(val);
|
292
|
+
}
|
293
|
+
}
|
294
|
+
}
|
293
295
|
}
|
294
296
|
|
295
297
|
/**
|
@@ -297,29 +299,29 @@ async function onFilter(val, update) {
|
|
297
299
|
* See the onUpdate function for more details
|
298
300
|
*/
|
299
301
|
function onClear() {
|
300
|
-
|
301
|
-
|
302
|
+
emit("update:model-value", undefined);
|
303
|
+
emit("update", undefined);
|
302
304
|
}
|
303
305
|
|
304
306
|
/**
|
305
307
|
* Handle behavior when showing the dropdown
|
306
308
|
*/
|
307
309
|
function onShow() {
|
308
|
-
|
310
|
+
isShowing.value = true;
|
309
311
|
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
312
|
+
// XXX: See description on shouldFilter declaration. Only allow filtering after dropdown is ALREADY opened
|
313
|
+
shouldFilter.value = false;
|
314
|
+
nextTick(() => {
|
315
|
+
shouldFilter.value = true;
|
316
|
+
selectField.value.focus();
|
317
|
+
});
|
316
318
|
}
|
317
319
|
|
318
320
|
/**
|
319
321
|
* Handle behavior when hiding the dropdown
|
320
322
|
*/
|
321
323
|
function onHide() {
|
322
|
-
|
323
|
-
|
324
|
+
isShowing.value = false;
|
325
|
+
shouldFilter.value = false;
|
324
326
|
}
|
325
327
|
</script>
|