@lemonadejs/dropdown 5.8.0 → 5.8.2
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/index.d.ts +3 -1
- package/dist/index.js +59 -4
- package/dist/style.css +4 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -102,7 +102,9 @@ declare namespace Dropdown {
|
|
|
102
102
|
isClosed: () => boolean;
|
|
103
103
|
/** Get current value */
|
|
104
104
|
getValue: () => number | string | number[] | string[];
|
|
105
|
-
/** Get current
|
|
105
|
+
/** Get current text (label). Returns string if single, string[] if multiple */
|
|
106
|
+
getText: () => string | string[];
|
|
107
|
+
/** Set current value */
|
|
106
108
|
setValue: (value: number | string | number[] | string[]) => void;
|
|
107
109
|
/** Get current data */
|
|
108
110
|
getData: () => Item[];
|
package/dist/index.js
CHANGED
|
@@ -539,7 +539,13 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
539
539
|
|
|
540
540
|
if (Array.isArray(data)) {
|
|
541
541
|
data.map(function (s) {
|
|
542
|
-
s.selected = newValue.some(v =>
|
|
542
|
+
s.selected = newValue.some(v => {
|
|
543
|
+
// Use strict equality when either value is empty string to avoid '' == 0 being true
|
|
544
|
+
if (v === '' || s.value === '') {
|
|
545
|
+
return v === s.value;
|
|
546
|
+
}
|
|
547
|
+
return v == s.value;
|
|
548
|
+
});
|
|
543
549
|
if (s.selected) {
|
|
544
550
|
value.push(s);
|
|
545
551
|
}
|
|
@@ -574,6 +580,20 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
574
580
|
return null;
|
|
575
581
|
}
|
|
576
582
|
|
|
583
|
+
const getText = function () {
|
|
584
|
+
if (self.multiple) {
|
|
585
|
+
if (value && value.length) {
|
|
586
|
+
return value.filter(v => v.selected).map(i => i.text);
|
|
587
|
+
}
|
|
588
|
+
} else {
|
|
589
|
+
if (value && value.length) {
|
|
590
|
+
return value[0].text;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
return null;
|
|
595
|
+
}
|
|
596
|
+
|
|
577
597
|
const onopen = function () {
|
|
578
598
|
self.state = true;
|
|
579
599
|
// Value
|
|
@@ -719,7 +739,7 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
719
739
|
if (! self.isClosed() && self.autocomplete) {
|
|
720
740
|
|
|
721
741
|
// Remote or normal search
|
|
722
|
-
if (self.remote === true) {
|
|
742
|
+
if (self.remote === true && self.url) {
|
|
723
743
|
// Clear existing timeout
|
|
724
744
|
if (searchTimeout) {
|
|
725
745
|
clearTimeout(searchTimeout);
|
|
@@ -744,7 +764,11 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
744
764
|
|
|
745
765
|
// Debounce the search with 300ms delay
|
|
746
766
|
searchTimeout = setTimeout(() => {
|
|
747
|
-
|
|
767
|
+
let url = self.url;
|
|
768
|
+
url += url.indexOf('?') === -1 ? '?' : '&';
|
|
769
|
+
url += `q=${query}`;
|
|
770
|
+
|
|
771
|
+
fetch(url, http).then(r => r.json()).then(resetData).catch((error) => {
|
|
748
772
|
resetData([]);
|
|
749
773
|
});
|
|
750
774
|
}, 300);
|
|
@@ -1024,6 +1048,10 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
1024
1048
|
return self.value;
|
|
1025
1049
|
}
|
|
1026
1050
|
|
|
1051
|
+
self.getText = function() {
|
|
1052
|
+
return getText();
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1027
1055
|
self.setValue = function(v) {
|
|
1028
1056
|
self.value = v;
|
|
1029
1057
|
}
|
|
@@ -1143,8 +1171,35 @@ if (!Modal && typeof (require) === 'function') {
|
|
|
1143
1171
|
if (prop === 'value') {
|
|
1144
1172
|
setValue(self.value);
|
|
1145
1173
|
} else if (prop === 'data') {
|
|
1174
|
+
// Store current value before resetting data
|
|
1175
|
+
let currentValue = self.value;
|
|
1146
1176
|
setData();
|
|
1147
|
-
|
|
1177
|
+
|
|
1178
|
+
// Only reset value if it's not in the new data
|
|
1179
|
+
if (currentValue !== null && currentValue !== undefined && currentValue !== '') {
|
|
1180
|
+
let valuesToCheck = Array.isArray(currentValue) ? currentValue : [currentValue];
|
|
1181
|
+
|
|
1182
|
+
// Filter to keep only values that exist in the new data
|
|
1183
|
+
let validValues = valuesToCheck.filter(v => {
|
|
1184
|
+
return self.data.some(item => {
|
|
1185
|
+
if (v === '' || item.value === '') {
|
|
1186
|
+
return v === item.value;
|
|
1187
|
+
}
|
|
1188
|
+
return v == item.value;
|
|
1189
|
+
});
|
|
1190
|
+
});
|
|
1191
|
+
|
|
1192
|
+
if (validValues.length === 0) {
|
|
1193
|
+
// No valid values remain, reset to null
|
|
1194
|
+
self.value = null;
|
|
1195
|
+
} else if (self.multiple) {
|
|
1196
|
+
// Multi-select: keep only valid values
|
|
1197
|
+
self.value = validValues;
|
|
1198
|
+
} else {
|
|
1199
|
+
// Single select: re-apply the value
|
|
1200
|
+
self.value = validValues[0];
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1148
1203
|
}
|
|
1149
1204
|
|
|
1150
1205
|
if (typeof (lazyloading) === 'function') {
|
package/dist/style.css
CHANGED
package/package.json
CHANGED
|
@@ -14,10 +14,10 @@
|
|
|
14
14
|
"javascript plugins"
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"lemonadejs": "^5.3.
|
|
18
|
-
"@lemonadejs/modal": "^5.8.
|
|
17
|
+
"lemonadejs": "^5.3.6",
|
|
18
|
+
"@lemonadejs/modal": "^5.8.2"
|
|
19
19
|
},
|
|
20
20
|
"main": "dist/index.js",
|
|
21
21
|
"types": "dist/index.d.ts",
|
|
22
|
-
"version": "5.8.
|
|
22
|
+
"version": "5.8.2"
|
|
23
23
|
}
|