vue3-extended-multiselect 1.7.5 → 1.8.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.
- package/CHANGELOG.md +16 -2
- package/README.md +1 -2
- package/jest.config.js +1 -1
- package/package.json +1 -2
- package/src/components/ExtendedMultiselectInput.vue +5 -4
- package/src/components/Vue3ExtendedMultiselect.vue +38 -12
- package/src/composition/debounce.js +9 -0
- package/src/composition/emitter.js +3 -3
- package/src/tools/Debounce.js +26 -0
- package/src/{events → tools}/LocalEmitter.js +0 -0
- package/src/tools/instance.js +3 -0
- package/tests/unit/tools.spec.js +54 -0
- package/typings/vue3-extended-multiselect.d.ts +2 -1
- package/src/events/instance.js +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Patch notes
|
|
2
2
|
|
|
3
|
-
Current `vue3-extended-multiselect` version: **1.
|
|
3
|
+
Current `vue3-extended-multiselect` version: **1.8.1**
|
|
4
4
|
|
|
5
5
|
***
|
|
6
6
|
|
|
@@ -293,4 +293,18 @@ Adding descriptive comments for some types in typings.
|
|
|
293
293
|
|
|
294
294
|
### 1.7.5 (2023-02-08)
|
|
295
295
|
|
|
296
|
-
* Removal of excess condition in toggle restriction.
|
|
296
|
+
* Removal of excess condition in toggle restriction.
|
|
297
|
+
|
|
298
|
+
### 1.8.0 (2023-02-15)
|
|
299
|
+
|
|
300
|
+
* Adding tools directory.
|
|
301
|
+
* Adding Debounce.js file with debounce tool.
|
|
302
|
+
* Adding type for "update-wrapper" event.
|
|
303
|
+
* Adding tools.spec.js file with unit-tests for tools.
|
|
304
|
+
* Moving local emitter files to tools directory.
|
|
305
|
+
* Removal of "lodash-es" dependency.
|
|
306
|
+
|
|
307
|
+
### 1.8.1 (2023-02-21)
|
|
308
|
+
|
|
309
|
+
* Removal of "update:wrapper" event.
|
|
310
|
+
* Fixing bug with incorrect v-model updating in custom wrappers.
|
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# vue3-extended-multiselect v1.
|
|
1
|
+
# vue3-extended-multiselect v1.8.1
|
|
2
2
|
|
|
3
3
|
***
|
|
4
4
|
|
|
@@ -122,7 +122,6 @@ Event name | Event appointment | Listener method | Simplified event payload | Fi
|
|
|
122
122
|
**active**|Dropdown options list expanding.|@active|—|``inputId`` — id of search field set by "id" prop|
|
|
123
123
|
**close**|Rolling up dropdown options list.|@close|``options`` — array of selected options|``options`` — array of selected options,<br/>``inputId`` — id of search field set by "id" prop|
|
|
124
124
|
**increase**|Increasing current limit of displayed elements with selected options.|@increase|``limit`` — current limit of options to be shown next|``limit`` — current limit of options to be shown next,<br/>``inputId`` — id of search field set by "id" prop|
|
|
125
|
-
**update:wrapper**|Notifies wrapper component that inner modelValue has been updated by external modelValue update|@update:wrapper|``options`` — array of selected options|``options`` — array of selected options,<br/>``inputId`` — id of search field set by "id" prop|
|
|
126
125
|
|
|
127
126
|
## Styling with css
|
|
128
127
|
|
package/jest.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue3-extended-multiselect",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.1",
|
|
4
4
|
"description": "Extended multiselect component for applications based on Vue 3 framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"multiselect",
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"core-js": "^3.6.5",
|
|
26
26
|
"extended-click-outside": "^1.1.0",
|
|
27
|
-
"lodash-es": "^4.17.21",
|
|
28
27
|
"vue": "^3.0.0"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
@@ -152,7 +152,7 @@ import {
|
|
|
152
152
|
watch,
|
|
153
153
|
} from "vue";
|
|
154
154
|
|
|
155
|
-
import
|
|
155
|
+
import useDebounce from "../composition/debounce";
|
|
156
156
|
|
|
157
157
|
import ExtendedMultiselectMultiple from "./ExtendedMultiselectMultiple.vue";
|
|
158
158
|
|
|
@@ -419,6 +419,8 @@ const setSearchPattern = inject("setSearchPattern");
|
|
|
419
419
|
|
|
420
420
|
const emitter = toRef(props, "emitter");
|
|
421
421
|
|
|
422
|
+
const { DebounceConstructor } = useDebounce();
|
|
423
|
+
|
|
422
424
|
const blurSkip = ref(false);
|
|
423
425
|
const reversePrevented = ref(false);
|
|
424
426
|
const searchFieldFocused = ref(false);
|
|
@@ -428,9 +430,8 @@ const singleLabel = ref("");
|
|
|
428
430
|
const blurSkipByToggleIcon = ref(0);
|
|
429
431
|
const blurSkipByBlock = ref(0);
|
|
430
432
|
const labelBlocks = ref([]);
|
|
431
|
-
const searchDebounce = ref(
|
|
433
|
+
const searchDebounce = ref(new DebounceConstructor.value(() => {
|
|
432
434
|
const searchPattern = searchValue.value ? new RegExp(`${searchValue.value}`, "i") : null;
|
|
433
|
-
|
|
434
435
|
if (externalOptionsLoader.value) {
|
|
435
436
|
emitter.value.emit("extended:loader-pattern-changed", searchValue.value);
|
|
436
437
|
} else {
|
|
@@ -609,7 +610,7 @@ const rollUp = () => {
|
|
|
609
610
|
* @function
|
|
610
611
|
*/
|
|
611
612
|
const search = () => {
|
|
612
|
-
searchDebounce.value();
|
|
613
|
+
searchDebounce.value.start();
|
|
613
614
|
};
|
|
614
615
|
|
|
615
616
|
/**
|
|
@@ -245,7 +245,7 @@ import {
|
|
|
245
245
|
UnionPropType,
|
|
246
246
|
} from "../sets/sets";
|
|
247
247
|
|
|
248
|
-
import localEmitter from "../
|
|
248
|
+
import localEmitter from "../tools/instance.js";
|
|
249
249
|
|
|
250
250
|
import useToggle from "../composition/toggle";
|
|
251
251
|
import useCancel from "../composition/cancel";
|
|
@@ -262,7 +262,7 @@ import ExtendedMultiselectToggle from "./ExtendedMultiselectToggle.vue";
|
|
|
262
262
|
|
|
263
263
|
/**
|
|
264
264
|
* @author Ridiger Daniil Dmitrievich, 2022
|
|
265
|
-
* @version 1.
|
|
265
|
+
* @version 1.8.1
|
|
266
266
|
*/
|
|
267
267
|
|
|
268
268
|
const props = defineProps({
|
|
@@ -903,6 +903,7 @@ const emit = defineEmits([
|
|
|
903
903
|
]);
|
|
904
904
|
|
|
905
905
|
const dropdownActive = ref(false);
|
|
906
|
+
const skipNextUpdate = ref(false);
|
|
906
907
|
const externalOptionsLoader = ref(null);
|
|
907
908
|
const chosenToggleAppearanceSide = ref(null);
|
|
908
909
|
const selectedOptionsWatcher = ref(null);
|
|
@@ -1086,6 +1087,17 @@ const internalLoading = computed(() => {
|
|
|
1086
1087
|
return loading.value;
|
|
1087
1088
|
});
|
|
1088
1089
|
|
|
1090
|
+
/**
|
|
1091
|
+
* Defines mapped list of previously restricted options
|
|
1092
|
+
* @function
|
|
1093
|
+
* @returns {Array} options
|
|
1094
|
+
*/
|
|
1095
|
+
const mappedOptions = computed(() => {
|
|
1096
|
+
return restrictedOptions.value.map((restrictedOption) => {
|
|
1097
|
+
return JSON.stringify(restrictedOption);
|
|
1098
|
+
});
|
|
1099
|
+
});
|
|
1100
|
+
|
|
1089
1101
|
/**
|
|
1090
1102
|
* Defines a list of options filtered by maximal admissible options amount
|
|
1091
1103
|
* @function
|
|
@@ -1156,6 +1168,11 @@ watch(dropdownActive, (value) => {
|
|
|
1156
1168
|
* @function
|
|
1157
1169
|
*/
|
|
1158
1170
|
watch(modelValue, () => {
|
|
1171
|
+
if (skipNextUpdate.value) {
|
|
1172
|
+
skipNextUpdate.value = false;
|
|
1173
|
+
return;
|
|
1174
|
+
}
|
|
1175
|
+
|
|
1159
1176
|
setPreselectedOptionsByModelValue(true);
|
|
1160
1177
|
}, { deep: true });
|
|
1161
1178
|
|
|
@@ -1324,12 +1341,15 @@ const selectByEnter = (keyboardEvent) => {
|
|
|
1324
1341
|
*/
|
|
1325
1342
|
const setPreselectedOption = (preselectedOption, restriction = true) => {
|
|
1326
1343
|
const availableOptionType = optionTypeRestrictor(preselectedOption);
|
|
1327
|
-
const
|
|
1328
|
-
return JSON.stringify(
|
|
1344
|
+
const mappedSelectedOptions = selectedOptions.value.map((selectedOption) => {
|
|
1345
|
+
return JSON.stringify(selectedOption);
|
|
1329
1346
|
});
|
|
1330
1347
|
|
|
1331
1348
|
if (!availableOptionType) return;
|
|
1332
|
-
if (
|
|
1349
|
+
if (
|
|
1350
|
+
(!mappedOptions.value.includes(JSON.stringify(preselectedOption)) && restriction)
|
|
1351
|
+
&& !mappedSelectedOptions.includes(JSON.stringify(preselectedOption))
|
|
1352
|
+
) {
|
|
1333
1353
|
if (showInsertWarnings.value) {
|
|
1334
1354
|
console.warn("vue-extended-multiselect: option in «preselectedOption» property should be the same as analogue in «options» property");
|
|
1335
1355
|
}
|
|
@@ -1356,8 +1376,8 @@ const setPreselectedOption = (preselectedOption, restriction = true) => {
|
|
|
1356
1376
|
*/
|
|
1357
1377
|
const setPreselectedOptions = async (preselectedOptions, restriction = true) => {
|
|
1358
1378
|
let allOptionsWereSelected = 0;
|
|
1359
|
-
const
|
|
1360
|
-
return JSON.stringify(
|
|
1379
|
+
const mappedSelectedOptions = selectedOptions.value.map((selectedOption) => {
|
|
1380
|
+
return JSON.stringify(selectedOption);
|
|
1361
1381
|
});
|
|
1362
1382
|
|
|
1363
1383
|
preselectedOptions.forEach((preselectedOption) => {
|
|
@@ -1366,7 +1386,10 @@ const setPreselectedOptions = async (preselectedOptions, restriction = true) =>
|
|
|
1366
1386
|
if (!preselectedOption || !availableOptionType) return;
|
|
1367
1387
|
if (selectedOptions.value.includes(preselectedOption)) return;
|
|
1368
1388
|
|
|
1369
|
-
if (
|
|
1389
|
+
if (
|
|
1390
|
+
(mappedOptions.value.includes(JSON.stringify(preselectedOption)) || !restriction)
|
|
1391
|
+
&& !mappedSelectedOptions.includes(JSON.stringify(preselectedOption))
|
|
1392
|
+
) {
|
|
1370
1393
|
const isObjectOrArray = typeof option === "object";
|
|
1371
1394
|
const label = createLabel(isObjectOrArray, preselectedOption);
|
|
1372
1395
|
|
|
@@ -1407,11 +1430,14 @@ const setPreselectedOptionsByModelValue = (withRemoval = false) => {
|
|
|
1407
1430
|
}
|
|
1408
1431
|
|
|
1409
1432
|
if (withRemoval) {
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1433
|
+
if (multiple.value) {
|
|
1434
|
+
emit("update:modelValue", selectedOptions.value);
|
|
1435
|
+
} else {
|
|
1436
|
+
emit("update:modelValue", selectedOptions.value[0]);
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
skipNextUpdate.value = true;
|
|
1413
1440
|
|
|
1414
|
-
emit("update:wrapper", eventData);
|
|
1415
1441
|
selectedOptionsWatcher.value = watch(selectedOptions, (value) => {
|
|
1416
1442
|
if (multiple.value) {
|
|
1417
1443
|
emit("update:modelValue", value);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ref } from "vue";
|
|
2
2
|
|
|
3
|
-
import LocalEmitter from "../
|
|
3
|
+
import LocalEmitter from "../tools/LocalEmitter";
|
|
4
4
|
|
|
5
5
|
export default function useEmitter() {
|
|
6
|
-
|
|
6
|
+
const emitter = ref(new LocalEmitter());
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
return { emitter };
|
|
9
9
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class Debounce {
|
|
2
|
+
|
|
3
|
+
_localTimer = null;
|
|
4
|
+
_localTimeout = null;
|
|
5
|
+
_callback = null;
|
|
6
|
+
_timer = 0;
|
|
7
|
+
|
|
8
|
+
constructor(callback, timer) {
|
|
9
|
+
this._callback = callback;
|
|
10
|
+
this._timer = timer;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
start() {
|
|
14
|
+
this._localTimer = performance.now();
|
|
15
|
+
|
|
16
|
+
if (this._localTimeout) {
|
|
17
|
+
clearTimeout(this._localTimeout);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
this._localTimeout = setTimeout(() => {
|
|
21
|
+
this._callback();
|
|
22
|
+
}, this._timer);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default Debounce;
|
|
File without changes
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { fireEvent } from "@testing-library/dom";
|
|
2
|
+
|
|
3
|
+
import { mountComponent } from "../utils/mount";
|
|
4
|
+
|
|
5
|
+
import Vue3ExtendedMultiselect from "../../src/components/Vue3ExtendedMultiselect.vue";
|
|
6
|
+
import ExtendedMultiselectOptions from "../../src/components/ExtendedMultiselectOptions.vue";
|
|
7
|
+
|
|
8
|
+
let wrapper;
|
|
9
|
+
|
|
10
|
+
describe("tools", () => {
|
|
11
|
+
it("correctly debounces search value changing", async (done) => {
|
|
12
|
+
const propsData = {
|
|
13
|
+
defaultExpanded: true,
|
|
14
|
+
options: globalThis.OPTIONS,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
wrapper = await mountComponent(Vue3ExtendedMultiselect, false, propsData);
|
|
18
|
+
|
|
19
|
+
const input = wrapper.find("input");
|
|
20
|
+
const optionsWrapper = wrapper.findComponent(ExtendedMultiselectOptions);
|
|
21
|
+
const optionsListWrapper = optionsWrapper.find(".extended__multiselect-options_container");
|
|
22
|
+
|
|
23
|
+
await fireEvent.input(input.element, { target: { value: globalThis.SEARCH_VALUE_WITH_RESULTS } });
|
|
24
|
+
|
|
25
|
+
expect(optionsListWrapper.element.children).toHaveLength(4);
|
|
26
|
+
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
expect(optionsListWrapper.element.children).toHaveLength(1);
|
|
29
|
+
|
|
30
|
+
done();
|
|
31
|
+
}, 1000);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
it("correctly handles outside clicks", async () => {
|
|
36
|
+
const propsData = {
|
|
37
|
+
defaultExpanded: true,
|
|
38
|
+
options: globalThis.OPTIONS,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
wrapper = await mountComponent(Vue3ExtendedMultiselect, false, propsData);
|
|
42
|
+
|
|
43
|
+
let optionsWrapper = wrapper.findComponent(ExtendedMultiselectOptions);
|
|
44
|
+
|
|
45
|
+
expect(optionsWrapper.exists()).toBeTruthy();
|
|
46
|
+
expect(optionsWrapper.isVisible()).toBeTruthy();
|
|
47
|
+
|
|
48
|
+
await fireEvent.click(document.documentElement);
|
|
49
|
+
|
|
50
|
+
optionsWrapper = wrapper.findComponent(ExtendedMultiselectOptions);
|
|
51
|
+
|
|
52
|
+
expect(optionsWrapper.exists()).toBeFalsy();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -41,4 +41,5 @@ export type CloseEvent = CleanEvent;
|
|
|
41
41
|
export type IncreaseEvent = number | Limit;
|
|
42
42
|
export type OptionCreatedEvent = UnionOptionType | SingleOption;
|
|
43
43
|
export type PatternChangedEvent = string | PatternChanged;
|
|
44
|
-
export type SelectEvent = OptionCreatedEvent;
|
|
44
|
+
export type SelectEvent = OptionCreatedEvent;
|
|
45
|
+
export type UpdateWrapperEvent = OptionsList;
|
package/src/events/instance.js
DELETED